From: Beata Michalska <beata.michalska@arm.com>
To: ojeda@kernel.org, dakr@kernel.org, gregkh@linuxfoundation.org,
rafael@kernel.org
Cc: boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com,
lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
tmgross@umich.edu, daniel.almeida@collabora.com,
boris.brezillon@collabora.com, work@onurozkan.dev,
samitolvanen@google.com, acourbot@nvidia.com,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: [PATCH v3 2/3] rust: platform: wire runtime PM callbacks
Date: Wed, 26 Aug 2026 15:10:56 +0200 [thread overview]
Message-ID: <20260826131213.1820408-3-beata.michalska@arm.com> (raw)
In-Reply-To: <20260826131213.1820408-1-beata.michalska@arm.com>
Allow platform drivers to provide Rust runtime PM callbacks by exposing
typed `dev_pm_ops` through the platform driver trait and installing them
via the generated `platform_driver`.
Add a platform-specific constructor for `pm::DevPMOps` that ties the
PM callbacks to `platform::Adapter<T>` and requires callbacks to use
a bound platform device. This keeps the unsafe generic PM ops constructor
internal while letting platform drivers opt into runtime PM without
affecting drivers that do not use it.
The platform glue only wires the callback table into the C driver model;
ownership of the callback payload and runtime PM teardown remain with
the pm module.
Signed-off-by: Beata Michalska <beata.michalska@arm.com>
---
rust/kernel/platform.rs | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 9b362e0495d3..3da2a5ed4857 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -72,6 +72,10 @@ unsafe fn register(
None => core::ptr::null(),
};
+ let pm_ops = T::dev_pm_ops()
+ .map(|ops| ops.as_raw())
+ .unwrap_or(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();
@@ -79,6 +83,7 @@ unsafe fn register(
(*pdrv.get()).remove = Some(Self::remove_callback);
(*pdrv.get()).driver.of_match_table = of_table;
(*pdrv.get()).driver.acpi_match_table = acpi_table;
+ (*pdrv.get()).driver.pm = pm_ops;
}
// SAFETY: `pdrv` is guaranteed to be a valid `DriverType`.
@@ -195,6 +200,7 @@ macro_rules! module_platform_driver {
/// impl platform::Driver for MyDriver {
/// type IdInfo = ();
/// type Data<'bound> = Self;
+///
/// const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
/// const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
///
@@ -224,6 +230,14 @@ pub trait Driver {
/// The table of ACPI device ids supported by the driver.
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = None;
+ /// Provides driver's PM callbacks, if any.
+ fn dev_pm_ops() -> Option<crate::pm::DevPMOps<Adapter<Self>, Self>>
+ where
+ Self: Sized,
+ {
+ None
+ }
+
/// Platform driver probe.
///
/// Called when a new platform device is added or discovered.
@@ -571,3 +585,19 @@ unsafe impl Sync for Device {}
// SAFETY: Same as `Device<Normal>` -- the underlying `struct platform_device` is the same;
// `Bound` is a zero-sized type-state marker that does not affect thread safety.
unsafe impl Sync for Device<device::Bound> {}
+
+#[allow(clippy::new_without_default)]
+impl<T> crate::pm::DevPMOps<Adapter<T>, T>
+where
+ T: Driver + crate::pm::PMOps<Adapter<T>, DeviceType = Device<device::Bound>>,
+{
+ /// Creates a platform driver's runtime PM callbacks for `T`.
+ ///
+ /// This constructor is available only when `T` is a platform driver and
+ /// its runtime PM callbacks accept a bound platform device.
+ pub const fn new() -> Self {
+ // SAFETY: `Adapter<T>` is the platform bus adapter for `T`, and the
+ // bound above forces PM callbacks to receive a platform bound device.
+ unsafe { crate::pm::DevPMOps::new_unchecked() }
+ }
+}
--
2.43.0
next prev parent reply other threads:[~2026-08-26 13:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 13:10 [PATCH v3 0/3] Rust: add runtime PM support Beata Michalska
2026-08-26 13:10 ` [PATCH v3 1/3] rust: " Beata Michalska
2026-08-29 0:37 ` Sami Tolvanen
2026-08-26 13:10 ` Beata Michalska [this message]
2026-08-26 13:10 ` [PATCH v3 3/3 DO NOT MERGE] drm/tyr: enable runtime PM Beata Michalska
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=20260826131213.1820408-3-beata.michalska@arm.com \
--to=beata.michalska@arm.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=boris.brezillon@collabora.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox