From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F981435A9D; Thu, 30 Jul 2026 17:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785431151; cv=none; b=jSNA1H4bJ+i9POtrwQ0t16tv3jfqf5fgqXeo61gy+am238jQuedpGWsxhHV8cKHJnyTcb4wz9OyafQ9GzPlaJcOjeZHXco+EhzAKjo9I61A7W0JA3QZx0OfBnN9NvMZDxR5M+I27EazAi+iCTiWXkHyhXS+T4aaw2cjCUxyaq68= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785431151; c=relaxed/simple; bh=Mu/THEs4NT5nNw4z7NqjGMWVALSaA8dgypD02/JDRXs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qcMJPNe1Y5KrKGOpQjUqpG3hJKCOUUWKA8Topbbqi406M6C8zO1UDXvHhWKns69IIwsQxuYjypFT3EcpyP5DIe9Wp33R6A8fB6YusAkD3yZWjihgP98rRAyaW4X6Mw2okibONZCzal/Y5/PPShQcl153wT6WQvihnaIc0SShOx4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ynCcWmuX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ynCcWmuX" Received: by smtp.kernel.org (Postfix) with ESMTPS id 09E6DC2BD04; Thu, 30 Jul 2026 17:05:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1785431151; bh=Mu/THEs4NT5nNw4z7NqjGMWVALSaA8dgypD02/JDRXs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ynCcWmuXnB0jjo1gfEzF2jgxiV2aL0oZzLWejxsMLXb4okCPLe3K7+G64qxTK4MIo 6rNizpKjra+f6AvlJ25j+D+OYwTWtqqOaWRlKiYjQnpXP7YDpeA7koaKn++mlN071N 7z5nZrEFA7ueImCwM19zTdbwN1+n6Yzuhp1/NiIc= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECB5AC55164; Thu, 30 Jul 2026 17:05:50 +0000 (UTC) From: Alvin Sun Date: Fri, 31 Jul 2026 01:05:43 +0800 Subject: [PATCH v2 5/9] rust: drm: add debugfs_init callback to Driver trait Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260731-tyr-debugfs-v2-v2-5-aea19eccb996@linux.dev> References: <20260731-tyr-debugfs-v2-v2-0-aea19eccb996@linux.dev> In-Reply-To: <20260731-tyr-debugfs-v2-v2-0-aea19eccb996@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?= , Greg Kroah-Hartman , "Rafael J. Wysocki" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: Alexander Viro , Christian Brauner , Jan Kara , Matthew Brost , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , =?utf-8?q?Ma=C3=ADra_Canal?= , Melissa Wen , Wambui Karuga , Eric Anholt , Ben Gamari , rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1785431148; l=4261; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=Mu/THEs4NT5nNw4z7NqjGMWVALSaA8dgypD02/JDRXs=; b=Vv+KfURg6kwiS2V3pkSEKb24JmkZRi0mkucL3WPHVnRo6orv2pNtzyrdWBlpd9MdSl2XLFoEQ faMxHsP+XSCCZhDPDUwU633m6r4bYMpHblmSoeScV4tqQqJjnmvF8px 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 Add debugfs_init method to the Driver trait, enabling Rust DRM drivers to populate debugfs entries during device registration. The C callback converts from raw C minor/dentry types to Rust Device and ScopedDir references. Signed-off-by: Alvin Sun --- rust/bindings/bindings_helper.h | 1 + rust/kernel/drm/device.rs | 36 ++++++++++++++++++++++++++++++++++-- rust/kernel/drm/driver.rs | 11 +++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 1124785e210b3..c3b2a86528934 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index 7a3a0e21e9557..c9aa5d2374444 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -7,6 +7,7 @@ use crate::{ alloc::allocator::Kmalloc, bindings, + debugfs::ScopedDir, device, drm::{ self, @@ -39,7 +40,7 @@ ptr::{ self, NonNull, // - }, + }, // }; #[cfg(CONFIG_DRM_LEGACY)] @@ -170,7 +171,7 @@ const fn compute_features() -> u32 { release: Some(Device::::release), master_set: None, master_drop: None, - debugfs_init: None, + debugfs_init: Some(Device::::debugfs_init_callback), gem_create_object: T::Object::ALLOC_OPS.gem_create_object, prime_handle_to_fd: T::Object::ALLOC_OPS.prime_handle_to_fd, @@ -353,6 +354,37 @@ extern "C" fn release(ptr: *mut bindings::drm_device) { unsafe { core::ptr::drop_in_place(this) }; } + /// C callback for `drm_driver.debugfs_init`. + /// + /// # Safety + /// + /// The DRM core guarantees that `minor` is valid and non-null when calling + /// this callback, and that `minor->dev` is a valid `drm_device` embedded + /// in a `Device`. + unsafe extern "C" fn debugfs_init_callback(minor: *mut bindings::drm_minor) { + // SAFETY: `minor` is valid and non-null per the function's safety + // precondition. + let dev_ptr = unsafe { (*minor).dev }; + // SAFETY: `minor` is valid per the function's safety precondition. + let debugfs_root = unsafe { (*minor).debugfs_root }; + + // Debugfs may be disabled. + if debugfs_root.is_null() { + return; + } + + // SAFETY: `dev_ptr` points to a valid `drm_device` embedded in + // `Device`. `debugfs_init` runs during registration, so + // the `Normal` context is correct. + let device = unsafe { Device::::from_raw(dev_ptr) }; + + // SAFETY: `debugfs_root` is a valid dentry that remains alive as long as the + // DRM device is registered, which outlives this `ScopedDir`. + let dir = unsafe { ScopedDir::from_dentry(debugfs_root) }; + + T::debugfs_init(device, &dir); + } + /// Change the [`DeviceContext`] for a [`Device`]. /// /// # Safety diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index 08b2a318cf02a..7f3a6eaeddc5e 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -6,6 +6,7 @@ use crate::{ bindings, + debugfs::ScopedDir, device, drm, error::to_result, @@ -138,6 +139,16 @@ pub trait Driver { /// usable from the render node (i.e. marked DRM_RENDER_ALLOW), whereas /// userspace processes using the master node can invoke any ioctl. const FEAT_RENDER: bool = false; + + /// Populates debugfs for this DRM device. + /// + /// Called by the DRM core during registration, once per minor (callback + /// runs after `dev->registered`). + fn debugfs_init<'a>(_dev: &'a drm::Device, _dir: &ScopedDir<'a, 'static>) + where + Self: Sized, + { + } } /// The registration type of a `drm::Device`. -- 2.43.0