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(drm_device_t * dev, int minor,
94 struct proc_dir_entry *root, struct proc_dir_entry **dev_root)
96 struct proc_dir_entry *ent;
100 sprintf(name, "%d", minor);
101 *dev_root = proc_mkdir(name, 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, *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);
119 ent->read_proc = drm_proc_list[i].f;
126 * Cleanup the proc filesystem resources.
128 * \param minor device minor number.
129 * \param root DRI proc dir entry.
130 * \param dev_root DRI device proc dir entry.
131 * \return always zero.
133 * Remove all proc entries created by proc_init().
135 int drm_proc_cleanup(int minor, struct proc_dir_entry *root,
136 struct proc_dir_entry *dev_root)
141 if (!root || !dev_root)
144 for (i = 0; i < DRM_PROC_ENTRIES; i++)
145 remove_proc_entry(drm_proc_list[i].name, dev_root);
146 sprintf(name, "%d", minor);
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 drm_device_t *dev = (drm_device_t *) data;
171 if (offset > DRM_PROC_LIMIT) {
176 *start = &buf[offset];
180 DRM_PROC_PRINT("%s %s %s\n",
181 dev->driver->pci_driver.name,
182 pci_name(dev->pdev), dev->unique);
184 DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
185 pci_name(dev->pdev));
188 if (len > request + offset)
195 * Called when "/proc/dri/.../vm" is read.
197 * \param buf output buffer.
198 * \param start start of output data.
199 * \param offset requested start offset.
200 * \param request requested number of bytes.
201 * \param eof whether there is no more data to return.
202 * \param data private data.
203 * \return number of written bytes.
205 * Prints information about all mappings in drm_device::maplist.
207 static int drm__vm_info(char *buf, char **start, off_t offset, int request,
208 int *eof, void *data)
210 drm_device_t *dev = (drm_device_t *) data;
213 drm_map_list_t *r_list;
215 /* Hardcoded from _DRM_FRAME_BUFFER,
216 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP,
217 _DRM_SCATTER_GATHER, and _DRM_CONSISTENT. */
218 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
222 if (offset > DRM_PROC_LIMIT) {
227 *start = &buf[offset];
230 DRM_PROC_PRINT("slot offset size type flags "
233 list_for_each_entry(r_list, &dev->maplist, head) {
237 if (map->type < 0 || map->type > 5)
240 type = types[map->type];
241 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
244 map->size, type, map->flags,
245 (unsigned long) r_list->user_token);
248 DRM_PROC_PRINT("none\n");
250 DRM_PROC_PRINT("%4d\n", map->mtrr);
255 if (len > request + offset)
262 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
264 static int drm_vm_info(char *buf, char **start, off_t offset, int request,
265 int *eof, void *data)
267 drm_device_t *dev = (drm_device_t *) data;
270 mutex_lock(&dev->struct_mutex);
271 ret = drm__vm_info(buf, start, offset, request, eof, data);
272 mutex_unlock(&dev->struct_mutex);
277 * Called when "/proc/dri/.../queues" is read.
279 * \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.
287 static int drm__queues_info(char *buf, char **start, off_t offset,
288 int request, int *eof, void *data)
290 drm_device_t *dev = (drm_device_t *) data;
295 if (offset > DRM_PROC_LIMIT) {
300 *start = &buf[offset];
303 DRM_PROC_PRINT(" ctx/flags use fin"
304 " blk/rw/rwf wait flushed queued"
306 for (i = 0; i < dev->queue_count; i++) {
307 q = dev->queuelist[i];
308 atomic_inc(&q->use_count);
309 DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
311 " %5d/%c%c/%c%c%c %5Zd\n",
314 atomic_read(&q->use_count),
315 atomic_read(&q->finalization),
316 atomic_read(&q->block_count),
317 atomic_read(&q->block_read) ? 'r' : '-',
318 atomic_read(&q->block_write) ? 'w' : '-',
319 waitqueue_active(&q->read_queue) ? 'r' : '-',
320 waitqueue_active(&q->
321 write_queue) ? 'w' : '-',
322 waitqueue_active(&q->
323 flush_queue) ? 'f' : '-',
324 DRM_BUFCOUNT(&q->waitlist));
325 atomic_dec(&q->use_count);
328 if (len > request + offset)
335 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
337 static int drm_queues_info(char *buf, char **start, off_t offset, int request,
338 int *eof, void *data)
340 drm_device_t *dev = (drm_device_t *) data;
343 mutex_lock(&dev->struct_mutex);
344 ret = drm__queues_info(buf, start, offset, request, eof, data);
345 mutex_unlock(&dev->struct_mutex);
350 * Called when "/proc/dri/.../bufs" is read.
352 * \param buf output buffer.
353 * \param start start of output data.
354 * \param offset requested start offset.
355 * \param request requested number of bytes.
356 * \param eof whether there is no more data to return.
357 * \param data private data.
358 * \return number of written bytes.
360 static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
361 int *eof, void *data)
363 drm_device_t *dev = (drm_device_t *) data;
365 drm_device_dma_t *dma = dev->dma;
368 if (!dma || offset > DRM_PROC_LIMIT) {
373 *start = &buf[offset];
376 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
377 for (i = 0; i <= DRM_MAX_ORDER; i++) {
378 if (dma->bufs[i].buf_count)
379 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
381 dma->bufs[i].buf_size,
382 dma->bufs[i].buf_count,
383 atomic_read(&dma->bufs[i]
385 dma->bufs[i].seg_count,
386 dma->bufs[i].seg_count
387 * (1 << dma->bufs[i].page_order),
388 (dma->bufs[i].seg_count
389 * (1 << dma->bufs[i].page_order))
392 DRM_PROC_PRINT("\n");
393 for (i = 0; i < dma->buf_count; i++) {
395 DRM_PROC_PRINT("\n");
396 DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
398 DRM_PROC_PRINT("\n");
400 if (len > request + offset)
407 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
409 static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
410 int *eof, void *data)
412 drm_device_t *dev = (drm_device_t *) data;
415 mutex_lock(&dev->struct_mutex);
416 ret = drm__bufs_info(buf, start, offset, request, eof, data);
417 mutex_unlock(&dev->struct_mutex);
422 * Called when "/proc/dri/.../objects" is read.
424 * \param buf output buffer.
425 * \param start start of output data.
426 * \param offset requested start offset.
427 * \param request requested number of bytes.
428 * \param eof whether there is no more data to return.
429 * \param data private data.
430 * \return number of written bytes.
432 static int drm__objects_info(char *buf, char **start, off_t offset, int request,
433 int *eof, void *data)
435 drm_device_t *dev = (drm_device_t *) data;
437 drm_buffer_manager_t *bm = &dev->bm;
438 drm_fence_manager_t *fm = &dev->fm;
444 if (offset > DRM_PROC_LIMIT) {
449 *start = &buf[offset];
452 DRM_PROC_PRINT("Object accounting:\n\n");
453 if (fm->initialized) {
454 DRM_PROC_PRINT("Number of active fence objects: %d.\n",
455 atomic_read(&fm->count));
457 DRM_PROC_PRINT("Fence objects are not supported by this driver\n");
460 if (bm->initialized) {
461 DRM_PROC_PRINT("Number of active buffer objects: %d.\n\n",
462 atomic_read(&bm->count));
464 DRM_PROC_PRINT("Memory accounting:\n\n");
465 if (bm->initialized) {
466 DRM_PROC_PRINT("Number of locked GATT pages: %lu.\n", bm->cur_pages);
468 DRM_PROC_PRINT("Buffer objects are not supported by this driver.\n");
471 drm_query_memctl(&used_mem, &low_mem, &high_mem);
473 if (used_mem > 16*PAGE_SIZE) {
474 DRM_PROC_PRINT("Used object memory is %lu pages.\n",
475 (unsigned long) (used_mem >> PAGE_SHIFT));
477 DRM_PROC_PRINT("Used object memory is %lu bytes.\n",
478 (unsigned long) used_mem);
480 DRM_PROC_PRINT("Soft object memory usage threshold is %lu pages.\n",
481 (unsigned long) (low_mem >> PAGE_SHIFT));
482 DRM_PROC_PRINT("Hard object memory usage threshold is %lu pages.\n",
483 (unsigned long) (high_mem >> PAGE_SHIFT));
485 DRM_PROC_PRINT("\n");
487 if (len > request + offset)
494 * Simply calls _objects_info() while holding the drm_device::struct_mutex lock.
496 static int drm_objects_info(char *buf, char **start, off_t offset, int request,
497 int *eof, void *data)
499 drm_device_t *dev = (drm_device_t *) data;
502 mutex_lock(&dev->struct_mutex);
503 ret = drm__objects_info(buf, start, offset, request, eof, data);
504 mutex_unlock(&dev->struct_mutex);
509 * Called when "/proc/dri/.../clients" is read.
511 * \param buf output buffer.
512 * \param start start of output data.
513 * \param offset requested start offset.
514 * \param request requested number of bytes.
515 * \param eof whether there is no more data to return.
516 * \param data private data.
517 * \return number of written bytes.
519 static int drm__clients_info(char *buf, char **start, off_t offset,
520 int request, int *eof, void *data)
522 drm_device_t *dev = (drm_device_t *) data;
526 if (offset > DRM_PROC_LIMIT) {
531 *start = &buf[offset];
534 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
535 list_for_each_entry(priv, &dev->filelist, lhead) {
536 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
537 priv->authenticated ? 'y' : 'n',
540 priv->uid, priv->magic, priv->ioctl_count);
543 if (len > request + offset)
550 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
552 static int drm_clients_info(char *buf, char **start, off_t offset,
553 int request, int *eof, void *data)
555 drm_device_t *dev = (drm_device_t *) data;
558 mutex_lock(&dev->struct_mutex);
559 ret = drm__clients_info(buf, start, offset, request, eof, data);
560 mutex_unlock(&dev->struct_mutex);
566 static int drm__vma_info(char *buf, char **start, off_t offset, int request,
567 int *eof, void *data)
569 drm_device_t *dev = (drm_device_t *) data;
572 struct vm_area_struct *vma;
573 #if defined(__i386__)
577 if (offset > DRM_PROC_LIMIT) {
582 *start = &buf[offset];
585 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
586 atomic_read(&dev->vma_count),
587 high_memory, virt_to_phys(high_memory));
588 list_for_each_entry(pt, &dev->vmalist, head) {
589 if (!(vma = pt->vma))
591 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
595 vma->vm_flags & VM_READ ? 'r' : '-',
596 vma->vm_flags & VM_WRITE ? 'w' : '-',
597 vma->vm_flags & VM_EXEC ? 'x' : '-',
598 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
599 vma->vm_flags & VM_LOCKED ? 'l' : '-',
600 vma->vm_flags & VM_IO ? 'i' : '-',
603 #if defined(__i386__)
604 pgprot = pgprot_val(vma->vm_page_prot);
605 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
606 pgprot & _PAGE_PRESENT ? 'p' : '-',
607 pgprot & _PAGE_RW ? 'w' : 'r',
608 pgprot & _PAGE_USER ? 'u' : 's',
609 pgprot & _PAGE_PWT ? 't' : 'b',
610 pgprot & _PAGE_PCD ? 'u' : 'c',
611 pgprot & _PAGE_ACCESSED ? 'a' : '-',
612 pgprot & _PAGE_DIRTY ? 'd' : '-',
613 pgprot & _PAGE_PSE ? 'm' : 'k',
614 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
616 DRM_PROC_PRINT("\n");
619 if (len > request + offset)
625 static int drm_vma_info(char *buf, char **start, off_t offset, int request,
626 int *eof, void *data)
628 drm_device_t *dev = (drm_device_t *) data;
631 mutex_lock(&dev->struct_mutex);
632 ret = drm__vma_info(buf, start, offset, request, eof, data);
633 mutex_unlock(&dev->struct_mutex);