2023-04-24 22:34:58

by Armin Wolf

[permalink] [raw]
Subject: [PATCH v2 0/4] platform/x86: wmi: Add subsystem documentation

Currently, there is no recent documentation available for writing WMI
drivers using the modern bus-based interface. This leads to developers
using the deprecated GUID-based interface when developing new drivers,
causing issues with notification handling when multiple WMI devices sharing
the same notification ID are present. There is also no way for WMI
drivers to add device specific documentation at the moment.
Add documentation for the WMI subsystem to solve those issues. The
device specific documentation currently onyl include documentation for
the wmi-bmof driver, but more is expected to follow.
---
Changes in v2:
- spelling fixes
- tell readers that MOF means Managed Object Format
- 80-cloumn limit

Armin Wolf (4):
platform/x86: wmi: Add kernel doc comments
platform/x86: wmi: Mark GUID-based WMI interface as deprecated
platform/x86: wmi: Add documentation
platform/x86: wmi: Add device specific documentation

.../ABI/stable/sysfs-platform-wmi-bmof | 7 ++
Documentation/driver-api/index.rst | 1 +
Documentation/driver-api/wmi.rst | 21 ++++
Documentation/subsystem-apis.rst | 1 +
Documentation/wmi/acpi-interface.rst | 96 +++++++++++++++++++
Documentation/wmi/devices/index.rst | 22 +++++
Documentation/wmi/devices/wmi-bmof.rst | 25 +++++
Documentation/wmi/index.rst | 19 ++++
MAINTAINERS | 9 ++
drivers/platform/x86/Kconfig | 4 +-
drivers/platform/x86/wmi.c | 63 +++++++++---
include/linux/wmi.h | 41 +++++++-
12 files changed, 289 insertions(+), 20 deletions(-)
create mode 100644 Documentation/ABI/stable/sysfs-platform-wmi-bmof
create mode 100644 Documentation/driver-api/wmi.rst
create mode 100644 Documentation/wmi/acpi-interface.rst
create mode 100644 Documentation/wmi/devices/index.rst
create mode 100644 Documentation/wmi/devices/wmi-bmof.rst
create mode 100644 Documentation/wmi/index.rst

--
2.30.2


2023-04-24 22:35:00

by Armin Wolf

[permalink] [raw]
Subject: [PATCH v2 1/4] platform/x86: wmi: Add kernel doc comments

Add kernel doc comments useful for documenting the functions/structs
used to interact with the WMI driver core.

