From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alvin Sun Date: Thu, 26 Mar 2026 14:53:00 +0800 Subject: [PATCH 07/13] rust: drm: add Device::primary_index() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260326-b4-tyr-debugfs-v1-7-074badd18716@linux.dev> References: <20260326-b4-tyr-debugfs-v1-0-074badd18716@linux.dev> In-Reply-To: <20260326-b4-tyr-debugfs-v1-0-074badd18716@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Almeida Cc: rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1774508149; l=1091; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=DA84Ymbf079qCjCVvVAH/KpIbPA3jpISHviOPMVP3qo=; b=G376wniR4/sgouAGFGuqpemjkx7s04qm0u0u+1vYHG+/xqPwdUKq00ukzZnB5dEGw4UkQJZGf g2zURToulH8BusETt7LXl3Ivbf1R1oqJf4cTcIk1q+WcExHgwBW4+j/ X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 List-Id: B4 Relay Submissions 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 --- 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(&self) -> &Device Device { + /// 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 Deref for Device { type Target = T::Data; -- 2.43.0