From: Nick Dowsett <nick42d@gmail.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>, "Armin Wolf" <W_Armin@gmx.de>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
platform-driver-x86@vger.kernel.org,
Nick Dowsett <nick42d@gmail.com>
Subject: [PATCH v2 2/4] rust: wmi: add DeviceId and wmi_device_table! macro
Date: Fri, 27 Nov 2026 19:02:50 +0800 [thread overview]
Message-ID: <20261127-rust-wmi-v2-2-5bfafabd6a6e@gmail.com> (raw)
In-Reply-To: <20261127-rust-wmi-v2-0-5bfafabd6a6e@gmail.com>
- Add `wmi::DeviceId` wrapping `struct wmi_device_id`.
- Implements `wmi::IdTable` and the `wmi_device_table!`.
Signed-off-by: Nick Dowsett <nick42d@gmail.com>
---
rust/kernel/wmi.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/rust/kernel/wmi.rs b/rust/kernel/wmi.rs
index f821bf35220e..f7fbde29177b 100644
--- a/rust/kernel/wmi.rs
+++ b/rust/kernel/wmi.rs
@@ -7,6 +7,8 @@
use crate::{
bindings,
device,
+ device_id::RawDeviceId,
+ prelude::*,
sync::aref::AlwaysRefCounted,
types::Opaque, //
};
@@ -15,6 +17,64 @@
ptr::NonNull, //
};
+/// IdTable type for WMI drivers.
+pub type IdTable = &'static dyn crate::device_id::IdTable<DeviceId, ()>;
+
+/// A WMI device ID wrapping [`struct wmi_device_id`].
+///
+/// [`struct wmi_device_id`]: srctree/include/linux/device-id/wmi.h
+///
+/// # Invariants
+/// `self.0.guid_string` is a valid, null-terminated string of length [`bindings::UUID_STRING_LEN`].
+#[repr(transparent)]
+#[derive(Clone, Copy)]
+pub struct DeviceId(bindings::wmi_device_id);
+// SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `wmi_device_id`.
+// `wmi_device_id` does not have any invariants, so it's safe to transmute to it.
+unsafe impl RawDeviceId for DeviceId {
+ type RawType = bindings::wmi_device_id;
+}
+impl DeviceId {
+ const WMI_UUID_LEN: usize = crate::num::casts::u32_as_usize(bindings::UUID_STRING_LEN);
+ /// Creates a new [`DeviceId`].
+ ///
+ /// Fails at compile time if `guid.len()` is not [`bindings::UUID_STRING_LEN`].
+ #[inline(always)]
+ pub const fn new(guid: &'static CStr) -> Self {
+ let src = guid.to_bytes_with_nul();
+ // NOTE: Function is marked `#[inline(always)]` to help compiler optimise the error path.
+ build_assert!(
+ src.len() == Self::WMI_UUID_LEN + 1,
+ "WMI DeviceId length incorrect"
+ );
+ let mut id: bindings::wmi_device_id = pin_init::zeroed();
+ // TODO: Upgrade to core::slice::copy_from_slice(src) once rustc>=1.87
+ let mut i = 0;
+ while i < src.len() {
+ id.guid_string[i] = src[i];
+ i += 1;
+ }
+ // INVARIANT:
+ // - All bytes were copied from a Rust `&'static CStr`.
+ // - The build assert above guarantees `id` to meet the length invariant.
+ Self(id)
+ }
+}
+
+/// Create a WMI [`IdTable`] with an "alias" for modpost.
+#[macro_export]
+macro_rules! wmi_device_table {
+ ($table_name:ident, [$($id:expr),* $(,)?]) => {
+ $crate::module_device_table!(
+ "wmi",
+ $crate::wmi::DeviceId,
+ $table_name,
+ @none,
+ [$($id),*]
+ );
+ };
+}
+
/// A WMI bus device ([`struct wmi_device`]).
///
/// # Invariants
--
2.56.1
WARNING: multiple messages have this Message-ID (diff)
From: Nick Dowsett via B4 Relay <devnull+nick42d.gmail.com@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>, "Armin Wolf" <W_Armin@gmx.de>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
platform-driver-x86@vger.kernel.org,
Nick Dowsett <nick42d@gmail.com>
Subject: [PATCH v2 2/4] rust: wmi: add DeviceId and wmi_device_table! macro
Date: Fri, 27 Nov 2026 19:02:50 +0800 [thread overview]
Message-ID: <20261127-rust-wmi-v2-2-5bfafabd6a6e@gmail.com> (raw)
In-Reply-To: <20261127-rust-wmi-v2-0-5bfafabd6a6e@gmail.com>
From: Nick Dowsett <nick42d@gmail.com>
- Add `wmi::DeviceId` wrapping `struct wmi_device_id`.
- Implements `wmi::IdTable` and the `wmi_device_table!`.
Signed-off-by: Nick Dowsett <nick42d@gmail.com>
---
rust/kernel/wmi.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/rust/kernel/wmi.rs b/rust/kernel/wmi.rs
index f821bf35220e..f7fbde29177b 100644
--- a/rust/kernel/wmi.rs
+++ b/rust/kernel/wmi.rs
@@ -7,6 +7,8 @@
use crate::{
bindings,
device,
+ device_id::RawDeviceId,
+ prelude::*,
sync::aref::AlwaysRefCounted,
types::Opaque, //
};
@@ -15,6 +17,64 @@
ptr::NonNull, //
};
+/// IdTable type for WMI drivers.
+pub type IdTable = &'static dyn crate::device_id::IdTable<DeviceId, ()>;
+
+/// A WMI device ID wrapping [`struct wmi_device_id`].
+///
+/// [`struct wmi_device_id`]: srctree/include/linux/device-id/wmi.h
+///
+/// # Invariants
+/// `self.0.guid_string` is a valid, null-terminated string of length [`bindings::UUID_STRING_LEN`].
+#[repr(transparent)]
+#[derive(Clone, Copy)]
+pub struct DeviceId(bindings::wmi_device_id);
+// SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `wmi_device_id`.
+// `wmi_device_id` does not have any invariants, so it's safe to transmute to it.
+unsafe impl RawDeviceId for DeviceId {
+ type RawType = bindings::wmi_device_id;
+}
+impl DeviceId {
+ const WMI_UUID_LEN: usize = crate::num::casts::u32_as_usize(bindings::UUID_STRING_LEN);
+ /// Creates a new [`DeviceId`].
+ ///
+ /// Fails at compile time if `guid.len()` is not [`bindings::UUID_STRING_LEN`].
+ #[inline(always)]
+ pub const fn new(guid: &'static CStr) -> Self {
+ let src = guid.to_bytes_with_nul();
+ // NOTE: Function is marked `#[inline(always)]` to help compiler optimise the error path.
+ build_assert!(
+ src.len() == Self::WMI_UUID_LEN + 1,
+ "WMI DeviceId length incorrect"
+ );
+ let mut id: bindings::wmi_device_id = pin_init::zeroed();
+ // TODO: Upgrade to core::slice::copy_from_slice(src) once rustc>=1.87
+ let mut i = 0;
+ while i < src.len() {
+ id.guid_string[i] = src[i];
+ i += 1;
+ }
+ // INVARIANT:
+ // - All bytes were copied from a Rust `&'static CStr`.
+ // - The build assert above guarantees `id` to meet the length invariant.
+ Self(id)
+ }
+}
+
+/// Create a WMI [`IdTable`] with an "alias" for modpost.
+#[macro_export]
+macro_rules! wmi_device_table {
+ ($table_name:ident, [$($id:expr),* $(,)?]) => {
+ $crate::module_device_table!(
+ "wmi",
+ $crate::wmi::DeviceId,
+ $table_name,
+ @none,
+ [$($id),*]
+ );
+ };
+}
+
/// A WMI bus device ([`struct wmi_device`]).
///
/// # Invariants
--
2.56.1
next prev parent reply other threads:[~2026-11-27 11:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 11:02 [PATCH v2 0/4] rust: wmi: add ACPI WMI bus abstractions Nick Dowsett
2026-11-27 11:02 ` Nick Dowsett via B4 Relay
2026-11-27 11:02 ` [PATCH v2 1/4] rust: wmi: add basic WMI device abstraction Nick Dowsett
2026-11-27 11:02 ` Nick Dowsett via B4 Relay
2026-11-27 11:02 ` Nick Dowsett [this message]
2026-11-27 11:02 ` [PATCH v2 2/4] rust: wmi: add DeviceId and wmi_device_table! macro Nick Dowsett via B4 Relay
2026-11-27 11:02 ` [PATCH v2 3/4] rust: wmi: add Driver trait, Adapter and implement RegistrationOps Nick Dowsett
2026-11-27 11:02 ` Nick Dowsett via B4 Relay
2026-11-28 15:57 ` Armin Wolf
2026-11-29 1:32 ` Nick Dowsett
2026-11-27 11:02 ` [PATCH v2 4/4] rust: wmi: add Buffer and Device::invoke_method() Nick Dowsett
2026-11-27 11:02 ` Nick Dowsett via B4 Relay
2026-11-28 16:05 ` Armin Wolf
2026-11-29 3:08 ` Nick Dowsett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127-rust-wmi-v2-2-5bfafabd6a6e@gmail.com \
--to=nick42d@gmail.com \
--cc=W_Armin@gmx.de \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.