* [PATCH 1/7] rust: reset: add reset control helpers
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
@ 2026-11-26 16:04 ` Daniel Almeida
2026-11-26 16:04 ` [PATCH 2/7] rust: reset: add ExclusiveResetControl Daniel Almeida
` (6 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 16:04 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova,
Nicolas Dufresne
In preparation for the reset control abstraction added by the next
patch, make the static inline functions it uses available to bindgen.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
MAINTAINERS | 1 +
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 +
rust/helpers/reset.c | 33 +++++++++++++++++++++++++++++++++
4 files changed, 36 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 222b7fc2c3aa..d8bcacb7d8ef 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24063,6 +24063,7 @@ F: include/dt-bindings/reset/
F: include/linux/reset-controller.h
F: include/linux/reset.h
F: include/linux/reset/
+F: rust/helpers/reset.c
K: \b(?:devm_|of_)?reset_control(?:ler_[a-z]+|_[a-z_]+)?\b
RESTARTABLE SEQUENCES SUPPORT
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 3791af0aadc7..c96634bfaacb 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -85,6 +85,7 @@
#include <linux/random.h>
#include <linux/refcount.h>
#include <linux/regulator/consumer.h>
+#include <linux/reset.h>
#include <linux/sched.h>
#include <linux/security.h>
#include <linux/serdev.h>
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index d62c7be1ca7b..a5a127935961 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -92,6 +92,7 @@
#include "rcu.c"
#include "refcount.c"
#include "regulator.c"
+#include "reset.c"
#include "scatterlist.c"
#include "security.c"
#include "serdev.c"
diff --git a/rust/helpers/reset.c b/rust/helpers/reset.c
new file mode 100644
index 000000000000..ea2e6f09b7d5
--- /dev/null
+++ b/rust/helpers/reset.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/reset.h>
+
+__rust_helper struct reset_control *
+rust_helper_reset_control_get_exclusive(struct device *dev, const char *id)
+{
+ return reset_control_get_exclusive(dev, id);
+}
+
+__rust_helper struct reset_control *
+rust_helper_reset_control_get_optional_exclusive(struct device *dev,
+ const char *id)
+{
+ return reset_control_get_optional_exclusive(dev, id);
+}
+
+#ifndef CONFIG_RESET_CONTROLLER
+__rust_helper void rust_helper_reset_control_put(struct reset_control *rstc)
+{
+ reset_control_put(rstc);
+}
+
+__rust_helper int rust_helper_reset_control_assert(struct reset_control *rstc)
+{
+ return reset_control_assert(rstc);
+}
+
+__rust_helper int rust_helper_reset_control_deassert(struct reset_control *rstc)
+{
+ return reset_control_deassert(rstc);
+}
+#endif
--
2.56.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 2/7] rust: reset: add ExclusiveResetControl
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 ` Daniel Almeida
2026-11-26 16:04 ` [PATCH 3/7] rust: reset: add ExclusiveResetControl::get_array() and get_array_optional() Daniel Almeida
` (5 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 16:04 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova,
Nicolas Dufresne
Add an abstraction for exclusive reset controls, so that Rust drivers
can assert and deassert the reset lines of their device.
It follows the type-state pattern of the regulator abstraction. It
borrows the bound device it was obtained from, which ties it to the
binding as devm_reset_control_get_exclusive() does in C.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
MAINTAINERS | 1 +
rust/kernel/lib.rs | 1 +
rust/kernel/reset.rs | 333 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 335 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index d8bcacb7d8ef..e427742252d0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24064,6 +24064,7 @@ F: include/linux/reset-controller.h
F: include/linux/reset.h
F: include/linux/reset/
F: rust/helpers/reset.c
+F: rust/kernel/reset.rs
K: \b(?:devm_|of_)?reset_control(?:ler_[a-z]+|_[a-z_]+)?\b
RESTARTABLE SEQUENCES SUPPORT
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 1ab41129d557..c0199ec055b8 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -125,6 +125,7 @@
pub mod ratelimit;
pub mod rbtree;
pub mod regulator;
+pub mod reset;
pub mod revocable;
pub mod safety;
pub mod scatterlist;
diff --git a/rust/kernel/reset.rs b/rust/kernel/reset.rs
new file mode 100644
index 000000000000..396f1e19ee2e
--- /dev/null
+++ b/rust/kernel/reset.rs
@@ -0,0 +1,333 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Reset control abstractions, the consumer side of the reset controller API.
+//!
+//! A reset controller controls a number of reset lines. A device is held in reset while its reset
+//! line is asserted.
+//!
+//! A driver gets an [`ExclusiveResetControl`] for a reset line of its device, and uses it to
+//! 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.
+//!
+//! 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.
+
+use crate::{
+ bindings,
+ device::{
+ Bound,
+ Device, //
+ },
+ error::{
+ from_err_ptr,
+ to_result, //
+ },
+ prelude::*, //
+};
+
+use core::{
+ marker::PhantomData,
+ mem::ManuallyDrop,
+ ptr, //
+};
+
+mod private {
+ pub trait Sealed {}
+
+ impl Sealed for super::Unknown {}
+ impl Sealed for super::Asserted {}
+ impl Sealed for super::Deasserted {}
+}
+
+/// A trait representing the different states a reset control can be in.
+pub trait ResetState: private::Sealed {
+ /// Whether dropping a reset control in this state asserts the line.
+ const ASSERT_ON_DROP: bool;
+}
+
+/// A state that records nothing about the reset line, which may be asserted or deasserted.
+///
+/// Dropping a reset control in this state does not change the line.
+pub struct Unknown;
+
+/// A state where the last successful operation on the reset control was an assert.
+///
+/// Dropping a reset control in this state does not change the line.
+pub struct Asserted;
+
+/// A state where the last successful operation on the reset control was a deassert.
+///
+/// Dropping a reset control in this state asserts the line. An error from that assert is
+/// discarded.
+pub struct Deasserted;
+
+impl ResetState for Unknown {
+ const ASSERT_ON_DROP: bool = false;
+}
+
+impl ResetState for Asserted {
+ const ASSERT_ON_DROP: bool = false;
+}
+
+impl ResetState for Deasserted {
+ const ASSERT_ON_DROP: bool = true;
+}
+
+/// An error that can occur when trying to move a reset control between states.
+pub struct Error<T> {
+ /// The error that occurred.
+ pub error: kernel::error::Error,
+
+ /// The reset control the operation failed on.
+ pub reset: T,
+}
+
+impl<T> From<Error<T>> for kernel::error::Error {
+ /// Drops the reset control and keeps the error, so that `?` works on the state transitions.
+ #[inline]
+ fn from(err: Error<T>) -> Self {
+ err.error
+ }
+}
+
+/// An exclusive reset control of a device.
+///
+/// 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.
+///
+/// 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
+/// [`ExclusiveResetControl`] cannot outlive the binding of that device to its driver.
+///
+/// # Examples
+///
+/// Holding a device in reset while its clocks are turned on, then releasing it:
+///
+/// ```
+/// use kernel::{
+/// device::{
+/// Bound,
+/// Device, //
+/// },
+/// reset::{
+/// Deasserted,
+/// ExclusiveResetControl, //
+/// },
+/// };
+///
+/// struct Data<'a> {
+/// // Dropping `Data` asserts the line again.
+/// reset: ExclusiveResetControl<'a, Deasserted>,
+/// }
+///
+/// fn probe<'a>(dev: &'a Device<Bound>) -> Result<Data<'a>> {
+/// // Put the device in reset.
+/// let reset = ExclusiveResetControl::get(dev, None)?.assert()?;
+///
+/// // For example, turn on the clocks of the device here, while it is held in reset.
+///
+/// // Release the device from reset.
+/// let reset = reset.deassert()?;
+///
+/// Ok(Data { reset })
+/// }
+/// ```
+///
+/// # Invariants
+///
+/// `inner` is a pointer obtained from a successful call to one of the following:
+///
+/// - [`reset_control_get_exclusive()`]
+/// - [`reset_control_get_optional_exclusive()`]
+///
+/// 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
+/// call returned.
+///
+/// [`reset_control_get_exclusive()`]:
+/// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_exclusive
+/// [`reset_control_get_optional_exclusive()`]:
+/// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_optional_exclusive
+pub struct ExclusiveResetControl<'a, State: ResetState> {
+ inner: *mut bindings::reset_control,
+ _phantom: PhantomData<(&'a Device<Bound>, State)>,
+}
+
+// SAFETY: A reset control can be used and released from any thread.
+unsafe impl<State: ResetState> Send for ExclusiveResetControl<'_, State> {}
+
+// SAFETY: An `ExclusiveResetControl` has no `&self` methods, so references to it can be shared
+// between threads.
+unsafe impl<State: ResetState> Sync for ExclusiveResetControl<'_, State> {}
+
+impl<'a> ExclusiveResetControl<'a, Unknown> {
+ /// Gets the reset line `name` of `dev`, or its first reset line if `name` is `None`.
+ ///
+ /// Equivalent to the kernel's [`reset_control_get_exclusive()`].
+ ///
+ /// [`reset_control_get_exclusive()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_exclusive
+ #[inline]
+ pub fn get(dev: &'a Device<Bound>, name: Option<&CStr>) -> Result<Self> {
+ let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+ // SAFETY: `dev` is a valid device, and `id` is `NULL` or a valid C string.
+ let inner = unsafe { bindings::reset_control_get_exclusive(dev.as_raw(), id) };
+ let inner = from_err_ptr(inner)?;
+
+ // INVARIANT: `inner` comes from a successful call to `reset_control_get_exclusive()`, and
+ // the returned value owns the reference from that call.
+ Ok(Self {
+ inner,
+ _phantom: PhantomData,
+ })
+ }
+
+ /// Gets the reset line `name` of `dev`, if there is one.
+ ///
+ /// Behaves the same as [`Self::get`], except when the device has no such reset line or
+ /// `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 [`reset_control_get_optional_exclusive()`].
+ ///
+ /// [`reset_control_get_optional_exclusive()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_optional_exclusive
+ #[inline]
+ pub fn get_optional(dev: &'a Device<Bound>, name: Option<&CStr>) -> Result<Self> {
+ let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+ // SAFETY: `dev` is a valid device, and `id` is `NULL` or a valid C string.
+ let inner = unsafe { bindings::reset_control_get_optional_exclusive(dev.as_raw(), id) };
+ let inner = from_err_ptr(inner)?;
+
+ // INVARIANT: `inner` comes from a successful call to
+ // `reset_control_get_optional_exclusive()`, and the returned value owns the reference from
+ // that call.
+ Ok(Self {
+ inner,
+ _phantom: PhantomData,
+ })
+ }
+}
+
+impl<'a, State: ResetState> ExclusiveResetControl<'a, State> {
+ /// Asserts the reset line and moves the [`ExclusiveResetControl`] to the [`Asserted`] state.
+ ///
+ /// Equivalent to the kernel's [`reset_control_assert()`].
+ ///
+ /// [`reset_control_assert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_assert
+ #[inline]
+ fn assert_internal(self) -> Result<ExclusiveResetControl<'a, Asserted>, Error<Self>> {
+ // INVARIANT: The reference that `self` owns moves to the value that this returns.
+ let reset = ManuallyDrop::new(self);
+
+ // SAFETY: By the type invariants, `reset.inner` is a pointer that a C getter returned, and
+ // `reset` owns its reference.
+ to_result(unsafe { bindings::reset_control_assert(reset.inner) })
+ .map(|()| ExclusiveResetControl {
+ inner: reset.inner,
+ _phantom: PhantomData,
+ })
+ .map_err(|error| Error {
+ error,
+ reset: ManuallyDrop::into_inner(reset),
+ })
+ }
+
+ /// Deasserts the reset line and moves the [`ExclusiveResetControl`] to the [`Deasserted`]
+ /// state.
+ ///
+ /// Equivalent to the kernel's [`reset_control_deassert()`].
+ ///
+ /// [`reset_control_deassert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_deassert
+ #[inline]
+ fn deassert_internal(self) -> Result<ExclusiveResetControl<'a, Deasserted>, Error<Self>> {
+ // INVARIANT: The reference that `self` owns moves to the value that this returns.
+ let reset = ManuallyDrop::new(self);
+
+ // SAFETY: By the type invariants, `reset.inner` is a pointer that a C getter returned, and
+ // `reset` owns its reference.
+ to_result(unsafe { bindings::reset_control_deassert(reset.inner) })
+ .map(|()| ExclusiveResetControl {
+ inner: reset.inner,
+ _phantom: PhantomData,
+ })
+ .map_err(|error| Error {
+ error,
+ reset: ManuallyDrop::into_inner(reset),
+ })
+ }
+}
+
+impl<'a> ExclusiveResetControl<'a, Unknown> {
+ /// Asserts the reset line and moves the [`ExclusiveResetControl`] to the [`Asserted`] state.
+ ///
+ /// Equivalent to the kernel's [`reset_control_assert()`].
+ ///
+ /// [`reset_control_assert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_assert
+ #[inline]
+ pub fn assert(self) -> Result<ExclusiveResetControl<'a, Asserted>, Error<Self>> {
+ self.assert_internal()
+ }
+
+ /// Deasserts the reset line and moves the [`ExclusiveResetControl`] to the [`Deasserted`]
+ /// state.
+ ///
+ /// Equivalent to the kernel's [`reset_control_deassert()`].
+ ///
+ /// [`reset_control_deassert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_deassert
+ #[inline]
+ pub fn deassert(self) -> Result<ExclusiveResetControl<'a, Deasserted>, Error<Self>> {
+ self.deassert_internal()
+ }
+}
+
+impl<'a> ExclusiveResetControl<'a, Asserted> {
+ /// Deasserts the reset line and moves the [`ExclusiveResetControl`] to the [`Deasserted`]
+ /// state.
+ ///
+ /// Equivalent to the kernel's [`reset_control_deassert()`].
+ ///
+ /// [`reset_control_deassert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_deassert
+ #[inline]
+ pub fn deassert(self) -> Result<ExclusiveResetControl<'a, Deasserted>, Error<Self>> {
+ self.deassert_internal()
+ }
+}
+
+impl<'a> ExclusiveResetControl<'a, Deasserted> {
+ /// Asserts the reset line and moves the [`ExclusiveResetControl`] to the [`Asserted`] state.
+ ///
+ /// Equivalent to the kernel's [`reset_control_assert()`].
+ ///
+ /// [`reset_control_assert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_assert
+ #[inline]
+ pub fn assert(self) -> Result<ExclusiveResetControl<'a, Asserted>, Error<Self>> {
+ self.assert_internal()
+ }
+}
+
+impl<State: ResetState> Drop for ExclusiveResetControl<'_, State> {
+ fn drop(&mut self) {
+ if State::ASSERT_ON_DROP {
+ // SAFETY: By the type invariants, `self.inner` is a pointer that a C getter returned,
+ // and `self` owns its reference.
+ unsafe { bindings::reset_control_assert(self.inner) };
+ }
+
+ // SAFETY: By the type invariants, `self` owns the reference that the C getter returned,
+ // so it is safe to relinquish it now.
+ unsafe { bindings::reset_control_put(self.inner) };
+ }
+}
--
2.56.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 3/7] rust: reset: add ExclusiveResetControl::get_array() and get_array_optional()
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
2026-11-26 16:04 ` [PATCH 4/7] rust: reset: add AssertedGuard Daniel Almeida
` (4 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 16:04 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova,
Nicolas Dufresne
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
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 4/7] rust: reset: add AssertedGuard
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
` (2 preceding siblings ...)
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 ` Daniel Almeida
2026-11-26 16:04 ` [PATCH 5/7] rust: reset: add SharedResetControl Daniel Almeida
` (3 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 16:04 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova,
Nicolas Dufresne
Some drivers hold their device in reset for a short time while they
are bound.
Add ExclusiveResetControl::assert_guard() as a convenience for them. It
asserts the reset line of an Unknown control and returns an
AssertedGuard that deasserts it when dropped, so the control stays in
the Unknown state.
The guard borrows the control mutably because, unlike regulators,
exclusive resets do not have an "enabled" count. Therefore, allowing
more than one guard at a time would not work, as dropping one of them
would invalidate the other while it is still alive.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
rust/kernel/reset.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/rust/kernel/reset.rs b/rust/kernel/reset.rs
index 7ca83f2d6abf..3bbd226825d8 100644
--- a/rust/kernel/reset.rs
+++ b/rust/kernel/reset.rs
@@ -12,6 +12,10 @@
//! 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.
//!
+//! An [`ExclusiveResetControl`] in the [`Unknown`] state can also assert its line for a limited
+//! time, with [`ExclusiveResetControl::assert_guard`]. The [`AssertedGuard`] that it returns
+//! deasserts the line when dropped, and the control stays in the [`Unknown`] state.
+//!
//! 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.
@@ -381,6 +385,24 @@ pub fn assert(self) -> Result<ExclusiveResetControl<'a, Asserted>, Error<Self>>
pub fn deassert(self) -> Result<ExclusiveResetControl<'a, Deasserted>, Error<Self>> {
self.deassert_internal()
}
+
+ /// Asserts the reset line and returns an [`AssertedGuard`], which deasserts it when dropped.
+ ///
+ /// The [`ExclusiveResetControl`] stays in the [`Unknown`] state, and it cannot be used while
+ /// the guard exists.
+ ///
+ /// The line is asserted with the kernel's [`reset_control_assert()`].
+ ///
+ /// [`reset_control_assert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_assert
+ #[inline]
+ pub fn assert_guard(&mut self) -> Result<AssertedGuard<'_, 'a>> {
+ // SAFETY: By the type invariants, `self.inner` is a pointer that a C getter returned, and
+ // `self` owns its reference.
+ to_result(unsafe { bindings::reset_control_assert(self.inner) })?;
+
+ Ok(AssertedGuard { reset: self })
+ }
}
impl<'a> ExclusiveResetControl<'a, Asserted> {
@@ -423,3 +445,63 @@ fn drop(&mut self) {
unsafe { bindings::reset_control_put(self.inner) };
}
}
+
+/// A guard returned by [`ExclusiveResetControl::assert_guard`], which deasserts the reset line when
+/// dropped.
+///
+/// An error from the deassert done on drop is discarded. [`AssertedGuard::deassert`] deasserts the
+/// line and returns the error.
+///
+/// # Examples
+///
+/// Holding a device in reset for a limited time:
+///
+/// ```
+/// use kernel::reset::{
+/// ExclusiveResetControl,
+/// Unknown, //
+/// };
+///
+/// # fn restart_clocks() -> Result { Ok(()) }
+/// fn reset_device(reset: &mut ExclusiveResetControl<'_, Unknown>) -> Result {
+/// let asserted = reset.assert_guard()?;
+///
+/// // If this fails, dropping `asserted` deasserts the line.
+/// restart_clocks()?;
+///
+/// asserted.deassert()
+/// }
+/// ```
+#[must_use = "the reset line is deasserted immediately when the guard is unused"]
+pub struct AssertedGuard<'r, 'a> {
+ reset: &'r mut ExclusiveResetControl<'a, Unknown>,
+}
+
+impl<'r, 'a> AssertedGuard<'r, 'a> {
+ /// Deasserts the reset line and consumes the guard.
+ ///
+ /// The only difference from dropping the guard is that this returns an error from the
+ /// deassert, which a drop discards.
+ ///
+ /// Equivalent to the kernel's [`reset_control_deassert()`].
+ ///
+ /// [`reset_control_deassert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_deassert
+ #[inline]
+ pub fn deassert(self) -> Result {
+ // Skip `drop()`, which would deassert the line a second time.
+ let guard = ManuallyDrop::new(self);
+
+ // SAFETY: By the type invariants of `ExclusiveResetControl`, `guard.reset.inner` is a
+ // pointer that a C getter returned, and `guard.reset` owns its reference.
+ to_result(unsafe { bindings::reset_control_deassert(guard.reset.inner) })
+ }
+}
+
+impl<'r, 'a> Drop for AssertedGuard<'r, 'a> {
+ fn drop(&mut self) {
+ // SAFETY: By the type invariants of `ExclusiveResetControl`, `self.reset.inner` is a
+ // pointer that a C getter returned, and `self.reset` owns its reference.
+ unsafe { bindings::reset_control_deassert(self.reset.inner) };
+ }
+}
--
2.56.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 5/7] rust: reset: add SharedResetControl
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
` (3 preceding siblings ...)
2026-11-26 16:04 ` [PATCH 4/7] rust: reset: add AssertedGuard Daniel Almeida
@ 2026-11-26 16:04 ` 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
` (2 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 16:04 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova,
Nicolas Dufresne
A reset line can be shared between devices. The reset core then counts
the deasserts on the line, and only the first deassert and the last
assert act on it.
Add SharedResetControl for such lines, with get() and get_optional().
It has two states, Unknown and Deasserted, which correspond to Disabled
and Enabled of Regulator<T>. An assert returns it to Unknown, since
other users may keep the line deasserted.
Like ExclusiveResetControl, it borrows the bound device it was obtained
from, which ties it to the binding as devm_reset_control_get_shared()
does in C.
Nothing uses SharedResetControl yet.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
rust/helpers/reset.c | 13 ++++
rust/kernel/reset.rs | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 219 insertions(+)
diff --git a/rust/helpers/reset.c b/rust/helpers/reset.c
index 435f2c7c815d..9c106d8b6de1 100644
--- a/rust/helpers/reset.c
+++ b/rust/helpers/reset.c
@@ -15,6 +15,19 @@ rust_helper_reset_control_get_optional_exclusive(struct device *dev,
return reset_control_get_optional_exclusive(dev, id);
}
+__rust_helper struct reset_control *
+rust_helper_reset_control_get_shared(struct device *dev, const char *id)
+{
+ return reset_control_get_shared(dev, id);
+}
+
+__rust_helper struct reset_control *
+rust_helper_reset_control_get_optional_shared(struct device *dev,
+ const char *id)
+{
+ return reset_control_get_optional_shared(dev, id);
+}
+
#ifndef CONFIG_RESET_CONTROLLER
__rust_helper struct reset_control *
rust_helper_fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
diff --git a/rust/kernel/reset.rs b/rust/kernel/reset.rs
index 3bbd226825d8..4d241ec6e549 100644
--- a/rust/kernel/reset.rs
+++ b/rust/kernel/reset.rs
@@ -16,6 +16,9 @@
//! time, with [`ExclusiveResetControl::assert_guard`]. The [`AssertedGuard`] that it returns
//! deasserts the line when dropped, and the control stays in the [`Unknown`] state.
//!
+//! If the reset line is shared with other devices, the driver asks for a [`SharedResetControl`]
+//! instead.
+//!
//! 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.
@@ -67,6 +70,9 @@ pub trait ResetState: private::Sealed {
///
/// Dropping a reset control in this state asserts the line. An error from that assert is
/// discarded.
+///
+/// For a [`SharedResetControl`], the line may still be deasserted after that assert, as described
+/// in [`SharedResetControl::assert`].
pub struct Deasserted;
impl ResetState for Unknown {
@@ -81,6 +87,15 @@ impl ResetState for Deasserted {
const ASSERT_ON_DROP: bool = true;
}
+/// A trait representing the states a [`SharedResetControl`] can be in.
+///
+/// [`Asserted`] is not one of them, since the line may still be deasserted after a
+/// [`SharedResetControl`] is asserted.
+pub trait SharedResetState: ResetState {}
+
+impl SharedResetState for Unknown {}
+impl SharedResetState for Deasserted {}
+
/// An error that can occur when trying to move a reset control between states.
pub struct Error<T> {
/// The error that occurred.
@@ -505,3 +520,194 @@ fn drop(&mut self) {
unsafe { bindings::reset_control_deassert(self.reset.inner) };
}
}
+
+/// A shared reset control of a device.
+///
+/// Shared means that other devices may use the same reset line. The deasserts on the line are
+/// counted, and only the first deassert and the last assert act on it. A [`SharedResetControl`]
+/// can only be asserted after it was deasserted, as the C API requires.
+///
+/// A reset line cannot be held by a [`SharedResetControl`] and by an [`ExclusiveResetControl`] at
+/// the same time.
+///
+/// The reset control is released when the [`SharedResetControl`] is dropped. The lifetime `'a` is
+/// that of the reference to the bound device it was obtained from, so a [`SharedResetControl`]
+/// cannot outlive the binding of that device to its driver.
+///
+/// # Examples
+///
+/// Keeping a shared reset line deasserted:
+///
+/// ```
+/// use kernel::{
+/// device::{
+/// Bound,
+/// Device, //
+/// },
+/// reset::{
+/// Deasserted,
+/// SharedResetControl, //
+/// },
+/// };
+///
+/// struct Data<'a> {
+/// // Dropping `Data` asserts the reset control again.
+/// reset: SharedResetControl<'a, Deasserted>,
+/// }
+///
+/// fn probe<'a>(dev: &'a Device<Bound>) -> Result<Data<'a>> {
+/// let reset = SharedResetControl::get(dev, None)?.deassert()?;
+///
+/// Ok(Data { reset })
+/// }
+/// ```
+///
+/// # Invariants
+///
+/// `inner` is a pointer obtained from a successful call to one of the following:
+///
+/// - [`reset_control_get_shared()`]
+/// - [`reset_control_get_optional_shared()`]
+///
+/// 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
+/// call returned.
+///
+/// [`reset_control_get_shared()`]:
+/// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_shared
+/// [`reset_control_get_optional_shared()`]:
+/// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_optional_shared
+pub struct SharedResetControl<'a, State: SharedResetState> {
+ inner: *mut bindings::reset_control,
+ _phantom: PhantomData<(&'a Device<Bound>, State)>,
+}
+
+// SAFETY: A reset control can be used and released from any thread.
+unsafe impl<State: SharedResetState> Send for SharedResetControl<'_, State> {}
+
+// SAFETY: A `SharedResetControl` has no `&self` methods, so references to it can be shared between
+// threads.
+unsafe impl<State: SharedResetState> Sync for SharedResetControl<'_, State> {}
+
+impl<'a> SharedResetControl<'a, Unknown> {
+ /// Gets the reset line `name` of `dev`, or its first reset line if `name` is `None`.
+ ///
+ /// Equivalent to the kernel's [`reset_control_get_shared()`].
+ ///
+ /// [`reset_control_get_shared()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_shared
+ #[inline]
+ pub fn get(dev: &'a Device<Bound>, name: Option<&CStr>) -> Result<Self> {
+ let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+ // SAFETY: `dev` is a valid device, and `id` is `NULL` or a valid C string.
+ let inner = unsafe { bindings::reset_control_get_shared(dev.as_raw(), id) };
+ let inner = from_err_ptr(inner)?;
+
+ // INVARIANT: `inner` comes from a successful call to `reset_control_get_shared()`, and the
+ // returned value owns the reference from that call.
+ Ok(Self {
+ inner,
+ _phantom: PhantomData,
+ })
+ }
+
+ /// Gets the reset line `name` of `dev`, if there is one.
+ ///
+ /// Behaves the same as [`Self::get`], except when the device has no such reset line or
+ /// `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 [`reset_control_get_optional_shared()`].
+ ///
+ /// [`reset_control_get_optional_shared()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_get_optional_shared
+ #[inline]
+ pub fn get_optional(dev: &'a Device<Bound>, name: Option<&CStr>) -> Result<Self> {
+ let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+ // SAFETY: `dev` is a valid device, and `id` is `NULL` or a valid C string.
+ let inner = unsafe { bindings::reset_control_get_optional_shared(dev.as_raw(), id) };
+ let inner = from_err_ptr(inner)?;
+
+ // INVARIANT: `inner` comes from a successful call to
+ // `reset_control_get_optional_shared()`, and the returned value owns the reference from
+ // that call.
+ Ok(Self {
+ inner,
+ _phantom: PhantomData,
+ })
+ }
+
+ /// Deasserts the reset line and moves the [`SharedResetControl`] to the [`Deasserted`] state.
+ ///
+ /// Equivalent to the kernel's [`reset_control_deassert()`].
+ ///
+ /// [`reset_control_deassert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_deassert
+ #[inline]
+ pub fn deassert(self) -> Result<SharedResetControl<'a, Deasserted>, Error<Self>> {
+ // INVARIANT: The reference that `self` owns moves to the value that this returns.
+ let reset = ManuallyDrop::new(self);
+
+ // SAFETY: By the type invariants, `reset.inner` is a pointer that a C getter returned, and
+ // `reset` owns its reference.
+ to_result(unsafe { bindings::reset_control_deassert(reset.inner) })
+ .map(|()| SharedResetControl {
+ inner: reset.inner,
+ _phantom: PhantomData,
+ })
+ .map_err(|error| Error {
+ error,
+ reset: ManuallyDrop::into_inner(reset),
+ })
+ }
+}
+
+impl<'a> SharedResetControl<'a, Deasserted> {
+ /// Asserts the reset line and moves the [`SharedResetControl`] to the [`Unknown`] state.
+ ///
+ /// The line may still be deasserted afterwards, for as long as other users keep it so.
+ ///
+ /// If this fails, the [`SharedResetControl`] is returned in the [`Unknown`] state as well.
+ ///
+ /// Equivalent to the kernel's [`reset_control_assert()`].
+ ///
+ /// [`reset_control_assert()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_assert
+ #[inline]
+ pub fn assert(
+ self,
+ ) -> Result<SharedResetControl<'a, Unknown>, Error<SharedResetControl<'a, Unknown>>> {
+ // INVARIANT: The reference that `self` owns moves to `reset`.
+ let this = ManuallyDrop::new(self);
+ let reset = SharedResetControl {
+ inner: this.inner,
+ _phantom: PhantomData,
+ };
+
+ // An assert that fails may already have given the deassert back, so `reset` is `Unknown`
+ // in both cases.
+ //
+ // SAFETY: By the type invariants, `reset.inner` is a pointer that a C getter returned, and
+ // `reset` owns its reference.
+ match to_result(unsafe { bindings::reset_control_assert(reset.inner) }) {
+ Ok(()) => Ok(reset),
+ Err(error) => Err(Error { error, reset }),
+ }
+ }
+}
+
+impl<State: SharedResetState> Drop for SharedResetControl<'_, State> {
+ fn drop(&mut self) {
+ if State::ASSERT_ON_DROP {
+ // SAFETY: By the type invariants, `self.inner` is a pointer that a C getter returned,
+ // and `self` owns its reference.
+ unsafe { bindings::reset_control_assert(self.inner) };
+ }
+
+ // SAFETY: By the type invariants, `self` owns the reference that the C getter returned,
+ // so it is safe to relinquish it now.
+ unsafe { bindings::reset_control_put(self.inner) };
+ }
+}
--
2.56.0
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 5/7] rust: reset: add SharedResetControl
2026-11-26 16:04 ` [PATCH 5/7] rust: reset: add SharedResetControl Daniel Almeida
@ 2026-11-26 19:14 ` Alice Ryhl
0 siblings, 0 replies; 14+ messages in thread
From: Alice Ryhl @ 2026-11-26 19:14 UTC (permalink / raw)
To: Daniel Almeida
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
Tamir Duberstein, Alexandre Courbot, Onur Özkan,
Philipp Zabel, linux-kernel, rust-for-linux, dri-devel,
Detlev Casanova, Nicolas Dufresne
On Thu, Nov 26, 2026 at 01:04:32PM -0300, Daniel Almeida wrote:
> + /// Deasserts the reset line and moves the [`SharedResetControl`] to the [`Deasserted`] state.
> + ///
> + /// Equivalent to the kernel's [`reset_control_deassert()`].
> + ///
> + /// [`reset_control_deassert()`]:
> + /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_deassert
> + #[inline]
> + pub fn deassert(self) -> Result<SharedResetControl<'a, Deasserted>, Error<Self>> {
> + // INVARIANT: The reference that `self` owns moves to the value that this returns.
> + let reset = ManuallyDrop::new(self);
> +
> + // SAFETY: By the type invariants, `reset.inner` is a pointer that a C getter returned, and
> + // `reset` owns its reference.
> + to_result(unsafe { bindings::reset_control_deassert(reset.inner) })
> + .map(|()| SharedResetControl {
> + inner: reset.inner,
> + _phantom: PhantomData,
> + })
> + .map_err(|error| Error {
> + error,
> + reset: ManuallyDrop::into_inner(reset),
> + })
> + }
The C side here interacts badly with the error path of
`SharedResetControl::deassert()`.
In `drivers/reset/core.c`, `reset_control_deassert()` does:
if (rstc->shared) {
if (WARN_ON(atomic_read(&rstc->triggered_count) != 0))
return -EINVAL;
if (atomic_inc_return(&rstc->deassert_count) != 1)
return 0;
}
...
return rcdev->ops->deassert(rcdev, rstc->id);
Unlike `reset_control_reset()`, `reset_control_deassert()` does not
decrement `rstc->deassert_count` when `rcdev->ops->deassert()` returns
an error.
Because `SharedResetControl::deassert()` returns `reset` in the
`Unknown` state (`ASSERT_ON_DROP == false`) on error:
- If the caller drops `reset`, `deassert_count` stays leaked at 1, so
future shared users will see `deassert_count != 0` and skip
`ops->deassert()`.
- If the caller retries `reset.deassert()`, `atomic_inc_return()` returns
2 (`!= 1`), so `reset_control_deassert()` returns 0 without calling
`ops->deassert()`, leaving the line asserted while Rust treats the
control as `Deasserted`.
I wonder if this is a bug on the C side we should fix in core.c?
Alice
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 6/7] rust: reset: add SharedResetControl::get_array() and get_array_optional()
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
` (4 preceding siblings ...)
2026-11-26 16:04 ` [PATCH 5/7] rust: reset: add SharedResetControl Daniel Almeida
@ 2026-11-26 16:04 ` 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
7 siblings, 0 replies; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 16:04 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova,
Nicolas Dufresne
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
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 7/7] rust: reset: add devm_deassert() and devm_deassert_optional()
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
` (5 preceding siblings ...)
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 ` Daniel Almeida
2026-11-26 16:33 ` [PATCH 0/7] rust: reset: add reset control abstractions Nicolas Dufresne
7 siblings, 0 replies; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 16:04 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova,
Nicolas Dufresne
Many drivers need the reset line of their device deasserted while the
device is bound, but otherwise do not care about exerting finer control
over it. C drivers do that with
devm_reset_control_get_exclusive_deasserted() and
devm_reset_control_get_optional_exclusive_deasserted().
Add ExclusiveResetControl::devm_deassert() and devm_deassert_optional(),
which call them and leave the reset control to devres.
Nothing uses them yet.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
rust/helpers/reset.c | 14 +++++++++++
rust/kernel/reset.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)
diff --git a/rust/helpers/reset.c b/rust/helpers/reset.c
index 9c106d8b6de1..aa20b3e7a88b 100644
--- a/rust/helpers/reset.c
+++ b/rust/helpers/reset.c
@@ -28,6 +28,20 @@ rust_helper_reset_control_get_optional_shared(struct device *dev,
return reset_control_get_optional_shared(dev, id);
}
+__rust_helper struct reset_control *
+rust_helper_devm_reset_control_get_exclusive_deasserted(struct device *dev,
+ const char *id)
+{
+ return devm_reset_control_get_exclusive_deasserted(dev, id);
+}
+
+__rust_helper struct reset_control *
+rust_helper_devm_reset_control_get_optional_exclusive_deasserted(struct device *dev,
+ const char *id)
+{
+ return devm_reset_control_get_optional_exclusive_deasserted(dev, id);
+}
+
#ifndef CONFIG_RESET_CONTROLLER
__rust_helper struct reset_control *
rust_helper_fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
diff --git a/rust/kernel/reset.rs b/rust/kernel/reset.rs
index 85c51fc153ac..e2fbd4c2147c 100644
--- a/rust/kernel/reset.rs
+++ b/rust/kernel/reset.rs
@@ -19,6 +19,9 @@
//! If the reset line is shared with other devices, the driver asks for a [`SharedResetControl`]
//! instead.
//!
+//! A driver that only needs its reset line deasserted while it is bound can call
+//! [`ExclusiveResetControl::devm_deassert`] instead of keeping a reset control.
+//!
//! 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.
@@ -324,6 +327,69 @@ pub fn get_array(dev: &'a Device<Bound>) -> Result<Self> {
pub fn get_array_optional(dev: &'a Device<Bound>) -> Result<Self> {
Self::get_array_internal(dev, true)
}
+
+ /// Deasserts the reset line `name` of `dev`, or its first reset line if `name` is `None`, until
+ /// `dev` is unbound.
+ ///
+ /// The reset control is managed by devres, which asserts the line and releases the control
+ /// when `dev` is unbound. An error from that assert is discarded. Until then, devres holds
+ /// the line as an [`ExclusiveResetControl`] does.
+ ///
+ /// Equivalent to the kernel's [`devm_reset_control_get_exclusive_deasserted()`].
+ ///
+ /// # Examples
+ ///
+ /// Keeping the reset line of a device deasserted until the device is unbound:
+ ///
+ /// ```
+ /// use kernel::{
+ /// device::{
+ /// Bound,
+ /// Device, //
+ /// },
+ /// reset::ExclusiveResetControl,
+ /// };
+ ///
+ /// fn probe(dev: &Device<Bound>) -> Result {
+ /// ExclusiveResetControl::devm_deassert(dev, None)
+ /// }
+ /// ```
+ ///
+ /// [`devm_reset_control_get_exclusive_deasserted()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.devm_reset_control_get_exclusive_deasserted
+ #[inline]
+ pub fn devm_deassert(dev: &Device<Bound>, name: Option<&CStr>) -> Result {
+ let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+ // SAFETY: `dev` is a valid and bound device, and `id` is `NULL` or a valid C string.
+ let inner =
+ unsafe { bindings::devm_reset_control_get_exclusive_deasserted(dev.as_raw(), id) };
+ from_err_ptr(inner)?;
+
+ Ok(())
+ }
+
+ /// Deasserts the reset line `name` of `dev` until `dev` is unbound, if there is such a line.
+ ///
+ /// Behaves the same as [`Self::devm_deassert`], except when the device has no such reset line
+ /// or `CONFIG_RESET_CONTROLLER` is disabled. In those cases, it succeeds and does nothing.
+ ///
+ /// Equivalent to the kernel's [`devm_reset_control_get_optional_exclusive_deasserted()`].
+ ///
+ /// [`devm_reset_control_get_optional_exclusive_deasserted()`]:
+ /// https://docs.kernel.org/driver-api/reset.html#c.devm_reset_control_get_optional_exclusive_deasserted
+ #[inline]
+ pub fn devm_deassert_optional(dev: &Device<Bound>, name: Option<&CStr>) -> Result {
+ let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+ // SAFETY: `dev` is a valid and bound device, and `id` is `NULL` or a valid C string.
+ let inner = unsafe {
+ bindings::devm_reset_control_get_optional_exclusive_deasserted(dev.as_raw(), id)
+ };
+ from_err_ptr(inner)?;
+
+ Ok(())
+ }
}
impl<'a, State: ResetState> ExclusiveResetControl<'a, State> {
--
2.56.0
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 0/7] rust: reset: add reset control abstractions
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
` (6 preceding siblings ...)
2026-11-26 16:04 ` [PATCH 7/7] rust: reset: add devm_deassert() and devm_deassert_optional() Daniel Almeida
@ 2026-11-26 16:33 ` Nicolas Dufresne
2026-11-26 18:02 ` Daniel Almeida
7 siblings, 1 reply; 14+ messages in thread
From: Nicolas Dufresne @ 2026-11-26 16:33 UTC (permalink / raw)
To: Daniel Almeida, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Philipp Zabel
Cc: linux-kernel, rust-for-linux, dri-devel, Detlev Casanova
[-- Attachment #1: Type: text/plain, Size: 3469 bytes --]
Hi Daniel,
Le jeudi 26 novembre 2026 à 13:04 -0300, Daniel Almeida a écrit :
> This series adds a Rust abstraction for the consumer side of the reset
> controller API. A driver can get the reset lines of its device, as an
> exclusive or a shared reset control, and assert and deassert them.
>
> This will be used by the upcoming rkvenc driver that my colleagues
> Detlev Casanova, Nicolas Dufresne and I are working on, to recover a
> hung core of the encoder without stopping the other one. More details on
> this driver can be found by watching Nicolas Dufresne's talk at LPC 2026
> [0]. Samsung's Rust UFS RFC [1] also uses reset lines, through an
> abstraction that it has not posted.
I don't mind being cited, but please give a heads-up, we haven't discussed any
of this, so I can't really comment if its a good or bad idea. On the C side,
shared reset don't really work today, so I'm left wondering.
Nicolas
>
> The abstraction follows the regulator abstraction and the clk series
> [2], with the reset state as a type parameter.
>
> Patch 1 adds the C helpers that patch 2 needs.
>
> Patch 2 adds ExclusiveResetControl, with the Unknown, Asserted and
> Deasserted states.
>
> Patch 3 adds ExclusiveResetControl::get_array() and
> get_array_optional(), which get all the reset lines of a device as one
> control.
>
> Patch 4 adds AssertedGuard, which asserts the line of an exclusive
> control in the Unknown state and deasserts it when dropped, as a
> convenience for drivers.
>
> Patch 5 adds SharedResetControl, with the Unknown and Deasserted states
> only, and patch 6 adds its array getters.
>
> Patch 7 adds ExclusiveResetControl::devm_deassert() and
> devm_deassert_optional(), for drivers that only need their line
> deasserted while they are bound.
>
> reset_control_reset(), the bulk API and the shared devm getters are not
> covered, and there is no guard for a Deasserted control or for a shared
> one. Nothing in the tree uses the abstraction yet.
>
> Patches 1 and 2 add the two new files to the RESET CONTROLLER FRAMEWORK
> entry of MAINTAINERS. Philipp, please let me know if you would rather
> have them elsewhere.
>
> This is based on v7.4-rc2.
>
> [0]: https://www.youtube.com/watch?v=75E15eHY7ac
> [1]: https://lore.kernel.org/r/20260912-rufs-private-v1-1-716db733e655@samsung.com
> [2]: https://lore.kernel.org/r/20261013-clk-type-state-v6-0-a5e9977b3509@collabora.com
>
> ---
> Daniel Almeida (7):
> rust: reset: add reset control helpers
> rust: reset: add ExclusiveResetControl
> rust: reset: add ExclusiveResetControl::get_array() and get_array_optional()
> rust: reset: add AssertedGuard
> rust: reset: add SharedResetControl
> rust: reset: add SharedResetControl::get_array() and get_array_optional()
> rust: reset: add devm_deassert() and devm_deassert_optional()
>
> MAINTAINERS | 2 +
> rust/bindings/bindings_helper.h | 1 +
> rust/helpers/helpers.c | 1 +
> rust/helpers/reset.c | 67 ++++
> rust/kernel/lib.rs | 1 +
> rust/kernel/reset.rs | 870 ++++++++++++++++++++++++++++++++++++++++
> 6 files changed, 942 insertions(+)
> ---
> base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
> change-id: 20261113-b4-rust-reset-ca5deca6e036
>
> Best regards,
> --
> Daniel Almeida <daniel.almeida@collabora.com>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 0/7] rust: reset: add reset control abstractions
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
0 siblings, 1 reply; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 18:02 UTC (permalink / raw)
To: Nicolas Dufresne
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Philipp Zabel, linux-kernel, rust-for-linux,
dri-devel, Detlev Casanova
Hi Nicolas,
> On 26 Nov 2026, at 13:33, Nicolas Dufresne <nicolas.dufresne@collabora.com> wrote:
>
> Hi Daniel,
>
> Le jeudi 26 novembre 2026 à 13:04 -0300, Daniel Almeida a écrit :
>> This series adds a Rust abstraction for the consumer side of the reset
>> controller API. A driver can get the reset lines of its device, as an
>> exclusive or a shared reset control, and assert and deassert them.
>>
>> This will be used by the upcoming rkvenc driver that my colleagues
>> Detlev Casanova, Nicolas Dufresne and I are working on, to recover a
>> hung core of the encoder without stopping the other one. More details on
>> this driver can be found by watching Nicolas Dufresne's talk at LPC 2026
>> [0]. Samsung's Rust UFS RFC [1] also uses reset lines, through an
>> abstraction that it has not posted.
>
> I don't mind being cited, but please give a heads-up, we haven't discussed any
> of this, so I can't really comment if its a good or bad idea. On the C side,
> shared reset don't really work today, so I'm left wondering.
>
> Nicolas
>
Fair, sorry for not giving you a heads-up. I have a branch a bit
further ahead where I have tested both encoder cores at once, including
this change. Due to the hierarchy of the power domains, to power down
core 0, you also need to power down core 1. In other words, if core 0
becomes stuck, there is no way to bring it back by means of a power
cycle without also stopping the jobs running on core 1.
This series mainly makes it possible to access the reset lines in an
established pattern (e.g. Regulator<T> already uses it, and so does the
Clk<T> series). For rkvenc, it allows pulsing only the lines of the
affected core.
Reset lines haven't come up so far because with only a single core
powered up, a power cycle is fine, since there is no other core to
affect anyway.
Also note that rkvenc does not use SharedResetControl, but I ended up
deciding to make it available as well. The same can be said of Clk<T>,
where we have devm_ and other conveniences like guards that are not
necessarily used at the moment, but that make sense when you look at
what a lot of C drivers tend to need and carry that over to Rust.
What does not work with shared resets on the C side?
— Daniel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/7] rust: reset: add reset control abstractions
2026-11-26 18:02 ` Daniel Almeida
@ 2026-11-26 18:11 ` Nicolas Dufresne
2026-11-26 18:36 ` Daniel Almeida
0 siblings, 1 reply; 14+ messages in thread
From: Nicolas Dufresne @ 2026-11-26 18:11 UTC (permalink / raw)
To: Daniel Almeida
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Philipp Zabel, linux-kernel, rust-for-linux,
dri-devel, Detlev Casanova
[-- Attachment #1: Type: text/plain, Size: 640 bytes --]
Le jeudi 26 novembre 2026 à 15:02 -0300, Daniel Almeida a écrit :
> What does not work with shared resets on the C side?
Above make sense, for shared, you need a mechanism to coordinate the reset. A
bit like the comment above you made about flushing active jobs, and holding on
new jobs until the reset has completed. I think for multiple instance of the
same driver its quite feasible, but when the triggering driver have no clue what
other driver it shares with, there is nothing as far as I know to help with this
coordination, and its possibly non-trivial, specially if that was not part of
the initial design.
Nicolas
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/7] rust: reset: add reset control abstractions
2026-11-26 18:11 ` Nicolas Dufresne
@ 2026-11-26 18:36 ` Daniel Almeida
2026-11-26 18:46 ` Nicolas Dufresne
0 siblings, 1 reply; 14+ messages in thread
From: Daniel Almeida @ 2026-11-26 18:36 UTC (permalink / raw)
To: Nicolas Dufresne
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Philipp Zabel, linux-kernel, rust-for-linux,
dri-devel, Detlev Casanova
> On 26 Nov 2026, at 15:11, Nicolas Dufresne <nicolas.dufresne@collabora.com> wrote:
>
> Le jeudi 26 novembre 2026 à 15:02 -0300, Daniel Almeida a écrit :
>> What does not work with shared resets on the C side?
>
> Above make sense, for shared, you need a mechanism to coordinate the reset. A
> bit like the comment above you made about flushing active jobs, and holding on
> new jobs until the reset has completed. I think for multiple instance of the
> same driver its quite feasible, but when the triggering driver have no clue what
> other driver it shares with, there is nothing as far as I know to help with this
> coordination, and its possibly non-trivial, specially if that was not part of
> the initial design.
>
> Nicolas
My understanding (correct me if I am wrong?) is that this coordination is
indeed needed, but baked into the C assert/deassert API:
Someone on a shared line has no power to assert the line
unconditionally, all a single consumer can say is "I'd like this line to
be asserted". The line is only asserted when all users agree (i.e.: when
all other users also ask for a reset).
So if driver A wants a reset, it gets its house in order, and asks for
it. Same for all other drivers, and it goes through when the last one
does so. This is the de-facto coordination between consumers and it is
not something that Rust influences one way or the other.
Sure, B is not told that A wants a reset, and A is not told by the reset
APIs when the reset goes through, but at least no user gets its hardware
yanked from them all of a sudden.
In fact, we do enforce this even harder by making sure that one cannot
construct a SharedResetControl<Asserted>, for the reasons above.
-- Daniel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/7] rust: reset: add reset control abstractions
2026-11-26 18:36 ` Daniel Almeida
@ 2026-11-26 18:46 ` Nicolas Dufresne
0 siblings, 0 replies; 14+ messages in thread
From: Nicolas Dufresne @ 2026-11-26 18:46 UTC (permalink / raw)
To: Daniel Almeida
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Philipp Zabel, linux-kernel, rust-for-linux,
dri-devel, Detlev Casanova
[-- Attachment #1: Type: text/plain, Size: 2207 bytes --]
Le jeudi 26 novembre 2026 à 15:36 -0300, Daniel Almeida a écrit :
>
> > On 26 Nov 2026, at 15:11, Nicolas Dufresne <nicolas.dufresne@collabora.com> wrote:
> >
> > Le jeudi 26 novembre 2026 à 15:02 -0300, Daniel Almeida a écrit :
> > > What does not work with shared resets on the C side?
> >
> > Above make sense, for shared, you need a mechanism to coordinate the reset. A
> > bit like the comment above you made about flushing active jobs, and holding on
> > new jobs until the reset has completed. I think for multiple instance of the
> > same driver its quite feasible, but when the triggering driver have no clue what
> > other driver it shares with, there is nothing as far as I know to help with this
> > coordination, and its possibly non-trivial, specially if that was not part of
> > the initial design.
> >
> > Nicolas
>
>
> My understanding (correct me if I am wrong?) is that this coordination is
> indeed needed, but baked into the C assert/deassert API:
>
> Someone on a shared line has no power to assert the line
> unconditionally, all a single consumer can say is "I'd like this line to
> be asserted". The line is only asserted when all users agree (i.e.: when
> all other users also ask for a reset).
>
> So if driver A wants a reset, it gets its house in order, and asks for
> it. Same for all other drivers, and it goes through when the last one
> does so. This is the de-facto coordination between consumers and it is
> not something that Rust influences one way or the other.
>
> Sure, B is not told that A wants a reset, and A is not told by the reset
> APIs when the reset goes through, but at least no user gets its hardware
> yanked from them all of a sudden.
Which comes back to my point, if the drivers have no back-channel, the lonely
driver wanting to reset will wait forever. And the interaction with runtime PM
seems a bit undefined too no? My question is if this is actually usable in
practice.
>
> In fact, we do enforce this even harder by making sure that one cannot
> construct a SharedResetControl<Asserted>, for the reasons above.
Maybe I'm just missing concrete examples.
Nicolas
>
> -- Daniel
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread