[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251020223516.241050-9-dakr@kernel.org>
Date: Tue, 21 Oct 2025 00:34:30 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: gregkh@...uxfoundation.org,
rafael@...nel.org,
bhelgaas@...gle.com,
kwilczynski@...nel.org,
david.m.ertman@...el.com,
ira.weiny@...el.com,
leon@...nel.org,
acourbot@...dia.com,
ojeda@...nel.org,
alex.gaynor@...il.com,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
lossin@...nel.org,
a.hindborg@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu,
pcolberg@...hat.com
Cc: rust-for-linux@...r.kernel.org,
linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org,
Danilo Krummrich <dakr@...nel.org>
Subject: [PATCH 8/8] samples: rust: auxiliary: illustrate driver interaction
Illustrate how a parent driver of an auxiliary driver can take advantage
of the device context guarantees given by the auxiliary bus and
subsequently safely derive its device private data.
Signed-off-by: Danilo Krummrich <dakr@...nel.org>
---
samples/rust/rust_driver_auxiliary.rs | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index a5d67d4d9e83..5761ea314f44 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -5,10 +5,17 @@
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
use kernel::{
- auxiliary, c_str, device::Core, devres::Devres, driver, error::Error, pci, prelude::*,
+ auxiliary, c_str,
+ device::{Bound, Core},
+ devres::Devres,
+ driver,
+ error::Error,
+ pci,
+ prelude::*,
InPlaceModule,
};
+use core::any::TypeId;
use pin_init::PinInit;
const MODULE_NAME: &CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
@@ -43,6 +50,7 @@ fn probe(adev: &auxiliary::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<S
#[pin_data]
struct ParentDriver {
+ private: TypeId,
#[pin]
_reg0: Devres<auxiliary::Registration>,
#[pin]
@@ -63,6 +71,7 @@ impl pci::Driver for ParentDriver {
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
try_pin_init!(Self {
+ private: TypeId::of::<Self>(),
_reg0 <- auxiliary::Registration::new(pdev.as_ref(), AUXILIARY_NAME, 0, MODULE_NAME),
_reg1 <- auxiliary::Registration::new(pdev.as_ref(), AUXILIARY_NAME, 1, MODULE_NAME),
})
@@ -70,9 +79,10 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, E
}
impl ParentDriver {
- fn connect(adev: &auxiliary::Device) -> Result {
+ fn connect(adev: &auxiliary::Device<Bound>) -> Result {
let dev = adev.parent();
- let pdev: &pci::Device = dev.try_into()?;
+ let pdev: &pci::Device<Bound> = dev.try_into()?;
+ let drvdata = dev.drvdata::<Self>()?;
dev_info!(
dev,
@@ -82,6 +92,12 @@ fn connect(adev: &auxiliary::Device) -> Result {
pdev.device_id()
);
+ dev_info!(
+ dev,
+ "We have access to the private data of {:?}.\n",
+ drvdata.private
+ );
+
Ok(())
}
}
--
2.51.0
Powered by blists - more mailing lists