Message ID | 20250605165231.3663810-1-igor.korotin.linux@gmail.com |
---|---|
State | New |
Headers | show |
Series | rust: Add ACPI match table support for Rust drivers | expand |
On Thu, Jun 05, 2025 at 05:52:31PM +0100, Igor Korotin wrote: > 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 | 40 +++++++++++++++++++++++++++- > 1 file changed, 39 insertions(+), 1 deletion(-) > > diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs > index e3992e7a71e9..ee0780c1d6ae 100644 > --- a/samples/rust/rust_driver_platform.rs > +++ b/samples/rust/rust_driver_platform.rs > @@ -17,10 +17,48 @@ 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(c_str!("TEST4321")), Info(0))] Can you please explain add a comment explaining how to make this probe? In the cover letter you mention: "Tested using QEMU with a custom SSDT that creates an ACPI device matching the sample Rust platform driver." > +); > + > +/// OF/ACPI match tables for Platform Driver implementation > +/// > +/// The platform::Driver requires declaration of both OF_ID_TABLE and > +/// ACPI_ID_TABLE, but if driver is not going to use either of them > +/// it can implement one of them or both as None. > +/// > +/// # Example: > +/// > +///``` > +/// impl platform::Driver for SampleDriver { > +/// type IdInfo = Info; > +/// const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None; > +/// const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = None; > +/// > +/// 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"); > +/// > +/// if let Some(info) = info { > +/// dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info.0); > +/// } > +/// > +/// let drvdata = KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?; > +/// > +/// Ok(drvdata.into()) > +/// } > +/// } > +///``` I assume you want to make clear that both the ACPI and OF table are optional; not sure of that's required given their type is Option<...>. But I'm fine having this additional comment and example. Please make sure that it compiles though and remove everything unnecessary from probe() please. > + > 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; > + const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE); > > fn probe( > pdev: &platform::Device<Core>, > -- > 2.43.0 >
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs index e3992e7a71e9..ee0780c1d6ae 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -17,10 +17,48 @@ 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(c_str!("TEST4321")), Info(0))] +); + +/// OF/ACPI match tables for Platform Driver implementation +/// +/// The platform::Driver requires declaration of both OF_ID_TABLE and +/// ACPI_ID_TABLE, but if driver is not going to use either of them +/// it can implement one of them or both as None. +/// +/// # Example: +/// +///``` +/// impl platform::Driver for SampleDriver { +/// type IdInfo = Info; +/// const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None; +/// const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = None; +/// +/// 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"); +/// +/// if let Some(info) = info { +/// dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info.0); +/// } +/// +/// let drvdata = KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?; +/// +/// Ok(drvdata.into()) +/// } +/// } +///``` + 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; + const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE); fn probe( pdev: &platform::Device<Core>,
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 | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)