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 3/7] rust: reset: add ExclusiveResetControl::get_array() and get_array_optional()
Date: Thu, 26 Nov 2026 13:04:30 -0300 [thread overview]
Message-ID: <20261126-b4-rust-reset-v1-3-9c4c3d029080@collabora.com> (raw)
In-Reply-To: <20261126-b4-rust-reset-v1-0-9c4c3d029080@collabora.com>
Add ExclusiveResetControl::get_array() and get_array_optional(), which
get all the reset lines in the resets property of a device as a single
reset control. This is for drivers that assert and deassert all the
reset lines of their device together.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
rust/helpers/reset.c | 7 ++++
rust/kernel/reset.rs | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 101 insertions(+), 2 deletions(-)
diff --git a/rust/helpers/reset.c b/rust/helpers/reset.c
index ea2e6f09b7d5..435f2c7c815d 100644
--- a/rust/helpers/reset.c
+++ b/rust/helpers/reset.c
@@ -16,6 +16,13 @@ rust_helper_reset_control_get_optional_exclusive(struct device *dev,
}
#ifndef CONFIG_RESET_CONTROLLER
+__rust_helper struct reset_control *
+rust_helper_fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
+ enum reset_control_flags flags)
+{
+ return fwnode_reset_control_array_get(fwnode, flags);
+}
+
__rust_helper void rust_helper_reset_control_put(struct reset_control *rstc)
{
reset_control_put(rstc);
diff --git a/rust/kernel/reset.rs b/rust/kernel/reset.rs
index 396f1e19ee2e..7ca83f2d6abf 100644
--- a/rust/kernel/reset.rs
+++ b/rust/kernel/reset.rs
@@ -9,6 +9,9 @@
//! assert and deassert the line. A new control is in the [`Unknown`] state. Its `assert()` and
//! `deassert()` methods, when they succeed, move it to the [`Asserted`] or [`Deasserted`] state.
//!
+//! A driver can also get a single reset control for all the reset lines in the `resets`
+//! property of its device. Its operations then act on all of those lines.
+//!
//! C header: [`include/linux/reset.h`](srctree/include/linux/reset.h)
//!
//! See [Reset controller API](https://docs.kernel.org/driver-api/reset.html) for more information.
@@ -96,8 +99,9 @@ fn from(err: Error<T>) -> Self {
/// Exclusive means that the driver has direct control over the reset line. A reset line can be
/// held by one [`ExclusiveResetControl`] at a time.
///
-/// A reset control obtained with [`ExclusiveResetControl::get_optional`] may have no reset line,
-/// in which case every operation on it succeeds and does nothing.
+/// A reset control obtained with [`ExclusiveResetControl::get_optional`] or
+/// [`ExclusiveResetControl::get_array_optional`] may have no reset line, in which case every
+/// operation on it succeeds and does nothing.
///
/// The reset control is released when the [`ExclusiveResetControl`] is dropped. The lifetime `'a`
/// is that of the reference to the bound device it was obtained from, so an
@@ -143,6 +147,8 @@ fn from(err: Error<T>) -> Self {
///
/// - [`reset_control_get_exclusive()`]
/// - [`reset_control_get_optional_exclusive()`]
+/// - `fwnode_reset_control_array_get()` with the `RESET_CONTROL_EXCLUSIVE` or
+/// `RESET_CONTROL_OPTIONAL_EXCLUSIVE` 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 [`ExclusiveResetControl`] owns the reference that the
@@ -213,6 +219,92 @@ pub fn get_optional(dev: &'a Device<Bound>, name: Option<&CStr>) -> Result<Self>
_phantom: PhantomData,
})
}
+
+ /// Gets the reset lines of `dev` as one [`ExclusiveResetControl`], 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_EXCLUSIVE
+ } else {
+ bindings::reset_control_flags_RESET_CONTROL_EXCLUSIVE
+ };
+
+ 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
+ /// [`ExclusiveResetControl`].
+ ///
+ /// 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, whatever
+ /// state they were in before. This includes operations that are done on drop. The caller only
+ /// gets the error from the line that failed, while errors from the opposite operation are
+ /// discarded.
+ ///
+ /// Equivalent to the kernel's `fwnode_reset_control_array_get()` on the firmware node of
+ /// `dev`, as `devm_reset_control_array_get_exclusive()` does.
+ ///
+ /// # Examples
+ ///
+ /// Keeping all the reset lines of a device deasserted:
+ ///
+ /// ```
+ /// use kernel::{
+ /// device::{
+ /// Bound,
+ /// Device, //
+ /// },
+ /// reset::{
+ /// Deasserted,
+ /// ExclusiveResetControl, //
+ /// },
+ /// };
+ ///
+ /// struct Data<'a> {
+ /// // Dropping `Data` tries to assert the lines again.
+ /// resets: ExclusiveResetControl<'a, Deasserted>,
+ /// }
+ ///
+ /// fn probe<'a>(dev: &'a Device<Bound>) -> Result<Data<'a>> {
+ /// let resets = ExclusiveResetControl::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
+ /// [`ExclusiveResetControl`], 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 an [`ExclusiveResetControl`] 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_exclusive()` does.
+ #[inline]
+ pub fn get_array_optional(dev: &'a Device<Bound>) -> Result<Self> {
+ Self::get_array_internal(dev, true)
+ }
}
impl<'a, State: ResetState> ExclusiveResetControl<'a, State> {
--
2.56.0
next prev parent reply other threads:[~2026-11-26 16:06 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 ` Daniel Almeida [this message]
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 ` [PATCH 6/7] rust: reset: add SharedResetControl::get_array() and get_array_optional() Daniel Almeida
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-3-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®