drm_info.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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;
  50. mutex_lock(&dev->master_mutex);
  51. master = dev->master;
  52. seq_printf(m, "%s", dev->driver->name);
  53. if (dev->dev)
  54. seq_printf(m, " dev=%s", dev_name(dev->dev));
  55. if (master && master->unique)
  56. seq_printf(m, " master=%s", master->unique);
  57. if (dev->unique)
  58. seq_printf(m, " unique=%s", dev->unique);
  59. seq_printf(m, "\n");
  60. mutex_unlock(&dev->master_mutex);
  61. return 0;
  62. }
  63. /**
  64. * Called when "/proc/dri/.../clients" is read.
  65. *
  66. */
  67. int drm_clients_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_file *priv;
  72. kuid_t uid;
  73. seq_printf(m,
  74. "%20s %5s %3s master a %5s %10s\n",
  75. "command",
  76. "pid",
  77. "dev",
  78. "uid",
  79. "magic");
  80. /* dev->filelist is sorted youngest first, but we want to present
  81. * oldest first (i.e. kernel, servers, clients), so walk backwardss.
  82. */
  83. mutex_lock(&dev->filelist_mutex);
  84. list_for_each_entry_reverse(priv, &dev->filelist, lhead) {
  85. struct task_struct *task;
  86. rcu_read_lock(); /* locks pid_task()->comm */
  87. task = pid_task(priv->pid, PIDTYPE_PID);
  88. uid = task ? __task_cred(task)->euid : GLOBAL_ROOT_UID;
  89. seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n",
  90. task ? task->comm : "<unknown>",
  91. pid_vnr(priv->pid),
  92. priv->minor->index,
  93. drm_is_current_master(priv) ? 'y' : 'n',
  94. priv->authenticated ? 'y' : 'n',
  95. from_kuid_munged(seq_user_ns(m), uid),
  96. priv->magic);
  97. rcu_read_unlock();
  98. }
  99. mutex_unlock(&dev->filelist_mutex);
  100. return 0;
  101. }
  102. static int drm_gem_one_name_info(int id, void *ptr, void *data)
  103. {
  104. struct drm_gem_object *obj = ptr;
  105. struct seq_file *m = data;
  106. seq_printf(m, "%6d %8zd %7d %8d\n",
  107. obj->name, obj->size,
  108. obj->handle_count,
  109. atomic_read(&obj->refcount.refcount));
  110. return 0;
  111. }
  112. int drm_gem_name_info(struct seq_file *m, void *data)
  113. {
  114. struct drm_info_node *node = (struct drm_info_node *) m->private;
  115. struct drm_device *dev = node->minor->dev;
  116. seq_printf(m, " name size handles refcount\n");
  117. mutex_lock(&dev->object_name_lock);
  118. idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
  119. mutex_unlock(&dev->object_name_lock);
  120. return 0;
  121. }