Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: move drm based debugfs funcs to drm_debugfs.c

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)

v10: Since we moved drm_debugfs_root, hence to handle drm bridge
debugfs add a new function which call drm_bridge_debugfs_params where
drm_debugfs_root is accessible.

Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
Link: https://lore.kernel.org/r/20250704075548.1549849-2-sunil.khatri@amd.com
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>

authored by

Sunil Khatri and committed by
Christian König
348fe34a 9cbc4052

+55 -44
-16
drivers/accel/drm_accel.c
··· 20 20 21 21 DEFINE_XARRAY_ALLOC(accel_minors_xa); 22 22 23 - static struct dentry *accel_debugfs_root; 24 - 25 23 static const struct device_type accel_sysfs_device_minor = { 26 24 .name = "accel_minor" 27 25 }; ··· 70 72 {"name", accel_name_info, 0} 71 73 }; 72 74 #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list) 73 - 74 - /** 75 - * accel_debugfs_init() - Initialize debugfs for device 76 - * @dev: Pointer to the device instance. 77 - * 78 - * This function creates a root directory for the device in debugfs. 79 - */ 80 - void accel_debugfs_init(struct drm_device *dev) 81 - { 82 - drm_debugfs_dev_init(dev, accel_debugfs_root); 83 - } 84 75 85 76 /** 86 77 * accel_debugfs_register() - Register debugfs for device ··· 181 194 void accel_core_exit(void) 182 195 { 183 196 unregister_chrdev(ACCEL_MAJOR, "accel"); 184 - debugfs_remove(accel_debugfs_root); 185 197 accel_sysfs_destroy(); 186 198 WARN_ON(!xa_empty(&accel_minors_xa)); 187 199 } ··· 194 208 DRM_ERROR("Cannot create ACCEL class: %d\n", ret); 195 209 goto error; 196 210 } 197 - 198 - accel_debugfs_root = debugfs_create_dir("accel", NULL); 199 211 200 212 ret = register_chrdev(ACCEL_MAJOR, "accel", &accel_stub_fops); 201 213 if (ret < 0)
+31 -6
drivers/gpu/drm/drm_debugfs.c
··· 44 44 #include "drm_crtc_internal.h" 45 45 #include "drm_internal.h" 46 46 47 + static struct dentry *accel_debugfs_root; 48 + static struct dentry *drm_debugfs_root; 49 + 47 50 /*************************************************** 48 51 * Initialization, etc. 49 52 **************************************************/ ··· 290 287 } 291 288 EXPORT_SYMBOL(drm_debugfs_remove_files); 292 289 290 + void drm_debugfs_bridge_params(void) 291 + { 292 + drm_bridge_debugfs_params(drm_debugfs_root); 293 + } 294 + 295 + void drm_debugfs_init_root(void) 296 + { 297 + drm_debugfs_root = debugfs_create_dir("dri", NULL); 298 + #if IS_ENABLED(CONFIG_DRM_ACCEL) 299 + accel_debugfs_root = debugfs_create_dir("accel", NULL); 300 + #endif 301 + } 302 + 303 + void drm_debugfs_remove_root(void) 304 + { 305 + #if IS_ENABLED(CONFIG_DRM_ACCEL) 306 + debugfs_remove(accel_debugfs_root); 307 + #endif 308 + debugfs_remove(drm_debugfs_root); 309 + } 310 + 293 311 /** 294 312 * drm_debugfs_dev_init - create debugfs directory for the device 295 313 * @dev: the device which we want to create the directory for 296 - * @root: the parent directory depending on the device type 297 314 * 298 315 * Creates the debugfs directory for the device under the given root directory. 299 316 */ 300 - void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root) 317 + void drm_debugfs_dev_init(struct drm_device *dev) 301 318 { 302 - dev->debugfs_root = debugfs_create_dir(dev->unique, root); 319 + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) 320 + dev->debugfs_root = debugfs_create_dir(dev->unique, accel_debugfs_root); 321 + else 322 + dev->debugfs_root = debugfs_create_dir(dev->unique, drm_debugfs_root); 303 323 } 304 324 305 325 /** ··· 349 323 drm_atomic_debugfs_init(dev); 350 324 } 351 325 352 - int drm_debugfs_register(struct drm_minor *minor, int minor_id, 353 - struct dentry *root) 326 + int drm_debugfs_register(struct drm_minor *minor, int minor_id) 354 327 { 355 328 struct drm_device *dev = minor->dev; 356 329 char name[64]; 357 330 358 331 sprintf(name, "%d", minor_id); 359 - minor->debugfs_symlink = debugfs_create_symlink(name, root, 332 + minor->debugfs_symlink = debugfs_create_symlink(name, drm_debugfs_root, 360 333 dev->unique); 361 334 362 335 /* TODO: Only for compatibility with drivers */
+5 -11
drivers/gpu/drm/drm_drv.c
··· 72 72 */ 73 73 static bool drm_core_init_complete; 74 74 75 - static struct dentry *drm_debugfs_root; 76 - 77 75 DEFINE_STATIC_SRCU(drm_unplug_srcu); 78 76 79 77 /* ··· 184 186 return 0; 185 187 186 188 if (minor->type != DRM_MINOR_ACCEL) { 187 - ret = drm_debugfs_register(minor, minor->index, 188 - drm_debugfs_root); 189 + ret = drm_debugfs_register(minor, minor->index); 189 190 if (ret) { 190 191 DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); 191 192 goto err_debugfs; ··· 784 787 goto err; 785 788 } 786 789 787 - if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) 788 - accel_debugfs_init(dev); 789 - else 790 - drm_debugfs_dev_init(dev, drm_debugfs_root); 790 + drm_debugfs_dev_init(dev); 791 791 792 792 return 0; 793 793 ··· 1224 1230 drm_panic_exit(); 1225 1231 accel_core_exit(); 1226 1232 unregister_chrdev(DRM_MAJOR, "drm"); 1227 - debugfs_remove(drm_debugfs_root); 1233 + drm_debugfs_remove_root(); 1228 1234 drm_sysfs_destroy(); 1229 1235 WARN_ON(!xa_empty(&drm_minors_xa)); 1230 1236 drm_connector_ida_destroy(); ··· 1243 1249 goto error; 1244 1250 } 1245 1251 1246 - drm_debugfs_root = debugfs_create_dir("dri", NULL); 1247 - drm_bridge_debugfs_params(drm_debugfs_root); 1252 + drm_debugfs_init_root(); 1253 + drm_debugfs_bridge_params(); 1248 1254 1249 1255 ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops); 1250 1256 if (ret < 0)
+2 -4
drivers/gpu/drm/drm_internal.h
··· 182 182 #if defined(CONFIG_DEBUG_FS) 183 183 void drm_debugfs_dev_fini(struct drm_device *dev); 184 184 void drm_debugfs_dev_register(struct drm_device *dev); 185 - int drm_debugfs_register(struct drm_minor *minor, int minor_id, 186 - struct dentry *root); 185 + int drm_debugfs_register(struct drm_minor *minor, int minor_id); 187 186 void drm_debugfs_unregister(struct drm_minor *minor); 188 187 void drm_debugfs_connector_add(struct drm_connector *connector); 189 188 void drm_debugfs_connector_remove(struct drm_connector *connector); ··· 200 201 { 201 202 } 202 203 203 - static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id, 204 - struct dentry *root) 204 + static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id) 205 205 { 206 206 return 0; 207 207 }
-5
include/drm/drm_accel.h
··· 58 58 int accel_core_init(void); 59 59 void accel_set_device_instance_params(struct device *kdev, int index); 60 60 int accel_open(struct inode *inode, struct file *filp); 61 - void accel_debugfs_init(struct drm_device *dev); 62 61 void accel_debugfs_register(struct drm_device *dev); 63 62 64 63 #else ··· 73 74 } 74 75 75 76 static inline void accel_set_device_instance_params(struct device *kdev, int index) 76 - { 77 - } 78 - 79 - static inline void accel_debugfs_init(struct drm_device *dev) 80 77 { 81 78 } 82 79
+17 -2
include/drm/drm_drv.h
··· 572 572 } 573 573 574 574 #if defined(CONFIG_DEBUG_FS) 575 - void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root); 575 + void drm_debugfs_dev_init(struct drm_device *dev); 576 + void drm_debugfs_init_root(void); 577 + void drm_debugfs_remove_root(void); 578 + void drm_debugfs_bridge_params(void); 576 579 #else 577 - static inline void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root) 580 + static inline void drm_debugfs_dev_init(struct drm_device *dev) 581 + { 582 + } 583 + 584 + static inline void drm_debugfs_init_root(void) 585 + { 586 + } 587 + 588 + static inline void drm_debugfs_remove_root(void) 589 + { 590 + } 591 + 592 + static inline void drm_debugfs_bridge_params(void) 578 593 { 579 594 } 580 595 #endif