v3d_debugfs.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* Copyright (C) 2014-2018 Broadcom */
  3. #include <linux/circ_buf.h>
  4. #include <linux/ctype.h>
  5. #include <linux/debugfs.h>
  6. #include <linux/seq_file.h>
  7. #include <linux/string_helpers.h>
  8. #include <drm/drm_debugfs.h>
  9. #include "v3d_drv.h"
  10. #include "v3d_regs.h"
  11. #define REGDEF(min_ver, max_ver, reg) { min_ver, max_ver, reg, #reg }
  12. struct v3d_reg_def {
  13. u32 min_ver;
  14. u32 max_ver;
  15. u32 reg;
  16. const char *name;
  17. };
  18. static const struct v3d_reg_def v3d_hub_reg_defs[] = {
  19. REGDEF(33, 42, V3D_HUB_AXICFG),
  20. REGDEF(33, 71, V3D_HUB_UIFCFG),
  21. REGDEF(33, 71, V3D_HUB_IDENT0),
  22. REGDEF(33, 71, V3D_HUB_IDENT1),
  23. REGDEF(33, 71, V3D_HUB_IDENT2),
  24. REGDEF(33, 71, V3D_HUB_IDENT3),
  25. REGDEF(33, 71, V3D_HUB_INT_STS),
  26. REGDEF(33, 71, V3D_HUB_INT_MSK_STS),
  27. REGDEF(33, 71, V3D_MMU_CTL),
  28. REGDEF(33, 71, V3D_MMU_VIO_ADDR),
  29. REGDEF(33, 71, V3D_MMU_VIO_ID),
  30. REGDEF(33, 71, V3D_MMU_DEBUG_INFO),
  31. REGDEF(71, 71, V3D_GMP_STATUS(71)),
  32. REGDEF(71, 71, V3D_GMP_CFG(71)),
  33. REGDEF(71, 71, V3D_GMP_VIO_ADDR(71)),
  34. };
  35. static const struct v3d_reg_def v3d_gca_reg_defs[] = {
  36. REGDEF(33, 33, V3D_GCA_SAFE_SHUTDOWN),
  37. REGDEF(33, 33, V3D_GCA_SAFE_SHUTDOWN_ACK),
  38. };
  39. static const struct v3d_reg_def v3d_core_reg_defs[] = {
  40. REGDEF(33, 71, V3D_CTL_IDENT0),
  41. REGDEF(33, 71, V3D_CTL_IDENT1),
  42. REGDEF(33, 71, V3D_CTL_IDENT2),
  43. REGDEF(33, 71, V3D_CTL_MISCCFG),
  44. REGDEF(33, 71, V3D_CTL_INT_STS),
  45. REGDEF(33, 71, V3D_CTL_INT_MSK_STS),
  46. REGDEF(33, 71, V3D_CLE_CT0CS),
  47. REGDEF(33, 71, V3D_CLE_CT0CA),
  48. REGDEF(33, 71, V3D_CLE_CT0EA),
  49. REGDEF(33, 71, V3D_CLE_CT1CS),
  50. REGDEF(33, 71, V3D_CLE_CT1CA),
  51. REGDEF(33, 71, V3D_CLE_CT1EA),
  52. REGDEF(33, 71, V3D_PTB_BPCA),
  53. REGDEF(33, 71, V3D_PTB_BPCS),
  54. REGDEF(33, 42, V3D_GMP_STATUS(33)),
  55. REGDEF(33, 42, V3D_GMP_CFG(33)),
  56. REGDEF(33, 42, V3D_GMP_VIO_ADDR(33)),
  57. REGDEF(33, 71, V3D_ERR_FDBGO),
  58. REGDEF(33, 71, V3D_ERR_FDBGB),
  59. REGDEF(33, 71, V3D_ERR_FDBGS),
  60. REGDEF(33, 71, V3D_ERR_STAT),
  61. };
  62. static const struct v3d_reg_def v3d_csd_reg_defs[] = {
  63. REGDEF(41, 71, V3D_CSD_STATUS),
  64. REGDEF(41, 42, V3D_CSD_CURRENT_CFG0(41)),
  65. REGDEF(41, 42, V3D_CSD_CURRENT_CFG1(41)),
  66. REGDEF(41, 42, V3D_CSD_CURRENT_CFG2(41)),
  67. REGDEF(41, 42, V3D_CSD_CURRENT_CFG3(41)),
  68. REGDEF(41, 42, V3D_CSD_CURRENT_CFG4(41)),
  69. REGDEF(41, 42, V3D_CSD_CURRENT_CFG5(41)),
  70. REGDEF(41, 42, V3D_CSD_CURRENT_CFG6(41)),
  71. REGDEF(71, 71, V3D_CSD_CURRENT_CFG0(71)),
  72. REGDEF(71, 71, V3D_CSD_CURRENT_CFG1(71)),
  73. REGDEF(71, 71, V3D_CSD_CURRENT_CFG2(71)),
  74. REGDEF(71, 71, V3D_CSD_CURRENT_CFG3(71)),
  75. REGDEF(71, 71, V3D_CSD_CURRENT_CFG4(71)),
  76. REGDEF(71, 71, V3D_CSD_CURRENT_CFG5(71)),
  77. REGDEF(71, 71, V3D_CSD_CURRENT_CFG6(71)),
  78. REGDEF(71, 71, V3D_V7_CSD_CURRENT_CFG7),
  79. };
  80. static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
  81. {
  82. struct drm_debugfs_entry *entry = m->private;
  83. struct drm_device *dev = entry->dev;
  84. struct v3d_dev *v3d = to_v3d_dev(dev);
  85. int i, core;
  86. for (i = 0; i < ARRAY_SIZE(v3d_hub_reg_defs); i++) {
  87. const struct v3d_reg_def *def = &v3d_hub_reg_defs[i];
  88. if (v3d->ver >= def->min_ver && v3d->ver <= def->max_ver) {
  89. seq_printf(m, "%s (0x%04x): 0x%08x\n",
  90. def->name, def->reg, V3D_READ(def->reg));
  91. }
  92. }
  93. for (i = 0; i < ARRAY_SIZE(v3d_gca_reg_defs); i++) {
  94. const struct v3d_reg_def *def = &v3d_gca_reg_defs[i];
  95. if (v3d->ver >= def->min_ver && v3d->ver <= def->max_ver) {
  96. seq_printf(m, "%s (0x%04x): 0x%08x\n",
  97. def->name, def->reg, V3D_GCA_READ(def->reg));
  98. }
  99. }
  100. for (core = 0; core < v3d->cores; core++) {
  101. for (i = 0; i < ARRAY_SIZE(v3d_core_reg_defs); i++) {
  102. const struct v3d_reg_def *def = &v3d_core_reg_defs[i];
  103. if (v3d->ver >= def->min_ver && v3d->ver <= def->max_ver) {
  104. seq_printf(m, "core %d %s (0x%04x): 0x%08x\n",
  105. core, def->name, def->reg,
  106. V3D_CORE_READ(core, def->reg));
  107. }
  108. }
  109. for (i = 0; i < ARRAY_SIZE(v3d_csd_reg_defs); i++) {
  110. const struct v3d_reg_def *def = &v3d_csd_reg_defs[i];
  111. if (v3d->ver >= def->min_ver && v3d->ver <= def->max_ver) {
  112. seq_printf(m, "core %d %s (0x%04x): 0x%08x\n",
  113. core, def->name, def->reg,
  114. V3D_CORE_READ(core, def->reg));
  115. }
  116. }
  117. }
  118. return 0;
  119. }
  120. static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)
  121. {
  122. struct drm_debugfs_entry *entry = m->private;
  123. struct drm_device *dev = entry->dev;
  124. struct v3d_dev *v3d = to_v3d_dev(dev);
  125. u32 ident0, ident1, ident2, ident3, cores;
  126. int core;
  127. ident0 = V3D_READ(V3D_HUB_IDENT0);
  128. ident1 = V3D_READ(V3D_HUB_IDENT1);
  129. ident2 = V3D_READ(V3D_HUB_IDENT2);
  130. ident3 = V3D_READ(V3D_HUB_IDENT3);
  131. cores = V3D_GET_FIELD(ident1, V3D_HUB_IDENT1_NCORES);
  132. seq_printf(m, "Revision: %d.%d.%d.%d\n",
  133. V3D_GET_FIELD(ident1, V3D_HUB_IDENT1_TVER),
  134. V3D_GET_FIELD(ident1, V3D_HUB_IDENT1_REV),
  135. V3D_GET_FIELD(ident3, V3D_HUB_IDENT3_IPREV),
  136. V3D_GET_FIELD(ident3, V3D_HUB_IDENT3_IPIDX));
  137. seq_printf(m, "MMU: %s\n",
  138. str_yes_no(ident2 & V3D_HUB_IDENT2_WITH_MMU));
  139. seq_printf(m, "TFU: %s\n",
  140. str_yes_no(ident1 & V3D_HUB_IDENT1_WITH_TFU));
  141. if (v3d->ver <= 42) {
  142. seq_printf(m, "TSY: %s\n",
  143. str_yes_no(ident1 & V3D_HUB_IDENT1_WITH_TSY));
  144. }
  145. seq_printf(m, "MSO: %s\n",
  146. str_yes_no(ident1 & V3D_HUB_IDENT1_WITH_MSO));
  147. seq_printf(m, "L3C: %s (%dkb)\n",
  148. str_yes_no(ident1 & V3D_HUB_IDENT1_WITH_L3C),
  149. V3D_GET_FIELD(ident2, V3D_HUB_IDENT2_L3C_NKB));
  150. for (core = 0; core < cores; core++) {
  151. u32 misccfg;
  152. u32 nslc, ntmu, qups;
  153. ident0 = V3D_CORE_READ(core, V3D_CTL_IDENT0);
  154. ident1 = V3D_CORE_READ(core, V3D_CTL_IDENT1);
  155. ident2 = V3D_CORE_READ(core, V3D_CTL_IDENT2);
  156. misccfg = V3D_CORE_READ(core, V3D_CTL_MISCCFG);
  157. nslc = V3D_GET_FIELD(ident1, V3D_IDENT1_NSLC);
  158. ntmu = V3D_GET_FIELD(ident1, V3D_IDENT1_NTMU);
  159. qups = V3D_GET_FIELD(ident1, V3D_IDENT1_QUPS);
  160. seq_printf(m, "Core %d:\n", core);
  161. seq_printf(m, " Revision: %d.%d\n",
  162. V3D_GET_FIELD(ident0, V3D_IDENT0_VER),
  163. V3D_GET_FIELD(ident1, V3D_IDENT1_REV));
  164. seq_printf(m, " Slices: %d\n", nslc);
  165. seq_printf(m, " TMUs: %d\n", nslc * ntmu);
  166. seq_printf(m, " QPUs: %d\n", nslc * qups);
  167. seq_printf(m, " Semaphores: %d\n",
  168. V3D_GET_FIELD(ident1, V3D_IDENT1_NSEM));
  169. if (v3d->ver <= 42) {
  170. seq_printf(m, " BCG int: %d\n",
  171. (ident2 & V3D_IDENT2_BCG_INT) != 0);
  172. }
  173. if (v3d->ver < 40) {
  174. seq_printf(m, " Override TMU: %d\n",
  175. (misccfg & V3D_MISCCFG_OVRTMUOUT) != 0);
  176. }
  177. }
  178. return 0;
  179. }
  180. static int v3d_debugfs_bo_stats(struct seq_file *m, void *unused)
  181. {
  182. struct drm_debugfs_entry *entry = m->private;
  183. struct drm_device *dev = entry->dev;
  184. struct v3d_dev *v3d = to_v3d_dev(dev);
  185. mutex_lock(&v3d->bo_lock);
  186. seq_printf(m, "allocated bos: %d\n",
  187. v3d->bo_stats.num_allocated);
  188. seq_printf(m, "allocated bo size (kb): %ld\n",
  189. (long)v3d->bo_stats.pages_allocated << (V3D_MMU_PAGE_SHIFT - 10));
  190. mutex_unlock(&v3d->bo_lock);
  191. return 0;
  192. }
  193. static int v3d_measure_clock(struct seq_file *m, void *unused)
  194. {
  195. struct drm_debugfs_entry *entry = m->private;
  196. struct drm_device *dev = entry->dev;
  197. struct v3d_dev *v3d = to_v3d_dev(dev);
  198. uint32_t cycles;
  199. int core = 0;
  200. int measure_ms = 1000;
  201. if (v3d->ver >= 40) {
  202. int cycle_count_reg = V3D_PCTR_CYCLE_COUNT(v3d->ver);
  203. V3D_CORE_WRITE(core, V3D_V4_PCTR_0_SRC_0_3,
  204. V3D_SET_FIELD_VER(cycle_count_reg,
  205. V3D_PCTR_S0, v3d->ver));
  206. V3D_CORE_WRITE(core, V3D_V4_PCTR_0_CLR, 1);
  207. V3D_CORE_WRITE(core, V3D_V4_PCTR_0_EN, 1);
  208. } else {
  209. V3D_CORE_WRITE(core, V3D_V3_PCTR_0_PCTRS0,
  210. V3D_PCTR_CYCLE_COUNT(v3d->ver));
  211. V3D_CORE_WRITE(core, V3D_V3_PCTR_0_CLR, 1);
  212. V3D_CORE_WRITE(core, V3D_V3_PCTR_0_EN,
  213. V3D_V3_PCTR_0_EN_ENABLE |
  214. 1);
  215. }
  216. msleep(measure_ms);
  217. cycles = V3D_CORE_READ(core, V3D_PCTR_0_PCTR0);
  218. seq_printf(m, "cycles: %d (%d.%d Mhz)\n",
  219. cycles,
  220. cycles / (measure_ms * 1000),
  221. (cycles / (measure_ms * 100)) % 10);
  222. return 0;
  223. }
  224. static int v3d_debugfs_mm(struct seq_file *m, void *unused)
  225. {
  226. struct drm_printer p = drm_seq_file_printer(m);
  227. struct drm_debugfs_entry *entry = m->private;
  228. struct drm_device *dev = entry->dev;
  229. struct v3d_dev *v3d = to_v3d_dev(dev);
  230. spin_lock(&v3d->mm_lock);
  231. drm_mm_print(&v3d->mm, &p);
  232. spin_unlock(&v3d->mm_lock);
  233. return 0;
  234. }
  235. static const struct drm_debugfs_info v3d_debugfs_list[] = {
  236. {"v3d_ident", v3d_v3d_debugfs_ident, 0},
  237. {"v3d_regs", v3d_v3d_debugfs_regs, 0},
  238. {"measure_clock", v3d_measure_clock, 0},
  239. {"bo_stats", v3d_debugfs_bo_stats, 0},
  240. {"v3d_mm", v3d_debugfs_mm, 0},
  241. };
  242. void
  243. v3d_debugfs_init(struct drm_minor *minor)
  244. {
  245. drm_debugfs_add_files(minor->dev, v3d_debugfs_list, ARRAY_SIZE(v3d_debugfs_list));
  246. }