drivers/char/hpet.c
Source file repositories/reference/linux-study-clean/drivers/char/hpet.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/hpet.c- Extension
.c- Size
- 24000 bytes
- Lines
- 1042
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/kernel.hlinux/types.hlinux/miscdevice.hlinux/major.hlinux/ioport.hlinux/fcntl.hlinux/init.hlinux/io-64-nonatomic-lo-hi.hlinux/poll.hlinux/mm.hlinux/proc_fs.hlinux/spinlock.hlinux/sysctl.hlinux/wait.hlinux/sched/signal.hlinux/bcd.hlinux/seq_file.hlinux/bitops.hlinux/compat.hlinux/clocksource.hlinux/uaccess.hlinux/slab.hlinux/io.hlinux/acpi.hlinux/hpet.hlinux/platform_device.hasm/current.hasm/irq.hasm/div64.h
Detected Declarations
struct hpet_devstruct hpetsstruct compat_hpet_infofunction hpet_interruptfunction hpet_timer_set_irqfunction for_each_set_bitfunction hpet_openfunction hpet_readfunction hpet_pollfunction hpet_mmap_enablefunction hpet_mmap_preparefunction hpet_mmap_preparefunction hpet_fasyncfunction hpet_releasefunction hpet_ioctl_ieonfunction hpet_time_divfunction hpet_ioctl_commonfunction hpet_ioctlfunction hpet_compat_ioctlfunction hpet_is_knownfunction __hpet_calibratefunction hpet_calibratefunction hpet_allocfunction hpet_resourcesfunction hpet_acpi_probefunction hpet_initmodule init hpet_init
Annotated Snippet
static const struct file_operations hpet_fops = {
.owner = THIS_MODULE,
.read = hpet_read,
.poll = hpet_poll,
.unlocked_ioctl = hpet_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = hpet_compat_ioctl,
#endif
.open = hpet_open,
.release = hpet_release,
.fasync = hpet_fasync,
.mmap_prepare = hpet_mmap_prepare,
};
static int hpet_is_known(struct hpet_data *hdp)
{
struct hpets *hpetp;
for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
if (hpetp->hp_hpet_phys == hdp->hd_phys_address)
return 1;
return 0;
}
static const struct ctl_table hpet_table[] = {
{
.procname = "max-user-freq",
.data = &hpet_max_freq,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec,
},
};
static struct ctl_table_header *sysctl_header;
/*
* Adjustment for when arming the timer with
* initial conditions. That is, main counter
* ticks expired before interrupts are enabled.
*/
#define TICK_CALIBRATE (1000UL)
static unsigned long __hpet_calibrate(struct hpets *hpetp)
{
struct hpet_timer __iomem *timer = NULL;
unsigned long t, m, count, i, flags, start;
struct hpet_dev *devp;
int j;
struct hpet __iomem *hpet;
for (j = 0, devp = hpetp->hp_dev; j < hpetp->hp_ntimer; j++, devp++)
if ((devp->hd_flags & HPET_OPEN) == 0) {
timer = devp->hd_timer;
break;
}
if (!timer)
return 0;
hpet = hpetp->hp_hpet;
t = read_counter(&timer->hpet_compare);
i = 0;
count = hpet_time_div(hpetp, TICK_CALIBRATE);
local_irq_save(flags);
start = read_counter(&hpet->hpet_mc);
do {
m = read_counter(&hpet->hpet_mc);
write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare);
} while (i++, (m - start) < count);
local_irq_restore(flags);
return (m - start) / i;
}
static unsigned long hpet_calibrate(struct hpets *hpetp)
{
unsigned long ret = ~0UL;
unsigned long tmp;
/*
* Try to calibrate until return value becomes stable small value.
* If SMI interruption occurs in calibration loop, the return value
* will be big. This avoids its impact.
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/kernel.h`, `linux/types.h`, `linux/miscdevice.h`, `linux/major.h`, `linux/ioport.h`, `linux/fcntl.h`, `linux/init.h`.
- Detected declarations: `struct hpet_dev`, `struct hpets`, `struct compat_hpet_info`, `function hpet_interrupt`, `function hpet_timer_set_irq`, `function for_each_set_bit`, `function hpet_open`, `function hpet_read`, `function hpet_poll`, `function hpet_mmap_enable`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.