Advertisement
Guest User

5.13-amdgpu-debugfs.patch

a guest
Sep 1st, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.16 KB | None | 0 0
  1. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
  2. index 264176a01e16..601f4ad844cb 100644
  3. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
  4. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
  5. @@ -823,7 +823,12 @@ struct amdgpu_device {
  6. bool accel_working;
  7. struct notifier_block acpi_nb;
  8. struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
  9. - struct debugfs_blob_wrapper debugfs_vbios_blob;
  10. + struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  11. + unsigned debugfs_count;
  12. +#if defined(CONFIG_DEBUG_FS)
  13. + struct dentry *debugfs_preempt;
  14. + struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  15. +#endif
  16. struct amdgpu_atif *atif;
  17. struct amdgpu_atcs atcs;
  18. struct mutex srbm_mutex;
  19. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
  20. index bcaf271b39bf..43059ead733b 100644
  21. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
  22. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
  23. @@ -28,6 +28,7 @@
  24. #include <linux/uaccess.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/poll.h>
  27. +#include <drm/drm_debugfs.h>
  28.  
  29. #include "amdgpu.h"
  30. #include "amdgpu_pm.h"
  31. @@ -37,6 +38,45 @@
  32. #include "amdgpu_securedisplay.h"
  33. #include "amdgpu_fw_attestation.h"
  34.  
  35. +/**
  36. + * amdgpu_debugfs_add_files - Add simple debugfs entries
  37. + *
  38. + * @adev: Device to attach debugfs entries to
  39. + * @files: Array of function callbacks that respond to reads
  40. + * @nfiles: Number of callbacks to register
  41. + *
  42. + */
  43. +int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
  44. + const struct drm_info_list *files,
  45. + unsigned nfiles)
  46. +{
  47. + unsigned i;
  48. +
  49. + for (i = 0; i < adev->debugfs_count; i++) {
  50. + if (adev->debugfs[i].files == files) {
  51. + /* Already registered */
  52. + return 0;
  53. + }
  54. + }
  55. +
  56. + i = adev->debugfs_count + 1;
  57. + if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
  58. + DRM_ERROR("Reached maximum number of debugfs components.\n");
  59. + DRM_ERROR("Report so we increase "
  60. + "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
  61. + return -EINVAL;
  62. + }
  63. + adev->debugfs[adev->debugfs_count].files = files;
  64. + adev->debugfs[adev->debugfs_count].num_files = nfiles;
  65. + adev->debugfs_count = i;
  66. +#if defined(CONFIG_DEBUG_FS)
  67. + drm_debugfs_create_files(files, nfiles,
  68. + adev_to_drm(adev)->primary->debugfs_root,
  69. + adev_to_drm(adev)->primary);
  70. +#endif
  71. + return 0;
  72. +}
  73. +
  74. int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev)
  75. {
  76. #if defined(CONFIG_DEBUG_FS)
  77. @@ -1188,20 +1228,22 @@ int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
  78. adev, debugfs_regs[i]);
  79. if (!i && !IS_ERR_OR_NULL(ent))
  80. i_size_write(ent->d_inode, adev->rmmio_size);
  81. + adev->debugfs_regs[i] = ent;
  82. }
  83.  
  84. return 0;
  85. }
  86.  
  87. -static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
  88. +static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
  89. {
  90. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  91. - struct drm_device *dev = adev_to_drm(adev);
  92. + struct drm_info_node *node = (struct drm_info_node *) m->private;
  93. + struct drm_device *dev = node->minor->dev;
  94. + struct amdgpu_device *adev = drm_to_adev(dev);
  95. int r = 0, i;
  96.  
  97. r = pm_runtime_get_sync(dev->dev);
  98. if (r < 0) {
  99. - pm_runtime_put_autosuspend(dev->dev);
  100. + pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  101. return r;
  102. }
  103.  
  104. @@ -1243,19 +1285,30 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
  105. return 0;
  106. }
  107.  
  108. -static int amdgpu_debugfs_evict_vram(void *data, u64 *val)
  109. +static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void *data)
  110. {
  111. - struct amdgpu_device *adev = (struct amdgpu_device *)data;
  112. - struct drm_device *dev = adev_to_drm(adev);
  113. + struct drm_info_node *node = (struct drm_info_node *) m->private;
  114. + struct drm_device *dev = node->minor->dev;
  115. + struct amdgpu_device *adev = drm_to_adev(dev);
  116. +
  117. + seq_write(m, adev->bios, adev->bios_size);
  118. + return 0;
  119. +}
  120. +
  121. +static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
  122. +{
  123. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  124. + struct drm_device *dev = node->minor->dev;
  125. + struct amdgpu_device *adev = drm_to_adev(dev);
  126. int r;
  127.  
  128. r = pm_runtime_get_sync(dev->dev);
  129. if (r < 0) {
  130. - pm_runtime_put_autosuspend(dev->dev);
  131. + pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  132. return r;
  133. }
  134.  
  135. - *val = amdgpu_bo_evict_vram(adev);
  136. + seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
  137.  
  138. pm_runtime_mark_last_busy(dev->dev);
  139. pm_runtime_put_autosuspend(dev->dev);
  140. @@ -1263,11 +1316,11 @@ static int amdgpu_debugfs_evict_vram(void *data, u64 *val)
  141. return 0;
  142. }
  143.  
  144. -
  145. -static int amdgpu_debugfs_evict_gtt(void *data, u64 *val)
  146. +static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
  147. {
  148. - struct amdgpu_device *adev = (struct amdgpu_device *)data;
  149. - struct drm_device *dev = adev_to_drm(adev);
  150. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  151. + struct drm_device *dev = node->minor->dev;
  152. + struct amdgpu_device *adev = drm_to_adev(dev);
  153. struct ttm_resource_manager *man;
  154. int r;
  155.  
  156. @@ -1278,7 +1331,8 @@ static int amdgpu_debugfs_evict_gtt(void *data, u64 *val)
  157. }
  158.  
  159. man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
  160. - *val = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
  161. + r = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
  162. + seq_printf(m, "(%d)\n", r);
  163.  
  164. pm_runtime_mark_last_busy(dev->dev);
  165. pm_runtime_put_autosuspend(dev->dev);
  166. @@ -1286,11 +1340,10 @@ static int amdgpu_debugfs_evict_gtt(void *data, u64 *val)
  167. return 0;
  168. }
  169.  
  170. -
  171. -static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused)
  172. +static int amdgpu_debugfs_vm_info(struct seq_file *m, void *data)
  173. {
  174. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  175. - struct drm_device *dev = adev_to_drm(adev);
  176. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  177. + struct drm_device *dev = node->minor->dev;
  178. struct drm_file *file;
  179. int r;
  180.  
  181. @@ -1316,12 +1369,13 @@ static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused)
  182. return r;
  183. }
  184.  
  185. -DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_test_ib);
  186. -DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_vm_info);
  187. -DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_vram_fops, amdgpu_debugfs_evict_vram,
  188. - NULL, "%lld\n");
  189. -DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_evict_gtt_fops, amdgpu_debugfs_evict_gtt,
  190. - NULL, "%lld\n");
  191. +static const struct drm_info_list amdgpu_debugfs_list[] = {
  192. + {"amdgpu_vbios", amdgpu_debugfs_get_vbios_dump},
  193. + {"amdgpu_test_ib", &amdgpu_debugfs_test_ib},
  194. + {"amdgpu_evict_vram", &amdgpu_debugfs_evict_vram},
  195. + {"amdgpu_evict_gtt", &amdgpu_debugfs_evict_gtt},
  196. + {"amdgpu_vm_info", &amdgpu_debugfs_vm_info},
  197. +};
  198.  
  199. static void amdgpu_ib_preempt_fences_swap(struct amdgpu_ring *ring,
  200. struct dma_fence **fences)
  201. @@ -1532,50 +1586,71 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
  202. return 0;
  203. }
  204.  
  205. -DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
  206. +DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
  207. amdgpu_debugfs_ib_preempt, "%llu\n");
  208.  
  209. -DEFINE_DEBUGFS_ATTRIBUTE(fops_sclk_set, NULL,
  210. +DEFINE_SIMPLE_ATTRIBUTE(fops_sclk_set, NULL,
  211. amdgpu_debugfs_sclk_set, "%llu\n");
  212.  
  213. int amdgpu_debugfs_init(struct amdgpu_device *adev)
  214. {
  215. - struct dentry *root = adev_to_drm(adev)->primary->debugfs_root;
  216. - struct dentry *ent;
  217. int r, i;
  218.  
  219. -
  220. -
  221. - ent = debugfs_create_file("amdgpu_preempt_ib", 0600, root, adev,
  222. - &fops_ib_preempt);
  223. - if (!ent) {
  224. + adev->debugfs_preempt =
  225. + debugfs_create_file("amdgpu_preempt_ib", 0600,
  226. + adev_to_drm(adev)->primary->debugfs_root, adev,
  227. + &fops_ib_preempt);
  228. + if (!(adev->debugfs_preempt)) {
  229. DRM_ERROR("unable to create amdgpu_preempt_ib debugsfs file\n");
  230. return -EIO;
  231. }
  232.  
  233. - ent = debugfs_create_file("amdgpu_force_sclk", 0200, root, adev,
  234. - &fops_sclk_set);
  235. - if (!ent) {
  236. + adev->smu.debugfs_sclk =
  237. + debugfs_create_file("amdgpu_force_sclk", 0200,
  238. + adev_to_drm(adev)->primary->debugfs_root, adev,
  239. + &fops_sclk_set);
  240. + if (!(adev->smu.debugfs_sclk)) {
  241. DRM_ERROR("unable to create amdgpu_set_sclk debugsfs file\n");
  242. return -EIO;
  243. }
  244.  
  245. /* Register debugfs entries for amdgpu_ttm */
  246. - amdgpu_ttm_debugfs_init(adev);
  247. - amdgpu_debugfs_pm_init(adev);
  248. - amdgpu_debugfs_sa_init(adev);
  249. - amdgpu_debugfs_fence_init(adev);
  250. - amdgpu_debugfs_gem_init(adev);
  251. + r = amdgpu_ttm_debugfs_init(adev);
  252. + if (r) {
  253. + DRM_ERROR("Failed to init debugfs\n");
  254. + return r;
  255. + }
  256. +
  257. + r = amdgpu_debugfs_pm_init(adev);
  258. + if (r) {
  259. + DRM_ERROR("Failed to register debugfs file for dpm!\n");
  260. + return r;
  261. + }
  262. +
  263. + if (amdgpu_debugfs_sa_init(adev)) {
  264. + dev_err(adev->dev, "failed to register debugfs file for SA\n");
  265. + }
  266. +
  267. + if (amdgpu_debugfs_fence_init(adev))
  268. + dev_err(adev->dev, "fence debugfs file creation failed\n");
  269. +
  270. + r = amdgpu_debugfs_gem_init(adev);
  271. + if (r)
  272. + DRM_ERROR("registering gem debugfs failed (%d).\n", r);
  273.  
  274. r = amdgpu_debugfs_regs_init(adev);
  275. if (r)
  276. DRM_ERROR("registering register debugfs failed (%d).\n", r);
  277.  
  278. - amdgpu_debugfs_firmware_init(adev);
  279. + r = amdgpu_debugfs_firmware_init(adev);
  280. + if (r)
  281. + DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
  282.  
  283. #if defined(CONFIG_DRM_AMD_DC)
  284. - if (amdgpu_device_has_dc_support(adev))
  285. - dtn_debugfs_init(adev);
  286. + if (amdgpu_device_has_dc_support(adev)) {
  287. + if (dtn_debugfs_init(adev))
  288. + DRM_ERROR("amdgpu: failed initialize dtn debugfs support.\n");
  289. + }
  290. #endif
  291.  
  292. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  293. @@ -1590,26 +1665,17 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
  294. }
  295.  
  296. amdgpu_ras_debugfs_create_all(adev);
  297. +
  298. amdgpu_debugfs_autodump_init(adev);
  299. +
  300. amdgpu_rap_debugfs_init(adev);
  301. - amdgpu_securedisplay_debugfs_init(adev);
  302. - amdgpu_fw_attestation_debugfs_init(adev);
  303.  
  304. - debugfs_create_file("amdgpu_evict_vram", 0444, root, adev,
  305. - &amdgpu_evict_vram_fops);
  306. - debugfs_create_file("amdgpu_evict_gtt", 0444, root, adev,
  307. - &amdgpu_evict_gtt_fops);
  308. - debugfs_create_file("amdgpu_test_ib", 0444, root, adev,
  309. - &amdgpu_debugfs_test_ib_fops);
  310. - debugfs_create_file("amdgpu_vm_info", 0444, root, adev,
  311. - &amdgpu_debugfs_vm_info_fops);
  312. + amdgpu_securedisplay_debugfs_init(adev);
  313.  
  314. - adev->debugfs_vbios_blob.data = adev->bios;
  315. - adev->debugfs_vbios_blob.size = adev->bios_size;
  316. - debugfs_create_blob("amdgpu_vbios", 0444, root,
  317. - &adev->debugfs_vbios_blob);
  318. + amdgpu_fw_attestation_debugfs_init(adev);
  319.  
  320. - return 0;
  321. + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,
  322. + ARRAY_SIZE(amdgpu_debugfs_list));
  323. }
  324.  
  325. #else
  326. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
  327. index 141a8474e24f..2803884d338d 100644
  328. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
  329. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
  330. @@ -26,6 +26,11 @@
  331. /*
  332. * Debugfs
  333. */
  334. +struct amdgpu_debugfs {
  335. + const struct drm_info_list *files;
  336. + unsigned num_files;
  337. +};
  338. +
  339. struct amdgpu_autodump {
  340. struct completion dumping;
  341. struct wait_queue_head gpu_hang;
  342. @@ -34,7 +39,10 @@ struct amdgpu_autodump {
  343. int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);
  344. int amdgpu_debugfs_init(struct amdgpu_device *adev);
  345. void amdgpu_debugfs_fini(struct amdgpu_device *adev);
  346. -void amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
  347. -void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
  348. -void amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
  349. +int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
  350. + const struct drm_info_list *files,
  351. + unsigned nfiles);
  352. +int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
  353. +int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
  354. +int amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
  355. int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev);
  356. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
  357. index 47ea46859618..669cc67409d2 100644
  358. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
  359. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
  360. @@ -36,6 +36,8 @@
  361. #include <linux/firmware.h>
  362. #include <linux/pm_runtime.h>
  363.  
  364. +#include <drm/drm_debugfs.h>
  365. +
  366. #include "amdgpu.h"
  367. #include "amdgpu_trace.h"
  368.  
  369. @@ -698,9 +700,11 @@ static const struct dma_fence_ops amdgpu_fence_ops = {
  370. * Fence debugfs
  371. */
  372. #if defined(CONFIG_DEBUG_FS)
  373. -static int amdgpu_debugfs_fence_info_show(struct seq_file *m, void *unused)
  374. +static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
  375. {
  376. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  377. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  378. + struct drm_device *dev = node->minor->dev;
  379. + struct amdgpu_device *adev = drm_to_adev(dev);
  380. int i;
  381.  
  382. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  383. @@ -745,10 +749,11 @@ static int amdgpu_debugfs_fence_info_show(struct seq_file *m, void *unused)
  384. *
  385. * Manually trigger a gpu reset at the next fence wait.
  386. */
  387. -static int gpu_recover_get(void *data, u64 *val)
  388. +static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
  389. {
  390. - struct amdgpu_device *adev = (struct amdgpu_device *)data;
  391. - struct drm_device *dev = adev_to_drm(adev);
  392. + struct drm_info_node *node = (struct drm_info_node *) m->private;
  393. + struct drm_device *dev = node->minor->dev;
  394. + struct amdgpu_device *adev = drm_to_adev(dev);
  395. int r;
  396.  
  397. r = pm_runtime_get_sync(dev->dev);
  398. @@ -757,7 +762,8 @@ static int gpu_recover_get(void *data, u64 *val)
  399. return 0;
  400. }
  401.  
  402. - *val = amdgpu_device_gpu_recover(adev, NULL);
  403. + seq_printf(m, "gpu recover\n");
  404. + amdgpu_device_gpu_recover(adev, NULL);
  405.  
  406. pm_runtime_mark_last_busy(dev->dev);
  407. pm_runtime_put_autosuspend(dev->dev);
  408. @@ -765,24 +771,26 @@ static int gpu_recover_get(void *data, u64 *val)
  409. return 0;
  410. }
  411.  
  412. -DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_fence_info);
  413. -DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gpu_recover_fops, gpu_recover_get, NULL,
  414. - "%lld\n");
  415. +static const struct drm_info_list amdgpu_debugfs_fence_list[] = {
  416. + {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
  417. + {"amdgpu_gpu_recover", &amdgpu_debugfs_gpu_recover, 0, NULL}
  418. +};
  419.  
  420. +static const struct drm_info_list amdgpu_debugfs_fence_list_sriov[] = {
  421. + {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
  422. +};
  423. #endif
  424.  
  425. -void amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
  426. +int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
  427. {
  428. #if defined(CONFIG_DEBUG_FS)
  429. - struct drm_minor *minor = adev_to_drm(adev)->primary;
  430. - struct dentry *root = minor->debugfs_root;
  431. -
  432. - debugfs_create_file("amdgpu_fence_info", 0444, root, adev,
  433. - &amdgpu_debugfs_fence_info_fops);
  434. -
  435. - if (!amdgpu_sriov_vf(adev))
  436. - debugfs_create_file("amdgpu_gpu_recover", 0444, root, adev,
  437. - &amdgpu_debugfs_gpu_recover_fops);
  438. + if (amdgpu_sriov_vf(adev))
  439. + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list_sriov,
  440. + ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
  441. + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
  442. + ARRAY_SIZE(amdgpu_debugfs_fence_list));
  443. +#else
  444. + return 0;
  445. #endif
  446. }
  447.  
  448. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
  449. index 311bcdc59eda..d3269b143ce1 100644
  450. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
  451. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
  452. @@ -32,6 +32,7 @@
  453. #include <linux/dma-buf.h>
  454.  
  455. #include <drm/amdgpu_drm.h>
  456. +#include <drm/drm_debugfs.h>
  457. #include <drm/drm_gem_ttm_helper.h>
  458.  
  459. #include "amdgpu.h"
  460. @@ -858,10 +859,10 @@ int amdgpu_mode_dumb_create(struct drm_file *file_priv,
  461. }
  462.  
  463. #if defined(CONFIG_DEBUG_FS)
  464. -static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)
  465. +static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
  466. {
  467. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  468. - struct drm_device *dev = adev_to_drm(adev);
  469. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  470. + struct drm_device *dev = node->minor->dev;
  471. struct drm_file *file;
  472. int r;
  473.  
  474. @@ -899,17 +900,16 @@ static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)
  475. return 0;
  476. }
  477.  
  478. -DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_gem_info);
  479. -
  480. +static const struct drm_info_list amdgpu_debugfs_gem_list[] = {
  481. + {"amdgpu_gem_info", &amdgpu_debugfs_gem_info, 0, NULL},
  482. +};
  483. #endif
  484.  
  485. -void amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
  486. +int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
  487. {
  488. #if defined(CONFIG_DEBUG_FS)
  489. - struct drm_minor *minor = adev_to_drm(adev)->primary;
  490. - struct dentry *root = minor->debugfs_root;
  491. -
  492. - debugfs_create_file("amdgpu_gem_info", 0444, root, adev,
  493. - &amdgpu_debugfs_gem_info_fops);
  494. + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
  495. + ARRAY_SIZE(amdgpu_debugfs_gem_list));
  496. #endif
  497. + return 0;
  498. }
  499. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
  500. index 98906a43fda3..7892958d5f59 100644
  501. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
  502. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
  503. @@ -30,6 +30,7 @@
  504. #include <linux/slab.h>
  505.  
  506. #include <drm/amdgpu_drm.h>
  507. +#include <drm/drm_debugfs.h>
  508.  
  509. #include "amdgpu.h"
  510. #include "atom.h"
  511. @@ -445,9 +446,11 @@ int amdgpu_ib_ring_tests(struct amdgpu_device *adev)
  512. */
  513. #if defined(CONFIG_DEBUG_FS)
  514.  
  515. -static int amdgpu_debugfs_sa_info_show(struct seq_file *m, void *unused)
  516. +static int amdgpu_debugfs_sa_info(struct seq_file *m, void *data)
  517. {
  518. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  519. + struct drm_info_node *node = (struct drm_info_node *) m->private;
  520. + struct drm_device *dev = node->minor->dev;
  521. + struct amdgpu_device *adev = drm_to_adev(dev);
  522.  
  523. seq_printf(m, "--------------------- DELAYED --------------------- \n");
  524. amdgpu_sa_bo_dump_debug_info(&adev->ib_pools[AMDGPU_IB_POOL_DELAYED],
  525. @@ -461,18 +464,18 @@ static int amdgpu_debugfs_sa_info_show(struct seq_file *m, void *unused)
  526. return 0;
  527. }
  528.  
  529. -DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_sa_info);
  530. +static const struct drm_info_list amdgpu_debugfs_sa_list[] = {
  531. + {"amdgpu_sa_info", &amdgpu_debugfs_sa_info, 0, NULL},
  532. +};
  533.  
  534. #endif
  535.  
  536. -void amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
  537. +int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
  538. {
  539. #if defined(CONFIG_DEBUG_FS)
  540. - struct drm_minor *minor = adev_to_drm(adev)->primary;
  541. - struct dentry *root = minor->debugfs_root;
  542. -
  543. - debugfs_create_file("amdgpu_sa_info", 0444, root, adev,
  544. - &amdgpu_debugfs_sa_info_fops);
  545. -
  546. + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
  547. + ARRAY_SIZE(amdgpu_debugfs_sa_list));
  548. +#else
  549. + return 0;
  550. #endif
  551. }
  552. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
  553. index 39ee88d29cca..09fc4244976e 100644
  554. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
  555. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
  556. @@ -27,6 +27,7 @@
  557. */
  558.  
  559. #include "amdgpu.h"
  560. +#include <drm/drm_debugfs.h>
  561. #include <drm/amdgpu_drm.h>
  562. #include "amdgpu_uvd.h"
  563. #include "amdgpu_vce.h"
  564. @@ -1330,9 +1331,11 @@ void amdgpu_disable_vblank_kms(struct drm_crtc *crtc)
  565. */
  566. #if defined(CONFIG_DEBUG_FS)
  567.  
  568. -static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
  569. +static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
  570. {
  571. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  572. + struct drm_info_node *node = (struct drm_info_node *) m->private;
  573. + struct drm_device *dev = node->minor->dev;
  574. + struct amdgpu_device *adev = drm_to_adev(dev);
  575. struct drm_amdgpu_info_firmware fw_info;
  576. struct drm_amdgpu_query_fw query_fw;
  577. struct atom_context *ctx = adev->mode_info.atom_context;
  578. @@ -1532,18 +1535,17 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
  579. return 0;
  580. }
  581.  
  582. -DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_firmware_info);
  583. -
  584. +static const struct drm_info_list amdgpu_firmware_info_list[] = {
  585. + {"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL},
  586. +};
  587. #endif
  588.  
  589. -void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
  590. +int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
  591. {
  592. #if defined(CONFIG_DEBUG_FS)
  593. - struct drm_minor *minor = adev_to_drm(adev)->primary;
  594. - struct dentry *root = minor->debugfs_root;
  595. -
  596. - debugfs_create_file("amdgpu_firmware_info", 0444, root,
  597. - adev, &amdgpu_debugfs_firmware_info_fops);
  598. -
  599. + return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list,
  600. + ARRAY_SIZE(amdgpu_firmware_info_list));
  601. +#else
  602. + return 0;
  603. #endif
  604. }
  605. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
  606. index 2d1fefbe1e99..68083e6fcc3e 100644
  607. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
  608. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
  609. @@ -337,7 +337,7 @@ void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager,
  610. struct seq_file *m);
  611. u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m);
  612. #endif
  613. -void amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
  614. +int amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
  615.  
  616. bool amdgpu_bo_support_uswc(u64 bo_flags);
  617.  
  618. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
  619. index b0d2fc9454ca..f1a7166823bc 100644
  620. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
  621. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
  622. @@ -1262,19 +1262,16 @@ static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
  623. *
  624. */
  625. /* debugfs begin */
  626. -static struct dentry *amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
  627. +static void amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
  628. {
  629. struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  630. - struct dentry *dir;
  631. struct drm_minor *minor = adev_to_drm(adev)->primary;
  632.  
  633. - dir = debugfs_create_dir(RAS_FS_NAME, minor->debugfs_root);
  634. - debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, dir, adev,
  635. - &amdgpu_ras_debugfs_ctrl_ops);
  636. - debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, dir, adev,
  637. - &amdgpu_ras_debugfs_eeprom_ops);
  638. - debugfs_create_u32("bad_page_cnt_threshold", 0444, dir,
  639. - &con->bad_page_cnt_threshold);
  640. + con->dir = debugfs_create_dir(RAS_FS_NAME, minor->debugfs_root);
  641. + debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, con->dir,
  642. + adev, &amdgpu_ras_debugfs_ctrl_ops);
  643. + debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, con->dir,
  644. + adev, &amdgpu_ras_debugfs_eeprom_ops);
  645.  
  646. /*
  647. * After one uncorrectable error happens, usually GPU recovery will
  648. @@ -1284,24 +1283,24 @@ static struct dentry *amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *
  649. * ERREVENT_ATHUB_INTERRUPT generated. Normal GPU recovery routine
  650. * will never be called.
  651. */
  652. - debugfs_create_bool("auto_reboot", S_IWUGO | S_IRUGO, dir, &con->reboot);
  653. + debugfs_create_bool("auto_reboot", S_IWUGO | S_IRUGO, con->dir,
  654. + &con->reboot);
  655.  
  656. /*
  657. * User could set this not to clean up hardware's error count register
  658. * of RAS IPs during ras recovery.
  659. */
  660. - debugfs_create_bool("disable_ras_err_cnt_harvest", 0644, dir,
  661. - &con->disable_ras_err_cnt_harvest);
  662. - return dir;
  663. + debugfs_create_bool("disable_ras_err_cnt_harvest", 0644,
  664. + con->dir, &con->disable_ras_err_cnt_harvest);
  665. }
  666.  
  667. static void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
  668. - struct ras_fs_if *head,
  669. - struct dentry *dir)
  670. + struct ras_fs_if *head)
  671. {
  672. + struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  673. struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
  674.  
  675. - if (!obj || !dir)
  676. + if (!obj || obj->ent)
  677. return;
  678.  
  679. get_obj(obj);
  680. @@ -1310,14 +1309,14 @@ static void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
  681. head->debugfs_name,
  682. sizeof(obj->fs_data.debugfs_name));
  683.  
  684. - debugfs_create_file(obj->fs_data.debugfs_name, S_IWUGO | S_IRUGO, dir,
  685. - obj, &amdgpu_ras_debugfs_ops);
  686. + obj->ent = debugfs_create_file(obj->fs_data.debugfs_name,
  687. + S_IWUGO | S_IRUGO, con->dir, obj,
  688. + &amdgpu_ras_debugfs_ops);
  689. }
  690.  
  691. void amdgpu_ras_debugfs_create_all(struct amdgpu_device *adev)
  692. {
  693. struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  694. - struct dentry *dir;
  695. struct ras_manager *obj;
  696. struct ras_fs_if fs_info;
  697.  
  698. @@ -1328,7 +1327,7 @@ void amdgpu_ras_debugfs_create_all(struct amdgpu_device *adev)
  699. if (!IS_ENABLED(CONFIG_DEBUG_FS) || !con)
  700. return;
  701.  
  702. - dir = amdgpu_ras_debugfs_create_ctrl_node(adev);
  703. + amdgpu_ras_debugfs_create_ctrl_node(adev);
  704.  
  705. list_for_each_entry(obj, &con->head, node) {
  706. if (amdgpu_ras_is_supported(adev, obj->head.block) &&
  707. @@ -1336,11 +1335,34 @@ void amdgpu_ras_debugfs_create_all(struct amdgpu_device *adev)
  708. sprintf(fs_info.debugfs_name, "%s_err_inject",
  709. ras_block_str(obj->head.block));
  710. fs_info.head = obj->head;
  711. - amdgpu_ras_debugfs_create(adev, &fs_info, dir);
  712. + amdgpu_ras_debugfs_create(adev, &fs_info);
  713. }
  714. }
  715. }
  716.  
  717. +static void amdgpu_ras_debugfs_remove(struct amdgpu_device *adev,
  718. + struct ras_common_if *head)
  719. +{
  720. + struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
  721. +
  722. + if (!obj || !obj->ent)
  723. + return;
  724. +
  725. + obj->ent = NULL;
  726. + put_obj(obj);
  727. +}
  728. +
  729. +static void amdgpu_ras_debugfs_remove_all(struct amdgpu_device *adev)
  730. +{
  731. + struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  732. + struct ras_manager *obj, *tmp;
  733. +
  734. + list_for_each_entry_safe(obj, tmp, &con->head, node) {
  735. + amdgpu_ras_debugfs_remove(adev, &obj->head);
  736. + }
  737. +
  738. + con->dir = NULL;
  739. +}
  740. /* debugfs end */
  741.  
  742. /* ras fs */
  743. @@ -1387,17 +1409,8 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
  744.  
  745. static int amdgpu_ras_fs_fini(struct amdgpu_device *adev)
  746. {
  747. - struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  748. - struct ras_manager *con_obj, *ip_obj, *tmp;
  749. -
  750. - if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  751. - list_for_each_entry_safe(con_obj, tmp, &con->head, node) {
  752. - ip_obj = amdgpu_ras_find_obj(adev, &con_obj->head);
  753. - if (ip_obj)
  754. - put_obj(ip_obj);
  755. - }
  756. - }
  757. -
  758. + if (IS_ENABLED(CONFIG_DEBUG_FS))
  759. + amdgpu_ras_debugfs_remove_all(adev);
  760. amdgpu_ras_sysfs_remove_all(adev);
  761. return 0;
  762. }
  763. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
  764. index 60df268a0c66..436b7b77fcb7 100644
  765. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
  766. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
  767. @@ -318,6 +318,8 @@ struct amdgpu_ras {
  768. uint32_t supported;
  769. uint32_t features;
  770. struct list_head head;
  771. + /* debugfs */
  772. + struct dentry *dir;
  773. /* sysfs */
  774. struct device_attribute features_attr;
  775. struct bin_attribute badpages_attr;
  776. @@ -393,6 +395,8 @@ struct ras_manager {
  777. struct list_head node;
  778. /* the device */
  779. struct amdgpu_device *adev;
  780. + /* debugfs */
  781. + struct dentry *ent;
  782. /* sysfs */
  783. struct device_attribute sysfs_attr;
  784. int attr_inuse;
  785. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
  786. index d5cbc51c5eaa..5245a7f565cd 100644
  787. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
  788. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
  789. @@ -47,6 +47,7 @@
  790. #include <drm/ttm/ttm_bo_driver.h>
  791. #include <drm/ttm/ttm_placement.h>
  792.  
  793. +#include <drm/drm_debugfs.h>
  794. #include <drm/amdgpu_drm.h>
  795.  
  796. #include "amdgpu.h"
  797. @@ -1615,7 +1616,7 @@ static void amdgpu_ttm_training_data_block_init(struct amdgpu_device *adev)
  798. (adev->gmc.mc_vram_size - GDDR6_MEM_TRAINING_OFFSET);
  799. ctx->train_data_size =
  800. GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES;
  801. -
  802. +
  803. DRM_DEBUG("train_data_size:%llx,p2c_train_data_offset:%llx,c2p_train_data_offset:%llx.\n",
  804. ctx->train_data_size,
  805. ctx->p2c_train_data_offset,
  806. @@ -2105,74 +2106,36 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
  807.  
  808. #if defined(CONFIG_DEBUG_FS)
  809.  
  810. -static int amdgpu_mm_vram_table_show(struct seq_file *m, void *unused)
  811. +static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
  812. {
  813. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  814. - struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
  815. - TTM_PL_VRAM);
  816. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  817. + unsigned ttm_pl = (uintptr_t)node->info_ent->data;
  818. + struct drm_device *dev = node->minor->dev;
  819. + struct amdgpu_device *adev = drm_to_adev(dev);
  820. + struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, ttm_pl);
  821. struct drm_printer p = drm_seq_file_printer(m);
  822.  
  823. man->func->debug(man, &p);
  824. return 0;
  825. }
  826.  
  827. -static int amdgpu_ttm_page_pool_show(struct seq_file *m, void *unused)
  828. +static int amdgpu_ttm_pool_debugfs(struct seq_file *m, void *data)
  829. {
  830. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  831. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  832. + struct drm_device *dev = node->minor->dev;
  833. + struct amdgpu_device *adev = drm_to_adev(dev);
  834.  
  835. return ttm_pool_debugfs(&adev->mman.bdev.pool, m);
  836. }
  837.  
  838. -static int amdgpu_mm_tt_table_show(struct seq_file *m, void *unused)
  839. -{
  840. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  841. - struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
  842. - TTM_PL_TT);
  843. - struct drm_printer p = drm_seq_file_printer(m);
  844. -
  845. - man->func->debug(man, &p);
  846. - return 0;
  847. -}
  848. -
  849. -static int amdgpu_mm_gds_table_show(struct seq_file *m, void *unused)
  850. -{
  851. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  852. - struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
  853. - AMDGPU_PL_GDS);
  854. - struct drm_printer p = drm_seq_file_printer(m);
  855. -
  856. - man->func->debug(man, &p);
  857. - return 0;
  858. -}
  859. -
  860. -static int amdgpu_mm_gws_table_show(struct seq_file *m, void *unused)
  861. -{
  862. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  863. - struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
  864. - AMDGPU_PL_GWS);
  865. - struct drm_printer p = drm_seq_file_printer(m);
  866. -
  867. - man->func->debug(man, &p);
  868. - return 0;
  869. -}
  870. -
  871. -static int amdgpu_mm_oa_table_show(struct seq_file *m, void *unused)
  872. -{
  873. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  874. - struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev,
  875. - AMDGPU_PL_OA);
  876. - struct drm_printer p = drm_seq_file_printer(m);
  877. -
  878. - man->func->debug(man, &p);
  879. - return 0;
  880. -}
  881. -
  882. -DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_vram_table);
  883. -DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_tt_table);
  884. -DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gds_table);
  885. -DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_gws_table);
  886. -DEFINE_SHOW_ATTRIBUTE(amdgpu_mm_oa_table);
  887. -DEFINE_SHOW_ATTRIBUTE(amdgpu_ttm_page_pool);
  888. +static const struct drm_info_list amdgpu_ttm_debugfs_list[] = {
  889. + {"amdgpu_vram_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_VRAM},
  890. + {"amdgpu_gtt_mm", amdgpu_mm_dump_table, 0, (void *)TTM_PL_TT},
  891. + {"amdgpu_gds_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GDS},
  892. + {"amdgpu_gws_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_GWS},
  893. + {"amdgpu_oa_mm", amdgpu_mm_dump_table, 0, (void *)AMDGPU_PL_OA},
  894. + {"ttm_page_pool", amdgpu_ttm_pool_debugfs, 0, NULL},
  895. +};
  896.  
  897. /*
  898. * amdgpu_ttm_vram_read - Linear read access to VRAM
  899. @@ -2374,29 +2337,46 @@ static const struct file_operations amdgpu_ttm_iomem_fops = {
  900. .llseek = default_llseek
  901. };
  902.  
  903. +static const struct {
  904. + char *name;
  905. + const struct file_operations *fops;
  906. + int domain;
  907. +} ttm_debugfs_entries[] = {
  908. + { "amdgpu_vram", &amdgpu_ttm_vram_fops, TTM_PL_VRAM },
  909. +#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
  910. + { "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT },
  911. +#endif
  912. + { "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
  913. +};
  914. +
  915. #endif
  916.  
  917. -void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
  918. +int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
  919. {
  920. #if defined(CONFIG_DEBUG_FS)
  921. + unsigned count;
  922. +
  923. struct drm_minor *minor = adev_to_drm(adev)->primary;
  924. - struct dentry *root = minor->debugfs_root;
  925. -
  926. - debugfs_create_file_size("amdgpu_vram", 0444, root, adev,
  927. - &amdgpu_ttm_vram_fops, adev->gmc.mc_vram_size);
  928. - debugfs_create_file("amdgpu_iomem", 0444, root, adev,
  929. - &amdgpu_ttm_iomem_fops);
  930. - debugfs_create_file("amdgpu_vram_mm", 0444, root, adev,
  931. - &amdgpu_mm_vram_table_fops);
  932. - debugfs_create_file("amdgpu_gtt_mm", 0444, root, adev,
  933. - &amdgpu_mm_tt_table_fops);
  934. - debugfs_create_file("amdgpu_gds_mm", 0444, root, adev,
  935. - &amdgpu_mm_gds_table_fops);
  936. - debugfs_create_file("amdgpu_gws_mm", 0444, root, adev,
  937. - &amdgpu_mm_gws_table_fops);
  938. - debugfs_create_file("amdgpu_oa_mm", 0444, root, adev,
  939. - &amdgpu_mm_oa_table_fops);
  940. - debugfs_create_file("ttm_page_pool", 0444, root, adev,
  941. - &amdgpu_ttm_page_pool_fops);
  942. + struct dentry *ent, *root = minor->debugfs_root;
  943. +
  944. + for (count = 0; count < ARRAY_SIZE(ttm_debugfs_entries); count++) {
  945. + ent = debugfs_create_file(
  946. + ttm_debugfs_entries[count].name,
  947. + S_IFREG | S_IRUGO, root,
  948. + adev,
  949. + ttm_debugfs_entries[count].fops);
  950. + if (IS_ERR(ent))
  951. + return PTR_ERR(ent);
  952. + if (ttm_debugfs_entries[count].domain == TTM_PL_VRAM)
  953. + i_size_write(ent->d_inode, adev->gmc.mc_vram_size);
  954. + else if (ttm_debugfs_entries[count].domain == TTM_PL_TT)
  955. + i_size_write(ent->d_inode, adev->gmc.gart_size);
  956. + adev->mman.debugfs_entries[count] = ent;
  957. + }
  958. +
  959. + count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
  960. + return amdgpu_debugfs_add_files(adev, amdgpu_ttm_debugfs_list, count);
  961. +#else
  962. + return 0;
  963. #endif
  964. }
  965. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
  966. index 9e38475e0f8d..af94527d0e9b 100644
  967. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
  968. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
  969. @@ -64,6 +64,10 @@ struct amdgpu_mman {
  970. bool initialized;
  971. void __iomem *aper_base_kaddr;
  972.  
  973. +#if defined(CONFIG_DEBUG_FS)
  974. + struct dentry *debugfs_entries[8];
  975. +#endif
  976. +
  977. /* buffer handling */
  978. const struct amdgpu_buffer_funcs *buffer_funcs;
  979. struct amdgpu_ring *buffer_funcs_ring;
  980. @@ -182,6 +186,6 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_resource *mem);
  981. uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
  982. struct ttm_resource *mem);
  983.  
  984. -void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
  985. +int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
  986.  
  987. #endif
  988. 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
  989. index 1b6b15708b96..c6e5f8d0308c 100644
  990. --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
  991. +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
  992. @@ -25,6 +25,8 @@
  993.  
  994. #include <linux/uaccess.h>
  995.  
  996. +#include <drm/drm_debugfs.h>
  997. +
  998. #include "dc.h"
  999. #include "amdgpu.h"
  1000. #include "amdgpu_dm.h"
  1001. @@ -2925,9 +2927,11 @@ static ssize_t dtn_log_write(
  1002. * As written to display, taking ABM and backlight lut into account.
  1003. * Ranges from 0x0 to 0x10000 (= 100% PWM)
  1004. */
  1005. -static int current_backlight_show(struct seq_file *m, void *unused)
  1006. +static int current_backlight_read(struct seq_file *m, void *data)
  1007. {
  1008. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  1009. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  1010. + struct drm_device *dev = node->minor->dev;
  1011. + struct amdgpu_device *adev = drm_to_adev(dev);
  1012. struct amdgpu_display_manager *dm = &adev->dm;
  1013.  
  1014. unsigned int backlight = dc_link_get_backlight_level(dm->backlight_link);
  1015. @@ -2941,9 +2945,11 @@ static int current_backlight_show(struct seq_file *m, void *unused)
  1016. * As written to display, taking ABM and backlight lut into account.
  1017. * Ranges from 0x0 to 0x10000 (= 100% PWM)
  1018. */
  1019. -static int target_backlight_show(struct seq_file *m, void *unused)
  1020. +static int target_backlight_read(struct seq_file *m, void *data)
  1021. {
  1022. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  1023. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  1024. + struct drm_device *dev = node->minor->dev;
  1025. + struct amdgpu_device *adev = drm_to_adev(dev);
  1026. struct amdgpu_display_manager *dm = &adev->dm;
  1027.  
  1028. unsigned int backlight = dc_link_get_target_backlight_pwm(dm->backlight_link);
  1029. @@ -2952,10 +2958,10 @@ static int target_backlight_show(struct seq_file *m, void *unused)
  1030. return 0;
  1031. }
  1032.  
  1033. -static int mst_topo_show(struct seq_file *m, void *unused)
  1034. +static int mst_topo(struct seq_file *m, void *unused)
  1035. {
  1036. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  1037. - struct drm_device *dev = adev_to_drm(adev);
  1038. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  1039. + struct drm_device *dev = node->minor->dev;
  1040. struct drm_connector *connector;
  1041. struct drm_connector_list_iter conn_iter;
  1042. struct amdgpu_dm_connector *aconnector;
  1043. @@ -2979,6 +2985,12 @@ static int mst_topo_show(struct seq_file *m, void *unused)
  1044. return 0;
  1045. }
  1046.  
  1047. +static const struct drm_info_list amdgpu_dm_debugfs_list[] = {
  1048. + {"amdgpu_current_backlight_pwm", &current_backlight_read},
  1049. + {"amdgpu_target_backlight_pwm", &target_backlight_read},
  1050. + {"amdgpu_mst_topology", &mst_topo},
  1051. +};
  1052. +
  1053. /*
  1054. * Sets trigger hpd for MST topologies.
  1055. * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
  1056. @@ -3134,9 +3146,6 @@ static int visual_confirm_get(void *data, u64 *val)
  1057. return 0;
  1058. }
  1059.  
  1060. -DEFINE_SHOW_ATTRIBUTE(current_backlight);
  1061. -DEFINE_SHOW_ATTRIBUTE(target_backlight);
  1062. -DEFINE_SHOW_ATTRIBUTE(mst_topo);
  1063. DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
  1064. visual_confirm_set, "%llu\n");
  1065.  
  1066. @@ -3198,7 +3207,7 @@ static int visual_confirm_get(void *data, u64 *val)
  1067. return result;
  1068. }
  1069.  
  1070. -void dtn_debugfs_init(struct amdgpu_device *adev)
  1071. +int dtn_debugfs_init(struct amdgpu_device *adev)
  1072. {
  1073. static const struct file_operations dtn_log_fops = {
  1074. .owner = THIS_MODULE,
  1075. @@ -3214,13 +3223,13 @@ void dtn_debugfs_init(struct amdgpu_device *adev)
  1076.  
  1077. struct drm_minor *minor = adev_to_drm(adev)->primary;
  1078. struct dentry *root = minor->debugfs_root;
  1079. + int ret;
  1080. +
  1081. + ret = amdgpu_debugfs_add_files(adev, amdgpu_dm_debugfs_list,
  1082. + ARRAY_SIZE(amdgpu_dm_debugfs_list));
  1083. + if (ret)
  1084. + return ret;
  1085.  
  1086. - debugfs_create_file("amdgpu_current_backlight_pwm", 0444,
  1087. - root, adev, &current_backlight_fops);
  1088. - debugfs_create_file("amdgpu_target_backlight_pwm", 0444,
  1089. - root, adev, &target_backlight_fops);
  1090. - debugfs_create_file("amdgpu_mst_topology", 0444, root,
  1091. - adev, &mst_topo_fops);
  1092. debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
  1093. &dtn_log_fops);
  1094.  
  1095. @@ -3236,16 +3245,8 @@ void dtn_debugfs_init(struct amdgpu_device *adev)
  1096. debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
  1097. adev, &force_timing_sync_ops);
  1098.  
  1099. - debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
  1100. - adev, &dmcub_trace_event_state_fops);
  1101. -
  1102. - debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
  1103. - adev, &trigger_hpd_mst_ops);
  1104. -
  1105. debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
  1106. &dcc_en_bits_fops);
  1107.  
  1108. - debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,
  1109. - &disable_hpd_ops);
  1110. -
  1111. + return 0;
  1112. }
  1113. 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
  1114. index 3366cb644053..cfe8aa2db5cc 100644
  1115. --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.h
  1116. +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.h
  1117. @@ -30,9 +30,9 @@
  1118. #include "amdgpu_dm.h"
  1119.  
  1120. void connector_debugfs_init(struct amdgpu_dm_connector *connector);
  1121. -void dtn_debugfs_init(struct amdgpu_device *adev);
  1122. #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
  1123. void crtc_debugfs_init(struct drm_crtc *crtc);
  1124. #endif
  1125. +int dtn_debugfs_init(struct amdgpu_device *adev);
  1126.  
  1127. #endif
  1128. diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
  1129. index 9a54066ec0af..f1a691b659f4 100644
  1130. --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
  1131. +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
  1132. @@ -23,6 +23,8 @@
  1133. * Alex Deucher <[email protected]>
  1134. */
  1135.  
  1136. +#include <drm/drm_debugfs.h>
  1137. +
  1138. #include "amdgpu.h"
  1139. #include "amdgpu_drv.h"
  1140. #include "amdgpu_pm.h"
  1141. @@ -3479,10 +3481,11 @@ static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
  1142. (flags & clocks[i].flag) ? "On" : "Off");
  1143. }
  1144.  
  1145. -static int amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
  1146. +static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
  1147. {
  1148. - struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
  1149. - struct drm_device *dev = adev_to_drm(adev);
  1150. + struct drm_info_node *node = (struct drm_info_node *) m->private;
  1151. + struct drm_device *dev = node->minor->dev;
  1152. + struct amdgpu_device *adev = drm_to_adev(dev);
  1153. u32 flags = 0;
  1154. int r;
  1155.  
  1156. @@ -3532,18 +3535,16 @@ static int amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
  1157. return r;
  1158. }
  1159.  
  1160. -DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_pm_info);
  1161. -
  1162. +static const struct drm_info_list amdgpu_pm_info_list[] = {
  1163. + {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
  1164. +};
  1165. #endif
  1166.  
  1167. -void amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
  1168. +int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
  1169. {
  1170. #if defined(CONFIG_DEBUG_FS)
  1171. - struct drm_minor *minor = adev_to_drm(adev)->primary;
  1172. - struct dentry *root = minor->debugfs_root;
  1173. -
  1174. - debugfs_create_file("amdgpu_pm_info", 0444, root, adev,
  1175. - &amdgpu_debugfs_pm_info_fops);
  1176. -
  1177. + return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));
  1178. +#else
  1179. + return 0;
  1180. #endif
  1181. }
  1182. diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h
  1183. index a920515e2274..45a22e101d15 100644
  1184. --- a/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h
  1185. +++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_pm.h
  1186. @@ -84,6 +84,6 @@ int amdgpu_pm_virt_sysfs_init(struct amdgpu_device *adev);
  1187. void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev);
  1188. void amdgpu_pm_virt_sysfs_fini(struct amdgpu_device *adev);
  1189.  
  1190. -void amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
  1191. +int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
  1192.  
  1193. #endif
  1194. diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
  1195. index 8bb224f6c762..c7b5578072fc 100644
  1196. --- a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
  1197. +++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
  1198. @@ -444,6 +444,9 @@ struct smu_context
  1199. struct smu_baco_context smu_baco;
  1200. struct smu_temperature_range thermal_range;
  1201. void *od_settings;
  1202. +#if defined(CONFIG_DEBUG_FS)
  1203. + struct dentry *debugfs_sclk;
  1204. +#endif
  1205.  
  1206. struct smu_umd_pstate_table pstate_table;
  1207. uint32_t pstate_sclk;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement