diff mbox series

[2/5] drm/debugfs: rework debugfs directory creation v3

Message ID 20230412145206.2483-3-christian.koenig@amd.com (mailing list archive)
State New, archived
Headers show
Series [1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 | expand

Commit Message

Christian König April 12, 2023, 2:52 p.m. UTC
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

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/accel/drm_accel.c           | 27 ++++++++-----
 drivers/gpu/drm/drm_atomic.c        |  4 +-
 drivers/gpu/drm/drm_client.c        |  4 +-
 drivers/gpu/drm/drm_crtc_internal.h |  2 +-
 drivers/gpu/drm/drm_debugfs.c       | 60 ++++++++++++++++++-----------
 drivers/gpu/drm/drm_drv.c           | 18 +++++++--
 drivers/gpu/drm/drm_framebuffer.c   |  4 +-
 drivers/gpu/drm/drm_internal.h      | 16 +++++---
 include/drm/drm_accel.h             |  9 ++++-
 include/drm/drm_client.h            |  2 +-
 include/drm/drm_device.h            |  7 ++++
 include/drm/drm_drv.h               |  8 ++++
 include/drm/drm_file.h              |  1 +
 13 files changed, 110 insertions(+), 52 deletions(-)

Comments

kernel test robot April 13, 2023, 11:29 a.m. UTC | #1
Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on drm-intel/for-linux-next drm-intel/for-linux-next-fixes tegra/for-next linus/master v6.3-rc6 next-20230412]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-K-nig/drm-debugfs-rework-debugfs-directory-creation-v3/20230412-235231
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230412145206.2483-3-christian.koenig%40amd.com
patch subject: [PATCH 2/5] drm/debugfs: rework debugfs directory creation v3
config: arc-randconfig-r043-20230413 (https://download.01.org/0day-ci/archive/20230413/202304131935.9BjNzso4-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/92a7a4f0fd59d427c5827c323692b76095f90efc
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Christian-K-nig/drm-debugfs-rework-debugfs-directory-creation-v3/20230412-235231
        git checkout 92a7a4f0fd59d427c5827c323692b76095f90efc
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash drivers/gpu/drm/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304131935.9BjNzso4-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/gpu/drm/drm_drv.c: In function 'drm_dev_unregister':
>> drivers/gpu/drm/drm_drv.c:1011:9: error: implicit declaration of function 'drm_debugfs_dev_fini'; did you mean 'drm_debugfs_dev_init'? [-Werror=implicit-function-declaration]
    1011 |         drm_debugfs_dev_fini(dev);
         |         ^~~~~~~~~~~~~~~~~~~~
         |         drm_debugfs_dev_init
   cc1: some warnings being treated as errors


vim +1011 drivers/gpu/drm/drm_drv.c

   974	
   975	/**
   976	 * drm_dev_unregister - Unregister DRM device
   977	 * @dev: Device to unregister
   978	 *
   979	 * Unregister the DRM device from the system. This does the reverse of
   980	 * drm_dev_register() but does not deallocate the device. The caller must call
   981	 * drm_dev_put() to drop their final reference.
   982	 *
   983	 * A special form of unregistering for hotpluggable devices is drm_dev_unplug(),
   984	 * which can be called while there are still open users of @dev.
   985	 *
   986	 * This should be called first in the device teardown code to make sure
   987	 * userspace can't access the device instance any more.
   988	 */
   989	void drm_dev_unregister(struct drm_device *dev)
   990	{
   991		if (drm_core_check_feature(dev, DRIVER_LEGACY))
   992			drm_lastclose(dev);
   993	
   994		dev->registered = false;
   995	
   996		drm_client_dev_unregister(dev);
   997	
   998		if (drm_core_check_feature(dev, DRIVER_MODESET))
   999			drm_modeset_unregister_all(dev);
  1000	
  1001		if (dev->driver->unload)
  1002			dev->driver->unload(dev);
  1003	
  1004		drm_legacy_pci_agp_destroy(dev);
  1005		drm_legacy_rmmaps(dev);
  1006	
  1007		remove_compat_control_link(dev);
  1008		drm_minor_unregister(dev, DRM_MINOR_ACCEL);
  1009		drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
  1010		drm_minor_unregister(dev, DRM_MINOR_RENDER);
> 1011		drm_debugfs_dev_fini(dev);
  1012	}
  1013	EXPORT_SYMBOL(drm_dev_unregister);
  1014
kernel test robot April 13, 2023, 3:39 p.m. UTC | #2
Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on drm-intel/for-linux-next drm-intel/for-linux-next-fixes tegra/for-next linus/master v6.3-rc6 next-20230412]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-K-nig/drm-debugfs-rework-debugfs-directory-creation-v3/20230412-235231
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230412145206.2483-3-christian.koenig%40amd.com
patch subject: [PATCH 2/5] drm/debugfs: rework debugfs directory creation v3
config: hexagon-randconfig-r002-20230409 (https://download.01.org/0day-ci/archive/20230413/202304132344.9oz5dfJI-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 9638da200e00bd069e6dd63604e14cbafede9324)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/92a7a4f0fd59d427c5827c323692b76095f90efc
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Christian-K-nig/drm-debugfs-rework-debugfs-directory-creation-v3/20230412-235231
        git checkout 92a7a4f0fd59d427c5827c323692b76095f90efc
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/gpu/drm/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304132344.9oz5dfJI-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/gpu/drm/drm_drv.c:38:
   In file included from include/drm/drm_accel.h:11:
   In file included from include/drm/drm_file.h:39:
   In file included from include/drm/drm_prime.h:37:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
                                                     ^
   In file included from drivers/gpu/drm/drm_drv.c:38:
   In file included from include/drm/drm_accel.h:11:
   In file included from include/drm/drm_file.h:39:
   In file included from include/drm/drm_prime.h:37:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
                                                     ^
   In file included from drivers/gpu/drm/drm_drv.c:38:
   In file included from include/drm/drm_accel.h:11:
   In file included from include/drm/drm_file.h:39:
   In file included from include/drm/drm_prime.h:37:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
>> drivers/gpu/drm/drm_drv.c:1011:2: error: call to undeclared function 'drm_debugfs_dev_fini'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
           drm_debugfs_dev_fini(dev);
           ^
   drivers/gpu/drm/drm_drv.c:1011:2: note: did you mean 'drm_debugfs_dev_init'?
   include/drm/drm_drv.h:596:13: note: 'drm_debugfs_dev_init' declared here
   static void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
               ^
   6 warnings and 1 error generated.


vim +/drm_debugfs_dev_fini +1011 drivers/gpu/drm/drm_drv.c

   974	
   975	/**
   976	 * drm_dev_unregister - Unregister DRM device
   977	 * @dev: Device to unregister
   978	 *
   979	 * Unregister the DRM device from the system. This does the reverse of
   980	 * drm_dev_register() but does not deallocate the device. The caller must call
   981	 * drm_dev_put() to drop their final reference.
   982	 *
   983	 * A special form of unregistering for hotpluggable devices is drm_dev_unplug(),
   984	 * which can be called while there are still open users of @dev.
   985	 *
   986	 * This should be called first in the device teardown code to make sure
   987	 * userspace can't access the device instance any more.
   988	 */
   989	void drm_dev_unregister(struct drm_device *dev)
   990	{
   991		if (drm_core_check_feature(dev, DRIVER_LEGACY))
   992			drm_lastclose(dev);
   993	
   994		dev->registered = false;
   995	
   996		drm_client_dev_unregister(dev);
   997	
   998		if (drm_core_check_feature(dev, DRIVER_MODESET))
   999			drm_modeset_unregister_all(dev);
  1000	
  1001		if (dev->driver->unload)
  1002			dev->driver->unload(dev);
  1003	
  1004		drm_legacy_pci_agp_destroy(dev);
  1005		drm_legacy_rmmaps(dev);
  1006	
  1007		remove_compat_control_link(dev);
  1008		drm_minor_unregister(dev, DRM_MINOR_ACCEL);
  1009		drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
  1010		drm_minor_unregister(dev, DRM_MINOR_RENDER);
> 1011		drm_debugfs_dev_fini(dev);
  1012	}
  1013	EXPORT_SYMBOL(drm_dev_unregister);
  1014
Tomer Tayar April 16, 2023, 4:03 p.m. UTC | #3
On 12/04/2023 17:52, Christian König wrote:
>   /**
> - * accel_debugfs_init() - Initialize debugfs for accel minor
> + * accel_debugfs_init() - Register debugfs for accel minor
> + * @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
>    * @minor: Pointer to the drm_minor instance.
>    * @minor_id: The minor's id
>    *
> - * This function initializes the drm minor's debugfs members and creates
> - * a root directory for the minor in debugfs. It also creates common files
> - * for accelerators and calls the driver's debugfs init callback.
> + * Creates common files for accelerators.
>    */
> -void accel_debugfs_init(struct drm_minor *minor, int minor_id)
> +void accel_debugfs_register(struct drm_device *dev)
>   {

Maybe the accel_debugfs_init() description should now be "Initialize 
debugfs for device"?
Christian König April 17, 2023, 7:18 a.m. UTC | #4
Am 16.04.23 um 18:03 schrieb Tomer Tayar:
> On 12/04/2023 17:52, Christian König wrote:
>>    /**
>> - * accel_debugfs_init() - Initialize debugfs for accel minor
>> + * accel_debugfs_init() - Register debugfs for accel minor
>> + * @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
>>     * @minor: Pointer to the drm_minor instance.
>>     * @minor_id: The minor's id
>>     *
>> - * This function initializes the drm minor's debugfs members and creates
>> - * a root directory for the minor in debugfs. It also creates common files
>> - * for accelerators and calls the driver's debugfs init callback.
>> + * Creates common files for accelerators.
>>     */
>> -void accel_debugfs_init(struct drm_minor *minor, int minor_id)
>> +void accel_debugfs_register(struct drm_device *dev)
>>    {
> Maybe the accel_debugfs_init() description should now be "Initialize
> debugfs for device"?

Good point, going to adjust that as well.

Thanks,
Christian.
Stanislaw Gruszka April 17, 2023, 10:26 a.m. UTC | #5
On Mon, Apr 17, 2023 at 09:18:31AM +0200, Christian König wrote:
> 
> 
> Am 16.04.23 um 18:03 schrieb Tomer Tayar:
> > On 12/04/2023 17:52, Christian König wrote:
> > >    /**
> > > - * accel_debugfs_init() - Initialize debugfs for accel minor
> > > + * accel_debugfs_init() - Register debugfs for accel minor
> > > + * @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
> > >     * @minor: Pointer to the drm_minor instance.
> > >     * @minor_id: The minor's id
> > >     *
> > > - * This function initializes the drm minor's debugfs members and creates
> > > - * a root directory for the minor in debugfs. It also creates common files
> > > - * for accelerators and calls the driver's debugfs init callback.
> > > + * Creates common files for accelerators.
> > >     */
> > > -void accel_debugfs_init(struct drm_minor *minor, int minor_id)
> > > +void accel_debugfs_register(struct drm_device *dev)
> > >    {
I wonder if we need this and can not use drm_debugfs_dev_register() ?
In drm there are two additional files "clients" and "gem_names" which are
appropriate to accel as well and so far we do not have any accel
specific files.

Regards
Stanislaw
Christian König April 24, 2023, 12:17 p.m. UTC | #6
Am 17.04.23 um 12:26 schrieb Stanislaw Gruszka:
> On Mon, Apr 17, 2023 at 09:18:31AM +0200, Christian König wrote:
>>
>> Am 16.04.23 um 18:03 schrieb Tomer Tayar:
>>> On 12/04/2023 17:52, Christian König wrote:
>>>>     /**
>>>> - * accel_debugfs_init() - Initialize debugfs for accel minor
>>>> + * accel_debugfs_init() - Register debugfs for accel minor
>>>> + * @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
>>>>      * @minor: Pointer to the drm_minor instance.
>>>>      * @minor_id: The minor's id
>>>>      *
>>>> - * This function initializes the drm minor's debugfs members and creates
>>>> - * a root directory for the minor in debugfs. It also creates common files
>>>> - * for accelerators and calls the driver's debugfs init callback.
>>>> + * Creates common files for accelerators.
>>>>      */
>>>> -void accel_debugfs_init(struct drm_minor *minor, int minor_id)
>>>> +void accel_debugfs_register(struct drm_device *dev)
>>>>     {
> I wonder if we need this and can not use drm_debugfs_dev_register() ?
> In drm there are two additional files "clients" and "gem_names" which are
> appropriate to accel as well and so far we do not have any accel
> specific files.

I was wondering the same thing while going over this, but then decided 
to leave it as it is for now.

My primary concern is to remove the mid layering with the driver 
callback because that is blocking functionality from working correctly, 
cleanup and re-joining of functionality can then come later on.

Regards,
Christian.

>
> Regards
> Stanislaw
diff mbox series

Patch

diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c
index d473388ee807..e28fb64cbd5e 100644
--- a/drivers/accel/drm_accel.c
+++ b/drivers/accel/drm_accel.c
@@ -79,26 +79,33 @@  static const struct drm_info_list accel_debugfs_list[] = {
 #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list)
 
 /**
- * accel_debugfs_init() - Initialize debugfs for accel minor
+ * accel_debugfs_init() - Register debugfs for accel minor
+ * @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
  * @minor: Pointer to the drm_minor instance.
  * @minor_id: The minor's id
  *
- * This function initializes the drm minor's debugfs members and creates
- * a root directory for the minor in debugfs. It also creates common files
- * for accelerators and calls the driver's debugfs init callback.
+ * Creates common files for accelerators.
  */
-void accel_debugfs_init(struct drm_minor *minor, int minor_id)
+void accel_debugfs_register(struct drm_device *dev)
 {
-	struct drm_device *dev = minor->dev;
-	char name[64];
+	struct drm_minor *minor = dev->accel;
 
 	INIT_LIST_HEAD(&minor->debugfs_list);
 	mutex_init(&minor->debugfs_lock);
-	sprintf(name, "%d", minor_id);
-	minor->debugfs_root = debugfs_create_dir(name, accel_debugfs_root);
+	minor->debugfs_root = dev->debugfs_root;
 
 	drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES,
-				 minor->debugfs_root, minor);
+				 dev->debugfs_root, minor);
 }
 
 /**
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index fed41800fea7..1cc11b948f64 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1771,9 +1771,9 @@  static const struct drm_debugfs_info drm_atomic_debugfs_list[] = {
 	{"state", drm_state_info, 0},
 };
 
-void drm_atomic_debugfs_init(struct drm_minor *minor)
+void drm_atomic_debugfs_init(struct drm_device *dev)
 {
-	drm_debugfs_add_files(minor->dev, drm_atomic_debugfs_list,
+	drm_debugfs_add_files(dev, drm_atomic_debugfs_list,
 			      ARRAY_SIZE(drm_atomic_debugfs_list));
 }
 #endif
diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
index f6292ba0e6fc..a91132276f21 100644
--- a/drivers/gpu/drm/drm_client.c
+++ b/drivers/gpu/drm/drm_client.c
@@ -514,9 +514,9 @@  static const struct drm_debugfs_info drm_client_debugfs_list[] = {
 	{ "internal_clients", drm_client_debugfs_internal_clients, 0 },
 };
 
-void drm_client_debugfs_init(struct drm_minor *minor)
+void drm_client_debugfs_init(struct drm_device *dev)
 {
-	drm_debugfs_add_files(minor->dev, drm_client_debugfs_list,
+	drm_debugfs_add_files(dev, drm_client_debugfs_list,
 			      ARRAY_SIZE(drm_client_debugfs_list));
 }
 #endif
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index 501a10edd0e1..8556c3b3ff88 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -232,7 +232,7 @@  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
 /* drm_atomic.c */
 #ifdef CONFIG_DEBUG_FS
 struct drm_minor;
-void drm_atomic_debugfs_init(struct drm_minor *minor);
+void drm_atomic_debugfs_init(struct drm_device *dev);
 #endif
 
 int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 54376e2400bb..59c3d76d28f4 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -218,8 +218,31 @@  void drm_debugfs_create_files(const struct drm_info_list *files, int count,
 }
 EXPORT_SYMBOL(drm_debugfs_create_files);
 
-int drm_debugfs_init(struct drm_minor *minor, int minor_id,
-		     struct dentry *root)
+void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+{
+	dev->debugfs_root = debugfs_create_dir(dev->unique, root);
+}
+
+void drm_debugfs_dev_fini(struct drm_device *dev)
+{
+	debugfs_remove_recursive(dev->debugfs_root);
+	dev->debugfs_root = NULL;
+}
+
+void drm_debugfs_dev_register(struct drm_device *dev)
+{
+	drm_debugfs_add_files(dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES);
+
+	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		drm_framebuffer_debugfs_init(dev);
+		drm_client_debugfs_init(dev);
+	}
+	if (drm_drv_uses_atomic_modeset(dev))
+		drm_atomic_debugfs_init(dev);
+}
+
+int drm_debugfs_register(struct drm_minor *minor, int minor_id,
+			 struct dentry *root)
 {
 	struct drm_device *dev = minor->dev;
 	struct drm_debugfs_entry *entry, *tmp;
@@ -228,19 +251,11 @@  int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 	INIT_LIST_HEAD(&minor->debugfs_list);
 	mutex_init(&minor->debugfs_lock);
 	sprintf(name, "%d", minor_id);
-	minor->debugfs_root = debugfs_create_dir(name, root);
+	minor->debugfs_symlink = debugfs_create_symlink(name, root,
+							dev->unique);
 
-	drm_debugfs_add_files(minor->dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES);
-
-	if (drm_drv_uses_atomic_modeset(dev)) {
-		drm_atomic_debugfs_init(minor);
-	}
-
-	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
-		drm_framebuffer_debugfs_init(minor);
-
-		drm_client_debugfs_init(minor);
-	}
+	/* TODO: Only for compatibility with drivers */
+	minor->debugfs_root = dev->debugfs_root;
 
 	if (dev->driver->debugfs_init && dev->render != minor)
 		dev->driver->debugfs_init(minor);
@@ -307,13 +322,12 @@  static void drm_debugfs_remove_all_files(struct drm_minor *minor)
 
 void drm_debugfs_cleanup(struct drm_minor *minor)
 {
-	if (!minor->debugfs_root)
+	if (!minor->debugfs_symlink)
 		return;
 
 	drm_debugfs_remove_all_files(minor);
-
-	debugfs_remove_recursive(minor->debugfs_root);
-	minor->debugfs_root = NULL;
+	debugfs_remove(minor->debugfs_symlink);
+	minor->debugfs_symlink = NULL;
 }
 
 /**
@@ -498,13 +512,13 @@  static const struct file_operations drm_connector_fops = {
 
 void drm_debugfs_connector_add(struct drm_connector *connector)
 {
-	struct drm_minor *minor = connector->dev->primary;
+	struct drm_device *dev = connector->dev;
 	struct dentry *root;
 
-	if (!minor->debugfs_root)
+	if (!dev->debugfs_root)
 		return;
 
-	root = debugfs_create_dir(connector->name, minor->debugfs_root);
+	root = debugfs_create_dir(connector->name, dev->debugfs_root);
 	connector->debugfs_entry = root;
 
 	/* force */
@@ -539,7 +553,7 @@  void drm_debugfs_connector_remove(struct drm_connector *connector)
 
 void drm_debugfs_crtc_add(struct drm_crtc *crtc)
 {
-	struct drm_minor *minor = crtc->dev->primary;
+	struct drm_device *dev = crtc->dev;
 	struct dentry *root;
 	char *name;
 
@@ -547,7 +561,7 @@  void drm_debugfs_crtc_add(struct drm_crtc *crtc)
 	if (!name)
 		return;
 
-	root = debugfs_create_dir(name, minor->debugfs_root);
+	root = debugfs_create_dir(name, dev->debugfs_root);
 	kfree(name);
 
 	crtc->debugfs_entry = root;
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index cee0cc522ed9..05b831f9fe71 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -172,10 +172,9 @@  static int drm_minor_register(struct drm_device *dev, unsigned int type)
 	if (!minor)
 		return 0;
 
-	if (minor->type == DRM_MINOR_ACCEL) {
-		accel_debugfs_init(minor, minor->index);
-	} else {
-		ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root);
+	if (minor->type != DRM_MINOR_ACCEL) {
+		ret = drm_debugfs_register(minor, minor->index,
+					   drm_debugfs_root);
 		if (ret) {
 			DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
 			goto err_debugfs;
@@ -697,6 +696,11 @@  static int drm_dev_init(struct drm_device *dev,
 		goto err;
 	}
 
+	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
+		accel_debugfs_init(dev);
+	else
+		drm_debugfs_dev_init(dev, drm_debugfs_root);
+
 	return 0;
 
 err:
@@ -916,6 +920,11 @@  int drm_dev_register(struct drm_device *dev, unsigned long flags)
 	if (drm_dev_needs_global_mutex(dev))
 		mutex_lock(&drm_global_mutex);
 
+	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
+		accel_debugfs_register(dev);
+	else
+		drm_debugfs_dev_register(dev);
+
 	ret = drm_minor_register(dev, DRM_MINOR_RENDER);
 	if (ret)
 		goto err_minors;
@@ -999,6 +1008,7 @@  void drm_dev_unregister(struct drm_device *dev)
 	drm_minor_unregister(dev, DRM_MINOR_ACCEL);
 	drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
 	drm_minor_unregister(dev, DRM_MINOR_RENDER);
+	drm_debugfs_dev_fini(dev);
 }
 EXPORT_SYMBOL(drm_dev_unregister);
 
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index aff3746dedfb..ba51deb6d042 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -1222,9 +1222,9 @@  static const struct drm_debugfs_info drm_framebuffer_debugfs_list[] = {
 	{ "framebuffer", drm_framebuffer_info, 0 },
 };
 
-void drm_framebuffer_debugfs_init(struct drm_minor *minor)
+void drm_framebuffer_debugfs_init(struct drm_device *dev)
 {
-	drm_debugfs_add_files(minor->dev, drm_framebuffer_debugfs_list,
+	drm_debugfs_add_files(dev, drm_framebuffer_debugfs_list,
 			      ARRAY_SIZE(drm_framebuffer_debugfs_list));
 }
 #endif
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index d7e023bbb0d5..5c6e1cadf09b 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -180,8 +180,10 @@  void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
 
 /* drm_debugfs.c drm_debugfs_crc.c */
 #if defined(CONFIG_DEBUG_FS)
-int drm_debugfs_init(struct drm_minor *minor, int minor_id,
-		     struct dentry *root);
+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);
 void drm_debugfs_cleanup(struct drm_minor *minor);
 void drm_debugfs_late_register(struct drm_device *dev);
 void drm_debugfs_connector_add(struct drm_connector *connector);
@@ -190,8 +192,12 @@  void drm_debugfs_crtc_add(struct drm_crtc *crtc);
 void drm_debugfs_crtc_remove(struct drm_crtc *crtc);
 void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc);
 #else
-static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
-				   struct dentry *root)
+static inline void drm_debugfs_dev_register(struct drm_device *dev)
+{
+}
+
+static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id,
+				       struct dentry *root)
 {
 	return 0;
 }
@@ -257,4 +263,4 @@  int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
 /* drm_framebuffer.c */
 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
 				const struct drm_framebuffer *fb);
-void drm_framebuffer_debugfs_init(struct drm_minor *minor);
+void drm_framebuffer_debugfs_init(struct drm_device *dev);
diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h
index d4955062c77e..f4d3784b1dce 100644
--- a/include/drm/drm_accel.h
+++ b/include/drm/drm_accel.h
@@ -58,7 +58,8 @@  int accel_minor_alloc(void);
 void accel_minor_replace(struct drm_minor *minor, int index);
 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_minor *minor, int minor_id);
