All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/amd/display: do not use drm middle layer for debugfs
@ 2021-02-15 10:16 Nirmoy Das
  2021-02-15 10:16 ` [PATCH 2/3] drm/amd/pm: " Nirmoy Das
  2021-02-15 10:16 ` [PATCH 3/3] drm/amdgpu: " Nirmoy Das
  0 siblings, 2 replies; 6+ messages in thread
From: Nirmoy Das @ 2021-02-15 10:16 UTC (permalink / raw)
  To: Christian.Koenig; +Cc: Nirmoy Das, amd-gfx

Use debugfs API directly instead of drm middle layer.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   |  6 +--
 .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 46 ++++++++-----------
 .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.h |  2 +-
 3 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 55db646d0ba4..60b2f2d4ca80 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -1642,10 +1642,8 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
 		DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
 
 #if defined(CONFIG_DRM_AMD_DC)
-	if (amdgpu_device_has_dc_support(adev)) {
-		if (dtn_debugfs_init(adev))
-			DRM_ERROR("amdgpu: failed initialize dtn debugfs support.\n");
-	}
+	if (amdgpu_device_has_dc_support(adev))
+		dtn_debugfs_init(adev);
 #endif
 
 	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
index 360952129b6d..9a5f119a834f 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
@@ -25,8 +25,6 @@
 
 #include <linux/uaccess.h>
 
-#include <drm/drm_debugfs.h>
-
 #include "dc.h"
 #include "amdgpu.h"
 #include "amdgpu_dm.h"
@@ -2450,11 +2448,9 @@ static ssize_t dtn_log_write(
  * As written to display, taking ABM and backlight lut into account.
  * Ranges from 0x0 to 0x10000 (= 100% PWM)
  */
-static int current_backlight_read(struct seq_file *m, void *data)
+static int current_backlight_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
 	struct amdgpu_display_manager *dm = &adev->dm;
 
 	unsigned int backlight = dc_link_get_backlight_level(dm->backlight_link);
@@ -2468,11 +2464,9 @@ static int current_backlight_read(struct seq_file *m, void *data)
  * As written to display, taking ABM and backlight lut into account.
  * Ranges from 0x0 to 0x10000 (= 100% PWM)
  */
-static int target_backlight_read(struct seq_file *m, void *data)
+static int target_backlight_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
 	struct amdgpu_display_manager *dm = &adev->dm;
 
 	unsigned int backlight = dc_link_get_target_backlight_pwm(dm->backlight_link);
@@ -2481,10 +2475,10 @@ static int target_backlight_read(struct seq_file *m, void *data)
 	return 0;
 }
 
-static int mst_topo(struct seq_file *m, void *unused)
+static int mst_topo_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct drm_device *dev = adev_to_drm(adev);
 	struct drm_connector *connector;
 	struct drm_connector_list_iter conn_iter;
 	struct amdgpu_dm_connector *aconnector;
@@ -2504,12 +2498,6 @@ static int mst_topo(struct seq_file *m, void *unused)
 	return 0;
 }
 
-static const struct drm_info_list amdgpu_dm_debugfs_list[] = {
-	{"amdgpu_current_backlight_pwm", &current_backlight_read},
-	{"amdgpu_target_backlight_pwm", &target_backlight_read},
-	{"amdgpu_mst_topology", &mst_topo},
-};
-
 /*
  * Sets the force_timing_sync debug optino from the given string.
  * All connected displays will be force synchronized immediately.
@@ -2568,10 +2556,13 @@ static int visual_confirm_get(void *data, u64 *val)
 	return 0;
 }
 
+DEFINE_SHOW_ATTRIBUTE(current_backlight);
+DEFINE_SHOW_ATTRIBUTE(target_backlight);
+DEFINE_SHOW_ATTRIBUTE(mst_topo);
 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
 			 visual_confirm_set, "%llu\n");
 
-int dtn_debugfs_init(struct amdgpu_device *adev)
+void dtn_debugfs_init(struct amdgpu_device *adev)
 {
 	static const struct file_operations dtn_log_fops = {
 		.owner = THIS_MODULE,
@@ -2581,14 +2572,15 @@ int dtn_debugfs_init(struct amdgpu_device *adev)
 	};
 
 	struct drm_minor *minor = adev_to_drm(adev)->primary;
+	umode_t mode = S_IFREG | S_IRUGO;
 	struct dentry *root = minor->debugfs_root;
-	int ret;
-
-	ret = amdgpu_debugfs_add_files(adev, amdgpu_dm_debugfs_list,
-				ARRAY_SIZE(amdgpu_dm_debugfs_list));
-	if (ret)
-		return ret;
 
+	debugfs_create_file("amdgpu_current_backlight_pwm", mode, root, adev,
+			    &current_backlight_fops);
+	debugfs_create_file("amdgpu_target_backlight_pwm", mode, root, adev,
+			    &target_backlight_fops);
+	debugfs_create_file("amdgpu_mst_topology", mode, root, adev,
+			    &mst_topo_fops);
 	debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
 			    &dtn_log_fops);
 
@@ -2603,6 +2595,4 @@ int dtn_debugfs_init(struct amdgpu_device *adev)
 
 	debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
 				   adev, &force_timing_sync_ops);
-
-	return 0;
 }
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.h
index 5e5b2b2afa31..32f85c2b608f 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.h
@@ -30,6 +30,6 @@
 #include "amdgpu_dm.h"
 
 void connector_debugfs_init(struct amdgpu_dm_connector *connector);
-int dtn_debugfs_init(struct amdgpu_device *adev);
+void dtn_debugfs_init(struct amdgpu_device *adev);
 
 #endif
-- 
2.30.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] drm/amd/pm: do not use drm middle layer for debugfs
  2021-02-15 10:16 [PATCH 1/3] drm/amd/display: do not use drm middle layer for debugfs Nirmoy Das
@ 2021-02-15 10:16 ` Nirmoy Das
  2021-02-15 10:16 ` [PATCH 3/3] drm/amdgpu: " Nirmoy Das
  1 sibling, 0 replies; 6+ messages in thread
From: Nirmoy Das @ 2021-02-15 10:16 UTC (permalink / raw)
  To: Christian.Koenig; +Cc: Nirmoy Das, amd-gfx

Use debugfs API directly instead of drm middle layer.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |  6 +----
 drivers/gpu/drm/amd/pm/amdgpu_pm.c          | 26 ++++++++++-----------
 drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h      |  2 +-
 3 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 60b2f2d4ca80..719ae65ad633 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -1616,11 +1616,7 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
 		return r;
 	}
 
-	r = amdgpu_debugfs_pm_init(adev);
-	if (r) {
-		DRM_ERROR("Failed to register debugfs file for dpm!\n");
-		return r;
-	}
+	amdgpu_debugfs_pm_init(adev);
 
 	if (amdgpu_debugfs_sa_init(adev)) {
 		dev_err(adev->dev, "failed to register debugfs file for SA\n");
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index 5fa65f191a37..ded66f55cfdb 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
@@ -23,8 +23,6 @@
  *          Alex Deucher <alexdeucher@gmail.com>
  */
 
-#include <drm/drm_debugfs.h>
-
 #include "amdgpu.h"
 #include "amdgpu_drv.h"
 #include "amdgpu_pm.h"
@@ -3784,11 +3782,10 @@ static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
 			   (flags & clocks[i].flag) ? "On" : "Off");
 }
 
-static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
+static int amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *) m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct drm_device *dev = adev_to_drm(adev);
 	u32 flags = 0;
 	int r;
 
@@ -3836,16 +3833,19 @@ static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
 	return r;
 }
 
-static const struct drm_info_list amdgpu_pm_info_list[] = {
-	{"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
-};
+DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_pm_info);
+
 #endif
 
-int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
+void amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));
-#else
-	return 0;
+	struct drm_minor *minor = adev_to_drm(adev)->primary;
+	umode_t mode = S_IFREG | S_IRUGO;
+	struct dentry *root = minor->debugfs_root;
+
+	debugfs_create_file("amdgpu_pm_info", mode, root, adev,
+			    &amdgpu_debugfs_pm_info_fops);
+
 #endif
 }
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h
index 45a22e101d15..a920515e2274 100644
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h
@@ -84,6 +84,6 @@ int amdgpu_pm_virt_sysfs_init(struct amdgpu_device *adev);
 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev);
 void amdgpu_pm_virt_sysfs_fini(struct amdgpu_device *adev);
 
-int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
 
 #endif
