blob: 7a8e5a9d8f54dc8fc39c51b8f920dd02fde14962 [file] [log] [blame]
Ben Gamari955b12d2009-02-17 20:08:49 -05001/**
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 Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Daniel Vetterba8286f2014-09-11 07:43:25 +020038#include "drm_legacy.h"
Ben Gamari955b12d2009-02-17 20:08:49 -050039
40/**
41 * Called when "/proc/dri/.../name" is read.
42 *
43 * Prints the device name together with the bus id if available.
44 */
45int drm_name_info(struct seq_file *m, void *data)
46{
47 struct drm_info_node *node = (struct drm_info_node *) m->private;
48 struct drm_minor *minor = node->minor;
49 struct drm_device *dev = minor->dev;
50 struct drm_master *master = minor->master;
Ben Gamari955b12d2009-02-17 20:08:49 -050051 if (!master)
52 return 0;
53
Dave Airlie8410ea32010-12-15 03:16:38 +100054 if (master->unique) {
55 seq_printf(m, "%s %s %s\n",
Daniel Vetter9de1b51f2013-11-03 22:24:37 +010056 dev->driver->name,
Dave Airlie8410ea32010-12-15 03:16:38 +100057 dev_name(dev->dev), master->unique);
Ben Gamari955b12d2009-02-17 20:08:49 -050058 } else {
Dave Airlie8410ea32010-12-15 03:16:38 +100059 seq_printf(m, "%s %s\n",
Daniel Vetter9de1b51f2013-11-03 22:24:37 +010060 dev->driver->name, dev_name(dev->dev));
Ben Gamari955b12d2009-02-17 20:08:49 -050061 }
Ben Gamari955b12d2009-02-17 20:08:49 -050062 return 0;
63}
64
65/**
66 * Called when "/proc/dri/.../vm" is read.
67 *
68 * Prints information about all mappings in drm_device::maplist.
69 */
70int drm_vm_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;
Dave Airlie1847a542009-03-09 12:47:18 +100074 struct drm_local_map *map;
Ben Gamari955b12d2009-02-17 20:08:49 -050075 struct drm_map_list *r_list;
76
77 /* Hardcoded from _DRM_FRAME_BUFFER,
78 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
79 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
80 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
81 const char *type;
82 int i;
83
84 mutex_lock(&dev->struct_mutex);
85 seq_printf(m, "slot offset size type flags address mtrr\n\n");
86 i = 0;
87 list_for_each_entry(r_list, &dev->maplist, head) {
88 map = r_list->map;
89 if (!map)
90 continue;
91 if (map->type < 0 || map->type > 5)
92 type = "??";
93 else
94 type = types[map->type];
95
Dave Airlie1847a542009-03-09 12:47:18 +100096 seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ",
Ben Gamari955b12d2009-02-17 20:08:49 -050097 i,
Dave Airlie1847a542009-03-09 12:47:18 +100098 (unsigned long long)map->offset,
Ben Gamari955b12d2009-02-17 20:08:49 -050099 map->size, type, map->flags,
100 (unsigned long) r_list->user_token);
101 if (map->mtrr < 0)
102 seq_printf(m, "none\n");
103 else
104 seq_printf(m, "%4d\n", map->mtrr);
105 i++;
106 }
107 mutex_unlock(&dev->struct_mutex);
108 return 0;
109}
110
111/**
Ben Gamari955b12d2009-02-17 20:08:49 -0500112 * Called when "/proc/dri/.../bufs" is read.
113 */
114int drm_bufs_info(struct seq_file *m, void *data)
115{
116 struct drm_info_node *node = (struct drm_info_node *) m->private;
117 struct drm_device *dev = node->minor->dev;
118 struct drm_device_dma *dma;
119 int i, seg_pages;
120
121 mutex_lock(&dev->struct_mutex);
122 dma = dev->dma;
123 if (!dma) {
124 mutex_unlock(&dev->struct_mutex);
125 return 0;
126 }
127
128 seq_printf(m, " o size count free segs pages kB\n\n");
129 for (i = 0; i <= DRM_MAX_ORDER; i++) {
130 if (dma->bufs[i].buf_count) {
131 seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
132 seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
133 i,
134 dma->bufs[i].buf_size,
135 dma->bufs[i].buf_count,
David Herrmannb008c0f2014-07-23 17:26:36 +0200136 0,
Ben Gamari955b12d2009-02-17 20:08:49 -0500137 dma->bufs[i].seg_count,
138 seg_pages,
139 seg_pages * PAGE_SIZE / 1024);
140 }
141 }
142 seq_printf(m, "\n");
143 for (i = 0; i < dma->buf_count; i++) {
144 if (i && !(i % 32))
145 seq_printf(m, "\n");
146 seq_printf(m, " %d", dma->buflist[i]->list);
147 }
148 seq_printf(m, "\n");
149 mutex_unlock(&dev->struct_mutex);
150 return 0;
151}
152
153/**
154 * Called when "/proc/dri/.../vblank" is read.
155 */
156int drm_vblank_info(struct seq_file *m, void *data)
157{
158 struct drm_info_node *node = (struct drm_info_node *) m->private;
159 struct drm_device *dev = node->minor->dev;
160 int crtc;
161
162 mutex_lock(&dev->struct_mutex);
163 for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
164 seq_printf(m, "CRTC %d enable: %d\n",
Ville Syrjälä5380e922013-10-04 14:53:36 +0300165 crtc, atomic_read(&dev->vblank[crtc].refcount));
Ben Gamari955b12d2009-02-17 20:08:49 -0500166 seq_printf(m, "CRTC %d counter: %d\n",
167 crtc, drm_vblank_count(dev, crtc));
168 seq_printf(m, "CRTC %d last wait: %d\n",
Ville Syrjälä5380e922013-10-04 14:53:36 +0300169 crtc, dev->vblank[crtc].last_wait);
Ben Gamari955b12d2009-02-17 20:08:49 -0500170 seq_printf(m, "CRTC %d in modeset: %d\n",
Ville Syrjälä5380e922013-10-04 14:53:36 +0300171 crtc, dev->vblank[crtc].inmodeset);
Ben Gamari955b12d2009-02-17 20:08:49 -0500172 }
173 mutex_unlock(&dev->struct_mutex);
174 return 0;
175}
176
177/**
178 * Called when "/proc/dri/.../clients" is read.
179 *
180 */
181int drm_clients_info(struct seq_file *m, void *data)
182{
183 struct drm_info_node *node = (struct drm_info_node *) m->private;
184 struct drm_device *dev = node->minor->dev;
185 struct drm_file *priv;
186
187 mutex_lock(&dev->struct_mutex);
Daniel Vetter5952fba2013-12-11 11:35:09 +0100188 seq_printf(m, "a dev pid uid magic\n\n");
Ben Gamari955b12d2009-02-17 20:08:49 -0500189 list_for_each_entry(priv, &dev->filelist, lhead) {
Daniel Vetter5952fba2013-12-11 11:35:09 +0100190 seq_printf(m, "%c %3d %5d %5d %10u\n",
Ben Gamari955b12d2009-02-17 20:08:49 -0500191 priv->authenticated ? 'y' : 'n',
192 priv->minor->index,
Eric W. Biederman5fce5e02012-02-07 16:47:26 -0800193 pid_vnr(priv->pid),
194 from_kuid_munged(seq_user_ns(m), priv->uid),
Daniel Vetter5952fba2013-12-11 11:35:09 +0100195 priv->magic);
Ben Gamari955b12d2009-02-17 20:08:49 -0500196 }
197 mutex_unlock(&dev->struct_mutex);
198 return 0;
199}
200
201
Sachin Kamatb375de02012-06-18 11:09:56 +0530202static int drm_gem_one_name_info(int id, void *ptr, void *data)
Ben Gamari955b12d2009-02-17 20:08:49 -0500203{
204 struct drm_gem_object *obj = ptr;
205 struct seq_file *m = data;
206
Ben Gamari955b12d2009-02-17 20:08:49 -0500207 seq_printf(m, "%6d %8zd %7d %8d\n",
208 obj->name, obj->size,
Daniel Vettera8e11d12013-08-15 00:02:37 +0200209 obj->handle_count,
Ben Gamari955b12d2009-02-17 20:08:49 -0500210 atomic_read(&obj->refcount.refcount));
211 return 0;
212}
213
214int drm_gem_name_info(struct seq_file *m, void *data)
215{
216 struct drm_info_node *node = (struct drm_info_node *) m->private;
217 struct drm_device *dev = node->minor->dev;
218
219 seq_printf(m, " name size handles refcount\n");
Daniel Vetter90254ac2013-08-08 15:41:33 +0200220
Daniel Vettercd4f0132013-08-15 00:02:44 +0200221 mutex_lock(&dev->object_name_lock);
Ben Gamari955b12d2009-02-17 20:08:49 -0500222 idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
Daniel Vettercd4f0132013-08-15 00:02:44 +0200223 mutex_unlock(&dev->object_name_lock);
Daniel Vetter90254ac2013-08-08 15:41:33 +0200224
Ben Gamari955b12d2009-02-17 20:08:49 -0500225 return 0;
226}