WMI Driver API
The WMI driver core supports a more modern bus-based interface for interacting with WMI devices, and an older GUID-based interface. The latter interface is considered to be deprecated, so new WMI drivers should generally avoid it since it has some issues with multiple WMI devices sharing the same GUID. The modern bus-based interface instead maps each WMI device to a struct wmi_device <wmi_device>, so it supports WMI devices sharing the same GUID. Drivers can then register a struct wmi_driver <wmi_driver> which will be bound to compatible WMI devices by the driver core.
struct wmi_device #
WMI device structure
Definition
;
Members
dev: Device associated with this WMI devicesetable: True for devices implementing the Set Control Methoddriver_override: Driver name to force a match; do not set directly, because core frees it; usedriver_set_override()to set or clear it.
Description
This represents WMI devices discovered by the WMI driver core.
to_wmi_device() #
Helper macro to cast a device to a wmi_device
Parameters
device: device struct
Description
Cast a struct device to a struct wmi_device.
struct wmi_buffer #
WMI data buffer
Definition
;
Members
length: Buffer length in bytesdata: Pointer to the buffer content
Description
This structure is used to exchange data with the WMI driver core.
struct wmi_string #
WMI string representation
Definition
;
Members
length: Size of chars in byteschars: UTF16-LE characters with optional nul termination and padding
Description
This structure is used when exchanging string data over the WMI interface.
struct wmi_driver #
WMI driver structure
Definition
;
Members
driver: Driver model structureid_table: List of WMI GUIDs supported by this driverno_notify_data: Driver supports WMI events which provide no event datano_singleton: Driver can be instantiated multiple timesprobe: Callback for device bindingremove: Callback for device unbindingshutdown: Callback for device shutdownnotify: Callback for receiving WMI events (deprecated)notify_new: Callback for receiving WMI events
Description
This represents WMI drivers which handle WMI devices. The data inside the buffer passed to the notify_new callback is guaranteed to be aligned on a 8-byte boundary.
to_wmi_driver() #
Helper macro to cast a driver to a wmi_driver
Parameters
drv: driver struct
Description
Cast a struct device_driver to a struct wmi_driver.
wmi_driver_register() #
Helper macro to register a WMI driver
Parameters
driver: wmi_driver struct
Description
Helper macro for registering a WMI driver. It automatically passes THIS_MODULE to the underlying function.
module_wmi_driver() #
Helper macro to register/unregister a WMI driver
Parameters
__wmi_driver: wmi_driver struct
Description
Helper macro for WMI drivers which do not do anything special in module
init/exit. This eliminates a lot of boilerplate. Each module may only
use this macro once, and calling it replaces module_init() and module_exit().
wmi_string_to_utf8s() #
ssize_t Convert a WMI string into a UTF8 string.
Parameters
const struct wmi_string *str: WMI string representationu8 *dst: Buffer to fill with UTF8 characterssize_t length: Length of the destination buffer
Description
Convert as WMI string into a standard UTF8 string. The conversion will stop once a NUL character is detected or when the buffer is full. Any invalid UTF16 characters will be ignored. The resulting UTF8 string will always be NUL-terminated when this function returns successfully.
Return
Length of the resulting UTF8 string or negative errno code on failure.
wmi_string_from_utf8s() #
ssize_t Convert a UTF8 string into a WMI string.
Parameters
struct wmi_string *str: WMI string representationsize_t max_chars: Maximum number of UTF16 code points to store inside the WMI stringconst u8 *src: UTF8 string to convertsize_t src_length: Length of the source string without any trailing NUL-characters
Description
Convert a UTF8 string into a WMI string. The conversion will stop when the WMI string is full. The resulting WMI string will always be NUL-terminated and have its length field set to and appropriate value when this function returns successfully.
Return
Number of UTF16 code points inside the WMI string or negative errno code on failure.
wmi_instance_count() #
int Get number of WMI object instances
Parameters
const char *guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
Description
Get the number of WMI object instances.
Return
Number of WMI object instances or negative error code.
wmidev_instance_count() #
u8 Get number of WMI object instances
Parameters
struct wmi_device *wdev: A wmi bus device from a driver
Description
Get the number of WMI object instances.
Return
Number of WMI object instances.
wmi_evaluate_method() #
acpi_status Evaluate a WMI method (deprecated)
Parameters
const char *guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49bau8 instance: Instance indexu32 method_id: Method ID to callconst struct acpi_buffer *in: Mandatory buffer containing input for the method callstruct acpi_buffer *out: Empty buffer to return the method results
Description
Call an ACPI-WMI method, the caller must free out.
Return
acpi_status signaling success or error.
wmidev_evaluate_method() #
acpi_status Evaluate a WMI method (deprecated)
Parameters
struct wmi_device *wdev: A wmi bus device from a driveru8 instance: Instance indexu32 method_id: Method ID to callconst struct acpi_buffer *in: Mandatory buffer containing input for the method callstruct acpi_buffer *out: Empty buffer to return the method results
Description
Call an ACPI-WMI method, the caller must free out.
Return
acpi_status signaling success or error.
wmidev_invoke_method() #
int Invoke a WMI method
Parameters
struct wmi_device *wdev: A wmi bus device from a driveru8 instance: Instance indexu32 method_id: Method ID to callconst struct wmi_buffer *in: Mandatory WMI buffer containing input for the method callstruct wmi_buffer *out: Optional WMI buffer to return the method results
Description
Invoke a WMI method, the caller must free the resulting data inside out. Said data is guaranteed to be aligned on a 8-byte boundary.
Return
0 on success or negative error code on failure.
wmi_query_block() #
acpi_status Return contents of a WMI block (deprecated)
Parameters
const char *guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49bau8 instance: Instance indexstruct acpi_buffer *out: Empty buffer to return the contents of the data block to
Description
Query a ACPI-WMI block, the caller must free out.
Return
ACPI object containing the content of the WMI block.
wmidev_block_query() #
union acpi_object * Return contents of a WMI block (deprectated)
Parameters
struct wmi_device *wdev: A wmi bus device from a driveru8 instance: Instance index
Description
Query an ACPI-WMI block, the caller must free the result.
Return
ACPI object containing the content of the WMI block.
wmidev_query_block() #
int Return contents of a WMI data block
Parameters
struct wmi_device *wdev: A wmi bus device from a driveru8 instance: Instance indexstruct wmi_buffer *out: WMI buffer to fill
Description
Query a WMI data block, the caller must free the resulting data inside out. Said data is guaranteed to be aligned on a 8-byte boundary.
Return
0 on success or a negative error code on failure.
wmi_set_block() #
acpi_status Write to a WMI block (deprecated)
Parameters
const char *guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49bau8 instance: Instance indexconst struct acpi_buffer *in: Buffer containing new values for the data block
Description
Write the contents of the input buffer to an ACPI-WMI data block.
Return
acpi_status signaling success or error.
wmidev_block_set() #
acpi_status Write to a WMI block (deprecated)
Parameters
struct wmi_device *wdev: A wmi bus device from a driveru8 instance: Instance indexconst struct acpi_buffer *in: Buffer containing new values for the data block
Description
Write contents of the input buffer to an ACPI-WMI data block.
Return
acpi_status signaling success or error.
wmidev_set_block() #
int Write to a WMI data block
Parameters
struct wmi_device *wdev: A wmi bus device from a driveru8 instance: Instance indexconst struct wmi_buffer *in: WMI buffer containing new values for the data block
Description
Write the content of in into a WMI data block.
Return
0 on success or negative error code on failure.
wmi_install_notify_handler() #
acpi_status Register handler for WMI events (deprecated)
Parameters
const char *guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49bawmi_notify_handler handler: Function to handle notificationsvoid *data: Data to be returned to handler when event is fired
Description
Register a handler for events sent to the ACPI-WMI mapper device.
Return
acpi_status signaling success or error.
wmi_remove_notify_handler() #
acpi_status Unregister handler for WMI events (deprecated)
Parameters
const char *guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
Description
Unregister handler for events sent to the ACPI-WMI mapper device.
Return
acpi_status signaling success or error.
wmi_has_guid() #
bool Check if a GUID is available
Parameters
const char *guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
Description
Check if a given GUID is defined by _WDG.
Return
True if GUID is available, false otherwise.
wmi_get_acpi_device_uid() #
char * Get _UID name of ACPI device that defines GUID (deprecated)
Parameters
const char *guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
Description
Find the _UID of ACPI device associated with this WMI GUID.
Return
The ACPI _UID field value or NULL if the WMI GUID was not found.
wmi_driver_unregister() #
void Unregister a WMI driver
Parameters
struct wmi_driver *driver: WMI driver to unregister
Description
Unregisters a WMI driver from the WMI bus.