drm_info.c 8.9 KB

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