Skip to content

Commit f933b74

Browse files
author
Danilo Krummrich
committed
rust: device: implement Bound device context
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. Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Add missing `::` prefix in macros. - Danilo ] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 3edaefb commit f933b74

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

rust/kernel/device.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,19 @@ pub struct Normal;
232232
/// any of the bus callbacks, such as `probe()`.
233233
pub struct Core;
234234

235+
/// The [`Bound`] context is the context of a bus specific device reference when it is guaranteed to
236+
/// be bound for the duration of its lifetime.
237+
pub struct Bound;
238+
235239
mod private {
236240
pub trait Sealed {}
237241

242+
impl Sealed for super::Bound {}
238243
impl Sealed for super::Core {}
239244
impl Sealed for super::Normal {}
240245
}
241246

247+
impl DeviceContext for Bound {}
242248
impl DeviceContext for Core {}
243249
impl DeviceContext for Normal {}
244250

@@ -281,7 +287,14 @@ macro_rules! impl_device_context_deref {
281287
// `__impl_device_context_deref!`.
282288
::kernel::__impl_device_context_deref!(unsafe {
283289
$device,
284-
$crate::device::Core => $crate::device::Normal
290+
$crate::device::Core => $crate::device::Bound
291+
});
292+
293+
// SAFETY: This macro has the exact same safety requirement as
294+
// `__impl_device_context_deref!`.
295+
::kernel::__impl_device_context_deref!(unsafe {
296+
$device,
297+
$crate::device::Bound => $crate::device::Normal
285298
});
286299
};
287300
}
@@ -304,6 +317,7 @@ macro_rules! __impl_device_context_into_aref {
304317
macro_rules! impl_device_context_into_aref {
305318
($device:tt) => {
306319
::kernel::__impl_device_context_into_aref!($crate::device::Core, $device);
320+
::kernel::__impl_device_context_into_aref!($crate::device::Bound, $device);
307321
};
308322
}
309323

0 commit comments

Comments
 (0)