drm_proc.c 15 KB

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