Add primary_index() to return the primary minor index (e.g. the N in /dev/dri/cardN). Needed by drivers to register per-device debugfs under a unique directory name.
Signed-off-by: Alvin Sun <[email protected]> --- rust/kernel/drm/device.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index d7bb338efb9d8..268ac02e800fd 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -336,6 +336,16 @@ pub(crate) unsafe fn assume_ctx<NewCtx: DeviceContext>(&self) -> &Device<T, NewC } } +impl<T: drm::Driver> Device<T, Registered> { + /// Returns the primary minor index (the number in `/dev/dri/cardN`). + #[inline] + pub fn primary_index(&self) -> u32 { + // SAFETY: `self.as_raw()` is guaranteed to be a valid pointer to a `struct drm_device`. + let index = unsafe { (*(*self.as_raw()).primary).index }; + index as u32 + } +} + impl<T: drm::Driver> Deref for Device<T, Registered> { type Target = T::Data; -- 2.43.0
