msm_debugfs.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. mutex_lock(&show_priv->dev->struct_mutex);
  49. gpu->funcs->gpu_state_put(show_priv->state);
  50. mutex_unlock(&show_priv->dev->struct_mutex);
  51. kfree(show_priv);
  52. return single_release(inode, file);
  53. }
  54. static int msm_gpu_open(struct inode *inode, struct file *file)
  55. {
  56. struct drm_device *dev = inode->i_private;
  57. struct msm_drm_private *priv = dev->dev_private;
  58. struct msm_gpu *gpu = priv->gpu;
  59. struct msm_gpu_show_priv *show_priv;
  60. int ret;
  61. if (!gpu)
  62. return -ENODEV;
  63. show_priv = kmalloc(sizeof(*show_priv), GFP_KERNEL);
  64. if (!show_priv)
  65. return -ENOMEM;
  66. ret = mutex_lock_interruptible(&dev->struct_mutex);
  67. if (ret)
  68. goto free_priv;
  69. pm_runtime_get_sync(&gpu->pdev->dev);
  70. show_priv->state = gpu->funcs->gpu_state_get(gpu);
  71. pm_runtime_put_sync(&gpu->pdev->dev);
  72. mutex_unlock(&dev->struct_mutex);
  73. if (IS_ERR(show_priv->state)) {
  74. ret = PTR_ERR(show_priv->state);
  75. goto free_priv;
  76. }
  77. show_priv->dev = dev;
  78. ret = single_open(file, msm_gpu_show, show_priv);
  79. if (ret)
  80. goto free_priv;
  81. return 0;
  82. free_priv:
  83. kfree(show_priv);
  84. return ret;
  85. }
  86. static const struct file_operations msm_gpu_fops = {
  87. .owner = THIS_MODULE,
  88. .open = msm_gpu_open,
  89. .read = seq_read,
  90. .llseek = seq_lseek,
  91. .release = msm_gpu_release,
  92. };
  93. static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
  94. {
  95. struct msm_drm_private *priv = dev->dev_private;
  96. struct msm_gpu *gpu = priv->gpu;
  97. if (gpu) {
  98. seq_printf(m, "Active Objects (%s):\n", gpu->name);
  99. msm_gem_describe_objects(&gpu->active_list, m);
  100. }
  101. seq_printf(m, "Inactive Objects:\n");
  102. msm_gem_describe_objects(&priv->inactive_list, m);
  103. return 0;
  104. }
  105. static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
  106. {
  107. struct drm_printer p = drm_seq_file_printer(m);
  108. drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
  109. return 0;
  110. }
  111. static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
  112. {
  113. struct msm_drm_private *priv = dev->dev_private;
  114. struct drm_framebuffer *fb, *fbdev_fb = NULL;
  115. if (priv->fbdev) {
  116. seq_printf(m, "fbcon ");
  117. fbdev_fb = priv->fbdev->fb;
  118. msm_framebuffer_describe(fbdev_fb, m);
  119. }
  120. mutex_lock(&dev->mode_config.fb_lock);
  121. list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
  122. if (fb == fbdev_fb)
  123. continue;
  124. seq_printf(m, "user ");
  125. msm_framebuffer_describe(fb, m);
  126. }
  127. mutex_unlock(&dev->mode_config.fb_lock);
  128. return 0;
  129. }
  130. static int show_locked(struct seq_file *m, void *arg)
  131. {
  132. struct drm_info_node *node = (struct drm_info_node *) m->private;
  133. struct drm_device *dev = node->minor->dev;
  134. int (*show)(struct drm_device *dev, struct seq_file *m) =
  135. node->info_ent->data;
  136. int ret;
  137. ret = mutex_lock_interruptible(&dev->struct_mutex);
  138. if (ret)
  139. return ret;
  140. ret = show(dev, m);
  141. mutex_unlock(&dev->struct_mutex);
  142. return ret;
  143. }
  144. static struct drm_info_list msm_debugfs_list[] = {
  145. {"gem", show_locked, 0, msm_gem_show},
  146. { "mm", show_locked, 0, msm_mm_show },
  147. { "fb", show_locked, 0, msm_fb_show },
  148. };
  149. static int late_init_minor(struct drm_minor *minor)
  150. {
  151. int ret;
  152. if (!minor)
  153. return 0;
  154. ret = msm_rd_debugfs_init(minor);
  155. if (ret) {
  156. dev_err(minor->dev->dev, "could not install rd debugfs\n");
  157. return ret;
  158. }
  159. ret = msm_perf_debugfs_init(minor);
  160. if (ret) {
  161. dev_err(minor->dev->dev, "could not install perf debugfs\n");
  162. return ret;
  163. }
  164. return 0;
  165. }
  166. int msm_debugfs_late_init(struct drm_device *dev)
  167. {
  168. int ret;
  169. ret = late_init_minor(dev->primary);
  170. if (ret)
  171. return ret;
  172. ret = late_init_minor(dev->render);
  173. return ret;
  174. }
  175. int msm_debugfs_init(struct drm_minor *minor)
  176. {
  177. struct drm_device *dev = minor->dev;
  178. struct msm_drm_private *priv = dev->dev_private;
  179. int ret;
  180. ret = drm_debugfs_create_files(msm_debugfs_list,
  181. ARRAY_SIZE(msm_debugfs_list),
  182. minor->debugfs_root, minor);
  183. if (ret) {
  184. dev_err(dev->dev, "could not install msm_debugfs_list\n");
  185. return ret;
  186. }
  187. debugfs_create_file("gpu", S_IRUSR, minor->debugfs_root,
  188. dev, &msm_gpu_fops);
  189. if (priv->kms->funcs->debugfs_init) {
  190. ret = priv->kms->funcs->debugfs_init(priv->kms, minor);
  191. if (ret)
  192. return ret;
  193. }
  194. return ret;
  195. }
  196. #endif