summaryrefslogtreecommitdiff
path: root/rust/kernel/pci.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/kernel/pci.rs')
-rw-r--r--rust/kernel/pci.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 410b79d46632..82e128431f08 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -24,6 +24,7 @@ use crate::{
};
use core::{
marker::PhantomData,
+ mem::offset_of,
ptr::{
addr_of_mut,
NonNull, //
@@ -443,6 +444,12 @@ impl Device<device::Core> {
}
}
+// SAFETY: `pci::Device` is a transparent wrapper of `struct pci_dev`.
+// The offset is guaranteed to point to a valid device field inside `pci::Device`.
+unsafe impl<Ctx: device::DeviceContext> device::AsBusDevice<Ctx> for Device<Ctx> {
+ const OFFSET: usize = offset_of!(bindings::pci_dev, dev);
+}
+
// SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic
// argument.
kernel::impl_device_context_deref!(unsafe { Device });