drivers/platform/wmi/core.c
Source file repositories/reference/linux-study-clean/drivers/platform/wmi/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/wmi/core.c- Extension
.c- Size
- 40264 bytes
- Lines
- 1606
- 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.
- 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/acpi.hlinux/bits.hlinux/build_bug.hlinux/device.hlinux/idr.hlinux/init.hlinux/kernel.hlinux/limits.hlinux/module.hlinux/platform_device.hlinux/rwsem.hlinux/slab.hlinux/sysfs.hlinux/types.hlinux/uuid.hlinux/wmi.hlinux/fs.hinternal.h
Detected Declarations
struct guid_blockstruct wmi_blockstruct wmi_guid_count_contextfunction guid_parse_and_comparefunction get_acpi_method_namefunction wmidev_match_guidfunction wmi_device_enablefunction wmi_device_putfunction wmi_instance_countfunction wmidev_instance_countfunction wmi_evaluate_methodfunction wmidev_evaluate_methodfunction wmidev_invoke_methodfunction wmidev_invoke_procedurefunction __query_blockfunction wmi_query_blockfunction kfreefunction wmi_set_blockfunction wmidev_block_setfunction wmidev_set_blockfunction wmi_install_notify_handlerfunction wmi_remove_notify_handlerfunction wmi_has_guidfunction wmi_get_acpi_device_uidfunction modalias_showfunction guid_showfunction instance_count_showfunction expensive_showfunction notify_id_showfunction object_id_showfunction setable_showfunction wmi_dev_ueventfunction wmi_dev_releasefunction wmi_dev_matchfunction wmi_dev_disablefunction wmi_dev_probefunction wmi_dev_removefunction wmi_dev_shutdownfunction wmi_count_guidsfunction guid_countfunction wmi_dev_set_namefunction wmi_create_devicefunction wmi_add_devicefunction parse_wdgfunction wmi_get_notify_datafunction wmi_notify_driverfunction wmi_notify_devicefunction acpi_wmi_notify_handler
Annotated Snippet
static const struct bus_type wmi_bus_type;
static const struct device_type wmi_type_event;
static const struct device_type wmi_type_method;
static int wmi_device_enable(struct wmi_device *wdev, bool enable)
{
struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
char method[WMI_ACPI_METHOD_NAME_SIZE];
acpi_handle handle;
acpi_status status;
if (wblock->dev.dev.type == &wmi_type_method)
return 0;
if (wblock->dev.dev.type == &wmi_type_event) {
/*
* Windows always enables/disables WMI events, even when they are
* not marked as being expensive. We follow this behavior for
* compatibility reasons.
*/
snprintf(method, sizeof(method), "WE%02X", wblock->gblock.notify_id);
} else {
if (!(wblock->gblock.flags & ACPI_WMI_EXPENSIVE))
return 0;
get_acpi_method_name(wblock, 'C', method);
}
/*
* Not all WMI devices marked as expensive actually implement the
* necessary ACPI method. Ignore this missing ACPI method to match
* the behaviour of the Windows driver.
*/
status = acpi_get_handle(wblock->acpi_device->handle, method, &handle);
if (ACPI_FAILURE(status))
return 0;
status = acpi_execute_simple_method(handle, NULL, enable);
if (ACPI_FAILURE(status))
return -EIO;
return 0;
}
static struct wmi_device *wmi_find_device_by_guid(const char *guid_string)
{
struct device *dev;
guid_t guid;
int ret;
ret = guid_parse(guid_string, &guid);
if (ret < 0)
return ERR_PTR(ret);
dev = bus_find_device(&wmi_bus_type, NULL, &guid, wmidev_match_guid);
if (!dev)
return ERR_PTR(-ENODEV);
return to_wmi_device(dev);
}
static void wmi_device_put(struct wmi_device *wdev)
{
put_device(&wdev->dev);
}
/*
* Exported WMI functions
*/
/**
* wmi_instance_count - Get number of WMI object instances
* @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
*
* Get the number of WMI object instances.
*
* Returns: Number of WMI object instances or negative error code.
*/
int wmi_instance_count(const char *guid_string)
{
struct wmi_device *wdev;
int ret;
wdev = wmi_find_device_by_guid(guid_string);
if (IS_ERR(wdev))
return PTR_ERR(wdev);
ret = wmidev_instance_count(wdev);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/bits.h`, `linux/build_bug.h`, `linux/device.h`, `linux/idr.h`, `linux/init.h`, `linux/kernel.h`, `linux/limits.h`.
- Detected declarations: `struct guid_block`, `struct wmi_block`, `struct wmi_guid_count_context`, `function guid_parse_and_compare`, `function get_acpi_method_name`, `function wmidev_match_guid`, `function wmi_device_enable`, `function wmi_device_put`, `function wmi_instance_count`, `function wmidev_instance_count`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: pattern implementation candidate.
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.