[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250314160932.100165-3-dakr@kernel.org>
Date: Fri, 14 Mar 2025 17:09:05 +0100
From: Danilo Krummrich <dakr@...nel.org>
To: gregkh@...uxfoundation.org,
rafael@...nel.org,
bhelgaas@...gle.com,
ojeda@...nel.org,
alex.gaynor@...il.com,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me,
a.hindborg@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu
Cc: linux-kernel@...r.kernel.org,
linux-pci@...r.kernel.org,
rust-for-linux@...r.kernel.org,
Danilo Krummrich <dakr@...nel.org>
Subject: [PATCH v2 2/4] rust: device: implement device context marker
Some bus device functions should only be called from bus callbacks,
such as probe(), remove(), resume(), suspend(), etc.
To ensure this add device context marker structs, that can be used as
generics for bus device implementations.
Reviewed-by: Benno Lossin <benno.lossin@...ton.me>
Suggested-by: Benno Lossin <benno.lossin@...ton.me>
Signed-off-by: Danilo Krummrich <dakr@...nel.org>
---
rust/kernel/device.rs | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index db2d9658ba47..21b343a1dc4d 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -209,6 +209,32 @@ unsafe impl Send for Device {}
// synchronization in `struct device`.
unsafe impl Sync for Device {}
+/// Marker trait for the context of a bus specific device.
+///
+/// Some functions of a bus specific device should only be called from a certain context, i.e. bus
+/// callbacks, such as `probe()`.
+///
+/// This is the marker trait for structures representing the context of a bus specific device.
+pub trait DeviceContext: private::Sealed {}
+
+/// The [`Normal`] context is the context of a bus specific device when it is not an argument of
+/// any bus callback.
+pub struct Normal;
+
+/// The [`Core`] context is the context of a bus specific device when it is supplied as argument of
+/// any of the bus callbacks, such as `probe()`.
+pub struct Core;
+
+mod private {
+ pub trait Sealed {}
+
+ impl Sealed for super::Core {}
+ impl Sealed for super::Normal {}
+}
+
+impl DeviceContext for Core {}
+impl DeviceContext for Normal {}
+
#[doc(hidden)]
#[macro_export]
macro_rules! dev_printk {
--
2.48.1
Powered by blists - more mailing lists