HPET API †
HPET API 日本語ページ
Here shows HPET driver API. Using man page like format with some modifications. Following lines shows modifications,
- "SYNOPSIS" shows with preferred, or fixed value argument.
- "PRECONDITION" shows conditions that application should satisfy before calling the API.
- "RETURN VALUE" and "ERROR" shows only HPET driver specification. To see basic system call specification, use man pages.
- "KERNEL CONFIGURATION and PARAMETER" shows some conditions at kernel building and kernel booting affected to API behavior.
- "KERNEL SOURCE" shows related kernel source code.
Features †
HPET driver provides following features.
To know more details refer to HPET specification.
Example †
To know HPET driver /drivers/char/hpet.c API, here is example application hpet_example.tar.gz. This application program is based on /Documentation/timers/hpet_example.c with some modifications and additions.
Device path †
Most linux distributions enable HPET driver and prepare access node /dev/hpet. /dev/hpet is the character device node associated to major=10, minor=228 one of "misc device".
Open device †
To use HPET device, open /dev/hpet with file mode O_RDONLY. If there is a unused(free) HPET timer, assign a timer to opened file descriptor. A timer is one of timer circuit block in HPET block. HPET driver's ioctl() calls manipulate the timer assigned to file descriptor.
Header files †
To use HPET device from user space (Linux Application), include header files as follows.
#define _GNU_SOURCE
#include <features.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/hpet.h>
If you wish to use poll(), include optional header file as follows.
#include <poll.h>
If you wish to use select(), include optional header files as follows.
#include <sys/time.h>
#include <sys/select.h>
If you wish to use signal(), include optional header file as follows.
#include <signal.h>
If you wish to use mmap(), include optional header file as follows.
#include <sys/mman.h>
If you wish to handle error, include optional header files as follows.
#include <string.h> /* strerror() */
#include <errno.h> /* errno, Exxx macros. */
HPET driver's ioctl API †
In this section shows HPET driver ioctl() API. HPET driver provides following ioctl() API.
ioctl request number | description | HPET_INFO | Get Information int ioctl(int fd, HPET_INFO, /* out */ struct hpet_info *info); | HPET_IRQFREQ | Set Interrupt Frequency in Hz int ioctl(int fd, HPET_IRQFREQ, unsigned long frequency); | HPET_EPI | Enable hardware periodic interrupt int ioctl(int fd, HPET_EPI); | HPET_DPI | Disable hardware periodic interrupt int ioctl(int fd, HPET_DPI); | HPET_IE_ON | Interrupt On int ioctl(int fd, HPET_IE_ON); | HPET_IE_OFF | Interrupt Off int ioctl(int fd, HPET_IE_OFF); |
Here shows HPET driver specific behaviors. To see basic file system ioctl() behaviors refer to man 2 ioctl.
HPET_INFO - Get Information †
- SYNOPSIS
struct hpet_info {
unsigned long hi_ireqfreq; /* Period or time in Hz */
unsigned long hi_flags; /* Information: 0x0: Not supported periodic int., 0x10: Supported periodic int. */
unsigned short hi_hpet; /* HPET device number, [0..TheNumberOfHPETDevicesInPlatform-1] */
unsigned short hi_timer; /* Timer number in HPET device, [0..31] */
};
int ioctl(int fd, HPET_INFO, /* out */ struct hpet_info *info);
- DESCRIPTION
Get the timer information assigned to file descriptor fd. ioctl call with HPET_INFO stores timer information to *info. This ioctl call fills hpet_info members as follows.
member | description | hi_ireqfreq | Interrupt frequency in Hz. | hi_flags | Timer capability. The value will be as follows, 0x00UL This timer doesn't have hardware implemented periodic interrupt. 0x10UL This timer has hardware implemented periodic interrupt. | hi_hpet | HPET device number on platform. It satisfies (hi_hpet >= 0) && (hi_hpet < M), where M is the number of HPET devices (circuit blocks) on platform. | hi_timer | Timer number in HPET device. It satisfies (hi_timer >= 0) && (hi_timer < N), where N is the number of timers in HPET device and N <= 32. NOTE: You may see {hi_hpet, hi_timer} == {0, 2} at first opened HPET timer, because the timer 0 and timer 1 replaces PIT(programmable Interval Timer) and RTC(Real Time Clock). |
- RETURN VALUE
- ERRORS
- EBADF: Invalid file descriptor fd.
- EFAULT: info points an inaccessible memory area.
- KERNEL SOURCE
HPET_INFO
HPET_IRQFREQ - Set Interrupt Frequency in Hz †
HPET_EPI - Enable hardware periodic interrupt †
HPET_DPI - Disable hardware periodic interrupt †
HPET_IE_ON - Interrupt On †
HPET_IE_OFF - Interrupt Off †
File System and Memory Mapping API related to HPET †
In this section shows File System and Memory Mapping API related to HPET driver. When using open(), close(), read(), mmap(), munmap(), fcntl(), and these alternate functions to access HPET, these API have HPET specific behaviour. Here shows
HPET specific behavior. To see file system specific basic behavior and details, refer to system call man pages. man 2 fcntl shows about sending signal from file descriptor in detail.
open HPET timer †
close HPET timer †
- SYNOPSIS
int close(int fd);
- DESCRIPTION
Close the HPET timer assigned to file descriptor fd. Release the timer from fd, the timer will be unused. Strictly speaking, the timer will be released at no one refers to fd. Duplicating fd, and mapping fd to memory add reference to fd. At releasing the timer from fd, do the following procedures.
- Disable interrupt from the timer.
- Disable hardware implemented periodic interrupt.
- Free IRQ handler.
- KERNEL SOURCE
read and clear interrupted count †
mmap HPET register on memory address space †
- SYNOPSIS
void *mmap(void *addr, size_t length, int prot, int flags, int fd, /* offset */ 0);
int munmap(void *addr, size_t length);
- DESCRIPTION
mmap() and munmap() HPET registers which has the timer assigned to file descriptor fd. This call maps/unmaps whole HPET block not only the timer to memory address space. When mmap() returns valid pointer, the pointer points HPET "General Capabilities and ID Register".
Valid length range is [ 0x1 .. page size (equal to sysconf(_SC_PAGESIZE)) ], but it maps HPET registers (and may containing other device(s) registers) ranged page size or more to memory address space.
offset should be zero.
- RETURN VALUE
- return_value != MAP_FAILED: Returned pointer points HPET "General Capabilities and ID Register"
- MAP_FAILED: Can't map HPET register.
- ERROR (HPET device specific)
- EACCESS: Not enabled mmap feature. Kernel was built without CONFIG_HPET_MMAP_DEFAULT, or kernel booted with "hpet_mmap=0". To enable HPET mmap feature, Add kernel parameter "hpet_mmap=1".
- ENOSYS:
- Kernel doesn't have HPET mmap function. Kernel was built without CONFIG_HPET_MMAP. This error also means that the kernel boot parameter "hpet_mmap=1" can't enable HPET mmap feature.
- HPET hardware implementation issue, HPET registers is not aligned to page boundary.
- KERNEL CONFIGURATION and PARAMETER
To use HPET mmap feature, satisfy following two conditions.
- Build kernel with CONFIG_HPET_MMAP=y.
- Add "hpet_mmap=1" to kernel parameter, if distributor or you built kernel without CONFIG_HPET_MMAP_DEFAULT=y.
- SEE ALSO
- KERNEL SOURCE
hpet_mmap()
F_GETOWN - Get file descriptor owner †
F_GETOWN_EX - Get file descriptor owner with extended feature †
- SYNOPSIS
struct f_owner_ex {
int type; /* F_OWNER_PID, F_OWNER_PGRP, or F_OWNER_TID */
pid_t pid; /* process id, process group id, or thread id. */
}
int fcntl(int fd, F_GETOWN_EX, /* out */ struct f_owner_ex *owner_ex);
- DESCRIPTION
Get owner assigned to file descriptor fd. fcntl() F_GETOWN_EX call stores result in *owner_ex. See more details in F_SETOWN_EX.
- KERNEL SOURCE
F_GETOWN_EX
F_SETOWN - Set file descriptor owner †
F_SETOWN_EX - Set file descriptor owner with extended feature †
- SYNOPSIS
struct f_owner_ex {
int type; /* F_OWNER_PID, F_OWNER_PGRP, or F_OWNER_TID */
pid_t pid; /* process id, process group id, or thread id. */
}
int fcntl(int fd, F_GETOWN_EX, /* in */ struct f_owner_ex *owner_ex);
- DESCRIPTION
Set one of process id, process group id, or thread id to file descriptor fd. type specifies pid containing which id. type should be one of F_OWNER_PID (process id), F_OWNER_PGRP (process group id), or F_OWNER_TID (thread id), and set process, process group, or thread id to pid.
When the timer assigned to fd interrupts a processor and the fd's file status flags has been ORed with O_ASYNC, a signal is sent to pid.
- KERNEL SOURCE
F_SETOWN_EX
F_GETFL - Get file status flags †
F_SETFL - Set file status flags †
F_GETSIG - Get signal number will be sent †
F_SETSIG - Set signal number will be sent †
|