drm_info.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 "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. const char *bus_name;
  48. if (!master)
  49. return 0;
  50. bus_name = dev->driver->bus->get_name(dev);
  51. if (master->unique) {
  52. seq_printf(m, "%s %s %s\n",
  53. bus_name,
  54. dev_name(dev->dev), master->unique);
  55. } else {
  56. seq_printf(m, "%s %s\n",
  57. bus_name, dev_name(dev->dev));
  58. }
  59. return 0;
  60. }
  61. /**
  62. * Called when "/proc/dri/.../vm" is read.
  63. *
  64. * Prints information about all mappings in drm_device::maplist.
  65. */
  66. int drm_vm_info(struct seq_file *m, void *data)
  67. {
  68. struct drm_info_node *node = (struct drm_info_node *) m->private;
  69. struct drm_device *dev = node->minor->dev;
  70. struct drm_local_map *map;
  71. struct drm_map_list *r_list;
  72. /* Hardcoded from _DRM_FRAME_BUFFER,
  73. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  74. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  75. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  76. const char *type;
  77. int i;
  78. mutex_lock(&dev->struct_mutex);
  79. seq_printf(m, "slot offset size type flags address mtrr\n\n");
  80. i = 0;
  81. list_for_each_entry(r_list, &dev->maplist, head) {
  82. map = r_list->map;
  83. if (!map)
  84. continue;
  85. if (map->type < 0 || map->type > 5)
  86. type = "??";
  87. else
  88. type = types[map->type];
  89. seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ",
  90. i,
  91. (unsigned long long)map->offset,
  92. map->size, type, map->flags,
  93. (unsigned long) r_list->user_token);
  94. if (map->mtrr < 0)
  95. seq_printf(m, "none\n");
  96. else
  97. seq_printf(m, "%4d\n", map->mtrr);
  98. i++;
  99. }
  100. mutex_unlock(&dev->struct_mutex);
  101. return 0;
  102. }
  103. /**
  104. * Called when "/proc/dri/.../bufs" is read.
  105. */
  106. int drm_bufs_info(struct seq_file *m, void *data)
  107. {
  108. struct drm_info_node *node = (struct drm_info_node *) m->private;
  109. struct drm_device *dev = node->minor->dev;
  110. struct drm_device_dma *dma;
  111. int i, seg_pages;
  112. mutex_lock(&dev->struct_mutex);
  113. dma = dev->dma;
  114. if (!dma) {
  115. mutex_unlock(&dev->struct_mutex);
  116. return 0;
  117. }
  118. seq_printf(m, " o size count free segs pages kB\n\n");
  119. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  120. if (dma->bufs[i].buf_count) {
  121. seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
  122. seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
  123. i,
  124. dma->bufs[i].buf_size,
  125. dma->bufs[i].buf_count,
  126. atomic_read(&dma->bufs[i].freelist.count),
  127. dma->bufs[i].seg_count,
  128. seg_pages,
  129. seg_pages * PAGE_SIZE / 1024);
  130. }
  131. }
  132. seq_printf(m, "\n");
  133. for (i = 0; i < dma->buf_count; i++) {
  134. if (i && !(i % 32))
  135. seq_printf(m, "\n");
  136. seq_printf(m, " %d", dma->buflist[i]->list);
  137. }
  138. seq_printf(m, "\n");
  139. mutex_unlock(&dev->struct_mutex);
  140. return 0;
  141. }
  142. /**
  143. * Called when "/proc/dri/.../vblank" is read.
  144. */
  145. int drm_vblank_info(struct seq_file *m, void *data)
  146. {
  147. struct drm_info_node *node = (struct drm_info_node *) m->private;
  148. struct drm_device *dev = node->minor->dev;
  149. int crtc;
  150. mutex_lock(&dev->struct_mutex);
  151. for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
  152. seq_printf(m, "CRTC %d enable: %d\n",
  153. crtc, atomic_read(&dev->vblank_refcount[crtc]));
  154. seq_printf(m, "CRTC %d counter: %d\n",
  155. crtc, drm_vblank_count(dev, crtc));
  156. seq_printf(m, "CRTC %d last wait: %d\n",
  157. crtc, dev->last_vblank_wait[crtc]);
  158. seq_printf(m, "CRTC %d in modeset: %d\n",
  159. crtc, dev->vblank_inmodeset[crtc]);
  160. }
  161. mutex_unlock(&dev->struct_mutex);
  162. return 0;
  163. }
  164. /**
  165. * Called when "/proc/dri/.../clients" is read.
  166. *
  167. */
  168. int drm_clients_info(struct seq_file *m, void *data)
  169. {
  170. struct drm_info_node *node = (struct drm_info_node *) m->private;
  171. struct drm_device *dev = node->minor->dev;
  172. struct drm_file *priv;
  173. mutex_lock(&dev->struct_mutex);
  174. seq_printf(m, "a dev pid uid magic ioctls\n\n");
  175. list_for_each_entry(priv, &dev->filelist, lhead) {
  176. seq_printf(m, "%c %3d %5d %5d %10u %10lu\n",
  177. priv->authenticated ? 'y' : 'n',
  178. priv->minor->index,
  179. priv->pid,
  180. priv->uid, priv->magic, priv->ioctl_count);
  181. }
  182. mutex_unlock(&dev->struct_mutex);
  183. return 0;
  184. }
  185. static int drm_gem_one_name_info(int id, void *ptr, void *data)
  186. {
  187. struct drm_gem_object *obj = ptr;
  188. struct seq_file *m = data;
  189. seq_printf(m, "name %d size %zd\n", obj->name, obj->size);
  190. seq_printf(m, "%6d %8zd %7d %8d\n",
  191. obj->name, obj->size,
  192. atomic_read(&obj->handle_count),
  193. atomic_read(&obj->refcount.refcount));
  194. return 0;
  195. }
  196. int drm_gem_name_info(struct seq_file *m, void *data)
  197. {
  198. struct drm_info_node *node = (struct drm_info_node *) m->private;
  199. struct drm_device *dev = node->minor->dev;
  200. seq_printf(m, " name size handles refcount\n");
  201. idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
  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. #if defined(__i386__)
  212. unsigned int pgprot;
  213. #endif
  214. mutex_lock(&dev->struct_mutex);
  215. seq_printf(m, "vma use count: %d, high_memory = %pK, 0x%pK\n",
  216. atomic_read(&dev->vma_count),
  217. high_memory, (void *)virt_to_phys(high_memory));
  218. list_for_each_entry(pt, &dev->vmalist, head) {
  219. vma = pt->vma;
  220. if (!vma)
  221. continue;
  222. seq_printf(m,
  223. "\n%5d 0x%pK-0x%pK %c%c%c%c%c%c 0x%08lx000",
  224. pt->pid,
  225. (void *)vma->vm_start, (void *)vma->vm_end,
  226. vma->vm_flags & VM_READ ? 'r' : '-',
  227. vma->vm_flags & VM_WRITE ? 'w' : '-',
  228. vma->vm_flags & VM_EXEC ? 'x' : '-',
  229. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  230. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  231. vma->vm_flags & VM_IO ? 'i' : '-',
  232. vma->vm_pgoff);
  233. #if defined(__i386__)
  234. pgprot = pgprot_val(vma->vm_page_prot);
  235. seq_printf(m, " %c%c%c%c%c%c%c%c%c",
  236. pgprot & _PAGE_PRESENT ? 'p' : '-',
  237. pgprot & _PAGE_RW ? 'w' : 'r',
  238. pgprot & _PAGE_USER ? 'u' : 's',
  239. pgprot & _PAGE_PWT ? 't' : 'b',
  240. pgprot & _PAGE_PCD ? 'u' : 'c',
  241. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  242. pgprot & _PAGE_DIRTY ? 'd' : '-',
  243. pgprot & _PAGE_PSE ? 'm' : 'k',
  244. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  245. #endif
  246. seq_printf(m, "\n");
  247. }
  248. mutex_unlock(&dev->struct_mutex);
  249. return 0;
  250. }
  251. #endif