[PATCH v2 0/2] rust: WMI abstractions

Gladyshev Ilya posted 2 patches 3 weeks, 5 days ago
MAINTAINERS                     |   1 +
rust/bindings/bindings_helper.h |   1 +
rust/kernel/acpi.rs             |  97 +++++++++++
rust/kernel/lib.rs              |   2 +
rust/kernel/wmi.rs              | 286 ++++++++++++++++++++++++++++++++
5 files changed, 387 insertions(+)
create mode 100644 rust/kernel/wmi.rs
[PATCH v2 0/2] rust: WMI abstractions
Posted by Gladyshev Ilya 3 weeks, 5 days ago
Overview
========
This patchset implements WMI abstractions for Rust drivers. It is the successor
of the previous RFC posting [0]. These abstractions allow most WMI drivers to be
implemented in Rust (provided other dependencies are abstracted as well).

Currently, the only driver in existance is a reference driver (rewrite of redmi-wmi,
Armin is OK with that [1]). While being fully functional, it depends on sparse-keyboard
abstractions, which I am still polishing. You can view WIP abstractions & driver at [2].

Notes
=====
I do not know how these abstractions should be handled in MAINTAINERS, so for now I have
simply added them to the original WMI entry. I would be happy to be added as a reviewer
to keep the Rust version 'synced'/valid though.

[0]: https://lore.kernel.org/rust-for-linux/cover.1766331321.git.foxido@foxido.dev/
[1]: https://lore.kernel.org/rust-for-linux/c7384f13-e286-45a4-95c6-24d389217185@gmx.de/
[2]: https://git.foxido.dev/foxido/linux/-/commits/rust_wmi?ref_type=heads

---
Changes since v1:
- Add lifetime to AcpiObject
- Add forgotten `Sync` requirement to the WMI driver trait
- Drop unsafe in DeviceId::new() (so no need for the const_intrinsic_copy feature)
- Device<Core> -> Device<Bound> in notify
- Small fixes (styling, missing safety comment)
- Add link to the WIP reference driver

I didn't touch AcpiObject::type_id() in v2 because it does its job for now. It's currently
small (only one subtype, whereas both enum options would introduce a larger integration
surface), and it would be an easy change if someone needs a more powerful solution.

I've also played around with some other suggestions, but:
- Suggested wrapping acpi_object instead of bindgen union subtypes will only introduce
    unneeded unsafety in each subtype's operation. I decided it's better to expose the bindgen
    type once than to validate a safety invariant each time.
- Suggested implementation via a sealed trait didn't really provide any benefits; it just
    raised code complexity a bit. Maybe I did it wrong, though...

Link to v1: https://lore.kernel.org/rust-for-linux/cover.1767818037.git.foxido@foxido.dev/
---

Gladyshev Ilya (2):
  rust: implement wrapper for acpi_object
  rust: add WMI abstractions

 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/acpi.rs             |  97 +++++++++++
 rust/kernel/lib.rs              |   2 +
 rust/kernel/wmi.rs              | 286 ++++++++++++++++++++++++++++++++
 5 files changed, 387 insertions(+)
 create mode 100644 rust/kernel/wmi.rs


base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb
-- 
2.52.0
Re: [PATCH v2 0/2] rust: WMI abstractions
Posted by Armin Wolf 3 weeks, 4 days ago
Am 11.01.26 um 19:31 schrieb Gladyshev Ilya:

> Overview
> ========
> This patchset implements WMI abstractions for Rust drivers. It is the successor
> of the previous RFC posting [0]. These abstractions allow most WMI drivers to be
> implemented in Rust (provided other dependencies are abstracted as well).
>
> Currently, the only driver in existance is a reference driver (rewrite of redmi-wmi,
> Armin is OK with that [1]). While being fully functional, it depends on sparse-keyboard
> abstractions, which I am still polishing. You can view WIP abstractions & driver at [2].
>
> Notes
> =====
> I do not know how these abstractions should be handled in MAINTAINERS, so for now I have
> simply added them to the original WMI entry. I would be happy to be added as a reviewer
> to keep the Rust version 'synced'/valid though.
>
> [0]: https://lore.kernel.org/rust-for-linux/cover.1766331321.git.foxido@foxido.dev/
> [1]: https://lore.kernel.org/rust-for-linux/c7384f13-e286-45a4-95c6-24d389217185@gmx.de/
> [2]: https://git.foxido.dev/foxido/linux/-/commits/rust_wmi?ref_type=heads

Just a side note:

The patch series for the buffer-based WMI API (https://lore.kernel.org/platform-driver-x86/0914098e-e61b-40c1-9b6e-357832fef5a9@gmx.de/T/#mb8d1591e475a6c346421e8875a1307f3ed1528af)
was accepted into the pdx86 kernel tree and will soon show up on the for-next branch. If you want you can target this API instead because
it replaces the usage of ACPI objects with a plain buffer that might be easier to model in rust.

Thanks,
Armin Wolf

> ---
> Changes since v1:
> - Add lifetime to AcpiObject
> - Add forgotten `Sync` requirement to the WMI driver trait
> - Drop unsafe in DeviceId::new() (so no need for the const_intrinsic_copy feature)
> - Device<Core> -> Device<Bound> in notify
> - Small fixes (styling, missing safety comment)
> - Add link to the WIP reference driver
>
> I didn't touch AcpiObject::type_id() in v2 because it does its job for now. It's currently
> small (only one subtype, whereas both enum options would introduce a larger integration
> surface), and it would be an easy change if someone needs a more powerful solution.
>
> I've also played around with some other suggestions, but:
> - Suggested wrapping acpi_object instead of bindgen union subtypes will only introduce
>      unneeded unsafety in each subtype's operation. I decided it's better to expose the bindgen
>      type once than to validate a safety invariant each time.
> - Suggested implementation via a sealed trait didn't really provide any benefits; it just
>      raised code complexity a bit. Maybe I did it wrong, though...
>
> Link to v1: https://lore.kernel.org/rust-for-linux/cover.1767818037.git.foxido@foxido.dev/
> ---
>
> Gladyshev Ilya (2):
>    rust: implement wrapper for acpi_object
>    rust: add WMI abstractions
>
>   MAINTAINERS                     |   1 +
>   rust/bindings/bindings_helper.h |   1 +
>   rust/kernel/acpi.rs             |  97 +++++++++++
>   rust/kernel/lib.rs              |   2 +
>   rust/kernel/wmi.rs              | 286 ++++++++++++++++++++++++++++++++
>   5 files changed, 387 insertions(+)
>   create mode 100644 rust/kernel/wmi.rs
>
>
> base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb