3 * /proc support for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
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.
14 * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
16 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
17 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
18 * All Rights Reserved.
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:
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
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.
42 static int drm_name_info(char *buf, char **start, off_t offset,
43 int request, int *eof, void *data);
44 static int drm_vm_info(char *buf, char **start, off_t offset,
45 int request, int *eof, void *data);
46 static int drm_clients_info(char *buf, char **start, off_t offset,
47 int request, int *eof, void *data);
48 static int drm_queues_info(char *buf, char **start, off_t offset,
49 int request, int *eof, void *data);
50 static int drm_bufs_info(char *buf, char **start, off_t offset,
51 int request, int *eof, void *data);
52 static int drm_objects_info(char *buf, char **start, off_t offset,
53 int request, int *eof, void *data);
55 static int drm_vma_info(char *buf, char **start, off_t offset,
56 int request, int *eof, void *data);
62 static struct drm_proc_list {
63 const char *name; /**< file name */
64 int (*f) (char *, char **, off_t, int, int *, void *); /**< proc callback*/
66 {"name", drm_name_info},
67 {"mem", drm_mem_info},
69 {"clients", drm_clients_info},
70 {"queues", drm_queues_info},
71 {"bufs", drm_bufs_info},
72 {"objects", drm_objects_info},
74 {"vma", drm_vma_info},
78 #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
81 * Initialize the DRI proc filesystem for a device.
83 * \param dev DRM device.
84 * \param minor device minor number.
85 * \param root DRI proc dir entry.
86 * \param dev_root resulting DRI device proc dir entry.
87 * \return root entry pointer on success, or NULL on failure.
89 * Create the DRI proc root entry "/proc/dri", the device proc root entry
90 * "/proc/dri/%minor%/", and each entry in proc_list as
91 * "/proc/dri/%minor%/%name%".
93 int drm_proc_init(struct drm_minor *minor, int minor_id,
94 struct proc_dir_entry *root)
96 struct proc_dir_entry *ent;
100 sprintf(name, "%d", minor_id);
101 minor->dev_root = proc_mkdir(name, root);
102 if (!minor->dev_root) {
103 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
107 for (i = 0; i < DRM_PROC_ENTRIES; i++) {
108 ent = create_proc_entry(drm_proc_list[i].name,
109 S_IFREG | S_IRUGO, minor->dev_root);
111 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
112 name, drm_proc_list[i].name);
113 for (j = 0; j < i; j++)
114 remove_proc_entry(drm_proc_list[i].name,
116 remove_proc_entry(name, root);
117 minor->dev_root = NULL;
120 ent->read_proc = drm_proc_list[i].f;
127 * Cleanup the proc filesystem resources.
129 * \param minor device minor number.
130 * \param root DRI proc dir entry.
131 * \param dev_root DRI device proc dir entry.
132 * \return always zero.
134 * Remove all proc entries created by proc_init().
136 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
141 if (!root || !minor->dev_root)
144 for (i = 0; i < DRM_PROC_ENTRIES; i++)
145 remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
146 sprintf(name, "%d", minor->index);
147 remove_proc_entry(name, root);
153 * Called when "/proc/dri/.../name" is read.
155 * \param buf output buffer.
156 * \param start start of output data.
157 * \param offset requested start offset.
158 * \param request requested number of bytes.
159 * \param eof whether there is no more data to return.
160 * \param data private data.
161 * \return number of written bytes.
163 * Prints the device name together with the bus id if available.
165 static int drm_name_info(char *buf, char **start, off_t offset, int request,
166 int *eof, void *data)
168 struct drm_minor *minor = (struct drm_minor *) data;
169 struct drm_master *master = minor->master;
170 struct drm_device *dev = minor->dev;
173 if (offset > DRM_PROC_LIMIT) {
178 *start = &buf[offset];
181 if (master->unique) {
182 DRM_PROC_PRINT("%s %s %s\n",
183 dev->driver->pci_driver.name,
184 pci_name(dev->pdev), master->unique);
186 DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
187 pci_name(dev->pdev));
190 if (len > request + offset)
197 * Called when "/proc/dri/.../vm" is read.
199 * \param buf output buffer.
200 * \param start start of output data.
201 * \param offset requested start offset.
202 * \param request requested number of bytes.
203 * \param eof whether there is no more data to return.
204 * \param data private data.
205 * \return number of written bytes.
207 * Prints information about all mappings in drm_device::maplist.
209 static int drm__vm_info(char *buf, char **start, off_t offset, int request,
210 int *eof, void *data)
212 struct drm_minor *minor = (struct drm_minor *) data;
213 struct drm_device *dev = minor->dev;
216 struct drm_map_list *r_list;
218 /* Hardcoded from _DRM_FRAME_BUFFER,
219 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP,
220 _DRM_SCATTER_GATHER, and _DRM_CONSISTENT. */
221 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
225 if (offset > DRM_PROC_LIMIT) {
230 *start = &buf[offset];
233 DRM_PROC_PRINT("slot offset size type flags "
236 list_for_each_entry(r_list, &dev->maplist, head) {
240 if (map->type < 0 || map->type > 5)
243 type = types[map->type];
244 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
247 map->size, type, map->flags,
248 (unsigned long) r_list->user_token);
251 DRM_PROC_PRINT("none\n");
253 DRM_PROC_PRINT("%4d\n", map->mtrr);
258 if (len > request + offset)
265 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
267 static int drm_vm_info(char *buf, char **start, off_t offset, int request,
268 int *eof, void *data)
270 struct drm_minor *minor = (struct drm_minor *) data;
271 struct drm_device *dev = minor->dev;
274 mutex_lock(&dev->struct_mutex);
275 ret = drm__vm_info(buf, start, offset, request, eof, data);
276 mutex_unlock(&dev->struct_mutex);
281 * Called when "/proc/dri/.../queues" is read.
283 * \param buf output buffer.
284 * \param start start of output data.
285 * \param offset requested start offset.
286 * \param request requested number of bytes.
287 * \param eof whether there is no more data to return.
288 * \param data private data.
289 * \return number of written bytes.
291 static int drm__queues_info(char *buf, char **start, off_t offset,
292 int request, int *eof, void *data)
294 struct drm_minor *minor = (struct drm_minor *) data;
295 struct drm_device *dev = minor->dev;
300 if (offset > DRM_PROC_LIMIT) {
305 *start = &buf[offset];
308 DRM_PROC_PRINT(" ctx/flags use fin"
309 " blk/rw/rwf wait flushed queued"
311 for (i = 0; i < dev->queue_count; i++) {
312 q = dev->queuelist[i];
313 atomic_inc(&q->use_count);
314 DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
316 " %5d/%c%c/%c%c%c %5Zd\n",
319 atomic_read(&q->use_count),
320 atomic_read(&q->finalization),
321 atomic_read(&q->block_count),
322 atomic_read(&q->block_read) ? 'r' : '-',
323 atomic_read(&q->block_write) ? 'w' : '-',
324 waitqueue_active(&q->read_queue) ? 'r' : '-',
325 waitqueue_active(&q->
326 write_queue) ? 'w' : '-',
327 waitqueue_active(&q->
328 flush_queue) ? 'f' : '-',
329 DRM_BUFCOUNT(&q->waitlist));
330 atomic_dec(&q->use_count);
333 if (len > request + offset)
340 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
342 static int drm_queues_info(char *buf, char **start, off_t offset, int request,
343 int *eof, void *data)
345 struct drm_minor *minor = (struct drm_minor *) data;
346 struct drm_device *dev = minor->dev;
349 mutex_lock(&dev->struct_mutex);
350 ret = drm__queues_info(buf, start, offset, request, eof, data);
351 mutex_unlock(&dev->struct_mutex);
356 * Called when "/proc/dri/.../bufs" is read.
358 * \param buf output buffer.
359 * \param start start of output data.
360 * \param offset requested start offset.
361 * \param request requested number of bytes.
362 * \param eof whether there is no more data to return.
363 * \param data private data.
364 * \return number of written bytes.
366 static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
367 int *eof, void *data)
369 struct drm_minor *minor = (struct drm_minor *) data;
370 struct drm_device *dev = minor->dev;
372 struct drm_device_dma *dma = dev->dma;
375 if (!dma || offset > DRM_PROC_LIMIT) {
380 *start = &buf[offset];
383 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
384 for (i = 0; i <= DRM_MAX_ORDER; i++) {
385 if (dma->bufs[i].buf_count)
386 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
388 dma->bufs[i].buf_size,
389 dma->bufs[i].buf_count,
390 atomic_read(&dma->bufs[i]
392 dma->bufs[i].seg_count,
393 dma->bufs[i].seg_count
394 * (1 << dma->bufs[i].page_order),
395 (dma->bufs[i].seg_count
396 * (1 << dma->bufs[i].page_order))
399 DRM_PROC_PRINT("\n");
400 for (i = 0; i < dma->buf_count; i++) {
402 DRM_PROC_PRINT("\n");
403 DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
405 DRM_PROC_PRINT("\n");
407 if (len > request + offset)
414 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
416 static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
417 int *eof, void *data)
419 struct drm_minor *minor = (struct drm_minor *) data;
420 struct drm_device *dev = minor->dev;
423 mutex_lock(&dev->struct_mutex);
424 ret = drm__bufs_info(buf, start, offset, request, eof, data);
425 mutex_unlock(&dev->struct_mutex);
430 * Called when "/proc/dri/.../objects" is read.
432 * \param buf output buffer.
433 * \param start start of output data.
434 * \param offset requested start offset.
435 * \param request requested number of bytes.
436 * \param eof whether there is no more data to return.
437 * \param data private data.
438 * \return number of written bytes.
440 static int drm__objects_info(char *buf, char **start, off_t offset, int request,
441 int *eof, void *data)
443 struct drm_minor *minor = (struct drm_minor *) data;
444 struct drm_device *dev = minor->dev;
446 struct drm_buffer_manager *bm = &dev->bm;
447 struct drm_fence_manager *fm = &dev->fm;
453 if (offset > DRM_PROC_LIMIT) {
458 *start = &buf[offset];
461 DRM_PROC_PRINT("Object accounting:\n\n");
462 if (fm->initialized) {
463 DRM_PROC_PRINT("Number of active fence objects: %d.\n",
464 atomic_read(&fm->count));
466 DRM_PROC_PRINT("Fence objects are not supported by this driver\n");
469 if (bm->initialized) {
470 DRM_PROC_PRINT("Number of active buffer objects: %d.\n\n",
471 atomic_read(&bm->count));
473 DRM_PROC_PRINT("Memory accounting:\n\n");
474 if (bm->initialized) {
475 DRM_PROC_PRINT("Number of locked GATT pages: %lu.\n", bm->cur_pages);
477 DRM_PROC_PRINT("Buffer objects are not supported by this driver.\n");
480 drm_query_memctl(&used_mem, &low_mem, &high_mem);
482 if (used_mem > 16*PAGE_SIZE) {
483 DRM_PROC_PRINT("Used object memory is %lu pages.\n",
484 (unsigned long) (used_mem >> PAGE_SHIFT));
486 DRM_PROC_PRINT("Used object memory is %lu bytes.\n",
487 (unsigned long) used_mem);
489 DRM_PROC_PRINT("Soft object memory usage threshold is %lu pages.\n",
490 (unsigned long) (low_mem >> PAGE_SHIFT));
491 DRM_PROC_PRINT("Hard object memory usage threshold is %lu pages.\n",
492 (unsigned long) (high_mem >> PAGE_SHIFT));
494 DRM_PROC_PRINT("\n");
496 if (len > request + offset)
503 * Simply calls _objects_info() while holding the drm_device::struct_mutex lock.
505 static int drm_objects_info(char *buf, char **start, off_t offset, int request,
506 int *eof, void *data)
508 struct drm_minor *minor = (struct drm_minor *) data;
509 struct drm_device *dev = minor->dev;
512 mutex_lock(&dev->struct_mutex);
513 ret = drm__objects_info(buf, start, offset, request, eof, data);
514 mutex_unlock(&dev->struct_mutex);
519 * Called when "/proc/dri/.../clients" is read.
521 * \param buf output buffer.
522 * \param start start of output data.
523 * \param offset requested start offset.
524 * \param request requested number of bytes.
525 * \param eof whether there is no more data to return.
526 * \param data private data.
527 * \return number of written bytes.
529 static int drm__clients_info(char *buf, char **start, off_t offset,
530 int request, int *eof, void *data)
532 struct drm_minor *minor = (struct drm_minor *) data;
533 struct drm_device *dev = minor->dev;
535 struct drm_file *priv;
537 if (offset > DRM_PROC_LIMIT) {
542 *start = &buf[offset];
545 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
546 list_for_each_entry(priv, &dev->filelist, lhead) {
547 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
548 priv->authenticated ? 'y' : 'n',
551 priv->uid, priv->magic, priv->ioctl_count);
554 if (len > request + offset)
561 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
563 static int drm_clients_info(char *buf, char **start, off_t offset,
564 int request, int *eof, void *data)
566 struct drm_minor *minor = (struct drm_minor *) data;
567 struct drm_device *dev = minor->dev;
570 mutex_lock(&dev->struct_mutex);
571 ret = drm__clients_info(buf, start, offset, request, eof, data);
572 mutex_unlock(&dev->struct_mutex);
578 static int drm__vma_info(char *buf, char **start, off_t offset, int request,
579 int *eof, void *data)
581 struct drm_minor *minor = (struct drm_minor *) data;
582 struct drm_device *dev = minor->dev;
584 struct drm_vma_entry *pt;
585 struct vm_area_struct *vma;
586 #if defined(__i386__)
590 if (offset > DRM_PROC_LIMIT) {
595 *start = &buf[offset];
598 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
599 atomic_read(&dev->vma_count),
600 high_memory, virt_to_phys(high_memory));
601 list_for_each_entry(pt, &dev->vmalist, head) {
602 if (!(vma = pt->vma))
604 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
608 vma->vm_flags & VM_READ ? 'r' : '-',
609 vma->vm_flags & VM_WRITE ? 'w' : '-',
610 vma->vm_flags & VM_EXEC ? 'x' : '-',
611 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
612 vma->vm_flags & VM_LOCKED ? 'l' : '-',
613 vma->vm_flags & VM_IO ? 'i' : '-',
616 #if defined(__i386__)
617 pgprot = pgprot_val(vma->vm_page_prot);
618 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
619 pgprot & _PAGE_PRESENT ? 'p' : '-',
620 pgprot & _PAGE_RW ? 'w' : 'r',
621 pgprot & _PAGE_USER ? 'u' : 's',
622 pgprot & _PAGE_PWT ? 't' : 'b',
623 pgprot & _PAGE_PCD ? 'u' : 'c',
624 pgprot & _PAGE_ACCESSED ? 'a' : '-',
625 pgprot & _PAGE_DIRTY ? 'd' : '-',
626 pgprot & _PAGE_PSE ? 'm' : 'k',
627 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
629 DRM_PROC_PRINT("\n");
632 if (len > request + offset)
638 static int drm_vma_info(char *buf, char **start, off_t offset, int request,
639 int *eof, void *data)
641 struct drm_minor *minor = (struct drm_minor *) data;
642 struct drm_device *dev = minor->dev;
645 mutex_lock(&dev->struct_mutex);
646 ret = drm__vma_info(buf, start, offset, request, eof, data);
647 mutex_unlock(&dev->struct_mutex);