drm_info.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * \file drm_info.c
  3. * DRM info file implementations
  4. *
  5. * \author Ben Gamari <bgamari@gmail.com>
  6. */
  7. /*
  8. * Created: Sun Dec 21 13:09:50 2008 by bgamari@gmail.com
  9. *
  10. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  11. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  12. * Copyright 2008 Ben Gamari <bgamari@gmail.com>
  13. * All Rights Reserved.
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a
  16. * copy of this software and associated documentation files (the "Software"),
  17. * to deal in the Software without restriction, including without limitation
  18. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  19. * and/or sell copies of the Software, and to permit persons to whom the
  20. * Software is furnished to do so, subject to the following conditions:
  21. *
  22. * The above copyright notice and this permission notice (including the next
  23. * paragraph) shall be included in all copies or substantial portions of the
  24. * Software.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  29. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  30. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  31. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  32. * OTHER DEALINGS IN THE SOFTWARE.
  33. */
  34. #include <linux/seq_file.h>
  35. #include <drm/drmP.h>
  36. #include <drm/drm_gem.h>
  37. #include "drm_internal.h"
  38. #include "drm_legacy.h"
  39. /**
  40. * Called when "/proc/dri/.../name" is read.
  41. *
  42. * Prints the device name together with the bus id if available.
  43. */
  44. int drm_name_info(struct seq_file *m, void *data)
  45. {
  46. struct drm_info_node *node = (struct drm_info_node *) m->private;
  47. struct drm_minor *minor = node->minor;
  48. struct drm_device *dev = minor->dev;
  49. struct drm_master *master = minor->master;
  50. if (!master)
  51. return 0;
  52. if (master->unique) {
  53. seq_printf(m, "%s %s %s\n",
  54. dev->driver->name,
  55. dev_name(dev->dev), master->unique);
  56. } else {
  57. seq_printf(m, "%s %s\n",
  58. dev->driver->name, dev_name(dev->dev));
  59. }
  60. return 0;
  61. }
  62. /**
  63. * Called when "/proc/dri/.../vm" is read.
  64. *
  65. * Prints information about all mappings in drm_device::maplist.
  66. */
  67. int drm_vm_info(struct seq_file *m, void *data)
  68. {
  69. struct drm_info_node *node = (struct drm_info_node *) m->private;
  70. struct drm_device *dev = node->minor->dev;
  71. struct drm_local_map *map;
  72. struct drm_map_list *r_list;
  73. /* Hardcoded from _DRM_FRAME_BUFFER,
  74. _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  75. _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  76. const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  77. const char *type;
  78. int i;
  79. mutex_lock(&dev->struct_mutex);
  80. seq_printf(m, "slot offset size type flags address mtrr\n\n");
  81. i = 0;
  82. list_for_each_entry(r_list, &dev->maplist, head) {
  83. map = r_list->map;
  84. if (!map)
  85. continue;
  86. if (map->type < 0 || map->type > 5)
  87. type = "??";
  88. else
  89. type = types[map->type];
  90. seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ",
  91. i,
  92. (unsigned long long)map->offset,
  93. map->size, type, map->flags,
  94. (unsigned long) r_list->user_token);
  95. if (map->mtrr < 0)
  96. seq_printf(m, "none\n");
  97. else
  98. seq_printf(m, "%4d\n", map->mtrr);
  99. i++;
  100. }
  101. mutex_unlock(&dev->struct_mutex);
  102. return 0;
  103. }
  104. /**
  105. * Called when "/proc/dri/.../bufs" is read.
  106. */
  107. int drm_bufs_info(struct seq_file *m, void *data)
  108. {
  109. struct drm_info_node *node = (struct drm_info_node *) m->private;
  110. struct drm_device *dev = node->minor->dev;
  111. struct drm_device_dma *dma;
  112. int i, seg_pages;
  113. mutex_lock(&dev->struct_mutex);
  114. dma = dev->dma;
  115. if (!dma) {
  116. mutex_unlock(&dev->struct_mutex);
  117. return 0;
  118. }
  119. seq_printf(m, " o size count free segs pages kB\n\n");
  120. for (i = 0; i <= DRM_MAX_ORDER; i++) {
  121. if (dma->bufs[i].buf_count) {
  122. seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
  123. seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
  124. i,
  125. dma->bufs[i].buf_size,
  126. dma->bufs[i].buf_count,
  127. 0,
  128. dma->bufs[i].seg_count,
  129. seg_pages,
  130. seg_pages * PAGE_SIZE / 1024);
  131. }
  132. }
  133. seq_printf(m, "\n");
  134. for (i = 0; i < dma->buf_count; i++) {
  135. if (i && !(i % 32))
  136. seq_printf(m, "\n");
  137. seq_printf(m, " %d", dma->buflist[i]->list);
  138. }
  139. seq_printf(m, "\n");
  140. mutex_unlock(&dev->struct_mutex);
  141. return 0;
  142. }
  143. /**
  144. * Called when "/proc/dri/.../clients" is read.
  145. *
  146. */
  147. int drm_clients_info(struct seq_file *m, void *data)
  148. {
  149. struct drm_info_node *node = (struct drm_info_node *) m->private;
  150. struct drm_device *dev = node->minor->dev;
  151. struct drm_file *priv;
  152. seq_printf(m,
  153. "%20s %5s %3s master a %5s %10s\n",
  154. "command",
  155. "pid",
  156. "dev",
  157. "uid",
  158. "magic");
  159. /* dev->filelist is sorted youngest first, but we want to present
  160. * oldest first (i.e. kernel, servers, clients), so walk backwardss.
  161. */
  162. mutex_lock(&dev->struct_mutex);
  163. list_for_each_entry_reverse(priv, &dev->filelist, lhead) {
  164. struct task_struct *task;
  165. rcu_read_lock(); /* locks pid_task()->comm */
  166. task = pid_task(priv->pid, PIDTYPE_PID);
  167. seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n",
  168. task ? task->comm : "<unknown>",
  169. pid_vnr(priv->pid),
  170. priv->minor->index,
  171. priv->is_master ? 'y' : 'n',
  172. priv->authenticated ? 'y' : 'n',
  173. from_kuid_munged(seq_user_ns(m), priv->uid),
  174. priv->magic);
  175. rcu_read_unlock();
  176. }
  177. mutex_unlock(&dev->struct_mutex);
  178. return 0;
  179. }
  180. static int drm_gem_one_name_info(int id, void *ptr, void *data)
  181. {
  182. struct drm_gem_object *obj = ptr;
  183. struct seq_file *m = data;
  184. seq_printf(m, "%6d %8zd %7d %8d\n",
  185. obj->name, obj->size,
  186. obj->handle_count,
  187. atomic_read(&obj->refcount.refcount));
  188. return 0;
  189. }
  190. int drm_gem_name_info(struct seq_file *m, void *data)
  191. {
  192. struct drm_info_node *node = (struct drm_info_node *) m->private;
  193. struct drm_device *dev = node->minor->dev;
  194. seq_printf(m, " name size handles refcount\n");
  195. mutex_lock(&dev->object_name_lock);
  196. idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
  197. mutex_unlock(&dev->object_name_lock);
  198. return 0;
  199. }