drm_info.c 4.0 KB

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