rust: Add ACPI match table support for Rust drivers
Subsystems (4)
cover rust: Add ACPI match table support for Rust drivers
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.
- A helper function is_of_node() for determining fwnode types.
- 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.
Igor Korotin (5):
rust: acpi: add acpi::DeviceId abstraction
rust: helpers: Add is_of_node helper function
rust: driver: Add ACPI id table support to Adapter trait
rust: platform: Add ACPI match table support to Driver trait
samples: rust: add ACPI match table example to platform driver
MAINTAINERS | 2 + rust/bindings/bindings_helper.h | 1 + rust/helpers/helpers.c | 1 + rust/helpers/of.c | 6 +++ rust/kernel/acpi.rs | 62 ++++++++++++++++++++++++++++ rust/kernel/driver.rs | 58 ++++++++++++++++++++++++-- rust/kernel/lib.rs | 1 + rust/kernel/platform.rs | 17 +++++++- samples/rust/rust_driver_platform.rs | 41 +++++++++++++++++- 9 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 rust/helpers/of.c create mode 100644 rust/kernel/acpi.rs
Signature · 1 line
2.43.0
PATCH 1/5 rust: acpi: add `acpi::DeviceId` abstraction
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.
--- MAINTAINERS | 1 + rust/kernel/acpi.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 64 insertions(+) create mode 100644 rust/kernel/acpi.rs
MAINTAINERS +1 -0
@@ -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
rust/kernel/acpi.rs new file +62 -0
62 lines not on this page · raw message
rust/kernel/lib.rs +1 -0
@@ -51,6 +51,7 @@pub use ffi; +pub mod acpi;pub mod alloc;#[cfg( CONFIG_BLOCK )] pub mod block;
Signature · 1 line
2.43.0
PATCH 2/5 rust: helpers: Add `is_of_node` helper function
In reply to Igor KorotinAdd a helper function to determine whether a given device appears to be an Open Firmware (OF) node.
This function will be used in Rust driver abstractions to support both ACPI and OF matching simultaneously in subsequent patches.
--- MAINTAINERS | 1 + rust/helpers/helpers.c | 1 + rust/helpers/of.c | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 rust/helpers/of.c
MAINTAINERS +1 -0
@@ -18215,6 +18215,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/
rust/helpers/helpers.c +1 -0
@@ -21,6 +21,7 @@#include "jump_label.c" #include "kunit.c" #include "mutex.c" +#include "of.c" #include "page.c" #include "platform.c" #include "pci.c"
rust/helpers/of.c new file +6 -0
@@ -0,0 +1,6 @@ +#include <linux/of.h> + +bool rust_helper_is_of_node (const struct fwnode_handle *fwnode) +{ +return is_of_node (fwnode); +}
Signature · 1 line
2.43.0
PATCH 4/5 rust: platform: Add ACPI match table support to `Driver` trait
In reply to Igor KorotinExtend 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.
To avoid breaking compilation, a stub ACPI match table definition is added to the Rust sample platform driver. Functional support for ACPI matching in the sample driver will be provided in a follow-up patch.
--- rust/kernel/platform.rs | 14 ++++++++++++-- samples/rust/rust_driver_platform.rs | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-)
rust/kernel/platform.rs +12 -2
@@ -39,12 +39,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`.
@@ -98,7 +104,7 @@ fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> { }fn acpi_id_table () ->Option <acpi::IdTable <Self ::IdInfo >> { -None +T ::ACPI_ID_TABLE } }
@@ -129,7 +135,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; ///
@@ -145,6 +151,7 @@ macro_rules! module_platform_driver {/// 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>,
@@ -165,6 +172,9 @@ pub trait Driver: Send {/// The table of OF device ids supported by the driver. const OF_ID_TABLE :Option <of::IdTable <Self ::IdInfo >>; +/// The table of ACPI device ids supported by the driver. +const ACPI_ID_TABLE :Option <acpi::IdTable <Self ::IdInfo >>; +/// Platform driver probe. /// /// Called when a new platform device is added or discovered.
samples/rust/rust_driver_platform.rs +2 -1
@@ -2,7 +2,7 @@//! Rust Platform driver sample. -use kernel::{c_str, device::Core , of, platform, prelude::*, types::ARef }; +use kernel::{acpi, c_str, device::Core , of, platform, prelude::*, types::ARef };struct SampleDriver { pdev:ARef <platform::Device >,
@@ -20,6 +20,7 @@ struct SampleDriver {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 >> =None ;fn probe ( pdev: &platform::Device<Core>,
Signature · 1 line
2.43.0
Danilo Krummrich
maintainerQuoted 16 lines · Igor Korotin
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 newacpi::DeviceIdabstraction for working withstruct acpi_device_id.
- A helper functionis_of_node()for determining fwnode types.
- Updates to the coreAdaptertrait andplatform::Driverto support optional ACPI ID tables.
- A sample implementation in the Rust platform driver, demonstrating multi-bus matching.
Quoted 5 lines
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.
Thanks this is great!
Unfortunately, it seems that something went wrong sending this patch series. Patches 3 and 5 are missing on my end (and on the corresponding lists as well). Can you please resend?
Also, technically this series is a v2; patch 1 differs from the one you sent originally -- please include a changelog.
Quoted 5 lines
Thanks this is great!
Unfortunately, it seems that something went wrong sending this patch series. Patches 3 and 5 are missing on my end (and on the corresponding lists as well).
Yes, I know. Gmail has blocked me from sending any letters. I probably hit some limit. It will likely unblock me sometime today or tomorrow.
Quoted 2 lines
Also, technically this series is a v2; patch 1 differs from the one you sent originally -- please include a changelog.
Because of this Gmail issue, I need to clarify the right course of action to avoid being blocked again:
Should I resend the whole series as PATCH v2 with a changelog?
Thanks
Igor
Danilo Krummrich
maintainerQuoted 1 line · Igor Korotin
Should I resend the whole series as PATCH v2 with a changelog?
Yes, please do so.