[PATCH v3 0/9] platform/wmi: Introduce marshalling support

Armin Wolf posted 9 patches 4 weeks, 1 day ago
There is a newer version of this series
Documentation/driver-api/wmi.rst              |   3 +
Documentation/wmi/acpi-interface.rst          |  68 +++
.../wmi/driver-development-guide.rst          |  76 ++-
drivers/platform/wmi/Kconfig                  |   3 +
drivers/platform/wmi/Makefile                 |   5 +-
drivers/platform/wmi/core.c                   | 160 ++++++-
drivers/platform/wmi/internal.h               |  17 +
drivers/platform/wmi/marshalling.c            | 241 ++++++++++
drivers/platform/wmi/string.c                 |  92 ++++
drivers/platform/wmi/tests/Kconfig            |  27 ++
drivers/platform/wmi/tests/Makefile           |  11 +
.../platform/wmi/tests/marshalling_kunit.c    | 449 ++++++++++++++++++
drivers/platform/wmi/tests/string_kunit.c     | 278 +++++++++++
.../platform/x86/intel/wmi/sbl-fw-update.c    |  43 +-
drivers/platform/x86/intel/wmi/thunderbolt.c  |  26 +-
drivers/platform/x86/wmi-bmof.c               |  34 +-
drivers/platform/x86/xiaomi-wmi.c             |   5 +-
include/linux/wmi.h                           |  45 +-
18 files changed, 1491 insertions(+), 92 deletions(-)
create mode 100644 drivers/platform/wmi/internal.h
create mode 100644 drivers/platform/wmi/marshalling.c
create mode 100644 drivers/platform/wmi/string.c
create mode 100644 drivers/platform/wmi/tests/Kconfig
create mode 100644 drivers/platform/wmi/tests/Makefile
create mode 100644 drivers/platform/wmi/tests/marshalling_kunit.c
create mode 100644 drivers/platform/wmi/tests/string_kunit.c
[PATCH v3 0/9] platform/wmi: Introduce marshalling support
Posted by Armin Wolf 4 weeks, 1 day ago
The Windows WMI-ACPI driver likely uses wmilib [1] to interact with
the WMI service in userspace. Said library uses plain byte buffers
for exchanging data, so the WMI-ACPI driver has to convert between
those byte buffers and ACPI objects returned by the ACPI firmware.

The format of the byte buffer is publicly documented [2], and after
some reverse eingineering of the WMI-ACPI driver using a set of custom
ACPI tables, the following conversion rules have been discovered:

- ACPI integers are always converted into a uint32
- ACPI strings are converted into special WMI strings
- ACPI buffers are copied as-is
- ACPI packages are unpacked

Extending the ACPI-WMI to perform this kind of marshalling for WMI
data blocks, methods and events would give us a number of benefits:

- WMI drivers are not restricted to a fixed set of supported ACPI data
  types anymore, see dell-wmi-aio (integer vs buffer) and
  hp-wmi-sensors (string vs buffer)

- correct marshalling of WMI strings when data blocks are marked
  as requiring ACPI strings instead of ACPI buffers

- development of WMI drivers without having to understand ACPI

This eventually should result in better compatibility with some
ACPI firmware implementations and in simpler WMI drivers. 

The first patch extends the WMI driver core to perform said
marshalling as well as a new API not based on ACPI objects. The next
patch adds a KUnit test for testing the marshalling code. The
following two patches then add a set of helper functions for dealing
with WMI string data together with another KUnit test.

The remaining patches then convert some simple WMI drivers to use the
new WMI API and update the driver development guide so that new WMI
drivers stop using the ACPI-based API.

The series has been tested on multiple machines, with the xiaomi-wmi
and intel-wmi-sbl-fw-update being tested using a set of custom ACPI
tables loaded over configFS.

[1] https://learn.microsoft.com/de-de/windows-hardware/drivers/ddi/wmilib/

Changes since v2:
- assert that kmallloc aligns buffer on a 8 byte boundary
- add missing includes
- fix some code style issues

Changes since v1:
- fix spelling issues inside the documentation
- add Reviewed-by tag for the documentation

Armin Wolf (9):
  platform/wmi: Introduce marshalling support
  platform/wmi: Add kunit test for the marshalling code
  platform/wmi: Add helper functions for WMI string conversions
  platform/wmi: Add kunit test for the string conversion code
  platform/x86: intel-wmi-sbl-fw-update: Use new buffer-based WMI API
  platform/x86/intel/wmi: thunderbolt: Use new buffer-based WMI API
  platform/x86: xiaomi-wmi: Use new buffer-based WMI API
  platform/x86: wmi-bmof: Use new buffer-based WMI API
  platform/wmi: Update driver development guide

 Documentation/driver-api/wmi.rst              |   3 +
 Documentation/wmi/acpi-interface.rst          |  68 +++
 .../wmi/driver-development-guide.rst          |  76 ++-
 drivers/platform/wmi/Kconfig                  |   3 +
 drivers/platform/wmi/Makefile                 |   5 +-
 drivers/platform/wmi/core.c                   | 160 ++++++-
 drivers/platform/wmi/internal.h               |  17 +
 drivers/platform/wmi/marshalling.c            | 241 ++++++++++
 drivers/platform/wmi/string.c                 |  92 ++++
 drivers/platform/wmi/tests/Kconfig            |  27 ++
 drivers/platform/wmi/tests/Makefile           |  11 +
 .../platform/wmi/tests/marshalling_kunit.c    | 449 ++++++++++++++++++
 drivers/platform/wmi/tests/string_kunit.c     | 278 +++++++++++
 .../platform/x86/intel/wmi/sbl-fw-update.c    |  43 +-
 drivers/platform/x86/intel/wmi/thunderbolt.c  |  26 +-
 drivers/platform/x86/wmi-bmof.c               |  34 +-
 drivers/platform/x86/xiaomi-wmi.c             |   5 +-
 include/linux/wmi.h                           |  45 +-
 18 files changed, 1491 insertions(+), 92 deletions(-)
 create mode 100644 drivers/platform/wmi/internal.h
 create mode 100644 drivers/platform/wmi/marshalling.c
 create mode 100644 drivers/platform/wmi/string.c
 create mode 100644 drivers/platform/wmi/tests/Kconfig
 create mode 100644 drivers/platform/wmi/tests/Makefile
 create mode 100644 drivers/platform/wmi/tests/marshalling_kunit.c
 create mode 100644 drivers/platform/wmi/tests/string_kunit.c

