From: Matteo Kloiber <kernel@matt3o12.de>
To: Danilo Krummrich <dakr@kernel.org>,
Alexandre Courbot <acourbot@nvidia.com>,
Alice Ryhl <aliceryhl@google.com>,
Abdiel Janulgue <abdiel.janulgue@gmail.com>,
Robin Murphy <robin.murphy@arm.com>,
Andreas Hindborg <a.hindborg@kernel.org>,
Gary Guo <gary@garyguo.net>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev,
linux-kernel@vger.kernel.org,
"Matteo Kloiber" <kernel@matt3o12.de>
Subject: [RFC PATCH v2 01/10] rust: pci, platform: pass InitTokens to probe()
Date: Sun, 29 Nov 2026 23:24:20 +0100 [thread overview]
Message-ID: <20261129222429.2380652-2-kernel@matt3o12.de> (raw)
In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de>
Some capabilities should only be available to a driver while it binds
to a device, for example configuring the device for DMA before any
memory is allocated or mapped. A probe-time token lets the type system
enforce such ordering, but adding a new argument to probe() for every
token would touch every driver each time.
Add an InitTokens struct to the PCI and platform buses and pass it to
Driver::probe(). Buses add new tokens as fields of this struct. It is
marked #[non_exhaustive], so drivers destructure it with `..` and
adding tokens later does not break them.
The struct carries no tokens yet. Update all drivers, samples and
doctests to accept and ignore it.
Suggested-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/DLR1JCUWS824.35QJU45D2W9ZE@nvidia.com
Signed-off-by: Matteo Kloiber <kernel@matt3o12.de>
---
drivers/cpufreq/rcpufreq_dt.rs | 1 +
drivers/gpu/drm/tyr/driver.rs | 1 +
drivers/gpu/nova-core/driver.rs | 1 +
drivers/pwm/pwm_th1520.rs | 1 +
rust/kernel/cpufreq.rs | 1 +
rust/kernel/io/mem.rs | 2 ++
rust/kernel/pci.rs | 10 +++++++++-
rust/kernel/platform.rs | 10 +++++++++-
samples/rust/rust_debugfs.rs | 1 +
samples/rust/rust_dma.rs | 1 +
samples/rust/rust_driver_auxiliary.rs | 1 +
samples/rust/rust_driver_pci.rs | 1 +
samples/rust/rust_driver_platform.rs | 1 +
samples/rust/rust_driver_sriov/pf.rs | 1 +
samples/rust/rust_driver_sriov/vf.rs | 1 +
samples/rust/rust_i2c_client.rs | 1 +
samples/rust/rust_soc.rs | 1 +
17 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
index 2b1f18b7a1e7..a6e314f4d809 100644
--- a/drivers/cpufreq/rcpufreq_dt.rs
+++ b/drivers/cpufreq/rcpufreq_dt.rs
@@ -212,6 +212,7 @@ impl platform::Driver for CPUFreqDTDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
+ _tokens: platform::InitTokens<'bound>,
_id_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
cpufreq::Registration::<CPUFreqDTDriver>::new_foreign_owned(pdev.as_ref())?;
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 557f2ec0a767..7650ade4ad72 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -119,6 +119,7 @@ impl platform::Driver for TyrPlatformDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
+ _tokens: platform::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
pin_init::pin_init_scope(move || {
diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
index bea1b1b0844c..365e77ff0cc4 100644
--- a/drivers/gpu/nova-core/driver.rs
+++ b/drivers/gpu/nova-core/driver.rs
@@ -101,6 +101,7 @@ impl pci::Driver for NovaCoreDriver {
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
+ _tokens: pci::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
dev_dbg!(pdev, "Probe Nova Core GPU driver.\n");
diff --git a/drivers/pwm/pwm_th1520.rs b/drivers/pwm/pwm_th1520.rs
index 728993998446..2486333c4a91 100644
--- a/drivers/pwm/pwm_th1520.rs
+++ b/drivers/pwm/pwm_th1520.rs
@@ -316,6 +316,7 @@ impl platform::Driver for Th1520PwmPlatformDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
+ _tokens: platform::InitTokens<'bound>,
_id_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
let dev = pdev.as_ref();
diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index b75d692846a2..0032264fe72c 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -916,6 +916,7 @@ fn register_em(_policy: &mut Policy) {
///
/// fn probe<'bound>(
/// pdev: &'bound platform::Device<Core<'_>>,
+/// _tokens: platform::InitTokens<'bound>,
/// _id_info: Option<&'bound Self::IdInfo>,
/// ) -> impl PinInit<Self, Error> + 'bound {
/// cpufreq::Registration::<SampleDriver>::new_foreign_owned(pdev.as_ref())?;
diff --git a/rust/kernel/io/mem.rs b/rust/kernel/io/mem.rs
index 32a919099dcd..50dedd32d1a7 100644
--- a/rust/kernel/io/mem.rs
+++ b/rust/kernel/io/mem.rs
@@ -70,6 +70,7 @@ pub(crate) unsafe fn new(device: &'a Device<Bound>, resource: &'a Resource) -> S
///
/// fn probe<'bound>(
/// pdev: &'bound platform::Device<Core<'_>>,
+ /// _tokens: platform::InitTokens<'bound>,
/// info: Option<&'bound Self::IdInfo>,
/// ) -> impl PinInit<Self, Error> + 'bound {
/// let offset = 0; // Some offset.
@@ -130,6 +131,7 @@ pub fn iomap_exclusive_sized<const SIZE: usize>(self) -> Result<ExclusiveIoMem<'
///
/// fn probe<'bound>(
/// pdev: &'bound platform::Device<Core<'_>>,
+ /// _tokens: platform::InitTokens<'bound>,
/// info: Option<&'bound Self::IdInfo>,
/// ) -> impl PinInit<Self, Error> + 'bound {
/// let offset = 0; // Some offset.
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 04a6d240afb2..1d61fcb64b03 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -147,7 +147,7 @@ extern "C" fn probe_callback(
let info = unsafe { id.info_unchecked_opt::<T::IdInfo>() };
from_result(|| {
- let data = T::probe(pdev, info);
+ let data = T::probe(pdev, InitTokens { _p: PhantomData }, info);
pdev.as_ref().set_drvdata(data)?;
Ok(0)
@@ -451,6 +451,12 @@ macro_rules! pci_device_table {
};
}
+/// Initialization tokens passed to a PCI driver's [`Driver::probe`] callback.
+#[non_exhaustive]
+pub struct InitTokens<'bound> {
+ _p: PhantomData<&'bound ()>,
+}
+
/// The PCI driver trait.
///
/// # Examples
@@ -479,6 +485,7 @@ macro_rules! pci_device_table {
///
/// fn probe<'bound>(
/// _pdev: &'bound pci::Device<Core<'_>>,
+/// _tokens: pci::InitTokens<'bound>,
/// _id_info: Option<&'bound Self::IdInfo>,
/// ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
/// Err(ENODEV)
@@ -513,6 +520,7 @@ pub trait Driver {
/// attempt to initialize the device here.
fn probe<'bound>(
dev: &'bound Device<device::Core<'_>>,
+ tokens: InitTokens<'bound>,
id_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index ac0a012ae1bb..a7b33e229a30 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -104,7 +104,7 @@ extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ff
let info = unsafe { <Self as driver::Adapter>::id_info(pdev.as_ref()) };
from_result(|| {
- let data = T::probe(pdev, info);
+ let data = T::probe(pdev, InitTokens { _p: PhantomData }, info);
pdev.as_ref().set_drvdata(data)?;
Ok(0)
@@ -159,6 +159,12 @@ macro_rules! module_platform_driver {
};
}
+/// Initialization tokens passed to a platform driver's [`Driver::probe`] callback.
+#[non_exhaustive]
+pub struct InitTokens<'bound> {
+ _p: PhantomData<&'bound ()>,
+}
+
/// The platform driver trait.
///
/// Drivers must implement this trait in order to get a platform driver registered.
@@ -199,6 +205,7 @@ macro_rules! module_platform_driver {
///
/// fn probe<'bound>(
/// _pdev: &'bound platform::Device<Core<'_>>,
+/// _tokens: platform::InitTokens<'bound>,
/// _id_info: Option<&'bound Self::IdInfo>,
/// ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
/// Err(ENODEV)
@@ -229,6 +236,7 @@ pub trait Driver {
/// Implementers should attempt to initialize the device here.
fn probe<'bound>(
dev: &'bound Device<device::Core<'_>>,
+ tokens: InitTokens<'bound>,
id_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;
diff --git a/samples/rust/rust_debugfs.rs b/samples/rust/rust_debugfs.rs
index 77c19a437695..d0cc2b624835 100644
--- a/samples/rust/rust_debugfs.rs
+++ b/samples/rust/rust_debugfs.rs
@@ -122,6 +122,7 @@ impl platform::Driver for RustDebugFs {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
+ _tokens: platform::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
RustDebugFs::new(pdev).pin_chain(|this| {
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index 804d55a63005..b6a36d10bf74 100644
--- a/samples/rust/rust_dma.rs
+++ b/samples/rust/rust_dma.rs
@@ -77,6 +77,7 @@ impl pci::Driver for DmaSampleDriver {
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
+ _tokens: pci::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
pin_init::pin_init_scope(move || {
diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index 6cff9bf8c80c..96954f001b13 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -99,6 +99,7 @@ impl pci::Driver for ParentDriver {
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
+ _tokens: pci::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
try_pin_init!(ParentData {
diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
index 50c8709739c6..33b864d2cbea 100644
--- a/samples/rust/rust_driver_pci.rs
+++ b/samples/rust/rust_driver_pci.rs
@@ -148,6 +148,7 @@ impl pci::Driver for SampleDriver {
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
+ _tokens: pci::InitTokens<'bound>,
info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
let vendor = pdev.vendor_id();
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index 710145b3605a..80b08d32435f 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -105,6 +105,7 @@ impl platform::Driver for SampleDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
+ _tokens: platform::InitTokens<'bound>,
info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
let dev = pdev.as_ref();
diff --git a/samples/rust/rust_driver_sriov/pf.rs b/samples/rust/rust_driver_sriov/pf.rs
index 8f9958683528..3df204c9951c 100644
--- a/samples/rust/rust_driver_sriov/pf.rs
+++ b/samples/rust/rust_driver_sriov/pf.rs
@@ -69,6 +69,7 @@ impl pci::Driver for SamplePfDriver {
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
+ _tokens: pci::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
try_pin_init!(PfDriverData {
diff --git a/samples/rust/rust_driver_sriov/vf.rs b/samples/rust/rust_driver_sriov/vf.rs
index 256b1b3dfab7..c4bfca1a1c31 100644
--- a/samples/rust/rust_driver_sriov/vf.rs
+++ b/samples/rust/rust_driver_sriov/vf.rs
@@ -31,6 +31,7 @@ impl pci::Driver for SampleVfDriver {
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
+ _tokens: pci::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
dev_info!(
diff --git a/samples/rust/rust_i2c_client.rs b/samples/rust/rust_i2c_client.rs
index c8a23875ef5b..93b207699860 100644
--- a/samples/rust/rust_i2c_client.rs
+++ b/samples/rust/rust_i2c_client.rs
@@ -110,6 +110,7 @@ impl platform::Driver for SampleDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<device::Core<'_>>,
+ _tokens: platform::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
dev_info!(
diff --git a/samples/rust/rust_soc.rs b/samples/rust/rust_soc.rs
index f5e5f2f9adf7..f54c173fed94 100644
--- a/samples/rust/rust_soc.rs
+++ b/samples/rust/rust_soc.rs
@@ -41,6 +41,7 @@ impl platform::Driver for SampleSocDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
+ _tokens: platform::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
dev_dbg!(pdev, "Probe Rust SoC driver sample.\n");
--
2.51.2
next prev parent reply other threads:[~2026-11-29 22:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 22:24 [RFC PATCH v2 00/10] rust: dma: require device configuration before DMA Matteo Kloiber
2026-11-29 22:24 ` Matteo Kloiber [this message]
2026-11-29 22:24 ` [RFC PATCH v2 02/10] rust: dma: add Setup, Params and Handle Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 03/10] gpu: nova-core: configure DMA through dma::Setup Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 04/10] drm/tyr: " Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 05/10] samples: rust: dma: " Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 06/10] rust: dma: require a Handle for coherent allocations Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 07/10] rust: scatterlist: require a dma::Handle for SGTable::new() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 08/10] rust: iommu: require a dma::Handle for IoPageTable::new() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 09/10] rust: drm: require a dma::Handle for shmem sg_table() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 10/10] rust: dma: remove the Device trait and its setters Matteo Kloiber
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=20261129222429.2380652-2-kernel@matt3o12.de \
--to=kernel@matt3o12.de \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/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.