Merge branch 'timers-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6] / drivers / gpu / drm / i915 / i915_gem_debugfs.c
1 /*
2  * Copyright © 2008 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *    Keith Packard <keithp@keithp.com>
26  *
27  */
28
29 #include <linux/seq_file.h>
30 #include "drmP.h"
31 #include "drm.h"
32 #include "i915_drm.h"
33 #include "i915_drv.h"
34
35 #define DRM_I915_RING_DEBUG 1
36
37
38 #if defined(CONFIG_DEBUG_FS)
39
40 #define ACTIVE_LIST     1
41 #define FLUSHING_LIST   2
42 #define INACTIVE_LIST   3
43
44 static const char *get_pin_flag(struct drm_i915_gem_object *obj_priv)
45 {
46         if (obj_priv->user_pin_count > 0)
47                 return "P";
48         else if (obj_priv->pin_count > 0)
49                 return "p";
50         else
51                 return " ";
52 }
53
54 static const char *get_tiling_flag(struct drm_i915_gem_object *obj_priv)
55 {
56     switch (obj_priv->tiling_mode) {
57     default:
58     case I915_TILING_NONE: return " ";
59     case I915_TILING_X: return "X";
60     case I915_TILING_Y: return "Y";
61     }
62 }
63
64 static int i915_gem_object_list_info(struct seq_file *m, void *data)
65 {
66         struct drm_info_node *node = (struct drm_info_node *) m->private;
67         uintptr_t list = (uintptr_t) node->info_ent->data;
68         struct list_head *head;
69         struct drm_device *dev = node->minor->dev;
70         drm_i915_private_t *dev_priv = dev->dev_private;
71         struct drm_i915_gem_object *obj_priv;
72         spinlock_t *lock = NULL;
73
74         switch (list) {
75         case ACTIVE_LIST:
76                 seq_printf(m, "Active:\n");
77                 lock = &dev_priv->mm.active_list_lock;
78                 head = &dev_priv->mm.active_list;
79                 break;
80         case INACTIVE_LIST:
81                 seq_printf(m, "Inactive:\n");
82                 head = &dev_priv->mm.inactive_list;
83                 break;
84         case FLUSHING_LIST:
85                 seq_printf(m, "Flushing:\n");
86                 head = &dev_priv->mm.flushing_list;
87                 break;
88         default:
89                 DRM_INFO("Ooops, unexpected list\n");
90                 return 0;
91         }
92
93         if (lock)
94                 spin_lock(lock);
95         list_for_each_entry(obj_priv, head, list)
96         {
97                 struct drm_gem_object *obj = obj_priv->obj;
98
99                 seq_printf(m, "    %p: %s %08x %08x %d",
100                            obj,
101                            get_pin_flag(obj_priv),
102                            obj->read_domains, obj->write_domain,
103                            obj_priv->last_rendering_seqno);
104
105                 if (obj->name)
106                         seq_printf(m, " (name: %d)", obj->name);
107                 if (obj_priv->fence_reg != I915_FENCE_REG_NONE)
108                         seq_printf(m, " (fence: %d)", obj_priv->fence_reg);
109                 if (obj_priv->gtt_space != NULL)
110                         seq_printf(m, " (gtt_offset: %08x)", obj_priv->gtt_offset);
111
112                 seq_printf(m, "\n");
113         }
114
115         if (lock)
116             spin_unlock(lock);
117         return 0;
118 }
119
120 static int i915_gem_request_info(struct seq_file *m, void *data)
121 {
122         struct drm_info_node *node = (struct drm_info_node *) m->private;
123         struct drm_device *dev = node->minor->dev;
124         drm_i915_private_t *dev_priv = dev->dev_private;
125         struct drm_i915_gem_request *gem_request;
126
127         seq_printf(m, "Request:\n");
128         list_for_each_entry(gem_request, &dev_priv->mm.request_list, list) {
129                 seq_printf(m, "    %d @ %d\n",
130                            gem_request->seqno,
131                            (int) (jiffies - gem_request->emitted_jiffies));
132         }
133         return 0;
134 }
135
136 static int i915_gem_seqno_info(struct seq_file *m, void *data)
137 {
138         struct drm_info_node *node = (struct drm_info_node *) m->private;
139         struct drm_device *dev = node->minor->dev;
140         drm_i915_private_t *dev_priv = dev->dev_private;
141
142         if (dev_priv->hw_status_page != NULL) {
143                 seq_printf(m, "Current sequence: %d\n",
144                            i915_get_gem_seqno(dev));
145         } else {
146                 seq_printf(m, "Current sequence: hws uninitialized\n");
147         }
148         seq_printf(m, "Waiter sequence:  %d\n",
149                         dev_priv->mm.waiting_gem_seqno);
150         seq_printf(m, "IRQ sequence:     %d\n", dev_priv->mm.irq_gem_seqno);
151         return 0;
152 }
153
154
155 static int i915_interrupt_info(struct seq_file *m, void *data)
156 {
157         struct drm_info_node *node = (struct drm_info_node *) m->private;
158         struct drm_device *dev = node->minor->dev;
159         drm_i915_private_t *dev_priv = dev->dev_private;
160
161         seq_printf(m, "Interrupt enable:    %08x\n",
162                    I915_READ(IER));
163         seq_printf(m, "Interrupt identity:  %08x\n",
164                    I915_READ(IIR));
165         seq_printf(m, "Interrupt mask:      %08x\n",
166                    I915_READ(IMR));
167         seq_printf(m, "Pipe A stat:         %08x\n",
168                    I915_READ(PIPEASTAT));
169         seq_printf(m, "Pipe B stat:         %08x\n",
170                    I915_READ(PIPEBSTAT));
171         seq_printf(m, "Interrupts received: %d\n",
172                    atomic_read(&dev_priv->irq_received));
173         if (dev_priv->hw_status_page != NULL) {
174                 seq_printf(m, "Current sequence:    %d\n",
175                            i915_get_gem_seqno(dev));
176         } else {
177                 seq_printf(m, "Current sequence:    hws uninitialized\n");
178         }
179         seq_printf(m, "Waiter sequence:     %d\n",
180                    dev_priv->mm.waiting_gem_seqno);
181         seq_printf(m, "IRQ sequence:        %d\n",
182                    dev_priv->mm.irq_gem_seqno);
183         return 0;
184 }
185
186 static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
187 {
188         struct drm_info_node *node = (struct drm_info_node *) m->private;
189         struct drm_device *dev = node->minor->dev;
190         drm_i915_private_t *dev_priv = dev->dev_private;
191         int i;
192
193         seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
194         seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
195         for (i = 0; i < dev_priv->num_fence_regs; i++) {
196                 struct drm_gem_object *obj = dev_priv->fence_regs[i].obj;
197
198                 if (obj == NULL) {
199                         seq_printf(m, "Fenced object[%2d] = unused\n", i);
200                 } else {
201                         struct drm_i915_gem_object *obj_priv;
202
203                         obj_priv = obj->driver_private;
204                         seq_printf(m, "Fenced object[%2d] = %p: %s "
205                                    "%08x %08zx %08x %s %08x %08x %d",
206                                    i, obj, get_pin_flag(obj_priv),
207                                    obj_priv->gtt_offset,
208                                    obj->size, obj_priv->stride,
209                                    get_tiling_flag(obj_priv),
210                                    obj->read_domains, obj->write_domain,
211                                    obj_priv->last_rendering_seqno);
212                         if (obj->name)
213                                 seq_printf(m, " (name: %d)", obj->name);
214                         seq_printf(m, "\n");
215                 }
216         }
217
218         return 0;
219 }
220
221 static int i915_hws_info(struct seq_file *m, void *data)
222 {
223         struct drm_info_node *node = (struct drm_info_node *) m->private;
224         struct drm_device *dev = node->minor->dev;
225         drm_i915_private_t *dev_priv = dev->dev_private;
226         int i;
227         volatile u32 *hws;
228
229         hws = (volatile u32 *)dev_priv->hw_status_page;
230         if (hws == NULL)
231                 return 0;
232
233         for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
234                 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
235                            i * 4,
236                            hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
237         }
238         return 0;
239 }
240
241 static void i915_dump_pages(struct seq_file *m, struct page **pages, int page_count)
242 {
243         int page, i;
244         uint32_t *mem;
245
246         for (page = 0; page < page_count; page++) {
247                 mem = kmap(pages[page]);
248                 for (i = 0; i < PAGE_SIZE; i += 4)
249                         seq_printf(m, "%08x :  %08x\n", i, mem[i / 4]);
250                 kunmap(pages[page]);
251         }
252 }
253
254 static int i915_batchbuffer_info(struct seq_file *m, void *data)
255 {
256         struct drm_info_node *node = (struct drm_info_node *) m->private;
257         struct drm_device *dev = node->minor->dev;
258         drm_i915_private_t *dev_priv = dev->dev_private;
259         struct drm_gem_object *obj;
260         struct drm_i915_gem_object *obj_priv;
261         int ret;
262
263         spin_lock(&dev_priv->mm.active_list_lock);
264
265         list_for_each_entry(obj_priv, &dev_priv->mm.active_list, list) {
266                 obj = obj_priv->obj;
267                 if (obj->read_domains & I915_GEM_DOMAIN_COMMAND) {
268                     ret = i915_gem_object_get_pages(obj);
269                     if (ret) {
270                             DRM_ERROR("Failed to get pages: %d\n", ret);
271                             spin_unlock(&dev_priv->mm.active_list_lock);
272                             return ret;
273                     }
274
275                     seq_printf(m, "--- gtt_offset = 0x%08x\n", obj_priv->gtt_offset);
276                     i915_dump_pages(m, obj_priv->pages, obj->size / PAGE_SIZE);
277
278                     i915_gem_object_put_pages(obj);
279                 }
280         }
281
282         spin_unlock(&dev_priv->mm.active_list_lock);
283
284         return 0;
285 }
286
287 static int i915_ringbuffer_data(struct seq_file *m, void *data)
288 {
289         struct drm_info_node *node = (struct drm_info_node *) m->private;
290         struct drm_device *dev = node->minor->dev;
291         drm_i915_private_t *dev_priv = dev->dev_private;
292         u8 *virt;
293         uint32_t *ptr, off;
294
295         if (!dev_priv->ring.ring_obj) {
296                 seq_printf(m, "No ringbuffer setup\n");
297                 return 0;
298         }
299
300         virt = dev_priv->ring.virtual_start;
301
302         for (off = 0; off < dev_priv->ring.Size; off += 4) {
303                 ptr = (uint32_t *)(virt + off);
304                 seq_printf(m, "%08x :  %08x\n", off, *ptr);
305         }
306
307         return 0;
308 }
309
310 static int i915_ringbuffer_info(struct seq_file *m, void *data)
311 {
312         struct drm_info_node *node = (struct drm_info_node *) m->private;
313         struct drm_device *dev = node->minor->dev;
314         drm_i915_private_t *dev_priv = dev->dev_private;
315         unsigned int head, tail, mask;
316
317         head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
318         tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
319         mask = dev_priv->ring.tail_mask;
320
321         seq_printf(m, "RingHead :  %08x\n", head);
322         seq_printf(m, "RingTail :  %08x\n", tail);
323         seq_printf(m, "RingMask :  %08x\n", mask);
324         seq_printf(m, "RingSize :  %08lx\n", dev_priv->ring.Size);
325         seq_printf(m, "Acthd :     %08x\n", I915_READ(IS_I965G(dev) ? ACTHD_I965 : ACTHD));
326
327         return 0;
328 }
329
330 static int i915_error_state(struct seq_file *m, void *unused)
331 {
332         struct drm_info_node *node = (struct drm_info_node *) m->private;
333         struct drm_device *dev = node->minor->dev;
334         drm_i915_private_t *dev_priv = dev->dev_private;
335         struct drm_i915_error_state *error;
336         unsigned long flags;
337
338         spin_lock_irqsave(&dev_priv->error_lock, flags);
339         if (!dev_priv->first_error) {
340                 seq_printf(m, "no error state collected\n");
341                 goto out;
342         }
343
344         error = dev_priv->first_error;
345
346         seq_printf(m, "EIR: 0x%08x\n", error->eir);
347         seq_printf(m, "  PGTBL_ER: 0x%08x\n", error->pgtbl_er);
348         seq_printf(m, "  INSTPM: 0x%08x\n", error->instpm);
349         seq_printf(m, "  IPEIR: 0x%08x\n", error->ipeir);
350         seq_printf(m, "  IPEHR: 0x%08x\n", error->ipehr);
351         seq_printf(m, "  INSTDONE: 0x%08x\n", error->instdone);
352         seq_printf(m, "  ACTHD: 0x%08x\n", error->acthd);
353         if (IS_I965G(dev)) {
354                 seq_printf(m, "  INSTPS: 0x%08x\n", error->instps);
355                 seq_printf(m, "  INSTDONE1: 0x%08x\n", error->instdone1);
356         }
357
358 out:
359         spin_unlock_irqrestore(&dev_priv->error_lock, flags);
360
361         return 0;
362 }
363
364 static struct drm_info_list i915_gem_debugfs_list[] = {
365         {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
366         {"i915_gem_flushing", i915_gem_object_list_info, 0, (void *) FLUSHING_LIST},
367         {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
368         {"i915_gem_request", i915_gem_request_info, 0},
369         {"i915_gem_seqno", i915_gem_seqno_info, 0},
370         {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
371         {"i915_gem_interrupt", i915_interrupt_info, 0},
372         {"i915_gem_hws", i915_hws_info, 0},
373         {"i915_ringbuffer_data", i915_ringbuffer_data, 0},
374         {"i915_ringbuffer_info", i915_ringbuffer_info, 0},
375         {"i915_batchbuffers", i915_batchbuffer_info, 0},
376         {"i915_error_state", i915_error_state, 0},
377 };
378 #define I915_GEM_DEBUGFS_ENTRIES ARRAY_SIZE(i915_gem_debugfs_list)
379
380 int i915_gem_debugfs_init(struct drm_minor *minor)
381 {
382         return drm_debugfs_create_files(i915_gem_debugfs_list,
383                                         I915_GEM_DEBUGFS_ENTRIES,
384                                         minor->debugfs_root, minor);
385 }
386
387 void i915_gem_debugfs_cleanup(struct drm_minor *minor)
388 {
389         drm_debugfs_remove_files(i915_gem_debugfs_list,
390                                  I915_GEM_DEBUGFS_ENTRIES, minor);
391 }
392
393 #endif /* CONFIG_DEBUG_FS */
394