diff mbox series

[6/9] rust: device: implement Bound device context

Message ID 20250331202805.338468-7-dakr@kernel.org (mailing list archive)
State Handled Elsewhere
Delegated to: Bjorn Helgaas
Headers show
Series Implement "Bound" device context | expand

Commit Message

Danilo Krummrich March 31, 2025, 8:27 p.m. UTC
The Bound device context indicates that a device is bound to a driver.
It must be used for APIs that require the device to be bound, such as
Devres or dma::CoherentAllocation.

Implement Bound and add the corresponding Deref hierarchy, as well as the
corresponding ARef conversion for this device context.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 rust/kernel/device.rs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index 2d98e650376e..a7da1519439d 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -230,13 +230,19 @@  pub trait DeviceContext: private::Sealed {}
 /// any of the bus callbacks, such as `probe()`.
 pub struct Core;
 
+/// The [`Bound`] context is the context of a bus specific device reference when it is guranteed to
+/// be bound for the duration of its lifetime.
+pub struct Bound;
+
 mod private {
     pub trait Sealed {}
 
+    impl Sealed for super::Bound {}
     impl Sealed for super::Core {}
     impl Sealed for super::Normal {}
 }
 
+impl DeviceContext for Bound {}
 impl DeviceContext for Core {}
 impl DeviceContext for Normal {}
 
@@ -265,7 +271,12 @@  fn deref(&self) -> &Self::Target {
 #[macro_export]
 macro_rules! impl_device_context_deref {
     ($device:tt) => {
-        kernel::__impl_device_context_deref!($crate::device::Core, $crate::device::Normal, $device);
+        kernel::__impl_device_context_deref!($crate::device::Core, $crate::device::Bound, $device);
+        kernel::__impl_device_context_deref!(
+            $crate::device::Bound,
+            $crate::device::Normal,
+            $device
+        );
     };
 }
 
@@ -287,6 +298,7 @@  fn from(dev: &$device<$src>) -> Self {
 macro_rules! impl_device_context_into_aref {
     ($device:tt) => {
         kernel::__impl_device_context_into_aref!($crate::device::Core, $device);
+        kernel::__impl_device_context_into_aref!($crate::device::Bound, $device);
     };
 }