drm_proc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. {
  61. "name", drm_name_info}, {
  62. "mem", drm_mem_info}, {
  63. "vm", drm_vm_info}, {
  64. "clients", drm_clients_info}, {
  65. "queues", drm_queues_info}, {
  66. "bufs", drm_bufs_info},
  67. #if DRM_DEBUG_CODE
  68. {
  69. "vma", drm_vma_info},
  70. #endif
  71. };
  72. #define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
  73. /**
  74. * Initialize the DRI proc filesystem for a device.
  75. *
  76. * \param dev DRM device.
  77. * \param minor device minor number.
  78. * \param root DRI proc dir entry.
  79. * \param dev_root resulting DRI device proc dir entry.
  80. * \return root entry pointer on success, or NULL on failure.
  81. *
  82. * Create the DRI proc root entry "/proc/dri", the device proc root entry
  83. * "/proc/dri/%minor%/", and each entry in proc_list as
  84. * "/proc/dri/%minor%/%name%".
  85. */
  86. int drm_proc_init(drm_device_t * dev, int minor,
  87. struct proc_dir_entry *root, struct proc_dir_entry **dev_root)
  88. {
  89. struct proc_dir_entry *ent;
  90. int i, j;
  91. char name[64];
  92. sprintf(name, "%d", minor);
  93. *dev_root = create_proc_entry(name, S_IFDIR, root);
  94. if (!*dev_root) {
  95. DRM_ERROR("Cannot create /proc/dri/%s\n", name);
  96. return -1;
  97. }
  98. for (i = 0; i < DRM_PROC_ENTRIES; i++) {
  99. ent = create_proc_entry(drm_proc_list[i].name,
  100. S_IFREG | S_IRUGO, *dev_root);
  101. if (!ent) {
  102. DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
  103. name, drm_proc_list[i].name);
  104. for (j = 0; j < i; j++)
  105. remove_proc_entry(drm_proc_list[i].name,
  106. *dev_root);
  107. remove_proc_entry(name, root);
  108. return -1;
  109. }
  110. ent->read_proc = drm_proc_list[i].f;
  111. ent->data = dev;
  112. }
  113. return 0;
  114. }
  115. /**
  116. * Cleanup the proc filesystem resources.
  117. *
  118. * \param minor device minor number.
  119. * \param root DRI proc dir entry.
  120. * \param dev_root DRI device proc dir entry.
  121. * \return always zero.
  122. *
  123. * Remove all proc entries created by proc_init().
  124. */
  125. int drm_proc_cleanup(int minor, struct proc_dir_entry *root,
  126. struct proc_dir_entry *dev_root)
  127. {
  128. int i;
  129. char name[64];
  130. if (!root || !dev_root)
  131. return 0;
  132. for (i = 0; i < DRM_PROC_ENTRIES; i++)
  133. remove_proc_entry(drm_proc_list[i].name, dev_root);
  134. sprintf(name, "%d", minor);
  135. remove_proc_entry(name, root);
  136. return 0;
  137. }
  138. /**
  139. * Called when "/proc/dri/.../name" is read.
  140. *
  141. * \param buf output buffer.
  142. * \param start start of output data.
  143. * \param offset requested start offset.
  144. * \param request requested number of bytes.
  145. * \param eof whether there is no more data to return.
  146. * \param data private data.
  147. * \return number of written bytes.
  148. *
  149. * Prints the device name together with the bus id if available.
  150. */
  151. static int drm_name_info(char *buf, char **start, off_t offset, int request,
  152. int *eof, void *data)
  153. {
  154. drm_device_t *dev = (drm_device_t *) data;
  155. int len = 0;
  156. if (offset > DRM_PROC_LIMIT) {
  157. *eof = 1;
  158. return 0;
  159. }
  160. *start = &buf[offset];
  161. *eof = 0;
  162. if (dev->unique) {
  163. DRM_PROC_PRINT("%s %s %s\n",
  164. dev->driver->pci_driver.name,
  165. pci_name(dev->pdev), dev->unique);
  166. } else {
  167. DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
  168. pci_name(dev->pdev));
  169. }
  170. if (len > request + offset)
  171. return request;
  172. *eof = 1;
  173. return len - offset;
  174. }
  175. /**
  176. * Called when "/proc/dri/.../vm" is read.
  177. *
  178. * \param buf output buffer.
  179. * \param start start of output data.
  180. * \param offset requested start offset.
  181. * \param request requested number of bytes.
  182. * \param eof whether there is no more data to return.
  183. * \param data private data.
  184. * \return number of written bytes.
  185. *
  186. * Prints information about all mappings in drm_device::maplist.
  187. */
  188. static int drm__vm_info(char *buf, char **start, off_t offset, int request,
  189. int *eof, void *data)
  190. {
  191. drm_device_t *dev = (drm_device_t *) data;
  192. int len = 0;
  193. drm_map_t *map;
  194. drm_map_list_t *r_list;
  195. struct list_head *list;
  196. /* Hardcoded from _DRM_FRAME_BUFFER,
  197. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  198. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  199. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  200. const char *type;
  201. int i;
  202. if (offset > DRM_PROC_LIMIT) {
  203. *eof = 1;
  204. return 0;
  205. }
  206. *start = &buf[offset];
  207. *eof = 0;
  208. DRM_PROC_PRINT("slot offset size type flags "
  209. "address mtrr\n\n");
  210. i = 0;
  211. if (dev->maplist != NULL)
  212. list_for_each(list, &dev->maplist->head) {
  213. r_list = list_entry(list, drm_map_list_t, head);
  214. map = r_list->map;
  215. if (!map)
  216. continue;
  217. if (map->type < 0 || map->type > 5)
  218. type = "??";
  219. else
  220. type = types[map->type];
  221. DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08x ",
  222. i,
  223. map->offset,
  224. map->size, type, map->flags, r_list->user_token);
  225. if (map->mtrr < 0) {
  226. DRM_PROC_PRINT("none\n");
  227. } else {
  228. DRM_PROC_PRINT("%4d\n", map->mtrr);
  229. }
  230. i++;
  231. }
  232. if (len > request + offset)
  233. return request;
  234. *eof = 1;
  235. return len - offset;
  236. }
  237. /**
  238. * Simply calls _vm_info() while holding the drm_device::struct_sem lock.
  239. */
  240. static int drm_vm_info(char *buf, char **start, off_t offset, int request,
  241. int *eof, void *data)
  242. {
  243. drm_device_t *dev = (drm_device_t *) data;
  244. int ret;
  245. down(&dev->struct_sem);
  246. ret = drm__vm_info(buf, start, offset, request, eof, data);
  247. up(&dev->struct_sem);
  248. return ret;
  249. }
  250. /**
  251. * Called when "/proc/dri/.../queues" is read.
  252. *
  253. * \param buf output buffer.
  254. * \param start start of output data.
  255. * \param offset requested start offset.
  256. * \param request requested number of bytes.
  257. * \param eof whether there is no more data to return.
  258. * \param data private data.
  259. * \return number of written bytes.
  260. */
  261. static int drm__queues_info(char *buf, char **start, off_t offset,
  262. int request, int *eof, void *data)
  263. {
  264. drm_device_t *dev = (drm_device_t *) data;
  265. int len = 0;
  266. int i;
  267. drm_queue_t *q;
  268. if (offset > DRM_PROC_LIMIT) {
  269. *eof = 1;
  270. return 0;
  271. }
  272. *start = &buf[offset];
  273. *eof = 0;
  274. DRM_PROC_PRINT(" ctx/flags use fin"
  275. " blk/rw/rwf wait flushed queued"
  276. " locks\n\n");
  277. for (i = 0; i < dev->queue_count; i++) {
  278. q = dev->queuelist[i];
  279. atomic_inc(&q->use_count);
  280. DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
  281. "%5d/0x%03x %5d %5d"
  282. " %5d/%c%c/%c%c%c %5Zd\n",
  283. i,
  284. q->flags,
  285. atomic_read(&q->use_count),
  286. atomic_read(&q->finalization),
  287. atomic_read(&q->block_count),
  288. atomic_read(&q->block_read) ? 'r' : '-',
  289. atomic_read(&q->block_write) ? 'w' : '-',
  290. waitqueue_active(&q->read_queue) ? 'r' : '-',
  291. waitqueue_active(&q->
  292. write_queue) ? 'w' : '-',
  293. waitqueue_active(&q->
  294. flush_queue) ? 'f' : '-',
  295. DRM_BUFCOUNT(&q->waitlist));
  296. atomic_dec(&q->use_count);
  297. }
  298. if (len > request + offset)
  299. return request;
  300. *eof = 1;
  301. return len - offset;
  302. }
  303. /**
  304. * Simply calls _queues_info() while holding the drm_device::struct_sem lock.
  305. */
  306. static int drm_queues_info(char *buf, char **start, off_t offset, int request,
  307. int *eof, void *data)
  308. {
  309. drm_device_t *dev = (drm_device_t *) data;
  310. int ret;
  311. down(&dev->struct_sem);
  312. ret = drm__queues_info(buf, start, offset, request, eof, data);
  313. up(&dev->struct_sem);
  314. return ret;
  315. }
  316. /**
  317. * Called when "/proc/dri/.../bufs" is read.
  318. *
  319. * \param buf output buffer.
  320. * \param start start of output data.
  321. * \param offset requested start offset.
  322. * \param request requested number of bytes.
  323. * \param eof whether there is no more data to return.
  324. * \param data private data.
  325. * \return number of written bytes.
  326. */
  327. static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
  328. int *eof, void *data)
  329. {
  330. drm_device_t *dev = (drm_device_t *) data;
  331. int len = 0;
  332. drm_device_dma_t *dma = dev->dma;
  333. int i;
  334. if (!dma || offset > DRM_PROC_LIMIT) {
  335. *eof = 1;
  336. return 0;
  337. }
  338. *start = &buf[offset];
  339. *eof = 0;
  340. DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
  341. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  342. if (dma->bufs[i].buf_count)
  343. DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
  344. i,
  345. dma->bufs[i].buf_size,
  346. dma->bufs[i].buf_count,
  347. atomic_read(&dma->bufs[i]
  348. .freelist.count),
  349. dma->bufs[i].seg_count,
  350. dma->bufs[i].seg_count
  351. * (1 << dma->bufs[i].page_order),
  352. (dma->bufs[i].seg_count
  353. * (1 << dma->bufs[i].page_order))
  354. * PAGE_SIZE / 1024);
  355. }
  356. DRM_PROC_PRINT("\n");
  357. for (i = 0; i < dma->buf_count; i++) {
  358. if (i && !(i % 32))
  359. DRM_PROC_PRINT("\n");
  360. DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
  361. }
  362. DRM_PROC_PRINT("\n");
  363. if (len > request + offset)
  364. return request;
  365. *eof = 1;
  366. return len - offset;
  367. }
  368. /**
  369. * Simply calls _bufs_info() while holding the drm_device::struct_sem lock.
  370. */
  371. static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
  372. int *eof, void *data)
  373. {
  374. drm_device_t *dev = (drm_device_t *) data;
  375. int ret;
  376. down(&dev->struct_sem);
  377. ret = drm__bufs_info(buf, start, offset, request, eof, data);
  378. up(&dev->struct_sem);
  379. return ret;
  380. }
  381. /**
  382. * Called when "/proc/dri/.../clients" is read.
  383. *
  384. * \param buf output buffer.
  385. * \param start start of output data.
  386. * \param offset requested start offset.
  387. * \param request requested number of bytes.
  388. * \param eof whether there is no more data to return.
  389. * \param data private data.
  390. * \return number of written bytes.
  391. */
  392. static int drm__clients_info(char *buf, char **start, off_t offset,
  393. int request, int *eof, void *data)
  394. {
  395. drm_device_t *dev = (drm_device_t *) data;
  396. int len = 0;
  397. drm_file_t *priv;
  398. if (offset > DRM_PROC_LIMIT) {
  399. *eof = 1;
  400. return 0;
  401. }
  402. *start = &buf[offset];
  403. *eof = 0;
  404. DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
  405. for (priv = dev->file_first; priv; priv = priv->next) {
  406. DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
  407. priv->authenticated ? 'y' : 'n',
  408. priv->minor,
  409. priv->pid,
  410. priv->uid, priv->magic, priv->ioctl_count);
  411. }
  412. if (len > request + offset)
  413. return request;
  414. *eof = 1;
  415. return len - offset;
  416. }
  417. /**
  418. * Simply calls _clients_info() while holding the drm_device::struct_sem lock.
  419. */
  420. static int drm_clients_info(char *buf, char **start, off_t offset,
  421. int request, int *eof, void *data)
  422. {
  423. drm_device_t *dev = (drm_device_t *) data;
  424. int ret;
  425. down(&dev->struct_sem);
  426. ret = drm__clients_info(buf, start, offset, request, eof, data);
  427. up(&dev->struct_sem);
  428. return ret;
  429. }
  430. #if DRM_DEBUG_CODE
  431. static int drm__vma_info(char *buf, char **start, off_t offset, int request,
  432. int *eof, void *data)
  433. {
  434. drm_device_t *dev = (drm_device_t *) data;
  435. int len = 0;
  436. drm_vma_entry_t *pt;
  437. struct vm_area_struct *vma;
  438. #if defined(__i386__)
  439. unsigned int pgprot;
  440. #endif
  441. if (offset > DRM_PROC_LIMIT) {
  442. *eof = 1;
  443. return 0;
  444. }
  445. *start = &buf[offset];
  446. *eof = 0;
  447. DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
  448. atomic_read(&dev->vma_count),
  449. high_memory, virt_to_phys(high_memory));
  450. for (pt = dev->vmalist; pt; pt = pt->next) {
  451. if (!(vma = pt->vma))
  452. continue;
  453. DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
  454. pt->pid,
  455. vma->vm_start,
  456. vma->vm_end,
  457. vma->vm_flags & VM_READ ? 'r' : '-',
  458. vma->vm_flags & VM_WRITE ? 'w' : '-',
  459. vma->vm_flags & VM_EXEC ? 'x' : '-',
  460. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  461. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  462. vma->vm_flags & VM_IO ? 'i' : '-',
  463. VM_OFFSET(vma));
  464. #if defined(__i386__)
  465. pgprot = pgprot_val(vma->vm_page_prot);
  466. DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
  467. pgprot & _PAGE_PRESENT ? 'p' : '-',
  468. pgprot & _PAGE_RW ? 'w' : 'r',
  469. pgprot & _PAGE_USER ? 'u' : 's',
  470. pgprot & _PAGE_PWT ? 't' : 'b',
  471. pgprot & _PAGE_PCD ? 'u' : 'c',
  472. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  473. pgprot & _PAGE_DIRTY ? 'd' : '-',
  474. pgprot & _PAGE_PSE ? 'm' : 'k',
  475. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  476. #endif
  477. DRM_PROC_PRINT("\n");
  478. }
  479. if (len > request + offset)
  480. return request;
  481. *eof = 1;
  482. return len - offset;
  483. }
  484. static int drm_vma_info(char *buf, char **start, off_t offset, int request,
  485. int *eof, void *data)
  486. {
  487. drm_device_t *dev = (drm_device_t *) data;
  488. int ret;
  489. down(&dev->struct_sem);
  490. ret = drm__vma_info(buf, start, offset, request, eof, data);
  491. up(&dev->struct_sem);
  492. return ret;
  493. }
  494. #endif