From: Daniel Almeida <daniel.almeida@collabora.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
dri-devel@lists.freedesktop.org,
Detlev Casanova <detlev.casanova@collabora.com>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>
Subject: [PATCH 6/7] rust: reset: add SharedResetControl::get_array() and get_array_optional()
Date: Thu, 26 Nov 2026 13:04:33 -0300 [thread overview]
Message-ID: <20261126-b4-rust-reset-v1-6-9c4c3d029080@collabora.com> (raw)
In-Reply-To: <20261126-b4-rust-reset-v1-0-9c4c3d029080@collabora.com>
Add SharedResetControl::get_array() and get_array_optional(), which get
all the reset lines in the resets property of a device as a single
shared reset control, as devm_reset_control_array_get_shared() and
devm_reset_control_array_get_optional_shared() do in C. This is for
drivers that assert and deassert all the shared reset lines of their
device together.
Nothing uses them yet.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
rust/kernel/reset.rs | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
diff --git a/rust/kernel/reset.rs b/rust/kernel/reset.rs
index 4d241ec6e549..85c51fc153ac 100644
--- a/rust/kernel/reset.rs
+++ b/rust/kernel/reset.rs
@@ -568,6 +568,8 @@ fn drop(&mut self) {
///
/// - [`reset_control_get_shared()`]
/// - [`reset_control_get_optional_shared()`]
+/// - `fwnode_reset_control_array_get()` with the `RESET_CONTROL_SHARED` or
+/// `RESET_CONTROL_OPTIONAL_SHARED` flag
///
/// It is treated as an opaque token that may only be accessed using C API methods (e.g., it may be
/// `NULL` if the C API returns `NULL`). The [`SharedResetControl`] owns the reference that the
@@ -639,6 +641,95 @@ pub fn get_optional(dev: &'a Device<Bound>, name: Option<&CStr>) -> Result<Self>
})
}
+ /// Gets the reset lines of `dev` as one [`SharedResetControl`], as [`Self::get_array`] does
+ /// or, if `optional` is set, as [`Self::get_array_optional`] does.
+ fn get_array_internal(dev: &'a Device<Bound>, optional: bool) -> Result<Self> {
+ let flags = if optional {
+ bindings::reset_control_flags_RESET_CONTROL_OPTIONAL_SHARED
+ } else {
+ bindings::reset_control_flags_RESET_CONTROL_SHARED
+ };
+
+ let fwnode = dev
+ .fwnode()
+ .map_or(ptr::null_mut(), |fwnode| fwnode.as_raw());
+
+ // SAFETY: `fwnode` is the firmware node of `dev` or `NULL`, which
+ // `fwnode_reset_control_array_get()` checks for.
+ let inner = unsafe { bindings::fwnode_reset_control_array_get(fwnode, flags) };
+ let inner = from_err_ptr(inner)?;
+
+ // INVARIANT: `inner` comes from a successful call to `fwnode_reset_control_array_get()`
+ // with one of the two flags above, and the returned value owns the reference from that
+ // call.
+ Ok(Self {
+ inner,
+ _phantom: PhantomData,
+ })
+ }
+
+ /// Gets the reset lines listed in the `resets` property of `dev` as one
+ /// [`SharedResetControl`].
+ ///
+ /// Its operations act on all the lines, in no guaranteed order. If one of them fails on a
+ /// line, the opposite operation is run on the lines it had already succeeded on. This
+ /// includes the assert that is done on drop. The caller only gets the error from the line
+ /// that failed, while errors from the opposite operation are discarded.
+ ///
+ /// A [`SharedResetControl::assert`] that fails on one line therefore leaves the control
+ /// holding its deasserts on the other lines. The control is in the [`Unknown`] state then,
+ /// and does not give them back.
+ ///
+ /// Equivalent to the kernel's `fwnode_reset_control_array_get()` on the firmware node of
+ /// `dev`, as `devm_reset_control_array_get_shared()` does.
+ ///
+ /// # Examples
+ ///
+ /// Keeping all the shared reset lines of a device deasserted:
+ ///
+ /// ```
+ /// use kernel::{
+ /// device::{
+ /// Bound,
+ /// Device, //
+ /// },
+ /// reset::{
+ /// Deasserted,
+ /// SharedResetControl, //
+ /// },
+ /// };
+ ///
+ /// struct Data<'a> {
+ /// // Dropping `Data` asserts the reset control again.
+ /// resets: SharedResetControl<'a, Deasserted>,
+ /// }
+ ///
+ /// fn probe<'a>(dev: &'a Device<Bound>) -> Result<Data<'a>> {
+ /// let resets = SharedResetControl::get_array(dev)?.deassert()?;
+ ///
+ /// Ok(Data { resets })
+ /// }
+ /// ```
+ #[inline]
+ pub fn get_array(dev: &'a Device<Bound>) -> Result<Self> {
+ Self::get_array_internal(dev, false)
+ }
+
+ /// Gets the reset lines listed in the `resets` property of `dev` as one
+ /// [`SharedResetControl`], if there are any.
+ ///
+ /// Behaves the same as [`Self::get_array`], except when `dev` has no firmware node, when its
+ /// `resets` property has no entry or cannot be read, or when `CONFIG_RESET_CONTROLLER` is
+ /// disabled. In those cases, it returns a [`SharedResetControl`] on which every operation
+ /// succeeds and does nothing.
+ ///
+ /// Equivalent to the kernel's `fwnode_reset_control_array_get()` on the firmware node of
+ /// `dev`, as `devm_reset_control_array_get_optional_shared()` does.
+ #[inline]
+ pub fn get_array_optional(dev: &'a Device<Bound>) -> Result<Self> {
+ Self::get_array_internal(dev, true)
+ }
+
/// Deasserts the reset line and moves the [`SharedResetControl`] to the [`Deasserted`] state.
///
/// Equivalent to the kernel's [`reset_control_deassert()`].
--
2.56.0
next prev parent reply other threads:[~2026-11-26 16:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
2026-11-26 16:04 ` [PATCH 1/7] rust: reset: add reset control helpers Daniel Almeida
2026-11-26 16:04 ` [PATCH 2/7] rust: reset: add ExclusiveResetControl Daniel Almeida
2026-11-26 16:04 ` [PATCH 3/7] rust: reset: add ExclusiveResetControl::get_array() and get_array_optional() Daniel Almeida
2026-11-26 16:04 ` [PATCH 4/7] rust: reset: add AssertedGuard Daniel Almeida
2026-11-26 16:04 ` [PATCH 5/7] rust: reset: add SharedResetControl Daniel Almeida
2026-11-26 19:14 ` Alice Ryhl
2026-11-26 16:04 ` Daniel Almeida [this message]
2026-11-26 16:04 ` [PATCH 7/7] rust: reset: add devm_deassert() and devm_deassert_optional() Daniel Almeida
2026-11-26 16:33 ` [PATCH 0/7] rust: reset: add reset control abstractions Nicolas Dufresne
2026-11-26 18:02 ` Daniel Almeida
2026-11-26 18:11 ` Nicolas Dufresne
2026-11-26 18:36 ` Daniel Almeida
2026-11-26 18:46 ` Nicolas Dufresne
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=20261126-b4-rust-reset-v1-6-9c4c3d029080@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=detlev.casanova@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=ojeda@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--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
all inboxes | Powered by JetHome®