-- 
2.30.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] drm/amdgpu: do not use drm middle layer for debugfs
  2021-02-15 10:16 [PATCH 1/3] drm/amd/display: do not use drm middle layer for debugfs Nirmoy Das
  2021-02-15 10:16 ` [PATCH 2/3] drm/amd/pm: " Nirmoy Das
@ 2021-02-15 10:16 ` Nirmoy Das
  2021-02-15 10:43   ` Christian König
  1 sibling, 1 reply; 6+ messages in thread
From: Nirmoy Das @ 2021-02-15 10:16 UTC (permalink / raw)
  To: Christian.Koenig; +Cc: Nirmoy Das, amd-gfx

Use debugfs API directly instead of drm middle layer.

This also includes following debugfs file output changes:
1 amdgpu_evict_vram/amdgpu_evict_gtt output will not contain any braces.
  e.g. (0) --> 0
2 amdgpu_gpu_recover output will print return value of
  amdgpu_device_gpu_recover() instead of not so important "gpu recover"
  message.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 157 +++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h |   6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c   |  47 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     |  23 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c      |  24 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     |  25 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h  |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c     | 127 ++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h     |   2 +-
 9 files changed, 209 insertions(+), 204 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 719ae65ad633..827a4fd15f85 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -28,7 +28,6 @@
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
 #include <linux/poll.h>
-#include <drm/drm_debugfs.h>
 
 #include "amdgpu.h"
 #include "amdgpu_pm.h"
@@ -38,45 +37,6 @@
 #include "amdgpu_securedisplay.h"
 #include "amdgpu_fw_attestation.h"
 
-/**
- * amdgpu_debugfs_add_files - Add simple debugfs entries
- *
- * @adev:  Device to attach debugfs entries to
- * @files:  Array of function callbacks that respond to reads
- * @nfiles: Number of callbacks to register
- *
- */
-int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
-			     const struct drm_info_list *files,
-			     unsigned nfiles)
-{
-	unsigned i;
-
-	for (i = 0; i < adev->debugfs_count; i++) {
-		if (adev->debugfs[i].files == files) {
-			/* Already registered */
-			return 0;
-		}
-	}
-
-	i = adev->debugfs_count + 1;
-	if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
-		DRM_ERROR("Reached maximum number of debugfs components.\n");
-		DRM_ERROR("Report so we increase "
-			  "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
-		return -EINVAL;
-	}
-	adev->debugfs[adev->debugfs_count].files = files;
-	adev->debugfs[adev->debugfs_count].num_files = nfiles;
-	adev->debugfs_count = i;
-#if defined(CONFIG_DEBUG_FS)
-	drm_debugfs_create_files(files, nfiles,
-				 adev_to_drm(adev)->primary->debugfs_root,
-				 adev_to_drm(adev)->primary);
-#endif
-	return 0;
-}
-
 int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_DEBUG_FS)
@@ -1233,16 +1193,15 @@ int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
 	return 0;
 }
 
-static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
+static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *) m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct drm_device *dev = adev_to_drm(adev);
 	int r = 0, i;
 
 	r = pm_runtime_get_sync(dev->dev);
 	if (r < 0) {
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+		pm_runtime_put_autosuspend(dev->dev);
 		return r;
 	}
 
@@ -1284,30 +1243,19 @@ static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
 	return 0;
 }
 
-static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void *data)
-{
-	struct drm_info_node *node = (struct drm_info_node *) m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
-
-	seq_write(m, adev->bios, adev->bios_size);
-	return 0;
-}
-
-static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
+static int evict_vram_get(void *data, u64 *val)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)data;
+	struct drm_device *dev = adev_to_drm(adev);
 	int r;
 
 	r = pm_runtime_get_sync(dev->dev);
 	if (r < 0) {
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+		pm_runtime_put_autosuspend(dev->dev);
 		return r;
 	}
 
-	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
+	*val = amdgpu_bo_evict_vram(adev);
 
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
@@ -1315,11 +1263,11 @@ static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
 	return 0;
 }
 
-static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
+
+static int evict_gtt_get(void *data, u64 *val)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)data;
+	struct drm_device *dev = adev_to_drm(adev);
 	int r;
 
 	r = pm_runtime_get_sync(dev->dev);
@@ -1328,7 +1276,7 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
 		return r;
 	}
 
-	seq_printf(m, "(%d)\n", ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT));
+	*val = ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT);
 
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
@@ -1336,10 +1284,11 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
 	return 0;
 }
 
-static int amdgpu_debugfs_vm_info(struct seq_file *m, void *data)
+
+static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct drm_device *dev = adev_to_drm(adev);
 	struct drm_file *file;
 	int r;
 
@@ -1365,13 +1314,10 @@ static int amdgpu_debugfs_vm_info(struct seq_file *m, void *data)
 	return r;
 }
 
-static const struct drm_info_list amdgpu_debugfs_list[] = {
-	{"amdgpu_vbios", amdgpu_debugfs_get_vbios_dump},
-	{"amdgpu_test_ib", &amdgpu_debugfs_test_ib},
-	{"amdgpu_evict_vram", &amdgpu_debugfs_evict_vram},
-	{"amdgpu_evict_gtt", &amdgpu_debugfs_evict_gtt},
-	{"amdgpu_vm_info", &amdgpu_debugfs_vm_info},
-};
+DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_test_ib);
+DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_vm_info);
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_vram_fops, evict_vram_get, NULL, "%lld\n");
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_gtt_fops, evict_gtt_get, NULL, "%lld\n");
 
 static void amdgpu_ib_preempt_fences_swap(struct amdgpu_ring *ring,
 					  struct dma_fence **fences)
@@ -1592,17 +1538,19 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
 {
 	struct dentry *ent;
 	int r, i;
+	struct dentry *root = adev_to_drm(adev)->primary->debugfs_root;
+	struct debugfs_blob_wrapper *vbios;
+
+
 
-	ent = debugfs_create_file("amdgpu_preempt_ib", 0600,
-				  adev_to_drm(adev)->primary->debugfs_root, adev,
+	ent = debugfs_create_file("amdgpu_preempt_ib", 0600, root, adev,
 				  &fops_ib_preempt);
 	if (!ent) {
 		DRM_ERROR("unable to create amdgpu_preempt_ib debugsfs file\n");
 		return -EIO;
 	}
 
-	ent = debugfs_create_file("amdgpu_force_sclk", 0200,
-				  adev_to_drm(adev)->primary->debugfs_root, adev,
+	ent = debugfs_create_file("amdgpu_force_sclk", 0200, root, adev,
 				  &fops_sclk_set);
 	if (!ent) {
 		DRM_ERROR("unable to create amdgpu_set_sclk debugsfs file\n");
@@ -1610,32 +1558,17 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
 	}
 
 	/* Register debugfs entries for amdgpu_ttm */
-	r = amdgpu_ttm_debugfs_init(adev);
-	if (r) {
-		DRM_ERROR("Failed to init debugfs\n");
-		return r;
-	}
-
+	amdgpu_ttm_debugfs_init(adev);
 	amdgpu_debugfs_pm_init(adev);
-
-	if (amdgpu_debugfs_sa_init(adev)) {
-		dev_err(adev->dev, "failed to register debugfs file for SA\n");
-	}
-
-	if (amdgpu_debugfs_fence_init(adev))
-		dev_err(adev->dev, "fence debugfs file creation failed\n");
-
-	r = amdgpu_debugfs_gem_init(adev);
-	if (r)
-		DRM_ERROR("registering gem debugfs failed (%d).\n", r);
+	amdgpu_debugfs_sa_init(adev);
+	amdgpu_debugfs_fence_init(adev);
+	amdgpu_debugfs_gem_init(adev);
 
 	r = amdgpu_debugfs_regs_init(adev);
 	if (r)
 		DRM_ERROR("registering register debugfs failed (%d).\n", r);
 
-	r = amdgpu_debugfs_firmware_init(adev);
-	if (r)
-		DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
+	amdgpu_debugfs_firmware_init(adev);
 
 #if defined(CONFIG_DRM_AMD_DC)
 	if (amdgpu_device_has_dc_support(adev))
@@ -1654,17 +1587,29 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
 	}
 
 	amdgpu_ras_debugfs_create_all(adev);
-
 	amdgpu_debugfs_autodump_init(adev);
-
 	amdgpu_rap_debugfs_init(adev);
-
 	amdgpu_securedisplay_debugfs_init(adev);
-
 	amdgpu_fw_attestation_debugfs_init(adev);
 
-	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,
-					ARRAY_SIZE(amdgpu_debugfs_list));
+	debugfs_create_file("amdgpu_evict_vram", S_IFREG | S_IRUGO, root, adev,
+			    &amdgpu_evict_vram_fops);
+	debugfs_create_file("amdgpu_evict_gtt", S_IFREG | S_IRUGO, root, adev,
+			    &amdgpu_evict_gtt_fops);
+	debugfs_create_file("amdgpu_test_ib", S_IFREG | S_IRUGO, root, adev,
+			    &amdgpu_debugfs_test_ib_fops);
+	debugfs_create_file("amdgpu_vm_info", S_IFREG | S_IRUGO, root, adev,
+			    &amdgpu_debugfs_vm_info_fops);
+
+	vbios = devm_kzalloc(adev_to_drm(adev)->dev, sizeof(*vbios), GFP_KERNEL);
+	if (!vbios)
+		return -ENOMEM;
+
+	vbios->data = adev->bios;
+	vbios->size = adev->bios_size;
+	debugfs_create_blob("amdgpu_vbios", S_IFREG | S_IRUGO, root, vbios);
+
+	return 0;
 }
 
 #else
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
index 2803884d338d..0ed866da865e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
@@ -42,7 +42,7 @@ void amdgpu_debugfs_fini(struct amdgpu_device *adev);
 int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
 			     const struct drm_info_list *files,
 			     unsigned nfiles);
-int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
-int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
-int amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
 int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index d56f4023ebb3..7809c4db5a3e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -36,8 +36,6 @@
 #include <linux/firmware.h>
 #include <linux/pm_runtime.h>
 
-#include <drm/drm_debugfs.h>
-
 #include "amdgpu.h"
 #include "amdgpu_trace.h"
 
@@ -697,11 +695,9 @@ static const struct dma_fence_ops amdgpu_fence_ops = {
  * Fence debugfs
  */
 #if defined(CONFIG_DEBUG_FS)
-static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
+static int amdgpu_debugfs_fence_info_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
 	int i;
 
 	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
@@ -746,11 +742,10 @@ static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
  *
  * Manually trigger a gpu reset at the next fence wait.
  */
-static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
+static int gpu_recover_get(void *data, u64 *val)
 {
-	struct drm_info_node *node = (struct drm_info_node *) m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)data;
+	struct drm_device *dev = adev_to_drm(adev);
 	int r;
 
 	r = pm_runtime_get_sync(dev->dev);
@@ -759,8 +754,7 @@ static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
 		return 0;
 	}
 
-	seq_printf(m, "gpu recover\n");
-	amdgpu_device_gpu_recover(adev, NULL);
+	*val = amdgpu_device_gpu_recover(adev, NULL);
 
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
@@ -768,26 +762,25 @@ static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
 	return 0;
 }
 
-static const struct drm_info_list amdgpu_debugfs_fence_list[] = {
-	{"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
-	{"amdgpu_gpu_recover", &amdgpu_debugfs_gpu_recover, 0, NULL}
-};
+DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_fence_info);
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gpu_recover_fops, gpu_recover_get, NULL,
+			 "%lld\n");
 
-static const struct drm_info_list amdgpu_debugfs_fence_list_sriov[] = {
-	{"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
-};
 #endif
 
-int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
+void amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	if (amdgpu_sriov_vf(adev))
-		return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list_sriov,
-						ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
-	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
-					ARRAY_SIZE(amdgpu_debugfs_fence_list));
-#else
-	return 0;
+	struct drm_minor *minor = adev_to_drm(adev)->primary;
+	umode_t mode = S_IFREG | S_IRUGO;
+	struct dentry *root = minor->debugfs_root;
+
+	debugfs_create_file("amdgpu_fence_info", mode, root, adev,
+			    &amdgpu_debugfs_fence_info_fops);
+
+	if (!amdgpu_sriov_vf(adev))
+		debugfs_create_file("amdgpu_gpu_recover", mode, root, adev,
+				    &amdgpu_debugfs_gpu_recover_fops);
 #endif
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 5b50860eece4..c2e77ab3331a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -32,7 +32,6 @@
 #include <linux/dma-buf.h>
 
 #include <drm/amdgpu_drm.h>
-#include <drm/drm_debugfs.h>
 
 #include "amdgpu.h"
 #include "amdgpu_display.h"
@@ -836,10 +835,10 @@ int amdgpu_mode_dumb_create(struct drm_file *file_priv,
 }
 
 #if defined(CONFIG_DEBUG_FS)
-static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
+static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct drm_device *dev = adev_to_drm(adev);
 	struct drm_file *file;
 	int r;
 
@@ -877,16 +876,18 @@ static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
 	return 0;
 }
 
-static const struct drm_info_list amdgpu_debugfs_gem_list[] = {
-	{"amdgpu_gem_info", &amdgpu_debugfs_gem_info, 0, NULL},
-};
+DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_gem_info);
+
 #endif
 
-int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
+void amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
-					ARRAY_SIZE(amdgpu_debugfs_gem_list));
+	struct drm_minor *minor = adev_to_drm(adev)->primary;
+	umode_t mode = S_IFREG | S_IRUGO;
+	struct dentry *root = minor->debugfs_root;
+
+	debugfs_create_file("amdgpu_gem_info", mode, root, adev,
+			    &amdgpu_debugfs_gem_info_fops);
 #endif
-	return 0;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 7645223ea0ef..3155e4b61d9f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -30,7 +30,6 @@
 #include <linux/slab.h>
 
 #include <drm/amdgpu_drm.h>
-#include <drm/drm_debugfs.h>
 
 #include "amdgpu.h"
 #include "atom.h"
@@ -453,11 +452,9 @@ int amdgpu_ib_ring_tests(struct amdgpu_device *adev)
  */
 #if defined(CONFIG_DEBUG_FS)
 
-static int amdgpu_debugfs_sa_info(struct seq_file *m, void *data)
+static int amdgpu_debugfs_sa_info_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *) m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
 
 	seq_printf(m, "--------------------- DELAYED --------------------- \n");
 	amdgpu_sa_bo_dump_debug_info(&adev->ib_pools[AMDGPU_IB_POOL_DELAYED],
@@ -471,18 +468,19 @@ static int amdgpu_debugfs_sa_info(struct seq_file *m, void *data)
 	return 0;
 }
 
-static const struct drm_info_list amdgpu_debugfs_sa_list[] = {
-	{"amdgpu_sa_info", &amdgpu_debugfs_sa_info, 0, NULL},
-};
+DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_sa_info);
 
 #endif
 
-int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
+void amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
-					ARRAY_SIZE(amdgpu_debugfs_sa_list));
-#else
-	return 0;
+	struct drm_minor *minor = adev_to_drm(adev)->primary;
+	umode_t mode = S_IFREG | S_IRUGO;
+	struct dentry *root = minor->debugfs_root;
+
+	debugfs_create_file("amdgpu_sa_info", mode, root, adev,
+			    &amdgpu_debugfs_sa_info_fops);
+
 #endif
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index e365c4fdcfe3..3ab0a0b48675 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -27,7 +27,6 @@
  */
 
 #include "amdgpu.h"
-#include <drm/drm_debugfs.h>
 #include <drm/amdgpu_drm.h>
 #include "amdgpu_sched.h"
 #include "amdgpu_uvd.h"
@@ -1287,11 +1286,9 @@ const int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms);
  */
 #if defined(CONFIG_DEBUG_FS)
 
-static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
+static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *) m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
 	struct drm_amdgpu_info_firmware fw_info;
 	struct drm_amdgpu_query_fw query_fw;
 	struct atom_context *ctx = adev->mode_info.atom_context;
@@ -1497,17 +1494,19 @@ static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
 	return 0;
 }
 
-static const struct drm_info_list amdgpu_firmware_info_list[] = {
-	{"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL},
-};
+DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_firmware_info);
+
 #endif
 
-int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
+void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list,
-					ARRAY_SIZE(amdgpu_firmware_info_list));
-#else
-	return 0;
+	struct drm_minor *minor = adev_to_drm(adev)->primary;
+	umode_t mode = S_IFREG | S_IRUGO;
+	struct dentry *root = minor->debugfs_root;
+
+	debugfs_create_file("amdgpu_firmware_info", mode, root, adev,
+			    &amdgpu_debugfs_firmware_info_fops);
+
 #endif
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index adbefd6a655d..192627d35bae 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -331,7 +331,7 @@ void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager,
 					 struct seq_file *m);
 u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m);
 #endif
-int amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
 
 bool amdgpu_bo_support_uswc(u64 bo_flags);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index ce92768cd146..3006a720b6f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -49,7 +49,6 @@
 #include <drm/ttm/ttm_module.h>
 #include <drm/ttm/ttm_page_alloc.h>
 
-#include <drm/drm_debugfs.h>
 #include <drm/amdgpu_drm.h>
 
 #include "amdgpu.h"
@@ -2253,30 +2252,66 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
 
 #if defined(CONFIG_DEBUG_FS)
 
-static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
+static int amdgpu_mm_vram_table_show(struct seq_file *m, void *unused)
 {
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	unsigned ttm_pl = (uintptr_t)node->info_ent->data;
-	struct drm_device *dev = node->minor->dev;
-	struct amdgpu_device *adev = drm_to_adev(dev);
-	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, ttm_pl);
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
+							    TTM_PL_VRAM);
 	struct drm_printer p = drm_seq_file_printer(m);
 
 	man->func->debug(man, &p);
 	return 0;
 }
 
-static const struct drm_info_list amdgpu_ttm_debugfs_list[] = {
-	{"amdgpu_vram_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_VRAM},
-	{"amdgpu_gtt_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_TT},
-	{"amdgpu_gds_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GDS},
-	{"amdgpu_gws_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GWS},
-	{"amdgpu_oa_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_OA},
-	{"ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL},
-#ifdef CONFIG_SWIOTLB
-	{"ttm_dma_page_pool", ttm_dma_page_alloc_debugfs, 0, NULL}
-#endif
-};
+static int amdgpu_mm_tt_table_show(struct seq_file *m, void *unused)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
+							    TTM_PL_TT);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	man->func->debug(man, &p);
+	return 0;
+}
+
+static int amdgpu_mm_gds_table_show(struct seq_file *m, void *unused)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
+							    AMDGPU_PL_GDS);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	man->func->debug(man, &p);
+	return 0;
+}
+
+static int amdgpu_mm_gws_table_show(struct seq_file *m, void *unused)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
+							    AMDGPU_PL_GWS);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	man->func->debug(man, &p);
+	return 0;
+}
+
+static int amdgpu_mm_oa_table_show(struct seq_file *m, void *unused)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
+	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
+							    AMDGPU_PL_OA);
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	man->func->debug(man, &p);
+	return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_vram_table);
+DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_tt_table);
+DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gds_table);
+DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gws_table);
+DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_oa_table);
 
 /*
  * amdgpu_ttm_vram_read - Linear read access to VRAM
@@ -2478,13 +2513,40 @@ static const struct file_operations amdgpu_ttm_iomem_fops = {
 	.llseek = default_llseek
 };
 
+static int amdgpu_ttm_page_debugfs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, ttm_page_alloc_debugfs, inode->i_private);
+}
+
+static const struct file_operations amdgpu_ttm_page_debugfs_fops = {
+	.owner = THIS_MODULE,
+	.open = amdgpu_ttm_page_debugfs_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+#ifdef CONFIG_SWIOTLB
+static int amdgpu_ttm_dma_page_debugfs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, ttm_dma_page_alloc_debugfs, inode->i_private);
+}
+
+
+static const struct file_operations amdgpu_ttm_dma_page_debugfs_fops = {
+	.owner = THIS_MODULE,
+	.open = amdgpu_ttm_dma_page_debugfs_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
 #endif
 
-int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
+#endif
+
+void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	unsigned count;
-
 	struct drm_minor *minor = adev_to_drm(adev)->primary;
 	umode_t mode = S_IFREG | S_IRUGO;
 	struct dentry *root = minor->debugfs_root;
@@ -2493,15 +2555,22 @@ int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
 				 &amdgpu_ttm_vram_fops, adev->gmc.mc_vram_size);
 	debugfs_create_file("amdgpu_iomem", mode, root, adev,
 			    &amdgpu_ttm_iomem_fops);
-	count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
-
+	debugfs_create_file("amdgpu_vram_mm", mode, root, adev,
+			    &amdgpu_mm_vram_table_fops);
+	debugfs_create_file("amdgpu_gtt_mm", mode, root, adev,
+			    &amdgpu_mm_tt_table_fops);
+	debugfs_create_file("amdgpu_gds_mm", mode, root, adev,
+			    &amdgpu_mm_gds_table_fops);
+	debugfs_create_file("amdgpu_gws_mm", mode, root, adev,
+			    &amdgpu_mm_gws_table_fops);
+	debugfs_create_file("amdgpu_oa_mm", mode, root, adev,
+			    &amdgpu_mm_oa_table_fops);
+	debugfs_create_file("ttm_page_pool", mode, root, adev,
+			    &amdgpu_ttm_page_debugfs_fops);
 #ifdef CONFIG_SWIOTLB
-	if (!(adev->need_swiotlb && swiotlb_nr_tbl()))
-		--count;
+	if ((adev->need_swiotlb && swiotlb_nr_tbl()))
+		debugfs_create_file("ttm_dma_page_pool", mode, root, adev,
+				    &amdgpu_ttm_dma_page_debugfs_fops);
 #endif
-
-	return amdgpu_debugfs_add_files(adev, amdgpu_ttm_debugfs_list, count);
-#else
-	return 0;
 #endif
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index 4df4cf2fd4dd..69ba8dd4f3ee 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -186,6 +186,6 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_resource *mem);
 uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
 				 struct ttm_resource *mem);
 
-int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
+void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
 
 #endif
-- 
2.30.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] drm/amdgpu: do not use drm middle layer for debugfs
  2021-02-15 10:16 ` [PATCH 3/3] drm/amdgpu: " Nirmoy Das
