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_vblank_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*/
69 u32 driver_features; /**< Required driver features for this entry */
71 {"name", drm_name_info, 0},
72 {"mem", drm_mem_info, 0},
73 {"vm", drm_vm_info, 0},
74 {"clients", drm_clients_info, 0},
75 {"queues", drm_queues_info, 0},
76 {"bufs", drm_bufs_info, 0},
77 {"vblank", drm_vblank_info, 0},
78 {"gem_names", drm_gem_name_info, DRIVER_GEM},
79 {"gem_objects", drm_gem_object_info, DRIVER_GEM},
81 {"vma", drm_vma_info},
85 #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
88 * Initialize the DRI proc filesystem for a device.
90 * \param dev DRM device.
91 * \param minor device minor number.
92 * \param root DRI proc dir entry.
93 * \param dev_root resulting DRI device proc dir entry.
94 * \return root entry pointer on success, or NULL on failure.
96 * Create the DRI proc root entry "/proc/dri", the device proc root entry
97 * "/proc/dri/%minor%/", and each entry in proc_list as
98 * "/proc/dri/%minor%/%name%".
100 int drm_proc_init(struct drm_minor *minor, int minor_id,
101 struct proc_dir_entry *root)
103 struct drm_device *dev = minor->dev;
104 struct proc_dir_entry *ent;
108 sprintf(name, "%d", minor_id);
109 minor->dev_root = proc_mkdir(name, root);
110 if (!minor->dev_root) {
111 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
115 for (i = 0; i < DRM_PROC_ENTRIES; i++) {
116 u32 features = drm_proc_list[i].driver_features;
119 (dev->driver->driver_features & features) != features)
122 ent = create_proc_entry(drm_proc_list[i].name,
123 S_IFREG | S_IRUGO, minor->dev_root);
125 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
126 name, drm_proc_list[i].name);
130 ent->read_proc = drm_proc_list[i].f;
134 if (dev->driver->proc_init) {
135 ret = dev->driver->proc_init(minor);
137 DRM_ERROR("DRM: Driver failed to initialize "
146 for (j = 0; j < i; j++)
147 remove_proc_entry(drm_proc_list[i].name,
149 remove_proc_entry(name, root);
150 minor->dev_root = NULL;
155 * Cleanup the proc filesystem resources.
157 * \param minor device minor number.
158 * \param root DRI proc dir entry.
159 * \param dev_root DRI device proc dir entry.
160 * \return always zero.
162 * Remove all proc entries created by proc_init().
164 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
166 struct drm_device *dev = minor->dev;
170 if (!root || !minor->dev_root)
173 if (dev->driver->proc_cleanup)
174 dev->driver->proc_cleanup(minor);
176 for (i = 0; i < DRM_PROC_ENTRIES; i++)
177 remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
178 sprintf(name, "%d", minor->index);
179 remove_proc_entry(name, root);
185 * Called when "/proc/dri/.../name" is read.
187 * \param buf output buffer.
188 * \param start start of output data.
189 * \param offset requested start offset.
190 * \param request requested number of bytes.
191 * \param eof whether there is no more data to return.
192 * \param data private data.
193 * \return number of written bytes.
195 * Prints the device name together with the bus id if available.
197 static int drm_name_info(char *buf, char **start, off_t offset, int request,
198 int *eof, void *data)
200 struct drm_minor *minor = (struct drm_minor *) data;
201 struct drm_master *master = minor->master;
202 struct drm_device *dev = minor->dev;
205 if (offset > DRM_PROC_LIMIT) {
213 *start = &buf[offset];
216 if (master->unique) {
217 DRM_PROC_PRINT("%s %s %s\n",
218 dev->driver->pci_driver.name,
219 pci_name(dev->pdev), master->unique);
221 DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
222 pci_name(dev->pdev));
225 if (len > request + offset)
232 * Called when "/proc/dri/.../vm" is read.
234 * \param buf output buffer.
235 * \param start start of output data.
236 * \param offset requested start offset.
237 * \param request requested number of bytes.
238 * \param eof whether there is no more data to return.
239 * \param data private data.
240 * \return number of written bytes.
242 * Prints information about all mappings in drm_device::maplist.
244 static int drm__vm_info(char *buf, char **start, off_t offset, int request,
245 int *eof, void *data)
247 struct drm_minor *minor = (struct drm_minor *) data;
248 struct drm_device *dev = minor->dev;
251 struct drm_map_list *r_list;
253 /* Hardcoded from _DRM_FRAME_BUFFER,
254 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
255 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
256 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
260 if (offset > DRM_PROC_LIMIT) {
265 *start = &buf[offset];
268 DRM_PROC_PRINT("slot offset size type flags "
271 list_for_each_entry(r_list, &dev->maplist, head) {
275 if (map->type < 0 || map->type > 5)
278 type = types[map->type];
279 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
282 map->size, type, map->flags,
283 (unsigned long) r_list->user_token);
285 DRM_PROC_PRINT("none\n");
287 DRM_PROC_PRINT("%4d\n", map->mtrr);
292 if (len > request + offset)
299 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
301 static int drm_vm_info(char *buf, char **start, off_t offset, int request,
302 int *eof, void *data)
304 struct drm_minor *minor = (struct drm_minor *) data;
305 struct drm_device *dev = minor->dev;
308 mutex_lock(&dev->struct_mutex);
309 ret = drm__vm_info(buf, start, offset, request, eof, data);
310 mutex_unlock(&dev->struct_mutex);
315 * Called when "/proc/dri/.../queues" is read.
317 * \param buf output buffer.
318 * \param start start of output data.
319 * \param offset requested start offset.
320 * \param request requested number of bytes.
321 * \param eof whether there is no more data to return.
322 * \param data private data.
323 * \return number of written bytes.
325 static int drm__queues_info(char *buf, char **start, off_t offset,
326 int request, int *eof, void *data)
328 struct drm_minor *minor = (struct drm_minor *) data;
329 struct drm_device *dev = minor->dev;
334 if (offset > DRM_PROC_LIMIT) {
339 *start = &buf[offset];
342 DRM_PROC_PRINT(" ctx/flags use fin"
343 " blk/rw/rwf wait flushed queued"
345 for (i = 0; i < dev->queue_count; i++) {
346 q = dev->queuelist[i];
347 atomic_inc(&q->use_count);
348 DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
350 " %5d/%c%c/%c%c%c %5Zd\n",
353 atomic_read(&q->use_count),
354 atomic_read(&q->finalization),
355 atomic_read(&q->block_count),
356 atomic_read(&q->block_read) ? 'r' : '-',
357 atomic_read(&q->block_write) ? 'w' : '-',
358 waitqueue_active(&q->read_queue) ? 'r' : '-',
359 waitqueue_active(&q->
360 write_queue) ? 'w' : '-',
361 waitqueue_active(&q->
362 flush_queue) ? 'f' : '-',
363 DRM_BUFCOUNT(&q->waitlist));
364 atomic_dec(&q->use_count);
367 if (len > request + offset)
374 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
376 static int drm_queues_info(char *buf, char **start, off_t offset, int request,
377 int *eof, void *data)
379 struct drm_minor *minor = (struct drm_minor *) data;
380 struct drm_device *dev = minor->dev;
383 mutex_lock(&dev->struct_mutex);
384 ret = drm__queues_info(buf, start, offset, request, eof, data);
385 mutex_unlock(&dev->struct_mutex);
390 * Called when "/proc/dri/.../bufs" is read.
392 * \param buf output buffer.
393 * \param start start of output data.
394 * \param offset requested start offset.
395 * \param request requested number of bytes.
396 * \param eof whether there is no more data to return.
397 * \param data private data.
398 * \return number of written bytes.
400 static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
401 int *eof, void *data)
403 struct drm_minor *minor = (struct drm_minor *) data;
404 struct drm_device *dev = minor->dev;
406 struct drm_device_dma *dma = dev->dma;
409 if (!dma || offset > DRM_PROC_LIMIT) {
414 *start = &buf[offset];
417 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
418 for (i = 0; i <= DRM_MAX_ORDER; i++) {
419 if (dma->bufs[i].buf_count)
420 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
422 dma->bufs[i].buf_size,
423 dma->bufs[i].buf_count,
424 atomic_read(&dma->bufs[i]
426 dma->bufs[i].seg_count,
427 dma->bufs[i].seg_count
428 * (1 << dma->bufs[i].page_order),
429 (dma->bufs[i].seg_count
430 * (1 << dma->bufs[i].page_order))
433 DRM_PROC_PRINT("\n");
434 for (i = 0; i < dma->buf_count; i++) {
436 DRM_PROC_PRINT("\n");
437 DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
439 DRM_PROC_PRINT("\n");
441 if (len > request + offset)
448 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
450 static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
451 int *eof, void *data)
453 struct drm_minor *minor = (struct drm_minor *) data;
454 struct drm_device *dev = minor->dev;
457 mutex_lock(&dev->struct_mutex);
458 ret = drm__bufs_info(buf, start, offset, request, eof, data);
459 mutex_unlock(&dev->struct_mutex);
464 * Called when "/proc/dri/.../vblank" is read.
466 * \param buf output buffer.
467 * \param start start of output data.
468 * \param offset requested start offset.
469 * \param request requested number of bytes.
470 * \param eof whether there is no more data to return.
471 * \param data private data.
472 * \return number of written bytes.
474 static int drm__vblank_info(char *buf, char **start, off_t offset, int request,
475 int *eof, void *data)
477 struct drm_minor *minor = (struct drm_minor *) data;
478 struct drm_device *dev = minor->dev;
482 if (offset > DRM_PROC_LIMIT) {
487 *start = &buf[offset];
490 for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
491 DRM_PROC_PRINT("CRTC %d enable: %d\n",
492 crtc, atomic_read(&dev->vblank_refcount[crtc]));
493 DRM_PROC_PRINT("CRTC %d counter: %d\n",
494 crtc, drm_vblank_count(dev, crtc));
495 DRM_PROC_PRINT("CRTC %d last wait: %d\n",
496 crtc, dev->last_vblank_wait[crtc]);
497 DRM_PROC_PRINT("CRTC %d in modeset: %d\n",
498 crtc, dev->vblank_inmodeset[crtc]);
501 if (len > request + offset)
508 * Simply calls _vblank_info() while holding the drm_device::struct_mutex lock.
510 static int drm_vblank_info(char *buf, char **start, off_t offset, int request,
511 int *eof, void *data)
513 struct drm_minor *minor = (struct drm_minor *) data;
514 struct drm_device *dev = minor->dev;
517 mutex_lock(&dev->struct_mutex);
518 ret = drm__vblank_info(buf, start, offset, request, eof, data);
519 mutex_unlock(&dev->struct_mutex);
524 * Called when "/proc/dri/.../clients" is read.
526 * \param buf output buffer.
527 * \param start start of output data.
528 * \param offset requested start offset.
529 * \param request requested number of bytes.
530 * \param eof whether there is no more data to return.
531 * \param data private data.
532 * \return number of written bytes.
534 static int drm__clients_info(char *buf, char **start, off_t offset,
535 int request, int *eof, void *data)
537 struct drm_minor *minor = (struct drm_minor *) data;
538 struct drm_device *dev = minor->dev;
540 struct drm_file *priv;
542 if (offset > DRM_PROC_LIMIT) {
547 *start = &buf[offset];
550 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
551 list_for_each_entry(priv, &dev->filelist, lhead) {
552 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
553 priv->authenticated ? 'y' : 'n',
556 priv->uid, priv->magic, priv->ioctl_count);
559 if (len > request + offset)
566 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
568 static int drm_clients_info(char *buf, char **start, off_t offset,
569 int request, int *eof, void *data)
571 struct drm_minor *minor = (struct drm_minor *) data;
572 struct drm_device *dev = minor->dev;
575 mutex_lock(&dev->struct_mutex);
576 ret = drm__clients_info(buf, start, offset, request, eof, data);
577 mutex_unlock(&dev->struct_mutex);
581 struct drm_gem_name_info_data {
587 static int drm_gem_one_name_info(int id, void *ptr, void *data)
589 struct drm_gem_object *obj = ptr;
590 struct drm_gem_name_info_data *nid = data;
592 DRM_INFO("name %d size %zd\n", obj->name, obj->size);
596 nid->len += sprintf(&nid->buf[nid->len],
597 "%6d %8zd %7d %8d\n",
598 obj->name, obj->size,
599 atomic_read(&obj->handlecount.refcount),
600 atomic_read(&obj->refcount.refcount));
601 if (nid->len > DRM_PROC_LIMIT) {
608 static int drm_gem_name_info(char *buf, char **start, off_t offset,
609 int request, int *eof, void *data)
611 struct drm_minor *minor = (struct drm_minor *) data;
612 struct drm_device *dev = minor->dev;
613 struct drm_gem_name_info_data nid;
615 if (offset > DRM_PROC_LIMIT) {
620 nid.len = sprintf(buf, " name size handles refcount\n");
623 idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, &nid);
625 *start = &buf[offset];
627 if (nid.len > request + offset)
630 return nid.len - offset;
633 static int drm_gem_object_info(char *buf, char **start, off_t offset,
634 int request, int *eof, void *data)
636 struct drm_minor *minor = (struct drm_minor *) data;
637 struct drm_device *dev = minor->dev;
640 if (offset > DRM_PROC_LIMIT) {
645 *start = &buf[offset];
647 DRM_PROC_PRINT("%d objects\n", atomic_read(&dev->object_count));
648 DRM_PROC_PRINT("%d object bytes\n", atomic_read(&dev->object_memory));
649 DRM_PROC_PRINT("%d pinned\n", atomic_read(&dev->pin_count));
650 DRM_PROC_PRINT("%d pin bytes\n", atomic_read(&dev->pin_memory));
651 DRM_PROC_PRINT("%d gtt bytes\n", atomic_read(&dev->gtt_memory));
652 DRM_PROC_PRINT("%d gtt total\n", dev->gtt_total);
653 if (len > request + offset)
661 static int drm__vma_info(char *buf, char **start, off_t offset, int request,
662 int *eof, void *data)
664 struct drm_minor *minor = (struct drm_minor *) data;
665 struct drm_device *dev = minor->dev;
667 struct drm_vma_entry *pt;
668 struct vm_area_struct *vma;
669 #if defined(__i386__)
673 if (offset > DRM_PROC_LIMIT) {
678 *start = &buf[offset];
681 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%llx\n",
682 atomic_read(&dev->vma_count),
683 high_memory, (u64)virt_to_phys(high_memory));
684 list_for_each_entry(pt, &dev->vmalist, head) {
685 if (!(vma = pt->vma))
687 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
691 vma->vm_flags & VM_READ ? 'r' : '-',
692 vma->vm_flags & VM_WRITE ? 'w' : '-',
693 vma->vm_flags & VM_EXEC ? 'x' : '-',
694 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
695 vma->vm_flags & VM_LOCKED ? 'l' : '-',
696 vma->vm_flags & VM_IO ? 'i' : '-',
699 #if defined(__i386__)
700 pgprot = pgprot_val(vma->vm_page_prot);
701 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
702 pgprot & _PAGE_PRESENT ? 'p' : '-',
703 pgprot & _PAGE_RW ? 'w' : 'r',
704 pgprot & _PAGE_USER ? 'u' : 's',
705 pgprot & _PAGE_PWT ? 't' : 'b',
706 pgprot & _PAGE_PCD ? 'u' : 'c',
707 pgprot & _PAGE_ACCESSED ? 'a' : '-',
708 pgprot & _PAGE_DIRTY ? 'd' : '-',
709 pgprot & _PAGE_PSE ? 'm' : 'k',
710 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
712 DRM_PROC_PRINT("\n");
715 if (len > request + offset)
721 static int drm_vma_info(char *buf, char **start, off_t offset, int request,
722 int *eof, void *data)
724 struct drm_minor *minor = (struct drm_minor *) data;
725 struct drm_device *dev = minor->dev;
728 mutex_lock(&dev->struct_mutex);
729 ret = drm__vma_info(buf, start, offset, request, eof, data);
730 mutex_unlock(&dev->struct_mutex);