-- 
2.39.5
Re: [PATCH v3 0/9] platform/wmi: Introduce marshalling support
Posted by Ilpo Järvinen 3 weeks, 5 days ago
On Fri, 09 Jan 2026 22:46:10 +0100, Armin Wolf wrote:

> The Windows WMI-ACPI driver likely uses wmilib [1] to interact with
> the WMI service in userspace. Said library uses plain byte buffers
> for exchanging data, so the WMI-ACPI driver has to convert between
> those byte buffers and ACPI objects returned by the ACPI firmware.
> 
> The format of the byte buffer is publicly documented [2], and after
> some reverse eingineering of the WMI-ACPI driver using a set of custom
> ACPI tables, the following conversion rules have been discovered:
> 
> [...]


Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/9] platform/wmi: Introduce marshalling support
      commit: bfa284e9f5e77c9e7389116a403b1dc478f2d58e
[2/9] platform/wmi: Add kunit test for the marshalling code
      commit: 1e4746e93871168f50f237e9e316dc6c9a883719
[3/9] platform/wmi: Add helper functions for WMI string conversions
      commit: 3ae53ee45d5c958aae883173d1e4cafe15564cce
[4/9] platform/wmi: Add kunit test for the string conversion code
      commit: 3579df4cf0b5a3c1d50146c72b13bb4215d509b5
[5/9] platform/x86: intel-wmi-sbl-fw-update: Use new buffer-based WMI API
      commit: ca7861de6a37a52bf75fe41be51fd39162a9281d
[6/9] platform/x86/intel/wmi: thunderbolt: Use new buffer-based WMI API
      commit: 7f331e5f10ebb72d3bbc83470e4b409337024093
[7/9] platform/x86: xiaomi-wmi: Use new buffer-based WMI API
      commit: e9997669653bc0622f9ed8a3fe778cc989d1e254
[8/9] platform/x86: wmi-bmof: Use new buffer-based WMI API
      commit: 70d37a7fd341e5c0090385034feb8f6f93a56ae7
[9/9] platform/wmi: Update driver development guide
      commit: 0835f9737d4705a9f72de05fde09ba806dcbc862

--
 i.
Re: [PATCH v3 0/9] platform/wmi: Introduce marshalling support
Posted by Armin Wolf 3 weeks, 5 days ago
Am 12.01.26 um 16:33 schrieb Ilpo Järvinen:

> On Fri, 09 Jan 2026 22:46:10 +0100, Armin Wolf wrote:
>
>> The Windows WMI-ACPI driver likely uses wmilib [1] to interact with
>> the WMI service in userspace. Said library uses plain byte buffers
>> for exchanging data, so the WMI-ACPI driver has to convert between
>> those byte buffers and ACPI objects returned by the ACPI firmware.
>>
>> The format of the byte buffer is publicly documented [2], and after
>> some reverse eingineering of the WMI-ACPI driver using a set of custom
>> ACPI tables, the following conversion rules have been discovered:
>>
>> [...]
>
> Thank you for your contribution, it has been applied to my local
> review-ilpo-next branch. Note it will show up in the public
> platform-drivers-x86/review-ilpo-next branch only once I've pushed my
> local branch there, which might take a while.
>
> The list of commits applied:
> [1/9] platform/wmi: Introduce marshalling support
>        commit: bfa284e9f5e77c9e7389116a403b1dc478f2d58e
> [2/9] platform/wmi: Add kunit test for the marshalling code
>        commit: 1e4746e93871168f50f237e9e316dc6c9a883719
> [3/9] platform/wmi: Add helper functions for WMI string conversions
>        commit: 3ae53ee45d5c958aae883173d1e4cafe15564cce
> [4/9] platform/wmi: Add kunit test for the string conversion code
>        commit: 3579df4cf0b5a3c1d50146c72b13bb4215d509b5
> [5/9] platform/x86: intel-wmi-sbl-fw-update: Use new buffer-based WMI API
>        commit: ca7861de6a37a52bf75fe41be51fd39162a9281d
> [6/9] platform/x86/intel/wmi: thunderbolt: Use new buffer-based WMI API
>        commit: 7f331e5f10ebb72d3bbc83470e4b409337024093
> [7/9] platform/x86: xiaomi-wmi: Use new buffer-based WMI API
>        commit: e9997669653bc0622f9ed8a3fe778cc989d1e254
> [8/9] platform/x86: wmi-bmof: Use new buffer-based WMI API
>        commit: 70d37a7fd341e5c0090385034feb8f6f93a56ae7
> [9/9] platform/wmi: Update driver development guide
>        commit: 0835f9737d4705a9f72de05fde09ba806dcbc862

Thank you :)

> --
>   i.
>
>