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 | |
Daniel Vetter | ba8286f | 2014-09-11 07:43:25 +0200 | [diff] [blame] | 40 | #include "drm_legacy.h" |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Called when "/proc/dri/.../name" is read. |
| 44 | * |
| 45 | * Prints the device name together with the bus id if available. |
| 46 | */ |
| 47 | int drm_name_info(struct seq_file *m, void *data) |
| 48 | { |
| 49 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 50 | struct drm_minor *minor = node->minor; |
| 51 | struct drm_device *dev = minor->dev; |
| 52 | struct drm_master *master = minor->master; |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 53 | if (!master) |
| 54 | return 0; |
| 55 | |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 56 | if (master->unique) { |
| 57 | seq_printf(m, "%s %s %s\n", |
Daniel Vetter | 9de1b51f | 2013-11-03 22:24:37 +0100 | [diff] [blame] | 58 | dev->driver->name, |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 59 | dev_name(dev->dev), master->unique); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 60 | } else { |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 61 | seq_printf(m, "%s %s\n", |
Daniel Vetter | 9de1b51f | 2013-11-03 22:24:37 +0100 | [diff] [blame] | 62 | dev->driver->name, dev_name(dev->dev)); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 63 | } |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Called when "/proc/dri/.../vm" is read. |
| 69 | * |
| 70 | * Prints information about all mappings in drm_device::maplist. |
| 71 | */ |
| 72 | int drm_vm_info(struct seq_file *m, void *data) |
| 73 | { |
| 74 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 75 | struct drm_device *dev = node->minor->dev; |
Dave Airlie | 1847a54 | 2009-03-09 12:47:18 +1000 | [diff] [blame] | 76 | struct drm_local_map *map; |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 77 | struct drm_map_list *r_list; |
| 78 | |
| 79 | /* Hardcoded from _DRM_FRAME_BUFFER, |
| 80 | _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and |
| 81 | _DRM_SCATTER_GATHER and _DRM_CONSISTENT */ |
| 82 | const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" }; |
| 83 | const char *type; |
| 84 | int i; |
| 85 | |
| 86 | mutex_lock(&dev->struct_mutex); |
| 87 | seq_printf(m, "slot offset size type flags address mtrr\n\n"); |
| 88 | i = 0; |
| 89 | list_for_each_entry(r_list, &dev->maplist, head) { |
| 90 | map = r_list->map; |
| 91 | if (!map) |
| 92 | continue; |
| 93 | if (map->type < 0 || map->type > 5) |
| 94 | type = "??"; |
| 95 | else |
| 96 | type = types[map->type]; |
| 97 | |
Dave Airlie | 1847a54 | 2009-03-09 12:47:18 +1000 | [diff] [blame] | 98 | seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ", |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 99 | i, |
Dave Airlie | 1847a54 | 2009-03-09 12:47:18 +1000 | [diff] [blame] | 100 | (unsigned long long)map->offset, |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 101 | map->size, type, map->flags, |
| 102 | (unsigned long) r_list->user_token); |
| 103 | if (map->mtrr < 0) |
| 104 | seq_printf(m, "none\n"); |
| 105 | else |
| 106 | seq_printf(m, "%4d\n", map->mtrr); |
| 107 | i++; |
| 108 | } |
| 109 | mutex_unlock(&dev->struct_mutex); |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | /** |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 114 | * Called when "/proc/dri/.../bufs" is read. |
| 115 | */ |
| 116 | int drm_bufs_info(struct seq_file *m, void *data) |
| 117 | { |
| 118 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 119 | struct drm_device *dev = node->minor->dev; |
| 120 | struct drm_device_dma *dma; |
| 121 | int i, seg_pages; |
| 122 | |
| 123 | mutex_lock(&dev->struct_mutex); |
| 124 | dma = dev->dma; |
| 125 | if (!dma) { |
| 126 | mutex_unlock(&dev->struct_mutex); |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | seq_printf(m, " o size count free segs pages kB\n\n"); |
| 131 | for (i = 0; i <= DRM_MAX_ORDER; i++) { |
| 132 | if (dma->bufs[i].buf_count) { |
| 133 | seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order); |
| 134 | seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n", |
| 135 | i, |
| 136 | dma->bufs[i].buf_size, |
| 137 | dma->bufs[i].buf_count, |
David Herrmann | b008c0f | 2014-07-23 17:26:36 +0200 | [diff] [blame] | 138 | 0, |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 139 | dma->bufs[i].seg_count, |
| 140 | seg_pages, |
| 141 | seg_pages * PAGE_SIZE / 1024); |
| 142 | } |
| 143 | } |
| 144 | seq_printf(m, "\n"); |
| 145 | for (i = 0; i < dma->buf_count; i++) { |
| 146 | if (i && !(i % 32)) |
| 147 | seq_printf(m, "\n"); |
| 148 | seq_printf(m, " %d", dma->buflist[i]->list); |
| 149 | } |
| 150 | seq_printf(m, "\n"); |
| 151 | mutex_unlock(&dev->struct_mutex); |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Called when "/proc/dri/.../vblank" is read. |
| 157 | */ |
| 158 | int drm_vblank_info(struct seq_file *m, void *data) |
| 159 | { |
| 160 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 161 | struct drm_device *dev = node->minor->dev; |
| 162 | int crtc; |
| 163 | |
| 164 | mutex_lock(&dev->struct_mutex); |
| 165 | for (crtc = 0; crtc < dev->num_crtcs; crtc++) { |
| 166 | seq_printf(m, "CRTC %d enable: %d\n", |
Ville Syrjälä | 5380e92 | 2013-10-04 14:53:36 +0300 | [diff] [blame] | 167 | crtc, atomic_read(&dev->vblank[crtc].refcount)); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 168 | seq_printf(m, "CRTC %d counter: %d\n", |
| 169 | crtc, drm_vblank_count(dev, crtc)); |
| 170 | seq_printf(m, "CRTC %d last wait: %d\n", |
Ville Syrjälä | 5380e92 | 2013-10-04 14:53:36 +0300 | [diff] [blame] | 171 | crtc, dev->vblank[crtc].last_wait); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 172 | seq_printf(m, "CRTC %d in modeset: %d\n", |
Ville Syrjälä | 5380e92 | 2013-10-04 14:53:36 +0300 | [diff] [blame] | 173 | crtc, dev->vblank[crtc].inmodeset); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 174 | } |
| 175 | mutex_unlock(&dev->struct_mutex); |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Called when "/proc/dri/.../clients" is read. |
| 181 | * |
| 182 | */ |
| 183 | int drm_clients_info(struct seq_file *m, void *data) |
| 184 | { |
| 185 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 186 | struct drm_device *dev = node->minor->dev; |
| 187 | struct drm_file *priv; |
| 188 | |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 189 | seq_printf(m, |
| 190 | "%20s %5s %3s master a %5s %10s\n", |
| 191 | "command", |
| 192 | "pid", |
| 193 | "dev", |
| 194 | "uid", |
| 195 | "magic"); |
| 196 | |
| 197 | /* dev->filelist is sorted youngest first, but we want to present |
| 198 | * oldest first (i.e. kernel, servers, clients), so walk backwardss. |
| 199 | */ |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 200 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 201 | list_for_each_entry_reverse(priv, &dev->filelist, lhead) { |
| 202 | struct task_struct *task; |
| 203 | |
| 204 | rcu_read_lock(); /* locks pid_task()->comm */ |
| 205 | task = pid_task(priv->pid, PIDTYPE_PID); |
| 206 | seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n", |
| 207 | task ? task->comm : "<unknown>", |
Eric W. Biederman | 5fce5e0 | 2012-02-07 16:47:26 -0800 | [diff] [blame] | 208 | pid_vnr(priv->pid), |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 209 | priv->minor->index, |
| 210 | priv->is_master ? 'y' : 'n', |
| 211 | priv->authenticated ? 'y' : 'n', |
Eric W. Biederman | 5fce5e0 | 2012-02-07 16:47:26 -0800 | [diff] [blame] | 212 | from_kuid_munged(seq_user_ns(m), priv->uid), |
Daniel Vetter | 5952fba | 2013-12-11 11:35:09 +0100 | [diff] [blame] | 213 | priv->magic); |
Chris Wilson | 50d47cb | 2014-09-02 08:03:22 +0100 | [diff] [blame] | 214 | rcu_read_unlock(); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 215 | } |
| 216 | mutex_unlock(&dev->struct_mutex); |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | |
Sachin Kamat | b375de0 | 2012-06-18 11:09:56 +0530 | [diff] [blame] | 221 | 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] | 222 | { |
| 223 | struct drm_gem_object *obj = ptr; |
| 224 | struct seq_file *m = data; |
| 225 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 226 | seq_printf(m, "%6d %8zd %7d %8d\n", |
| 227 | obj->name, obj->size, |
Daniel Vetter | a8e11d1 | 2013-08-15 00:02:37 +0200 | [diff] [blame] | 228 | obj->handle_count, |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 229 | atomic_read(&obj->refcount.refcount)); |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | int drm_gem_name_info(struct seq_file *m, void *data) |
| 234 | { |
| 235 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 236 | struct drm_device *dev = node->minor->dev; |
| 237 | |
| 238 | seq_printf(m, " name size handles refcount\n"); |
Daniel Vetter | 90254ac | 2013-08-08 15:41:33 +0200 | [diff] [blame] | 239 | |
Daniel Vetter | cd4f013 | 2013-08-15 00:02:44 +0200 | [diff] [blame] | 240 | mutex_lock(&dev->object_name_lock); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 241 | 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] | 242 | mutex_unlock(&dev->object_name_lock); |
Daniel Vetter | 90254ac | 2013-08-08 15:41:33 +0200 | [diff] [blame] | 243 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 244 | return 0; |
| 245 | } |