drm_info.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. if (!master)
  48. return 0;
  49. if (master->unique) {
  50. seq_printf(m, "%s %s %s\n",
  51. dev->driver->pci_driver.name,
  52. pci_name(dev->pdev), master->unique);
  53. } else {
  54. seq_printf(m, "%s %s\n", dev->driver->pci_driver.name,
  55. pci_name(dev->pdev));
  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/.../queues" is read.
  103. */
  104. int drm_queues_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. int i;
  109. struct drm_queue *q;
  110. mutex_lock(&dev->struct_mutex);
  111. seq_printf(m, " ctx/flags use fin"
  112. " blk/rw/rwf wait flushed queued"
  113. " locks\n\n");
  114. for (i = 0; i < dev->queue_count; i++) {
  115. q = dev->queuelist[i];
  116. atomic_inc(&q->use_count);
  117. seq_printf(m, "%5d/0x%03x %5d %5d"
  118. " %5d/%c%c/%c%c%c %5Zd\n",
  119. i,
  120. q->flags,
  121. atomic_read(&q->use_count),
  122. atomic_read(&q->finalization),
  123. atomic_read(&q->block_count),
  124. atomic_read(&q->block_read) ? 'r' : '-',
  125. atomic_read(&q->block_write) ? 'w' : '-',
  126. waitqueue_active(&q->read_queue) ? 'r' : '-',
  127. waitqueue_active(&q->write_queue) ? 'w' : '-',
  128. waitqueue_active(&q->flush_queue) ? 'f' : '-',
  129. DRM_BUFCOUNT(&q->waitlist));
  130. atomic_dec(&q->use_count);
  131. }
  132. mutex_unlock(&dev->struct_mutex);
  133. return 0;
  134. }
  135. /**
  136. * Called when "/proc/dri/.../bufs" is read.
  137. */
  138. int drm_bufs_info(struct seq_file *m, void *data)
  139. {
  140. struct drm_info_node *node = (struct drm_info_node *) m->private;
  141. struct drm_device *dev = node->minor->dev;
  142. struct drm_device_dma *dma;
  143. int i, seg_pages;
  144. mutex_lock(&dev->struct_mutex);
  145. dma = dev->dma;
  146. if (!dma) {
  147. mutex_unlock(&dev->struct_mutex);
  148. return 0;
  149. }
  150. seq_printf(m, " o size count free segs pages kB\n\n");
  151. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  152. if (dma->bufs[i].buf_count) {
  153. seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
  154. seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
  155. i,
  156. dma->bufs[i].buf_size,
  157. dma->bufs[i].buf_count,
  158. atomic_read(&dma->bufs[i].freelist.count),
  159. dma->bufs[i].seg_count,
  160. seg_pages,
  161. seg_pages * PAGE_SIZE / 1024);
  162. }
  163. }
  164. seq_printf(m, "\n");
  165. for (i = 0; i < dma->buf_count; i++) {
  166. if (i && !(i % 32))
  167. seq_printf(m, "\n");
  168. seq_printf(m, " %d", dma->buflist[i]->list);
  169. }
  170. seq_printf(m, "\n");
  171. mutex_unlock(&dev->struct_mutex);
  172. return 0;
  173. }
  174. /**
  175. * Called when "/proc/dri/.../vblank" is read.
  176. */
  177. int drm_vblank_info(struct seq_file *m, void *data)
  178. {
  179. struct drm_info_node *node = (struct drm_info_node *) m->private;
  180. struct drm_device *dev = node->minor->dev;
  181. int crtc;
  182. mutex_lock(&dev->struct_mutex);
  183. for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
  184. seq_printf(m, "CRTC %d enable: %d\n",
  185. crtc, atomic_read(&dev->vblank_refcount[crtc]));
  186. seq_printf(m, "CRTC %d counter: %d\n",
  187. crtc, drm_vblank_count(dev, crtc));
  188. seq_printf(m, "CRTC %d last wait: %d\n",
  189. crtc, dev->last_vblank_wait[crtc]);
  190. seq_printf(m, "CRTC %d in modeset: %d\n",
  191. crtc, dev->vblank_inmodeset[crtc]);
  192. }
  193. mutex_unlock(&dev->struct_mutex);
  194. return 0;
  195. }
  196. /**
  197. * Called when "/proc/dri/.../clients" is read.
  198. *
  199. */
  200. int drm_clients_info(struct seq_file *m, void *data)
  201. {
  202. struct drm_info_node *node = (struct drm_info_node *) m->private;
  203. struct drm_device *dev = node->minor->dev;
  204. struct drm_file *priv;
  205. mutex_lock(&dev->struct_mutex);
  206. seq_printf(m, "a dev pid uid magic ioctls\n\n");
  207. list_for_each_entry(priv, &dev->filelist, lhead) {
  208. seq_printf(m, "%c %3d %5d %5d %10u %10lu\n",
  209. priv->authenticated ? 'y' : 'n',
  210. priv->minor->index,
  211. priv->pid,
  212. priv->uid, priv->magic, priv->ioctl_count);
  213. }
  214. mutex_unlock(&dev->struct_mutex);
  215. return 0;
  216. }
  217. int drm_gem_one_name_info(int id, void *ptr, void *data)
  218. {
  219. struct drm_gem_object *obj = ptr;
  220. struct seq_file *m = data;
  221. seq_printf(m, "name %d size %zd\n", obj->name, obj->size);
  222. seq_printf(m, "%6d %8zd %7d %8d\n",
  223. obj->name, obj->size,
  224. atomic_read(&obj->handlecount.refcount),
  225. atomic_read(&obj->refcount.refcount));
  226. return 0;
  227. }
  228. int drm_gem_name_info(struct seq_file *m, void *data)
  229. {
  230. struct drm_info_node *node = (struct drm_info_node *) m->private;
  231. struct drm_device *dev = node->minor->dev;
  232. seq_printf(m, " name size handles refcount\n");
  233. idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
  234. return 0;
  235. }
  236. int drm_gem_object_info(struct seq_file *m, void* data)
  237. {
  238. struct drm_info_node *node = (struct drm_info_node *) m->private;
  239. struct drm_device *dev = node->minor->dev;
  240. seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
  241. seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
  242. seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
  243. seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
  244. seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
  245. seq_printf(m, "%d gtt total\n", dev->gtt_total);
  246. return 0;
  247. }
  248. #if DRM_DEBUG_CODE
  249. int drm_vma_info(struct seq_file *m, void *data)
  250. {
  251. struct drm_info_node *node = (struct drm_info_node *) m->private;
  252. struct drm_device *dev = node->minor->dev;
  253. struct drm_vma_entry *pt;
  254. struct vm_area_struct *vma;
  255. #if defined(__i386__)
  256. unsigned int pgprot;
  257. #endif
  258. mutex_lock(&dev->struct_mutex);
  259. seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
  260. atomic_read(&dev->vma_count),
  261. high_memory, (u64)virt_to_phys(high_memory));
  262. list_for_each_entry(pt, &dev->vmalist, head) {
  263. vma = pt->vma;
  264. if (!vma)
  265. continue;
  266. seq_printf(m,
  267. "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
  268. pt->pid, vma->vm_start, vma->vm_end,
  269. vma->vm_flags & VM_READ ? 'r' : '-',
  270. vma->vm_flags & VM_WRITE ? 'w' : '-',
  271. vma->vm_flags & VM_EXEC ? 'x' : '-',
  272. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  273. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  274. vma->vm_flags & VM_IO ? 'i' : '-',
  275. vma->vm_pgoff);
  276. #if defined(__i386__)
  277. pgprot = pgprot_val(vma->vm_page_prot);
  278. seq_printf(m, " %c%c%c%c%c%c%c%c%c",
  279. pgprot & _PAGE_PRESENT ? 'p' : '-',
  280. pgprot & _PAGE_RW ? 'w' : 'r',
  281. pgprot & _PAGE_USER ? 'u' : 's',
  282. pgprot & _PAGE_PWT ? 't' : 'b',
  283. pgprot & _PAGE_PCD ? 'u' : 'c',
  284. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  285. pgprot & _PAGE_DIRTY ? 'd' : '-',
  286. pgprot & _PAGE_PSE ? 'm' : 'k',
  287. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  288. #endif
  289. seq_printf(m, "\n");
  290. }
  291. mutex_unlock(&dev->struct_mutex);
  292. return 0;
  293. }
  294. #endif