blob: 7dbaa1a19ea4cfe4116d6e69529608d68c011a02 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
Dave Airlieb5e89ed2005-09-25 14:28:13 +10002 * \file drm_proc.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * /proc support for DRM
4 *
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
7 *
8 * \par Acknowledgements:
9 * Matthew J Sottek <matthew.j.sottek@intel.com> sent in a patch to fix
10 * the problem with the proc files not outputting all their information.
11 */
12
13/*
14 * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
15 *
16 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
17 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
18 * All Rights Reserved.
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining a
21 * copy of this software and associated documentation files (the "Software"),
22 * to deal in the Software without restriction, including without limitation
23 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
24 * and/or sell copies of the Software, and to permit persons to whom the
25 * Software is furnished to do so, subject to the following conditions:
26 *
27 * The above copyright notice and this permission notice (including the next
28 * paragraph) shall be included in all copies or substantial portions of the
29 * Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
35 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
36 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
37 * OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#include "drmP.h"
41
Dave Airlieb5e89ed2005-09-25 14:28:13 +100042static int drm_name_info(char *buf, char **start, off_t offset,
43 int request, int *eof, void *data);
44static int drm_vm_info(char *buf, char **start, off_t offset,
45 int request, int *eof, void *data);
46static int drm_clients_info(char *buf, char **start, off_t offset,
47 int request, int *eof, void *data);
48static int drm_queues_info(char *buf, char **start, off_t offset,
49 int request, int *eof, void *data);
50static int drm_bufs_info(char *buf, char **start, off_t offset,
51 int request, int *eof, void *data);
Eric Anholt673a3942008-07-30 12:06:12 -070052static int drm_gem_name_info(char *buf, char **start, off_t offset,
53 int request, int *eof, void *data);
54static int drm_gem_object_info(char *buf, char **start, off_t offset,
55 int request, int *eof, void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#if DRM_DEBUG_CODE
Dave Airlieb5e89ed2005-09-25 14:28:13 +100057static int drm_vma_info(char *buf, char **start, off_t offset,
58 int request, int *eof, void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#endif
60
61/**
62 * Proc file list.
63 */
Dave Airliec94f7022005-07-07 21:03:38 +100064static struct drm_proc_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 const char *name; /**< file name */
Dave Airlieb5e89ed2005-09-25 14:28:13 +100066 int (*f) (char *, char **, off_t, int, int *, void *); /**< proc callback*/
Eric Anholt673a3942008-07-30 12:06:12 -070067 u32 driver_features; /**< Required driver features for this entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068} drm_proc_list[] = {
Eric Anholt673a3942008-07-30 12:06:12 -070069 {"name", drm_name_info, 0},
70 {"mem", drm_mem_info, 0},
71 {"vm", drm_vm_info, 0},
72 {"clients", drm_clients_info, 0},
73 {"queues", drm_queues_info, 0},
74 {"bufs", drm_bufs_info, 0},
75 {"gem_names", drm_gem_name_info, DRIVER_GEM},
76 {"gem_objects", drm_gem_object_info, DRIVER_GEM},
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#if DRM_DEBUG_CODE
Dave Airliee96e33e2005-11-11 20:27:35 +110078 {"vma", drm_vma_info},
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#endif
80};
Dave Airlieb5e89ed2005-09-25 14:28:13 +100081
Ahmed S. Darwish8311d572007-02-09 10:30:10 +110082#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/**
85 * Initialize the DRI proc filesystem for a device.
86 *
87 * \param dev DRM device.
88 * \param minor device minor number.
89 * \param root DRI proc dir entry.
90 * \param dev_root resulting DRI device proc dir entry.
91 * \return root entry pointer on success, or NULL on failure.
Dave Airlieb5e89ed2005-09-25 14:28:13 +100092 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 * Create the DRI proc root entry "/proc/dri", the device proc root entry
94 * "/proc/dri/%minor%/", and each entry in proc_list as
95 * "/proc/dri/%minor%/%name%".
96 */
Dave Airlie2c14f282008-04-21 16:47:32 +100097int drm_proc_init(struct drm_minor *minor, int minor_id,
98 struct proc_dir_entry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Eric Anholt673a3942008-07-30 12:06:12 -0700100 struct drm_device *dev = minor->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 struct proc_dir_entry *ent;
Eric Anholt673a3942008-07-30 12:06:12 -0700102 int i, j, ret;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000103 char name[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Dave Airlie2c14f282008-04-21 16:47:32 +1000105 sprintf(name, "%d", minor_id);
106 minor->dev_root = proc_mkdir(name, root);
107 if (!minor->dev_root) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
109 return -1;
110 }
111
112 for (i = 0; i < DRM_PROC_ENTRIES; i++) {
Eric Anholt673a3942008-07-30 12:06:12 -0700113 u32 features = drm_proc_list[i].driver_features;
114
115 if (features != 0 &&
116 (dev->driver->driver_features & features) != features)
117 continue;
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 ent = create_proc_entry(drm_proc_list[i].name,
Dave Airlie2c14f282008-04-21 16:47:32 +1000120 S_IFREG | S_IRUGO, minor->dev_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if (!ent) {
122 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
123 name, drm_proc_list[i].name);
Eric Anholt673a3942008-07-30 12:06:12 -0700124 ret = -1;
125 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127 ent->read_proc = drm_proc_list[i].f;
Dave Airlie2c14f282008-04-21 16:47:32 +1000128 ent->data = minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130
Eric Anholt673a3942008-07-30 12:06:12 -0700131 if (dev->driver->proc_init) {
132 ret = dev->driver->proc_init(minor);
133 if (ret) {
134 DRM_ERROR("DRM: Driver failed to initialize "
135 "/proc/dri.\n");
136 goto fail;
137 }
138 }
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return 0;
Eric Anholt673a3942008-07-30 12:06:12 -0700141 fail:
142
143 for (j = 0; j < i; j++)
144 remove_proc_entry(drm_proc_list[i].name,
145 minor->dev_root);
146 remove_proc_entry(name, root);
147 minor->dev_root = NULL;
148 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151/**
152 * Cleanup the proc filesystem resources.
153 *
154 * \param minor device minor number.
155 * \param root DRI proc dir entry.
156 * \param dev_root DRI device proc dir entry.
157 * \return always zero.
158 *
159 * Remove all proc entries created by proc_init().
160 */
Dave Airlie2c14f282008-04-21 16:47:32 +1000161int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Eric Anholt673a3942008-07-30 12:06:12 -0700163 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000164 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 char name[64];
166
Dave Airlie2c14f282008-04-21 16:47:32 +1000167 if (!root || !minor->dev_root)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000168 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Eric Anholt673a3942008-07-30 12:06:12 -0700170 if (dev->driver->proc_cleanup)
171 dev->driver->proc_cleanup(minor);
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 for (i = 0; i < DRM_PROC_ENTRIES; i++)
Dave Airlie2c14f282008-04-21 16:47:32 +1000174 remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
175 sprintf(name, "%d", minor->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 remove_proc_entry(name, root);
177
178 return 0;
179}
180
181/**
182 * Called when "/proc/dri/.../name" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000183 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 * \param buf output buffer.
185 * \param start start of output data.
186 * \param offset requested start offset.
187 * \param request requested number of bytes.
188 * \param eof whether there is no more data to return.
189 * \param data private data.
190 * \return number of written bytes.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000191 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 * Prints the device name together with the bus id if available.
193 */
194static int drm_name_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000195 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Dave Airlie2c14f282008-04-21 16:47:32 +1000197 struct drm_minor *minor = (struct drm_minor *) data;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000198 struct drm_master *master = minor->master;
Dave Airlie2c14f282008-04-21 16:47:32 +1000199 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000200 int len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 if (offset > DRM_PROC_LIMIT) {
203 *eof = 1;
204 return 0;
205 }
206
Dave Airlie7c1c2872008-11-28 14:22:24 +1000207 if (!master)
208 return 0;
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000211 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Dave Airlie7c1c2872008-11-28 14:22:24 +1000213 if (master->unique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 DRM_PROC_PRINT("%s %s %s\n",
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000215 dev->driver->pci_driver.name,
Dave Airlie7c1c2872008-11-28 14:22:24 +1000216 pci_name(dev->pdev), master->unique);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 } else {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000218 DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
219 pci_name(dev->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
221
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000222 if (len > request + offset)
223 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 *eof = 1;
225 return len - offset;
226}
227
228/**
229 * Called when "/proc/dri/.../vm" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000230 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 * \param buf output buffer.
232 * \param start start of output data.
233 * \param offset requested start offset.
234 * \param request requested number of bytes.
235 * \param eof whether there is no more data to return.
236 * \param data private data.
237 * \return number of written bytes.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000238 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 * Prints information about all mappings in drm_device::maplist.
240 */
241static int drm__vm_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000242 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
Dave Airlie2c14f282008-04-21 16:47:32 +1000244 struct drm_minor *minor = (struct drm_minor *) data;
245 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000246 int len = 0;
Dave Airliec60ce622007-07-11 15:27:12 +1000247 struct drm_map *map;
Dave Airlie55910512007-07-11 16:53:40 +1000248 struct drm_map_list *r_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000250 /* Hardcoded from _DRM_FRAME_BUFFER,
251 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
252 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
253 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
254 const char *type;
255 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 if (offset > DRM_PROC_LIMIT) {
258 *eof = 1;
259 return 0;
260 }
261
262 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000263 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 DRM_PROC_PRINT("slot offset size type flags "
266 "address mtrr\n\n");
267 i = 0;
Dave Airliebd1b3312007-05-26 05:01:51 +1000268 list_for_each_entry(r_list, &dev->maplist, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 map = r_list->map;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000270 if (!map)
Dave Airlie2d0f9ea2005-07-10 14:34:13 +1000271 continue;
272 if (map->type < 0 || map->type > 5)
273 type = "??";
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000274 else
Dave Airlie2d0f9ea2005-07-10 14:34:13 +1000275 type = types[map->type];
Dave Airlie8562b3f2007-11-05 12:37:41 +1000276 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 i,
278 map->offset,
Dave Airliebd1b3312007-05-26 05:01:51 +1000279 map->size, type, map->flags,
Dave Airlie8562b3f2007-11-05 12:37:41 +1000280 (unsigned long) r_list->user_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (map->mtrr < 0) {
282 DRM_PROC_PRINT("none\n");
283 } else {
284 DRM_PROC_PRINT("%4d\n", map->mtrr);
285 }
286 i++;
Dave Airliebd1b3312007-05-26 05:01:51 +1000287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000289 if (len > request + offset)
290 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 *eof = 1;
292 return len - offset;
293}
294
295/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100296 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 */
298static int drm_vm_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000299 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Dave Airlie2c14f282008-04-21 16:47:32 +1000301 struct drm_minor *minor = (struct drm_minor *) data;
302 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000303 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Dave Airlie30e2fb12006-02-02 19:37:46 +1100305 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 ret = drm__vm_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100307 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 return ret;
309}
310
311/**
312 * Called when "/proc/dri/.../queues" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000313 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * \param buf output buffer.
315 * \param start start of output data.
316 * \param offset requested start offset.
317 * \param request requested number of bytes.
318 * \param eof whether there is no more data to return.
319 * \param data private data.
320 * \return number of written bytes.
321 */
322static int drm__queues_info(char *buf, char **start, off_t offset,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000323 int request, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Dave Airlie2c14f282008-04-21 16:47:32 +1000325 struct drm_minor *minor = (struct drm_minor *) data;
326 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000327 int len = 0;
328 int i;
Dave Airliecdd55a22007-07-11 16:32:08 +1000329 struct drm_queue *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 if (offset > DRM_PROC_LIMIT) {
332 *eof = 1;
333 return 0;
334 }
335
336 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000337 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 DRM_PROC_PRINT(" ctx/flags use fin"
340 " blk/rw/rwf wait flushed queued"
341 " locks\n\n");
342 for (i = 0; i < dev->queue_count; i++) {
343 q = dev->queuelist[i];
344 atomic_inc(&q->use_count);
345 DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
346 "%5d/0x%03x %5d %5d"
347 " %5d/%c%c/%c%c%c %5Zd\n",
348 i,
349 q->flags,
350 atomic_read(&q->use_count),
351 atomic_read(&q->finalization),
352 atomic_read(&q->block_count),
353 atomic_read(&q->block_read) ? 'r' : '-',
354 atomic_read(&q->block_write) ? 'w' : '-',
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000355 waitqueue_active(&q->read_queue) ? 'r' : '-',
356 waitqueue_active(&q->
357 write_queue) ? 'w' : '-',
358 waitqueue_active(&q->
359 flush_queue) ? 'f' : '-',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 DRM_BUFCOUNT(&q->waitlist));
361 atomic_dec(&q->use_count);
362 }
363
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000364 if (len > request + offset)
365 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 *eof = 1;
367 return len - offset;
368}
369
370/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100371 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 */
373static int drm_queues_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000374 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Dave Airlie2c14f282008-04-21 16:47:32 +1000376 struct drm_minor *minor = (struct drm_minor *) data;
377 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000378 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Dave Airlie30e2fb12006-02-02 19:37:46 +1100380 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 ret = drm__queues_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100382 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return ret;
384}
385
386/**
387 * Called when "/proc/dri/.../bufs" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000388 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 * \param buf output buffer.
390 * \param start start of output data.
391 * \param offset requested start offset.
392 * \param request requested number of bytes.
393 * \param eof whether there is no more data to return.
394 * \param data private data.
395 * \return number of written bytes.
396 */
397static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000398 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Dave Airlie2c14f282008-04-21 16:47:32 +1000400 struct drm_minor *minor = (struct drm_minor *) data;
401 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000402 int len = 0;
Dave Airliecdd55a22007-07-11 16:32:08 +1000403 struct drm_device_dma *dma = dev->dma;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000404 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 if (!dma || offset > DRM_PROC_LIMIT) {
407 *eof = 1;
408 return 0;
409 }
410
411 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000412 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
415 for (i = 0; i <= DRM_MAX_ORDER; i++) {
416 if (dma->bufs[i].buf_count)
417 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
418 i,
419 dma->bufs[i].buf_size,
420 dma->bufs[i].buf_count,
421 atomic_read(&dma->bufs[i]
422 .freelist.count),
423 dma->bufs[i].seg_count,
424 dma->bufs[i].seg_count
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000425 * (1 << dma->bufs[i].page_order),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 (dma->bufs[i].seg_count
427 * (1 << dma->bufs[i].page_order))
428 * PAGE_SIZE / 1024);
429 }
430 DRM_PROC_PRINT("\n");
431 for (i = 0; i < dma->buf_count; i++) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000432 if (i && !(i % 32))
433 DRM_PROC_PRINT("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
435 }
436 DRM_PROC_PRINT("\n");
437
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000438 if (len > request + offset)
439 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 *eof = 1;
441 return len - offset;
442}
443
444/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100445 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 */
447static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000448 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Dave Airlie2c14f282008-04-21 16:47:32 +1000450 struct drm_minor *minor = (struct drm_minor *) data;
451 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000452 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Dave Airlie30e2fb12006-02-02 19:37:46 +1100454 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 ret = drm__bufs_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100456 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 return ret;
458}
459
460/**
461 * Called when "/proc/dri/.../clients" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000462 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 * \param buf output buffer.
464 * \param start start of output data.
465 * \param offset requested start offset.
466 * \param request requested number of bytes.
467 * \param eof whether there is no more data to return.
468 * \param data private data.
469 * \return number of written bytes.
470 */
471static int drm__clients_info(char *buf, char **start, off_t offset,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000472 int request, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Dave Airlie2c14f282008-04-21 16:47:32 +1000474 struct drm_minor *minor = (struct drm_minor *) data;
475 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000476 int len = 0;
Dave Airlie84b1fd12007-07-11 15:53:27 +1000477 struct drm_file *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 if (offset > DRM_PROC_LIMIT) {
480 *eof = 1;
481 return 0;
482 }
483
484 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000485 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
Dave Airliebd1b3312007-05-26 05:01:51 +1000488 list_for_each_entry(priv, &dev->filelist, lhead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
490 priv->authenticated ? 'y' : 'n',
Dave Airlie2c14f282008-04-21 16:47:32 +1000491 priv->minor->index,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 priv->pid,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000493 priv->uid, priv->magic, priv->ioctl_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000496 if (len > request + offset)
497 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 *eof = 1;
499 return len - offset;
500}
501
502/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100503 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 */
505static int drm_clients_info(char *buf, char **start, off_t offset,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000506 int request, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Dave Airlie2c14f282008-04-21 16:47:32 +1000508 struct drm_minor *minor = (struct drm_minor *) data;
509 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000510 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Dave Airlie30e2fb12006-02-02 19:37:46 +1100512 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 ret = drm__clients_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100514 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 return ret;
516}
517
Eric Anholt673a3942008-07-30 12:06:12 -0700518struct drm_gem_name_info_data {
519 int len;
520 char *buf;
521 int eof;
522};
523
524static int drm_gem_one_name_info(int id, void *ptr, void *data)
525{
526 struct drm_gem_object *obj = ptr;
527 struct drm_gem_name_info_data *nid = data;
528
Linus Torvalds1ae87782008-10-20 14:14:25 -0700529 DRM_INFO("name %d size %zd\n", obj->name, obj->size);
Eric Anholt673a3942008-07-30 12:06:12 -0700530 if (nid->eof)
531 return 0;
532
533 nid->len += sprintf(&nid->buf[nid->len],
Linus Torvalds1ae87782008-10-20 14:14:25 -0700534 "%6d %8zd %7d %8d\n",
Eric Anholt673a3942008-07-30 12:06:12 -0700535 obj->name, obj->size,
536 atomic_read(&obj->handlecount.refcount),
537 atomic_read(&obj->refcount.refcount));
538 if (nid->len > DRM_PROC_LIMIT) {
539 nid->eof = 1;
540 return 0;
541 }
542 return 0;
543}
544
545static int drm_gem_name_info(char *buf, char **start, off_t offset,
546 int request, int *eof, void *data)
547{
548 struct drm_minor *minor = (struct drm_minor *) data;
549 struct drm_device *dev = minor->dev;
550 struct drm_gem_name_info_data nid;
551
552 if (offset > DRM_PROC_LIMIT) {
553 *eof = 1;
554 return 0;
555 }
556
557 nid.len = sprintf(buf, " name size handles refcount\n");
558 nid.buf = buf;
559 nid.eof = 0;
560 idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, &nid);
561
562 *start = &buf[offset];
563 *eof = 0;
564 if (nid.len > request + offset)
565 return request;
566 *eof = 1;
567 return nid.len - offset;
568}
569
570static int drm_gem_object_info(char *buf, char **start, off_t offset,
571 int request, int *eof, void *data)
572{
573 struct drm_minor *minor = (struct drm_minor *) data;
574 struct drm_device *dev = minor->dev;
575 int len = 0;
576
577 if (offset > DRM_PROC_LIMIT) {
578 *eof = 1;
579 return 0;
580 }
581
582 *start = &buf[offset];
583 *eof = 0;
584 DRM_PROC_PRINT("%d objects\n", atomic_read(&dev->object_count));
585 DRM_PROC_PRINT("%d object bytes\n", atomic_read(&dev->object_memory));
586 DRM_PROC_PRINT("%d pinned\n", atomic_read(&dev->pin_count));
587 DRM_PROC_PRINT("%d pin bytes\n", atomic_read(&dev->pin_memory));
588 DRM_PROC_PRINT("%d gtt bytes\n", atomic_read(&dev->gtt_memory));
589 DRM_PROC_PRINT("%d gtt total\n", dev->gtt_total);
590 if (len > request + offset)
591 return request;
592 *eof = 1;
593 return len - offset;
594}
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#if DRM_DEBUG_CODE
597
598static int drm__vma_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000599 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Dave Airlie2c14f282008-04-21 16:47:32 +1000601 struct drm_minor *minor = (struct drm_minor *) data;
602 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000603 int len = 0;
Dave Airlie8fc2fdf2007-07-11 16:21:47 +1000604 struct drm_vma_entry *pt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 struct vm_area_struct *vma;
606#if defined(__i386__)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000607 unsigned int pgprot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#endif
609
610 if (offset > DRM_PROC_LIMIT) {
611 *eof = 1;
612 return 0;
613 }
614
615 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000616 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
619 atomic_read(&dev->vma_count),
620 high_memory, virt_to_phys(high_memory));
Dave Airliebd1b3312007-05-26 05:01:51 +1000621 list_for_each_entry(pt, &dev->vmalist, head) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000622 if (!(vma = pt->vma))
623 continue;
Thomas Hellstrom15450852007-02-08 16:14:05 +1100624 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 pt->pid,
626 vma->vm_start,
627 vma->vm_end,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000628 vma->vm_flags & VM_READ ? 'r' : '-',
629 vma->vm_flags & VM_WRITE ? 'w' : '-',
630 vma->vm_flags & VM_EXEC ? 'x' : '-',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000632 vma->vm_flags & VM_LOCKED ? 'l' : '-',
633 vma->vm_flags & VM_IO ? 'i' : '-',
Thomas Hellstrom15450852007-02-08 16:14:05 +1100634 vma->vm_pgoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636#if defined(__i386__)
637 pgprot = pgprot_val(vma->vm_page_prot);
638 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000639 pgprot & _PAGE_PRESENT ? 'p' : '-',
640 pgprot & _PAGE_RW ? 'w' : 'r',
641 pgprot & _PAGE_USER ? 'u' : 's',
642 pgprot & _PAGE_PWT ? 't' : 'b',
643 pgprot & _PAGE_PCD ? 'u' : 'c',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 pgprot & _PAGE_ACCESSED ? 'a' : '-',
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000645 pgprot & _PAGE_DIRTY ? 'd' : '-',
646 pgprot & _PAGE_PSE ? 'm' : 'k',
647 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648#endif
649 DRM_PROC_PRINT("\n");
650 }
651
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000652 if (len > request + offset)
653 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 *eof = 1;
655 return len - offset;
656}
657
658static int drm_vma_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000659 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Dave Airlie2c14f282008-04-21 16:47:32 +1000661 struct drm_minor *minor = (struct drm_minor *) data;
662 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000663 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Dave Airlie30e2fb12006-02-02 19:37:46 +1100665 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 ret = drm__vma_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100667 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return ret;
669}
670#endif