msm_debugfs.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2013-2016 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. */
  6. #ifdef CONFIG_DEBUG_FS
  7. #include <linux/debugfs.h>
  8. #include <linux/fault-inject.h>
  9. #include <drm/drm_debugfs.h>
  10. #include <drm/drm_fb_helper.h>
  11. #include <drm/drm_file.h>
  12. #include <drm/drm_framebuffer.h>
  13. #include "msm_drv.h"
  14. #include "msm_gpu.h"
  15. #include "msm_kms.h"
  16. #include "msm_debugfs.h"
  17. #include "disp/msm_disp_snapshot.h"
  18. /*
  19. * GPU Snapshot:
  20. */
  21. struct msm_gpu_show_priv {
  22. struct msm_gpu_state *state;
  23. struct drm_device *dev;
  24. };
  25. static int msm_gpu_show(struct seq_file *m, void *arg)
  26. {
  27. struct drm_printer p = drm_seq_file_printer(m);
  28. struct msm_gpu_show_priv *show_priv = m->private;
  29. struct msm_drm_private *priv = show_priv->dev->dev_private;
  30. struct msm_gpu *gpu = priv->gpu;
  31. int ret;
  32. ret = mutex_lock_interruptible(&gpu->lock);
  33. if (ret)
  34. return ret;
  35. drm_printf(&p, "%s Status:\n", gpu->name);
  36. gpu->funcs->show(gpu, show_priv->state, &p);
  37. mutex_unlock(&gpu->lock);
  38. return 0;
  39. }
  40. static int msm_gpu_release(struct inode *inode, struct file *file)
  41. {
  42. struct seq_file *m = file->private_data;
  43. struct msm_gpu_show_priv *show_priv = m->private;
  44. struct msm_drm_private *priv = show_priv->dev->dev_private;
  45. struct msm_gpu *gpu = priv->gpu;
  46. mutex_lock(&gpu->lock);
  47. gpu->funcs->gpu_state_put(show_priv->state);
  48. mutex_unlock(&gpu->lock);
  49. kfree(show_priv);
  50. return single_release(inode, file);
  51. }
  52. static int msm_gpu_open(struct inode *inode, struct file *file)
  53. {
  54. struct drm_device *dev = inode->i_private;
  55. struct msm_drm_private *priv = dev->dev_private;
  56. struct msm_gpu *gpu = priv->gpu;
  57. struct msm_gpu_show_priv *show_priv;
  58. int ret;
  59. if (!gpu || !gpu->funcs->gpu_state_get)
  60. return -ENODEV;
  61. show_priv = kmalloc(sizeof(*show_priv), GFP_KERNEL);
  62. if (!show_priv)
  63. return -ENOMEM;
  64. ret = mutex_lock_interruptible(&gpu->lock);
  65. if (ret)
  66. goto free_priv;
  67. pm_runtime_get_sync(&gpu->pdev->dev);
  68. msm_gpu_hw_init(gpu);
  69. show_priv->state = gpu->funcs->gpu_state_get(gpu);
  70. pm_runtime_put_sync(&gpu->pdev->dev);
  71. mutex_unlock(&gpu->lock);
  72. if (IS_ERR(show_priv->state)) {
  73. ret = PTR_ERR(show_priv->state);
  74. goto free_priv;
  75. }
  76. show_priv->dev = dev;
  77. ret = single_open(file, msm_gpu_show, show_priv);
  78. if (ret)
  79. goto free_priv;
  80. return 0;
  81. free_priv:
  82. kfree(show_priv);
  83. return ret;
  84. }
  85. static const struct file_operations msm_gpu_fops = {
  86. .owner = THIS_MODULE,
  87. .open = msm_gpu_open,
  88. .read = seq_read,
  89. .llseek = seq_lseek,
  90. .release = msm_gpu_release,
  91. };
  92. /*
  93. * Display Snapshot:
  94. */
  95. static int msm_kms_show(struct seq_file *m, void *arg)
  96. {
  97. struct drm_printer p = drm_seq_file_printer(m);
  98. struct msm_disp_state *state = m->private;
  99. msm_disp_state_print(state, &p);
  100. return 0;
  101. }
  102. static int msm_kms_release(struct inode *inode, struct file *file)
  103. {
  104. struct seq_file *m = file->private_data;
  105. struct msm_disp_state *state = m->private;
  106. msm_disp_state_free(state);
  107. return single_release(inode, file);
  108. }
  109. static int msm_kms_open(struct inode *inode, struct file *file)
  110. {
  111. struct drm_device *dev = inode->i_private;
  112. struct msm_drm_private *priv = dev->dev_private;
  113. struct msm_disp_state *state;
  114. int ret;
  115. if (!priv->kms)
  116. return -ENODEV;
  117. ret = mutex_lock_interruptible(&priv->kms->dump_mutex);
  118. if (ret)
  119. return ret;
  120. state = msm_disp_snapshot_state_sync(priv->kms);
  121. mutex_unlock(&priv->kms->dump_mutex);
  122. if (IS_ERR(state)) {
  123. return PTR_ERR(state);
  124. }
  125. ret = single_open(file, msm_kms_show, state);
  126. if (ret) {
  127. msm_disp_state_free(state);
  128. return ret;
  129. }
  130. return 0;
  131. }
  132. static const struct file_operations msm_kms_fops = {
  133. .owner = THIS_MODULE,
  134. .open = msm_kms_open,
  135. .read = seq_read,
  136. .llseek = seq_lseek,
  137. .release = msm_kms_release,
  138. };
  139. /*
  140. * Other debugfs:
  141. */
  142. static unsigned long last_shrink_freed;
  143. static int
  144. shrink_get(void *data, u64 *val)
  145. {
  146. *val = last_shrink_freed;
  147. return 0;
  148. }
  149. static int
  150. shrink_set(void *data, u64 val)
  151. {
  152. struct drm_device *dev = data;
  153. last_shrink_freed = msm_gem_shrinker_shrink(dev, val);
  154. return 0;
  155. }
  156. DEFINE_DEBUGFS_ATTRIBUTE(shrink_fops,
  157. shrink_get, shrink_set,
  158. "0x%08llx\n");
  159. static int msm_gem_show(struct seq_file *m, void *arg)
  160. {
  161. struct drm_info_node *node = m->private;
  162. struct drm_device *dev = node->minor->dev;
  163. struct msm_drm_private *priv = dev->dev_private;
  164. int ret;
  165. ret = mutex_lock_interruptible(&priv->obj_lock);
  166. if (ret)
  167. return ret;
  168. msm_gem_describe_objects(&priv->objects, m);
  169. mutex_unlock(&priv->obj_lock);
  170. return 0;
  171. }
  172. static int msm_mm_show(struct seq_file *m, void *arg)
  173. {
  174. struct drm_info_node *node = m->private;
  175. struct drm_device *dev = node->minor->dev;
  176. struct drm_printer p = drm_seq_file_printer(m);
  177. drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
  178. return 0;
  179. }
  180. static int msm_fb_show(struct seq_file *m, void *arg)
  181. {
  182. struct drm_info_node *node = m->private;
  183. struct drm_device *dev = node->minor->dev;
  184. struct drm_framebuffer *fb, *fbdev_fb = NULL;
  185. if (dev->fb_helper && dev->fb_helper->fb) {
  186. seq_printf(m, "fbcon ");
  187. fbdev_fb = dev->fb_helper->fb;
  188. msm_framebuffer_describe(fbdev_fb, m);
  189. }
  190. mutex_lock(&dev->mode_config.fb_lock);
  191. list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
  192. if (fb == fbdev_fb)
  193. continue;
  194. seq_printf(m, "user ");
  195. msm_framebuffer_describe(fb, m);
  196. }
  197. mutex_unlock(&dev->mode_config.fb_lock);
  198. return 0;
  199. }
  200. static struct drm_info_list msm_debugfs_list[] = {
  201. {"gem", msm_gem_show},
  202. { "mm", msm_mm_show },
  203. };
  204. static struct drm_info_list msm_kms_debugfs_list[] = {
  205. { "fb", msm_fb_show },
  206. };
  207. static int late_init_minor(struct drm_minor *minor)
  208. {
  209. int ret;
  210. if (!minor)
  211. return 0;
  212. ret = msm_rd_debugfs_init(minor);
  213. if (ret) {
  214. DRM_DEV_ERROR(minor->dev->dev, "could not install rd debugfs\n");
  215. return ret;
  216. }
  217. ret = msm_perf_debugfs_init(minor);
  218. if (ret) {
  219. DRM_DEV_ERROR(minor->dev->dev, "could not install perf debugfs\n");
  220. return ret;
  221. }
  222. return 0;
  223. }
  224. int msm_debugfs_late_init(struct drm_device *dev)
  225. {
  226. int ret;
  227. ret = late_init_minor(dev->primary);
  228. if (ret)
  229. return ret;
  230. ret = late_init_minor(dev->render);
  231. return ret;
  232. }
  233. static void msm_debugfs_gpu_init(struct drm_minor *minor)
  234. {
  235. struct drm_device *dev = minor->dev;
  236. struct msm_drm_private *priv = dev->dev_private;
  237. struct dentry *gpu_devfreq;
  238. debugfs_create_file("gpu", S_IRUSR, minor->debugfs_root,
  239. dev, &msm_gpu_fops);
  240. debugfs_create_u32("hangcheck_period_ms", 0600, minor->debugfs_root,
  241. &priv->hangcheck_period);
  242. debugfs_create_bool("disable_err_irq", 0600, minor->debugfs_root,
  243. &priv->disable_err_irq);
  244. gpu_devfreq = debugfs_create_dir("devfreq", minor->debugfs_root);
  245. debugfs_create_bool("idle_clamp",0600, gpu_devfreq,
  246. &priv->gpu_clamp_to_idle);
  247. debugfs_create_u32("upthreshold",0600, gpu_devfreq,
  248. &priv->gpu_devfreq_config.upthreshold);
  249. debugfs_create_u32("downdifferential",0600, gpu_devfreq,
  250. &priv->gpu_devfreq_config.downdifferential);
  251. }
  252. void msm_debugfs_init(struct drm_minor *minor)
  253. {
  254. struct drm_device *dev = minor->dev;
  255. struct msm_drm_private *priv = dev->dev_private;
  256. drm_debugfs_create_files(msm_debugfs_list,
  257. ARRAY_SIZE(msm_debugfs_list),
  258. minor->debugfs_root, minor);
  259. if (priv->gpu_pdev)
  260. msm_debugfs_gpu_init(minor);
  261. if (priv->kms) {
  262. drm_debugfs_create_files(msm_kms_debugfs_list,
  263. ARRAY_SIZE(msm_kms_debugfs_list),
  264. minor->debugfs_root, minor);
  265. debugfs_create_file("kms", S_IRUSR, minor->debugfs_root,
  266. dev, &msm_kms_fops);
  267. }
  268. debugfs_create_file("shrink", S_IRWXU, minor->debugfs_root,
  269. dev, &shrink_fops);
  270. if (priv->kms && priv->kms->funcs->debugfs_init)
  271. priv->kms->funcs->debugfs_init(priv->kms, minor);
  272. fault_create_debugfs_attr("fail_gem_alloc", minor->debugfs_root,
  273. &fail_gem_alloc);
  274. fault_create_debugfs_attr("fail_gem_iova", minor->debugfs_root,
  275. &fail_gem_iova);
  276. }
  277. #endif