drm_proc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
  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(drm_device_t * 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. drm_device_t *dev = (drm_device_t *) 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. drm_device_t *dev = (drm_device_t *) data;
  190. int len = 0;
  191. drm_map_t *map;
  192. drm_map_list_t *r_list;
  193. struct list_head *list;
  194. /* Hardcoded from _DRM_FRAME_BUFFER,
  195. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  196. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  197. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  198. const char *type;
  199. int i;
  200. if (offset > DRM_PROC_LIMIT) {
  201. *eof = 1;
  202. return 0;
  203. }
  204. *start = &buf[offset];
  205. *eof = 0;
  206. DRM_PROC_PRINT("slot offset size type flags "
  207. "address mtrr\n\n");
  208. i = 0;
  209. if (dev->maplist != NULL)
  210. list_for_each(list, &dev->maplist->head) {
  211. r_list = list_entry(list, drm_map_list_t, head);
  212. map = r_list->map;
  213. if (!map)
  214. continue;
  215. if (map->type < 0 || map->type > 5)
  216. type = "??";
  217. else
  218. type = types[map->type];
  219. DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08x ",
  220. i,
  221. map->offset,
  222. map->size, type, map->flags, r_list->user_token);
  223. if (map->mtrr < 0) {
  224. DRM_PROC_PRINT("none\n");
  225. } else {
  226. DRM_PROC_PRINT("%4d\n", map->mtrr);
  227. }
  228. i++;
  229. }
  230. if (len > request + offset)
  231. return request;
  232. *eof = 1;
  233. return len - offset;
  234. }
  235. /**
  236. * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
  237. */
  238. static int drm_vm_info(char *buf, char **start, off_t offset, int request,
  239. int *eof, void *data)
  240. {
  241. drm_device_t *dev = (drm_device_t *) data;
  242. int ret;
  243. mutex_lock(&dev->struct_mutex);
  244. ret = drm__vm_info(buf, start, offset, request, eof, data);
  245. mutex_unlock(&dev->struct_mutex);
  246. return ret;
  247. }
  248. /**
  249. * Called when "/proc/dri/.../queues" is read.
  250. *
  251. * \param buf output buffer.
  252. * \param start start of output data.
  253. * \param offset requested start offset.
  254. * \param request requested number of bytes.
  255. * \param eof whether there is no more data to return.
  256. * \param data private data.
  257. * \return number of written bytes.
  258. */
  259. static int drm__queues_info(char *buf, char **start, off_t offset,
  260. int request, int *eof, void *data)
  261. {
  262. drm_device_t *dev = (drm_device_t *) data;
  263. int len = 0;
  264. int i;
  265. drm_queue_t *q;
  266. if (offset > DRM_PROC_LIMIT) {
  267. *eof = 1;
  268. return 0;
  269. }
  270. *start = &buf[offset];
  271. *eof = 0;
  272. DRM_PROC_PRINT(" ctx/flags use fin"
  273. " blk/rw/rwf wait flushed queued"
  274. " locks\n\n");
  275. for (i = 0; i < dev->queue_count; i++) {
  276. q = dev->queuelist[i];
  277. atomic_inc(&q->use_count);
  278. DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
  279. "%5d/0x%03x %5d %5d"
  280. " %5d/%c%c/%c%c%c %5Zd\n",
  281. i,
  282. q->flags,
  283. atomic_read(&q->use_count),
  284. atomic_read(&q->finalization),
  285. atomic_read(&q->block_count),
  286. atomic_read(&q->block_read) ? 'r' : '-',
  287. atomic_read(&q->block_write) ? 'w' : '-',
  288. waitqueue_active(&q->read_queue) ? 'r' : '-',
  289. waitqueue_active(&q->
  290. write_queue) ? 'w' : '-',
  291. waitqueue_active(&q->
  292. flush_queue) ? 'f' : '-',
  293. DRM_BUFCOUNT(&q->waitlist));
  294. atomic_dec(&q->use_count);
  295. }
  296. if (len > request + offset)
  297. return request;
  298. *eof = 1;
  299. return len - offset;
  300. }
  301. /**
  302. * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
  303. */
  304. static int drm_queues_info(char *buf, char **start, off_t offset, int request,
  305. int *eof, void *data)
  306. {
  307. drm_device_t *dev = (drm_device_t *) data;
  308. int ret;
  309. mutex_lock(&dev->struct_mutex);
  310. ret = drm__queues_info(buf, start, offset, request, eof, data);
  311. mutex_unlock(&dev->struct_mutex);
  312. return ret;
  313. }
  314. /**
  315. * Called when "/proc/dri/.../bufs" is read.
  316. *
  317. * \param buf output buffer.
  318. * \param start start of output data.
  319. * \param offset requested start offset.
  320. * \param request requested number of bytes.
  321. * \param eof whether there is no more data to return.
  322. * \param data private data.
  323. * \return number of written bytes.
  324. */
  325. static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
  326. int *eof, void *data)
  327. {
  328. drm_device_t *dev = (drm_device_t *) data;
  329. int len = 0;
  330. drm_device_dma_t *dma = dev->dma;
  331. int i;
  332. if (!dma || offset > DRM_PROC_LIMIT) {
  333. *eof = 1;
  334. return 0;
  335. }
  336. *start = &buf[offset];
  337. *eof = 0;
  338. DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
  339. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  340. if (dma->bufs[i].buf_count)
  341. DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
  342. i,
  343. dma->bufs[i].buf_size,
  344. dma->bufs[i].buf_count,
  345. atomic_read(&dma->bufs[i]
  346. .freelist.count),
  347. dma->bufs[i].seg_count,
  348. dma->bufs[i].seg_count
  349. * (1 << dma->bufs[i].page_order),
  350. (dma->bufs[i].seg_count
  351. * (1 << dma->bufs[i].page_order))
  352. * PAGE_SIZE / 1024);
  353. }
  354. DRM_PROC_PRINT("\n");
  355. for (i = 0; i < dma->buf_count; i++) {
  356. if (i && !(i % 32))
  357. DRM_PROC_PRINT("\n");
  358. DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
  359. }
  360. DRM_PROC_PRINT("\n");
  361. if (len > request + offset)
  362. return request;
  363. *eof = 1;
  364. return len - offset;
  365. }
  366. /**
  367. * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
  368. */
  369. static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
  370. int *eof, void *data)
  371. {
  372. drm_device_t *dev = (drm_device_t *) data;
  373. int ret;
  374. mutex_lock(&dev->struct_mutex);
  375. ret = drm__bufs_info(buf, start, offset, request, eof, data);
  376. mutex_unlock(&dev->struct_mutex);
  377. return ret;
  378. }
  379. /**
  380. * Called when "/proc/dri/.../clients" is read.
  381. *
  382. * \param buf output buffer.
  383. * \param start start of output data.
  384. * \param offset requested start offset.
  385. * \param request requested number of bytes.
  386. * \param eof whether there is no more data to return.
  387. * \param data private data.
  388. * \return number of written bytes.
  389. */
  390. static int drm__clients_info(char *buf, char **start, off_t offset,
  391. int request, int *eof, void *data)
  392. {
  393. drm_device_t *dev = (drm_device_t *) data;
  394. int len = 0;
  395. drm_file_t *priv;
  396. if (offset > DRM_PROC_LIMIT) {
  397. *eof = 1;
  398. return 0;
  399. }
  400. *start = &buf[offset];
  401. *eof = 0;
  402. DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
  403. for (priv = dev->file_first; priv; priv = priv->next) {
  404. DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
  405. priv->authenticated ? 'y' : 'n',
  406. priv->minor,
  407. priv->pid,
  408. priv->uid, priv->magic, priv->ioctl_count);
  409. }
  410. if (len > request + offset)
  411. return request;
  412. *eof = 1;
  413. return len - offset;
  414. }
  415. /**
  416. * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
  417. */
  418. static int drm_clients_info(char *buf, char **start, off_t offset,
  419. int request, int *eof, void *data)
  420. {
  421. drm_device_t *dev = (drm_device_t *) data;
  422. int ret;
  423. mutex_lock(&dev->struct_mutex);
  424. ret = drm__clients_info(buf, start, offset, request, eof, data);
  425. mutex_unlock(&dev->struct_mutex);
  426. return ret;
  427. }
  428. #if DRM_DEBUG_CODE
  429. static int drm__vma_info(char *buf, char **start, off_t offset, int request,
  430. int *eof, void *data)
  431. {
  432. drm_device_t *dev = (drm_device_t *) data;
  433. int len = 0;
  434. drm_vma_entry_t *pt;
  435. struct vm_area_struct *vma;
  436. #if defined(__i386__)
  437. unsigned int pgprot;
  438. #endif
  439. if (offset > DRM_PROC_LIMIT) {
  440. *eof = 1;
  441. return 0;
  442. }
  443. *start = &buf[offset];
  444. *eof = 0;
  445. DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
  446. atomic_read(&dev->vma_count),
  447. high_memory, virt_to_phys(high_memory));
  448. for (pt = dev->vmalist; pt; pt = pt->next) {
  449. if (!(vma = pt->vma))
  450. continue;
  451. DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
  452. pt->pid,
  453. vma->vm_start,
  454. vma->vm_end,
  455. vma->vm_flags & VM_READ ? 'r' : '-',
  456. vma->vm_flags & VM_WRITE ? 'w' : '-',
  457. vma->vm_flags & VM_EXEC ? 'x' : '-',
  458. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  459. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  460. vma->vm_flags & VM_IO ? 'i' : '-',
  461. vma->vm_pgoff << PAGE_SHIFT);
  462. #if defined(__i386__)
  463. pgprot = pgprot_val(vma->vm_page_prot);
  464. DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
  465. pgprot & _PAGE_PRESENT ? 'p' : '-',
  466. pgprot & _PAGE_RW ? 'w' : 'r',
  467. pgprot & _PAGE_USER ? 'u' : 's',
  468. pgprot & _PAGE_PWT ? 't' : 'b',
  469. pgprot & _PAGE_PCD ? 'u' : 'c',
  470. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  471. pgprot & _PAGE_DIRTY ? 'd' : '-',
  472. pgprot & _PAGE_PSE ? 'm' : 'k',
  473. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  474. #endif
  475. DRM_PROC_PRINT("\n");
  476. }
  477. if (len > request + offset)
  478. return request;
  479. *eof = 1;
  480. return len - offset;
  481. }
  482. static int drm_vma_info(char *buf, char **start, off_t offset, int request,
  483. int *eof, void *data)
  484. {
  485. drm_device_t *dev = (drm_device_t *) data;
  486. int ret;
  487. mutex_lock(&dev->struct_mutex);
  488. ret = drm__vma_info(buf, start, offset, request, eof, data);
  489. mutex_unlock(&dev->struct_mutex);
  490. return ret;
  491. }
  492. #endif