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 ARRAY_SIZE(drm_proc_list)
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(struct drm_minor
*minor
, int minor_id
,
91 struct proc_dir_entry
*root
)
93 struct proc_dir_entry
*ent
;
97 sprintf(name
, "%d", minor_id
);
98 minor
->dev_root
= proc_mkdir(name
, root
);
99 if (!minor
->dev_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
, minor
->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
);
114 minor
->dev_root
= NULL
;
117 ent
->read_proc
= drm_proc_list
[i
].f
;
125 * Cleanup the proc filesystem resources.
127 * \param minor device minor number.
128 * \param root DRI proc dir entry.
129 * \param dev_root DRI device proc dir entry.
130 * \return always zero.
132 * Remove all proc entries created by proc_init().
134 int drm_proc_cleanup(struct drm_minor
*minor
, struct proc_dir_entry
*root
)
139 if (!root
|| !minor
->dev_root
)
142 for (i
= 0; i
< DRM_PROC_ENTRIES
; i
++)
143 remove_proc_entry(drm_proc_list
[i
].name
, minor
->dev_root
);
144 sprintf(name
, "%d", minor
->index
);
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 struct drm_minor
*minor
= (struct drm_minor
*) data
;
167 struct drm_device
*dev
= minor
->dev
;
170 if (offset
> DRM_PROC_LIMIT
) {
175 *start
= &buf
[offset
];
179 DRM_PROC_PRINT("%s %s %s\n",
180 dev
->driver
->pci_driver
.name
,
181 pci_name(dev
->pdev
), dev
->unique
);
183 DRM_PROC_PRINT("%s %s\n", dev
->driver
->pci_driver
.name
,
184 pci_name(dev
->pdev
));
187 if (len
> request
+ offset
)
194 * Called when "/proc/dri/.../vm" is read.
196 * \param buf output buffer.
197 * \param start start of output data.
198 * \param offset requested start offset.
199 * \param request requested number of bytes.
200 * \param eof whether there is no more data to return.
201 * \param data private data.
202 * \return number of written bytes.
204 * Prints information about all mappings in drm_device::maplist.
206 static int drm__vm_info(char *buf
, char **start
, off_t offset
, int request
,
207 int *eof
, void *data
)
209 struct drm_minor
*minor
= (struct drm_minor
*) data
;
210 struct drm_device
*dev
= minor
->dev
;
213 struct drm_map_list
*r_list
;
215 /* Hardcoded from _DRM_FRAME_BUFFER,
216 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
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
);
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 struct drm_minor
*minor
= (struct drm_minor
*) data
;
267 struct drm_device
*dev
= minor
->dev
;
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 struct drm_minor
*minor
= (struct drm_minor
*) data
;
291 struct drm_device
*dev
= minor
->dev
;
296 if (offset
> DRM_PROC_LIMIT
) {
301 *start
= &buf
[offset
];
304 DRM_PROC_PRINT(" ctx/flags use fin"
305 " blk/rw/rwf wait flushed queued"
307 for (i
= 0; i
< dev
->queue_count
; i
++) {
308 q
= dev
->queuelist
[i
];
309 atomic_inc(&q
->use_count
);
310 DRM_PROC_PRINT_RET(atomic_dec(&q
->use_count
),
312 " %5d/%c%c/%c%c%c %5Zd\n",
315 atomic_read(&q
->use_count
),
316 atomic_read(&q
->finalization
),
317 atomic_read(&q
->block_count
),
318 atomic_read(&q
->block_read
) ? 'r' : '-',
319 atomic_read(&q
->block_write
) ? 'w' : '-',
320 waitqueue_active(&q
->read_queue
) ? 'r' : '-',
321 waitqueue_active(&q
->
322 write_queue
) ? 'w' : '-',
323 waitqueue_active(&q
->
324 flush_queue
) ? 'f' : '-',
325 DRM_BUFCOUNT(&q
->waitlist
));
326 atomic_dec(&q
->use_count
);
329 if (len
> request
+ offset
)
336 * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
338 static int drm_queues_info(char *buf
, char **start
, off_t offset
, int request
,
339 int *eof
, void *data
)
341 struct drm_minor
*minor
= (struct drm_minor
*) data
;
342 struct drm_device
*dev
= minor
->dev
;
345 mutex_lock(&dev
->struct_mutex
);
346 ret
= drm__queues_info(buf
, start
, offset
, request
, eof
, data
);
347 mutex_unlock(&dev
->struct_mutex
);
352 * Called when "/proc/dri/.../bufs" is read.
354 * \param buf output buffer.
355 * \param start start of output data.
356 * \param offset requested start offset.
357 * \param request requested number of bytes.
358 * \param eof whether there is no more data to return.
359 * \param data private data.
360 * \return number of written bytes.
362 static int drm__bufs_info(char *buf
, char **start
, off_t offset
, int request
,
363 int *eof
, void *data
)
365 struct drm_minor
*minor
= (struct drm_minor
*) data
;
366 struct drm_device
*dev
= minor
->dev
;
368 struct drm_device_dma
*dma
= dev
->dma
;
371 if (!dma
|| offset
> DRM_PROC_LIMIT
) {
376 *start
= &buf
[offset
];
379 DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
380 for (i
= 0; i
<= DRM_MAX_ORDER
; i
++) {
381 if (dma
->bufs
[i
].buf_count
)
382 DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
384 dma
->bufs
[i
].buf_size
,
385 dma
->bufs
[i
].buf_count
,
386 atomic_read(&dma
->bufs
[i
]
388 dma
->bufs
[i
].seg_count
,
389 dma
->bufs
[i
].seg_count
390 * (1 << dma
->bufs
[i
].page_order
),
391 (dma
->bufs
[i
].seg_count
392 * (1 << dma
->bufs
[i
].page_order
))
395 DRM_PROC_PRINT("\n");
396 for (i
= 0; i
< dma
->buf_count
; i
++) {
398 DRM_PROC_PRINT("\n");
399 DRM_PROC_PRINT(" %d", dma
->buflist
[i
]->list
);
401 DRM_PROC_PRINT("\n");
403 if (len
> request
+ offset
)
410 * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
412 static int drm_bufs_info(char *buf
, char **start
, off_t offset
, int request
,
413 int *eof
, void *data
)
415 struct drm_minor
*minor
= (struct drm_minor
*) data
;
416 struct drm_device
*dev
= minor
->dev
;
419 mutex_lock(&dev
->struct_mutex
);
420 ret
= drm__bufs_info(buf
, start
, offset
, request
, eof
, data
);
421 mutex_unlock(&dev
->struct_mutex
);
426 * Called when "/proc/dri/.../clients" is read.
428 * \param buf output buffer.
429 * \param start start of output data.
430 * \param offset requested start offset.
431 * \param request requested number of bytes.
432 * \param eof whether there is no more data to return.
433 * \param data private data.
434 * \return number of written bytes.
436 static int drm__clients_info(char *buf
, char **start
, off_t offset
,
437 int request
, int *eof
, void *data
)
439 struct drm_minor
*minor
= (struct drm_minor
*) data
;
440 struct drm_device
*dev
= minor
->dev
;
442 struct drm_file
*priv
;
444 if (offset
> DRM_PROC_LIMIT
) {
449 *start
= &buf
[offset
];
452 DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
453 list_for_each_entry(priv
, &dev
->filelist
, lhead
) {
454 DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
455 priv
->authenticated
? 'y' : 'n',
458 priv
->uid
, priv
->magic
, priv
->ioctl_count
);
461 if (len
> request
+ offset
)
468 * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
470 static int drm_clients_info(char *buf
, char **start
, off_t offset
,
471 int request
, int *eof
, void *data
)
473 struct drm_minor
*minor
= (struct drm_minor
*) data
;
474 struct drm_device
*dev
= minor
->dev
;
477 mutex_lock(&dev
->struct_mutex
);
478 ret
= drm__clients_info(buf
, start
, offset
, request
, eof
, data
);
479 mutex_unlock(&dev
->struct_mutex
);
485 static int drm__vma_info(char *buf
, char **start
, off_t offset
, int request
,
486 int *eof
, void *data
)
488 struct drm_minor
*minor
= (struct drm_minor
*) data
;
489 struct drm_device
*dev
= minor
->dev
;
491 struct drm_vma_entry
*pt
;
492 struct vm_area_struct
*vma
;
493 #if defined(__i386__)
497 if (offset
> DRM_PROC_LIMIT
) {
502 *start
= &buf
[offset
];
505 DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
506 atomic_read(&dev
->vma_count
),
507 high_memory
, virt_to_phys(high_memory
));
508 list_for_each_entry(pt
, &dev
->vmalist
, head
) {
509 if (!(vma
= pt
->vma
))
511 DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
515 vma
->vm_flags
& VM_READ
? 'r' : '-',
516 vma
->vm_flags
& VM_WRITE
? 'w' : '-',
517 vma
->vm_flags
& VM_EXEC
? 'x' : '-',
518 vma
->vm_flags
& VM_MAYSHARE
? 's' : 'p',
519 vma
->vm_flags
& VM_LOCKED
? 'l' : '-',
520 vma
->vm_flags
& VM_IO
? 'i' : '-',
523 #if defined(__i386__)
524 pgprot
= pgprot_val(vma
->vm_page_prot
);
525 DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
526 pgprot
& _PAGE_PRESENT
? 'p' : '-',
527 pgprot
& _PAGE_RW
? 'w' : 'r',
528 pgprot
& _PAGE_USER
? 'u' : 's',
529 pgprot
& _PAGE_PWT
? 't' : 'b',
530 pgprot
& _PAGE_PCD
? 'u' : 'c',
531 pgprot
& _PAGE_ACCESSED
? 'a' : '-',
532 pgprot
& _PAGE_DIRTY
? 'd' : '-',
533 pgprot
& _PAGE_PSE
? 'm' : 'k',
534 pgprot
& _PAGE_GLOBAL
? 'g' : 'l');
536 DRM_PROC_PRINT("\n");
539 if (len
> request
+ offset
)
545 static int drm_vma_info(char *buf
, char **start
, off_t offset
, int request
,
546 int *eof
, void *data
)
548 struct drm_minor
*minor
= (struct drm_minor
*) data
;
549 struct drm_device
*dev
= minor
->dev
;
552 mutex_lock(&dev
->struct_mutex
);
553 ret
= drm__vma_info(buf
, start
, offset
, request
, eof
, data
);
554 mutex_unlock(&dev
->struct_mutex
);
This page took 0.089675 seconds and 5 git commands to generate.