From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.216.248.203 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991104; b=EallF2V6PaCCPrSZAh+4u2EgL6+Wi3AyO+E8tqwlxkLf7DY6SND3vKmBmE17yFzYVgzq 8UQ1R2kmSI/A6m4RX00d93e5RQ2xzRrOwyKnYP/ON1Aw8v5P0D0AD/YBpToZX6OqLxT2a iKHNgFvPEEItCLQQszOVTgj57gEQXXxIXPCVm/9VOz4mT/GIgLI0rpWILP8qh4gw+g0XV 8MeY06FVNMtAHkgqdb9G/GtX1+E/Cube2fkkS92paUV2vqBoQQK+Tqlhsn4S1LJnb5Eul jtBONNIjPEireGjt0AGr7dsiC3EiAKYLUU3WVBXmoBFR+YF4l1IxkVACTYu8Lf85rLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991104; h=DMARC-Filter:From:DKIM-Signature:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=/YSzhlwmB2W0Cz7opLJDRjkQY4St95mwWOp738y23oo=; b=gTWL7OcoGDrby5jo2cVJ5f9Gc88Cl4haS9Virbd3Q548AARg/bLpxs56hBj7AfOT24bd YURLETCZRv0IbHufxlo+xy/YhPQ1OAm8Qakq2n+slARQE5GayUiDatSbhVxOY98KzvsCT trq7Ew3PCf0UztQBgFKJ9ybQGi/mpxCB3mN0gWi9KgL5p9I2Y6JSo/q7IG3jnSipD4Fxo mnsMzuDj1N5pCkYcLpq//l5bt7STfYa8pejyRy7mc9li8Ry3AvwwuuoJ7T/5s4rNktX0p pnCVb389zzTasilzoUpCXhLPB7JAvv4LSBh3iPzAMNtHYlYHUTVfPFupH09ZAKr7Jew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=matt3o12.de; spf=pass smtp.mailfrom=matt3o12.de; dkim=pass header.d=matt3o12.de header.i=@matt3o12.de header.a=rsa-sha256 header.s=securedbylima-20230709 header.b=chYhVerL; arc=none smtp.remote-ip=91.216.248.203 Received: from mx1.mail-out.lima-city.de (mx1.mail-out.lima-city.de [91.216.248.203]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51170606A329; Sun, 29 Nov 2026 22:25:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51170606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=matt3o12.de header.i=@matt3o12.de header.a=rsa-sha256 header.s=securedbylima-20230709 header.b=chYhVerL From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1795991095; bh=5umRNTKgLhhCwHT+547B/qgykx9smPKwLS/hvLc/dHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=chYhVerLACUWBqXJGDvm6XF7GgreQE/+gB06qyl6/Rg7HN/rHR6xNr8+DYCpRtzOH fGQIAvX/qOvPKTA85uHsMPBOrfJl39KJYtDpgAXlSSLLIQEzM0uJEzpBT85U9W/iJ9 h+QdaWJWSnFJ78tftZwXoX0xTruGo5BwWB2fS7vwEKeiJs7Wrm2PCh8Pnw2287aElc Q8DZFh2jThMQHZHRftdGqI/JYuBSNkRs+LpEPtx1qb3XRLWGT9tNpt4K6PwR1ORlok pjXbHMXPk0DcJze+5ubMb72HivyHE+brdShWcYOMVpYo8P8ameoaj0F0nWC08nUuUL Oc4UwX42ZZENQ== To: Danilo Krummrich , Alexandre Courbot , Alice Ryhl , Abdiel Janulgue , Robin Murphy , Andreas Hindborg , Gary Guo Cc: Daniel Almeida , Miguel Ojeda , David Airlie , Simona Vetter , Bjorn Helgaas , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Greg Kroah-Hartman , 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 Subject: [RFC PATCH v2 01/10] rust: pci, platform: pass InitTokens to probe() Date: Sun, 29 Nov 2026 23:24:20 +0100 Message-ID: <20261129222429.2380652-2-kernel@matt3o12.de> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de> References: <20261129222429.2380652-1-kernel@matt3o12.de> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Link: https://lore.kernel.org/DLR1JCUWS824.35QJU45D2W9ZE@nvidia.com Signed-off-by: Matteo Kloiber --- 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>, + _tokens: platform::InitTokens<'bound>, _id_info: Option<&'bound Self::IdInfo>, ) -> impl PinInit + 'bound { cpufreq::Registration::::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>, + _tokens: platform::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, + _tokens: pci::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, + _tokens: platform::InitTokens<'bound>, _id_info: Option<&'bound Self::IdInfo>, ) -> impl PinInit + '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>, +/// _tokens: platform::InitTokens<'bound>, /// _id_info: Option<&'bound Self::IdInfo>, /// ) -> impl PinInit + 'bound { /// cpufreq::Registration::::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, resource: &'a Resource) -> S /// /// fn probe<'bound>( /// pdev: &'bound platform::Device>, + /// _tokens: platform::InitTokens<'bound>, /// info: Option<&'bound Self::IdInfo>, /// ) -> impl PinInit + 'bound { /// let offset = 0; // Some offset. @@ -130,6 +131,7 @@ pub fn iomap_exclusive_sized(self) -> Result( /// pdev: &'bound platform::Device>, + /// _tokens: platform::InitTokens<'bound>, /// info: Option<&'bound Self::IdInfo>, /// ) -> impl PinInit + '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::() }; 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>, +/// _tokens: pci::InitTokens<'bound>, /// _id_info: Option<&'bound Self::IdInfo>, /// ) -> impl PinInit, Error> + 'bound { /// Err(ENODEV) @@ -513,6 +520,7 @@ pub trait Driver { /// attempt to initialize the device here. fn probe<'bound>( dev: &'bound Device>, + tokens: InitTokens<'bound>, id_info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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 { ::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>, +/// _tokens: platform::InitTokens<'bound>, /// _id_info: Option<&'bound Self::IdInfo>, /// ) -> impl PinInit, 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>, + tokens: InitTokens<'bound>, id_info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, + _tokens: platform::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit + '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>, + _tokens: pci::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, + _tokens: pci::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, + _tokens: pci::InitTokens<'bound>, info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, + _tokens: platform::InitTokens<'bound>, info: Option<&'bound Self::IdInfo>, ) -> impl PinInit + '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>, + _tokens: pci::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, + _tokens: pci::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit + '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>, + _tokens: platform::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit + '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>, + _tokens: platform::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit + 'bound { dev_dbg!(pdev, "Probe Rust SoC driver sample.\n"); -- 2.51.2