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);
54 static int drm_gem_name_info(char *buf, char **start, off_t offset,
55 int request, int *eof, void *data);
56 static int drm_gem_object_info(char *buf, char **start, off_t offset,
57 int request, int *eof, void *data);
59 static int drm_vma_info(char *buf, char **start, off_t offset,
60 int request, int *eof, void *data);
66 static struct drm_proc_list {
67 const char *name; /**< file name */
68 int (*f) (char *, char **, off_t, int, int *, void *); /**< proc callback*/
70 {"name", drm_name_info},
71 {"mem", drm_mem_info},
73 {"clients", drm_clients_info},
74 {"queues", drm_queues_info},
75 {"bufs", drm_bufs_info},
76 {"objects", drm_objects_info},
77 {"gem_names", drm_gem_name_info},
78 {"gem_objects", drm_gem_object_info},
80 {"vma", drm_vma_info},
84 #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
87 * Initialize the DRI proc filesystem for a device.
89 * \param dev DRM device.
90 * \param minor device minor number.
91 * \param root DRI proc dir entry.
92 * \param dev_root resulting DRI device proc dir entry.
93 * \return root entry pointer on success, or NULL on failure.
95 * Create the DRI proc root entry "/proc/dri", the device proc root entry
96 * "/proc/dri/%minor%/", and each entry in proc_list as
97 * "/proc/dri/%minor%/%name%".
99 int drm_proc_init(struct drm_minor *minor, int minor_id,
100 struct proc_dir_entry *root)
102 struct proc_dir_entry *ent;
106 sprintf(name, "%d", minor_id);
107 minor->dev_root = proc_mkdir(name, root);
108 if (!minor->dev_root) {
109 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
113 for (i = 0; i < DRM_PROC_ENTRIES; i++) {
114 ent = create_proc_entry(drm_proc_list[i].name,
115 S_IFREG | S_IRUGO, minor->dev_root);
117 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
118 name, drm_proc_list[i].name);
119 for (j = 0; j < i; j++)
120 remove_proc_entry(drm_proc_list[i].name,
122 remove_proc_entry(name, root);
123 minor->dev_root = NULL;
126 ent->read_proc = drm_proc_list[i].f;
133 * Cleanup the proc filesystem resources.
135 * \param minor device minor number.
136 * \param root DRI proc dir entry.
137 * \param dev_root DRI device proc dir entry.
138 * \return always zero.
140 * Remove all proc entries created by proc_init().
142 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
147 if (!root || !minor->dev_root)
150 for (i = 0; i < DRM_PROC_ENTRIES; i++)
151 remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
152 sprintf(name, "%d", minor->index);
153 remove_proc_entry(name, root);
159 * Called when "/proc/dri/.../name" is read.
161 * \param buf output buffer.
162 * \param start start of output data.
163 * \param offset requested start offset.
164 * \param request requested number of bytes.
165 * \param eof whether there is no more data to return.
166 * \param data private data.
167 * \return number of written bytes.
169 * Prints the device name together with the bus id if available.
171 static int drm_name_info(char *buf, char **start, off_t offset, int request,
172 int *eof, void *data)
174 struct drm_minor *minor = (struct drm_minor *) data;
175 struct drm_master *master = minor->master;
176 struct drm_device *dev = minor->dev;
179 if (offset > DRM_PROC_LIMIT) {
187 *start = &buf[offset];
190 if (master->unique) {
191 DRM_PROC_PRINT("%s %s %s\n",
192 dev->driver->pci_driver.name,
193 pci_name(dev->pdev), master->unique);
195 DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
196 pci_name(dev->pdev));
199 if (len > request + offset)
206 * Called when "/proc/dri/.../vm" is read.
208 * \param buf output buffer.
209 * \param start start of output data.
210 * \param offset requested start offset.
211 * \param request requested number of bytes.
212 * \param eof whether there is no more data to return.
213 * \param data private data.
214 * \return number of written bytes.
216 * Prints information about all mappings in drm_device::maplist.
218 static int drm__vm_info(char *buf, char **start, off_t offset, int request,
219 int *eof, void *data)
221 struct drm_minor *minor = (struct drm_minor *) data;
222 struct drm_device *dev = minor->dev;
225 struct drm_map_list *r_list;
227 /* Hardcoded from _DRM_FRAME_BUFFER,
228 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP,
229 _DRM_SCATTER_GATHER, and _DRM_CONSISTENT. */
230 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
234 if (offset > DRM_PROC_LIMIT) {
239 *start = &buf[offset];
242 DRM_PROC_PRINT("slot offset size type flags "
245 list_for_each_entry(r_list, &dev->maplist, head) {
249 if (map->type < 0 || map->type > 5)
252 type = types[map->type];
253 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
256 map->size, type, map->flags,
257 (unsigned long) r_list->user_token);
260 DRM_PROC_PRINT("none\n");
262 DRM_PROC_PRINT("%4d\n", map->mtrr);
267 if (len > request + offset)
274 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
276 static int drm_vm_info(char *buf, char **start, off_t offset, int request,
277 int *eof, void *data)
279 struct drm_minor *minor = (struct drm_minor *) data;
280 struct drm_device *dev = minor->dev;
283 mutex_lock(&dev->struct_mutex);
284 ret = drm__vm_info(buf, start, offset, request, eof, data);
285 mutex_unlock(&dev->struct_mutex);
290 * Called when "/proc/dri/.../queues" is read.
292 * \param buf output buffer.
293 * \param start start of output data.
294 * \param offset requested start offset.
295 * \param request requested number of bytes.
296 * \param eof whether there is no more data to return.
297 * \param data private data.
298 * \return number of written bytes.
300 static int drm__queues_info(char *buf, char **start, off_t offset,
301 int request, int *eof, void *data)
303 struct drm_minor *minor = (struct drm_minor *) data;
304 struct drm_device *dev = minor->dev;
309 if (offset > DRM_PROC_LIMIT) {
314 *start = &buf[offset];
317 DRM_PROC_PRINT(" ctx/flags use fin"
318 " blk/rw/rwf wait flushed queued"
320 for (i = 0; i < dev->queue_count; i++) {
321 q = dev->queuelist[i];
322 atomic_inc(&q->use_count);
323 DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
325 " %5d/%c%c/%c%c%c %5Zd\n",
328 atomic_read(&q->use_count),
329 atomic_read(&q->finalization),
330 atomic_read(&q->block_count),
331 atomic_read(&q->block_read) ? 'r' : '-',
332 atomic_read(&q->block_write) ? 'w' : '-',
333 waitqueue_active(&q->read_queue) ? 'r' : '-',
334 waitqueue_active(&q->
335 write_queue) ? 'w' : '-',
336 waitqueue_active(&q->
337 flush_queue) ? 'f' : '-',
338 DRM_BUFCOUNT(&q->waitlist));
339 atomic_dec(&q->use_count);
342 if (len > request + offset)
349 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
351 static int drm_queues_info(char *buf, char **start, off_t offset, int request,
352 int *eof, void *data)
354 struct drm_minor *minor = (struct drm_minor *) data;
355 struct drm_device *dev = minor->dev;
358 mutex_lock(&dev->struct_mutex);
359 ret = drm__queues_info(buf, start, offset, request, eof, data);
360 mutex_unlock(&dev->struct_mutex);
365 * Called when "/proc/dri/.../bufs" is read.
367 * \param buf output buffer.
368 * \param start start of output data.
369 * \param offset requested start offset.
370 * \param request requested number of bytes.
371 * \param eof whether there is no more data to return.
372 * \param data private data.
373 * \return number of written bytes.
375 static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
376 int *eof, void *data)
378 struct drm_minor *minor = (struct drm_minor *) data;
379 struct drm_device *dev = minor->dev;
381 struct drm_device_dma *dma = dev->dma;
384 if (!dma || offset > DRM_PROC_LIMIT) {
389 *start = &buf[offset];
392 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
393 for (i = 0; i <= DRM_MAX_ORDER; i++) {
394 if (dma->bufs[i].buf_count)
395 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
397 dma->bufs[i].buf_size,
398 dma->bufs[i].buf_count,
399 atomic_read(&dma->bufs[i]
401 dma->bufs[i].seg_count,
402 dma->bufs[i].seg_count
403 * (1 << dma->bufs[i].page_order),
404 (dma->bufs[i].seg_count
405 * (1 << dma->bufs[i].page_order))
408 DRM_PROC_PRINT("\n");
409 for (i = 0; i < dma->buf_count; i++) {
411 DRM_PROC_PRINT("\n");
412 DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
414 DRM_PROC_PRINT("\n");
416 if (len > request + offset)
423 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
425 static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
426 int *eof, void *data)
428 struct drm_minor *minor = (struct drm_minor *) data;
429 struct drm_device *dev = minor->dev;
432 mutex_lock(&dev->struct_mutex);
433 ret = drm__bufs_info(buf, start, offset, request, eof, data);
434 mutex_unlock(&dev->struct_mutex);
439 * Called when "/proc/dri/.../objects" is read.
441 * \param buf output buffer.
442 * \param start start of output data.
443 * \param offset requested start offset.
444 * \param request requested number of bytes.
445 * \param eof whether there is no more data to return.
446 * \param data private data.
447 * \return number of written bytes.
449 static int drm__objects_info(char *buf, char **start, off_t offset, int request,
450 int *eof, void *data)
452 struct drm_minor *minor = (struct drm_minor *) data;
453 struct drm_device *dev = minor->dev;
455 struct drm_buffer_manager *bm = &dev->bm;
456 struct drm_fence_manager *fm = &dev->fm;
463 if (offset > DRM_PROC_LIMIT) {
468 *start = &buf[offset];
471 DRM_PROC_PRINT("Object accounting:\n\n");
472 if (fm->initialized) {
473 DRM_PROC_PRINT("Number of active fence objects: %d.\n",
474 atomic_read(&fm->count));
476 DRM_PROC_PRINT("Fence objects are not supported by this driver\n");
479 if (bm->initialized) {
480 DRM_PROC_PRINT("Number of active buffer objects: %d.\n\n",
481 atomic_read(&bm->count));
483 DRM_PROC_PRINT("Memory accounting:\n\n");
484 if (bm->initialized) {
485 DRM_PROC_PRINT("Number of locked GATT pages: %lu.\n", bm->cur_pages);
487 DRM_PROC_PRINT("Buffer objects are not supported by this driver.\n");
490 drm_query_memctl(&used_mem, &used_emer, &low_mem, &high_mem, &emer_mem);
492 if (used_mem > 16*PAGE_SIZE) {
493 DRM_PROC_PRINT("Used object memory is %lu pages.\n",
494 (unsigned long) (used_mem >> PAGE_SHIFT));
496 DRM_PROC_PRINT("Used object memory is %lu bytes.\n",
497 (unsigned long) used_mem);
499 if (used_emer > 16*PAGE_SIZE) {
500 DRM_PROC_PRINT("Used emergency memory is %lu pages.\n",
501 (unsigned long) (used_emer >> PAGE_SHIFT));
503 DRM_PROC_PRINT("Used emergency memory is %lu bytes.\n\n",
504 (unsigned long) used_emer);
506 DRM_PROC_PRINT("Soft object memory usage threshold is %lu pages.\n",
507 (unsigned long) (low_mem >> PAGE_SHIFT));
508 DRM_PROC_PRINT("Hard object memory usage threshold is %lu pages.\n",
509 (unsigned long) (high_mem >> PAGE_SHIFT));
510 DRM_PROC_PRINT("Emergency root only memory usage threshold is %lu pages.\n",
511 (unsigned long) (emer_mem >> PAGE_SHIFT));
513 DRM_PROC_PRINT("\n");
515 if (len > request + offset)
522 * Simply calls _objects_info() while holding the drm_device::struct_mutex lock.
524 static int drm_objects_info(char *buf, char **start, off_t offset, int request,
525 int *eof, void *data)
527 struct drm_minor *minor = (struct drm_minor *) data;
528 struct drm_device *dev = minor->dev;
531 mutex_lock(&dev->struct_mutex);
532 ret = drm__objects_info(buf, start, offset, request, eof, data);
533 mutex_unlock(&dev->struct_mutex);
538 * Called when "/proc/dri/.../clients" is read.
540 * \param buf output buffer.
541 * \param start start of output data.
542 * \param offset requested start offset.
543 * \param request requested number of bytes.
544 * \param eof whether there is no more data to return.
545 * \param data private data.
546 * \return number of written bytes.
548 static int drm__clients_info(char *buf, char **start, off_t offset,
549 int request, int *eof, void *data)
551 struct drm_minor *minor = (struct drm_minor *) data;
552 struct drm_device *dev = minor->dev;
554 struct drm_file *priv;
556 if (offset > DRM_PROC_LIMIT) {
561 *start = &buf[offset];
564 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
565 list_for_each_entry(priv, &dev->filelist, lhead) {
566 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
567 priv->authenticated ? 'y' : 'n',
570 priv->uid, priv->magic, priv->ioctl_count);
573 if (len > request + offset)
580 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
582 static int drm_clients_info(char *buf, char **start, off_t offset,
583 int request, int *eof, void *data)
585 struct drm_minor *minor = (struct drm_minor *) data;
586 struct drm_device *dev = minor->dev;
589 mutex_lock(&dev->struct_mutex);
590 ret = drm__clients_info(buf, start, offset, request, eof, data);
591 mutex_unlock(&dev->struct_mutex);
595 struct drm_gem_name_info_data {
601 static int drm_gem_one_name_info(int id, void *ptr, void *data)
603 struct drm_gem_object *obj = ptr;
604 struct drm_gem_name_info_data *nid = data;
606 DRM_INFO("name %d size %d\n", obj->name, obj->size);
610 nid->len += sprintf(&nid->buf[nid->len],
612 obj->name, obj->size,
613 atomic_read(&obj->handlecount.refcount),
614 atomic_read(&obj->refcount.refcount));
615 if (nid->len > DRM_PROC_LIMIT) {
622 static int drm_gem_name_info(char *buf, char **start, off_t offset,
623 int request, int *eof, void *data)
625 struct drm_minor *minor = (struct drm_minor *) data;
626 struct drm_device *dev = minor->dev;
627 struct drm_gem_name_info_data nid;
629 if (offset > DRM_PROC_LIMIT) {
634 nid.len = sprintf(buf, " name size handles refcount\n");
637 idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, &nid);
639 *start = &buf[offset];
641 if (nid.len > request + offset)
644 return nid.len - offset;
647 static int drm_gem_object_info(char *buf, char **start, off_t offset,
648 int request, int *eof, void *data)
650 struct drm_minor *minor = (struct drm_minor *) data;
651 struct drm_device *dev = minor->dev;
654 if (offset > DRM_PROC_LIMIT) {
659 *start = &buf[offset];
661 DRM_PROC_PRINT("%d objects\n", atomic_read(&dev->object_count));
662 DRM_PROC_PRINT("%d object bytes\n", atomic_read(&dev->object_memory));
663 DRM_PROC_PRINT("%d pinned\n", atomic_read(&dev->pin_count));
664 DRM_PROC_PRINT("%d pin bytes\n", atomic_read(&dev->pin_memory));
665 DRM_PROC_PRINT("%d gtt bytes\n", atomic_read(&dev->gtt_memory));
666 DRM_PROC_PRINT("%d gtt total\n", dev->gtt_total);
667 if (len > request + offset)
675 static int drm__vma_info(char *buf, char **start, off_t offset, int request,
676 int *eof, void *data)
678 struct drm_minor *minor = (struct drm_minor *) data;
679 struct drm_device *dev = minor->dev;
681 struct drm_vma_entry *pt;
682 struct vm_area_struct *vma;
683 #if defined(__i386__)
687 if (offset > DRM_PROC_LIMIT) {
692 *start = &buf[offset];
695 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
696 atomic_read(&dev->vma_count),
697 high_memory, virt_to_phys(high_memory));
698 list_for_each_entry(pt, &dev->vmalist, head) {
699 if (!(vma = pt->vma))
701 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
705 vma->vm_flags & VM_READ ? 'r' : '-',
706 vma->vm_flags & VM_WRITE ? 'w' : '-',
707 vma->vm_flags & VM_EXEC ? 'x' : '-',
708 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
709 vma->vm_flags & VM_LOCKED ? 'l' : '-',
710 vma->vm_flags & VM_IO ? 'i' : '-',
713 #if defined(__i386__)
714 pgprot = pgprot_val(vma->vm_page_prot);
715 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
716 pgprot & _PAGE_PRESENT ? 'p' : '-',
717 pgprot & _PAGE_RW ? 'w' : 'r',
718 pgprot & _PAGE_USER ? 'u' : 's',
719 pgprot & _PAGE_PWT ? 't' : 'b',
720 pgprot & _PAGE_PCD ? 'u' : 'c',
721 pgprot & _PAGE_ACCESSED ? 'a' : '-',
722 pgprot & _PAGE_DIRTY ? 'd' : '-',
723 pgprot & _PAGE_PSE ? 'm' : 'k',
724 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
726 DRM_PROC_PRINT("\n");
729 if (len > request + offset)
735 static int drm_vma_info(char *buf, char **start, off_t offset, int request,
736 int *eof, void *data)
738 struct drm_minor *minor = (struct drm_minor *) data;
739 struct drm_device *dev = minor->dev;
742 mutex_lock(&dev->struct_mutex);
743 ret = drm__vma_info(buf, start, offset, request, eof, data);
744 mutex_unlock(&dev->struct_mutex);