Signed-off-by: Armin Wolf <[email protected]>
---
drivers/platform/x86/wmi.c | 51 +++++++++++++++++++++++++++++++-------
include/linux/wmi.h | 41 +++++++++++++++++++++++++++---
2 files changed, 80 insertions(+), 12 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index d81319a502ef..99af2cc03b0f 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -248,7 +248,9 @@ static acpi_status get_event_data(const struct wmi_block *wblock, struct acpi_bu
* @wdev: A wmi bus device from a driver
* @length: Required buffer size
*
- * Allocates memory needed for buffer, stores the buffer size in that memory
+ * Allocates memory needed for buffer, stores the buffer size in that memory.
+ *
+ * Return: 0 on success or a negative error code for failure.
*/
int set_required_buffer_size(struct wmi_device *wdev, u64 length)
{
@@ -269,7 +271,9 @@ EXPORT_SYMBOL_GPL(set_required_buffer_size);
* @in: Buffer containing input for the method call
* @out: Empty buffer to return the method results
*
- * Call an ACPI-WMI method
+ * Call an ACPI-WMI method, the caller must free @out.
+ *
+ * Return: acpi_status signaling success or error.
*/
acpi_status wmi_evaluate_method(const char *guid_string, u8 instance, u32 method_id,
const struct acpi_buffer *in, struct acpi_buffer *out)
@@ -294,7 +298,9 @@ EXPORT_SYMBOL_GPL(wmi_evaluate_method);
* @in: Buffer containing input for the method call
* @out: Empty buffer to return the method results
*
- * Call an ACPI-WMI method
+ * Call an ACPI-WMI method, the caller must free @out.
+ *
+ * Return: acpi_status signaling success or error.
*/
acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance, u32 method_id,
const struct acpi_buffer *in, struct acpi_buffer *out)
@@ -411,7 +417,9 @@ static acpi_status __query_block(struct wmi_block *wblock, u8 instance,
* @instance: Instance index
* @out: Empty buffer to return the contents of the data block to
*
- * Return the contents of an ACPI-WMI data block to a buffer
+ * Query a ACPI-WMI block, the caller must free @out.
+ *
+ * Return: ACPI object containing the content of the WMI block.
*/
acpi_status wmi_query_block(const char *guid_string, u8 instance,
struct acpi_buffer *out)
@@ -427,6 +435,15 @@ acpi_status wmi_query_block(const char *guid_string, u8 instance,
}
EXPORT_SYMBOL_GPL(wmi_query_block);

+/**
+ * wmidev_block_query - Return contents of a WMI block
+ * @wdev: A wmi bus device from a driver
+ * @instance: Instance index
+ *
+ * Query an ACPI-WMI block, the caller must free the result.
+ *
+ * Return: ACPI object containing the content of the WMI block.
+ */
union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance)
{
struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -445,7 +462,9 @@ EXPORT_SYMBOL_GPL(wmidev_block_query);
* @instance: Instance index
* @in: Buffer containing new values for the data block
*
- * Write the contents of the input buffer to an ACPI-WMI data block
+ * Write the contents of the input buffer to an ACPI-WMI data block.
+ *
+ * Return: acpi_status signaling success or error.
*/
acpi_status wmi_set_block(const char *guid_string, u8 instance,
const struct acpi_buffer *in)
@@ -555,6 +574,8 @@ static void wmi_notify_debug(u32 value, void *context)
* @data: Data to be returned to handler when event is fired
*
* Register a handler for events sent to the ACPI-WMI mapper device.
+ *
+ * Return: acpi_status signaling success or error.
*/
acpi_status wmi_install_notify_handler(const char *guid,
wmi_notify_handler handler,
@@ -597,6 +618,8 @@ EXPORT_SYMBOL_GPL(wmi_install_notify_handler);
* @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
*
* Unregister handler for events sent to the ACPI-WMI mapper device.
+ *
+ * Return: acpi_status signaling success or error.
*/
acpi_status wmi_remove_notify_handler(const char *guid)
{
@@ -641,9 +664,11 @@ EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);
* wmi_get_event_data - Get WMI data associated with an event
*
* @event: Event to find
- * @out: Buffer to hold event data. out->pointer should be freed with kfree()
+ * @out: Buffer to hold event data
+ *
+ * Get extra data associated with an WMI event, the caller needs to free @out.
*
- * Returns extra data associated with an event in WMI.
+ * Return: acpi_status signaling success or error.
*/
acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out)
{
@@ -664,7 +689,9 @@ EXPORT_SYMBOL_GPL(wmi_get_event_data);
* wmi_has_guid - Check if a GUID is available
* @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
*
- * Check if a given GUID is defined by _WDG
+ * Check if a given GUID is defined by _WDG.
+ *
+ * Return: True if GUID is available, false otherwise.
*/
bool wmi_has_guid(const char *guid_string)
{
@@ -678,7 +705,7 @@ EXPORT_SYMBOL_GPL(wmi_has_guid);
*
* 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
+ * Return: The ACPI _UID field value or NULL if the WMI GUID was not found.
*/
char *wmi_get_acpi_device_uid(const char *guid_string)
{
@@ -1454,6 +1481,12 @@ int __must_check __wmi_driver_register(struct wmi_driver *driver,
}
EXPORT_SYMBOL(__wmi_driver_register);

+/**
+ * wmi_driver_unregister() - Unregister a WMI driver
+ * @driver: WMI driver to unregister
+ *
+ * Unregisters a WMI driver from the WMI bus.
+ */
void wmi_driver_unregister(struct wmi_driver *driver)
{
driver_unregister(&driver->driver);
diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index b88d7b58e61e..c1a3bd4e4838 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -13,25 +13,44 @@
#include <linux/mod_devicetable.h>
#include <uapi/linux/wmi.h>

+/**
+ * struct wmi_device - WMI device structure
+ * @dev: Device associated with this WMI device
+ * @setable: True for devices implementing the Set Control Method
+ *
+ * This represents WMI devices discovered by the WMI driver core.
+ */
struct wmi_device {
struct device dev;

- /* True for data blocks implementing the Set Control Method */
+ /* private: used by the WMI driver core */
bool setable;
};

-/* evaluate the ACPI method associated with this device */
extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev,
u8 instance, u32 method_id,
const struct acpi_buffer *in,
struct acpi_buffer *out);

-/* Caller must kfree the result. */
extern union acpi_object *wmidev_block_query(struct wmi_device *wdev,
u8 instance);

extern int set_required_buffer_size(struct wmi_device *wdev, u64 length);

+/**
+ * struct wmi_driver - WMI driver structure
+ * @driver: Driver model structure
+ * @id_table: List of WMI GUIDs supported by this driver
+ * @no_notify_data: WMI events provide no event data
+ * @probe: Callback for device binding
+ * @remove: Callback for device unbinding
+ * @notify: Callback for receiving WMI events
+ * @filter_callback: Callback for filtering device IOCTLs
+ *
+ * This represents WMI drivers which handle WMI devices.
+ * @filter_callback is only necessary for drivers which
+ * want to set up a WMI IOCTL interface.
+ */
struct wmi_driver {
struct device_driver driver;
const struct wmi_device_id *id_table;
@@ -47,8 +66,24 @@ struct wmi_driver {
extern int __must_check __wmi_driver_register(struct wmi_driver *driver,
struct module *owner);
extern void wmi_driver_unregister(struct wmi_driver *driver);
+
+/**
+ * wmi_driver_register() - Helper macro to register a WMI driver
+ * @driver: wmi_driver struct
+ *
+ * Helper macro for registering a WMI driver. It automatically passes
+ * THIS_MODULE to the underlying function.
+ */
#define wmi_driver_register(driver) __wmi_driver_register((driver), THIS_MODULE)

+/**
+ * module_wmi_driver() - Helper macro to register/unregister a WMI driver
+ * @__wmi_driver: wmi_driver struct
+ *
+ * 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().
+ */
#define module_wmi_driver(__wmi_driver) \
module_driver(__wmi_driver, wmi_driver_register, \
wmi_driver_unregister)
--
2.30.2

2023-04-24 22:35:18

by Armin Wolf

[permalink] [raw]
Subject: [PATCH v2 3/4] platform/x86: wmi: Add documentation

Add documentation for the WMI subsystem. The documentation describes
both the ACPI WMI interface and the driver API for interacting with
the WMI driver core. The information regarding the ACPI interface
was retrieved from the Ubuntu kernel references and the Windows driver
samples available on GitHub. The documentation is supposed to help
driver developers writing WMI drivers, as many modern machines designed
to run Windows provide an ACPI WMI interface.

Signed-off-by: Armin Wolf <[email protected]>
---
Documentation/driver-api/index.rst | 1 +
Documentation/driver-api/wmi.rst | 21 ++++++
Documentation/subsystem-apis.rst | 1 +
Documentation/wmi/acpi-interface.rst | 96 ++++++++++++++++++++++++++++
Documentation/wmi/index.rst | 18 ++++++
MAINTAINERS | 2 +
6 files changed, 139 insertions(+)
create mode 100644 Documentation/driver-api/wmi.rst
create mode 100644 Documentation/wmi/acpi-interface.rst
create mode 100644 Documentation/wmi/index.rst

diff --git a/Documentation/driver-api/index.rst b/Documentation/driver-api/index.rst
index ff9aa1afdc62..1e16a40da3ba 100644
--- a/Documentation/driver-api/index.rst
+++ b/Documentation/driver-api/index.rst
@@ -113,6 +113,7 @@ available subsections can be seen below.
xillybus
zorro
hte/index
+ wmi

.. only:: subproject and html

diff --git a/Documentation/driver-api/wmi.rst b/Documentation/driver-api/wmi.rst
new file mode 100644
index 000000000000..6ca58c8249e5
--- /dev/null
+++ b/Documentation/driver-api/wmi.rst
@@ -0,0 +1,21 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+==============
+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 and events sharing the same GUIDs
+and/or notification IDs. The modern bus-based interface instead maps each
+WMI device to a :c:type:`struct wmi_device <wmi_device>`, so it supports
+WMI devices sharing GUIDs and/or notification IDs. Drivers can then register
+a :c:type:`struct wmi_driver <wmi_driver>`, which will be bound to compatible
+WMI devices by the driver core.
+
+.. kernel-doc:: include/linux/wmi.h
+ :internal:
+
+.. kernel-doc:: drivers/platform/x86/wmi.c
+ :export:
diff --git a/Documentation/subsystem-apis.rst b/Documentation/subsystem-apis.rst
index b51f38527e14..69f5e4d53bad 100644
--- a/Documentation/subsystem-apis.rst
+++ b/Documentation/subsystem-apis.rst
@@ -57,3 +57,4 @@ needed).
scheduler/index
mhi/index
peci/index
+ wmi/index
diff --git a/Documentation/wmi/acpi-interface.rst b/Documentation/wmi/acpi-interface.rst
new file mode 100644
index 000000000000..d31af0ed9c08
--- /dev/null
+++ b/Documentation/wmi/acpi-interface.rst
@@ -0,0 +1,96 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+==================
+ACPI WMI interface
+==================
+
+The ACPI WMI interface is a proprietary extension of the ACPI specification made
+by Microsoft to allow hardware vendors to embed WMI (Windows Management Instrumentation)
+objects inside their ACPI firmware. Typical functions implemented over ACPI WMI
+are hotkey events on modern notebooks and configuration of BIOS options.
+
+PNP0C14 ACPI device
+-------------------
+
+Discovery of WMI objects is handled by defining ACPI devices with a PNP ID
+of ``PNP0C14``. These devices will contain a set of ACPI buffers and methods
+used for mapping and execution of WMI methods and/or queries. If there exist
+multiple of such devices, then each device is required to have a
+unique ACPI UID.
+
+_WDG buffer
+-----------
+
+The ``_WDG`` buffer is used to discover WMI objects and is required to be
+static. Its internal structure consists of data blocks with a size of 20 bytes,
+containing the following data:
+
+======= =============== =====================================================
+Offset Size (in bytes) Content
+======= =============== =====================================================
+0x00 16 128 bit Variant 2 object GUID.
+0x10 2 2 character method ID or single byte notification ID.
+0x12 1 Object instance count.
+0x13 1 Object flags.
+======= =============== =====================================================
+
+The WMI object flags control whether the method or notification ID is used:
+
+- 0x1: Data block usage is expensive and must be explicitly enabled/disabled.
+- 0x2: Data block contains WMI methods.
+- 0x4: Data block contains ASCIZ string.
+- 0x8: Data block describes a WMI event, use notification ID instead
+ of method ID.
+
+Each WMI object GUID can appear multiple times inside a system.
+The method/notification ID is used to construct the ACPI method names used for
+interacting with the WMI object.
+
+WQxx ACPI methods
+-----------------
+
+If a data block does not contain WMI methods, then its content can be retrieved
+by this required ACPI method. The last two characters of the ACPI method name
+are the method ID of the data block to query. Their single parameter is an
+integer describing the instance which should be queried. This parameter can be
+omitted if the data block contains only a single instance.
+
+WSxx ACPI methods
+-----------------
+
+Similar to the ``WQxx`` ACPI methods, except that it is optional and takes an
+additional buffer as its second argument. The instance argument also cannot
+be omitted.
+
+WMxx ACPI methods
+-----------------
+
+Used for executing WMI methods associated with a data block. The last two
+characters of the ACPI method name are the method ID of the data block
+containing the WMI methods. Their first parameter is a integer describing the
+instance which methods should be executed. The second parameter is an integer
+describing the WMI method ID to execute, and the third parameter is a buffer
+containing the WMI method parameters. If the data block is marked as containing
+an ASCIZ string, then this buffer should contain an ASCIZ string. The ACPI
+method will return the result of the executed WMI method.
+
+WExx ACPI methods
+-----------------
+
+Used for optionally enabling/disabling WMI events, the last two characters of
+the ACPI method are the notification ID of the data block describing the WMI
+event as hexadecimal value. Their first parameter is an integer with a value
+of 0 if the WMI event should be disabled, other values will enable
+the WMI event.
+
+WCxx ACPI methods
+-----------------
+Similar to the ``WExx`` ACPI methods, except that it controls data collection
+instead of events and thus the last two characters of the ACPI method name are
+the method ID of the data block to enable/disable.
+
+_WED ACPI method
+----------------
+
+Used to retrieve additional WMI event data, its single parameter is a integer
+holding the notification ID of the event.
diff --git a/Documentation/wmi/index.rst b/Documentation/wmi/index.rst
new file mode 100644
index 000000000000..b29933a86380
--- /dev/null
+++ b/Documentation/wmi/index.rst
@@ -0,0 +1,18 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+=============
+WMI Subsystem
+=============
+
+.. toctree::
+ :maxdepth: 1
+
+ acpi-interface
+
+.. only:: subproject and html
+
+
+ Indices
+ =======
+
+ * :ref:`genindex`
diff --git a/MAINTAINERS b/MAINTAINERS
index 0c9011f5fc17..979d37176429 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -449,6 +449,8 @@ F: include/linux/acpi_viot.h
ACPI WMI DRIVER
L: [email protected]
S: Orphan
+F: Documentation/driver-api/wmi.rst
+F: Documentation/wmi/
F: drivers/platform/x86/wmi.c
F: include/uapi/linux/wmi.h

--
2.30.2

2023-04-24 22:35:32

by Armin Wolf

[permalink] [raw]
Subject: [PATCH v2 4/4] platform/x86: wmi: Add device specific documentation

Add a place for device-specific documentation of WMI drivers.
The first entry is documentation for the wmi-bmof driver, with
additional documentation being expected to follow.

Signed-off-by: Armin Wolf <[email protected]>
---
.../ABI/stable/sysfs-platform-wmi-bmof | 7 ++++++
Documentation/wmi/devices/index.rst | 22 ++++++++++++++++
Documentation/wmi/devices/wmi-bmof.rst | 25 +++++++++++++++++++
Documentation/wmi/index.rst | 1 +
MAINTAINERS | 7 ++++++
drivers/platform/x86/Kconfig | 4 +--
6 files changed, 64 insertions(+), 2 deletions(-)
create mode 100644 Documentation/ABI/stable/sysfs-platform-wmi-bmof
create mode 100644 Documentation/wmi/devices/index.rst
create mode 100644 Documentation/wmi/devices/wmi-bmof.rst

diff --git a/Documentation/ABI/stable/sysfs-platform-wmi-bmof b/Documentation/ABI/stable/sysfs-platform-wmi-bmof
new file mode 100644
index 000000000000..a786504b6027
--- /dev/null
+++ b/Documentation/ABI/stable/sysfs-platform-wmi-bmof
@@ -0,0 +1,7 @@
+What: /sys/bus/wmi/devices/05901221-D566-11D1-B2F0-00A0C9062910[-X]/bmof
+Date: Jun 2017
+KernelVersion: 4.13
+Description:
+ Binary MOF metadata used to decribe the details of available ACPI WMI interfaces.
+
+ See Documentation/wmi/devices/wmi-bmof.rst for details.
diff --git a/Documentation/wmi/devices/index.rst b/Documentation/wmi/devices/index.rst
new file mode 100644
index 000000000000..c08735a9d7df
--- /dev/null
+++ b/Documentation/wmi/devices/index.rst
@@ -0,0 +1,22 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+=============================
+Driver-specific Documentation
+=============================
+
+This section provides information about various devices supported by
+the Linux kernel, their protocols and driver details.
+
+.. toctree::
+ :maxdepth: 1
+ :numbered:
+ :glob:
+
+ *
+
+.. only:: subproject and html
+
+ Indices
+ =======
+
+ * :ref:`genindex`
diff --git a/Documentation/wmi/devices/wmi-bmof.rst b/Documentation/wmi/devices/wmi-bmof.rst
new file mode 100644
index 000000000000..ca1ee9a29be3
--- /dev/null
+++ b/Documentation/wmi/devices/wmi-bmof.rst
@@ -0,0 +1,25 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+==============================
+WMI embedded Binary MOF driver
+==============================
+
+Introduction
+============
+
+Many machines embed WMI Binary MOF (Managed Object Format) metadata used to
+describe the details of their ACPI WMI interfaces. The data can be decoded
+with tools like `bmfdec <https://github.com/pali/bmfdec>`_ to obtain a
+human readable WMI interface description, which is useful for developing
+new WMI drivers.
+
+The Binary MOF data can be retrieved from the ``bmof`` sysfs attribute of the
+associated WMI device. Please note that multiple WMI devices containing Binary
+MOF data can exist on a given system.
+
+WMI interface
+=============
+
+The Binary MOF WMI device is identified by the WMI GUID ``05901221-D566-11D1-B2F0-00A0C9062910``.
+The Binary MOF can be obtained by doing a WMI data block query. The result is
+then returned as an ACPI buffer with a variable size.
diff --git a/Documentation/wmi/index.rst b/Documentation/wmi/index.rst
index b29933a86380..537cff188e14 100644
--- a/Documentation/wmi/index.rst
+++ b/Documentation/wmi/index.rst
@@ -8,6 +8,7 @@ WMI Subsystem
:maxdepth: 1

acpi-interface
+ devices/index

.. only:: subproject and html

diff --git a/MAINTAINERS b/MAINTAINERS
index 979d37176429..4d5b1f6d77f6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -22556,6 +22556,13 @@ L: [email protected]
S: Odd fixes
F: drivers/net/wireless/wl3501*

+WMI BINARY MOF DRIVER
+L: [email protected]
+S: Orphan
+F: Documentation/ABI/stable/sysfs-platform-wmi-bmof
+F: Documentation/wmi/devices/wmi-bmof.rst
+F: drivers/platform/x86/wmi-bmof.c
+
WOLFSON MICROELECTRONICS DRIVERS
L: [email protected]
S: Supported
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 22052031c719..3d5dd9e997a6 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -43,8 +43,8 @@ config WMI_BMOF
default ACPI_WMI
help
Say Y here if you want to be able to read a firmware-embedded
- WMI Binary MOF data. Using this requires userspace tools and may be
- rather tedious.
+ WMI Binary MOF (Managed Object Format) data. Using this requires
+ userspace tools and may be rather tedious.

To compile this driver as a module, choose M here: the module will
be called wmi-bmof.
--
2.30.2

2023-04-24 22:35:45

by Armin Wolf

[permalink] [raw]
Subject: [PATCH v2 2/4] platform/x86: wmi: Mark GUID-based WMI interface as deprecated

The WMI driver core supports a more mordern bus-based interface for
interacting with WMI devices. The older GUID-based interface depends
on each WMI GUID and notification id being unique on a given system,
which turned out is not the case.
Mark the older interface as deprecated since new WMI drivers should
use the bus-based interface to avoid this issues.

Signed-off-by: Armin Wolf <[email protected]>
---
drivers/platform/x86/wmi.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 99af2cc03b0f..c226dd4163a1 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -264,7 +264,7 @@ int set_required_buffer_size(struct wmi_device *wdev, u64 length)
EXPORT_SYMBOL_GPL(set_required_buffer_size);

/**
- * wmi_evaluate_method - Evaluate a WMI method
+ * wmi_evaluate_method - Evaluate a WMI method (deprecated)
* @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
* @instance: Instance index
* @method_id: Method ID to call
@@ -457,7 +457,7 @@ union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance)
EXPORT_SYMBOL_GPL(wmidev_block_query);

/**
- * wmi_set_block - Write to a WMI block
+ * wmi_set_block - Write to a WMI block (deprecated)
* @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
* @instance: Instance index
* @in: Buffer containing new values for the data block
@@ -568,7 +568,7 @@ static void wmi_notify_debug(u32 value, void *context)
}

/**
- * wmi_install_notify_handler - Register handler for WMI events
+ * wmi_install_notify_handler - Register handler for WMI events (deprecated)
* @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
* @handler: Function to handle notifications
* @data: Data to be returned to handler when event is fired
@@ -614,7 +614,7 @@ acpi_status wmi_install_notify_handler(const char *guid,
EXPORT_SYMBOL_GPL(wmi_install_notify_handler);

/**
- * wmi_remove_notify_handler - Unregister handler for WMI events
+ * wmi_remove_notify_handler - Unregister handler for WMI events (deprecated)
* @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
*
* Unregister handler for events sent to the ACPI-WMI mapper device.
@@ -661,7 +661,7 @@ acpi_status wmi_remove_notify_handler(const char *guid)
EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);

/**
- * wmi_get_event_data - Get WMI data associated with an event
+ * wmi_get_event_data - Get WMI data associated with an event (deprecated)
*
* @event: Event to find
* @out: Buffer to hold event data
@@ -700,7 +700,7 @@ bool wmi_has_guid(const char *guid_string)
EXPORT_SYMBOL_GPL(wmi_has_guid);

/**
- * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID
+ * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID (deprecated)
* @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
*
* Find the _UID of ACPI device associated with this WMI GUID.
--
2.30.2

2023-04-25 03:09:25

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] platform/x86: wmi: Add documentation

Hi--

On 4/24/23 15:29, Armin Wolf wrote:
> Add documentation for the WMI subsystem. The documentation describes
> both the ACPI WMI interface and the driver API for interacting with
> the WMI driver core. The information regarding the ACPI interface
> was retrieved from the Ubuntu kernel references and the Windows driver
> samples available on GitHub. The documentation is supposed to help
> driver developers writing WMI drivers, as many modern machines designed
> to run Windows provide an ACPI WMI interface.
>
> Signed-off-by: Armin Wolf <[email protected]>
> ---
> Documentation/driver-api/index.rst | 1 +
> Documentation/driver-api/wmi.rst | 21 ++++++
> Documentation/subsystem-apis.rst | 1 +
> Documentation/wmi/acpi-interface.rst | 96 ++++++++++++++++++++++++++++
> Documentation/wmi/index.rst | 18 ++++++
> MAINTAINERS | 2 +
> 6 files changed, 139 insertions(+)
> create mode 100644 Documentation/driver-api/wmi.rst
> create mode 100644 Documentation/wmi/acpi-interface.rst
> create mode 100644 Documentation/wmi/index.rst
>

> diff --git a/Documentation/driver-api/wmi.rst b/Documentation/driver-api/wmi.rst
> new file mode 100644
> index 000000000000..6ca58c8249e5
> --- /dev/null
> +++ b/Documentation/driver-api/wmi.rst
> @@ -0,0 +1,21 @@
> +.. SPDX-License-Identifier: GPL-2.0-or-later
> +
> +==============
> +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 and events sharing the same GUIDs
> +and/or notification IDs. The modern bus-based interface instead maps each
> +WMI device to a :c:type:`struct wmi_device <wmi_device>`, so it supports
> +WMI devices sharing GUIDs and/or notification IDs. Drivers can then register
> +a :c:type:`struct wmi_driver <wmi_driver>`, which will be bound to compatible
> +WMI devices by the driver core.
> +
> +.. kernel-doc:: include/linux/wmi.h
> + :internal:

There are no kernel-doc comments in include/linux/wmi.h, so this
causes a kernel-doc warning:

../include/linux/wmi.h:1: warning: no structured comments found

Otherwise this all looks good.


Tested-by: Randy Dunlap <[email protected]>
Acked-by: Randy Dunlap <[email protected]>

thanks.
--
~Randy

2023-04-25 03:09:43

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] platform/x86: wmi: Add kernel doc comments

Hi--

On 4/24/23 15:29, Armin Wolf wrote:
> Add kernel doc comments useful for documenting the functions/structs
> used to interact with the WMI driver core.
>
> Signed-off-by: Armin Wolf <[email protected]>
> ---
> drivers/platform/x86/wmi.c | 51 +++++++++++++++++++++++++++++++-------
> include/linux/wmi.h | 41 +++++++++++++++++++++++++++---
> 2 files changed, 80 insertions(+), 12 deletions(-)
>

Tested-by: Randy Dunlap <[email protected]>
Acked-by: Randy Dunlap <[email protected]>

thanks.
--
~Randy

2023-04-25 03:10:13

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v2 4/4] platform/x86: wmi: Add device specific documentation



On 4/24/23 15:29, Armin Wolf wrote:
> Add a place for device-specific documentation of WMI drivers.
> The first entry is documentation for the wmi-bmof driver, with
> additional documentation being expected to follow.
>
> Signed-off-by: Armin Wolf <[email protected]>
> ---
> .../ABI/stable/sysfs-platform-wmi-bmof | 7 ++++++
> Documentation/wmi/devices/index.rst | 22 ++++++++++++++++
> Documentation/wmi/devices/wmi-bmof.rst | 25 +++++++++++++++++++
> Documentation/wmi/index.rst | 1 +
> MAINTAINERS | 7 ++++++
> drivers/platform/x86/Kconfig | 4 +--
> 6 files changed, 64 insertions(+), 2 deletions(-)
> create mode 100644 Documentation/ABI/stable/sysfs-platform-wmi-bmof
> create mode 100644 Documentation/wmi/devices/index.rst
> create mode 100644 Documentation/wmi/devices/wmi-bmof.rst

Tested-by: Randy Dunlap <[email protected]>
Acked-by: Randy Dunlap <[email protected]>

thank.
--
~Randy

2023-04-25 03:10:29

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] platform/x86: wmi: Mark GUID-based WMI interface as deprecated



On 4/24/23 15:29, Armin Wolf wrote:
> The WMI driver core supports a more mordern bus-based interface for
> interacting with WMI devices. The older GUID-based interface depends
> on each WMI GUID and notification id being unique on a given system,
> which turned out is not the case.
> Mark the older interface as deprecated since new WMI drivers should
> use the bus-based interface to avoid this issues.
>
> Signed-off-by: Armin Wolf <[email protected]>
> ---
> drivers/platform/x86/wmi.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)

Tested-by: Randy Dunlap <[email protected]>
Acked-by: Randy Dunlap <[email protected]>

thanks.
--
~Randy

2023-04-25 16:42:28

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] platform/x86: wmi: Add documentation

Hi All,

Armin thank you very mich for the WMI documentation work,
this is much appreciated!

On 4/25/23 05:07, Randy Dunlap wrote:
> Hi--
>
> On 4/24/23 15:29, Armin Wolf wrote:
>> Add documentation for the WMI subsystem. The documentation describes
>> both the ACPI WMI interface and the driver API for interacting with
>> the WMI driver core. The information regarding the ACPI interface
>> was retrieved from the Ubuntu kernel references and the Windows driver
>> samples available on GitHub. The documentation is supposed to help
>> driver developers writing WMI drivers, as many modern machines designed
>> to run Windows provide an ACPI WMI interface.
>>
>> Signed-off-by: Armin Wolf <[email protected]>
>> ---
>> Documentation/driver-api/index.rst | 1 +
>> Documentation/driver-api/wmi.rst | 21 ++++++
>> Documentation/subsystem-apis.rst | 1 +
>> Documentation/wmi/acpi-interface.rst | 96 ++++++++++++++++++++++++++++
>> Documentation/wmi/index.rst | 18 ++++++
>> MAINTAINERS | 2 +
>> 6 files changed, 139 insertions(+)
>> create mode 100644 Documentation/driver-api/wmi.rst
>> create mode 100644 Documentation/wmi/acpi-interface.rst
>> create mode 100644 Documentation/wmi/index.rst
>>
>
>> diff --git a/Documentation/driver-api/wmi.rst b/Documentation/driver-api/wmi.rst
>> new file mode 100644
>> index 000000000000..6ca58c8249e5
>> --- /dev/null
>> +++ b/Documentation/driver-api/wmi.rst
>> @@ -0,0 +1,21 @@
>> +.. SPDX-License-Identifier: GPL-2.0-or-later
>> +
>> +==============
>> +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 and events sharing the same GUIDs
>> +and/or notification IDs. The modern bus-based interface instead maps each
>> +WMI device to a :c:type:`struct wmi_device <wmi_device>`, so it supports
>> +WMI devices sharing GUIDs and/or notification IDs. Drivers can then register
>> +a :c:type:`struct wmi_driver <wmi_driver>`, which will be bound to compatible
>> +WMI devices by the driver core.
>> +
>> +.. kernel-doc:: include/linux/wmi.h
>> + :internal:
>
> There are no kernel-doc comments in include/linux/wmi.h, so this
> causes a kernel-doc warning:
>
> ../include/linux/wmi.h:1: warning: no structured comments found
>
> Otherwise this all looks good.

So what is the plan here, is there something we can do to fix this
new warning and should I expect a v3? Or shall I merge this as is ?

Regards,

Hans





>
>
> Tested-by: Randy Dunlap <[email protected]>
> Acked-by: Randy Dunlap <[email protected]>
>
> thanks.

2023-04-25 20:31:03

by Armin Wolf

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] platform/x86: wmi: Add documentation

Am 25.04.23 um 18:30 schrieb Hans de Goede:

> Hi All,
>
> Armin thank you very mich for the WMI documentation work,
> this is much appreciated!
>
> On 4/25/23 05:07, Randy Dunlap wrote:
>> Hi--
>>
>> On 4/24/23 15:29, Armin Wolf wrote:
>>> Add documentation for the WMI subsystem. The documentation describes
>>> both the ACPI WMI interface and the driver API for interacting with
>>> the WMI driver core. The information regarding the ACPI interface
>>> was retrieved from the Ubuntu kernel references and the Windows driver
>>> samples available on GitHub. The documentation is supposed to help
>>> driver developers writing WMI drivers, as many modern machines designed
>>> to run Windows provide an ACPI WMI interface.
>>>
>>> Signed-off-by: Armin Wolf <[email protected]>
>>> ---
>>> Documentation/driver-api/index.rst | 1 +
>>> Documentation/driver-api/wmi.rst | 21 ++++++
>>> Documentation/subsystem-apis.rst | 1 +
>>> Documentation/wmi/acpi-interface.rst | 96 ++++++++++++++++++++++++++++
>>> Documentation/wmi/index.rst | 18 ++++++
>>> MAINTAINERS | 2 +
>>> 6 files changed, 139 insertions(+)
>>> create mode 100644 Documentation/driver-api/wmi.rst
>>> create mode 100644 Documentation/wmi/acpi-interface.rst
>>> create mode 100644 Documentation/wmi/index.rst
>>>
>>> diff --git a/Documentation/driver-api/wmi.rst b/Documentation/driver-api/wmi.rst
>>> new file mode 100644
>>> index 000000000000..6ca58c8249e5
>>> --- /dev/null
>>> +++ b/Documentation/driver-api/wmi.rst
>>> @@ -0,0 +1,21 @@
>>> +.. SPDX-License-Identifier: GPL-2.0-or-later
>>> +
>>> +==============
>>> +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 and events sharing the same GUIDs
>>> +and/or notification IDs. The modern bus-based interface instead maps each
>>> +WMI device to a :c:type:`struct wmi_device <wmi_device>`, so it supports
>>> +WMI devices sharing GUIDs and/or notification IDs. Drivers can then register
>>> +a :c:type:`struct wmi_driver <wmi_driver>`, which will be bound to compatible
>>> +WMI devices by the driver core.
>>> +
>>> +.. kernel-doc:: include/linux/wmi.h
>>> + :internal:
>> There are no kernel-doc comments in include/linux/wmi.h, so this
>> causes a kernel-doc warning:
>>
>> ../include/linux/wmi.h:1: warning: no structured comments found
>>
>> Otherwise this all looks good.
> So what is the plan here, is there something we can do to fix this
> new warning and should I expect a v3? Or shall I merge this as is ?
>
> Regards,
>
> Hans
>
I did a complete rebuild of the documentation on my machine, and this
error message did not appear. Also include/linux/wmi.h does include
kernel-doc comments for macros like wmi_driver_register(), so i do not
know why this warning is issued by sphinx.

Armin Wolf

>
>
>
>>
>> Tested-by: Randy Dunlap <[email protected]>
>> Acked-by: Randy Dunlap <[email protected]>
>>
>> thanks.

2023-04-25 20:56:19

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] platform/x86: wmi: Add documentation



On 4/25/23 13:29, Armin Wolf wrote:
> Am 25.04.23 um 18:30 schrieb Hans de Goede:
>
>> Hi All,
>>
>> Armin thank you very mich for the WMI documentation work,
>> this is much appreciated!
>>
>> On 4/25/23 05:07, Randy Dunlap wrote:
>>> Hi--
>>>
>>> On 4/24/23 15:29, Armin Wolf wrote:
>>>> Add documentation for the WMI subsystem. The documentation describes
>>>> both the ACPI WMI interface and the driver API for interacting with
>>>> the WMI driver core. The information regarding the ACPI interface
>>>> was retrieved from the Ubuntu kernel references and the Windows driver
>>>> samples available on GitHub. The documentation is supposed to help
>>>> driver developers writing WMI drivers, as many modern machines designed
>>>> to run Windows provide an ACPI WMI interface.
>>>>
>>>> Signed-off-by: Armin Wolf <[email protected]>
>>>> ---
>>>>   Documentation/driver-api/index.rst   |  1 +
>>>>   Documentation/driver-api/wmi.rst     | 21 ++++++
>>>>   Documentation/subsystem-apis.rst     |  1 +
>>>>   Documentation/wmi/acpi-interface.rst | 96 ++++++++++++++++++++++++++++
>>>>   Documentation/wmi/index.rst          | 18 ++++++
>>>>   MAINTAINERS                          |  2 +
>>>>   6 files changed, 139 insertions(+)
>>>>   create mode 100644 Documentation/driver-api/wmi.rst
>>>>   create mode 100644 Documentation/wmi/acpi-interface.rst
>>>>   create mode 100644 Documentation/wmi/index.rst
>>>>
>>>> diff --git a/Documentation/driver-api/wmi.rst b/Documentation/driver-api/wmi.rst
>>>> new file mode 100644
>>>> index 000000000000..6ca58c8249e5
>>>> --- /dev/null
>>>> +++ b/Documentation/driver-api/wmi.rst
>>>> @@ -0,0 +1,21 @@
>>>> +.. SPDX-License-Identifier: GPL-2.0-or-later
>>>> +
>>>> +==============
>>>> +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 and events sharing the same GUIDs
>>>> +and/or notification IDs. The modern bus-based interface instead maps each
>>>> +WMI device to a :c:type:`struct wmi_device <wmi_device>`, so it supports
>>>> +WMI devices sharing GUIDs and/or notification IDs. Drivers can then register
>>>> +a :c:type:`struct wmi_driver <wmi_driver>`, which will be bound to compatible
>>>> +WMI devices by the driver core.
>>>> +
>>>> +.. kernel-doc:: include/linux/wmi.h
>>>> +   :internal:
>>> There are no kernel-doc comments in include/linux/wmi.h, so this
>>> causes a kernel-doc warning:
>>>
>>> ../include/linux/wmi.h:1: warning: no structured comments found
>>>
>>> Otherwise this all looks good.
>> So what is the plan here, is there something we can do to fix this
>> new warning and should I expect a v3?  Or shall I merge this as is ?
>>
>> Regards,
>>
>> Hans
>>
> I did a complete rebuild of the documentation on my machine, and this
> error message did not appear. Also include/linux/wmi.h does include
> kernel-doc comments for macros like wmi_driver_register(), so i do not
> know why this warning is issued by sphinx.

OK, Hans, go ahead and merge it as is.

Thanks.
--
~Randy

2023-04-26 12:46:19

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] platform/x86: wmi: Add subsystem documentation

Hi Armin,

On 4/25/23 00:29, Armin Wolf wrote:
> Currently, there is no recent documentation available for writing WMI
> drivers using the modern bus-based interface. This leads to developers
> using the deprecated GUID-based interface when developing new drivers,
> causing issues with notification handling when multiple WMI devices sharing
> the same notification ID are present. There is also no way for WMI
> drivers to add device specific documentation at the moment.
> Add documentation for the WMI subsystem to solve those issues. The
> device specific documentation currently onyl include documentation for
> the wmi-bmof driver, but more is expected to follow.

Thank you for your patch series, I've applied this series
to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.

Patches which are added to review-hans now are intended for
the next rc1. This branch will get rebased to the next rc1 when
it is out and after the rebasing the contents of review-hans
will be pushed to the platform-drivers-x86/for-next branch.

Regards,

Hans


> ---
> Changes in v2:
> - spelling fixes
> - tell readers that MOF means Managed Object Format
> - 80-cloumn limit
>
> Armin Wolf (4):
> platform/x86: wmi: Add kernel doc comments
> platform/x86: wmi: Mark GUID-based WMI interface as deprecated
> platform/x86: wmi: Add documentation
> platform/x86: wmi: Add device specific documentation
>
> .../ABI/stable/sysfs-platform-wmi-bmof | 7 ++
> Documentation/driver-api/index.rst | 1 +
> Documentation/driver-api/wmi.rst | 21 ++++
> Documentation/subsystem-apis.rst | 1 +
> Documentation/wmi/acpi-interface.rst | 96 +++++++++++++++++++
> Documentation/wmi/devices/index.rst | 22 +++++
> Documentation/wmi/devices/wmi-bmof.rst | 25 +++++
> Documentation/wmi/index.rst | 19 ++++
> MAINTAINERS | 9 ++
> drivers/platform/x86/Kconfig | 4 +-
> drivers/platform/x86/wmi.c | 63 +++++++++---
> include/linux/wmi.h | 41 +++++++-
> 12 files changed, 289 insertions(+), 20 deletions(-)
> create mode 100644 Documentation/ABI/stable/sysfs-platform-wmi-bmof
> create mode 100644 Documentation/driver-api/wmi.rst
> create mode 100644 Documentation/wmi/acpi-interface.rst
> create mode 100644 Documentation/wmi/devices/index.rst
> create mode 100644 Documentation/wmi/devices/wmi-bmof.rst
> create mode 100644 Documentation/wmi/index.rst
>
> --
> 2.30.2
>