+void accel_debugfs_init(struct drm_device *dev);
+void accel_debugfs_register(struct drm_device *dev);
 
 #else
 
@@ -89,7 +90,11 @@  static inline void accel_set_device_instance_params(struct device *kdev, int ind
 {
 }
 
-static inline void accel_debugfs_init(struct drm_minor *minor, int minor_id)
+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_client.h b/include/drm/drm_client.h
index c0a14b40c039..d47458ecdac4 100644
--- a/include/drm/drm_client.h
+++ b/include/drm/drm_client.h
@@ -195,6 +195,6 @@  int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
 	drm_for_each_connector_iter(connector, iter) \
 		if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
 
-void drm_client_debugfs_init(struct drm_minor *minor);
+void drm_client_debugfs_init(struct drm_device *dev);
 
 #endif
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index 7cf4afae2e79..3cf12b14232d 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -311,6 +311,13 @@  struct drm_device {
 	 */
 	struct drm_fb_helper *fb_helper;
 
+	/**
+	 * @debugfs_root:
+	 *
+	 * Root directory for debugfs files.
+	 */
+	struct dentry *debugfs_root;
+
 	/**
 	 * @debugfs_mutex:
 	 *
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index b419c59c4bef..14d5337f4297 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -590,4 +590,12 @@  static inline bool drm_firmware_drivers_only(void)
 	return video_firmware_drivers_only();
 }
 
+#if defined(CONFIG_DEBUG_FS)
+void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root);
+#else
+static void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+{
+}
+#endif
+
 #endif
diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index ecffe24e2b1b..1fe08fcaa149 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -78,6 +78,7 @@  struct drm_minor {
 	struct device *kdev;		/* Linux device */
 	struct drm_device *dev;
 
+	struct dentry *debugfs_symlink;
 	struct dentry *debugfs_root;
 
 	struct list_head debugfs_list;