drm_proc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /**
  2. * \file drm_proc.c
  3. * /proc support for DRM
  4. *
  5. * \author Rickard E. (Rik) Faith <faith@valinux.com>
  6. * \author Gareth Hughes <gareth@valinux.com>
  7. *
  8. * \par Acknowledgements:
  9. * Matthew J Sottek <matthew.j.sottek@intel.com> sent in a patch to fix
  10. * the problem with the proc files not outputting all their information.
  11. */
  12. /*
  13. * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
  14. *
  15. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  16. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  17. * All Rights Reserved.
  18. *
  19. * Permission is hereby granted, free of charge, to any person obtaining a
  20. * copy of this software and associated documentation files (the "Software"),
  21. * to deal in the Software without restriction, including without limitation
  22. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  23. * and/or sell copies of the Software, and to permit persons to whom the
  24. * Software is furnished to do so, subject to the following conditions:
  25. *
  26. * The above copyright notice and this permission notice (including the next
  27. * paragraph) shall be included in all copies or substantial portions of the
  28. * Software.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  31. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  33. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  34. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  35. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  36. * OTHER DEALINGS IN THE SOFTWARE.
  37. */
  38. #include "drmP.h"
  39. static int drm_name_info(char *buf, char **start, off_t offset,
  40. int request, int *eof, void *data);
  41. static int drm_vm_info(char *buf, char **start, off_t offset,
  42. int request, int *eof, void *data);
  43. static int drm_clients_info(char *buf, char **start, off_t offset,
  44. int request, int *eof, void *data);
  45. static int drm_queues_info(char *buf, char **start, off_t offset,
  46. int request, int *eof, void *data);
  47. static int drm_bufs_info(char *buf, char **start, off_t offset,
  48. int request, int *eof, void *data);
  49. #if DRM_DEBUG_CODE
  50. static int drm_vma_info(char *buf, char **start, off_t offset,
  51. int request, int *eof, void *data);
  52. #endif
  53. /**
  54. * Proc file list.
  55. */
  56. static struct drm_proc_list {
  57. const char *name; /**< file name */
  58. int (*f) (char *, char **, off_t, int, int *, void *); /**< proc callback*/
  59. } drm_proc_list[] = {
  60. {"name", drm_name_info},
  61. {"mem", drm_mem_info},
  62. {"vm", drm_vm_info},
  63. {"clients", drm_clients_info},
  64. {"queues", drm_queues_info},
  65. {"bufs", drm_bufs_info},
  66. #if DRM_DEBUG_CODE
  67. {"vma", drm_vma_info},
  68. #endif
  69. };
  70. #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
  71. /**
  72. * Initialize the DRI proc filesystem for a device.
  73. *
  74. * \param dev DRM device.
  75. * \param minor device minor number.
  76. * \param root DRI proc dir entry.
  77. * \param dev_root resulting DRI device proc dir entry.
  78. * \return root entry pointer on success, or NULL on failure.
  79. *
  80. * Create the DRI proc root entry "/proc/dri", the device proc root entry
  81. * "/proc/dri/%minor%/", and each entry in proc_list as
  82. * "/proc/dri/%minor%/%name%".
  83. */
  84. int drm_proc_init(struct drm_device * dev, int minor,
  85. struct proc_dir_entry *root, struct proc_dir_entry **dev_root)
  86. {
  87. struct proc_dir_entry *ent;
  88. int i, j;
  89. char name[64];
  90. sprintf(name, "%d", minor);
  91. *dev_root = proc_mkdir(name, root);
  92. if (!*dev_root) {
  93. DRM_ERROR("Cannot create /proc/dri/%s\n", name);
  94. return -1;
  95. }
  96. for (i = 0; i < DRM_PROC_ENTRIES; i++) {
  97. ent = create_proc_entry(drm_proc_list[i].name,
  98. S_IFREG | S_IRUGO, *dev_root);
  99. if (!ent) {
  100. DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
  101. name, drm_proc_list[i].name);
  102. for (j = 0; j < i; j++)
  103. remove_proc_entry(drm_proc_list[i].name,
  104. *dev_root);
  105. remove_proc_entry(name, root);
  106. return -1;
  107. }
  108. ent->read_proc = drm_proc_list[i].f;
  109. ent->data = dev;
  110. }
  111. return 0;
  112. }
  113. /**
  114. * Cleanup the proc filesystem resources.
  115. *
  116. * \param minor device minor number.
  117. * \param root DRI proc dir entry.
  118. * \param dev_root DRI device proc dir entry.
  119. * \return always zero.
  120. *
  121. * Remove all proc entries created by proc_init().
  122. */
  123. int drm_proc_cleanup(int minor, struct proc_dir_entry *root,
  124. struct proc_dir_entry *dev_root)
  125. {
  126. int i;
  127. char name[64];
  128. if (!root || !dev_root)
  129. return 0;
  130. for (i = 0; i < DRM_PROC_ENTRIES; i++)
  131. remove_proc_entry(drm_proc_list[i].name, dev_root);
  132. sprintf(name, "%d", minor);
  133. remove_proc_entry(name, root);
  134. return 0;
  135. }
  136. /**
  137. * Called when "/proc/dri/.../name" is read.
  138. *
  139. * \param buf output buffer.
  140. * \param start start of output data.
  141. * \param offset requested start offset.
  142. * \param request requested number of bytes.
  143. * \param eof whether there is no more data to return.
  144. * \param data private data.
  145. * \return number of written bytes.
  146. *
  147. * Prints the device name together with the bus id if available.
  148. */
  149. static int drm_name_info(char *buf, char **start, off_t offset, int request,
  150. int *eof, void *data)
  151. {
  152. struct drm_device *dev = (struct drm_device *) data;
  153. int len = 0;
  154. if (offset > DRM_PROC_LIMIT) {
  155. *eof = 1;
  156. return 0;
  157. }
  158. *start = &buf[offset];
  159. *eof = 0;
  160. if (dev->unique) {
  161. DRM_PROC_PRINT("%s %s %s\n",
  162. dev->driver->pci_driver.name,
  163. pci_name(dev->pdev), dev->unique);
  164. } else {
  165. DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
  166. pci_name(dev->pdev));
  167. }
  168. if (len > request + offset)
  169. return request;
  170. *eof = 1;
  171. return len - offset;
  172. }
  173. /**
  174. * Called when "/proc/dri/.../vm" is read.
  175. *
  176. * \param buf output buffer.
  177. * \param start start of output data.
  178. * \param offset requested start offset.
  179. * \param request requested number of bytes.
  180. * \param eof whether there is no more data to return.
  181. * \param data private data.
  182. * \return number of written bytes.
  183. *
  184. * Prints information about all mappings in drm_device::maplist.
  185. */
  186. static int drm__vm_info(char *buf, char **start, off_t offset, int request,
  187. int *eof, void *data)
  188. {
  189. struct drm_device *dev = (struct drm_device *) data;
  190. int len = 0;
  191. struct drm_map *map;
  192. struct drm_map_list *r_list;
  193. /* Hardcoded from _DRM_FRAME_BUFFER,
  194. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  195. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  196. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  197. const char *type;
  198. int i;
  199. if (offset > DRM_PROC_LIMIT) {
  200. *eof = 1;
  201. return 0;
  202. }
  203. *start = &buf[offset];
  204. *eof = 0;
  205. DRM_PROC_PRINT("slot offset size type flags "
  206. "address mtrr\n\n");
  207. i = 0;
  208. list_for_each_entry(r_list, &dev->maplist, head) {
  209. map = r_list->map;
  210. if (!map)
  211. continue;
  212. if (map->type < 0 || map->type > 5)
  213. type = "??";
  214. else
  215. type = types[map->type];
  216. DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08x ",
  217. i,
  218. map->offset,
  219. map->size, type, map->flags,
  220. r_list->user_token);
  221. if (map->mtrr < 0) {
  222. DRM_PROC_PRINT("none\n");
  223. } else {
  224. DRM_PROC_PRINT("%4d\n", map->mtrr);
  225. }
  226. i++;
  227. }
  228. if (len > request + offset)
  229. return request;
  230. *eof = 1;
  231. return len - offset;
  232. }
  233. /**
  234. * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
  235. */
  236. static int drm_vm_info(char *buf, char **start, off_t offset, int request,
  237. int *eof, void *data)
  238. {
  239. struct drm_device *dev = (struct drm_device *) data;
  240. int ret;
  241. mutex_lock(&dev->struct_mutex);
  242. ret = drm__vm_info(buf, start, offset, request, eof, data);
  243. mutex_unlock(&dev->struct_mutex);
  244. return ret;
  245. }
  246. /**
  247. * Called when "/proc/dri/.../queues" is read.
  248. *
  249. * \param buf output buffer.
  250. * \param start start of output data.
  251. * \param offset requested start offset.
  252. * \param request requested number of bytes.
  253. * \param eof whether there is no more data to return.
  254. * \param data private data.
  255. * \return number of written bytes.
  256. */
  257. static int drm__queues_info(char *buf, char **start, off_t offset,
  258. int request, int *eof, void *data)
  259. {
  260. struct drm_device *dev = (struct drm_device *) data;
  261. int len = 0;
  262. int i;
  263. struct drm_queue *q;
  264. if (offset > DRM_PROC_LIMIT) {
  265. *eof = 1;
  266. return 0;
  267. }
  268. *start = &buf[offset];
  269. *eof = 0;
  270. DRM_PROC_PRINT(" ctx/flags use fin"
  271. " blk/rw/rwf wait flushed queued"
  272. " locks\n\n");
  273. for (i = 0; i < dev->queue_count; i++) {
  274. q = dev->queuelist[i];
  275. atomic_inc(&q->use_count);
  276. DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
  277. "%5d/0x%03x %5d %5d"
  278. " %5d/%c%c/%c%c%c %5Zd\n",
  279. i,
  280. q->flags,
  281. atomic_read(&q->use_count),
  282. atomic_read(&q->finalization),
  283. atomic_read(&q->block_count),
  284. atomic_read(&q->block_read) ? 'r' : '-',
  285. atomic_read(&q->block_write) ? 'w' : '-',
  286. waitqueue_active(&q->read_queue) ? 'r' : '-',
  287. waitqueue_active(&q->
  288. write_queue) ? 'w' : '-',
  289. waitqueue_active(&q->
  290. flush_queue) ? 'f' : '-',
  291. DRM_BUFCOUNT(&q->waitlist));
  292. atomic_dec(&q->use_count);
  293. }
  294. if (len > request + offset)
  295. return request;
  296. *eof = 1;
  297. return len - offset;
  298. }
  299. /**
  300. * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
  301. */
  302. static int drm_queues_info(char *buf, char **start, off_t offset, int request,
  303. int *eof, void *data)
  304. {
  305. struct drm_device *dev = (struct drm_device *) data;
  306. int ret;
  307. mutex_lock(&dev->struct_mutex);
  308. ret = drm__queues_info(buf, start, offset, request, eof, data);
  309. mutex_unlock(&dev->struct_mutex);
  310. return ret;
  311. }
  312. /**
  313. * Called when "/proc/dri/.../bufs" is read.
  314. *
  315. * \param buf output buffer.
  316. * \param start start of output data.
  317. * \param offset requested start offset.
  318. * \param request requested number of bytes.
  319. * \param eof whether there is no more data to return.
  320. * \param data private data.
  321. * \return number of written bytes.
  322. */
  323. static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
  324. int *eof, void *data)
  325. {
  326. struct drm_device *dev = (struct drm_device *) data;
  327. int len = 0;
  328. struct drm_device_dma *dma = dev->dma;
  329. int i;
  330. if (!dma || offset > DRM_PROC_LIMIT) {
  331. *eof = 1;
  332. return 0;
  333. }
  334. *start = &buf[offset];
  335. *eof = 0;
  336. DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
  337. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  338. if (dma->bufs[i].buf_count)
  339. DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
  340. i,
  341. dma->bufs[i].buf_size,
  342. dma->bufs[i].buf_count,
  343. atomic_read(&dma->bufs[i]
  344. .freelist.count),
  345. dma->bufs[i].seg_count,
  346. dma->bufs[i].seg_count
  347. * (1 << dma->bufs[i].page_order),
  348. (dma->bufs[i].seg_count
  349. * (1 << dma->bufs[i].page_order))
  350. * PAGE_SIZE / 1024);
  351. }
  352. DRM_PROC_PRINT("\n");
  353. for (i = 0; i < dma->buf_count; i++) {
  354. if (i && !(i % 32))
  355. DRM_PROC_PRINT("\n");
  356. DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
  357. }
  358. DRM_PROC_PRINT("\n");
  359. if (len > request + offset)
  360. return request;
  361. *eof = 1;
  362. return len - offset;
  363. }
  364. /**
  365. * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
  366. */
  367. static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
  368. int *eof, void *data)
  369. {
  370. struct drm_device *dev = (struct drm_device *) data;
  371. int ret;
  372. mutex_lock(&dev->struct_mutex);
  373. ret = drm__bufs_info(buf, start, offset, request, eof, data);
  374. mutex_unlock(&dev->struct_mutex);
  375. return ret;
  376. }
  377. /**
  378. * Called when "/proc/dri/.../clients" is read.
  379. *
  380. * \param buf output buffer.
  381. * \param start start of output data.
  382. * \param offset requested start offset.
  383. * \param request requested number of bytes.
  384. * \param eof whether there is no more data to return.
  385. * \param data private data.
  386. * \return number of written bytes.
  387. */
  388. static int drm__clients_info(char *buf, char **start, off_t offset,
  389. int request, int *eof, void *data)
  390. {
  391. struct drm_device *dev = (struct drm_device *) data;
  392. int len = 0;
  393. struct drm_file *priv;
  394. if (offset > DRM_PROC_LIMIT) {
  395. *eof = 1;
  396. return 0;
  397. }
  398. *start = &buf[offset];
  399. *eof = 0;
  400. DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
  401. list_for_each_entry(priv, &dev->filelist, lhead) {
  402. DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
  403. priv->authenticated ? 'y' : 'n',
  404. priv->minor,
  405. priv->pid,
  406. priv->uid, priv->magic, priv->ioctl_count);
  407. }
  408. if (len > request + offset)
  409. return request;
  410. *eof = 1;
  411. return len - offset;
  412. }
  413. /**
  414. * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
  415. */
  416. static int drm_clients_info(char *buf, char **start, off_t offset,
  417. int request, int *eof, void *data)
  418. {
  419. struct drm_device *dev = (struct drm_device *) data;
  420. int ret;
  421. mutex_lock(&dev->struct_mutex);
  422. ret = drm__clients_info(buf, start, offset, request, eof, data);
  423. mutex_unlock(&dev->struct_mutex);
  424. return ret;
  425. }
  426. #if DRM_DEBUG_CODE
  427. static int drm__vma_info(char *buf, char **start, off_t offset, int request,
  428. int *eof, void *data)
  429. {
  430. struct drm_device *dev = (struct drm_device *) data;
  431. int len = 0;
  432. struct drm_vma_entry *pt;
  433. struct vm_area_struct *vma;
  434. #if defined(__i386__)
  435. unsigned int pgprot;
  436. #endif
  437. if (offset > DRM_PROC_LIMIT) {
  438. *eof = 1;
  439. return 0;
  440. }
  441. *start = &buf[offset];
  442. *eof = 0;
  443. DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
  444. atomic_read(&dev->vma_count),
  445. high_memory, virt_to_phys(high_memory));
  446. list_for_each_entry(pt, &dev->vmalist, head) {
  447. if (!(vma = pt->vma))
  448. continue;
  449. DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
  450. pt->pid,
  451. vma->vm_start,
  452. vma->vm_end,
  453. vma->vm_flags & VM_READ ? 'r' : '-',
  454. vma->vm_flags & VM_WRITE ? 'w' : '-',
  455. vma->vm_flags & VM_EXEC ? 'x' : '-',
  456. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  457. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  458. vma->vm_flags & VM_IO ? 'i' : '-',
  459. vma->vm_pgoff);
  460. #if defined(__i386__)
  461. pgprot = pgprot_val(vma->vm_page_prot);
  462. DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
  463. pgprot & _PAGE_PRESENT ? 'p' : '-',
  464. pgprot & _PAGE_RW ? 'w' : 'r',
  465. pgprot & _PAGE_USER ? 'u' : 's',
  466. pgprot & _PAGE_PWT ? 't' : 'b',
  467. pgprot & _PAGE_PCD ? 'u' : 'c',
  468. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  469. pgprot & _PAGE_DIRTY ? 'd' : '-',
  470. pgprot & _PAGE_PSE ? 'm' : 'k',
  471. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  472. #endif
  473. DRM_PROC_PRINT("\n");
  474. }
  475. if (len > request + offset)
  476. return request;
  477. *eof = 1;
  478. return len - offset;
  479. }
  480. static int drm_vma_info(char *buf, char **start, off_t offset, int request,
  481. int *eof, void *data)
  482. {
  483. struct drm_device *dev = (struct drm_device *) data;
  484. int ret;
  485. mutex_lock(&dev->struct_mutex);
  486. ret = drm__vma_info(buf, start, offset, request, eof, data);
  487. mutex_unlock(&dev->struct_mutex);
  488. return ret;
  489. }
  490. #endif