drm_info.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) {
  50. if (master->unique) {
  51. seq_printf(m, "%s %s %s\n",
  52. dev->driver->platform_device->name,
  53. dev_name(dev->dev), master->unique);
  54. } else {
  55. seq_printf(m, "%s\n",
  56. dev->driver->platform_device->name);
  57. }
  58. } else {
  59. if (master->unique) {
  60. seq_printf(m, "%s %s %s\n",
  61. dev->driver->pci_driver.name,
  62. dev_name(dev->dev), master->unique);
  63. } else {
  64. seq_printf(m, "%s %s\n", dev->driver->pci_driver.name,
  65. dev_name(dev->dev));
  66. }
  67. }
  68. return 0;
  69. }
  70. /**
  71. * Called when "/proc/dri/.../vm" is read.
  72. *
  73. * Prints information about all mappings in drm_device::maplist.
  74. */
  75. int drm_vm_info(struct seq_file *m, void *data)
  76. {
  77. struct drm_info_node *node = (struct drm_info_node *) m->private;
  78. struct drm_device *dev = node->minor->dev;
  79. struct drm_local_map *map;
  80. struct drm_map_list *r_list;
  81. /* Hardcoded from _DRM_FRAME_BUFFER,
  82. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  83. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  84. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  85. const char *type;
  86. int i;
  87. mutex_lock(&dev->struct_mutex);
  88. seq_printf(m, "slot offset size type flags address mtrr\n\n");
  89. i = 0;
  90. list_for_each_entry(r_list, &dev->maplist, head) {
  91. map = r_list->map;
  92. if (!map)
  93. continue;
  94. if (map->type < 0 || map->type > 5)
  95. type = "??";
  96. else
  97. type = types[map->type];
  98. seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ",
  99. i,
  100. (unsigned long long)map->offset,
  101. map->size, type, map->flags,
  102. (unsigned long) r_list->user_token);
  103. if (map->mtrr < 0)
  104. seq_printf(m, "none\n");
  105. else
  106. seq_printf(m, "%4d\n", map->mtrr);
  107. i++;
  108. }
  109. mutex_unlock(&dev->struct_mutex);
  110. return 0;
  111. }
  112. /**
  113. * Called when "/proc/dri/.../queues" is read.
  114. */
  115. int drm_queues_info(struct seq_file *m, void *data)
  116. {
  117. struct drm_info_node *node = (struct drm_info_node *) m->private;
  118. struct drm_device *dev = node->minor->dev;
  119. int i;
  120. struct drm_queue *q;
  121. mutex_lock(&dev->struct_mutex);
  122. seq_printf(m, " ctx/flags use fin"
  123. " blk/rw/rwf wait flushed queued"
  124. " locks\n\n");
  125. for (i = 0; i < dev->queue_count; i++) {
  126. q = dev->queuelist[i];
  127. atomic_inc(&q->use_count);
  128. seq_printf(m, "%5d/0x%03x %5d %5d"
  129. " %5d/%c%c/%c%c%c %5Zd\n",
  130. i,
  131. q->flags,
  132. atomic_read(&q->use_count),
  133. atomic_read(&q->finalization),
  134. atomic_read(&q->block_count),
  135. atomic_read(&q->block_read) ? 'r' : '-',
  136. atomic_read(&q->block_write) ? 'w' : '-',
  137. waitqueue_active(&q->read_queue) ? 'r' : '-',
  138. waitqueue_active(&q->write_queue) ? 'w' : '-',
  139. waitqueue_active(&q->flush_queue) ? 'f' : '-',
  140. DRM_BUFCOUNT(&q->waitlist));
  141. atomic_dec(&q->use_count);
  142. }
  143. mutex_unlock(&dev->struct_mutex);
  144. return 0;
  145. }
  146. /**
  147. * Called when "/proc/dri/.../bufs" is read.
  148. */
  149. int drm_bufs_info(struct seq_file *m, void *data)
  150. {
  151. struct drm_info_node *node = (struct drm_info_node *) m->private;
  152. struct drm_device *dev = node->minor->dev;
  153. struct drm_device_dma *dma;
  154. int i, seg_pages;
  155. mutex_lock(&dev->struct_mutex);
  156. dma = dev->dma;
  157. if (!dma) {
  158. mutex_unlock(&dev->struct_mutex);
  159. return 0;
  160. }
  161. seq_printf(m, " o size count free segs pages kB\n\n");
  162. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  163. if (dma->bufs[i].buf_count) {
  164. seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
  165. seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
  166. i,
  167. dma->bufs[i].buf_size,
  168. dma->bufs[i].buf_count,
  169. atomic_read(&dma->bufs[i].freelist.count),
  170. dma->bufs[i].seg_count,
  171. seg_pages,
  172. seg_pages * PAGE_SIZE / 1024);
  173. }
  174. }
  175. seq_printf(m, "\n");
  176. for (i = 0; i < dma->buf_count; i++) {
  177. if (i && !(i % 32))
  178. seq_printf(m, "\n");
  179. seq_printf(m, " %d", dma->buflist[i]->list);
  180. }
  181. seq_printf(m, "\n");
  182. mutex_unlock(&dev->struct_mutex);
  183. return 0;
  184. }
  185. /**
  186. * Called when "/proc/dri/.../vblank" is read.
  187. */
  188. int drm_vblank_info(struct seq_file *m, void *data)
  189. {
  190. struct drm_info_node *node = (struct drm_info_node *) m->private;
  191. struct drm_device *dev = node->minor->dev;
  192. int crtc;
  193. mutex_lock(&dev->struct_mutex);
  194. for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
  195. seq_printf(m, "CRTC %d enable: %d\n",
  196. crtc, atomic_read(&dev->vblank_refcount[crtc]));
  197. seq_printf(m, "CRTC %d counter: %d\n",
  198. crtc, drm_vblank_count(dev, crtc));
  199. seq_printf(m, "CRTC %d last wait: %d\n",
  200. crtc, dev->last_vblank_wait[crtc]);
  201. seq_printf(m, "CRTC %d in modeset: %d\n",
  202. crtc, dev->vblank_inmodeset[crtc]);
  203. }
  204. mutex_unlock(&dev->struct_mutex);
  205. return 0;
  206. }
  207. /**
  208. * Called when "/proc/dri/.../clients" is read.
  209. *
  210. */
  211. int drm_clients_info(struct seq_file *m, void *data)
  212. {
  213. struct drm_info_node *node = (struct drm_info_node *) m->private;
  214. struct drm_device *dev = node->minor->dev;
  215. struct drm_file *priv;
  216. mutex_lock(&dev->struct_mutex);
  217. seq_printf(m, "a dev pid uid magic ioctls\n\n");
  218. list_for_each_entry(priv, &dev->filelist, lhead) {
  219. seq_printf(m, "%c %3d %5d %5d %10u %10lu\n",
  220. priv->authenticated ? 'y' : 'n',
  221. priv->minor->index,
  222. priv->pid,
  223. priv->uid, priv->magic, priv->ioctl_count);
  224. }
  225. mutex_unlock(&dev->struct_mutex);
  226. return 0;
  227. }
  228. int drm_gem_one_name_info(int id, void *ptr, void *data)
  229. {
  230. struct drm_gem_object *obj = ptr;
  231. struct seq_file *m = data;
  232. seq_printf(m, "name %d size %zd\n", obj->name, obj->size);
  233. seq_printf(m, "%6d %8zd %7d %8d\n",
  234. obj->name, obj->size,
  235. atomic_read(&obj->handle_count),
  236. atomic_read(&obj->refcount.refcount));
  237. return 0;
  238. }
  239. int drm_gem_name_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. seq_printf(m, " name size handles refcount\n");
  244. idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
  245. return 0;
  246. }
  247. #if DRM_DEBUG_CODE
  248. int drm_vma_info(struct seq_file *m, void *data)
  249. {
  250. struct drm_info_node *node = (struct drm_info_node *) m->private;
  251. struct drm_device *dev = node->minor->dev;
  252. struct drm_vma_entry *pt;
  253. struct vm_area_struct *vma;
  254. #if defined(__i386__)
  255. unsigned int pgprot;
  256. #endif
  257. mutex_lock(&dev->struct_mutex);
  258. seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
  259. atomic_read(&dev->vma_count),
  260. high_memory, (u64)virt_to_phys(high_memory));
  261. list_for_each_entry(pt, &dev->vmalist, head) {
  262. vma = pt->vma;
  263. if (!vma)
  264. continue;
  265. seq_printf(m,
  266. "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
  267. pt->pid, vma->vm_start, vma->vm_end,
  268. vma->vm_flags & VM_READ ? 'r' : '-',
  269. vma->vm_flags & VM_WRITE ? 'w' : '-',
  270. vma->vm_flags & VM_EXEC ? 'x' : '-',
  271. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  272. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  273. vma->vm_flags & VM_IO ? 'i' : '-',
  274. vma->vm_pgoff);
  275. #if defined(__i386__)
  276. pgprot = pgprot_val(vma->vm_page_prot);
  277. seq_printf(m, " %c%c%c%c%c%c%c%c%c",
  278. pgprot & _PAGE_PRESENT ? 'p' : '-',
  279. pgprot & _PAGE_RW ? 'w' : 'r',
  280. pgprot & _PAGE_USER ? 'u' : 's',
  281. pgprot & _PAGE_PWT ? 't' : 'b',
  282. pgprot & _PAGE_PCD ? 'u' : 'c',
  283. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  284. pgprot & _PAGE_DIRTY ? 'd' : '-',
  285. pgprot & _PAGE_PSE ? 'm' : 'k',
  286. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  287. #endif
  288. seq_printf(m, "\n");
  289. }
  290. mutex_unlock(&dev->struct_mutex);
  291. return 0;
  292. }
  293. #endif