From: Alvin Sun Date: Sun, 22 Nov 2026 20:50:25 +0800 Subject: [PATCH v7 06/10] drm/tyr: add BO creation and lookup helpers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261122-tyr-ioctls-v7-6-3a2af624b992@linux.dev> References: <20261122-tyr-ioctls-v7-0-3a2af624b992@linux.dev> In-Reply-To: <20261122-tyr-ioctls-v7-0-3a2af624b992@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 , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , Lyude Paul , David Airlie , Simona Vetter , Greg Kroah-Hartman , "Rafael J. Wysocki" , Johan Hovold Cc: Sami Tolvanen , rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, driver-core@lists.linux.dev, Ke Sun , Alvin Sun X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795352551; l=2048; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=NWIPbx+eohkv3FNLcTsYqaXCTEHpzUO212X/sd33Vuo=; b=rVsp8LsarTYLUQnbwabWjT1vlXXdryHF7kLwQPKuCkX6AJ8l/rBx1+aAEqzCDTY3pN8g6Y43+ P6WCKtCcBElBkSuUu7aneKezy6GS+ax/Q+KjJRHqX2N5KjTlFvCmVUb 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 helpers for the BO ioctls: new_object() creates a GEM object with the size aligned up to PAGE_SIZE, and lookup_handle() resolves a handle for a DRM file. Signed-off-by: Alvin Sun Reviewed-by: Daniel Almeida --- drivers/gpu/drm/tyr/gem.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tyr/gem.rs b/drivers/gpu/drm/tyr/gem.rs index 3bf3787f5c3fd..0e0989a48678f 100644 --- a/drivers/gpu/drm/tyr/gem.rs +++ b/drivers/gpu/drm/tyr/gem.rs @@ -9,8 +9,10 @@ use kernel::{ drm::gem::{ self, - shmem, // + shmem, + BaseObject, // }, + page::PAGE_SIZE, prelude::*, sync::{ aref::ARef, @@ -23,6 +25,7 @@ TyrDrmDevice, TyrDrmDriver, // }, + file::TyrDrmFile, vm::{ Vm, VmMapFlags, // @@ -53,6 +56,32 @@ fn new(_dev: &TyrDrmDevice, _size: usize, args: BoCreateArgs) -> impl PinInit; +/// Create a new GEM buffer object. +#[expect(dead_code)] +pub(crate) fn new_object(ddev: &TyrDrmDevice, size: usize, flags: u32) -> Result> { + if size == 0 { + return Err(EINVAL); + } + + let aligned_size = size.checked_next_multiple_of(PAGE_SIZE).ok_or(EINVAL)?; + + Bo::new( + ddev, + aligned_size, + shmem::ObjectConfig { + map_wc: true, + parent_resv_obj: None, + }, + BoCreateArgs { flags }, + ) +} + +/// Look up a GEM object by handle for a DRM file. +#[expect(dead_code)] +pub(crate) fn lookup_handle(file: &TyrDrmFile, handle: u32) -> Result> { + Bo::lookup_handle(file, handle) +} + /// Creates a dummy GEM object to serve as the root of a GPUVM. pub(crate) fn new_dummy_object(ddev: &TyrDrmDevice) -> Result> { let bo = Bo::new( -- 2.43.0