msm_debugfs.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Copyright (C) 2013-2016 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifdef CONFIG_DEBUG_FS
  18. #include <linux/debugfs.h>
  19. #include "msm_drv.h"
  20. #include "msm_gpu.h"
  21. #include "msm_kms.h"
  22. #include "msm_debugfs.h"
  23. struct msm_gpu_show_priv {
  24. struct msm_gpu_state *state;
  25. struct drm_device *dev;
  26. };
  27. static int msm_gpu_show(struct seq_file *m, void *arg)
  28. {
  29. struct drm_printer p = drm_seq_file_printer(m);
  30. struct msm_gpu_show_priv *show_priv = m->private;
  31. struct msm_drm_private *priv = show_priv->dev->dev_private;
  32. struct msm_gpu *gpu = priv->gpu;
  33. int ret;
  34. ret = mutex_lock_interruptible(&show_priv->dev->struct_mutex);
  35. if (ret)
  36. return ret;
  37. drm_printf(&p, "%s Status:\n", gpu->name);
  38. gpu->funcs->show(gpu, show_priv->state, &p);
  39. mutex_unlock(&show_priv->dev->struct_mutex);
  40. return 0;
  41. }
  42. static int msm_gpu_release(struct inode *inode, struct file *file)
  43. {
  44. struct seq_file *m = file->private_data;
  45. struct msm_gpu_show_priv *show_priv = m->private;
  46. struct msm_drm_private *priv = show_priv->dev->dev_private;
  47. struct msm_gpu *gpu = priv->gpu;
  48. int ret;
  49. ret = mutex_lock_interruptible(&show_priv->dev->struct_mutex);
  50. if (ret)
  51. return ret;
  52. gpu->funcs->gpu_state_put(show_priv->state);
  53. mutex_unlock(&show_priv->dev->struct_mutex);
  54. kfree(show_priv);
  55. return single_release(inode, file);
  56. }
  57. static int msm_gpu_open(struct inode *inode, struct file *file)
  58. {
  59. struct drm_device *dev = inode->i_private;
  60. struct msm_drm_private *priv = dev->dev_private;
  61. struct msm_gpu *gpu = priv->gpu;
  62. struct msm_gpu_show_priv *show_priv;
  63. int ret;
  64. if (!gpu)
  65. return -ENODEV;
  66. show_priv = kmalloc(sizeof(*show_priv), GFP_KERNEL);
  67. if (!show_priv)
  68. return -ENOMEM;
  69. ret = mutex_lock_interruptible(&dev->struct_mutex);
  70. if (ret)
  71. goto free_priv;
  72. pm_runtime_get_sync(&gpu->pdev->dev);
  73. show_priv->state = gpu->funcs->gpu_state_get(gpu);
  74. pm_runtime_put_sync(&gpu->pdev->dev);
  75. mutex_unlock(&dev->struct_mutex);
  76. if (IS_ERR(show_priv->state)) {
  77. ret = PTR_ERR(show_priv->state);
  78. goto free_priv;
  79. }
  80. show_priv->dev = dev;
  81. ret = single_open(file, msm_gpu_show, show_priv);
  82. if (ret)
  83. goto free_priv;
  84. return 0;
  85. free_priv:
  86. kfree(show_priv);
  87. return ret;
  88. }
  89. static const struct file_operations msm_gpu_fops = {
  90. .owner = THIS_MODULE,
  91. .open = msm_gpu_open,
  92. .read = seq_read,
  93. .llseek = seq_lseek,
  94. .release = msm_gpu_release,
  95. };
  96. static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
  97. {
  98. struct msm_drm_private *priv = dev->dev_private;
  99. struct msm_gpu *gpu = priv->gpu;
  100. if (gpu) {
  101. seq_printf(m, "Active Objects (%s):\n", gpu->name);
  102. msm_gem_describe_objects(&gpu->active_list, m);
  103. }
  104. seq_printf(m, "Inactive Objects:\n");
  105. msm_gem_describe_objects(&priv->inactive_list, m);
  106. return 0;
  107. }
  108. static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
  109. {
  110. struct drm_printer p = drm_seq_file_printer(m);
  111. drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
  112. return 0;
  113. }
  114. static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
  115. {
  116. struct msm_drm_private *priv = dev->dev_private;
  117. struct drm_framebuffer *fb, *fbdev_fb = NULL;
  118. if (priv->fbdev) {
  119. seq_printf(m, "fbcon ");
  120. fbdev_fb = priv->fbdev->fb;
  121. msm_framebuffer_describe(fbdev_fb, m);
  122. }
  123. mutex_lock(&dev->mode_config.fb_lock);
  124. list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
  125. if (fb == fbdev_fb)
  126. continue;
  127. seq_printf(m, "user ");
  128. msm_framebuffer_describe(fb, m);
  129. }
  130. mutex_unlock(&dev->mode_config.fb_lock);
  131. return 0;
  132. }
  133. static int show_locked(struct seq_file *m, void *arg)
  134. {
  135. struct drm_info_node *node = (struct drm_info_node *) m->private;
  136. struct drm_device *dev = node->minor->dev;
  137. int (*show)(struct drm_device *dev, struct seq_file *m) =
  138. node->info_ent->data;
  139. int ret;
  140. ret = mutex_lock_interruptible(&dev->struct_mutex);
  141. if (ret)
  142. return ret;
  143. ret = show(dev, m);
  144. mutex_unlock(&dev->struct_mutex);
  145. return ret;
  146. }
  147. static struct drm_info_list msm_debugfs_list[] = {
  148. {"gem", show_locked, 0, msm_gem_show},
  149. { "mm", show_locked, 0, msm_mm_show },
  150. { "fb", show_locked, 0, msm_fb_show },
  151. };
  152. static int late_init_minor(struct drm_minor *minor)
  153. {
  154. int ret;
  155. if (!minor)
  156. return 0;
  157. ret = msm_rd_debugfs_init(minor);
  158. if (ret) {
  159. dev_err(minor->dev->dev, "could not install rd debugfs\n");
  160. return ret;
  161. }
  162. ret = msm_perf_debugfs_init(minor);
  163. if (ret) {
  164. dev_err(minor->dev->dev, "could not install perf debugfs\n");
  165. return ret;
  166. }
  167. return 0;
  168. }
  169. int msm_debugfs_late_init(struct drm_device *dev)
  170. {
  171. int ret;
  172. ret = late_init_minor(dev->primary);
  173. if (ret)
  174. return ret;
  175. ret = late_init_minor(dev->render);
  176. return ret;
  177. }
  178. int msm_debugfs_init(struct drm_minor *minor)
  179. {
  180. struct drm_device *dev = minor->dev;
  181. struct msm_drm_private *priv = dev->dev_private;
  182. int ret;
  183. ret = drm_debugfs_create_files(msm_debugfs_list,
  184. ARRAY_SIZE(msm_debugfs_list),
  185. minor->debugfs_root, minor);
  186. if (ret) {
  187. dev_err(dev->dev, "could not install msm_debugfs_list\n");
  188. return ret;
  189. }
  190. debugfs_create_file("gpu", S_IRUSR, minor->debugfs_root,
  191. dev, &msm_gpu_fops);
  192. if (priv->kms->funcs->debugfs_init) {
  193. ret = priv->kms->funcs->debugfs_init(priv->kms, minor);
  194. if (ret)
  195. return ret;
  196. }
  197. return ret;
  198. }
  199. #endif