DRM for platform devices
[kernel.git] / drivers / gpu / drm / drm_info.c
1 /**
2  * \file drm_info.c
3  * DRM info file implementations
4  *
5  * \author Ben Gamari <bgamari@gmail.com>
6  */
7
8 /*
9  * Created: Sun Dec 21 13:09:50 2008 by bgamari@gmail.com
10  *
11  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
12  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
13  * Copyright 2008 Ben Gamari <bgamari@gmail.com>
14  * All Rights Reserved.
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a
17  * copy of this software and associated documentation files (the "Software"),
18  * to deal in the Software without restriction, including without limitation
19  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20  * and/or sell copies of the Software, and to permit persons to whom the
21  * Software is furnished to do so, subject to the following conditions:
22  *
23  * The above copyright notice and this permission notice (including the next
24  * paragraph) shall be included in all copies or substantial portions of the
25  * Software.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
30  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33  * OTHER DEALINGS IN THE SOFTWARE.
34  */
35
36 #include <linux/seq_file.h>
37 #include "drmP.h"
38
39 /**
40  * Called when "/proc/dri/.../name" is read.
41  *
42  * Prints the device name together with the bus id if available.
43  */
44 int drm_name_info(struct seq_file *m, void *data)
45 {
46         struct drm_info_node *node = (struct drm_info_node *) m->private;
47         struct drm_minor *minor = node->minor;
48         struct drm_device *dev = minor->dev;
49         struct drm_master *master = minor->master;
50
51         if (!master)
52                 return 0;
53
54         if (master->unique) {
55
56                 if (drm_core_is_platform(dev)) {
57                         seq_printf(m, "%s %s %s\n",
58                                    dev->driver->name,
59                                    dev_name(&dev->platform_dev->dev),
60                                    master->unique);
61                 } else {
62                         seq_printf(m, "%s %s %s\n",
63                                    dev->driver->pci_driver.name,
64                                    pci_name(dev->pdev), master->unique);
65                 }
66
67         } else {
68
69                 if (drm_core_is_platform(dev)) {
70                         seq_printf(m, "%s %s\n", dev->driver->name,
71                                    dev_name(&dev->platform_dev->dev));
72                 } else {
73                         seq_printf(m, "%s %s\n", dev->driver->pci_driver.name,
74                                    pci_name(dev->pdev));
75                 }
76
77         }
78
79         return 0;
80 }
81
82 /**
83  * Called when "/proc/dri/.../vm" is read.
84  *
85  * Prints information about all mappings in drm_device::maplist.
86  */
87 int drm_vm_info(struct seq_file *m, void *data)
88 {
89         struct drm_info_node *node = (struct drm_info_node *) m->private;
90         struct drm_device *dev = node->minor->dev;
91         struct drm_local_map *map;
92         struct drm_map_list *r_list;
93
94         /* Hardcoded from _DRM_FRAME_BUFFER,
95            _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
96            _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
97         const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
98         const char *type;
99         int i;
100
101         mutex_lock(&dev->struct_mutex);
102         seq_printf(m, "slot      offset       size type flags    address mtrr\n\n");
103         i = 0;
104         list_for_each_entry(r_list, &dev->maplist, head) {
105                 map = r_list->map;
106                 if (!map)
107                         continue;
108                 if (map->type < 0 || map->type > 5)
109                         type = "??";
110                 else
111                         type = types[map->type];
112
113                 seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s  0x%02x 0x%08lx ",
114                            i,
115                            (unsigned long long)map->offset,
116                            map->size, type, map->flags,
117                            (unsigned long) r_list->user_token);
118                 if (map->mtrr < 0)
119                         seq_printf(m, "none\n");
120                 else
121                         seq_printf(m, "%4d\n", map->mtrr);
122                 i++;
123         }
124         mutex_unlock(&dev->struct_mutex);
125         return 0;
126 }
127
128 /**
129  * Called when "/proc/dri/.../queues" is read.
130  */
131 int drm_queues_info(struct seq_file *m, void *data)
132 {
133         struct drm_info_node *node = (struct drm_info_node *) m->private;
134         struct drm_device *dev = node->minor->dev;
135         int i;
136         struct drm_queue *q;
137
138         mutex_lock(&dev->struct_mutex);
139         seq_printf(m, "  ctx/flags   use   fin"
140                    "   blk/rw/rwf  wait    flushed         queued"
141                    "      locks\n\n");
142         for (i = 0; i < dev->queue_count; i++) {
143                 q = dev->queuelist[i];
144                 atomic_inc(&q->use_count);
145                 seq_printf(m,   "%5d/0x%03x %5d %5d"
146                            " %5d/%c%c/%c%c%c %5Zd\n",
147                            i,
148                            q->flags,
149                            atomic_read(&q->use_count),
150                            atomic_read(&q->finalization),
151                            atomic_read(&q->block_count),
152                            atomic_read(&q->block_read) ? 'r' : '-',
153                            atomic_read(&q->block_write) ? 'w' : '-',
154                            waitqueue_active(&q->read_queue) ? 'r' : '-',
155                            waitqueue_active(&q->write_queue) ? 'w' : '-',
156                            waitqueue_active(&q->flush_queue) ? 'f' : '-',
157                            DRM_BUFCOUNT(&q->waitlist));
158                 atomic_dec(&q->use_count);
159         }
160         mutex_unlock(&dev->struct_mutex);
161         return 0;
162 }
163
164 /**
165  * Called when "/proc/dri/.../bufs" is read.
166  */
167 int drm_bufs_info(struct seq_file *m, void *data)
168 {
169         struct drm_info_node *node = (struct drm_info_node *) m->private;
170         struct drm_device *dev = node->minor->dev;
171         struct drm_device_dma *dma;
172         int i, seg_pages;
173
174         mutex_lock(&dev->struct_mutex);
175         dma = dev->dma;
176         if (!dma) {
177                 mutex_unlock(&dev->struct_mutex);
178                 return 0;
179         }
180
181         seq_printf(m, " o     size count  free   segs pages    kB\n\n");
182         for (i = 0; i <= DRM_MAX_ORDER; i++) {
183                 if (dma->bufs[i].buf_count) {
184                         seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
185                         seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
186                                    i,
187                                    dma->bufs[i].buf_size,
188                                    dma->bufs[i].buf_count,
189                                    atomic_read(&dma->bufs[i].freelist.count),
190                                    dma->bufs[i].seg_count,
191                                    seg_pages,
192                                    seg_pages * PAGE_SIZE / 1024);
193                 }
194         }
195         seq_printf(m, "\n");
196         for (i = 0; i < dma->buf_count; i++) {
197                 if (i && !(i % 32))
198                         seq_printf(m, "\n");
199                 seq_printf(m, " %d", dma->buflist[i]->list);
200         }
201         seq_printf(m, "\n");
202         mutex_unlock(&dev->struct_mutex);
203         return 0;
204 }
205
206 /**
207  * Called when "/proc/dri/.../vblank" is read.
208  */
209 int drm_vblank_info(struct seq_file *m, void *data)
210 {
211         struct drm_info_node *node = (struct drm_info_node *) m->private;
212         struct drm_device *dev = node->minor->dev;
213         int crtc;
214
215         mutex_lock(&dev->struct_mutex);
216         for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
217                 seq_printf(m, "CRTC %d enable:     %d\n",
218                            crtc, atomic_read(&dev->vblank_refcount[crtc]));
219                 seq_printf(m, "CRTC %d counter:    %d\n",
220                            crtc, drm_vblank_count(dev, crtc));
221                 seq_printf(m, "CRTC %d last wait:  %d\n",
222                            crtc, dev->last_vblank_wait[crtc]);
223                 seq_printf(m, "CRTC %d in modeset: %d\n",
224                            crtc, dev->vblank_inmodeset[crtc]);
225         }
226         mutex_unlock(&dev->struct_mutex);
227         return 0;
228 }
229
230 /**
231  * Called when "/proc/dri/.../clients" is read.
232  *
233  */
234 int drm_clients_info(struct seq_file *m, void *data)
235 {
236         struct drm_info_node *node = (struct drm_info_node *) m->private;
237         struct drm_device *dev = node->minor->dev;
238         struct drm_file *priv;
239
240         mutex_lock(&dev->struct_mutex);
241         seq_printf(m, "a dev    pid    uid      magic     ioctls\n\n");
242         list_for_each_entry(priv, &dev->filelist, lhead) {
243                 seq_printf(m, "%c %3d %5d %5d %10u %10lu\n",
244                            priv->authenticated ? 'y' : 'n',
245                            priv->minor->index,
246                            priv->pid,
247                            priv->uid, priv->magic, priv->ioctl_count);
248         }
249         mutex_unlock(&dev->struct_mutex);
250         return 0;
251 }
252
253
254 int drm_gem_one_name_info(int id, void *ptr, void *data)
255 {
256         struct drm_gem_object *obj = ptr;
257         struct seq_file *m = data;
258
259         seq_printf(m, "name %d size %zd\n", obj->name, obj->size);
260
261         seq_printf(m, "%6d %8zd %7d %8d\n",
262                    obj->name, obj->size,
263                    atomic_read(&obj->handlecount.refcount),
264                    atomic_read(&obj->refcount.refcount));
265         return 0;
266 }
267
268 int drm_gem_name_info(struct seq_file *m, void *data)
269 {
270         struct drm_info_node *node = (struct drm_info_node *) m->private;
271         struct drm_device *dev = node->minor->dev;
272
273         seq_printf(m, "  name     size handles refcount\n");
274         idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
275         return 0;
276 }
277
278 int drm_gem_object_info(struct seq_file *m, void* data)
279 {
280         struct drm_info_node *node = (struct drm_info_node *) m->private;
281         struct drm_device *dev = node->minor->dev;
282
283         seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
284         seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
285         seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
286         seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
287         seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
288         seq_printf(m, "%d gtt total\n", dev->gtt_total);
289         return 0;
290 }
291
292 #if DRM_DEBUG_CODE
293
294 int drm_vma_info(struct seq_file *m, void *data)
295 {
296         struct drm_info_node *node = (struct drm_info_node *) m->private;
297         struct drm_device *dev = node->minor->dev;
298         struct drm_vma_entry *pt;
299         struct vm_area_struct *vma;
300 #if defined(__i386__)
301         unsigned int pgprot;
302 #endif
303
304         mutex_lock(&dev->struct_mutex);
305         seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
306                    atomic_read(&dev->vma_count),
307                    high_memory, (u64)virt_to_phys(high_memory));
308
309         list_for_each_entry(pt, &dev->vmalist, head) {
310                 vma = pt->vma;
311                 if (!vma)
312                         continue;
313                 seq_printf(m,
314                            "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
315                            pt->pid, vma->vm_start, vma->vm_end,
316                            vma->vm_flags & VM_READ ? 'r' : '-',
317                            vma->vm_flags & VM_WRITE ? 'w' : '-',
318                            vma->vm_flags & VM_EXEC ? 'x' : '-',
319                            vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
320                            vma->vm_flags & VM_LOCKED ? 'l' : '-',
321                            vma->vm_flags & VM_IO ? 'i' : '-',
322                            vma->vm_pgoff);
323
324 #if defined(__i386__)
325                 pgprot = pgprot_val(vma->vm_page_prot);
326                 seq_printf(m, " %c%c%c%c%c%c%c%c%c",
327                            pgprot & _PAGE_PRESENT ? 'p' : '-',
328                            pgprot & _PAGE_RW ? 'w' : 'r',
329                            pgprot & _PAGE_USER ? 'u' : 's',
330                            pgprot & _PAGE_PWT ? 't' : 'b',
331                            pgprot & _PAGE_PCD ? 'u' : 'c',
332                            pgprot & _PAGE_ACCESSED ? 'a' : '-',
333                            pgprot & _PAGE_DIRTY ? 'd' : '-',
334                            pgprot & _PAGE_PSE ? 'm' : 'k',
335                            pgprot & _PAGE_GLOBAL ? 'g' : 'l');
336 #endif
337                 seq_printf(m, "\n");
338         }
339         mutex_unlock(&dev->struct_mutex);
340         return 0;
341 }
342
343 #endif