Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 1 | /** |
| 2 | * \file drm_info.c |
| 3 | * DRM info file implementations |
| 4 | * |
| 5 | * \author Ben Gamari <bgamari@gmail.com> |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Created: Sun Dec 21 13:09:50 2008 by bgamari@gmail.com |
| 10 | * |
| 11 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. |
| 12 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 13 | * Copyright 2008 Ben Gamari <bgamari@gmail.com> |
| 14 | * All Rights Reserved. |
| 15 | * |
| 16 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 17 | * copy of this software and associated documentation files (the "Software"), |
| 18 | * to deal in the Software without restriction, including without limitation |
| 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 20 | * and/or sell copies of the Software, and to permit persons to whom the |
| 21 | * Software is furnished to do so, subject to the following conditions: |
| 22 | * |
| 23 | * The above copyright notice and this permission notice (including the next |
| 24 | * paragraph) shall be included in all copies or substantial portions of the |
| 25 | * Software. |
| 26 | * |
| 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 30 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 31 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 32 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 33 | * OTHER DEALINGS IN THE SOFTWARE. |
| 34 | */ |
| 35 | |
| 36 | #include <linux/seq_file.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/drmP.h> |
Daniel Vetter | d9fc941 | 2014-09-23 15:46:53 +0200 | [diff] [blame] | 38 | #include <drm/drm_gem.h> |
| 39 | |
Ville Syrjälä | 43fc884 | 2015-03-13 14:51:25 +0200 | [diff] [blame] | 40 | #include "drm_internal.h" |
Daniel Vetter | ba8286f | 2014-09-11 07:43:25 +0200 | [diff] [blame] | 41 | #include "drm_legacy.h" |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Called when "/proc/dri/.../name" is read. |
| 45 | * |
| 46 | * Prints the device name together with the bus id if available. |
| 47 | */ |
| 48 | int drm_name_info(struct seq_file *m, void *data) |
| 49 | { |
| 50 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 51 | struct drm_minor *minor = node->minor; |
| 52 | struct drm_device *dev = minor->dev; |
Daniel Vetter | 95c081c | 2016-06-21 10:54:12 +0200 | [diff] [blame] | 53 | struct drm_master *master; |
| 54 | |
| 55 | mutex_lock(&dev->master_mutex); |
| 56 | master = dev->master; |
Chris Wilson | e4245ea | 2016-06-20 19:53:33 +0100 | [diff] [blame] | 57 | seq_printf(m, "%s", dev->driver->name); |
| 58 | if (dev->dev) |
| 59 | seq_printf(m, " dev=%s", dev_name(dev->dev)); |
| 60 | if (master && master->unique) |
| 61 | seq_printf(m, " master=%s", master->unique); |
| 62 | if (dev->unique) |
| 63 | seq_printf(m, " unique=%s", dev->unique); |
| 64 | seq_printf(m, "\n"); |
Daniel Vetter | 95c081c | 2016-06-21 10:54:12 +0200 | [diff] [blame] | 65 | mutex_unlock(&dev->master_mutex); |
Chris Wilson | e4245ea | 2016-06-20 19:53:33 +0100 | [diff] [blame] | 66 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | /** |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 71 | * Called when "/proc/dri/.../clients" is read. |
| 72 | * |
| 73 | */ |
| 74 | int drm_clients_info(struct seq_file *m, void *data) |
| 75 | { |
| 76 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 77 | struct drm_device *dev = node->minor->dev; |
| 78 | struct drm_file *priv; |
David Herrmann | 75ae95a7 | 2016-09-01 14:48:32 +0200 | [diff] [blame] | 79 | kuid_t uid; |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 80 | |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 81 | seq_printf(m, |
| 82 | "%20s %5s %3s master a %5s %10s\n", |
| 83 | "command", |
| 84 | "pid", |
| 85 | "dev", |
| 86 | "uid", |
| 87 | "magic"); |
| 88 | |
| 89 | /* dev->filelist is sorted youngest first, but we want to present |
| 90 | * oldest first (i.e. kernel, servers, clients), so walk backwardss. |
| 91 | */ |
Daniel Vetter | 1d2ac40 | 2016-04-26 19:29:41 +0200 | [diff] [blame] | 92 | mutex_lock(&dev->filelist_mutex); |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 93 | list_for_each_entry_reverse(priv, &dev->filelist, lhead) { |
| 94 | struct task_struct *task; |
| 95 | |
| 96 | rcu_read_lock(); /* locks pid_task()->comm */ |
| 97 | task = pid_task(priv->pid, PIDTYPE_PID); |
David Herrmann | 75ae95a7 | 2016-09-01 14:48:32 +0200 | [diff] [blame] | 98 | uid = task ? __task_cred(task)->euid : GLOBAL_ROOT_UID; |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 99 | seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n", |
| 100 | task ? task->comm : "<unknown>", |
Eric W. Biederman | 5fce5e0 | 2012-02-07 16:47:26 -0800 | [diff] [blame] | 101 | pid_vnr(priv->pid), |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 102 | priv->minor->index, |
Daniel Vetter | b3ac9f2 | 2016-06-21 10:54:20 +0200 | [diff] [blame] | 103 | drm_is_current_master(priv) ? 'y' : 'n', |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 104 | priv->authenticated ? 'y' : 'n', |
David Herrmann | 75ae95a7 | 2016-09-01 14:48:32 +0200 | [diff] [blame] | 105 | from_kuid_munged(seq_user_ns(m), uid), |
Daniel Vetter | 5952fba | 2013-12-11 11:35:09 +0100 | [diff] [blame] | 106 | priv->magic); |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 107 | rcu_read_unlock(); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 108 | } |
Daniel Vetter | 1d2ac40 | 2016-04-26 19:29:41 +0200 | [diff] [blame] | 109 | mutex_unlock(&dev->filelist_mutex); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
Sachin Kamat | b375de0 | 2012-06-18 11:09:56 +0530 | [diff] [blame] | 113 | static int drm_gem_one_name_info(int id, void *ptr, void *data) |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 114 | { |
| 115 | struct drm_gem_object *obj = ptr; |
| 116 | struct seq_file *m = data; |
| 117 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 118 | seq_printf(m, "%6d %8zd %7d %8d\n", |
| 119 | obj->name, obj->size, |
Daniel Vetter | a8e11d1 | 2013-08-15 00:02:37 +0200 | [diff] [blame] | 120 | obj->handle_count, |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 121 | atomic_read(&obj->refcount.refcount)); |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | int drm_gem_name_info(struct seq_file *m, void *data) |
| 126 | { |
| 127 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 128 | struct drm_device *dev = node->minor->dev; |
| 129 | |
| 130 | seq_printf(m, " name size handles refcount\n"); |
Daniel Vetter | 90254ac | 2013-08-08 15:41:33 +0200 | [diff] [blame] | 131 | |
Daniel Vetter | cd4f013 | 2013-08-15 00:02:44 +0200 | [diff] [blame] | 132 | mutex_lock(&dev->object_name_lock); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 133 | idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m); |
Daniel Vetter | cd4f013 | 2013-08-15 00:02:44 +0200 | [diff] [blame] | 134 | mutex_unlock(&dev->object_name_lock); |
Daniel Vetter | 90254ac | 2013-08-08 15:41:33 +0200 | [diff] [blame] | 135 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 136 | return 0; |
| 137 | } |