@ 2021-02-15 10:43   ` Christian König
  2021-02-15 11:03     ` Nirmoy
  0 siblings, 1 reply; 6+ messages in thread
From: Christian König @ 2021-02-15 10:43 UTC (permalink / raw)
  To: Nirmoy Das; +Cc: amd-gfx



Am 15.02.21 um 11:16 schrieb Nirmoy Das:
> Use debugfs API directly instead of drm middle layer.
>
> This also includes following debugfs file output changes:
> 1 amdgpu_evict_vram/amdgpu_evict_gtt output will not contain any braces.
>    e.g. (0) --> 0
> 2 amdgpu_gpu_recover output will print return value of
>    amdgpu_device_gpu_recover() instead of not so important "gpu recover"
>    message.
>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 157 +++++++-------------
>   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h |   6 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c   |  47 +++---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     |  23 +--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c      |  24 ++-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     |  25 ++--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h  |   2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c     | 127 ++++++++++++----
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h     |   2 +-
>   9 files changed, 209 insertions(+), 204 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> index 719ae65ad633..827a4fd15f85 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> @@ -28,7 +28,6 @@
>   #include <linux/uaccess.h>
>   #include <linux/pm_runtime.h>
>   #include <linux/poll.h>
> -#include <drm/drm_debugfs.h>
>   
>   #include "amdgpu.h"
>   #include "amdgpu_pm.h"
> @@ -38,45 +37,6 @@
>   #include "amdgpu_securedisplay.h"
>   #include "amdgpu_fw_attestation.h"
>   
> -/**
> - * amdgpu_debugfs_add_files - Add simple debugfs entries
> - *
> - * @adev:  Device to attach debugfs entries to
> - * @files:  Array of function callbacks that respond to reads
> - * @nfiles: Number of callbacks to register
> - *
> - */
> -int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
> -			     const struct drm_info_list *files,
> -			     unsigned nfiles)
> -{
> -	unsigned i;
> -
> -	for (i = 0; i < adev->debugfs_count; i++) {
> -		if (adev->debugfs[i].files == files) {
> -			/* Already registered */
> -			return 0;
> -		}
> -	}
> -
> -	i = adev->debugfs_count + 1;
> -	if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
> -		DRM_ERROR("Reached maximum number of debugfs components.\n");
> -		DRM_ERROR("Report so we increase "
> -			  "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
> -		return -EINVAL;
> -	}
> -	adev->debugfs[adev->debugfs_count].files = files;
> -	adev->debugfs[adev->debugfs_count].num_files = nfiles;
> -	adev->debugfs_count = i;
> -#if defined(CONFIG_DEBUG_FS)
> -	drm_debugfs_create_files(files, nfiles,
> -				 adev_to_drm(adev)->primary->debugfs_root,
> -				 adev_to_drm(adev)->primary);
> -#endif
> -	return 0;
> -}
> -
>   int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> @@ -1233,16 +1193,15 @@ int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
>   	return 0;
>   }
>   
> -static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
> +static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *) m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct drm_device *dev = adev_to_drm(adev);
>   	int r = 0, i;
>   
>   	r = pm_runtime_get_sync(dev->dev);
>   	if (r < 0) {
> -		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> +		pm_runtime_put_autosuspend(dev->dev);
>   		return r;
>   	}
>   
> @@ -1284,30 +1243,19 @@ static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
>   	return 0;
>   }
>   
> -static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void *data)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *) m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> -
> -	seq_write(m, adev->bios, adev->bios_size);
> -	return 0;
> -}
> -
> -static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
> +static int evict_vram_get(void *data, u64 *val)

Please keep the function name unchanged.

>   {
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)data;
> +	struct drm_device *dev = adev_to_drm(adev);
>   	int r;
>   
>   	r = pm_runtime_get_sync(dev->dev);
>   	if (r < 0) {
> -		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> +		pm_runtime_put_autosuspend(dev->dev);
>   		return r;
>   	}
>   
> -	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
> +	*val = amdgpu_bo_evict_vram(adev);
>   
>   	pm_runtime_mark_last_busy(dev->dev);
>   	pm_runtime_put_autosuspend(dev->dev);
> @@ -1315,11 +1263,11 @@ static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
>   	return 0;
>   }
>   
> -static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
> +
> +static int evict_gtt_get(void *data, u64 *val)

Same here.

>   {
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)data;
> +	struct drm_device *dev = adev_to_drm(adev);
>   	int r;
>   
>   	r = pm_runtime_get_sync(dev->dev);
> @@ -1328,7 +1276,7 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
>   		return r;
>   	}
>   
> -	seq_printf(m, "(%d)\n", ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT));
> +	*val = ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT);
>   
>   	pm_runtime_mark_last_busy(dev->dev);
>   	pm_runtime_put_autosuspend(dev->dev);
> @@ -1336,10 +1284,11 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
>   	return 0;
>   }
>   
> -static int amdgpu_debugfs_vm_info(struct seq_file *m, void *data)
> +
> +static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct drm_device *dev = adev_to_drm(adev);
>   	struct drm_file *file;
>   	int r;
>   
> @@ -1365,13 +1314,10 @@ static int amdgpu_debugfs_vm_info(struct seq_file *m, void *data)
>   	return r;
>   }
>   
> -static const struct drm_info_list amdgpu_debugfs_list[] = {
> -	{"amdgpu_vbios", amdgpu_debugfs_get_vbios_dump},
> -	{"amdgpu_test_ib", &amdgpu_debugfs_test_ib},
> -	{"amdgpu_evict_vram", &amdgpu_debugfs_evict_vram},
> -	{"amdgpu_evict_gtt", &amdgpu_debugfs_evict_gtt},
> -	{"amdgpu_vm_info", &amdgpu_debugfs_vm_info},
> -};
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_test_ib);
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_vm_info);
> +DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_vram_fops, evict_vram_get, NULL, "%lld\n");
> +DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_gtt_fops, evict_gtt_get, NULL, "%lld\n");
>   
>   static void amdgpu_ib_preempt_fences_swap(struct amdgpu_ring *ring,
>   					  struct dma_fence **fences)
> @@ -1592,17 +1538,19 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
>   {
>   	struct dentry *ent;
>   	int r, i;
> +	struct dentry *root = adev_to_drm(adev)->primary->debugfs_root;
> +	struct debugfs_blob_wrapper *vbios;

Variable like "r, i" and "ent" declared last please.

> +
> +
>   
> -	ent = debugfs_create_file("amdgpu_preempt_ib", 0600,
> -				  adev_to_drm(adev)->primary->debugfs_root, adev,
> +	ent = debugfs_create_file("amdgpu_preempt_ib", 0600, root, adev,
>   				  &fops_ib_preempt);
>   	if (!ent) {
>   		DRM_ERROR("unable to create amdgpu_preempt_ib debugsfs file\n");
>   		return -EIO;
>   	}
>   
> -	ent = debugfs_create_file("amdgpu_force_sclk", 0200,
> -				  adev_to_drm(adev)->primary->debugfs_root, adev,
> +	ent = debugfs_create_file("amdgpu_force_sclk", 0200, root, adev,
>   				  &fops_sclk_set);
>   	if (!ent) {
>   		DRM_ERROR("unable to create amdgpu_set_sclk debugsfs file\n");
> @@ -1610,32 +1558,17 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
>   	}
>   
>   	/* Register debugfs entries for amdgpu_ttm */
> -	r = amdgpu_ttm_debugfs_init(adev);
> -	if (r) {
> -		DRM_ERROR("Failed to init debugfs\n");
> -		return r;
> -	}
> -
> +	amdgpu_ttm_debugfs_init(adev);
>   	amdgpu_debugfs_pm_init(adev);
> -
> -	if (amdgpu_debugfs_sa_init(adev)) {
> -		dev_err(adev->dev, "failed to register debugfs file for SA\n");
> -	}
> -
> -	if (amdgpu_debugfs_fence_init(adev))
> -		dev_err(adev->dev, "fence debugfs file creation failed\n");
> -
> -	r = amdgpu_debugfs_gem_init(adev);
> -	if (r)
> -		DRM_ERROR("registering gem debugfs failed (%d).\n", r);
> +	amdgpu_debugfs_sa_init(adev);
> +	amdgpu_debugfs_fence_init(adev);
> +	amdgpu_debugfs_gem_init(adev);
>   
>   	r = amdgpu_debugfs_regs_init(adev);
>   	if (r)
>   		DRM_ERROR("registering register debugfs failed (%d).\n", r);
>   
> -	r = amdgpu_debugfs_firmware_init(adev);
> -	if (r)
> -		DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
> +	amdgpu_debugfs_firmware_init(adev);
>   
>   #if defined(CONFIG_DRM_AMD_DC)
>   	if (amdgpu_device_has_dc_support(adev))
> @@ -1654,17 +1587,29 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
>   	}
>   
>   	amdgpu_ras_debugfs_create_all(adev);
> -
>   	amdgpu_debugfs_autodump_init(adev);
> -
>   	amdgpu_rap_debugfs_init(adev);
> -
>   	amdgpu_securedisplay_debugfs_init(adev);
> -
>   	amdgpu_fw_attestation_debugfs_init(adev);
>   
> -	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,
> -					ARRAY_SIZE(amdgpu_debugfs_list));
> +	debugfs_create_file("amdgpu_evict_vram", S_IFREG | S_IRUGO, root, adev,
> +			    &amdgpu_evict_vram_fops);
> +	debugfs_create_file("amdgpu_evict_gtt", S_IFREG | S_IRUGO, root, adev,
> +			    &amdgpu_evict_gtt_fops);
> +	debugfs_create_file("amdgpu_test_ib", S_IFREG | S_IRUGO, root, adev,
> +			    &amdgpu_debugfs_test_ib_fops);
> +	debugfs_create_file("amdgpu_vm_info", S_IFREG | S_IRUGO, root, adev,
> +			    &amdgpu_debugfs_vm_info_fops);
> +
> +	vbios = devm_kzalloc(adev_to_drm(adev)->dev, sizeof(*vbios), GFP_KERNEL);
> +	if (!vbios)
> +		return -ENOMEM;
> +
> +	vbios->data = adev->bios;
> +	vbios->size = adev->bios_size;
> +	debugfs_create_blob("amdgpu_vbios", S_IFREG | S_IRUGO, root, vbios);

Is that vbios allocation ever freed? Maybe just change adev->bios and 
adev->bios_dize into a debugfs_blob_wrapper structure.

Or at least keep the debugfs_blob_wrapper structure inside adev.

> +
> +	return 0;
>   }
>   
>   #else
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
> index 2803884d338d..0ed866da865e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
> @@ -42,7 +42,7 @@ void amdgpu_debugfs_fini(struct amdgpu_device *adev);
>   int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
>   			     const struct drm_info_list *files,
>   			     unsigned nfiles);
> -int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
> -int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
> -int amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
> +void amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
> +void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
> +void amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
>   int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> index d56f4023ebb3..7809c4db5a3e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> @@ -36,8 +36,6 @@
>   #include <linux/firmware.h>
>   #include <linux/pm_runtime.h>
>   
> -#include <drm/drm_debugfs.h>
> -
>   #include "amdgpu.h"
>   #include "amdgpu_trace.h"
>   
> @@ -697,11 +695,9 @@ static const struct dma_fence_ops amdgpu_fence_ops = {
>    * Fence debugfs
>    */
>   #if defined(CONFIG_DEBUG_FS)
> -static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
> +static int amdgpu_debugfs_fence_info_show(struct seq_file *m, void *unused)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>   	int i;
>   
>   	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
> @@ -746,11 +742,10 @@ static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
>    *
>    * Manually trigger a gpu reset at the next fence wait.
>    */
> -static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
> +static int gpu_recover_get(void *data, u64 *val)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *) m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)data;
> +	struct drm_device *dev = adev_to_drm(adev);
>   	int r;
>   
>   	r = pm_runtime_get_sync(dev->dev);
> @@ -759,8 +754,7 @@ static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
>   		return 0;
>   	}
>   
> -	seq_printf(m, "gpu recover\n");
> -	amdgpu_device_gpu_recover(adev, NULL);
> +	*val = amdgpu_device_gpu_recover(adev, NULL);
>   
>   	pm_runtime_mark_last_busy(dev->dev);
>   	pm_runtime_put_autosuspend(dev->dev);
> @@ -768,26 +762,25 @@ static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
>   	return 0;
>   }
>   
> -static const struct drm_info_list amdgpu_debugfs_fence_list[] = {
> -	{"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
> -	{"amdgpu_gpu_recover", &amdgpu_debugfs_gpu_recover, 0, NULL}
> -};
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_fence_info);
> +DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gpu_recover_fops, gpu_recover_get, NULL,
> +			 "%lld\n");
>   
> -static const struct drm_info_list amdgpu_debugfs_fence_list_sriov[] = {
> -	{"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
> -};
>   #endif
>   
> -int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
> +void amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> -	if (amdgpu_sriov_vf(adev))
> -		return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list_sriov,
> -						ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
> -	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
> -					ARRAY_SIZE(amdgpu_debugfs_fence_list));
> -#else
> -	return 0;
> +	struct drm_minor *minor = adev_to_drm(adev)->primary;
> +	umode_t mode = S_IFREG | S_IRUGO;

Why the mode as separate variable here? I would keep that close to each 
function call. Same for other places of course.

Apart from that this looks like a really nice cleanup to me.

Regards,
Christian.

> +	struct dentry *root = minor->debugfs_root;
> +
> +	debugfs_create_file("amdgpu_fence_info", mode, root, adev,
> +			    &amdgpu_debugfs_fence_info_fops);
> +
> +	if (!amdgpu_sriov_vf(adev))
> +		debugfs_create_file("amdgpu_gpu_recover", mode, root, adev,
> +				    &amdgpu_debugfs_gpu_recover_fops);
>   #endif
>   }
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 5b50860eece4..c2e77ab3331a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -32,7 +32,6 @@
>   #include <linux/dma-buf.h>
>   
>   #include <drm/amdgpu_drm.h>
> -#include <drm/drm_debugfs.h>
>   
>   #include "amdgpu.h"
>   #include "amdgpu_display.h"
> @@ -836,10 +835,10 @@ int amdgpu_mode_dumb_create(struct drm_file *file_priv,
>   }
>   
>   #if defined(CONFIG_DEBUG_FS)
> -static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
> +static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct drm_device *dev = adev_to_drm(adev);
>   	struct drm_file *file;
>   	int r;
>   
> @@ -877,16 +876,18 @@ static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
>   	return 0;
>   }
>   
> -static const struct drm_info_list amdgpu_debugfs_gem_list[] = {
> -	{"amdgpu_gem_info", &amdgpu_debugfs_gem_info, 0, NULL},
> -};
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_gem_info);
> +
>   #endif
>   
> -int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
> +void amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> -	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
> -					ARRAY_SIZE(amdgpu_debugfs_gem_list));
> +	struct drm_minor *minor = adev_to_drm(adev)->primary;
> +	umode_t mode = S_IFREG | S_IRUGO;
> +	struct dentry *root = minor->debugfs_root;
> +
> +	debugfs_create_file("amdgpu_gem_info", mode, root, adev,
> +			    &amdgpu_debugfs_gem_info_fops);
>   #endif
> -	return 0;
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> index 7645223ea0ef..3155e4b61d9f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> @@ -30,7 +30,6 @@
>   #include <linux/slab.h>
>   
>   #include <drm/amdgpu_drm.h>
> -#include <drm/drm_debugfs.h>
>   
>   #include "amdgpu.h"
>   #include "atom.h"
> @@ -453,11 +452,9 @@ int amdgpu_ib_ring_tests(struct amdgpu_device *adev)
>    */
>   #if defined(CONFIG_DEBUG_FS)
>   
> -static int amdgpu_debugfs_sa_info(struct seq_file *m, void *data)
> +static int amdgpu_debugfs_sa_info_show(struct seq_file *m, void *unused)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *) m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>   
>   	seq_printf(m, "--------------------- DELAYED --------------------- \n");
>   	amdgpu_sa_bo_dump_debug_info(&adev->ib_pools[AMDGPU_IB_POOL_DELAYED],
> @@ -471,18 +468,19 @@ static int amdgpu_debugfs_sa_info(struct seq_file *m, void *data)
>   	return 0;
>   }
>   
> -static const struct drm_info_list amdgpu_debugfs_sa_list[] = {
> -	{"amdgpu_sa_info", &amdgpu_debugfs_sa_info, 0, NULL},
> -};
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_sa_info);
>   
>   #endif
>   
> -int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
> +void amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> -	return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
> -					ARRAY_SIZE(amdgpu_debugfs_sa_list));
> -#else
> -	return 0;
> +	struct drm_minor *minor = adev_to_drm(adev)->primary;
> +	umode_t mode = S_IFREG | S_IRUGO;
> +	struct dentry *root = minor->debugfs_root;
> +
> +	debugfs_create_file("amdgpu_sa_info", mode, root, adev,
> +			    &amdgpu_debugfs_sa_info_fops);
> +
>   #endif
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index e365c4fdcfe3..3ab0a0b48675 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -27,7 +27,6 @@
>    */
>   
>   #include "amdgpu.h"
> -#include <drm/drm_debugfs.h>
>   #include <drm/amdgpu_drm.h>
>   #include "amdgpu_sched.h"
>   #include "amdgpu_uvd.h"
> @@ -1287,11 +1286,9 @@ const int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms);
>    */
>   #if defined(CONFIG_DEBUG_FS)
>   
> -static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
> +static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *) m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>   	struct drm_amdgpu_info_firmware fw_info;
>   	struct drm_amdgpu_query_fw query_fw;
>   	struct atom_context *ctx = adev->mode_info.atom_context;
> @@ -1497,17 +1494,19 @@ static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
>   	return 0;
>   }
>   
> -static const struct drm_info_list amdgpu_firmware_info_list[] = {
> -	{"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL},
> -};
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_firmware_info);
> +
>   #endif
>   
> -int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
> +void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> -	return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list,
> -					ARRAY_SIZE(amdgpu_firmware_info_list));
> -#else
> -	return 0;
> +	struct drm_minor *minor = adev_to_drm(adev)->primary;
> +	umode_t mode = S_IFREG | S_IRUGO;
> +	struct dentry *root = minor->debugfs_root;
> +
> +	debugfs_create_file("amdgpu_firmware_info", mode, root, adev,
> +			    &amdgpu_debugfs_firmware_info_fops);
> +
>   #endif
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index adbefd6a655d..192627d35bae 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -331,7 +331,7 @@ void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager,
>   					 struct seq_file *m);
>   u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m);
>   #endif
> -int amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
> +void amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
>   
>   bool amdgpu_bo_support_uswc(u64 bo_flags);
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index ce92768cd146..3006a720b6f5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -49,7 +49,6 @@
>   #include <drm/ttm/ttm_module.h>
>   #include <drm/ttm/ttm_page_alloc.h>
>   
> -#include <drm/drm_debugfs.h>
>   #include <drm/amdgpu_drm.h>
>   
>   #include "amdgpu.h"
> @@ -2253,30 +2252,66 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
>   
>   #if defined(CONFIG_DEBUG_FS)
>   
> -static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
> +static int amdgpu_mm_vram_table_show(struct seq_file *m, void *unused)
>   {
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	unsigned ttm_pl = (uintptr_t)node->info_ent->data;
> -	struct drm_device *dev = node->minor->dev;
> -	struct amdgpu_device *adev = drm_to_adev(dev);
> -	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, ttm_pl);
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
> +							    TTM_PL_VRAM);
>   	struct drm_printer p = drm_seq_file_printer(m);
>   
>   	man->func->debug(man, &p);
>   	return 0;
>   }
>   
> -static const struct drm_info_list amdgpu_ttm_debugfs_list[] = {
> -	{"amdgpu_vram_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_VRAM},
> -	{"amdgpu_gtt_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_TT},
> -	{"amdgpu_gds_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GDS},
> -	{"amdgpu_gws_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GWS},
> -	{"amdgpu_oa_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_OA},
> -	{"ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL},
> -#ifdef CONFIG_SWIOTLB
> -	{"ttm_dma_page_pool", ttm_dma_page_alloc_debugfs, 0, NULL}
> -#endif
> -};
> +static int amdgpu_mm_tt_table_show(struct seq_file *m, void *unused)
> +{
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
> +							    TTM_PL_TT);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	man->func->debug(man, &p);
> +	return 0;
> +}
> +
> +static int amdgpu_mm_gds_table_show(struct seq_file *m, void *unused)
> +{
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
> +							    AMDGPU_PL_GDS);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	man->func->debug(man, &p);
> +	return 0;
> +}
> +
> +static int amdgpu_mm_gws_table_show(struct seq_file *m, void *unused)
> +{
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
> +							    AMDGPU_PL_GWS);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	man->func->debug(man, &p);
> +	return 0;
> +}
> +
> +static int amdgpu_mm_oa_table_show(struct seq_file *m, void *unused)
> +{
> +	struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
> +	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
> +							    AMDGPU_PL_OA);
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	man->func->debug(man, &p);
> +	return 0;
> +}
> +
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_vram_table);
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_tt_table);
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gds_table);
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gws_table);
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_oa_table);
>   
>   /*
>    * amdgpu_ttm_vram_read - Linear read access to VRAM
> @@ -2478,13 +2513,40 @@ static const struct file_operations amdgpu_ttm_iomem_fops = {
>   	.llseek = default_llseek
>   };
>   
> +static int amdgpu_ttm_page_debugfs_open(struct inode *inode, struct file *file)
> +{
> +	return single_open(file, ttm_page_alloc_debugfs, inode->i_private);
> +}
> +
> +static const struct file_operations amdgpu_ttm_page_debugfs_fops = {
> +	.owner = THIS_MODULE,
> +	.open = amdgpu_ttm_page_debugfs_open,
> +	.read = seq_read,
> +	.llseek = seq_lseek,
> +	.release = single_release,
> +};
> +
> +#ifdef CONFIG_SWIOTLB
> +static int amdgpu_ttm_dma_page_debugfs_open(struct inode *inode, struct file *file)
> +{
> +	return single_open(file, ttm_dma_page_alloc_debugfs, inode->i_private);
> +}
> +
> +
> +static const struct file_operations amdgpu_ttm_dma_page_debugfs_fops = {
> +	.owner = THIS_MODULE,
> +	.open = amdgpu_ttm_dma_page_debugfs_open,
> +	.read = seq_read,
> +	.llseek = seq_lseek,
> +	.release = single_release,
> +};
>   #endif
>   
> -int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
> +#endif
> +
> +void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> -	unsigned count;
> -
>   	struct drm_minor *minor = adev_to_drm(adev)->primary;
>   	umode_t mode = S_IFREG | S_IRUGO;
>   	struct dentry *root = minor->debugfs_root;
> @@ -2493,15 +2555,22 @@ int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>   				 &amdgpu_ttm_vram_fops, adev->gmc.mc_vram_size);
>   	debugfs_create_file("amdgpu_iomem", mode, root, adev,
>   			    &amdgpu_ttm_iomem_fops);
> -	count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
> -
> +	debugfs_create_file("amdgpu_vram_mm", mode, root, adev,
> +			    &amdgpu_mm_vram_table_fops);
> +	debugfs_create_file("amdgpu_gtt_mm", mode, root, adev,
> +			    &amdgpu_mm_tt_table_fops);
> +	debugfs_create_file("amdgpu_gds_mm", mode, root, adev,
> +			    &amdgpu_mm_gds_table_fops);
> +	debugfs_create_file("amdgpu_gws_mm", mode, root, adev,
> +			    &amdgpu_mm_gws_table_fops);
> +	debugfs_create_file("amdgpu_oa_mm", mode, root, adev,
> +			    &amdgpu_mm_oa_table_fops);
> +	debugfs_create_file("ttm_page_pool", mode, root, adev,
> +			    &amdgpu_ttm_page_debugfs_fops);
>   #ifdef CONFIG_SWIOTLB
> -	if (!(adev->need_swiotlb && swiotlb_nr_tbl()))
> -		--count;
> +	if ((adev->need_swiotlb && swiotlb_nr_tbl()))
> +		debugfs_create_file("ttm_dma_page_pool", mode, root, adev,
> +				    &amdgpu_ttm_dma_page_debugfs_fops);
>   #endif
> -
> -	return amdgpu_debugfs_add_files(adev, amdgpu_ttm_debugfs_list, count);
> -#else
> -	return 0;
>   #endif
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> index 4df4cf2fd4dd..69ba8dd4f3ee 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> @@ -186,6 +186,6 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_resource *mem);
>   uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
>   				 struct ttm_resource *mem);
>   
> -int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
> +void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
>   
>   #endif

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] drm/amdgpu: do not use drm middle layer for debugfs
  2021-02-15 10:43   ` Christian König
@ 2021-02-15 11:03     ` Nirmoy
  2021-02-15 11:20       ` Nirmoy
  0 siblings, 1 reply; 6+ messages in thread
From: Nirmoy @ 2021-02-15 11:03 UTC (permalink / raw)
  To: Christian König, Nirmoy Das; +Cc: amd-gfx


On 2/15/21 11:43 AM, Christian König wrote:
>
>
> Am 15.02.21 um 11:16 schrieb Nirmoy Das:
>> Use debugfs API directly instead of drm middle layer.
>>
>> This also includes following debugfs file output changes:
>> 1 amdgpu_evict_vram/amdgpu_evict_gtt output will not contain any braces.
>>    e.g. (0) --> 0
>> 2 amdgpu_gpu_recover output will print return value of
>>    amdgpu_device_gpu_recover() instead of not so important "gpu recover"
>>    message.
>>
>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 157 +++++++-------------
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h |   6 +-
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c   |  47 +++---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     |  23 +--
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c      |  24 ++-
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     |  25 ++--
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h  |   2 +-
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c     | 127 ++++++++++++----
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h     |   2 +-
>>   9 files changed, 209 insertions(+), 204 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> index 719ae65ad633..827a4fd15f85 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> @@ -28,7 +28,6 @@
>>   #include <linux/uaccess.h>
>>   #include <linux/pm_runtime.h>
>>   #include <linux/poll.h>
>> -#include <drm/drm_debugfs.h>
>>     #include "amdgpu.h"
>>   #include "amdgpu_pm.h"
>> @@ -38,45 +37,6 @@
>>   #include "amdgpu_securedisplay.h"
>>   #include "amdgpu_fw_attestation.h"
>>   -/**
>> - * amdgpu_debugfs_add_files - Add simple debugfs entries
>> - *
>> - * @adev:  Device to attach debugfs entries to
>> - * @files:  Array of function callbacks that respond to reads
>> - * @nfiles: Number of callbacks to register
>> - *
>> - */
>> -int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
>> -                 const struct drm_info_list *files,
>> -                 unsigned nfiles)
>> -{
>> -    unsigned i;
>> -
>> -    for (i = 0; i < adev->debugfs_count; i++) {
>> -        if (adev->debugfs[i].files == files) {
>> -            /* Already registered */
>> -            return 0;
>> -        }
>> -    }
>> -
>> -    i = adev->debugfs_count + 1;
>> -    if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
>> -        DRM_ERROR("Reached maximum number of debugfs components.\n");
>> -        DRM_ERROR("Report so we increase "
>> -              "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
>> -        return -EINVAL;
>> -    }
>> -    adev->debugfs[adev->debugfs_count].files = files;
>> -    adev->debugfs[adev->debugfs_count].num_files = nfiles;
>> -    adev->debugfs_count = i;
>> -#if defined(CONFIG_DEBUG_FS)
>> -    drm_debugfs_create_files(files, nfiles,
>> - adev_to_drm(adev)->primary->debugfs_root,
>> -                 adev_to_drm(adev)->primary);
>> -#endif
>> -    return 0;
>> -}
>> -
>>   int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev)
>>   {
>>   #if defined(CONFIG_DEBUG_FS)
>> @@ -1233,16 +1193,15 @@ int amdgpu_debugfs_regs_init(struct 
>> amdgpu_device *adev)
>>       return 0;
>>   }
>>   -static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
>> +static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void 
>> *unused)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *) m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct drm_device *dev = adev_to_drm(adev);
>>       int r = 0, i;
>>         r = pm_runtime_get_sync(dev->dev);
>>       if (r < 0) {
>> -        pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
>> +        pm_runtime_put_autosuspend(dev->dev);
>>           return r;
>>       }
>>   @@ -1284,30 +1243,19 @@ static int amdgpu_debugfs_test_ib(struct 
>> seq_file *m, void *data)
>>       return 0;
>>   }
>>   -static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void 
>> *data)
>> -{
>> -    struct drm_info_node *node = (struct drm_info_node *) m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> -
>> -    seq_write(m, adev->bios, adev->bios_size);
>> -    return 0;
>> -}
>> -
>> -static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
>> +static int evict_vram_get(void *data, u64 *val)
>
> Please keep the function name unchanged.
>
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *)m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)data;
>> +    struct drm_device *dev = adev_to_drm(adev);
>>       int r;
>>         r = pm_runtime_get_sync(dev->dev);
>>       if (r < 0) {
>> -        pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
>> +        pm_runtime_put_autosuspend(dev->dev);
>>           return r;
>>       }
>>   -    seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
>> +    *val = amdgpu_bo_evict_vram(adev);
>>         pm_runtime_mark_last_busy(dev->dev);
>>       pm_runtime_put_autosuspend(dev->dev);
>> @@ -1315,11 +1263,11 @@ static int amdgpu_debugfs_evict_vram(struct 
>> seq_file *m, void *data)
>>       return 0;
>>   }
>>   -static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
>> +
>> +static int evict_gtt_get(void *data, u64 *val)
>
> Same here.
>
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *)m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)data;
>> +    struct drm_device *dev = adev_to_drm(adev);
>>       int r;
>>         r = pm_runtime_get_sync(dev->dev);
>> @@ -1328,7 +1276,7 @@ static int amdgpu_debugfs_evict_gtt(struct 
>> seq_file *m, void *data)
>>           return r;
>>       }
>>   -    seq_printf(m, "(%d)\n", ttm_bo_evict_mm(&adev->mman.bdev, 
>> TTM_PL_TT));
>> +    *val = ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT);
>>         pm_runtime_mark_last_busy(dev->dev);
>>       pm_runtime_put_autosuspend(dev->dev);
>> @@ -1336,10 +1284,11 @@ static int amdgpu_debugfs_evict_gtt(struct 
>> seq_file *m, void *data)
>>       return 0;
>>   }
>>   -static int amdgpu_debugfs_vm_info(struct seq_file *m, void *data)
>> +
>> +static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void 
>> *unused)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *)m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct drm_device *dev = adev_to_drm(adev);
>>       struct drm_file *file;
>>       int r;
>>   @@ -1365,13 +1314,10 @@ static int amdgpu_debugfs_vm_info(struct 
>> seq_file *m, void *data)
>>       return r;
>>   }
>>   -static const struct drm_info_list amdgpu_debugfs_list[] = {
>> -    {"amdgpu_vbios", amdgpu_debugfs_get_vbios_dump},
>> -    {"amdgpu_test_ib", &amdgpu_debugfs_test_ib},
>> -    {"amdgpu_evict_vram", &amdgpu_debugfs_evict_vram},
>> -    {"amdgpu_evict_gtt", &amdgpu_debugfs_evict_gtt},
>> -    {"amdgpu_vm_info", &amdgpu_debugfs_vm_info},
>> -};
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_test_ib);
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_vm_info);
>> +DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_vram_fops, evict_vram_get, 
>> NULL, "%lld\n");
>> +DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_gtt_fops, evict_gtt_get, NULL, 
>> "%lld\n");
>>     static void amdgpu_ib_preempt_fences_swap(struct amdgpu_ring *ring,
>>                         struct dma_fence **fences)
>> @@ -1592,17 +1538,19 @@ int amdgpu_debugfs_init(struct amdgpu_device 
>> *adev)
>>   {
>>       struct dentry *ent;
>>       int r, i;
>> +    struct dentry *root = adev_to_drm(adev)->primary->debugfs_root;
>> +    struct debugfs_blob_wrapper *vbios;
>
> Variable like "r, i" and "ent" declared last please.
>
>> +
>> +
>>   -    ent = debugfs_create_file("amdgpu_preempt_ib", 0600,
>> - adev_to_drm(adev)->primary->debugfs_root, adev,
>> +    ent = debugfs_create_file("amdgpu_preempt_ib", 0600, root, adev,
>>                     &fops_ib_preempt);
>>       if (!ent) {
>>           DRM_ERROR("unable to create amdgpu_preempt_ib debugsfs 
>> file\n");
>>           return -EIO;
>>       }
>>   -    ent = debugfs_create_file("amdgpu_force_sclk", 0200,
>> - adev_to_drm(adev)->primary->debugfs_root, adev,
>> +    ent = debugfs_create_file("amdgpu_force_sclk", 0200, root, adev,
>>                     &fops_sclk_set);
>>       if (!ent) {
>>           DRM_ERROR("unable to create amdgpu_set_sclk debugsfs file\n");
>> @@ -1610,32 +1558,17 @@ int amdgpu_debugfs_init(struct amdgpu_device 
>> *adev)
>>       }
>>         /* Register debugfs entries for amdgpu_ttm */
>> -    r = amdgpu_ttm_debugfs_init(adev);
>> -    if (r) {
>> -        DRM_ERROR("Failed to init debugfs\n");
>> -        return r;
>> -    }
>> -
>> +    amdgpu_ttm_debugfs_init(adev);
>>       amdgpu_debugfs_pm_init(adev);
>> -
>> -    if (amdgpu_debugfs_sa_init(adev)) {
>> -        dev_err(adev->dev, "failed to register debugfs file for SA\n");
>> -    }
>> -
>> -    if (amdgpu_debugfs_fence_init(adev))
>> -        dev_err(adev->dev, "fence debugfs file creation failed\n");
>> -
>> -    r = amdgpu_debugfs_gem_init(adev);
>> -    if (r)
>> -        DRM_ERROR("registering gem debugfs failed (%d).\n", r);
>> +    amdgpu_debugfs_sa_init(adev);
>> +    amdgpu_debugfs_fence_init(adev);
>> +    amdgpu_debugfs_gem_init(adev);
>>         r = amdgpu_debugfs_regs_init(adev);
>>       if (r)
>>           DRM_ERROR("registering register debugfs failed (%d).\n", r);
>>   -    r = amdgpu_debugfs_firmware_init(adev);
>> -    if (r)
>> -        DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
>> +    amdgpu_debugfs_firmware_init(adev);
>>     #if defined(CONFIG_DRM_AMD_DC)
>>       if (amdgpu_device_has_dc_support(adev))
>> @@ -1654,17 +1587,29 @@ int amdgpu_debugfs_init(struct amdgpu_device 
>> *adev)
>>       }
>>         amdgpu_ras_debugfs_create_all(adev);
>> -
>>       amdgpu_debugfs_autodump_init(adev);
>> -
>>       amdgpu_rap_debugfs_init(adev);
>> -
>>       amdgpu_securedisplay_debugfs_init(adev);
>> -
>>       amdgpu_fw_attestation_debugfs_init(adev);
>>   -    return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,
>> -                    ARRAY_SIZE(amdgpu_debugfs_list));
>> +    debugfs_create_file("amdgpu_evict_vram", S_IFREG | S_IRUGO, 
>> root, adev,
>> +                &amdgpu_evict_vram_fops);
>> +    debugfs_create_file("amdgpu_evict_gtt", S_IFREG | S_IRUGO, root, 
>> adev,
>> +                &amdgpu_evict_gtt_fops);
>> +    debugfs_create_file("amdgpu_test_ib", S_IFREG | S_IRUGO, root, 
>> adev,
>> +                &amdgpu_debugfs_test_ib_fops);
>> +    debugfs_create_file("amdgpu_vm_info", S_IFREG | S_IRUGO, root, 
>> adev,
>> +                &amdgpu_debugfs_vm_info_fops);
>> +
>> +    vbios = devm_kzalloc(adev_to_drm(adev)->dev, sizeof(*vbios), 
>> GFP_KERNEL);
>> +    if (!vbios)
>> +        return -ENOMEM;
>> +
>> +    vbios->data = adev->bios;
>> +    vbios->size = adev->bios_size;
>> +    debugfs_create_blob("amdgpu_vbios", S_IFREG | S_IRUGO, root, 
>> vbios);
>
> Is that vbios allocation ever freed? Maybe just change adev->bios and 
> adev->bios_dize into a debugfs_blob_wrapper structure.


devm_kzalloc will get freed on driver removal.

>
> Or at least keep the debugfs_blob_wrapper structure inside adev.
>
>> +
>> +    return 0;
>>   }
>>     #else
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
>> index 2803884d338d..0ed866da865e 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
>> @@ -42,7 +42,7 @@ void amdgpu_debugfs_fini(struct amdgpu_device *adev);
>>   int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
>>                    const struct drm_info_list *files,
>>                    unsigned nfiles);
>> -int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
>> -int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
>> -int amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
>> +void amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
>> +void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
>> +void amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
>>   int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
>> index d56f4023ebb3..7809c4db5a3e 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
>> @@ -36,8 +36,6 @@
>>   #include <linux/firmware.h>
>>   #include <linux/pm_runtime.h>
>>   -#include <drm/drm_debugfs.h>
>> -
>>   #include "amdgpu.h"
>>   #include "amdgpu_trace.h"
>>   @@ -697,11 +695,9 @@ static const struct dma_fence_ops 
>> amdgpu_fence_ops = {
>>    * Fence debugfs
>>    */
>>   #if defined(CONFIG_DEBUG_FS)
>> -static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
>> +static int amdgpu_debugfs_fence_info_show(struct seq_file *m, void 
>> *unused)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *)m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>>       int i;
>>         for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
>> @@ -746,11 +742,10 @@ static int amdgpu_debugfs_fence_info(struct 
>> seq_file *m, void *data)
>>    *
>>    * Manually trigger a gpu reset at the next fence wait.
>>    */
>> -static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
>> +static int gpu_recover_get(void *data, u64 *val)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *) m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)data;
>> +    struct drm_device *dev = adev_to_drm(adev);
>>       int r;
>>         r = pm_runtime_get_sync(dev->dev);
>> @@ -759,8 +754,7 @@ static int amdgpu_debugfs_gpu_recover(struct 
>> seq_file *m, void *data)
>>           return 0;
>>       }
>>   -    seq_printf(m, "gpu recover\n");
>> -    amdgpu_device_gpu_recover(adev, NULL);
>> +    *val = amdgpu_device_gpu_recover(adev, NULL);
>>         pm_runtime_mark_last_busy(dev->dev);
>>       pm_runtime_put_autosuspend(dev->dev);
>> @@ -768,26 +762,25 @@ static int amdgpu_debugfs_gpu_recover(struct 
>> seq_file *m, void *data)
>>       return 0;
>>   }
>>   -static const struct drm_info_list amdgpu_debugfs_fence_list[] = {
>> -    {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
>> -    {"amdgpu_gpu_recover", &amdgpu_debugfs_gpu_recover, 0, NULL}
>> -};
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_fence_info);
>> +DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gpu_recover_fops, 
>> gpu_recover_get, NULL,
>> +             "%lld\n");
>>   -static const struct drm_info_list 
>> amdgpu_debugfs_fence_list_sriov[] = {
>> -    {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
>> -};
>>   #endif
>>   -int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
>> +void amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
>>   {
>>   #if defined(CONFIG_DEBUG_FS)
>> -    if (amdgpu_sriov_vf(adev))
>> -        return amdgpu_debugfs_add_files(adev, 
>> amdgpu_debugfs_fence_list_sriov,
>> - ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
>> -    return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
>> -                    ARRAY_SIZE(amdgpu_debugfs_fence_list));
>> -#else
>> -    return 0;
>> +    struct drm_minor *minor = adev_to_drm(adev)->primary;
>> +    umode_t mode = S_IFREG | S_IRUGO;
>
> Why the mode as separate variable here? I would keep that close to 
> each function call. Same for other places of course.
>
> Apart from that this looks like a really nice cleanup to me.


Thanks, I will send resend a updated one.


Nirmoy


>
> Regards,
> Christian.
>
>> +    struct dentry *root = minor->debugfs_root;
>> +
>> +    debugfs_create_file("amdgpu_fence_info", mode, root, adev,
>> +                &amdgpu_debugfs_fence_info_fops);
>> +
>> +    if (!amdgpu_sriov_vf(adev))
>> +        debugfs_create_file("amdgpu_gpu_recover", mode, root, adev,
>> +                    &amdgpu_debugfs_gpu_recover_fops);
>>   #endif
>>   }
>>   diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> index 5b50860eece4..c2e77ab3331a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> @@ -32,7 +32,6 @@
>>   #include <linux/dma-buf.h>
>>     #include <drm/amdgpu_drm.h>
>> -#include <drm/drm_debugfs.h>
>>     #include "amdgpu.h"
>>   #include "amdgpu_display.h"
>> @@ -836,10 +835,10 @@ int amdgpu_mode_dumb_create(struct drm_file 
>> *file_priv,
>>   }
>>     #if defined(CONFIG_DEBUG_FS)
>> -static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
>> +static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void 
>> *unused)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *)m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct drm_device *dev = adev_to_drm(adev);
>>       struct drm_file *file;
>>       int r;
>>   @@ -877,16 +876,18 @@ static int amdgpu_debugfs_gem_info(struct 
>> seq_file *m, void *data)
>>       return 0;
>>   }
>>   -static const struct drm_info_list amdgpu_debugfs_gem_list[] = {
>> -    {"amdgpu_gem_info", &amdgpu_debugfs_gem_info, 0, NULL},
>> -};
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_gem_info);
>> +
>>   #endif
>>   -int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
>> +void amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
>>   {
>>   #if defined(CONFIG_DEBUG_FS)
>> -    return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
>> -                    ARRAY_SIZE(amdgpu_debugfs_gem_list));
>> +    struct drm_minor *minor = adev_to_drm(adev)->primary;
>> +    umode_t mode = S_IFREG | S_IRUGO;
>> +    struct dentry *root = minor->debugfs_root;
>> +
>> +    debugfs_create_file("amdgpu_gem_info", mode, root, adev,
>> +                &amdgpu_debugfs_gem_info_fops);
>>   #endif
>> -    return 0;
>>   }
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
>> index 7645223ea0ef..3155e4b61d9f 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
>> @@ -30,7 +30,6 @@
>>   #include <linux/slab.h>
>>     #include <drm/amdgpu_drm.h>
>> -#include <drm/drm_debugfs.h>
>>     #include "amdgpu.h"
>>   #include "atom.h"
>> @@ -453,11 +452,9 @@ int amdgpu_ib_ring_tests(struct amdgpu_device 
>> *adev)
>>    */
>>   #if defined(CONFIG_DEBUG_FS)
>>   -static int amdgpu_debugfs_sa_info(struct seq_file *m, void *data)
>> +static int amdgpu_debugfs_sa_info_show(struct seq_file *m, void 
>> *unused)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *) m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>>         seq_printf(m, "--------------------- DELAYED 
>> --------------------- \n");
>> amdgpu_sa_bo_dump_debug_info(&adev->ib_pools[AMDGPU_IB_POOL_DELAYED],
>> @@ -471,18 +468,19 @@ static int amdgpu_debugfs_sa_info(struct 
>> seq_file *m, void *data)
>>       return 0;
>>   }
>>   -static const struct drm_info_list amdgpu_debugfs_sa_list[] = {
>> -    {"amdgpu_sa_info", &amdgpu_debugfs_sa_info, 0, NULL},
>> -};
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_sa_info);
>>     #endif
>>   -int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
>> +void amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
>>   {
>>   #if defined(CONFIG_DEBUG_FS)
>> -    return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
>> -                    ARRAY_SIZE(amdgpu_debugfs_sa_list));
>> -#else
>> -    return 0;
>> +    struct drm_minor *minor = adev_to_drm(adev)->primary;
>> +    umode_t mode = S_IFREG | S_IRUGO;
>> +    struct dentry *root = minor->debugfs_root;
>> +
>> +    debugfs_create_file("amdgpu_sa_info", mode, root, adev,
>> +                &amdgpu_debugfs_sa_info_fops);
>> +
>>   #endif
>>   }
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>> index e365c4fdcfe3..3ab0a0b48675 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>> @@ -27,7 +27,6 @@
>>    */
>>     #include "amdgpu.h"
>> -#include <drm/drm_debugfs.h>
>>   #include <drm/amdgpu_drm.h>
>>   #include "amdgpu_sched.h"
>>   #include "amdgpu_uvd.h"
>> @@ -1287,11 +1286,9 @@ const int amdgpu_max_kms_ioctl = 
>> ARRAY_SIZE(amdgpu_ioctls_kms);
>>    */
>>   #if defined(CONFIG_DEBUG_FS)
>>   -static int amdgpu_debugfs_firmware_info(struct seq_file *m, void 
>> *data)
>> +static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, 
>> void *unused)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *) m->private;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>>       struct drm_amdgpu_info_firmware fw_info;
>>       struct drm_amdgpu_query_fw query_fw;
>>       struct atom_context *ctx = adev->mode_info.atom_context;
>> @@ -1497,17 +1494,19 @@ static int 
>> amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
>>       return 0;
>>   }
>>   -static const struct drm_info_list amdgpu_firmware_info_list[] = {
>> -    {"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL},
>> -};
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_firmware_info);
>> +
>>   #endif
>>   -int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
>> +void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
>>   {
>>   #if defined(CONFIG_DEBUG_FS)
>> -    return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list,
>> -                    ARRAY_SIZE(amdgpu_firmware_info_list));
>> -#else
>> -    return 0;
>> +    struct drm_minor *minor = adev_to_drm(adev)->primary;
>> +    umode_t mode = S_IFREG | S_IRUGO;
>> +    struct dentry *root = minor->debugfs_root;
>> +
>> +    debugfs_create_file("amdgpu_firmware_info", mode, root, adev,
>> +                &amdgpu_debugfs_firmware_info_fops);
>> +
>>   #endif
>>   }
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> index adbefd6a655d..192627d35bae 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> @@ -331,7 +331,7 @@ void amdgpu_sa_bo_dump_debug_info(struct 
>> amdgpu_sa_manager *sa_manager,
>>                        struct seq_file *m);
>>   u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct 
>> seq_file *m);
>>   #endif
>> -int amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
>> +void amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
>>     bool amdgpu_bo_support_uswc(u64 bo_flags);
>>   diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> index ce92768cd146..3006a720b6f5 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> @@ -49,7 +49,6 @@
>>   #include <drm/ttm/ttm_module.h>
>>   #include <drm/ttm/ttm_page_alloc.h>
>>   -#include <drm/drm_debugfs.h>
>>   #include <drm/amdgpu_drm.h>
>>     #include "amdgpu.h"
>> @@ -2253,30 +2252,66 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
>>     #if defined(CONFIG_DEBUG_FS)
>>   -static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
>> +static int amdgpu_mm_vram_table_show(struct seq_file *m, void *unused)
>>   {
>> -    struct drm_info_node *node = (struct drm_info_node *)m->private;
>> -    unsigned ttm_pl = (uintptr_t)node->info_ent->data;
>> -    struct drm_device *dev = node->minor->dev;
>> -    struct amdgpu_device *adev = drm_to_adev(dev);
>> -    struct ttm_resource_manager *man = 
>> ttm_manager_type(&adev->mman.bdev, ttm_pl);
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct ttm_resource_manager *man = 
>> ttm_manager_type(&adev->mman.bdev,
>> +                                TTM_PL_VRAM);
>>       struct drm_printer p = drm_seq_file_printer(m);
>>         man->func->debug(man, &p);
>>       return 0;
>>   }
>>   -static const struct drm_info_list amdgpu_ttm_debugfs_list[] = {
>> -    {"amdgpu_vram_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_VRAM},
>> -    {"amdgpu_gtt_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_TT},
>> -    {"amdgpu_gds_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GDS},
>> -    {"amdgpu_gws_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GWS},
>> -    {"amdgpu_oa_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_OA},
>> -    {"ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL},
>> -#ifdef CONFIG_SWIOTLB
>> -    {"ttm_dma_page_pool", ttm_dma_page_alloc_debugfs, 0, NULL}
>> -#endif
>> -};
>> +static int amdgpu_mm_tt_table_show(struct seq_file *m, void *unused)
>> +{
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct ttm_resource_manager *man = 
>> ttm_manager_type(&adev->mman.bdev,
>> +                                TTM_PL_TT);
>> +    struct drm_printer p = drm_seq_file_printer(m);
>> +
>> +    man->func->debug(man, &p);
>> +    return 0;
>> +}
>> +
>> +static int amdgpu_mm_gds_table_show(struct seq_file *m, void *unused)
>> +{
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct ttm_resource_manager *man = 
>> ttm_manager_type(&adev->mman.bdev,
>> +                                AMDGPU_PL_GDS);
>> +    struct drm_printer p = drm_seq_file_printer(m);
>> +
>> +    man->func->debug(man, &p);
>> +    return 0;
>> +}
>> +
>> +static int amdgpu_mm_gws_table_show(struct seq_file *m, void *unused)
>> +{
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct ttm_resource_manager *man = 
>> ttm_manager_type(&adev->mman.bdev,
>> +                                AMDGPU_PL_GWS);
>> +    struct drm_printer p = drm_seq_file_printer(m);
>> +
>> +    man->func->debug(man, &p);
>> +    return 0;
>> +}
>> +
>> +static int amdgpu_mm_oa_table_show(struct seq_file *m, void *unused)
>> +{
>> +    struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
>> +    struct ttm_resource_manager *man = 
>> ttm_manager_type(&adev->mman.bdev,
>> +                                AMDGPU_PL_OA);
>> +    struct drm_printer p = drm_seq_file_printer(m);
>> +
>> +    man->func->debug(man, &p);
>> +    return 0;
>> +}
>> +
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_vram_table);
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_tt_table);
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gds_table);
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gws_table);
>> +DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_oa_table);
>>     /*
>>    * amdgpu_ttm_vram_read - Linear read access to VRAM
>> @@ -2478,13 +2513,40 @@ static const struct file_operations 
>> amdgpu_ttm_iomem_fops = {
>>       .llseek = default_llseek
>>   };
>>   +static int amdgpu_ttm_page_debugfs_open(struct inode *inode, 
>> struct file *file)
>> +{
>> +    return single_open(file, ttm_page_alloc_debugfs, inode->i_private);
>> +}
>> +
>> +static const struct file_operations amdgpu_ttm_page_debugfs_fops = {
>> +    .owner = THIS_MODULE,
>> +    .open = amdgpu_ttm_page_debugfs_open,
>> +    .read = seq_read,
>> +    .llseek = seq_lseek,
>> +    .release = single_release,
>> +};
>> +
>> +#ifdef CONFIG_SWIOTLB
>> +static int amdgpu_ttm_dma_page_debugfs_open(struct inode *inode, 
>> struct file *file)
>> +{
>> +    return single_open(file, ttm_dma_page_alloc_debugfs, 
>> inode->i_private);
>> +}
>> +
>> +
>> +static const struct file_operations amdgpu_ttm_dma_page_debugfs_fops 
>> = {
>> +    .owner = THIS_MODULE,
>> +    .open = amdgpu_ttm_dma_page_debugfs_open,
>> +    .read = seq_read,
>> +    .llseek = seq_lseek,
>> +    .release = single_release,
>> +};
>>   #endif
>>   -int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>> +#endif
>> +
>> +void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>>   {
>>   #if defined(CONFIG_DEBUG_FS)
>> -    unsigned count;
>> -
>>       struct drm_minor *minor = adev_to_drm(adev)->primary;
>>       umode_t mode = S_IFREG | S_IRUGO;
>>       struct dentry *root = minor->debugfs_root;
>> @@ -2493,15 +2555,22 @@ int amdgpu_ttm_debugfs_init(struct 
>> amdgpu_device *adev)
>>                    &amdgpu_ttm_vram_fops, adev->gmc.mc_vram_size);
>>       debugfs_create_file("amdgpu_iomem", mode, root, adev,
>>                   &amdgpu_ttm_iomem_fops);
>> -    count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
>> -
>> +    debugfs_create_file("amdgpu_vram_mm", mode, root, adev,
>> +                &amdgpu_mm_vram_table_fops);
>> +    debugfs_create_file("amdgpu_gtt_mm", mode, root, adev,
>> +                &amdgpu_mm_tt_table_fops);
>> +    debugfs_create_file("amdgpu_gds_mm", mode, root, adev,
>> +                &amdgpu_mm_gds_table_fops);
>> +    debugfs_create_file("amdgpu_gws_mm", mode, root, adev,
>> +                &amdgpu_mm_gws_table_fops);
>> +    debugfs_create_file("amdgpu_oa_mm", mode, root, adev,
>> +                &amdgpu_mm_oa_table_fops);
>> +    debugfs_create_file("ttm_page_pool", mode, root, adev,
>> +                &amdgpu_ttm_page_debugfs_fops);
>>   #ifdef CONFIG_SWIOTLB
>> -    if (!(adev->need_swiotlb && swiotlb_nr_tbl()))
>> -        --count;
>> +    if ((adev->need_swiotlb && swiotlb_nr_tbl()))
>> +        debugfs_create_file("ttm_dma_page_pool", mode, root, adev,
>> +                    &amdgpu_ttm_dma_page_debugfs_fops);
>>   #endif
>> -
>> -    return amdgpu_debugfs_add_files(adev, amdgpu_ttm_debugfs_list, 
>> count);
>> -#else
>> -    return 0;
>>   #endif
>>   }
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
>> index 4df4cf2fd4dd..69ba8dd4f3ee 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
>> @@ -186,6 +186,6 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt 
>> *ttm, struct ttm_resource *mem);
>>   uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct 
>> ttm_tt *ttm,
>>                    struct ttm_resource *mem);
>>   -int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
>> +void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
>>     #endif
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] drm/amdgpu: do not use drm middle layer for debugfs
  2021-02-15 11:03     ` Nirmoy
@ 2021-02-15 11:20       ` Nirmoy
  0 siblings, 0 replies; 6+ messages in thread
From: Nirmoy @ 2021-02-15 11:20 UTC (permalink / raw)
  To: Christian König, Nirmoy Das; +Cc: amd-gfx


On 2/15/21 12:03 PM, Nirmoy wrote:
<snip>
>
>>> amdgpu_debugfs_autodump_init(adev);
>>> -
>>>       amdgpu_rap_debugfs_init(adev);
>>> -
>>>       amdgpu_securedisplay_debugfs_init(adev);
>>> -
>>>       amdgpu_fw_attestation_debugfs_init(adev);
>>>   -    return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,
>>> -                    ARRAY_SIZE(amdgpu_debugfs_list));
>>> +    debugfs_create_file("amdgpu_evict_vram", S_IFREG | S_IRUGO, 
>>> root, adev,
>>> +                &amdgpu_evict_vram_fops);
>>> +    debugfs_create_file("amdgpu_evict_gtt", S_IFREG | S_IRUGO, 
>>> root, adev,
>>> +                &amdgpu_evict_gtt_fops);
>>> +    debugfs_create_file("amdgpu_test_ib", S_IFREG | S_IRUGO, root, 
>>> adev,
>>> +                &amdgpu_debugfs_test_ib_fops);
>>> +    debugfs_create_file("amdgpu_vm_info", S_IFREG | S_IRUGO, root, 
>>> adev,
>>> +                &amdgpu_debugfs_vm_info_fops);
>>> +
>>> +    vbios = devm_kzalloc(adev_to_drm(adev)->dev, sizeof(*vbios), 
>>> GFP_KERNEL);
>>> +    if (!vbios)
>>> +        return -ENOMEM;
>>> +
>>> +    vbios->data = adev->bios;
>>> +    vbios->size = adev->bios_size;
>>> +    debugfs_create_blob("amdgpu_vbios", S_IFREG | S_IRUGO, root, 
>>> vbios);
>>
>> Is that vbios allocation ever freed? Maybe just change adev->bios and 
>> adev->bios_dize into a debugfs_blob_wrapper structure.
>
>
> devm_kzalloc will get freed on driver removal.


Sorry, this requires a devm_kfree() call at the end.


>
>>
>> Or at least keep the debugfs_blob_wrapper structure inside adev.


I will update with above suggestion.


Regards,

Nirmoy


>>
>>> +
>>> +    return 0;
>>>   }
>>>     #else
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
>>> index 2803884d338d..0ed866da865e 100644 
<snip>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-02-15 11:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 10:16 [PATCH 1/3] drm/amd/display: do not use drm middle layer for debugfs Nirmoy Das
2021-02-15 10:16 ` [PATCH 2/3] drm/amd/pm: " Nirmoy Das
2021-02-15 10:16 ` [PATCH 3/3] drm/amdgpu: " Nirmoy Das
2021-02-15 10:43   ` Christian König
2021-02-15 11:03     ` Nirmoy
2021-02-15 11:20       ` Nirmoy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.