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
);
53 static int drm_vma_info(char *buf
, char **start
, off_t offset
,
54 int request
, int *eof
, void *data
);
60 static struct drm_proc_list
{
61 const char *name
; /**< file name */
62 int (*f
) (char *, char **, off_t
, int, int *, void *); /**< proc callback*/
64 {"name", drm_name_info
},
65 {"mem", drm_mem_info
},
67 {"clients", drm_clients_info
},
68 {"queues", drm_queues_info
},
69 {"bufs", drm_bufs_info
},
71 {"vma", drm_vma_info
},
75 #define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
78 * Initialize the DRI proc filesystem for a device.
80 * \param dev DRM device.
81 * \param minor device minor number.
82 * \param root DRI proc dir entry.
83 * \param dev_root resulting DRI device proc dir entry.
84 * \return root entry pointer on success, or NULL on failure.
86 * Create the DRI proc root entry "/proc/dri", the device proc root entry
87 * "/proc/dri/%minor%/", and each entry in proc_list as
88 * "/proc/dri/%minor%/%name%".
90 int drm_proc_init(drm_device_t
* dev
, int minor
,
91 struct proc_dir_entry
*root
, struct proc_dir_entry
**dev_root
)
93 struct proc_dir_entry
*ent
;
97 sprintf(name
, "%d", minor
);
98 *dev_root
= proc_mkdir(name
, root
);
100 DRM_ERROR("Cannot create /proc/dri/%s\n", name
);
104 for (i
= 0; i
< DRM_PROC_ENTRIES
; i
++) {
105 ent
= create_proc_entry(drm_proc_list
[i
].name
,
106 S_IFREG
| S_IRUGO
, *dev_root
);
108 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
109 name
, drm_proc_list
[i
].name
);
110 for (j
= 0; j
< i
; j
++)
111 remove_proc_entry(drm_proc_list
[i
].name
,
113 remove_proc_entry(name
, root
);
116 ent
->read_proc
= drm_proc_list
[i
].f
;
124 * Cleanup the proc filesystem resources.
126 * \param minor device minor number.
127 * \param root DRI proc dir entry.
128 * \param dev_root DRI device proc dir entry.
129 * \return always zero.
131 * Remove all proc entries created by proc_init().
133 int drm_proc_cleanup(int minor
, struct proc_dir_entry
*root
,
134 struct proc_dir_entry
*dev_root
)
139 if (!root
|| !dev_root
)
142 for (i
= 0; i
< DRM_PROC_ENTRIES
; i
++)
143 remove_proc_entry(drm_proc_list
[i
].name
, dev_root
);
144 sprintf(name
, "%d", minor
);
145 remove_proc_entry(name
, root
);
151 * Called when "/proc/dri/.../name" is read.
153 * \param buf output buffer.
154 * \param start start of output data.
155 * \param offset requested start offset.
156 * \param request requested number of bytes.
157 * \param eof whether there is no more data to return.
158 * \param data private data.
159 * \return number of written bytes.
161 * Prints the device name together with the bus id if available.
163 static int drm_name_info(char *buf
, char **start
, off_t offset
, int request
,
164 int *eof
, void *data
)
166 drm_device_t
*dev
= (drm_device_t
*) data
;
169 if (offset
> DRM_PROC_LIMIT
) {
174 *start
= &buf
[offset
];
178 DRM_PROC_PRINT("%s %s %s\n",
179 dev
->driver
->pci_driver
.name
,
180 pci_name(dev
->pdev
), dev
->unique
);
182 DRM_PROC_PRINT("%s %s\n", dev
->driver
->pci_driver
.name
,
183 pci_name(dev
->pdev
));
186 if (len
> request
+ offset
)
193 * Called when "/proc/dri/.../vm" is read.
195 * \param buf output buffer.
196 * \param start start of output data.
197 * \param offset requested start offset.
198 * \param request requested number of bytes.
199 * \param eof whether there is no more data to return.
200 * \param data private data.
201 * \return number of written bytes.
203 * Prints information about all mappings in drm_device::maplist.
205 static int drm__vm_info(char *buf
, char **start
, off_t offset
, int request
,
206 int *eof
, void *data
)
208 drm_device_t
*dev
= (drm_device_t
*) data
;
211 drm_map_list_t
*r_list
;
212 struct list_head
*list
;
214 /* Hardcoded from _DRM_FRAME_BUFFER,
215 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
216 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
217 const char *types
[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
221 if (offset
> DRM_PROC_LIMIT
) {
226 *start
= &buf
[offset
];
229 DRM_PROC_PRINT("slot offset size type flags "
232 if (dev
->maplist
!= NULL
)
233 list_for_each(list
, &dev
->maplist
->head
) {
234 r_list
= list_entry(list
, drm_map_list_t
, head
);
238 if (map
->type
< 0 || map
->type
> 5)
241 type
= types
[map
->type
];
242 DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08x ",
245 map
->size
, type
, map
->flags
, r_list
->user_token
);
247 DRM_PROC_PRINT("none\n");
249 DRM_PROC_PRINT("%4d\n", map
->mtrr
);
254 if (len
> request
+ offset
)
261 * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
263 static int drm_vm_info(char *buf
, char **start
, off_t offset
, int request
,
264 int *eof
, void *data
)
266 drm_device_t
*dev
= (drm_device_t
*) data
;
269 mutex_lock(&dev
->struct_mutex
);
270 ret
= drm__vm_info(buf
, start
, offset
, request
, eof
, data
);
271 mutex_unlock(&dev
->struct_mutex
);
276 * Called when "/proc/dri/.../queues" is read.
278 * \param buf output buffer.
279 * \param start start of output data.
280 * \param offset requested start offset.
281 * \param request requested number of bytes.
282 * \param eof whether there is no more data to return.
283 * \param data private data.
284 * \return number of written bytes.
286 static int drm__queues_info(char *buf
, char **start
, off_t offset
,
287 int request
, int *eof
, void *data
)
289 drm_device_t
*dev
= (drm_device_t
*) data
;
294 if (offset
> DRM_PROC_LIMIT
) {
299 *start
= &buf
[offset
];
302 DRM_PROC_PRINT(" ctx/flags use fin"
303 " blk/rw/rwf wait flushed queued"
305 for (i
= 0; i
< dev
->queue_count
; i
++) {
306 q
= dev
->queuelist
[i
];
307 atomic_inc(&q
->use_count
);
308 DRM_PROC_PRINT_RET(atomic_dec(&q
->use_count
),
310 " %5d/%c%c/%c%c%c %5Zd\n",
313 atomic_read(&q
->use_count
),
314 atomic_read(&q
->finalization
),
315 atomic_read(&q
->block_count
),
316 atomic_read(&q
->block_read
) ? 'r' : '-',
317 atomic_read(&q
->block_write
) ? 'w' : '-',
318 waitqueue_active(&q
->read_queue
) ? 'r' : '-',
319 waitqueue_active(&q
->
320 write_queue
) ? 'w' : '-',
321 waitqueue_active(&q
->
322 flush_queue
) ? 'f' : '-',
323 DRM_BUFCOUNT(&q
->waitlist
));
324 atomic_dec(&q
->use_count
);
327 if (len
> request
+ offset
)
334 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
336 static int drm_queues_info(char *buf
, char **start
, off_t offset
, int request
,
337 int *eof
, void *data
)
339 drm_device_t
*dev
= (drm_device_t
*) data
;
342 mutex_lock(&dev
->struct_mutex
);
343 ret
= drm__queues_info(buf
, start
, offset
, request
, eof
, data
);
344 mutex_unlock(&dev
->struct_mutex
);
349 * Called when "/proc/dri/.../bufs" is read.
351 * \param buf output buffer.
352 * \param start start of output data.
353 * \param offset requested start offset.
354 * \param request requested number of bytes.
355 * \param eof whether there is no more data to return.
356 * \param data private data.
357 * \return number of written bytes.
359 static int drm__bufs_info(char *buf
, char **start
, off_t offset
, int request
,
360 int *eof
, void *data
)
362 drm_device_t
*dev
= (drm_device_t
*) data
;
364 drm_device_dma_t
*dma
= dev
->dma
;
367 if (!dma
|| offset
> DRM_PROC_LIMIT
) {
372 *start
= &buf
[offset
];
375 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
376 for (i
= 0; i
<= DRM_MAX_ORDER
; i
++) {
377 if (dma
->bufs
[i
].buf_count
)
378 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
380 dma
->bufs
[i
].buf_size
,
381 dma
->bufs
[i
].buf_count
,
382 atomic_read(&dma
->bufs
[i
]
384 dma
->bufs
[i
].seg_count
,
385 dma
->bufs
[i
].seg_count
386 * (1 << dma
->bufs
[i
].page_order
),
387 (dma
->bufs
[i
].seg_count
388 * (1 << dma
->bufs
[i
].page_order
))
391 DRM_PROC_PRINT("\n");
392 for (i
= 0; i
< dma
->buf_count
; i
++) {
394 DRM_PROC_PRINT("\n");
395 DRM_PROC_PRINT(" %d", dma
->buflist
[i
]->list
);
397 DRM_PROC_PRINT("\n");
399 if (len
> request
+ offset
)
406 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
408 static int drm_bufs_info(char *buf
, char **start
, off_t offset
, int request
,
409 int *eof
, void *data
)
411 drm_device_t
*dev
= (drm_device_t
*) data
;
414 mutex_lock(&dev
->struct_mutex
);
415 ret
= drm__bufs_info(buf
, start
, offset
, request
, eof
, data
);
416 mutex_unlock(&dev
->struct_mutex
);
421 * Called when "/proc/dri/.../clients" is read.
423 * \param buf output buffer.
424 * \param start start of output data.
425 * \param offset requested start offset.
426 * \param request requested number of bytes.
427 * \param eof whether there is no more data to return.
428 * \param data private data.
429 * \return number of written bytes.
431 static int drm__clients_info(char *buf
, char **start
, off_t offset
,
432 int request
, int *eof
, void *data
)
434 drm_device_t
*dev
= (drm_device_t
*) data
;
438 if (offset
> DRM_PROC_LIMIT
) {
443 *start
= &buf
[offset
];
446 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
447 for (priv
= dev
->file_first
; priv
; priv
= priv
->next
) {
448 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
449 priv
->authenticated
? 'y' : 'n',
452 priv
->uid
, priv
->magic
, priv
->ioctl_count
);
455 if (len
> request
+ offset
)
462 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
464 static int drm_clients_info(char *buf
, char **start
, off_t offset
,
465 int request
, int *eof
, void *data
)
467 drm_device_t
*dev
= (drm_device_t
*) data
;
470 mutex_lock(&dev
->struct_mutex
);
471 ret
= drm__clients_info(buf
, start
, offset
, request
, eof
, data
);
472 mutex_unlock(&dev
->struct_mutex
);
478 static int drm__vma_info(char *buf
, char **start
, off_t offset
, int request
,
479 int *eof
, void *data
)
481 drm_device_t
*dev
= (drm_device_t
*) data
;
484 struct vm_area_struct
*vma
;
485 #if defined(__i386__)
489 if (offset
> DRM_PROC_LIMIT
) {
494 *start
= &buf
[offset
];
497 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
498 atomic_read(&dev
->vma_count
),
499 high_memory
, virt_to_phys(high_memory
));
500 for (pt
= dev
->vmalist
; pt
; pt
= pt
->next
) {
501 if (!(vma
= pt
->vma
))
503 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
507 vma
->vm_flags
& VM_READ
? 'r' : '-',
508 vma
->vm_flags
& VM_WRITE
? 'w' : '-',
509 vma
->vm_flags
& VM_EXEC
? 'x' : '-',
510 vma
->vm_flags
& VM_MAYSHARE
? 's' : 'p',
511 vma
->vm_flags
& VM_LOCKED
? 'l' : '-',
512 vma
->vm_flags
& VM_IO
? 'i' : '-',
513 vma
->vm_pgoff
<< PAGE_SHIFT
);
515 #if defined(__i386__)
516 pgprot
= pgprot_val(vma
->vm_page_prot
);
517 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
518 pgprot
& _PAGE_PRESENT
? 'p' : '-',
519 pgprot
& _PAGE_RW
? 'w' : 'r',
520 pgprot
& _PAGE_USER
? 'u' : 's',
521 pgprot
& _PAGE_PWT
? 't' : 'b',
522 pgprot
& _PAGE_PCD
? 'u' : 'c',
523 pgprot
& _PAGE_ACCESSED
? 'a' : '-',
524 pgprot
& _PAGE_DIRTY
? 'd' : '-',
525 pgprot
& _PAGE_PSE
? 'm' : 'k',
526 pgprot
& _PAGE_GLOBAL
? 'g' : 'l');
528 DRM_PROC_PRINT("\n");
531 if (len
> request
+ offset
)
537 static int drm_vma_info(char *buf
, char **start
, off_t offset
, int request
,
538 int *eof
, void *data
)
540 drm_device_t
*dev
= (drm_device_t
*) data
;
543 mutex_lock(&dev
->struct_mutex
);
544 ret
= drm__vma_info(buf
, start
, offset
, request
, eof
, data
);
545 mutex_unlock(&dev
->struct_mutex
);