drivers/char/apm-emulation.c
Source file repositories/reference/linux-study-clean/drivers/char/apm-emulation.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/apm-emulation.c- Extension
.c- Size
- 17488 bytes
- Lines
- 718
- 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.
- 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/module.hlinux/poll.hlinux/slab.hlinux/mutex.hlinux/proc_fs.hlinux/seq_file.hlinux/miscdevice.hlinux/apm_bios.hlinux/capability.hlinux/sched.hlinux/suspend.hlinux/apm-emulation.hlinux/freezer.hlinux/device.hlinux/kernel.hlinux/list.hlinux/init.hlinux/completion.hlinux/kthread.hlinux/delay.h
Detected Declarations
struct apm_queuestruct apm_userenum apm_suspend_statefunction queue_emptyfunction queue_get_eventfunction queue_add_eventfunction queue_eventfunction apm_readfunction apm_pollfunction apm_ioctlfunction apm_releasefunction apm_openfunction proc_apm_showfunction kapmdfunction apm_suspend_notifierfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction apm_initfunction apm_exitfunction apm_setupfunction apm_queue_eventmodule init apm_initexport apm_get_power_statusexport apm_queue_event
Annotated Snippet
static const struct file_operations apm_bios_fops = {
.owner = THIS_MODULE,
.read = apm_read,
.poll = apm_poll,
.unlocked_ioctl = apm_ioctl,
.open = apm_open,
.release = apm_release,
.llseek = noop_llseek,
};
static struct miscdevice apm_device = {
.minor = APM_MINOR_DEV,
.name = "apm_bios",
.fops = &apm_bios_fops
};
#ifdef CONFIG_PROC_FS
/*
* Arguments, with symbols from linux/apm_bios.h.
*
* 0) Linux driver version (this will change if format changes)
* 1) APM BIOS Version. Usually 1.0, 1.1 or 1.2.
* 2) APM flags from APM Installation Check (0x00):
* bit 0: APM_16_BIT_SUPPORT
* bit 1: APM_32_BIT_SUPPORT
* bit 2: APM_IDLE_SLOWS_CLOCK
* bit 3: APM_BIOS_DISABLED
* bit 4: APM_BIOS_DISENGAGED
* 3) AC line status
* 0x00: Off-line
* 0x01: On-line
* 0x02: On backup power (BIOS >= 1.1 only)
* 0xff: Unknown
* 4) Battery status
* 0x00: High
* 0x01: Low
* 0x02: Critical
* 0x03: Charging
* 0x04: Selected battery not present (BIOS >= 1.2 only)
* 0xff: Unknown
* 5) Battery flag
* bit 0: High
* bit 1: Low
* bit 2: Critical
* bit 3: Charging
* bit 7: No system battery
* 0xff: Unknown
* 6) Remaining battery life (percentage of charge):
* 0-100: valid
* -1: Unknown
* 7) Remaining battery life (time units):
* Number of remaining minutes or seconds
* -1: Unknown
* 8) min = minutes; sec = seconds
*/
static int proc_apm_show(struct seq_file *m, void *v)
{
static const char driver_version[] = "1.13"; /* no spaces */
struct apm_power_info info;
char *units;
info.ac_line_status = 0xff;
info.battery_status = 0xff;
info.battery_flag = 0xff;
info.battery_life = -1;
info.time = -1;
info.units = -1;
if (apm_get_power_status)
apm_get_power_status(&info);
switch (info.units) {
default: units = "?"; break;
case 0: units = "min"; break;
case 1: units = "sec"; break;
}
seq_printf(m, "%s 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
driver_version, APM_32_BIT_SUPPORT,
info.ac_line_status, info.battery_status,
info.battery_flag, info.battery_life,
info.time, units);
return 0;
}
#endif
static int kapmd(void *arg)
Annotation
- Immediate include surface: `linux/module.h`, `linux/poll.h`, `linux/slab.h`, `linux/mutex.h`, `linux/proc_fs.h`, `linux/seq_file.h`, `linux/miscdevice.h`, `linux/apm_bios.h`.
- Detected declarations: `struct apm_queue`, `struct apm_user`, `enum apm_suspend_state`, `function queue_empty`, `function queue_get_event`, `function queue_add_event`, `function queue_event`, `function apm_read`, `function apm_poll`, `function apm_ioctl`.
- 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.
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.