The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Deborah Brouwer <deborah.brouwer@collabora.com>
To: "Alice Ryhl" <aliceryhl@google.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Daniel Almeida" <daniel.almeida@collabora.com>
Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org,
	 linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	 boris.brezillon@collabora.com, beata.michalska@arm.com,
	lyude@redhat.com,  acourbot@nvidia.com, work@onurozkan.dev,
	alvin.sun@linux.dev,  Laura Nao <laura.nao@collabora.com>,
	 Deborah Brouwer <deborah.brouwer@collabora.com>
Subject: [PATCH 3/7] drm/rust: add File::device() helper
Date: Thu, 07 May 2026 16:32:41 -0700	[thread overview]
Message-ID: <20260507-tyr-mmap-v1-3-eec048a23c25@collabora.com> (raw)
In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com>

Add a helper to retrieve the DRM device associated with an open
`drm::file::File<T>`.

This wraps the common pattern of traversing `drm_file.minor->dev` and
returning the corresponding `drm::Device<T::Driver>`.

This is useful for DRM file operation callbacks that need access to the
owning DRM device from a `File<T>` reference, avoiding repeated open-coded
raw pointer traversal in drivers.

Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
 rust/kernel/drm/file.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/rust/kernel/drm/file.rs b/rust/kernel/drm/file.rs
index 10160601ce5a..5af28a9558e9 100644
--- a/rust/kernel/drm/file.rs
+++ b/rust/kernel/drm/file.rs
@@ -45,6 +45,18 @@ pub(super) fn as_raw(&self) -> *mut bindings::drm_file {
         self.0.get()
     }
 
+    /// Returns the DRM device associated with this open file.
+    pub fn device(&self) -> &drm::Device<T::Driver> {
+        // SAFETY: By the type invariant, `self.as_raw()` points to a valid open
+        // `struct drm_file`. DRM initializes `minor` for open DRM files, and
+        // `minor->dev` points to the registered DRM device associated with this
+        // file.
+        unsafe {
+            let minor = (*self.as_raw()).minor;
+            drm::Device::from_raw((*minor).dev)
+        }
+    }
+
     fn driver_priv(&self) -> *mut T {
         // SAFETY: By the type invariants of `Self`, `self.as_raw()` is always valid.
         unsafe { (*self.as_raw()).driver_priv }.cast()

-- 
2.53.0


  parent reply	other threads:[~2026-05-07 23:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 23:32 [PATCH 0/7] drm/tyr: add userspace MMIO mmap support Deborah Brouwer
2026-05-07 23:32 ` [PATCH 1/7] mm: rust: add pgprot_noncached helper Deborah Brouwer
2026-05-07 23:32 ` [PATCH 2/7] mm: rust: add VMA page offset helper Deborah Brouwer
2026-05-07 23:32 ` Deborah Brouwer [this message]
2026-05-07 23:32 ` [PATCH 4/7] drm/rust: allow drivers to override file operations Deborah Brouwer
2026-05-07 23:32 ` [PATCH 5/7] drm/tyr: add USER register page definitions Deborah Brouwer
2026-05-07 23:32 ` [PATCH 6/7] drm/tyr: store MMIO physical base address Deborah Brouwer
2026-05-07 23:32 ` [PATCH 7/7] drm/tyr: add userspace MMIO mmap support Deborah Brouwer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260507-tyr-mmap-v1-3-eec048a23c25@collabora.com \
    --to=deborah.brouwer@collabora.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=alvin.sun@linux.dev \
    --cc=beata.michalska@arm.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=boris.brezillon@collabora.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=laura.nao@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox