From: Alice Ryhl <aliceryhl@google.com>
To: Beata Michalska <beata.michalska@arm.com>
Cc: ojeda@kernel.org, dakr@kernel.org, gregkh@linuxfoundation.org,
rafael@kernel.org, boqun@kernel.org, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu,
daniel.almeida@collabora.com, boris.brezillon@collabora.com,
work@onurozkan.dev, samitolvanen@google.com,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v2 1/3] rust: add runtime PM support
Date: Tue, 4 Aug 2026 08:13:13 +0000 [thread overview]
Message-ID: <anGfGWWxiuZj4i2U@google.com> (raw)
In-Reply-To: <20260721153617.869933-2-beata.michalska@arm.com>
On Tue, Jul 21, 2026 at 05:34:02PM +0200, Beata Michalska wrote:
> +/// Runtime PM callbacks implemented by a driver.
> +///
> +/// Defines the [`PMOps`] trait and its corresponding [`bindings::dev_pm_ops`].
> +///
> +/// Each generated C callback recovers the Rust bus device from the raw
> +/// `struct device *`, borrows the registered runtime PM payload, and delegates
> +/// to the matching [`PMOps`] trait method.
> +///
> +/// # Safety
> +///
> +/// `PMContext::<T>::PM_OPS` must only be installed for devices whose concrete
> +/// bus type is `T::DeviceType`, and whose runtime PM registration data was
> +/// installed by [`Registration::new`] for the same `T`.
> +///
> +macro_rules! define_pm_ops {
> + ($($name:ident $( : $desc:tt )? ),+ $(,)?) => {
> + $( define_pm_callback!( @parse_desc $name $( $desc )?); )+
> + define_pm_ops!(@common $( $name ), +);
> + };
> +
> + (@common $( $name:ident),+ ) => {
> + /// Runtime PM callbacks implemented by a driver
> + #[vtable]
> + pub trait PMOps: Sized
> + {
> + /// Type of a bus device
> + type DeviceType: AsBusDevice<device::Bound>;
> + /// Type of the data associated with a PM transitions:
> + type RuntimePayloadType: Send;
> +
> + $(
> + #[allow(missing_docs)]
> + // Callback-specific docs are provided by the generated `dev_pm_ops`
> + // contract on `PMOps`.
> +
> + fn $name<'a>(
> + _dev: &'a Self::DeviceType,
> + _payload: Option<Self::RuntimePayloadType>,
> + ) -> Result<Option<Self::RuntimePayloadType>, (Option<Self::RuntimePayloadType>, Error)> {
> + build_error!(VTABLE_DEFAULT_ERROR)
> + }
> + )+
> + }
> + paste!(
> + impl<'a, T:PMOps> PMContext<'a, T> {
> + /// Driver-provided runtime PM operations.
> + ///
> + /// A driver implements this trait to handle runtime PM
> + /// transitions for its device type.
> + ///
> + /// Each callback receives the device and the current payload.
> + /// On success, it returns the payload to keep for the next
> + /// transition. On failure, it returns the payload together
> + /// with the error so the previous, or otherwise sane state
> + /// can be preserved.
> + pub const PM_OPS: bindings::dev_pm_ops = bindings::dev_pm_ops {
> + $( [<$name>]: if T::[<HAS_ $name:upper>] {
> + Some([<$name _callback>]::<T>)
> + } else {
> + None
> + }, )+
> + ..PMOPS_NONE
> + };
> + }
> + );
> + }
> +}
> +
> +define_pm_ops!(
> + // PM state change
> + runtime_suspend,
> + runtime_resume,
> +);
I think using a macro to define this trait is overkill. Just write it
out:
pub trait PMOps: Sized {
/// Type of a bus device
type DeviceType: AsBusDevice<device::Bound>;
/// Type of the data associated with a PM transitions:
type RuntimePayloadType: Send;
fn runtime_suspend<'a>(
_dev: &'a Self::DeviceType,
_payload: Option<Self::RuntimePayloadType>,
) -> Result<Option<Self::RuntimePayloadType>, (Option<Self::RuntimePayloadType>, Error)> {
build_error!(VTABLE_DEFAULT_ERROR)
}
fn runtime_resume<'a>(
_dev: &'a Self::DeviceType,
_payload: Option<Self::RuntimePayloadType>,
) -> Result<Option<Self::RuntimePayloadType>, (Option<Self::RuntimePayloadType>, Error)> {
build_error!(VTABLE_DEFAULT_ERROR)
}
}
This is a lot easier to read.
Alice
next prev parent reply other threads:[~2026-08-04 8:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 15:34 [PATCH v2 0/3] Rust: add runtime PM support Beata Michalska
2026-07-21 15:34 ` [PATCH v2 1/3] rust: " Beata Michalska
2026-07-27 14:56 ` Onur Özkan
2026-07-29 9:07 ` Beata Michalska
2026-07-29 13:58 ` Onur Özkan
2026-08-03 9:30 ` Beata Michalska
2026-08-04 8:06 ` Alice Ryhl
2026-08-04 12:27 ` Beata Michalska
2026-08-04 8:13 ` Alice Ryhl [this message]
2026-08-04 12:27 ` Beata Michalska
2026-07-21 15:34 ` [PATCH v2 2/3] rust: platform: wire runtime PM callbacks Beata Michalska
2026-08-04 8:02 ` Alice Ryhl
2026-08-04 12:26 ` Beata Michalska
2026-08-04 9:16 ` Alice Ryhl
2026-08-04 12:28 ` Beata Michalska
2026-07-21 15:34 ` [PATCH v2 3/3] drm/tyr: enable runtime PM Beata Michalska
2026-07-27 15:00 ` Onur Özkan
2026-07-29 9:13 ` 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=anGfGWWxiuZj4i2U@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=beata.michalska@arm.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