drm_info.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /**
  2. * \file drm_info.c
  3. * DRM info file implementations
  4. *
  5. * \author Ben Gamari <bgamari@gmail.com>
  6. */
  7. /*
  8. * Created: Sun Dec 21 13:09:50 2008 by bgamari@gmail.com
  9. *
  10. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  11. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  12. * Copyright 2008 Ben Gamari <bgamari@gmail.com>
  13. * All Rights Reserved.
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a
  16. * copy of this software and associated documentation files (the "Software"),
  17. * to deal in the Software without restriction, including without limitation
  18. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  19. * and/or sell copies of the Software, and to permit persons to whom the
  20. * Software is furnished to do so, subject to the following conditions:
  21. *
  22. * The above copyright notice and this permission notice (including the next
  23. * paragraph) shall be included in all copies or substantial portions of the
  24. * Software.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  29. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  30. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  31. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  32. * OTHER DEALINGS IN THE SOFTWARE.
  33. */
  34. #include <linux/seq_file.h>
  35. #include <drm/drmP.h>
  36. /**
  37. * Called when "/proc/dri/.../name" is read.
  38. *
  39. * Prints the device name together with the bus id if available.
  40. */
  41. int drm_name_info(struct seq_file *m, void *data)
  42. {
  43. struct drm_info_node *node = (struct drm_info_node *) m->private;
  44. struct drm_minor *minor = node->minor;
  45. struct drm_device *dev = minor->dev;
  46. struct drm_master *master = minor->master;
  47. if (!master)
  48. return 0;
  49. if (master->unique) {
  50. seq_printf(m, "%s %s %s\n",
  51. dev->driver->name,
  52. dev_name(dev->dev), master->unique);
  53. } else {
  54. seq_printf(m, "%s %s\n",
  55. dev->driver->name, dev_name(dev->dev));
  56. }
  57. return 0;
  58. }
  59. /**
  60. * Called when "/proc/dri/.../vm" is read.
  61. *
  62. * Prints information about all mappings in drm_device::maplist.
  63. */
  64. int drm_vm_info(struct seq_file *m, void *data)
  65. {
  66. struct drm_info_node *node = (struct drm_info_node *) m->private;
  67. struct drm_device *dev = node->minor->dev;
  68. struct drm_local_map *map;
  69. struct drm_map_list *r_list;
  70. /* Hardcoded from _DRM_FRAME_BUFFER,
  71. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  72. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  73. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  74. const char *type;
  75. int i;
  76. mutex_lock(&dev->struct_mutex);
  77. seq_printf(m, "slot offset size type flags address mtrr\n\n");
  78. i = 0;
  79. list_for_each_entry(r_list, &dev->maplist, head) {
  80. map = r_list->map;
  81. if (!map)
  82. continue;
  83. if (map->type < 0 || map->type > 5)
  84. type = "??";
  85. else
  86. type = types[map->type];
  87. seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ",
  88. i,
  89. (unsigned long long)map->offset,
  90. map->size, type, map->flags,
  91. (unsigned long) r_list->user_token);
  92. if (map->mtrr < 0)
  93. seq_printf(m, "none\n");
  94. else
  95. seq_printf(m, "%4d\n", map->mtrr);
  96. i++;
  97. }
  98. mutex_unlock(&dev->struct_mutex);
  99. return 0;
  100. }
  101. /**
  102. * Called when "/proc/dri/.../bufs" is read.
  103. */
  104. int drm_bufs_info(struct seq_file *m, void *data)
  105. {
  106. struct drm_info_node *node = (struct drm_info_node *) m->private;
  107. struct drm_device *dev = node->minor->dev;
  108. struct drm_device_dma *dma;
  109. int i, seg_pages;
  110. mutex_lock(&dev->struct_mutex);
  111. dma = dev->dma;
  112. if (!dma) {
  113. mutex_unlock(&dev->struct_mutex);
  114. return 0;
  115. }
  116. seq_printf(m, " o size count free segs pages kB\n\n");
  117. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  118. if (dma->bufs[i].buf_count) {
  119. seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
  120. seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
  121. i,
  122. dma->bufs[i].buf_size,
  123. dma->bufs[i].buf_count,
  124. atomic_read(&dma->bufs[i].freelist.count),
  125. dma->bufs[i].seg_count,
  126. seg_pages,
  127. seg_pages * PAGE_SIZE / 1024);
  128. }
  129. }
  130. seq_printf(m, "\n");
  131. for (i = 0; i < dma->buf_count; i++) {
  132. if (i && !(i % 32))
  133. seq_printf(m, "\n");
  134. seq_printf(m, " %d", dma->buflist[i]->list);
  135. }
  136. seq_printf(m, "\n");
  137. mutex_unlock(&dev->struct_mutex);
  138. return 0;
  139. }
  140. /**
  141. * Called when "/proc/dri/.../vblank" is read.
  142. */
  143. int drm_vblank_info(struct seq_file *m, void *data)
  144. {
  145. struct drm_info_node *node = (struct drm_info_node *) m->private;
  146. struct drm_device *dev = node->minor->dev;
  147. int crtc;
  148. mutex_lock(&dev->struct_mutex);
  149. for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
  150. seq_printf(m, "CRTC %d enable: %d\n",
  151. crtc, atomic_read(&dev->vblank[crtc].refcount));
  152. seq_printf(m, "CRTC %d counter: %d\n",
  153. crtc, drm_vblank_count(dev, crtc));
  154. seq_printf(m, "CRTC %d last wait: %d\n",
  155. crtc, dev->vblank[crtc].last_wait);
  156. seq_printf(m, "CRTC %d in modeset: %d\n",
  157. crtc, dev->vblank[crtc].inmodeset);
  158. }
  159. mutex_unlock(&dev->struct_mutex);
  160. return 0;
  161. }
  162. /**
  163. * Called when "/proc/dri/.../clients" is read.
  164. *
  165. */
  166. int drm_clients_info(struct seq_file *m, void *data)
  167. {
  168. struct drm_info_node *node = (struct drm_info_node *) m->private;
  169. struct drm_device *dev = node->minor->dev;
  170. struct drm_file *priv;
  171. mutex_lock(&dev->struct_mutex);
  172. seq_printf(m, "a dev pid uid magic\n\n");
  173. list_for_each_entry(priv, &dev->filelist, lhead) {
  174. seq_printf(m, "%c %3d %5d %5d %10u\n",
  175. priv->authenticated ? 'y' : 'n',
  176. priv->minor->index,
  177. pid_vnr(priv->pid),
  178. from_kuid_munged(seq_user_ns(m), priv->uid),
  179. priv->magic);
  180. }
  181. mutex_unlock(&dev->struct_mutex);
  182. return 0;
  183. }
  184. static int drm_gem_one_name_info(int id, void *ptr, void *data)
  185. {
  186. struct drm_gem_object *obj = ptr;
  187. struct seq_file *m = data;
  188. seq_printf(m, "%6d %8zd %7d %8d\n",
  189. obj->name, obj->size,
  190. obj->handle_count,
  191. atomic_read(&obj->refcount.refcount));
  192. return 0;
  193. }
  194. int drm_gem_name_info(struct seq_file *m, void *data)
  195. {
  196. struct drm_info_node *node = (struct drm_info_node *) m->private;
  197. struct drm_device *dev = node->minor->dev;
  198. seq_printf(m, " name size handles refcount\n");
  199. mutex_lock(&dev->object_name_lock);
  200. idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
  201. mutex_unlock(&dev->object_name_lock);
  202. return 0;
  203. }
  204. #if DRM_DEBUG_CODE
  205. int drm_vma_info(struct seq_file *m, void *data)
  206. {
  207. struct drm_info_node *node = (struct drm_info_node *) m->private;
  208. struct drm_device *dev = node->minor->dev;
  209. struct drm_vma_entry *pt;
  210. struct vm_area_struct *vma;
  211. unsigned long vma_count = 0;
  212. #if defined(__i386__)
  213. unsigned int pgprot;
  214. #endif
  215. mutex_lock(&dev->struct_mutex);
  216. list_for_each_entry(pt, &dev->vmalist, head)
  217. vma_count++;
  218. seq_printf(m, "vma use count: %lu, high_memory = %pK, 0x%pK\n",
  219. vma_count, high_memory,
  220. (void *)(unsigned long)virt_to_phys(high_memory));
  221. list_for_each_entry(pt, &dev->vmalist, head) {
  222. vma = pt->vma;
  223. if (!vma)
  224. continue;
  225. seq_printf(m,
  226. "\n%5d 0x%pK-0x%pK %c%c%c%c%c%c 0x%08lx000",
  227. pt->pid,
  228. (void *)vma->vm_start, (void *)vma->vm_end,
  229. vma->vm_flags & VM_READ ? 'r' : '-',
  230. vma->vm_flags & VM_WRITE ? 'w' : '-',
  231. vma->vm_flags & VM_EXEC ? 'x' : '-',
  232. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  233. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  234. vma->vm_flags & VM_IO ? 'i' : '-',
  235. vma->vm_pgoff);
  236. #if defined(__i386__)
  237. pgprot = pgprot_val(vma->vm_page_prot);
  238. seq_printf(m, " %c%c%c%c%c%c%c%c%c",
  239. pgprot & _PAGE_PRESENT ? 'p' : '-',
  240. pgprot & _PAGE_RW ? 'w' : 'r',
  241. pgprot & _PAGE_USER ? 'u' : 's',
  242. pgprot & _PAGE_PWT ? 't' : 'b',
  243. pgprot & _PAGE_PCD ? 'u' : 'c',
  244. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  245. pgprot & _PAGE_DIRTY ? 'd' : '-',
  246. pgprot & _PAGE_PSE ? 'm' : 'k',
  247. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  248. #endif
  249. seq_printf(m, "\n");
  250. }
  251. mutex_unlock(&dev->struct_mutex);
  252. return 0;
  253. }
  254. #endif