blob: 93b1e0475c93bef525c06ea89785dded441d4f39 [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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#if DRM_DEBUG_CODE
Dave Airlieb5e89ed2005-09-25 14:28:13 +100053static int drm_vma_info(char *buf, char **start, off_t offset,
54 int request, int *eof, void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#endif
56
57/**
58 * Proc file list.
59 */
Dave Airliec94f7022005-07-07 21:03:38 +100060static struct drm_proc_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 const char *name; /**< file name */
Dave Airlieb5e89ed2005-09-25 14:28:13 +100062 int (*f) (char *, char **, off_t, int, int *, void *); /**< proc callback*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070063} drm_proc_list[] = {
Dave Airliee96e33e2005-11-11 20:27:35 +110064 {"name", drm_name_info},
65 {"mem", drm_mem_info},
66 {"vm", drm_vm_info},
67 {"clients", drm_clients_info},
68 {"queues", drm_queues_info},
69 {"bufs", drm_bufs_info},
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#if DRM_DEBUG_CODE
Dave Airliee96e33e2005-11-11 20:27:35 +110071 {"vma", drm_vma_info},
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif
73};
Dave Airlieb5e89ed2005-09-25 14:28:13 +100074
Ahmed S. Darwish8311d572007-02-09 10:30:10 +110075#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/**
78 * Initialize the DRI proc filesystem for a device.
79 *
80 * \param dev DRM device.
81 * \param minor device minor number.
82 * \param root DRI proc dir entry.
83 * \param dev_root resulting DRI device proc dir entry.
84 * \return root entry pointer on success, or NULL on failure.
Dave Airlieb5e89ed2005-09-25 14:28:13 +100085 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 * Create the DRI proc root entry "/proc/dri", the device proc root entry
87 * "/proc/dri/%minor%/", and each entry in proc_list as
88 * "/proc/dri/%minor%/%name%".
89 */
Dave Airlie2c14f282008-04-21 16:47:32 +100090int drm_proc_init(struct drm_minor *minor, int minor_id,
91 struct proc_dir_entry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 struct proc_dir_entry *ent;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100094 int i, j;
95 char name[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Dave Airlie2c14f282008-04-21 16:47:32 +100097 sprintf(name, "%d", minor_id);
98 minor->dev_root = proc_mkdir(name, root);
99 if (!minor->dev_root) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
101 return -1;
102 }
103
104 for (i = 0; i < DRM_PROC_ENTRIES; i++) {
105 ent = create_proc_entry(drm_proc_list[i].name,
Dave Airlie2c14f282008-04-21 16:47:32 +1000106 S_IFREG | S_IRUGO, minor->dev_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (!ent) {
108 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
109 name, drm_proc_list[i].name);
110 for (j = 0; j < i; j++)
111 remove_proc_entry(drm_proc_list[i].name,
Dave Airlie2c14f282008-04-21 16:47:32 +1000112 minor->dev_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 remove_proc_entry(name, root);
Dave Airlie2c14f282008-04-21 16:47:32 +1000114 minor->dev_root = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return -1;
116 }
117 ent->read_proc = drm_proc_list[i].f;
Dave Airlie2c14f282008-04-21 16:47:32 +1000118 ent->data = minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
120
121 return 0;
122}
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124/**
125 * Cleanup the proc filesystem resources.
126 *
127 * \param minor device minor number.
128 * \param root DRI proc dir entry.
129 * \param dev_root DRI device proc dir entry.
130 * \return always zero.
131 *
132 * Remove all proc entries created by proc_init().
133 */
Dave Airlie2c14f282008-04-21 16:47:32 +1000134int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000136 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 char name[64];
138
Dave Airlie2c14f282008-04-21 16:47:32 +1000139 if (!root || !minor->dev_root)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000140 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 for (i = 0; i < DRM_PROC_ENTRIES; i++)
Dave Airlie2c14f282008-04-21 16:47:32 +1000143 remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
144 sprintf(name, "%d", minor->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 remove_proc_entry(name, root);
146
147 return 0;
148}
149
150/**
151 * Called when "/proc/dri/.../name" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000152 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 * \param buf output buffer.
154 * \param start start of output data.
155 * \param offset requested start offset.
156 * \param request requested number of bytes.
157 * \param eof whether there is no more data to return.
158 * \param data private data.
159 * \return number of written bytes.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000160 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 * Prints the device name together with the bus id if available.
162 */
163static int drm_name_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000164 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Dave Airlie2c14f282008-04-21 16:47:32 +1000166 struct drm_minor *minor = (struct drm_minor *) data;
167 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000168 int len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 if (offset > DRM_PROC_LIMIT) {
171 *eof = 1;
172 return 0;
173 }
174
175 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000176 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 if (dev->unique) {
179 DRM_PROC_PRINT("%s %s %s\n",
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000180 dev->driver->pci_driver.name,
181 pci_name(dev->pdev), dev->unique);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 } else {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000183 DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
184 pci_name(dev->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000187 if (len > request + offset)
188 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 *eof = 1;
190 return len - offset;
191}
192
193/**
194 * Called when "/proc/dri/.../vm" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000195 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 * \param buf output buffer.
197 * \param start start of output data.
198 * \param offset requested start offset.
199 * \param request requested number of bytes.
200 * \param eof whether there is no more data to return.
201 * \param data private data.
202 * \return number of written bytes.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000203 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 * Prints information about all mappings in drm_device::maplist.
205 */
206static int drm__vm_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000207 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Dave Airlie2c14f282008-04-21 16:47:32 +1000209 struct drm_minor *minor = (struct drm_minor *) data;
210 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000211 int len = 0;
Dave Airliec60ce622007-07-11 15:27:12 +1000212 struct drm_map *map;
Dave Airlie55910512007-07-11 16:53:40 +1000213 struct drm_map_list *r_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000215 /* Hardcoded from _DRM_FRAME_BUFFER,
216 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
217 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
218 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
219 const char *type;
220 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 if (offset > DRM_PROC_LIMIT) {
223 *eof = 1;
224 return 0;
225 }
226
227 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000228 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 DRM_PROC_PRINT("slot offset size type flags "
231 "address mtrr\n\n");
232 i = 0;
Dave Airliebd1b3312007-05-26 05:01:51 +1000233 list_for_each_entry(r_list, &dev->maplist, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 map = r_list->map;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000235 if (!map)
Dave Airlie2d0f9ea2005-07-10 14:34:13 +1000236 continue;
237 if (map->type < 0 || map->type > 5)
238 type = "??";
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000239 else
Dave Airlie2d0f9ea2005-07-10 14:34:13 +1000240 type = types[map->type];
Dave Airlie8562b3f2007-11-05 12:37:41 +1000241 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 i,
243 map->offset,
Dave Airliebd1b3312007-05-26 05:01:51 +1000244 map->size, type, map->flags,
Dave Airlie8562b3f2007-11-05 12:37:41 +1000245 (unsigned long) r_list->user_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (map->mtrr < 0) {
247 DRM_PROC_PRINT("none\n");
248 } else {
249 DRM_PROC_PRINT("%4d\n", map->mtrr);
250 }
251 i++;
Dave Airliebd1b3312007-05-26 05:01:51 +1000252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000254 if (len > request + offset)
255 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 *eof = 1;
257 return len - offset;
258}
259
260/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100261 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 */
263static int drm_vm_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000264 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Dave Airlie2c14f282008-04-21 16:47:32 +1000266 struct drm_minor *minor = (struct drm_minor *) data;
267 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000268 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Dave Airlie30e2fb12006-02-02 19:37:46 +1100270 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 ret = drm__vm_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100272 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return ret;
274}
275
276/**
277 * Called when "/proc/dri/.../queues" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000278 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 * \param buf output buffer.
280 * \param start start of output data.
281 * \param offset requested start offset.
282 * \param request requested number of bytes.
283 * \param eof whether there is no more data to return.
284 * \param data private data.
285 * \return number of written bytes.
286 */
287static int drm__queues_info(char *buf, char **start, off_t offset,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000288 int request, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Dave Airlie2c14f282008-04-21 16:47:32 +1000290 struct drm_minor *minor = (struct drm_minor *) data;
291 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000292 int len = 0;
293 int i;
Dave Airliecdd55a22007-07-11 16:32:08 +1000294 struct drm_queue *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 if (offset > DRM_PROC_LIMIT) {
297 *eof = 1;
298 return 0;
299 }
300
301 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000302 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 DRM_PROC_PRINT(" ctx/flags use fin"
305 " blk/rw/rwf wait flushed queued"
306 " locks\n\n");
307 for (i = 0; i < dev->queue_count; i++) {
308 q = dev->queuelist[i];
309 atomic_inc(&q->use_count);
310 DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
311 "%5d/0x%03x %5d %5d"
312 " %5d/%c%c/%c%c%c %5Zd\n",
313 i,
314 q->flags,
315 atomic_read(&q->use_count),
316 atomic_read(&q->finalization),
317 atomic_read(&q->block_count),
318 atomic_read(&q->block_read) ? 'r' : '-',
319 atomic_read(&q->block_write) ? 'w' : '-',
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000320 waitqueue_active(&q->read_queue) ? 'r' : '-',
321 waitqueue_active(&q->
322 write_queue) ? 'w' : '-',
323 waitqueue_active(&q->
324 flush_queue) ? 'f' : '-',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 DRM_BUFCOUNT(&q->waitlist));
326 atomic_dec(&q->use_count);
327 }
328
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000329 if (len > request + offset)
330 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 *eof = 1;
332 return len - offset;
333}
334
335/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100336 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 */
338static int drm_queues_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000339 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Dave Airlie2c14f282008-04-21 16:47:32 +1000341 struct drm_minor *minor = (struct drm_minor *) data;
342 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000343 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Dave Airlie30e2fb12006-02-02 19:37:46 +1100345 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 ret = drm__queues_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100347 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return ret;
349}
350
351/**
352 * Called when "/proc/dri/.../bufs" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000353 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 * \param buf output buffer.
355 * \param start start of output data.
356 * \param offset requested start offset.
357 * \param request requested number of bytes.
358 * \param eof whether there is no more data to return.
359 * \param data private data.
360 * \return number of written bytes.
361 */
362static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000363 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Dave Airlie2c14f282008-04-21 16:47:32 +1000365 struct drm_minor *minor = (struct drm_minor *) data;
366 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000367 int len = 0;
Dave Airliecdd55a22007-07-11 16:32:08 +1000368 struct drm_device_dma *dma = dev->dma;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000369 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 if (!dma || offset > DRM_PROC_LIMIT) {
372 *eof = 1;
373 return 0;
374 }
375
376 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000377 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
380 for (i = 0; i <= DRM_MAX_ORDER; i++) {
381 if (dma->bufs[i].buf_count)
382 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
383 i,
384 dma->bufs[i].buf_size,
385 dma->bufs[i].buf_count,
386 atomic_read(&dma->bufs[i]
387 .freelist.count),
388 dma->bufs[i].seg_count,
389 dma->bufs[i].seg_count
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000390 * (1 << dma->bufs[i].page_order),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 (dma->bufs[i].seg_count
392 * (1 << dma->bufs[i].page_order))
393 * PAGE_SIZE / 1024);
394 }
395 DRM_PROC_PRINT("\n");
396 for (i = 0; i < dma->buf_count; i++) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000397 if (i && !(i % 32))
398 DRM_PROC_PRINT("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
400 }
401 DRM_PROC_PRINT("\n");
402
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000403 if (len > request + offset)
404 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 *eof = 1;
406 return len - offset;
407}
408
409/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100410 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 */
412static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000413 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Dave Airlie2c14f282008-04-21 16:47:32 +1000415 struct drm_minor *minor = (struct drm_minor *) data;
416 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000417 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Dave Airlie30e2fb12006-02-02 19:37:46 +1100419 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 ret = drm__bufs_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100421 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return ret;
423}
424
425/**
426 * Called when "/proc/dri/.../clients" is read.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000427 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 * \param buf output buffer.
429 * \param start start of output data.
430 * \param offset requested start offset.
431 * \param request requested number of bytes.
432 * \param eof whether there is no more data to return.
433 * \param data private data.
434 * \return number of written bytes.
435 */
436static int drm__clients_info(char *buf, char **start, off_t offset,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000437 int request, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Dave Airlie2c14f282008-04-21 16:47:32 +1000439 struct drm_minor *minor = (struct drm_minor *) data;
440 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000441 int len = 0;
Dave Airlie84b1fd12007-07-11 15:53:27 +1000442 struct drm_file *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 if (offset > DRM_PROC_LIMIT) {
445 *eof = 1;
446 return 0;
447 }
448
449 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000450 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
Dave Airliebd1b3312007-05-26 05:01:51 +1000453 list_for_each_entry(priv, &dev->filelist, lhead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
455 priv->authenticated ? 'y' : 'n',
Dave Airlie2c14f282008-04-21 16:47:32 +1000456 priv->minor->index,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 priv->pid,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000458 priv->uid, priv->magic, priv->ioctl_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
460
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000461 if (len > request + offset)
462 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 *eof = 1;
464 return len - offset;
465}
466
467/**
Dave Airlie30e2fb12006-02-02 19:37:46 +1100468 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 */
470static int drm_clients_info(char *buf, char **start, off_t offset,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000471 int request, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Dave Airlie2c14f282008-04-21 16:47:32 +1000473 struct drm_minor *minor = (struct drm_minor *) data;
474 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000475 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Dave Airlie30e2fb12006-02-02 19:37:46 +1100477 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 ret = drm__clients_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100479 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return ret;
481}
482
483#if DRM_DEBUG_CODE
484
485static int drm__vma_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000486 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
Dave Airlie2c14f282008-04-21 16:47:32 +1000488 struct drm_minor *minor = (struct drm_minor *) data;
489 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000490 int len = 0;
Dave Airlie8fc2fdf2007-07-11 16:21:47 +1000491 struct drm_vma_entry *pt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 struct vm_area_struct *vma;
493#if defined(__i386__)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000494 unsigned int pgprot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#endif
496
497 if (offset > DRM_PROC_LIMIT) {
498 *eof = 1;
499 return 0;
500 }
501
502 *start = &buf[offset];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000503 *eof = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
506 atomic_read(&dev->vma_count),
507 high_memory, virt_to_phys(high_memory));
Dave Airliebd1b3312007-05-26 05:01:51 +1000508 list_for_each_entry(pt, &dev->vmalist, head) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000509 if (!(vma = pt->vma))
510 continue;
Thomas Hellstrom15450852007-02-08 16:14:05 +1100511 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 pt->pid,
513 vma->vm_start,
514 vma->vm_end,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000515 vma->vm_flags & VM_READ ? 'r' : '-',
516 vma->vm_flags & VM_WRITE ? 'w' : '-',
517 vma->vm_flags & VM_EXEC ? 'x' : '-',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000519 vma->vm_flags & VM_LOCKED ? 'l' : '-',
520 vma->vm_flags & VM_IO ? 'i' : '-',
Thomas Hellstrom15450852007-02-08 16:14:05 +1100521 vma->vm_pgoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523#if defined(__i386__)
524 pgprot = pgprot_val(vma->vm_page_prot);
525 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000526 pgprot & _PAGE_PRESENT ? 'p' : '-',
527 pgprot & _PAGE_RW ? 'w' : 'r',
528 pgprot & _PAGE_USER ? 'u' : 's',
529 pgprot & _PAGE_PWT ? 't' : 'b',
530 pgprot & _PAGE_PCD ? 'u' : 'c',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 pgprot & _PAGE_ACCESSED ? 'a' : '-',
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000532 pgprot & _PAGE_DIRTY ? 'd' : '-',
533 pgprot & _PAGE_PSE ? 'm' : 'k',
534 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#endif
536 DRM_PROC_PRINT("\n");
537 }
538
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000539 if (len > request + offset)
540 return request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 *eof = 1;
542 return len - offset;
543}
544
545static int drm_vma_info(char *buf, char **start, off_t offset, int request,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000546 int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Dave Airlie2c14f282008-04-21 16:47:32 +1000548 struct drm_minor *minor = (struct drm_minor *) data;
549 struct drm_device *dev = minor->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000550 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Dave Airlie30e2fb12006-02-02 19:37:46 +1100552 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 ret = drm__vma_info(buf, start, offset, request, eof, data);
Dave Airlie30e2fb12006-02-02 19:37:46 +1100554 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return ret;
556}
557#endif