mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v6 0/3] Rust: add runtime PM support
@ 2026-11-24 11:34 Beata Michalska
  2026-11-24 11:34 ` [PATCH v6 1/3] rust: " Beata Michalska
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Beata Michalska @ 2026-11-24 11:34 UTC (permalink / raw)
  To: ojeda, dakr, gregkh, rafael, aliceryhl
  Cc: boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
	daniel.almeida, boris.brezillon, work, samitolvanen, acourbot,
	rust-for-linux, driver-core, linux-kernel, linux-pm

Hi All,

This series adds initial Rust support for Linux runtime PM.

The concept for Rust abstraction gets introduced in the first patch.
It provides callback registration, PM callback dispatch through PMOps trait,
scoped request helpers for common runtime PM operations and configuration
helpers.

The abstraction intends to keep the request semantics aligned with
the C runtime PM core.

Second patch integrates dev_pm_ops into the Rust platform driver abstraction,
enabling drivers to register PM callbacks with the core.

The last in the series is provided for demonstrative purposes
(not intended to be an actual merge material).

This has been lightly tested with the Tyr driver.

Based on drm-next.

---
v6:
- Moved the runtime PM API from rust/kernel/pm.rs to rust/kernel/device/pm.rs
- Reworked `Registration::new()` to initialize pinned registration data and
  return a `PinInit`; replaced the cloned, Arc-backed `PMContext` with one
  borrowed from the registration.
- Replaced the single `'static` runtime payload type with separate active
  and suspended payload types, plus registration data passed to callbacks
- Tied PM request scopes to the registration lifetime instead of device's one
- Added SRCU synchronization and intermediate enable/disable states so
  registration teardown waits for those operations to finish.
- Fixed `ResumeScope` and `AwakeScope` handling of `EINPROGRESS` for ASYNC
  and NOWAIT requests; rejected NOWAIT in the synchronous closure helpers.
- Changed enable ordering to apply PM configuration before marking the
  initial device state. Reset autosuspend and ignore-children settings on
  failure, disable and teardown.
- Updated naming, comments and documentation for the revised API and according
  to review suggestions.
- Removed the zero-valued `Sync` mode in favor of `Mode::empty()`, renamed
  `RuntimePMState::Resumed` to `Active`, and updated the PM ops type names.
- Reworked the Tyr example to use pinned hardware, PM and DRM registration
  data with explicit lifetime and drop ordering.

v5:
- Added doc comment for `rust_private`
- Dropped the `RuntimePMState::Unknown` as that was no longer needed
- Dropped masking the RPM mode in `ResumeScope::release_inner` as that is not
  necessary and brings in only confusion
- Fixed the behaviour of `AwakeScope::new` when the `Request::resume` returns
  `EINPROGRESS`.
- Note on `RetainScope`: the pairing of:
  `Request::get_noresume` ->`Request::put_noidle`
  is intentional to avoid mixing the expected behaviour of `Scope`s
- Cleaned up all the CONFIG_PM guards
- Switched the `PMPayload` to use `ManuallyDrop<>` instead of `Option<>`
- Apply the `PMConfig` only after successfully marking the devices devices PM
  state
- Dropped `#[pin_data]` for `RegistrationData`
- `Registration::new()` is now usafe to with the safety requirement that the
  `Registration` cannot be mem::forgotten
- Overall cleanup for attributes and formatting
- The `platform::Driver` trait is now sized to enable making the DevPMOps an
  associated constant.

v4:
- Simplified the PMOps/DevPMOps type model by making the bus adapter an
  associated type of PMOps, so DevPMOps is now parameterized only by the
  driver PM implementation type.
- Added DevPMOpsRef to pass typed, adapter-scoped dev_pm_ops references through
  bus registration code.
- Made DevPMOps own the generated dev_pm_ops table and require a static
  DevPMOps instance for Registration::new().
- Made the runtime PM payload mandatory.
- Replaced the PMContext enabled flag with an explicit Disabled/Enabled/Dead
  state machine to prevent re-enabling through stale PMContext clones during
  teardown.
- Updated with_get() to reject NOWAIT profiles in addition to ASYNC profiles.
- Changed AutoSuspendDelay to i32 to match the C runtime PM API.
- Renamed RuntimePMState variants to Rust-style names.
- Dropped the local EINPROGRESS error addition: already available
- Updated the platform PM wiring and Tyr example to the new DevPMOpsRef/static
  DevPMOps model.
- Cleaned up comments, docs, and minor typos.

v3:
- Dropped macros in favour of plain encoding of the PM callbacks
- Moved Mode to use kernel::impl_flags
- Generated PM callbacks, the stored payload, and the device cast
  are all monomorphized for the same (Adapter<T>, T) pair,
  with the registration sealing the contract by validating installed dev_pm_ops
- Platform PM wiring should be type-safe now
- Tracking runtime enable/disable state
- Few fixes for issues pointed out by Sami Tolvanen (samitolvanen@google.com),
  like making the registration teardown respecting the CONFIG_PM settings or
  fixing AwakeScope for async/no wait calls; Sami is also the person behind
  adding get_if_active variant (much appreciated)
- Changed base branch
v2:
- Moving away from the old PMContext<T, Dormant/Active> type-state design
- Introducing an explicit Registration<'a, T> object.
- PMContext now carries a lifetime and is derived from the registration
- Callback data is no longer recovered through driver data
- Simplified PMOps
- Runtime payload handling change
- Request helpers slightly extended

Beata Michalska (3):
  rust: add runtime PM support
  rust: platform: wire runtime PM callbacks
  drm/tyr: enable runtime PM

 drivers/base/base.h             |    6 +
 drivers/gpu/drm/tyr/driver.rs   |  220 ++++--
 drivers/gpu/drm/tyr/file.rs     |    7 +-
 rust/bindings/bindings_helper.h |    1 +
 rust/helpers/helpers.c          |    1 +
 rust/helpers/pm_runtime.c       |  101 +++
 rust/kernel/device.rs           |    1 +
 rust/kernel/device/pm.rs        | 1187 +++++++++++++++++++++++++++++++
 rust/kernel/platform.rs         |   35 +-
 9 files changed, 1499 insertions(+), 60 deletions(-)
 create mode 100644 rust/helpers/pm_runtime.c
 create mode 100644 rust/kernel/device/pm.rs

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-24 11:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 11:34 [PATCH v6 0/3] Rust: add runtime PM support Beata Michalska
2026-11-24 11:34 ` [PATCH v6 1/3] rust: " Beata Michalska
2026-11-24 11:34 ` [PATCH v6 2/3] rust: platform: wire runtime PM callbacks Beata Michalska
2026-11-24 11:34 ` [PATCH v6 3/3 DO NOT MERGE] drm/tyr: enable runtime PM Beata Michalska

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®