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_gem_name_info(char *buf, char **start, off_t offset,
53 int request, int *eof, void *data);
54 static int drm_gem_object_info(char *buf, char **start, off_t offset,
55 int request, int *eof, void *data);
57 static int drm_vma_info(char *buf, char **start, off_t offset,
58 int request, int *eof, void *data);
64 static struct drm_proc_list {
65 const char *name; /**< file name */
66 int (*f) (char *, char **, off_t, int, int *, void *); /**< proc callback*/
67 u32 driver_features; /**< Required driver features for this entry */
69 {"name", drm_name_info, 0},
70 {"mem", drm_mem_info, 0},
71 {"vm", drm_vm_info, 0},
72 {"clients", drm_clients_info, 0},
73 {"queues", drm_queues_info, 0},
74 {"bufs", drm_bufs_info, 0},
75 {"gem_names", drm_gem_name_info, DRIVER_GEM},
76 {"gem_objects", drm_gem_object_info, DRIVER_GEM},
78 {"vma", drm_vma_info},
82 #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
85 * Initialize the DRI proc filesystem for a device.
87 * \param dev DRM device.
88 * \param minor device minor number.
89 * \param root DRI proc dir entry.
90 * \param dev_root resulting DRI device proc dir entry.
91 * \return root entry pointer on success, or NULL on failure.
93 * Create the DRI proc root entry "/proc/dri", the device proc root entry
94 * "/proc/dri/%minor%/", and each entry in proc_list as
95 * "/proc/dri/%minor%/%name%".
97 int drm_proc_init(struct drm_minor *minor, int minor_id,
98 struct proc_dir_entry *root)
100 struct drm_device *dev = minor->dev;
101 struct proc_dir_entry *ent;
105 sprintf(name, "%d", minor_id);
106 minor->dev_root = proc_mkdir(name, root);
107 if (!minor->dev_root) {
108 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
112 for (i = 0; i < DRM_PROC_ENTRIES; i++) {
113 u32 features = drm_proc_list[i].driver_features;
116 (dev->driver->driver_features & features) != features)
119 ent = create_proc_entry(drm_proc_list[i].name,
120 S_IFREG | S_IRUGO, minor->dev_root);
122 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
123 name, drm_proc_list[i].name);
127 ent->read_proc = drm_proc_list[i].f;
131 if (dev->driver->proc_init) {
132 ret = dev->driver->proc_init(minor);
134 DRM_ERROR("DRM: Driver failed to initialize "
143 for (j = 0; j < i; j++)
144 remove_proc_entry(drm_proc_list[i].name,
146 remove_proc_entry(name, root);
147 minor->dev_root = NULL;
152 * Cleanup the proc filesystem resources.
154 * \param minor device minor number.
155 * \param root DRI proc dir entry.
156 * \param dev_root DRI device proc dir entry.
157 * \return always zero.
159 * Remove all proc entries created by proc_init().
161 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
163 struct drm_device *dev = minor->dev;
167 if (!root || !minor->dev_root)
170 if (dev->driver->proc_cleanup)
171 dev->driver->proc_cleanup(minor);
173 for (i = 0; i < DRM_PROC_ENTRIES; i++)
174 remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
175 sprintf(name, "%d", minor->index);
176 remove_proc_entry(name, root);
182 * Called when "/proc/dri/.../name" is read.
184 * \param buf output buffer.
185 * \param start start of output data.
186 * \param offset requested start offset.
187 * \param request requested number of bytes.
188 * \param eof whether there is no more data to return.
189 * \param data private data.
190 * \return number of written bytes.
192 * Prints the device name together with the bus id if available.
194 static int drm_name_info(char *buf, char **start, off_t offset, int request,
195 int *eof, void *data)
197 struct drm_minor *minor = (struct drm_minor *) data;
198 struct drm_master *master = minor->master;
199 struct drm_device *dev = minor->dev;
202 if (offset > DRM_PROC_LIMIT) {
210 *start = &buf[offset];
213 if (master->unique) {
214 DRM_PROC_PRINT("%s %s %s\n",
215 dev->driver->pci_driver.name,
216 pci_name(dev->pdev), master->unique);
218 DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
219 pci_name(dev->pdev));
222 if (len > request + offset)
229 * Called when "/proc/dri/.../vm" is read.
231 * \param buf output buffer.
232 * \param start start of output data.
233 * \param offset requested start offset.
234 * \param request requested number of bytes.
235 * \param eof whether there is no more data to return.
236 * \param data private data.
237 * \return number of written bytes.
239 * Prints information about all mappings in drm_device::maplist.
241 static int drm__vm_info(char *buf, char **start, off_t offset, int request,
242 int *eof, void *data)
244 struct drm_minor *minor = (struct drm_minor *) data;
245 struct drm_device *dev = minor->dev;
248 struct drm_map_list *r_list;
250 /* Hardcoded from _DRM_FRAME_BUFFER,
251 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
252 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
253 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
257 if (offset > DRM_PROC_LIMIT) {
262 *start = &buf[offset];
265 DRM_PROC_PRINT("slot offset size type flags "
268 list_for_each_entry(r_list, &dev->maplist, head) {
272 if (map->type < 0 || map->type > 5)
275 type = types[map->type];
276 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
279 map->size, type, map->flags,
280 (unsigned long) r_list->user_token);
282 DRM_PROC_PRINT("none\n");
284 DRM_PROC_PRINT("%4d\n", map->mtrr);
289 if (len > request + offset)
296 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
298 static int drm_vm_info(char *buf, char **start, off_t offset, int request,
299 int *eof, void *data)
301 struct drm_minor *minor = (struct drm_minor *) data;
302 struct drm_device *dev = minor->dev;
305 mutex_lock(&dev->struct_mutex);
306 ret = drm__vm_info(buf, start, offset, request, eof, data);
307 mutex_unlock(&dev->struct_mutex);
312 * Called when "/proc/dri/.../queues" is read.
314 * \param buf output buffer.
315 * \param start start of output data.
316 * \param offset requested start offset.
317 * \param request requested number of bytes.
318 * \param eof whether there is no more data to return.
319 * \param data private data.
320 * \return number of written bytes.
322 static int drm__queues_info(char *buf, char **start, off_t offset,
323 int request, int *eof, void *data)
325 struct drm_minor *minor = (struct drm_minor *) data;
326 struct drm_device *dev = minor->dev;
331 if (offset > DRM_PROC_LIMIT) {
336 *start = &buf[offset];
339 DRM_PROC_PRINT(" ctx/flags use fin"
340 " blk/rw/rwf wait flushed queued"
342 for (i = 0; i < dev->queue_count; i++) {
343 q = dev->queuelist[i];
344 atomic_inc(&q->use_count);
345 DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
347 " %5d/%c%c/%c%c%c %5Zd\n",
350 atomic_read(&q->use_count),
351 atomic_read(&q->finalization),
352 atomic_read(&q->block_count),
353 atomic_read(&q->block_read) ? 'r' : '-',
354 atomic_read(&q->block_write) ? 'w' : '-',
355 waitqueue_active(&q->read_queue) ? 'r' : '-',
356 waitqueue_active(&q->
357 write_queue) ? 'w' : '-',
358 waitqueue_active(&q->
359 flush_queue) ? 'f' : '-',
360 DRM_BUFCOUNT(&q->waitlist));
361 atomic_dec(&q->use_count);
364 if (len > request + offset)
371 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
373 static int drm_queues_info(char *buf, char **start, off_t offset, int request,
374 int *eof, void *data)
376 struct drm_minor *minor = (struct drm_minor *) data;
377 struct drm_device *dev = minor->dev;
380 mutex_lock(&dev->struct_mutex);
381 ret = drm__queues_info(buf, start, offset, request, eof, data);
382 mutex_unlock(&dev->struct_mutex);
387 * Called when "/proc/dri/.../bufs" is read.
389 * \param buf output buffer.
390 * \param start start of output data.
391 * \param offset requested start offset.
392 * \param request requested number of bytes.
393 * \param eof whether there is no more data to return.
394 * \param data private data.
395 * \return number of written bytes.
397 static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
398 int *eof, void *data)
400 struct drm_minor *minor = (struct drm_minor *) data;
401 struct drm_device *dev = minor->dev;
403 struct drm_device_dma *dma = dev->dma;
406 if (!dma || offset > DRM_PROC_LIMIT) {
411 *start = &buf[offset];
414 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
415 for (i = 0; i <= DRM_MAX_ORDER; i++) {
416 if (dma->bufs[i].buf_count)
417 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
419 dma->bufs[i].buf_size,
420 dma->bufs[i].buf_count,
421 atomic_read(&dma->bufs[i]
423 dma->bufs[i].seg_count,
424 dma->bufs[i].seg_count
425 * (1 << dma->bufs[i].page_order),
426 (dma->bufs[i].seg_count
427 * (1 << dma->bufs[i].page_order))
430 DRM_PROC_PRINT("\n");
431 for (i = 0; i < dma->buf_count; i++) {
433 DRM_PROC_PRINT("\n");
434 DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
436 DRM_PROC_PRINT("\n");
438 if (len > request + offset)
445 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
447 static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
448 int *eof, void *data)
450 struct drm_minor *minor = (struct drm_minor *) data;
451 struct drm_device *dev = minor->dev;
454 mutex_lock(&dev->struct_mutex);
455 ret = drm__bufs_info(buf, start, offset, request, eof, data);
456 mutex_unlock(&dev->struct_mutex);
461 * Called when "/proc/dri/.../clients" is read.
463 * \param buf output buffer.
464 * \param start start of output data.
465 * \param offset requested start offset.
466 * \param request requested number of bytes.
467 * \param eof whether there is no more data to return.
468 * \param data private data.
469 * \return number of written bytes.
471 static int drm__clients_info(char *buf, char **start, off_t offset,
472 int request, int *eof, void *data)
474 struct drm_minor *minor = (struct drm_minor *) data;
475 struct drm_device *dev = minor->dev;
477 struct drm_file *priv;
479 if (offset > DRM_PROC_LIMIT) {
484 *start = &buf[offset];
487 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
488 list_for_each_entry(priv, &dev->filelist, lhead) {
489 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
490 priv->authenticated ? 'y' : 'n',
493 priv->uid, priv->magic, priv->ioctl_count);
496 if (len > request + offset)
503 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
505 static int drm_clients_info(char *buf, char **start, off_t offset,
506 int request, 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__clients_info(buf, start, offset, request, eof, data);
514 mutex_unlock(&dev->struct_mutex);
518 struct drm_gem_name_info_data {
524 static int drm_gem_one_name_info(int id, void *ptr, void *data)
526 struct drm_gem_object *obj = ptr;
527 struct drm_gem_name_info_data *nid = data;
529 DRM_INFO("name %d size %zd\n", obj->name, obj->size);
533 nid->len += sprintf(&nid->buf[nid->len],
534 "%6d %8zd %7d %8d\n",
535 obj->name, obj->size,
536 atomic_read(&obj->handlecount.refcount),
537 atomic_read(&obj->refcount.refcount));
538 if (nid->len > DRM_PROC_LIMIT) {
545 static int drm_gem_name_info(char *buf, char **start, off_t offset,
546 int request, int *eof, void *data)
548 struct drm_minor *minor = (struct drm_minor *) data;
549 struct drm_device *dev = minor->dev;
550 struct drm_gem_name_info_data nid;
552 if (offset > DRM_PROC_LIMIT) {
557 nid.len = sprintf(buf, " name size handles refcount\n");
560 idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, &nid);
562 *start = &buf[offset];
564 if (nid.len > request + offset)
567 return nid.len - offset;
570 static int drm_gem_object_info(char *buf, char **start, off_t offset,
571 int request, int *eof, void *data)
573 struct drm_minor *minor = (struct drm_minor *) data;
574 struct drm_device *dev = minor->dev;
577 if (offset > DRM_PROC_LIMIT) {
582 *start = &buf[offset];
584 DRM_PROC_PRINT("%d objects\n", atomic_read(&dev->object_count));
585 DRM_PROC_PRINT("%d object bytes\n", atomic_read(&dev->object_memory));
586 DRM_PROC_PRINT("%d pinned\n", atomic_read(&dev->pin_count));
587 DRM_PROC_PRINT("%d pin bytes\n", atomic_read(&dev->pin_memory));
588 DRM_PROC_PRINT("%d gtt bytes\n", atomic_read(&dev->gtt_memory));
589 DRM_PROC_PRINT("%d gtt total\n", dev->gtt_total);
590 if (len > request + offset)
598 static int drm__vma_info(char *buf, char **start, off_t offset, int request,
599 int *eof, void *data)
601 struct drm_minor *minor = (struct drm_minor *) data;
602 struct drm_device *dev = minor->dev;
604 struct drm_vma_entry *pt;
605 struct vm_area_struct *vma;
606 #if defined(__i386__)
610 if (offset > DRM_PROC_LIMIT) {
615 *start = &buf[offset];
618 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
619 atomic_read(&dev->vma_count),
620 high_memory, virt_to_phys(high_memory));
621 list_for_each_entry(pt, &dev->vmalist, head) {
622 if (!(vma = pt->vma))
624 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
628 vma->vm_flags & VM_READ ? 'r' : '-',
629 vma->vm_flags & VM_WRITE ? 'w' : '-',
630 vma->vm_flags & VM_EXEC ? 'x' : '-',
631 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
632 vma->vm_flags & VM_LOCKED ? 'l' : '-',
633 vma->vm_flags & VM_IO ? 'i' : '-',
636 #if defined(__i386__)
637 pgprot = pgprot_val(vma->vm_page_prot);
638 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
639 pgprot & _PAGE_PRESENT ? 'p' : '-',
640 pgprot & _PAGE_RW ? 'w' : 'r',
641 pgprot & _PAGE_USER ? 'u' : 's',
642 pgprot & _PAGE_PWT ? 't' : 'b',
643 pgprot & _PAGE_PCD ? 'u' : 'c',
644 pgprot & _PAGE_ACCESSED ? 'a' : '-',
645 pgprot & _PAGE_DIRTY ? 'd' : '-',
646 pgprot & _PAGE_PSE ? 'm' : 'k',
647 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
649 DRM_PROC_PRINT("\n");
652 if (len > request + offset)
658 static int drm_vma_info(char *buf, char **start, off_t offset, int request,
659 int *eof, void *data)
661 struct drm_minor *minor = (struct drm_minor *) data;
662 struct drm_device *dev = minor->dev;
665 mutex_lock(&dev->struct_mutex);
666 ret = drm__vma_info(buf, start, offset, request, eof, data);
667 mutex_unlock(&dev->struct_mutex);