From: Danilo Krummrich <dakr@kernel.org>
To: bhelgaas@google.com, gregkh@linuxfoundation.org,
rafael@kernel.org, abdiel.janulgue@gmail.com
Cc: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com,
gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, a.hindborg@kernel.org,
aliceryhl@google.com, tmgross@umich.edu,
daniel.almeida@collabora.com, robin.murphy@arm.com,
linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, Danilo Krummrich <dakr@kernel.org>
Subject: [PATCH 6/9] rust: device: implement Bound device context
Date: Mon, 31 Mar 2025 22:27:59 +0200 [thread overview]
Message-ID: <20250331202805.338468-7-dakr@kernel.org> (raw)
In-Reply-To: <20250331202805.338468-1-dakr@kernel.org>
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 --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);
};
}
--
2.49.0
next prev parent reply other threads:[~2025-03-31 20:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 20:27 [PATCH 0/9] Implement "Bound" device context Danilo Krummrich
2025-03-31 20:27 ` [PATCH 1/9] rust: device: implement impl_device_context_deref! Danilo Krummrich
2025-03-31 20:27 ` [PATCH 2/9] rust: device: implement impl_device_context_into_aref! Danilo Krummrich
2025-03-31 20:27 ` [PATCH 3/9] rust: device: implement device context for Device Danilo Krummrich
2025-03-31 20:27 ` [PATCH 4/9] rust: platform: preserve device context in AsRef Danilo Krummrich
2025-03-31 20:27 ` [PATCH 5/9] rust: pci: " Danilo Krummrich
2025-03-31 20:27 ` Danilo Krummrich [this message]
2025-03-31 20:28 ` [PATCH 7/9] rust: pci: move iomap_region() to impl Device<Bound> Danilo Krummrich
2025-03-31 20:28 ` [PATCH 8/9] rust: devres: require a bound device Danilo Krummrich
2025-03-31 20:28 ` [PATCH 9/9] rust: dma: " Danilo Krummrich
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=20250331202805.338468-7-dakr@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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