drm_proc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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_minor *minor, int minor_id,
  85. struct proc_dir_entry *root)
  86. {
  87. struct proc_dir_entry *ent;
  88. int i, j;
  89. char name[64];
  90. sprintf(name, "%d", minor_id);
  91. minor->dev_root = proc_mkdir(name, root);
  92. if (!minor->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, minor->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. minor->dev_root);
  105. remove_proc_entry(name, root);
  106. minor->dev_root = NULL;
  107. return -1;
  108. }
  109. ent->read_proc = drm_proc_list[i].f;
  110. ent->data = minor;
  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(struct drm_minor *minor, struct proc_dir_entry *root)
  125. {
  126. int i;
  127. char name[64];
  128. if (!root || !minor->dev_root)
  129. return 0;
  130. for (i = 0; i < DRM_PROC_ENTRIES; i++)
  131. remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
  132. sprintf(name, "%d", minor->index);
  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_minor *minor = (struct drm_minor *) data;
  153. struct drm_device *dev = minor->dev;
  154. int len = 0;
  155. if (offset > DRM_PROC_LIMIT) {
  156. *eof = 1;
  157. return 0;
  158. }
  159. *start = &buf[offset];
  160. *eof = 0;
  161. if (dev->unique) {
  162. DRM_PROC_PRINT("%s %s %s\n",
  163. dev->driver->pci_driver.name,
  164. pci_name(dev->pdev), dev->unique);
  165. } else {
  166. DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
  167. pci_name(dev->pdev));
  168. }
  169. if (len > request + offset)
  170. return request;
  171. *eof = 1;
  172. return len - offset;
  173. }
  174. /**
  175. * Called when "/proc/dri/.../vm" is read.
  176. *
  177. * \param buf output buffer.
  178. * \param start start of output data.
  179. * \param offset requested start offset.
  180. * \param request requested number of bytes.
  181. * \param eof whether there is no more data to return.
  182. * \param data private data.
  183. * \return number of written bytes.
  184. *
  185. * Prints information about all mappings in drm_device::maplist.
  186. */
  187. static int drm__vm_info(char *buf, char **start, off_t offset, int request,
  188. int *eof, void *data)
  189. {
  190. struct drm_minor *minor = (struct drm_minor *) data;
  191. struct drm_device *dev = minor->dev;
  192. int len = 0;
  193. struct drm_map *map;
  194. struct drm_map_list *r_list;
  195. /* Hardcoded from _DRM_FRAME_BUFFER,
  196. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  197. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  198. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  199. const char *type;
  200. int i;
  201. if (offset > DRM_PROC_LIMIT) {
  202. *eof = 1;
  203. return 0;
  204. }
  205. *start = &buf[offset];
  206. *eof = 0;
  207. DRM_PROC_PRINT("slot offset size type flags "
  208. "address mtrr\n\n");
  209. i = 0;
  210. list_for_each_entry(r_list, &dev->maplist, head) {
  211. map = r_list->map;
  212. if (!map)
  213. continue;
  214. if (map->type < 0 || map->type > 5)
  215. type = "??";
  216. else
  217. type = types[map->type];
  218. DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
  219. i,
  220. map->offset,
  221. map->size, type, map->flags,
  222. (unsigned long) 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. struct drm_minor *minor = (struct drm_minor *) data;
  242. struct drm_device *dev = minor->dev;
  243. int ret;
  244. mutex_lock(&dev->struct_mutex);
  245. ret = drm__vm_info(buf, start, offset, request, eof, data);
  246. mutex_unlock(&dev->struct_mutex);
  247. return ret;
  248. }
  249. /**
  250. * Called when "/proc/dri/.../queues" is read.
  251. *
  252. * \param buf output buffer.
  253. * \param start start of output data.
  254. * \param offset requested start offset.
  255. * \param request requested number of bytes.
  256. * \param eof whether there is no more data to return.
  257. * \param data private data.
  258. * \return number of written bytes.
  259. */
  260. static int drm__queues_info(char *buf, char **start, off_t offset,
  261. int request, int *eof, void *data)
  262. {
  263. struct drm_minor *minor = (struct drm_minor *) data;
  264. struct drm_device *dev = minor->dev;
  265. int len = 0;
  266. int i;
  267. struct drm_queue *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_mutex lock.
  305. */
  306. static int drm_queues_info(char *buf, char **start, off_t offset, int request,
  307. int *eof, void *data)
  308. {
  309. struct drm_minor *minor = (struct drm_minor *) data;
  310. struct drm_device *dev = minor->dev;
  311. int ret;
  312. mutex_lock(&dev->struct_mutex);
  313. ret = drm__queues_info(buf, start, offset, request, eof, data);
  314. mutex_unlock(&dev->struct_mutex);
  315. return ret;
  316. }
  317. /**
  318. * Called when "/proc/dri/.../bufs" is read.
  319. *
  320. * \param buf output buffer.
  321. * \param start start of output data.
  322. * \param offset requested start offset.
  323. * \param request requested number of bytes.
  324. * \param eof whether there is no more data to return.
  325. * \param data private data.
  326. * \return number of written bytes.
  327. */
  328. static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
  329. int *eof, void *data)
  330. {
  331. struct drm_minor *minor = (struct drm_minor *) data;
  332. struct drm_device *dev = minor->dev;
  333. int len = 0;
  334. struct drm_device_dma *dma = dev->dma;
  335. int i;
  336. if (!dma || offset > DRM_PROC_LIMIT) {
  337. *eof = 1;
  338. return 0;
  339. }
  340. *start = &buf[offset];
  341. *eof = 0;
  342. DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
  343. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  344. if (dma->bufs[i].buf_count)
  345. DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
  346. i,
  347. dma->bufs[i].buf_size,
  348. dma->bufs[i].buf_count,
  349. atomic_read(&dma->bufs[i]
  350. .freelist.count),
  351. dma->bufs[i].seg_count,
  352. dma->bufs[i].seg_count
  353. * (1 << dma->bufs[i].page_order),
  354. (dma->bufs[i].seg_count
  355. * (1 << dma->bufs[i].page_order))
  356. * PAGE_SIZE / 1024);
  357. }
  358. DRM_PROC_PRINT("\n");
  359. for (i = 0; i < dma->buf_count; i++) {
  360. if (i && !(i % 32))
  361. DRM_PROC_PRINT("\n");
  362. DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
  363. }
  364. DRM_PROC_PRINT("\n");
  365. if (len > request + offset)
  366. return request;
  367. *eof = 1;
  368. return len - offset;
  369. }
  370. /**
  371. * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
  372. */
  373. static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
  374. int *eof, void *data)
  375. {
  376. struct drm_minor *minor = (struct drm_minor *) data;
  377. struct drm_device *dev = minor->dev;
  378. int ret;
  379. mutex_lock(&dev->struct_mutex);
  380. ret = drm__bufs_info(buf, start, offset, request, eof, data);
  381. mutex_unlock(&dev->struct_mutex);
  382. return ret;
  383. }
  384. /**
  385. * Called when "/proc/dri/.../clients" is read.
  386. *
  387. * \param buf output buffer.
  388. * \param start start of output data.
  389. * \param offset requested start offset.
  390. * \param request requested number of bytes.
  391. * \param eof whether there is no more data to return.
  392. * \param data private data.
  393. * \return number of written bytes.
  394. */
  395. static int drm__clients_info(char *buf, char **start, off_t offset,
  396. int request, int *eof, void *data)
  397. {
  398. struct drm_minor *minor = (struct drm_minor *) data;
  399. struct drm_device *dev = minor->dev;
  400. int len = 0;
  401. struct drm_file *priv;
  402. if (offset > DRM_PROC_LIMIT) {
  403. *eof = 1;
  404. return 0;
  405. }
  406. *start = &buf[offset];
  407. *eof = 0;
  408. DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
  409. list_for_each_entry(priv, &dev->filelist, lhead) {
  410. DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
  411. priv->authenticated ? 'y' : 'n',
  412. priv->minor->index,
  413. priv->pid,
  414. priv->uid, priv->magic, priv->ioctl_count);
  415. }
  416. if (len > request + offset)
  417. return request;
  418. *eof = 1;
  419. return len - offset;
  420. }
  421. /**
  422. * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
  423. */
  424. static int drm_clients_info(char *buf, char **start, off_t offset,
  425. int request, int *eof, void *data)
  426. {
  427. struct drm_minor *minor = (struct drm_minor *) data;
  428. struct drm_device *dev = minor->dev;
  429. int ret;
  430. mutex_lock(&dev->struct_mutex);
  431. ret = drm__clients_info(buf, start, offset, request, eof, data);
  432. mutex_unlock(&dev->struct_mutex);
  433. return ret;
  434. }
  435. #if DRM_DEBUG_CODE
  436. static int drm__vma_info(char *buf, char **start, off_t offset, int request,
  437. int *eof, void *data)
  438. {
  439. struct drm_minor *minor = (struct drm_minor *) data;
  440. struct drm_device *dev = minor->dev;
  441. int len = 0;
  442. struct drm_vma_entry *pt;
  443. struct vm_area_struct *vma;
  444. #if defined(__i386__)
  445. unsigned int pgprot;
  446. #endif
  447. if (offset > DRM_PROC_LIMIT) {
  448. *eof = 1;
  449. return 0;
  450. }
  451. *start = &buf[offset];
  452. *eof = 0;
  453. DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
  454. atomic_read(&dev->vma_count),
  455. high_memory, virt_to_phys(high_memory));
  456. list_for_each_entry(pt, &dev->vmalist, head) {
  457. if (!(vma = pt->vma))
  458. continue;
  459. DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
  460. pt->pid,
  461. vma->vm_start,
  462. vma->vm_end,
  463. vma->vm_flags & VM_READ ? 'r' : '-',
  464. vma->vm_flags & VM_WRITE ? 'w' : '-',
  465. vma->vm_flags & VM_EXEC ? 'x' : '-',
  466. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  467. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  468. vma->vm_flags & VM_IO ? 'i' : '-',
  469. vma->vm_pgoff);
  470. #if defined(__i386__)
  471. pgprot = pgprot_val(vma->vm_page_prot);
  472. DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
  473. pgprot & _PAGE_PRESENT ? 'p' : '-',
  474. pgprot & _PAGE_RW ? 'w' : 'r',
  475. pgprot & _PAGE_USER ? 'u' : 's',
  476. pgprot & _PAGE_PWT ? 't' : 'b',
  477. pgprot & _PAGE_PCD ? 'u' : 'c',
  478. pgprot & _PAGE_ACCESSED ? 'a' : '-',
  479. pgprot & _PAGE_DIRTY ? 'd' : '-',
  480. pgprot & _PAGE_PSE ? 'm' : 'k',
  481. pgprot & _PAGE_GLOBAL ? 'g' : 'l');
  482. #endif
  483. DRM_PROC_PRINT("\n");
  484. }
  485. if (len > request + offset)
  486. return request;
  487. *eof = 1;
  488. return len - offset;
  489. }
  490. static int drm_vma_info(char *buf, char **start, off_t offset, int request,
  491. int *eof, void *data)
  492. {
  493. struct drm_minor *minor = (struct drm_minor *) data;
  494. struct drm_device *dev = minor->dev;
  495. int ret;
  496. mutex_lock(&dev->struct_mutex);
  497. ret = drm__vma_info(buf, start, offset, request, eof, data);
  498. mutex_unlock(&dev->struct_mutex);
  499. return ret;
  500. }
  501. #endif