drivers/macintosh/via-pmu.c
Source file repositories/reference/linux-study-clean/drivers/macintosh/via-pmu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/macintosh/via-pmu.c- Extension
.c- Size
- 64918 bytes
- Lines
- 2670
- Domain
- Driver Families
- Bucket
- drivers/macintosh
- 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/stdarg.hlinux/mutex.hlinux/types.hlinux/errno.hlinux/kernel.hlinux/delay.hlinux/sched/signal.hlinux/miscdevice.hlinux/blkdev.hlinux/pci.hlinux/slab.hlinux/poll.hlinux/adb.hlinux/pmu.hlinux/cuda.hlinux/module.hlinux/spinlock.hlinux/pm.hlinux/proc_fs.hlinux/seq_file.hlinux/init.hlinux/interrupt.hlinux/device.hlinux/syscore_ops.hlinux/freezer.hlinux/syscalls.hlinux/suspend.hlinux/cpu.hlinux/compat.hlinux/of_address.hlinux/of_irq.hlinux/uaccess.h
Detected Declarations
struct pmu_privatestruct rb_entryfunction find_via_pmufunction pmu_probefunction pmu_initfunction via_pmu_startfunction via_pmu_dev_initfunction of_machine_is_compatiblefunction init_pmufunction pmu_get_modelfunction pmu_set_server_modefunction done_battery_state_oharefunction done_battery_state_smartfunction query_battery_statefunction pmu_info_proc_showfunction pmu_irqstats_proc_showfunction pmu_battery_proc_showfunction pmu_options_proc_showfunction pmu_options_proc_openfunction pmu_options_proc_writefunction pmu_send_requestfunction __pmu_adb_autopollfunction pmu_adb_autopollfunction pmu_adb_reset_busfunction pmu_requestfunction pmu_queue_requestfunction wait_for_ackfunction send_bytefunction recv_bytefunction pmu_donefunction pmu_startfunction pmu_pollfunction pmu_poll_adbfunction pmu_wait_completefunction pmu_suspendfunction pmu_resumefunction pmu_handle_datafunction pmu_sr_intrfunction via_pmu_interruptfunction pmu_unlockfunction gpio1_interruptfunction pmu_enable_irledfunction pmu_get_timefunction pmu_set_rtc_timefunction pmu_restartfunction pmu_shutdownfunction pmu_presentfunction save_via_state
Annotated Snippet
static const struct file_operations pmu_device_fops = {
.read = pmu_read,
.write = pmu_write,
.poll = pmu_fpoll,
.unlocked_ioctl = pmu_unlocked_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_pmu_ioctl,
#endif
.open = pmu_open,
.release = pmu_release,
.llseek = noop_llseek,
};
static struct miscdevice pmu_device = {
PMU_MINOR, "pmu", &pmu_device_fops
};
static int pmu_device_init(void)
{
if (pmu_state == uninitialized)
return 0;
if (misc_register(&pmu_device) < 0)
printk(KERN_ERR "via-pmu: cannot register misc device.\n");
return 0;
}
device_initcall(pmu_device_init);
#ifdef DEBUG_SLEEP
static inline void
polled_handshake(void)
{
via2[B] &= ~TREQ; eieio();
while ((via2[B] & TACK) != 0)
;
via2[B] |= TREQ; eieio();
while ((via2[B] & TACK) == 0)
;
}
static inline void
polled_send_byte(int x)
{
via1[ACR] |= SR_OUT | SR_EXT; eieio();
via1[SR] = x; eieio();
polled_handshake();
}
static inline int
polled_recv_byte(void)
{
int x;
via1[ACR] = (via1[ACR] & ~SR_OUT) | SR_EXT; eieio();
x = via1[SR]; eieio();
polled_handshake();
x = via1[SR]; eieio();
return x;
}
int
pmu_polled_request(struct adb_request *req)
{
unsigned long flags;
int i, l, c;
req->complete = 1;
c = req->data[0];
l = pmu_data_len[c][0];
if (l >= 0 && req->nbytes != l + 1)
return -EINVAL;
local_irq_save(flags);
while (pmu_state != idle)
pmu_poll();
while ((via2[B] & TACK) == 0)
;
polled_send_byte(c);
if (l < 0) {
l = req->nbytes - 1;
polled_send_byte(l);
}
for (i = 1; i <= l; ++i)
polled_send_byte(req->data[i]);
l = pmu_data_len[c][1];
if (l < 0)
l = polled_recv_byte();
for (i = 0; i < l; ++i)
Annotation
- Immediate include surface: `linux/stdarg.h`, `linux/mutex.h`, `linux/types.h`, `linux/errno.h`, `linux/kernel.h`, `linux/delay.h`, `linux/sched/signal.h`, `linux/miscdevice.h`.
- Detected declarations: `struct pmu_private`, `struct rb_entry`, `function find_via_pmu`, `function pmu_probe`, `function pmu_init`, `function via_pmu_start`, `function via_pmu_dev_init`, `function of_machine_is_compatible`, `function init_pmu`, `function pmu_get_model`.
- Atlas domain: Driver Families / drivers/macintosh.
- 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.