rust: drm: add AsRef<ParentDevice<Bound>> for Device<Registered>

Implement AsRef<T::ParentDevice<Bound>> for Device<T, Registered>,
providing access to the bound parent bus device for registered DRM
devices.

Since a Device<T, Registered> guarantees that the parent bus device is
bound, the conversion to T::ParentDevice<Bound> is safe.

Reviewed-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Deborah Brouwer <deborah.brouwer@collabora.com>
Link: https://patch.msgid.link/20260628145406.2107056-16-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Danilo Krummrich 2026-06-28 16:53:35 +02:00
parent 47f600d40b
commit 453197b7cc

View File

@ -462,6 +462,20 @@ fn as_ref(&self) -> &T::ParentDevice<device::Normal> {
}
}
impl<T: drm::Driver> AsRef<T::ParentDevice<device::Bound>> for Device<T, Registered> {
#[inline]
fn as_ref(&self) -> &T::ParentDevice<device::Bound> {
let dev = (**self).as_ref().as_ref();
// SAFETY: A `Device<T, Registered>` guarantees that the parent device is bound.
let dev = unsafe { dev.as_bound() };
// SAFETY: The DRM device was constructed in `UnregisteredDevice::new()` with a parent
// device of type `T::ParentDevice`, hence `dev` is contained in a `T::ParentDevice`.
unsafe { device::AsBusDevice::from_device(dev) }
}
}
// SAFETY: A `drm::Device` can be released from any thread.
unsafe impl<T: drm::Driver, C: DeviceContext> Send for Device<T, C> {}