* [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers
@ 2025-06-20 15:09 Igor Korotin
2025-06-20 15:15 ` [PATCH v8 1/9] rust: device: implement FwNode::is_of_node() Igor Korotin
` (10 more replies)
0 siblings, 11 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:09 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
This patch series introduces support for ACPI match tables in Rust
drivers.
Currently, Rust abstractions support only Open Firmware (OF) device
matching. This series extends the driver model to support ACPI-based
matching, enabling Rust drivers to bind to ACPI-described devices.
Changes include:
- A new `acpi::DeviceId` abstraction for working with
`struct acpi_device_id`.
- Updates to the core `Adapter` trait and `platform::Driver` to support
optional ACPI ID tables.
- A sample implementation in the Rust platform driver, demonstrating
multi-bus matching.
This is especially useful for writing drivers that work across platforms
using both OF and ACPI.
Tested using QEMU with a custom SSDT that creates an ACPI device matching
the sample Rust platform driver.
This series is based on three patches by Danilo Krummrich, which
introduce general improvements to the Rust platform driver. These patches
re included unchanged at the beginning of the series for completeness, as
they are required for the ACPI integration.
Danilo Krummrich (3):
rust: device: implement FwNode::is_of_node()
samples: rust: platform: don't call as_ref() repeatedly
samples: rust: platform: conditionally call Self::properties_parse()
Igor Korotin (6):
rust: acpi: add `acpi::DeviceId` abstraction
rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]`
rust: driver: Add ACPI id table support to Adapter trait
rust: platform: Set `OF_ID_TABLE` default to `None` in `Driver` trait
rust: platform: Add ACPI match table support to `Driver` trait
samples: rust: add ACPI match table example to platform driver
Changelog
---------
v8:
- Rebased on top of the latest state of the `driver-core-next` branch.
- Replaced `FwNode::is_compatible()` API with `FwNode::is_of_node()`
per Danilo's request. This includes initial commit and conditional call
in `samples: rust: platform: conditionally call Self::properties_parse()`
- Link to v7: https://lore.kernel.org/rust-for-linux/20250618100221.3047133-1-igor.korotin.linux@gmail.com/
v7:
- Rebased onto the driver-core-next branch
- Incorporated three of Danilo’s upstream patches as a base
- Switched from `assert!` to `build_assert!` in `acpi::DeviceId::new`
for compile-time checks
- Renamed the sample ACPI HID to `TST0001`
- Moved the ACPI test instructions into the module’s top-level
documentation comment
- Link to v6: https://lore.kernel.org/rust-for-linux/20250613133517.1229722-1-igor.korotin.linux@gmail.com/
v6:
- Moved set `Driver::OF_ID_TABLE` default to `None` to a separate commit
- Removed out of scope change related to cpufreq driver.
- Link to v5: https://lore.kernel.org/rust-for-linux/20250611174034.801460-1-igor.korotin.linux@gmail.com/
v5:
- Got rid of unnecessary consolidation of `Adapter::acpi_id_info` methods.
Instead, firstly made consolidation of `Adapter::of_id_info`, then
`Adapter::acpi_id_info` is added using the same pattern.
- Set `Adapter::OF_ID_TABLE` and `Adapter::ACPI_ID_TABLE` as None by
default.
- Removed `Adapter::OF_ID_TABLE`/`Adapter::ACPI_ID_TABLE` initialization
example due to irrelevance.
- Removed extra `of` dependency and `Adapter::OF_ID_TABLE` initialization
in cpufreq driver.
- Link to v4: https://lore.kernel.org/rust-for-linux/20250610145234.235005-1-igor.korotin.linux@gmail.com/
v4:
- Fixed code example for `trait Adapter` in platform.rs
- Fixed driver implementation example in rust_driver_platform.rs and moved
it to `trait Adapter` in platform.rs per Danilo Krummrich's suggestion.
- Consolidated `Adapter::of_id_info` and `Adapter::acpi_id_info` methods using
`#[cfg]` per Benno Lossin's suggestion.
- Link to v3: https://lore.kernel.org/rust-for-linux/20250606170341.3880941-1-igor.korotin.linux@gmail.com/
v3:
- Removed fwnode type check in `Adapter::id_info` per Greg's and Danilo's
comments
- Removed `is_of_node` rust helper, due to unnecessity.
- Fixed example code in `rust_driver_platform.rs` per Danilo's comment
- Added an instruction of testing ACPI using QEMU with a custom SSDT
- Fixed minor code formatting issues.
- Link to v2: https://lore.kernel.org/rust-for-linux/20250605161956.3658374-1-igor.korotin.linux@gmail.com/
v2:
- Removed misleading comment in `acpi::DeviceID` implementation.
- Removed unnecessary casting in `acpi::DeviceID::new`.
- Moved `pub mod acpi` to correct alphabetical position in `rust/kernel/lib.rs`.
- Link to v1: https://lore.kernel.org/rust-for-linux/20250530123815.1766726-1-igor.korotin.linux@gmail.com/
MAINTAINERS | 2 +
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 +
rust/helpers/of.c | 8 +++
rust/kernel/acpi.rs | 60 +++++++++++++++++++++
rust/kernel/device/property.rs | 7 +++
rust/kernel/driver.rs | 81 +++++++++++++++++++++-------
rust/kernel/lib.rs | 1 +
rust/kernel/platform.rs | 29 ++++++++--
samples/rust/rust_driver_platform.rs | 80 +++++++++++++++++++++++++--
10 files changed, 243 insertions(+), 27 deletions(-)
create mode 100644 rust/helpers/of.c
create mode 100644 rust/kernel/acpi.rs
base-commit: b29929b819f35503024c6a7e6ad442f6e36c68a0
--
2.43.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
@ 2025-06-20 15:15 ` Igor Korotin
2025-06-20 22:39 ` Danilo Krummrich
2025-06-25 14:08 ` Rob Herring
2025-06-20 15:18 ` [PATCH v8 2/9] samples: rust: platform: don't call as_ref() repeatedly Igor Korotin
` (9 subsequent siblings)
10 siblings, 2 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:15 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
From: Danilo Krummrich <dakr@kernel.org>
Implement FwNode::is_of_node() in order to check whether a FwNode
instance is embedded in a struct device_node.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
MAINTAINERS | 1 +
rust/helpers/helpers.c | 1 +
rust/helpers/of.c | 8 ++++++++
rust/kernel/device/property.rs | 7 +++++++
4 files changed, 17 insertions(+)
create mode 100644 rust/helpers/of.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 9f724cd556f4..1e918319cff4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18579,6 +18579,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
F: Documentation/ABI/testing/sysfs-firmware-ofw
F: drivers/of/
F: include/linux/of*.h
+F: rust/helpers/of.c
F: rust/kernel/of.rs
F: scripts/dtc/
F: tools/testing/selftests/dt/
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index ed00695af971..041a8112eb9e 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -26,6 +26,7 @@
#include "kunit.c"
#include "mm.c"
#include "mutex.c"
+#include "of.c"
#include "page.c"
#include "platform.c"
#include "pci.c"
diff --git a/rust/helpers/of.c b/rust/helpers/of.c
new file mode 100644
index 000000000000..86b51167c913
--- /dev/null
+++ b/rust/helpers/of.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/of.h>
+
+bool rust_helper_is_of_node(const struct fwnode_handle *fwnode)
+{
+ return is_of_node(fwnode);
+}
diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 838509111e57..63fe4b6ee6bc 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -61,6 +61,13 @@ pub(crate) fn as_raw(&self) -> *mut bindings::fwnode_handle {
self.0.get()
}
+ /// Returns `true` if `&self` is an OF node, `false` otherwise.
+ pub fn is_of_node(&self) -> bool {
+ // SAFETY: The type invariant of `Self` guarantees that `self.as_raw() is a pointer to a
+ // valid `struct fwnode_handle`.
+ unsafe { bindings::is_of_node(self.as_raw()) }
+ }
+
/// Returns an object that implements [`Display`](core::fmt::Display) for
/// printing the name of a node.
///
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 2/9] samples: rust: platform: don't call as_ref() repeatedly
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
2025-06-20 15:15 ` [PATCH v8 1/9] rust: device: implement FwNode::is_of_node() Igor Korotin
@ 2025-06-20 15:18 ` Igor Korotin
2025-06-21 3:28 ` Dirk Behme
2025-06-20 15:21 ` [PATCH v8 3/9] samples: rust: platform: conditionally call Self::properties_parse() Igor Korotin
` (8 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:18 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
From: Danilo Krummrich <dakr@kernel.org>
In SampleDriver::probe() don't call pdev.as_ref() repeatedly, instead
introduce a dedicated &Device.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
samples/rust/rust_driver_platform.rs | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index c0abf78d0683..000bb915af60 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -32,13 +32,15 @@ fn probe(
pdev: &platform::Device<Core>,
info: Option<&Self::IdInfo>,
) -> Result<Pin<KBox<Self>>> {
- dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver sample.\n");
+ let dev = pdev.as_ref();
+
+ dev_dbg!(dev, "Probe Rust Platform driver sample.\n");
if let Some(info) = info {
- dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info.0);
+ dev_info!(dev, "Probed with info: '{}'.\n", info.0);
}
- Self::properties_parse(pdev.as_ref())?;
+ Self::properties_parse(dev)?;
let drvdata = KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?;
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 3/9] samples: rust: platform: conditionally call Self::properties_parse()
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
2025-06-20 15:15 ` [PATCH v8 1/9] rust: device: implement FwNode::is_of_node() Igor Korotin
2025-06-20 15:18 ` [PATCH v8 2/9] samples: rust: platform: don't call as_ref() repeatedly Igor Korotin
@ 2025-06-20 15:21 ` Igor Korotin
2025-06-20 15:24 ` [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction Igor Korotin
` (7 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:21 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
From: Danilo Krummrich <dakr@kernel.org>
Only call Self::properties_parse() when the device is of node
Once we add ACPI support, we don't want the ACPI device to fail probing
in Self::properties_parse().
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
samples/rust/rust_driver_platform.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index 000bb915af60..8579290eecb3 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -40,7 +40,9 @@ fn probe(
dev_info!(dev, "Probed with info: '{}'.\n", info.0);
}
- Self::properties_parse(dev)?;
+ if dev.fwnode().is_some_and(|node| node.is_of_node()) {
+ Self::properties_parse(dev)?;
+ }
let drvdata = KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?;
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (2 preceding siblings ...)
2025-06-20 15:21 ` [PATCH v8 3/9] samples: rust: platform: conditionally call Self::properties_parse() Igor Korotin
@ 2025-06-20 15:24 ` Igor Korotin
2025-06-20 22:06 ` Danilo Krummrich
2025-06-26 15:25 ` Danilo Krummrich
2025-06-20 15:36 ` [PATCH v8 5/9] rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]` Igor Korotin
` (6 subsequent siblings)
10 siblings, 2 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:24 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
`acpi::DeviceId` is an abstraction around `struct acpi_device_id`.
This is used by subsequent patches, in particular the i2c driver
abstractions, to create ACPI device ID tables.
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
MAINTAINERS | 1 +
rust/kernel/acpi.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++
rust/kernel/lib.rs | 1 +
3 files changed, 62 insertions(+)
create mode 100644 rust/kernel/acpi.rs
diff --git a/MAINTAINERS b/MAINTAINERS
index 1e918319cff4..3e59a177ac0c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -302,6 +302,7 @@ F: include/linux/acpi.h
F: include/linux/fwnode.h
F: include/linux/fw_table.h
F: lib/fw_table.c
+F: rust/kernel/acpi.rs
F: tools/power/acpi/
ACPI APEI
diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs
new file mode 100644
index 000000000000..2b25dc9e07ac
--- /dev/null
+++ b/rust/kernel/acpi.rs
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Advanced Configuration and Power Interface abstractions.
+
+use crate::{bindings, device_id::RawDeviceId, prelude::*};
+
+/// IdTable type for ACPI drivers.
+pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
+
+/// An ACPI device id.
+#[repr(transparent)]
+#[derive(Clone, Copy)]
+pub struct DeviceId(bindings::acpi_device_id);
+
+// SAFETY:
+// * `DeviceId` is a `#[repr(transparent)` wrapper of `struct acpi_device_id` and does not add
+// additional invariants, so it's safe to transmute to `RawType`.
+// * `DRIVER_DATA_OFFSET` is the offset to the `data` field.
+unsafe impl RawDeviceId for DeviceId {
+ type RawType = bindings::acpi_device_id;
+
+ const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::acpi_device_id, driver_data);
+
+ fn index(&self) -> usize {
+ self.0.driver_data as _
+ }
+}
+
+impl DeviceId {
+ const ACPI_ID_LEN: usize = 16;
+
+ /// Create a new device id from an ACPI 'id' string.
+ pub const fn new<const N: usize>(id: &[u8; N]) -> Self {
+ build_assert!(N <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
+ // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`.
+ // SAFETY: FFI type is valid to be zero-initialized.
+ let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() };
+ let mut i = 0;
+ while i < N {
+ acpi.id[i] = id[i];
+ i += 1;
+ }
+
+ Self(acpi)
+ }
+}
+
+/// Create an ACPI `IdTable` with an "alias" for modpost.
+#[macro_export]
+macro_rules! acpi_device_table {
+ ($table_name:ident, $module_table_name:ident, $id_info_type: ty, $table_data: expr) => {
+ const $table_name: $crate::device_id::IdArray<
+ $crate::acpi::DeviceId,
+ $id_info_type,
+ { $table_data.len() },
+ > = $crate::device_id::IdArray::new($table_data);
+
+ $crate::module_device_table!("acpi", $module_table_name, $table_name);
+ };
+}
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 6b4774b2b1c3..5bbf3627212f 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -51,6 +51,7 @@
pub use ffi;
+pub mod acpi;
pub mod alloc;
#[cfg(CONFIG_AUXILIARY_BUS)]
pub mod auxiliary;
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 5/9] rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]`
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (3 preceding siblings ...)
2025-06-20 15:24 ` [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction Igor Korotin
@ 2025-06-20 15:36 ` Igor Korotin
2025-06-20 15:39 ` [PATCH v8 6/9] rust: driver: Add ACPI id table support to Adapter trait Igor Korotin
` (5 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:36 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
Refactor the `of_id_info` methods in the `Adapter` trait to reduce
duplication. Previously, the method had two versions selected
via `#[cfg(...)]` and `#[cfg(not(...))]`. This change merges them into a
single method by using `#[cfg]` blocks within the method body.
Suggested-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
rust/kernel/driver.rs | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index ec9166cedfa7..cb62b75a0c0e 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -147,30 +147,32 @@ pub trait Adapter {
/// Returns the driver's private data from the matching entry in the [`of::IdTable`], if any.
///
/// If this returns `None`, it means there is no match with an entry in the [`of::IdTable`].
- #[cfg(CONFIG_OF)]
fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
- let table = Self::of_id_table()?;
+ #[cfg(not(CONFIG_OF))]
+ {
+ let _ = dev;
+ return None;
+ }
- // SAFETY:
- // - `table` has static lifetime, hence it's valid for read,
- // - `dev` is guaranteed to be valid while it's alive, and so is `pdev.as_ref().as_raw()`.
- let raw_id = unsafe { bindings::of_match_device(table.as_ptr(), dev.as_raw()) };
+ #[cfg(CONFIG_OF)]
+ {
+ let table = Self::of_id_table()?;
- if raw_id.is_null() {
- None
- } else {
- // SAFETY: `DeviceId` is a `#[repr(transparent)` wrapper of `struct of_device_id` and
- // does not add additional invariants, so it's safe to transmute.
- let id = unsafe { &*raw_id.cast::<of::DeviceId>() };
+ // SAFETY:
+ // - `table` has static lifetime, hence it's valid for read,
+ // - `dev` is guaranteed to be valid while it's alive, and so is `pdev.as_ref().as_raw()`.
+ let raw_id = unsafe { bindings::of_match_device(table.as_ptr(), dev.as_raw()) };
- Some(table.info(<of::DeviceId as crate::device_id::RawDeviceId>::index(id)))
- }
- }
+ if raw_id.is_null() {
+ None
+ } else {
+ // SAFETY: `DeviceId` is a `#[repr(transparent)` wrapper of `struct of_device_id` and
+ // does not add additional invariants, so it's safe to transmute.
+ let id = unsafe { &*raw_id.cast::<of::DeviceId>() };
- #[cfg(not(CONFIG_OF))]
- #[allow(missing_docs)]
- fn of_id_info(_dev: &device::Device) -> Option<&'static Self::IdInfo> {
- None
+ Some(table.info(<of::DeviceId as crate::device_id::RawDeviceId>::index(id)))
+ }
+ }
}
/// Returns the driver's private data from the matching entry of any of the ID tables, if any.
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 6/9] rust: driver: Add ACPI id table support to Adapter trait
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (4 preceding siblings ...)
2025-06-20 15:36 ` [PATCH v8 5/9] rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]` Igor Korotin
@ 2025-06-20 15:39 ` Igor Korotin
2025-06-20 15:41 ` [PATCH v8 7/9] rust: platform: Set `OF_ID_TABLE` default to `None` in `Driver` trait Igor Korotin
` (4 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:39 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
Extend the `Adapter` trait to support ACPI device identification.
This mirrors the existing Open Firmware (OF) support (`of_id_table`) and
enables Rust drivers to match and retrieve ACPI-specific device data
when `CONFIG_ACPI` is enabled.
To avoid breaking compilation, a stub implementation of `acpi_id_table()`
is added to the Platform adapter; the full implementation will be provided
in a subsequent patch.
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
rust/bindings/bindings_helper.h | 1 +
rust/kernel/driver.rs | 41 ++++++++++++++++++++++++++++++++-
rust/kernel/platform.rs | 6 ++++-
3 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index bc494745f67b..dfb2dd500ef6 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -28,6 +28,7 @@
*/
#include <linux/hrtimer_types.h>
+#include <linux/acpi.h>
#include <drm/drm_device.h>
#include <drm/drm_drv.h>
#include <drm/drm_file.h>
diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index cb62b75a0c0e..8389c122a047 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -6,7 +6,7 @@
//! register using the [`Registration`] class.
use crate::error::{Error, Result};
-use crate::{device, of, str::CStr, try_pin_init, types::Opaque, ThisModule};
+use crate::{acpi, device, of, str::CStr, try_pin_init, types::Opaque, ThisModule};
use core::pin::Pin;
use pin_init::{pin_data, pinned_drop, PinInit};
@@ -141,6 +141,40 @@ pub trait Adapter {
/// The type holding driver private data about each device id supported by the driver.
type IdInfo: 'static;
+ /// The [`acpi::IdTable`] of the corresponding driver
+ fn acpi_id_table() -> Option<acpi::IdTable<Self::IdInfo>>;
+
+ /// Returns the driver's private data from the matching entry in the [`acpi::IdTable`], if any.
+ ///
+ /// If this returns `None`, it means there is no match with an entry in the [`acpi::IdTable`].
+ fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
+ #[cfg(not(CONFIG_ACPI))]
+ {
+ let _ = dev;
+ return None;
+ }
+
+ #[cfg(CONFIG_ACPI)]
+ {
+ let table = Self::acpi_id_table()?;
+
+ // SAFETY:
+ // - `table` has static lifetime, hence it's valid for read,
+ // - `dev` is guaranteed to be valid while it's alive, and so is `pdev.as_ref().as_raw()`.
+ let raw_id = unsafe { bindings::acpi_match_device(table.as_ptr(), dev.as_raw()) };
+
+ if raw_id.is_null() {
+ None
+ } else {
+ // SAFETY: `DeviceId` is a `#[repr(transparent)` wrapper of `struct of_device_id` and
+ // does not add additional invariants, so it's safe to transmute.
+ let id = unsafe { &*raw_id.cast::<acpi::DeviceId>() };
+
+ Some(table.info(<acpi::DeviceId as crate::device_id::RawDeviceId>::index(id)))
+ }
+ }
+ }
+
/// The [`of::IdTable`] of the corresponding driver.
fn of_id_table() -> Option<of::IdTable<Self::IdInfo>>;
@@ -180,6 +214,11 @@ fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
/// If this returns `None`, it means that there is no match in any of the ID tables directly
/// associated with a [`device::Device`].
fn id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
+ let id = Self::acpi_id_info(dev);
+ if id.is_some() {
+ return id;
+ }
+
let id = Self::of_id_info(dev);
if id.is_some() {
return id;
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 5b21fa517e55..5923d29a0511 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -5,7 +5,7 @@
//! C header: [`include/linux/platform_device.h`](srctree/include/linux/platform_device.h)
use crate::{
- bindings, container_of, device, driver,
+ acpi, bindings, container_of, device, driver,
error::{to_result, Result},
of,
prelude::*,
@@ -94,6 +94,10 @@ impl<T: Driver + 'static> driver::Adapter for Adapter<T> {
fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> {
T::OF_ID_TABLE
}
+
+ fn acpi_id_table() -> Option<acpi::IdTable<Self::IdInfo>> {
+ None
+ }
}
/// Declares a kernel module that exposes a single platform driver.
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 7/9] rust: platform: Set `OF_ID_TABLE` default to `None` in `Driver` trait
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (5 preceding siblings ...)
2025-06-20 15:39 ` [PATCH v8 6/9] rust: driver: Add ACPI id table support to Adapter trait Igor Korotin
@ 2025-06-20 15:41 ` Igor Korotin
2025-06-20 15:43 ` [PATCH v8 8/9] rust: platform: Add ACPI match table support to " Igor Korotin
` (3 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:41 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
Provide a default value of `None` for `Driver::OF_ID_TABLE` to simplify
driver implementations.
Drivers that do not require OpenFirmware matching no longer need to
import the `of` module or define the constant explicitly.
This reduces unnecessary boilerplate and avoids pulling in unused
dependencies.
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
rust/kernel/platform.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 5923d29a0511..2436f55b579b 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -162,7 +162,7 @@ pub trait Driver: Send {
type IdInfo: 'static;
/// The table of OF device ids supported by the driver.
- const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>>;
+ const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
/// Platform driver probe.
///
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 8/9] rust: platform: Add ACPI match table support to `Driver` trait
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (6 preceding siblings ...)
2025-06-20 15:41 ` [PATCH v8 7/9] rust: platform: Set `OF_ID_TABLE` default to `None` in `Driver` trait Igor Korotin
@ 2025-06-20 15:43 ` Igor Korotin
2025-06-20 15:45 ` [PATCH v8 9/9] samples: rust: add ACPI match table example to platform driver Igor Korotin
` (2 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:43 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
Extend the `platform::Driver` trait to support ACPI device matching by
adding the `ACPI_ID_TABLE` constant.
This allows Rust platform drivers to define ACPI match tables alongside
their existing OF match tables. These changes mirror the existing OF
support and allow Rust platform drivers to match devices based on ACPI
identifiers.
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
rust/kernel/platform.rs | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 2436f55b579b..0d00ab9acef7 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -37,12 +37,18 @@ unsafe fn register(
None => core::ptr::null(),
};
+ let acpi_table = match T::ACPI_ID_TABLE {
+ Some(table) => table.as_ptr(),
+ None => core::ptr::null(),
+ };
+
// SAFETY: It's safe to set the fields of `struct platform_driver` on initialization.
unsafe {
(*pdrv.get()).driver.name = name.as_char_ptr();
(*pdrv.get()).probe = Some(Self::probe_callback);
(*pdrv.get()).remove = Some(Self::remove_callback);
(*pdrv.get()).driver.of_match_table = of_table;
+ (*pdrv.get()).driver.acpi_match_table = acpi_table;
}
// SAFETY: `pdrv` is guaranteed to be a valid `RegType`.
@@ -96,7 +102,7 @@ fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> {
}
fn acpi_id_table() -> Option<acpi::IdTable<Self::IdInfo>> {
- None
+ T::ACPI_ID_TABLE
}
}
@@ -127,7 +133,7 @@ macro_rules! module_platform_driver {
/// # Example
///
///```
-/// # use kernel::{bindings, c_str, device::Core, of, platform};
+/// # use kernel::{acpi, bindings, c_str, device::Core, of, platform};
///
/// struct MyDriver;
///
@@ -140,9 +146,19 @@ macro_rules! module_platform_driver {
/// ]
/// );
///
+/// kernel::acpi_device_table!(
+/// ACPI_TABLE,
+/// MODULE_ACPI_TABLE,
+/// <MyDriver as platform::Driver>::IdInfo,
+/// [
+/// (acpi::DeviceId::new(b"TST0001"), ())
+/// ]
+/// );
+///
/// impl platform::Driver for MyDriver {
/// type IdInfo = ();
/// const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
+/// const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
///
/// fn probe(
/// _pdev: &platform::Device<Core>,
@@ -164,6 +180,9 @@ pub trait Driver: Send {
/// The table of OF device ids supported by the driver.
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
+ /// The table of ACPI device ids supported by the driver.
+ const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = None;
+
/// Platform driver probe.
///
/// Called when a new platform device is added or discovered.
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v8 9/9] samples: rust: add ACPI match table example to platform driver
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (7 preceding siblings ...)
2025-06-20 15:43 ` [PATCH v8 8/9] rust: platform: Add ACPI match table support to " Igor Korotin
@ 2025-06-20 15:45 ` Igor Korotin
2025-06-26 17:33 ` [PATCH v1 0/4] rust: Add basic I2C driver abstractions Igor Korotin
2025-06-26 22:31 ` [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Danilo Krummrich
10 siblings, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-20 15:45 UTC (permalink / raw)
To: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Igor Korotin, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
Extend the Rust sample platform driver to probe using device/driver name
matching, OF ID table matching, or ACPI ID table matching.
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
samples/rust/rust_driver_platform.rs | 70 +++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 1 deletion(-)
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index 8579290eecb3..9c16945e6c70 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -2,8 +2,68 @@
//! Rust Platform driver sample.
+//! ACPI match table test
+//!
+//! This demonstrates how to test an ACPI-based Rust platform driver using QEMU
+//! with a custom SSDT.
+//!
+//! Steps:
+//!
+//! 1. **Create an SSDT source file** (`ssdt.dsl`) with the following content:
+//!
+//! ```asl
+//! DefinitionBlock ("", "SSDT", 2, "TEST", "VIRTACPI", 0x00000001)
+//! {
+//! Scope (\_SB)
+//! {
+//! Device (T432)
+//! {
+//! Name (_HID, "TST0001") // ACPI hardware ID to match
+//! Name (_UID, 1)
+//! Name (_STA, 0x0F) // Device present, enabled
+//! Name (_CRS, ResourceTemplate ()
+//! {
+//! Memory32Fixed (ReadWrite, 0xFED00000, 0x1000)
+//! })
+//! }
+//! }
+//! }
+//! ```
+//!
+//! 2. **Compile the table**:
+//!
+//! ```sh
+//! iasl -tc ssdt.dsl
+//! ```
+//!
+//! This generates `ssdt.aml`
+//!
+//! 3. **Run QEMU** with the compiled AML file:
+//!
+//! ```sh
+//! qemu-system-x86_64 -m 512M \
+//! -enable-kvm \
+//! -kernel path/to/bzImage \
+//! -append "root=/dev/sda console=ttyS0" \
+//! -hda rootfs.img \
+//! -serial stdio \
+//! -acpitable file=ssdt.aml
+//! ```
+//!
+//! Requirements:
+//! - The `rust_driver_platform` must be present either:
+//! - built directly into the kernel (`bzImage`), or
+//! - available as a `.ko` file and loadable from `rootfs.img`
+//!
+//! 4. **Verify it worked** by checking `dmesg`:
+//!
+//! ```
+//! rust_driver_platform TST0001:00: Probed with info: '0'.
+//! ```
+//!
+
use kernel::{
- c_str,
+ acpi, c_str,
device::{self, Core},
of, platform,
prelude::*,
@@ -24,9 +84,17 @@ struct SampleDriver {
[(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
);
+kernel::acpi_device_table!(
+ ACPI_TABLE,
+ MODULE_ACPI_TABLE,
+ <SampleDriver as platform::Driver>::IdInfo,
+ [(acpi::DeviceId::new(b"TST0001"), Info(0))]
+);
+
impl platform::Driver for SampleDriver {
type IdInfo = Info;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
+ const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
fn probe(
pdev: &platform::Device<Core>,
--
2.43.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction
2025-06-20 15:24 ` [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction Igor Korotin
@ 2025-06-20 22:06 ` Danilo Krummrich
2025-06-23 9:03 ` Igor Korotin
2025-06-24 17:56 ` Rafael J. Wysocki
2025-06-26 15:25 ` Danilo Krummrich
1 sibling, 2 replies; 23+ messages in thread
From: Danilo Krummrich @ 2025-06-20 22:06 UTC (permalink / raw)
To: Igor Korotin, Rafael J . Wysocki
Cc: Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda, Rob Herring,
Saravana Kannan, Alex Hung, Andrew Morton, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo, Len Brown,
Trevor Gross
On Fri, Jun 20, 2025 at 04:24:25PM +0100, Igor Korotin wrote:
> `acpi::DeviceId` is an abstraction around `struct acpi_device_id`.
>
> This is used by subsequent patches, in particular the i2c driver
> abstractions, to create ACPI device ID tables.
I think this should say something like
"Enable drivers to build ACPI device ID tables, to be consumed by the
corresponding bus abstractions, such as platform or I2C."
instead.
If we agree, I can change it when applying the patch -- no need to resend.
>
> Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
@Rafael: Can I get an ACK for this one, such that I can take it together with
all other patches through the driver-core tree?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
2025-06-20 15:15 ` [PATCH v8 1/9] rust: device: implement FwNode::is_of_node() Igor Korotin
@ 2025-06-20 22:39 ` Danilo Krummrich
2025-06-24 20:46 ` Danilo Krummrich
2025-06-25 14:08 ` Rob Herring
1 sibling, 1 reply; 23+ messages in thread
From: Danilo Krummrich @ 2025-06-20 22:39 UTC (permalink / raw)
To: Rob Herring
Cc: Rafael J . Wysocki, Igor Korotin, Alex Gaynor, Greg Kroah-Hartman,
Miguel Ojeda, Saravana Kannan, Alex Hung, Andrew Morton,
Jakub Kicinski, Jonathan Cameron, Krzysztof Kozlowski,
Mauro Carvalho Chehab, Remo Senekowitsch, Tamir Duberstein,
Viresh Kumar, Wedson Almeida Filho, Xiangfei Ding, devicetree,
linux-acpi, linux-kernel, rust-for-linux, Björn Roy Baron,
Alice Ryhl, Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo,
Len Brown, Trevor Gross
On Fri, Jun 20, 2025 at 04:15:04PM +0100, Igor Korotin wrote:
> From: Danilo Krummrich <dakr@kernel.org>
>
> Implement FwNode::is_of_node() in order to check whether a FwNode
> instance is embedded in a struct device_node.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
> ---
> MAINTAINERS | 1 +
> rust/helpers/helpers.c | 1 +
> rust/helpers/of.c | 8 ++++++++
> rust/kernel/device/property.rs | 7 +++++++
> 4 files changed, 17 insertions(+)
> create mode 100644 rust/helpers/of.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9f724cd556f4..1e918319cff4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -18579,6 +18579,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
> F: Documentation/ABI/testing/sysfs-firmware-ofw
> F: drivers/of/
> F: include/linux/of*.h
> +F: rust/helpers/of.c
@Rob: Any concerns about adding the OF Rust helpers to the OF entry?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 2/9] samples: rust: platform: don't call as_ref() repeatedly
2025-06-20 15:18 ` [PATCH v8 2/9] samples: rust: platform: don't call as_ref() repeatedly Igor Korotin
@ 2025-06-21 3:28 ` Dirk Behme
0 siblings, 0 replies; 23+ messages in thread
From: Dirk Behme @ 2025-06-21 3:28 UTC (permalink / raw)
To: Igor Korotin, Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman,
Miguel Ojeda, Rob Herring, Saravana Kannan
Cc: Alex Hung, Andrew Morton, Jakub Kicinski, Jonathan Cameron,
Krzysztof Kozlowski, Mauro Carvalho Chehab, Remo Senekowitsch,
Tamir Duberstein, Viresh Kumar, Wedson Almeida Filho,
Xiangfei Ding, devicetree, linux-acpi, linux-kernel,
rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
On 20.06.25 17:18, Igor Korotin wrote:
> From: Danilo Krummrich <dakr@kernel.org>
>
> In SampleDriver::probe() don't call pdev.as_ref() repeatedly, instead
> introduce a dedicated &Device.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
Reviewed-by: Dirk Behme <dirk.behme@de.bosch.com>
Thanks!
Dirk
> ---
> samples/rust/rust_driver_platform.rs | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
> index c0abf78d0683..000bb915af60 100644
> --- a/samples/rust/rust_driver_platform.rs
> +++ b/samples/rust/rust_driver_platform.rs
> @@ -32,13 +32,15 @@ fn probe(
> pdev: &platform::Device<Core>,
> info: Option<&Self::IdInfo>,
> ) -> Result<Pin<KBox<Self>>> {
> - dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver sample.\n");
> + let dev = pdev.as_ref();
> +
> + dev_dbg!(dev, "Probe Rust Platform driver sample.\n");
>
> if let Some(info) = info {
> - dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info.0);
> + dev_info!(dev, "Probed with info: '{}'.\n", info.0);
> }
>
> - Self::properties_parse(pdev.as_ref())?;
> + Self::properties_parse(dev)?;
>
> let drvdata = KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?;
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction
2025-06-20 22:06 ` Danilo Krummrich
@ 2025-06-23 9:03 ` Igor Korotin
2025-06-24 17:56 ` Rafael J. Wysocki
1 sibling, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-23 9:03 UTC (permalink / raw)
To: Danilo Krummrich, Rafael J . Wysocki
Cc: Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda, Rob Herring,
Saravana Kannan, Alex Hung, Andrew Morton, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo, Len Brown,
Trevor Gross
On 6/20/25 23:06, Danilo Krummrich wrote:
> On Fri, Jun 20, 2025 at 04:24:25PM +0100, Igor Korotin wrote:
>> `acpi::DeviceId` is an abstraction around `struct acpi_device_id`.
>>
>> This is used by subsequent patches, in particular the i2c driver
>> abstractions, to create ACPI device ID tables.
>
> I think this should say something like
>
> "Enable drivers to build ACPI device ID tables, to be consumed by the
> corresponding bus abstractions, such as platform or I2C."
>
> instead.
>
> If we agree, I can change it when applying the patch -- no need to resend.
>
No objections.
Thanks
Igor
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction
2025-06-20 22:06 ` Danilo Krummrich
2025-06-23 9:03 ` Igor Korotin
@ 2025-06-24 17:56 ` Rafael J. Wysocki
1 sibling, 0 replies; 23+ messages in thread
From: Rafael J. Wysocki @ 2025-06-24 17:56 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Igor Korotin, Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman,
Miguel Ojeda, Rob Herring, Saravana Kannan, Alex Hung,
Andrew Morton, Jakub Kicinski, Jonathan Cameron,
Krzysztof Kozlowski, Mauro Carvalho Chehab, Remo Senekowitsch,
Tamir Duberstein, Viresh Kumar, Wedson Almeida Filho,
Xiangfei Ding, devicetree, linux-acpi, linux-kernel,
rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo, Len Brown,
Trevor Gross
On Sat, Jun 21, 2025 at 12:06 AM Danilo Krummrich <dakr@kernel.org> wrote:
>
> On Fri, Jun 20, 2025 at 04:24:25PM +0100, Igor Korotin wrote:
> > `acpi::DeviceId` is an abstraction around `struct acpi_device_id`.
> >
> > This is used by subsequent patches, in particular the i2c driver
> > abstractions, to create ACPI device ID tables.
>
> I think this should say something like
>
> "Enable drivers to build ACPI device ID tables, to be consumed by the
> corresponding bus abstractions, such as platform or I2C."
>
> instead.
>
> If we agree, I can change it when applying the patch -- no need to resend.
>
> >
> > Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
>
> @Rafael: Can I get an ACK for this one, such that I can take it together with
> all other patches through the driver-core tree?
I don't see anything objectionable in it, even though Rust code is
still kind of outside my confidence zone ATM.
Anyway, please feel free to add
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
to this.
Thanks!
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
2025-06-20 22:39 ` Danilo Krummrich
@ 2025-06-24 20:46 ` Danilo Krummrich
0 siblings, 0 replies; 23+ messages in thread
From: Danilo Krummrich @ 2025-06-24 20:46 UTC (permalink / raw)
To: Rob Herring
Cc: Rafael J . Wysocki, Igor Korotin, Alex Gaynor, Greg Kroah-Hartman,
Miguel Ojeda, Saravana Kannan, Alex Hung, Andrew Morton,
Jakub Kicinski, Jonathan Cameron, Krzysztof Kozlowski,
Mauro Carvalho Chehab, Remo Senekowitsch, Tamir Duberstein,
Viresh Kumar, Wedson Almeida Filho, Xiangfei Ding, devicetree,
linux-acpi, linux-kernel, rust-for-linux, Björn Roy Baron,
Alice Ryhl, Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo,
Len Brown, Trevor Gross
On Sat, Jun 21, 2025 at 12:40:02AM +0200, Danilo Krummrich wrote:
> On Fri, Jun 20, 2025 at 04:15:04PM +0100, Igor Korotin wrote:
> > From: Danilo Krummrich <dakr@kernel.org>
> >
> > Implement FwNode::is_of_node() in order to check whether a FwNode
> > instance is embedded in a struct device_node.
> >
> > Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> > Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
> > ---
> > MAINTAINERS | 1 +
> > rust/helpers/helpers.c | 1 +
> > rust/helpers/of.c | 8 ++++++++
> > rust/kernel/device/property.rs | 7 +++++++
> > 4 files changed, 17 insertions(+)
> > create mode 100644 rust/helpers/of.c
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 9f724cd556f4..1e918319cff4 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -18579,6 +18579,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
> > F: Documentation/ABI/testing/sysfs-firmware-ofw
> > F: drivers/of/
> > F: include/linux/of*.h
> > +F: rust/helpers/of.c
>
> @Rob: Any concerns about adding the OF Rust helpers to the OF entry?
Given that you proposed to use is_of_node() and rust/kernel/of.rs is under your
MAINTAINERS entry as well, I assume this is fine.
If not, please let me know.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
2025-06-20 15:15 ` [PATCH v8 1/9] rust: device: implement FwNode::is_of_node() Igor Korotin
2025-06-20 22:39 ` Danilo Krummrich
@ 2025-06-25 14:08 ` Rob Herring
1 sibling, 0 replies; 23+ messages in thread
From: Rob Herring @ 2025-06-25 14:08 UTC (permalink / raw)
To: Igor Korotin
Cc: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Saravana Kannan, Alex Hung, Andrew Morton, Jakub Kicinski,
Jonathan Cameron, Krzysztof Kozlowski, Mauro Carvalho Chehab,
Remo Senekowitsch, Tamir Duberstein, Viresh Kumar,
Wedson Almeida Filho, Xiangfei Ding, devicetree, linux-acpi,
linux-kernel, rust-for-linux, Björn Roy Baron, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Boqun Feng, Danilo Krummrich,
Gary Guo, Len Brown, Trevor Gross
On Fri, Jun 20, 2025 at 10:17 AM Igor Korotin
<igor.korotin.linux@gmail.com> wrote:
>
> From: Danilo Krummrich <dakr@kernel.org>
>
> Implement FwNode::is_of_node() in order to check whether a FwNode
> instance is embedded in a struct device_node.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
> ---
> MAINTAINERS | 1 +
> rust/helpers/helpers.c | 1 +
> rust/helpers/of.c | 8 ++++++++
> rust/kernel/device/property.rs | 7 +++++++
> 4 files changed, 17 insertions(+)
> create mode 100644 rust/helpers/of.c
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction
2025-06-20 15:24 ` [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction Igor Korotin
2025-06-20 22:06 ` Danilo Krummrich
@ 2025-06-26 15:25 ` Danilo Krummrich
2025-06-26 17:40 ` Igor Korotin
1 sibling, 1 reply; 23+ messages in thread
From: Danilo Krummrich @ 2025-06-26 15:25 UTC (permalink / raw)
To: Igor Korotin
Cc: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan, Alex Hung, Andrew Morton,
Jakub Kicinski, Jonathan Cameron, Krzysztof Kozlowski,
Mauro Carvalho Chehab, Remo Senekowitsch, Tamir Duberstein,
Viresh Kumar, Wedson Almeida Filho, Xiangfei Ding, devicetree,
linux-acpi, linux-kernel, rust-for-linux, Björn Roy Baron,
Alice Ryhl, Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo,
Len Brown, Trevor Gross
On 6/20/25 5:24 PM, Igor Korotin wrote:
> +impl DeviceId {
> + const ACPI_ID_LEN: usize = 16;
> +
> + /// Create a new device id from an ACPI 'id' string.
> + pub const fn new<const N: usize>(id: &[u8; N]) -> Self {
Didn't notice before, but why was this silently changed from &CStr to &[u8; N]
from v6 to v7?
> + build_assert!(N <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
> + // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`.
> + // SAFETY: FFI type is valid to be zero-initialized.
> + let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() };
> + let mut i = 0;
> + while i < N {
> + acpi.id[i] = id[i];
> + i += 1;
> + }
> +
> + Self(acpi)
> + }
> +}
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v1 0/4] rust: Add basic I2C driver abstractions
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (8 preceding siblings ...)
2025-06-20 15:45 ` [PATCH v8 9/9] samples: rust: add ACPI match table example to platform driver Igor Korotin
@ 2025-06-26 17:33 ` Igor Korotin
2025-06-26 17:47 ` Igor Korotin
2025-06-26 22:31 ` [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Danilo Krummrich
10 siblings, 1 reply; 23+ messages in thread
From: Igor Korotin @ 2025-06-26 17:33 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wolfram Sang
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Greg Kroah-Hartman, Viresh Kumar, Asahi Lina,
Wedson Almeida Filho, Alex Hung, Tamir Duberstein, Xiangfei Ding,
linux-kernel, rust-for-linux, linux-i2c
This patch series introduces basic Rust I2C driver abstractions
and optional ACPI match-table support and provides a sample driver
demonstrating both OF and ACPI binding
Currently Rust I2C abstractions support only Open Firmware OF device
matching. This series splits the work into four patches so that the
core abstractions and sample driver can land immediately while ACPI
integration may be reviewed once the ACPI macros are upstream
Changes include
- core I2C abstractions `i2c::Device` `i2c::Driver` `i2c::Adapter`
built on `struct i2c_client` and `struct i2c_driver`
- a standalone Rust sample driver exercising Legacy I2C ID and OF ID
matching
- optional ACPI ID-table support in the `i2c::Driver` abstraction
- ACPI-enabled sample driver showing `kernel::acpi_device_table!`
usage
This separation lets maintainers review and merge the non-ACPI portions
immediately while patches 3 and 4 both depending on the ACPI
infrastructure can be queued once the ACPI macros are upstream
Patch series:
1 rust: i2c: add basic I2C device and driver abstractions
2 samples: rust: add I2C sample driver (OF only)
3 rust: i2c: support ACPI match-table in driver abstractions
Depends-on: 20250620152425.285683-1-igor.korotin.linux@gmail.com
4 samples: rust: show ACPI ID-table in I2C sample driver
Depends-on: 20250620152425.285683-1-igor.korotin.linux@gmail.com
Igor Korotin (4):
rust: i2c: add basic I2C device and driver abstractions
samples: rust: add Rust I2C sample driver
rust: i2c: ACPI ID-table support for I2C abstractions
samples: rust: show ACPI ID-table in I2C sample driver
MAINTAINERS | 3 +
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 +
rust/helpers/i2c.c | 15 ++
rust/kernel/i2c.rs | 386 ++++++++++++++++++++++++++++++++
rust/kernel/lib.rs | 2 +
samples/rust/Kconfig | 11 +
samples/rust/Makefile | 1 +
samples/rust/rust_driver_i2c.rs | 69 ++++++
9 files changed, 489 insertions(+)
create mode 100644 rust/helpers/i2c.c
create mode 100644 rust/kernel/i2c.rs
create mode 100644 samples/rust/rust_driver_i2c.rs
base-commit: 63dafeb392139b893a73b6331f347613f0929702
--
2.43.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction
2025-06-26 15:25 ` Danilo Krummrich
@ 2025-06-26 17:40 ` Igor Korotin
2025-06-26 18:28 ` Danilo Krummrich
0 siblings, 1 reply; 23+ messages in thread
From: Igor Korotin @ 2025-06-26 17:40 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan, Alex Hung, Andrew Morton,
Jakub Kicinski, Jonathan Cameron, Krzysztof Kozlowski,
Mauro Carvalho Chehab, Remo Senekowitsch, Tamir Duberstein,
Viresh Kumar, Wedson Almeida Filho, Xiangfei Ding, devicetree,
linux-acpi, linux-kernel, rust-for-linux, Björn Roy Baron,
Alice Ryhl, Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo,
Len Brown, Trevor Gross
On 6/26/25 16:25, Danilo Krummrich wrote:
> On 6/20/25 5:24 PM, Igor Korotin wrote:
>> +impl DeviceId {
>> + const ACPI_ID_LEN: usize = 16;
>> +
>> + /// Create a new device id from an ACPI 'id' string.
>> + pub const fn new<const N: usize>(id: &[u8; N]) -> Self {
>
> Didn't notice before, but why was this silently changed from &CStr to
> &[u8; N]
> from v6 to v7?
>
>> + build_assert!(N <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
>> + // Replace with `bindings::acpi_device_id::default()` once
>> stabilized for `const`.
>> + // SAFETY: FFI type is valid to be zero-initialized.
>> + let mut acpi: bindings::acpi_device_id = unsafe
>> { core::mem::zeroed() };
>> + let mut i = 0;
>> + while i < N {
>> + acpi.id[i] = id[i];
>> + i += 1;
>> + }
>> +
>> + Self(acpi)
>> + }
>> +}
In v6 I was asked to change assert! (runtime) to build_assert! (build time)
It was as follows:
> + pub const fn new(id: &'static CStr) -> Self {
> + assert!(id.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
but id.len() breaks const context and so build_assert! triggers
assertion. If I needed to explicitly describe change from CStr to
[u8;20], then it's my bad.
Thanks,
Igor
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 0/4] rust: Add basic I2C driver abstractions
2025-06-26 17:33 ` [PATCH v1 0/4] rust: Add basic I2C driver abstractions Igor Korotin
@ 2025-06-26 17:47 ` Igor Korotin
0 siblings, 0 replies; 23+ messages in thread
From: Igor Korotin @ 2025-06-26 17:47 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wolfram Sang
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Greg Kroah-Hartman, Viresh Kumar, Asahi Lina,
Wedson Almeida Filho, Alex Hung, Tamir Duberstein, Xiangfei Ding,
linux-kernel, rust-for-linux, linux-i2c
On 6/26/25 18:33, Igor Korotin wrote:
> This patch series introduces basic Rust I2C driver abstractions
> and optional ACPI match-table support and provides a sample driver
> demonstrating both OF and ACPI binding
>
> Currently Rust I2C abstractions support only Open Firmware OF device
> matching. This series splits the work into four patches so that the
> core abstractions and sample driver can land immediately while ACPI
> integration may be reviewed once the ACPI macros are upstream
>
> Changes include
> - core I2C abstractions `i2c::Device` `i2c::Driver` `i2c::Adapter`
> built on `struct i2c_client` and `struct i2c_driver`
> - a standalone Rust sample driver exercising Legacy I2C ID and OF ID
> matching
> - optional ACPI ID-table support in the `i2c::Driver` abstraction
> - ACPI-enabled sample driver showing `kernel::acpi_device_table!`
> usage
>
> This separation lets maintainers review and merge the non-ACPI portions
> immediately while patches 3 and 4 both depending on the ACPI
> infrastructure can be queued once the ACPI macros are upstream
>
> Patch series:
>
> 1 rust: i2c: add basic I2C device and driver abstractions
> 2 samples: rust: add I2C sample driver (OF only)
> 3 rust: i2c: support ACPI match-table in driver abstractions
> Depends-on: 20250620152425.285683-1-igor.korotin.linux@gmail.com
> 4 samples: rust: show ACPI ID-table in I2C sample driver
> Depends-on: 20250620152425.285683-1-igor.korotin.linux@gmail.com
>
> Igor Korotin (4):
> rust: i2c: add basic I2C device and driver abstractions
> samples: rust: add Rust I2C sample driver
> rust: i2c: ACPI ID-table support for I2C abstractions
> samples: rust: show ACPI ID-table in I2C sample driver
>
> MAINTAINERS | 3 +
> rust/bindings/bindings_helper.h | 1 +
> rust/helpers/helpers.c | 1 +
> rust/helpers/i2c.c | 15 ++
> rust/kernel/i2c.rs | 386 ++++++++++++++++++++++++++++++++
> rust/kernel/lib.rs | 2 +
> samples/rust/Kconfig | 11 +
> samples/rust/Makefile | 1 +
> samples/rust/rust_driver_i2c.rs | 69 ++++++
> 9 files changed, 489 insertions(+)
> create mode 100644 rust/helpers/i2c.c
> create mode 100644 rust/kernel/i2c.rs
> create mode 100644 samples/rust/rust_driver_i2c.rs
>
>
> base-commit: 63dafeb392139b893a73b6331f347613f0929702
Please ignore. Was sent by mistake.
Thanks
Igor
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction
2025-06-26 17:40 ` Igor Korotin
@ 2025-06-26 18:28 ` Danilo Krummrich
0 siblings, 0 replies; 23+ messages in thread
From: Danilo Krummrich @ 2025-06-26 18:28 UTC (permalink / raw)
To: Igor Korotin
Cc: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan, Alex Hung, Andrew Morton,
Jakub Kicinski, Jonathan Cameron, Krzysztof Kozlowski,
Mauro Carvalho Chehab, Remo Senekowitsch, Tamir Duberstein,
Viresh Kumar, Wedson Almeida Filho, Xiangfei Ding, devicetree,
linux-acpi, linux-kernel, rust-for-linux, Björn Roy Baron,
Alice Ryhl, Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo,
Len Brown, Trevor Gross
On Thu, Jun 26, 2025 at 06:40:06PM +0100, Igor Korotin wrote:
>
>
> On 6/26/25 16:25, Danilo Krummrich wrote:
> > On 6/20/25 5:24 PM, Igor Korotin wrote:
> >> +impl DeviceId {
> >> + const ACPI_ID_LEN: usize = 16;
> >> +
> >> + /// Create a new device id from an ACPI 'id' string.
> >> + pub const fn new<const N: usize>(id: &[u8; N]) -> Self {
> >
> > Didn't notice before, but why was this silently changed from &CStr to
> > &[u8; N]
> > from v6 to v7?
> >
> >> + build_assert!(N <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
> >> + // Replace with `bindings::acpi_device_id::default()` once
> >> stabilized for `const`.
> >> + // SAFETY: FFI type is valid to be zero-initialized.
> >> + let mut acpi: bindings::acpi_device_id = unsafe
> >> { core::mem::zeroed() };
> >> + let mut i = 0;
> >> + while i < N {
> >> + acpi.id[i] = id[i];
> >> + i += 1;
> >> + }
> >> +
> >> + Self(acpi)
> >> + }
> >> +}
>
> In v6 I was asked to change assert! (runtime) to build_assert! (build time)
> It was as follows:
>
> > + pub const fn new(id: &'static CStr) -> Self {
> > + assert!(id.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
>
> but id.len() breaks const context and so build_assert! triggers
> assertion.
It does indeed, but I'm not sure why it does...
> If I needed to explicitly describe change from CStr to
> [u8;20], then it's my bad.
Yes, that's usually better. Otherwise reviewers might skip the changed part. In
this case I think it actually introduced a bug:
Checking for N <= Self::ACPI_ID_LEN it can happen that acpi_device_id::id is not
NULL terminated anymore, whereas before this was ensured by
CStr::as_bytes_with_nul(). See also [1].
I think we can easily fix this by just checking N < Self::ACPI_ID_LEN.
However, I'd still like to check why build_assert!() does not work with
CStr::len() in this case first.
[1] https://elixir.bootlin.com/linux/v6.15.3/source/drivers/acpi/bus.c#L899
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
` (9 preceding siblings ...)
2025-06-26 17:33 ` [PATCH v1 0/4] rust: Add basic I2C driver abstractions Igor Korotin
@ 2025-06-26 22:31 ` Danilo Krummrich
10 siblings, 0 replies; 23+ messages in thread
From: Danilo Krummrich @ 2025-06-26 22:31 UTC (permalink / raw)
To: Igor Korotin
Cc: Rafael J . Wysocki, Alex Gaynor, Greg Kroah-Hartman, Miguel Ojeda,
Rob Herring, Saravana Kannan, Alex Hung, Andrew Morton,
Jakub Kicinski, Jonathan Cameron, Krzysztof Kozlowski,
Mauro Carvalho Chehab, Remo Senekowitsch, Tamir Duberstein,
Viresh Kumar, Wedson Almeida Filho, Xiangfei Ding, devicetree,
linux-acpi, linux-kernel, rust-for-linux, Björn Roy Baron,
Alice Ryhl, Andreas Hindborg, Benno Lossin, Boqun Feng, Gary Guo,
Len Brown, Trevor Gross
On Fri, Jun 20, 2025 at 04:09:13PM +0100, Igor Korotin wrote:
> This patch series introduces support for ACPI match tables in Rust
> drivers.
Applied to driver-core-testing, thanks!
Once 0-day testing completed successfully, the patches are merged into
driver-core-next.
> Danilo Krummrich (3):
> rust: device: implement FwNode::is_of_node()
> samples: rust: platform: don't call as_ref() repeatedly
> samples: rust: platform: conditionally call Self::properties_parse()
>
> Igor Korotin (6):
> rust: acpi: add `acpi::DeviceId` abstraction
[ Always inline DeviceId::new() and use &'static CStr; slightly reword
commit message. - Danilo ]
> rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]`
[ Fix clippy warning if #[cfg(not(CONFIG_OF))]; fix checkpatch.pl line
length warnings. - Danilo ]
> rust: driver: Add ACPI id table support to Adapter trait
[ Fix clippy warning if #[cfg(not(CONFIG_OF))]; fix checkpatch.pl line
length warnings. - Danilo ]
> rust: platform: Set `OF_ID_TABLE` default to `None` in `Driver` trait
> rust: platform: Add ACPI match table support to `Driver` trait
[ Use 'LNUXBEEF' as ACPI ID. - Danilo ]
> samples: rust: add ACPI match table example to platform driver
[ Use 'LNUXBEEF' as ACPI ID. - Danilo ]
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2025-06-26 22:31 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 15:09 [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Igor Korotin
2025-06-20 15:15 ` [PATCH v8 1/9] rust: device: implement FwNode::is_of_node() Igor Korotin
2025-06-20 22:39 ` Danilo Krummrich
2025-06-24 20:46 ` Danilo Krummrich
2025-06-25 14:08 ` Rob Herring
2025-06-20 15:18 ` [PATCH v8 2/9] samples: rust: platform: don't call as_ref() repeatedly Igor Korotin
2025-06-21 3:28 ` Dirk Behme
2025-06-20 15:21 ` [PATCH v8 3/9] samples: rust: platform: conditionally call Self::properties_parse() Igor Korotin
2025-06-20 15:24 ` [PATCH v8 4/9] rust: acpi: add `acpi::DeviceId` abstraction Igor Korotin
2025-06-20 22:06 ` Danilo Krummrich
2025-06-23 9:03 ` Igor Korotin
2025-06-24 17:56 ` Rafael J. Wysocki
2025-06-26 15:25 ` Danilo Krummrich
2025-06-26 17:40 ` Igor Korotin
2025-06-26 18:28 ` Danilo Krummrich
2025-06-20 15:36 ` [PATCH v8 5/9] rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]` Igor Korotin
2025-06-20 15:39 ` [PATCH v8 6/9] rust: driver: Add ACPI id table support to Adapter trait Igor Korotin
2025-06-20 15:41 ` [PATCH v8 7/9] rust: platform: Set `OF_ID_TABLE` default to `None` in `Driver` trait Igor Korotin
2025-06-20 15:43 ` [PATCH v8 8/9] rust: platform: Add ACPI match table support to " Igor Korotin
2025-06-20 15:45 ` [PATCH v8 9/9] samples: rust: add ACPI match table example to platform driver Igor Korotin
2025-06-26 17:33 ` [PATCH v1 0/4] rust: Add basic I2C driver abstractions Igor Korotin
2025-06-26 17:47 ` Igor Korotin
2025-06-26 22:31 ` [PATCH v8 0/9] rust: Add ACPI match table support for Rust drivers Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).