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

drm/debugfs: rework debugfs directory creation v5

Instead of the per minor directories only create a single debugfs
directory for the whole device directly when the device is initialized.

For DRM devices each minor gets a symlink to the per device directory
for now until we can be sure that this isn't useful any more in any way.

Accel devices create only the per device directory and also drops the mid
layer callback to create driver specific files.

v2: cleanup accel component as well
v3: fix typo when debugfs is disabled
v4: call drm_debugfs_dev_fini() during release as well,
some kerneldoc typos fixed
v5: rebased and one more kerneldoc fix

Signed-off-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230829110115.3442-4-christian.koenig@amd.com
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>

authored by

Christian König and committed by
Christian König
0b30d57a 19ecbe83

+136 -58
+18 -12
drivers/accel/drm_accel.c
··· 79 79 #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list) 80 80 81 81 /** 82 - * accel_debugfs_init() - Initialize debugfs for accel minor 83 - * @minor: Pointer to the drm_minor instance. 84 - * @minor_id: The minor's id 82 + * accel_debugfs_init() - Initialize debugfs for device 83 + * @dev: Pointer to the device instance. 85 84 * 86 - * This function initializes the drm minor's debugfs members and creates 87 - * a root directory for the minor in debugfs. It also creates common files 88 - * for accelerators and calls the driver's debugfs init callback. 85 + * This function creates a root directory for the device in debugfs. 89 86 */ 90 - void accel_debugfs_init(struct drm_minor *minor, int minor_id) 87 + void accel_debugfs_init(struct drm_device *dev) 91 88 { 92 - struct drm_device *dev = minor->dev; 93 - char name[64]; 89 + drm_debugfs_dev_init(dev, accel_debugfs_root); 90 + } 91 + 92 + /** 93 + * accel_debugfs_register() - Register debugfs for device 94 + * @dev: Pointer to the device instance. 95 + * 96 + * Creates common files for accelerators. 97 + */ 98 + void accel_debugfs_register(struct drm_device *dev) 99 + { 100 + struct drm_minor *minor = dev->accel; 94 101 95 102 INIT_LIST_HEAD(&minor->debugfs_list); 96 103 mutex_init(&minor->debugfs_lock); 97 - sprintf(name, "%d", minor_id); 98 - minor->debugfs_root = debugfs_create_dir(name, accel_debugfs_root); 104 + minor->debugfs_root = dev->debugfs_root; 99 105 100 106 drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES, 101 - minor->debugfs_root, minor); 107 + dev->debugfs_root, minor); 102 108 } 103 109 104 110 /**
+2 -2
drivers/gpu/drm/drm_atomic.c
··· 1832 1832 {"state", drm_state_info, 0}, 1833 1833 }; 1834 1834 1835 - void drm_atomic_debugfs_init(struct drm_minor *minor) 1835 + void drm_atomic_debugfs_init(struct drm_device *dev) 1836 1836 { 1837 - drm_debugfs_add_files(minor->dev, drm_atomic_debugfs_list, 1837 + drm_debugfs_add_files(dev, drm_atomic_debugfs_list, 1838 1838 ARRAY_SIZE(drm_atomic_debugfs_list)); 1839 1839 } 1840 1840 #endif
+2 -2
drivers/gpu/drm/drm_bridge.c
··· 1384 1384 { "bridge_chains", drm_bridge_chains_info, 0 }, 1385 1385 }; 1386 1386 1387 - void drm_bridge_debugfs_init(struct drm_minor *minor) 1387 + void drm_bridge_debugfs_init(struct drm_device *dev) 1388 1388 { 1389 - drm_debugfs_add_files(minor->dev, drm_bridge_debugfs_list, 1389 + drm_debugfs_add_files(dev, drm_bridge_debugfs_list, 1390 1390 ARRAY_SIZE(drm_bridge_debugfs_list)); 1391 1391 } 1392 1392 #endif
+2 -2
drivers/gpu/drm/drm_client.c
··· 535 535 { "internal_clients", drm_client_debugfs_internal_clients, 0 }, 536 536 }; 537 537 538 - void drm_client_debugfs_init(struct drm_minor *minor) 538 + void drm_client_debugfs_init(struct drm_device *dev) 539 539 { 540 - drm_debugfs_add_files(minor->dev, drm_client_debugfs_list, 540 + drm_debugfs_add_files(dev, drm_client_debugfs_list, 541 541 ARRAY_SIZE(drm_client_debugfs_list)); 542 542 } 543 543 #endif
+1 -1
drivers/gpu/drm/drm_crtc_internal.h
··· 232 232 /* drm_atomic.c */ 233 233 #ifdef CONFIG_DEBUG_FS 234 234 struct drm_minor; 235 - void drm_atomic_debugfs_init(struct drm_minor *minor); 235 + void drm_atomic_debugfs_init(struct drm_device *dev); 236 236 #endif 237 237 238 238 int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
+52 -24
drivers/gpu/drm/drm_debugfs.c
··· 266 266 } 267 267 EXPORT_SYMBOL(drm_debugfs_create_files); 268 268 269 - int drm_debugfs_init(struct drm_minor *minor, int minor_id, 270 - struct dentry *root) 269 + /** 270 + * drm_debugfs_dev_init - create debugfs directory for the device 271 + * @dev: the device which we want to create the directory for 272 + * @root: the parent directory depending on the device type 273 + * 274 + * Creates the debugfs directory for the device under the given root directory. 275 + */ 276 + void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root) 277 + { 278 + dev->debugfs_root = debugfs_create_dir(dev->unique, root); 279 + } 280 + 281 + /** 282 + * drm_debugfs_dev_fini - cleanup debugfs directory 283 + * @dev: the device to cleanup the debugfs stuff 284 + * 285 + * Remove the debugfs directory, might be called multiple times. 286 + */ 287 + void drm_debugfs_dev_fini(struct drm_device *dev) 288 + { 289 + debugfs_remove_recursive(dev->debugfs_root); 290 + dev->debugfs_root = NULL; 291 + } 292 + 293 + void drm_debugfs_dev_register(struct drm_device *dev) 294 + { 295 + drm_debugfs_add_files(dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES); 296 + 297 + if (drm_core_check_feature(dev, DRIVER_MODESET)) { 298 + drm_framebuffer_debugfs_init(dev); 299 + drm_client_debugfs_init(dev); 300 + } 301 + if (drm_drv_uses_atomic_modeset(dev)) { 302 + drm_atomic_debugfs_init(dev); 303 + drm_bridge_debugfs_init(dev); 304 + } 305 + } 306 + 307 + int drm_debugfs_register(struct drm_minor *minor, int minor_id, 308 + struct dentry *root) 271 309 { 272 310 struct drm_device *dev = minor->dev; 273 311 struct drm_debugfs_entry *entry, *tmp; ··· 314 276 INIT_LIST_HEAD(&minor->debugfs_list); 315 277 mutex_init(&minor->debugfs_lock); 316 278 sprintf(name, "%d", minor_id); 317 - minor->debugfs_root = debugfs_create_dir(name, root); 279 + minor->debugfs_symlink = debugfs_create_symlink(name, root, 280 + dev->unique); 318 281 319 - drm_debugfs_add_files(minor->dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES); 320 - 321 - if (drm_drv_uses_atomic_modeset(dev)) { 322 - drm_atomic_debugfs_init(minor); 323 - drm_bridge_debugfs_init(minor); 324 - } 325 - 326 - if (drm_core_check_feature(dev, DRIVER_MODESET)) { 327 - drm_framebuffer_debugfs_init(minor); 328 - 329 - drm_client_debugfs_init(minor); 330 - } 282 + /* TODO: Only for compatibility with drivers */ 283 + minor->debugfs_root = dev->debugfs_root; 331 284 332 285 if (dev->driver->debugfs_init && dev->render != minor) 333 286 dev->driver->debugfs_init(minor); ··· 385 356 386 357 void drm_debugfs_cleanup(struct drm_minor *minor) 387 358 { 388 - if (!minor->debugfs_root) 359 + if (!minor->debugfs_symlink) 389 360 return; 390 361 391 362 drm_debugfs_remove_all_files(minor); 392 - 393 - debugfs_remove_recursive(minor->debugfs_root); 394 - minor->debugfs_root = NULL; 363 + debugfs_remove(minor->debugfs_symlink); 364 + minor->debugfs_symlink = NULL; 395 365 } 396 366 397 367 /** ··· 575 547 576 548 void drm_debugfs_connector_add(struct drm_connector *connector) 577 549 { 578 - struct drm_minor *minor = connector->dev->primary; 550 + struct drm_device *dev = connector->dev; 579 551 struct dentry *root; 580 552 581 - if (!minor->debugfs_root) 553 + if (!dev->debugfs_root) 582 554 return; 583 555 584 - root = debugfs_create_dir(connector->name, minor->debugfs_root); 556 + root = debugfs_create_dir(connector->name, dev->debugfs_root); 585 557 connector->debugfs_entry = root; 586 558 587 559 /* force */ ··· 616 588 617 589 void drm_debugfs_crtc_add(struct drm_crtc *crtc) 618 590 { 619 - struct drm_minor *minor = crtc->dev->primary; 591 + struct drm_device *dev = crtc->dev; 620 592 struct dentry *root; 621 593 char *name; 622 594 ··· 624 596 if (!name) 625 597 return; 626 598 627 - root = debugfs_create_dir(name, minor->debugfs_root); 599 + root = debugfs_create_dir(name, dev->debugfs_root); 628 600 kfree(name); 629 601 630 602 crtc->debugfs_entry = root;
+17 -4
drivers/gpu/drm/drm_drv.c
··· 172 172 if (!minor) 173 173 return 0; 174 174 175 - if (minor->type == DRM_MINOR_ACCEL) { 176 - accel_debugfs_init(minor, minor->index); 177 - } else { 178 - ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); 175 + if (minor->type != DRM_MINOR_ACCEL) { 176 + ret = drm_debugfs_register(minor, minor->index, 177 + drm_debugfs_root); 179 178 if (ret) { 180 179 DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); 181 180 goto err_debugfs; ··· 696 697 goto err; 697 698 } 698 699 700 + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) 701 + accel_debugfs_init(dev); 702 + else 703 + drm_debugfs_dev_init(dev, drm_debugfs_root); 704 + 699 705 return 0; 700 706 701 707 err: ··· 789 785 static void drm_dev_release(struct kref *ref) 790 786 { 791 787 struct drm_device *dev = container_of(ref, struct drm_device, ref); 788 + 789 + /* Just in case register/unregister was never called */ 790 + drm_debugfs_dev_fini(dev); 792 791 793 792 if (dev->driver->release) 794 793 dev->driver->release(dev); ··· 923 916 if (drm_dev_needs_global_mutex(dev)) 924 917 mutex_lock(&drm_global_mutex); 925 918 919 + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) 920 + accel_debugfs_register(dev); 921 + else 922 + drm_debugfs_dev_register(dev); 923 + 926 924 ret = drm_minor_register(dev, DRM_MINOR_RENDER); 927 925 if (ret) 928 926 goto err_minors; ··· 1013 1001 drm_minor_unregister(dev, DRM_MINOR_ACCEL); 1014 1002 drm_minor_unregister(dev, DRM_MINOR_PRIMARY); 1015 1003 drm_minor_unregister(dev, DRM_MINOR_RENDER); 1004 + drm_debugfs_dev_fini(dev); 1016 1005 } 1017 1006 EXPORT_SYMBOL(drm_dev_unregister); 1018 1007
+2 -2
drivers/gpu/drm/drm_framebuffer.c
··· 1222 1222 { "framebuffer", drm_framebuffer_info, 0 }, 1223 1223 }; 1224 1224 1225 - void drm_framebuffer_debugfs_init(struct drm_minor *minor) 1225 + void drm_framebuffer_debugfs_init(struct drm_device *dev) 1226 1226 { 1227 - drm_debugfs_add_files(minor->dev, drm_framebuffer_debugfs_list, 1227 + drm_debugfs_add_files(dev, drm_framebuffer_debugfs_list, 1228 1228 ARRAY_SIZE(drm_framebuffer_debugfs_list)); 1229 1229 } 1230 1230 #endif
+15 -5
drivers/gpu/drm/drm_internal.h
··· 180 180 181 181 /* drm_debugfs.c drm_debugfs_crc.c */ 182 182 #if defined(CONFIG_DEBUG_FS) 183 - int drm_debugfs_init(struct drm_minor *minor, int minor_id, 184 - struct dentry *root); 183 + void drm_debugfs_dev_fini(struct drm_device *dev); 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 187 void drm_debugfs_cleanup(struct drm_minor *minor); 186 188 void drm_debugfs_late_register(struct drm_device *dev); 187 189 void drm_debugfs_connector_add(struct drm_connector *connector); ··· 192 190 void drm_debugfs_crtc_remove(struct drm_crtc *crtc); 193 191 void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc); 194 192 #else 195 - static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id, 196 - struct dentry *root) 193 + static inline void drm_debugfs_dev_fini(struct drm_device *dev) 194 + { 195 + } 196 + 197 + static inline void drm_debugfs_dev_register(struct drm_device *dev) 198 + { 199 + } 200 + 201 + static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id, 202 + struct dentry *root) 197 203 { 198 204 return 0; 199 205 } ··· 269 259 /* drm_framebuffer.c */ 270 260 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent, 271 261 const struct drm_framebuffer *fb); 272 - void drm_framebuffer_debugfs_init(struct drm_minor *minor); 262 + void drm_framebuffer_debugfs_init(struct drm_device *dev);
+7 -2
include/drm/drm_accel.h
··· 58 58 void accel_minor_replace(struct drm_minor *minor, int index); 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_minor *minor, int minor_id); 61 + void accel_debugfs_init(struct drm_device *dev); 62 + void accel_debugfs_register(struct drm_device *dev); 62 63 63 64 #else 64 65 ··· 90 89 { 91 90 } 92 91 93 - static inline void accel_debugfs_init(struct drm_minor *minor, int minor_id) 92 + static inline void accel_debugfs_init(struct drm_device *dev) 93 + { 94 + } 95 + 96 + static inline void accel_debugfs_register(struct drm_device *dev) 94 97 { 95 98 } 96 99
+1 -1
include/drm/drm_bridge.h
··· 950 950 } 951 951 #endif 952 952 953 - void drm_bridge_debugfs_init(struct drm_minor *minor); 953 + void drm_bridge_debugfs_init(struct drm_device *dev); 954 954 955 955 #endif
+1 -1
include/drm/drm_client.h
··· 195 195 drm_for_each_connector_iter(connector, iter) \ 196 196 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 197 197 198 - void drm_client_debugfs_init(struct drm_minor *minor); 198 + void drm_client_debugfs_init(struct drm_device *dev); 199 199 200 200 #endif
+7
include/drm/drm_device.h
··· 312 312 struct drm_fb_helper *fb_helper; 313 313 314 314 /** 315 + * @debugfs_root: 316 + * 317 + * Root directory for debugfs files. 318 + */ 319 + struct dentry *debugfs_root; 320 + 321 + /** 315 322 * @debugfs_mutex: 316 323 * 317 324 * Protects &debugfs_list access.
+8
include/drm/drm_drv.h
··· 581 581 return video_firmware_drivers_only(); 582 582 } 583 583 584 + #if defined(CONFIG_DEBUG_FS) 585 + void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root); 586 + #else 587 + static void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root) 588 + { 589 + } 590 + #endif 591 + 584 592 #endif
+1
include/drm/drm_file.h
··· 79 79 struct device *kdev; /* Linux device */ 80 80 struct drm_device *dev; 81 81 82 + struct dentry *debugfs_symlink; 82 83 struct dentry *debugfs_root; 83 84 84 85 struct list_head debugfs_list;