From nobody Wed Oct 8 07:31:45 2025 Received: from rtg-sunil-navi33.amd.com (unknown [165.204.156.251]) (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 D17C727F003 for ; Tue, 1 Jul 2025 16:50:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=165.204.156.251 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751388630; cv=none; b=SOxWr0QyjBfwVguRbTvISLQ4imVXJLmn8IxnU97oFFGDi61KkVeZ6N/LGFT46e81kXQYHx6HlaVc66DfYa/gubW7y1zArT0GEQnsNbCTJE129yInzlsXHuc5R/9axTJZTaTIvFBYLPkcm+1ucZir1uej0LH09aPE9kWiBkNmhks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751388630; c=relaxed/simple; bh=DE/GhsG7SmSS/3k/E3YU9zDa78RkXrd1fo6bnfK+UYY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=DmCangA0sJ3CKO2aklqrA+B4jI/5eo3r/dybxc4y+ouqLlEryt86OgM43NS39N51nPzvz2elRCPng0M4PhjQJ7We2RWiabGANYFharr35iwNbLRzGyGYE6b8h1L/o0XQzBmdla3seqh+LWo8X/9G/T62P+xaDTr9TFb/EGYT9F0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com; spf=none smtp.mailfrom=rtg-sunil-navi33.amd.com; arc=none smtp.client-ip=165.204.156.251 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=rtg-sunil-navi33.amd.com Received: from rtg-sunil-navi33.amd.com (localhost [127.0.0.1]) by rtg-sunil-navi33.amd.com (8.15.2/8.15.2/Debian-22ubuntu3) with ESMTP id 561GnrA6008159; Tue, 1 Jul 2025 22:19:53 +0530 Received: (from sunil@localhost) by rtg-sunil-navi33.amd.com (8.15.2/8.15.2/Submit) id 561Gnra5008158; Tue, 1 Jul 2025 22:19:53 +0530 From: Sunil Khatri To: =?UTF-8?q?Christian=20K=C3=B6nig?= , dri-devel@lists.freedesktop.org Cc: amd-gfx@lists.freedesktop.org, simona@ffwll.ch, tzimmermann@suse.de, tursulin@ursulin.net, phasta@kernel.org, dakr@kernel.org, linux-kernel@vger.kernel.org, Oded Gabbay , Jeff Hugo , Sunil Khatri Subject: [PATCH v9 1/4] drm: move drm based debugfs funcs to drm_debugfs.c Date: Tue, 1 Jul 2025 22:19:45 +0530 Message-Id: <20250701164948.8105-2-sunil.khatri@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250701164948.8105-1-sunil.khatri@amd.com> References: <20250701164948.8105-1-sunil.khatri@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Requirement is to create per client-id based directories to hold key debugging information and for that access to root debugfs dentry is need which is not in one place and that information cannot be stored in drm_device. Move the debugfs functionality from drm_drv.c and drm_accel.c to drm_debugfs.c This enables debugfs root node reference directly drm_debugfs.c and hence enable to create per client-id directory. v8: Create drm_accel dentry only if it's config is enabled (Jeff, Hugo) v8: Merge drm_drv and drm_accel debugfs patches (Koenig, Christian) Suggested-by: Christian K=C3=B6nig Signed-off-by: Sunil Khatri --- drivers/accel/drm_accel.c | 16 ---------------- drivers/gpu/drm/drm_debugfs.c | 32 ++++++++++++++++++++++++++------ drivers/gpu/drm/drm_drv.c | 14 ++++---------- drivers/gpu/drm/drm_internal.h | 6 ++---- include/drm/drm_accel.h | 5 ----- include/drm/drm_drv.h | 14 ++++++++++++-- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index aa826033b0ce..ca3357acd127 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -20,8 +20,6 @@ =20 DEFINE_XARRAY_ALLOC(accel_minors_xa); =20 -static struct dentry *accel_debugfs_root; - static const struct device_type accel_sysfs_device_minor =3D { .name =3D "accel_minor" }; @@ -73,17 +71,6 @@ static const struct drm_info_list accel_debugfs_list[] = =3D { }; #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list) =20 -/** - * accel_debugfs_init() - Initialize debugfs for device - * @dev: Pointer to the device instance. - * - * This function creates a root directory for the device in debugfs. - */ -void accel_debugfs_init(struct drm_device *dev) -{ - drm_debugfs_dev_init(dev, accel_debugfs_root); -} - /** * accel_debugfs_register() - Register debugfs for device * @dev: Pointer to the device instance. @@ -194,7 +181,6 @@ static const struct file_operations accel_stub_fops =3D= { void accel_core_exit(void) { unregister_chrdev(ACCEL_MAJOR, "accel"); - debugfs_remove(accel_debugfs_root); accel_sysfs_destroy(); WARN_ON(!xa_empty(&accel_minors_xa)); } @@ -209,8 +195,6 @@ int __init accel_core_init(void) goto error; } =20 - accel_debugfs_root =3D debugfs_create_dir("accel", NULL); - ret =3D register_chrdev(ACCEL_MAJOR, "accel", &accel_stub_fops); if (ret < 0) DRM_ERROR("Cannot register ACCEL major: %d\n", ret); diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 6b2178864c7e..1c0e43400475 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -44,6 +44,9 @@ #include "drm_crtc_internal.h" #include "drm_internal.h" =20 +static struct dentry *accel_debugfs_root; +static struct dentry *drm_debugfs_root; + /*************************************************** * Initialization, etc. **************************************************/ @@ -285,16 +288,34 @@ int drm_debugfs_remove_files(const struct drm_info_li= st *files, int count, } EXPORT_SYMBOL(drm_debugfs_remove_files); =20 +void drm_debugfs_init_root(void) +{ + drm_debugfs_root =3D debugfs_create_dir("dri", NULL); +#if IS_ENABLED(CONFIG_DRM_ACCEL) + accel_debugfs_root =3D debugfs_create_dir("accel", NULL); +#endif +} + +void drm_debugfs_remove_root(void) +{ +#if IS_ENABLED(CONFIG_DRM_ACCEL) + debugfs_remove(accel_debugfs_root); +#endif + debugfs_remove(drm_debugfs_root); +} + /** * drm_debugfs_dev_init - create debugfs directory for the device * @dev: the device which we want to create the directory for - * @root: the parent directory depending on the device type * * Creates the debugfs directory for the device under the given root direc= tory. */ -void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root) +void drm_debugfs_dev_init(struct drm_device *dev) { - dev->debugfs_root =3D debugfs_create_dir(dev->unique, root); + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) + dev->debugfs_root =3D debugfs_create_dir(dev->unique, accel_debugfs_root= ); + else + dev->debugfs_root =3D debugfs_create_dir(dev->unique, drm_debugfs_root); } =20 /** @@ -321,14 +342,13 @@ void drm_debugfs_dev_register(struct drm_device *dev) drm_atomic_debugfs_init(dev); } =20 -int drm_debugfs_register(struct drm_minor *minor, int minor_id, - struct dentry *root) +int drm_debugfs_register(struct drm_minor *minor, int minor_id) { struct drm_device *dev =3D minor->dev; char name[64]; =20 sprintf(name, "%d", minor_id); - minor->debugfs_symlink =3D debugfs_create_symlink(name, root, + minor->debugfs_symlink =3D debugfs_create_symlink(name, drm_debugfs_root, dev->unique); =20 /* TODO: Only for compatibility with drivers */ diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 17fc5dc708f4..b9b5c9f953af 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -69,8 +69,6 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa); */ static bool drm_core_init_complete; =20 -static struct dentry *drm_debugfs_root; - DEFINE_STATIC_SRCU(drm_unplug_srcu); =20 /* @@ -183,8 +181,7 @@ static int drm_minor_register(struct drm_device *dev, e= num drm_minor_type type) return 0; =20 if (minor->type !=3D DRM_MINOR_ACCEL) { - ret =3D drm_debugfs_register(minor, minor->index, - drm_debugfs_root); + ret =3D drm_debugfs_register(minor, minor->index); if (ret) { DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); goto err_debugfs; @@ -751,10 +748,7 @@ static int drm_dev_init(struct drm_device *dev, goto err; } =20 - if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) - accel_debugfs_init(dev); - else - drm_debugfs_dev_init(dev, drm_debugfs_root); + drm_debugfs_dev_init(dev); =20 return 0; =20 @@ -1168,7 +1162,7 @@ static void drm_core_exit(void) drm_panic_exit(); accel_core_exit(); unregister_chrdev(DRM_MAJOR, "drm"); - debugfs_remove(drm_debugfs_root); + drm_debugfs_remove_root(); drm_sysfs_destroy(); WARN_ON(!xa_empty(&drm_minors_xa)); drm_connector_ida_destroy(); @@ -1187,7 +1181,7 @@ static int __init drm_core_init(void) goto error; } =20 - drm_debugfs_root =3D debugfs_create_dir("dri", NULL); + drm_debugfs_init_root(); =20 ret =3D register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops); if (ret < 0) diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index b2b6a8e49dda..d2d8e72f32d9 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -186,8 +186,7 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct = iosys_map *map); #if defined(CONFIG_DEBUG_FS) void drm_debugfs_dev_fini(struct drm_device *dev); void drm_debugfs_dev_register(struct drm_device *dev); -int drm_debugfs_register(struct drm_minor *minor, int minor_id, - struct dentry *root); +int drm_debugfs_register(struct drm_minor *minor, int minor_id); void drm_debugfs_unregister(struct drm_minor *minor); void drm_debugfs_connector_add(struct drm_connector *connector); void drm_debugfs_connector_remove(struct drm_connector *connector); @@ -205,8 +204,7 @@ static inline void drm_debugfs_dev_register(struct drm_= device *dev) { } =20 -static inline int drm_debugfs_register(struct drm_minor *minor, int minor_= id, - struct dentry *root) +static inline int drm_debugfs_register(struct drm_minor *minor, int minor_= id) { return 0; } diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h index 038ccb02f9a3..20a665ec6f16 100644 --- a/include/drm/drm_accel.h +++ b/include/drm/drm_accel.h @@ -58,7 +58,6 @@ void accel_core_exit(void); int accel_core_init(void); void accel_set_device_instance_params(struct device *kdev, int index); int accel_open(struct inode *inode, struct file *filp); -void accel_debugfs_init(struct drm_device *dev); void accel_debugfs_register(struct drm_device *dev); =20 #else @@ -77,10 +76,6 @@ static inline void accel_set_device_instance_params(stru= ct device *kdev, int ind { } =20 -static inline void accel_debugfs_init(struct drm_device *dev) -{ -} - static inline void accel_debugfs_register(struct drm_device *dev) { } diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index a43d707b5f36..392baeaaa4a1 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -566,9 +566,19 @@ static inline bool drm_firmware_drivers_only(void) } =20 #if defined(CONFIG_DEBUG_FS) -void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root); +void drm_debugfs_dev_init(struct drm_device *dev); +void drm_debugfs_init_root(void); +void drm_debugfs_remove_root(void); #else -static inline void drm_debugfs_dev_init(struct drm_device *dev, struct den= try *root) +static inline void drm_debugfs_dev_init(struct drm_device *dev) +{ +} + +static inline void drm_debugfs_init_root(void) +{ +} + +static inline void drm_debugfs_remove_root(void) { } #endif --=20 2.34.1