drivers/platform/x86/apple-gmux.c
Source file repositories/reference/linux-study-clean/drivers/platform/x86/apple-gmux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/x86/apple-gmux.c- Extension
.c- Size
- 32201 bytes
- Lines
- 1040
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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/kernel.hlinux/init.hlinux/backlight.hlinux/acpi.hlinux/pnp.hlinux/apple-gmux.hlinux/slab.hlinux/delay.hlinux/pci.hlinux/vga_switcheroo.hlinux/debugfs.hacpi/video.hasm/io.h
Detected Declarations
struct apple_gmux_configstruct apple_gmux_datastruct apple_gmux_configfunction gmux_pio_read8function gmux_pio_write8function gmux_pio_read32function gmux_pio_write32function gmux_index_wait_readyfunction gmux_index_wait_completefunction gmux_index_read8function gmux_index_write8function gmux_index_read32function gmux_index_write32function gmux_mmio_waitfunction gmux_mmio_read8function gmux_mmio_write8function gmux_mmio_read32function gmux_mmio_write32function gmux_read8function gmux_write8function gmux_read32function gmux_write32function gmux_get_brightnessfunction gmux_update_statusfunction userfunction gmux_write_switch_statefunction gmux_switchtofunction gmux_switch_ddcfunction gmux_set_discrete_statefunction gmux_set_power_statefunction gmux_get_client_idfunction GMSPfunction gmux_enable_interruptsfunction gmux_interrupt_get_statusfunction gmux_clear_interruptsfunction gmux_notify_handlerfunction gmux_selected_port_data_writefunction gmux_selected_port_data_readfunction gmux_init_debugfsfunction gmux_fini_debugfsfunction gmux_suspendfunction gmux_resumefunction is_thunderboltfunction gmux_probefunction gmux_remove
Annotated Snippet
static const struct file_operations gmux_port_data_ops = {
.open = simple_open,
.write = gmux_selected_port_data_write,
.read = gmux_selected_port_data_read
};
static void gmux_init_debugfs(struct apple_gmux_data *gmux_data)
{
gmux_data->debug_dentry = debugfs_create_dir(KBUILD_MODNAME, NULL);
debugfs_create_u8("selected_port", 0644, gmux_data->debug_dentry,
&gmux_data->selected_port);
debugfs_create_file("selected_port_data", 0644, gmux_data->debug_dentry,
gmux_data, &gmux_port_data_ops);
}
static void gmux_fini_debugfs(struct apple_gmux_data *gmux_data)
{
debugfs_remove_recursive(gmux_data->debug_dentry);
}
static int gmux_suspend(struct device *dev)
{
struct pnp_dev *pnp = to_pnp_dev(dev);
struct apple_gmux_data *gmux_data = pnp_get_drvdata(pnp);
gmux_disable_interrupts(gmux_data);
return 0;
}
static int gmux_resume(struct device *dev)
{
struct pnp_dev *pnp = to_pnp_dev(dev);
struct apple_gmux_data *gmux_data = pnp_get_drvdata(pnp);
gmux_enable_interrupts(gmux_data);
gmux_write_switch_state(gmux_data);
if (gmux_data->power_state == VGA_SWITCHEROO_OFF)
gmux_set_discrete_state(gmux_data, gmux_data->power_state);
return 0;
}
static int is_thunderbolt(struct device *dev, void *data)
{
return to_pci_dev(dev)->is_thunderbolt;
}
static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
{
struct apple_gmux_data *gmux_data;
struct resource *res;
struct backlight_properties props;
struct backlight_device *bdev = NULL;
u8 ver_major, ver_minor, ver_release;
bool register_bdev = true;
int ret = -ENXIO;
acpi_status status;
unsigned long long gpe;
enum apple_gmux_type type;
u32 version;
if (apple_gmux_data)
return -EBUSY;
if (!apple_gmux_detect(pnp, &type)) {
pr_info("gmux device not present\n");
return -ENODEV;
}
gmux_data = kzalloc_obj(*gmux_data);
if (!gmux_data)
return -ENOMEM;
pnp_set_drvdata(pnp, gmux_data);
switch (type) {
case APPLE_GMUX_TYPE_MMIO:
gmux_data->config = &apple_gmux_mmio;
mutex_init(&gmux_data->index_lock);
res = pnp_get_resource(pnp, IORESOURCE_MEM, 0);
gmux_data->iostart = res->start;
/* Although the ACPI table only allocates 8 bytes, we need 16. */
gmux_data->iolen = 16;
if (!request_mem_region(gmux_data->iostart, gmux_data->iolen,
"Apple gmux")) {
pr_err("gmux I/O already in use\n");
goto err_free;
}
gmux_data->iomem_base = ioremap(gmux_data->iostart, gmux_data->iolen);
if (!gmux_data->iomem_base) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/init.h`, `linux/backlight.h`, `linux/acpi.h`, `linux/pnp.h`, `linux/apple-gmux.h`, `linux/slab.h`.
- Detected declarations: `struct apple_gmux_config`, `struct apple_gmux_data`, `struct apple_gmux_config`, `function gmux_pio_read8`, `function gmux_pio_write8`, `function gmux_pio_read32`, `function gmux_pio_write32`, `function gmux_index_wait_ready`, `function gmux_index_wait_complete`, `function gmux_index_read8`.
- Atlas domain: Driver Families / drivers/platform.
- 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.