2 * Copyright © 2008 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
29 #include <linux/seq_file.h>
35 #define DRM_I915_RING_DEBUG 1
38 #if defined(CONFIG_DEBUG_FS)
41 #define FLUSHING_LIST 2
42 #define INACTIVE_LIST 3
44 static const char *get_pin_flag(struct drm_i915_gem_object
*obj_priv
)
46 if (obj_priv
->user_pin_count
> 0)
48 else if (obj_priv
->pin_count
> 0)
54 static const char *get_tiling_flag(struct drm_i915_gem_object
*obj_priv
)
56 switch (obj_priv
->tiling_mode
) {
58 case I915_TILING_NONE
: return " ";
59 case I915_TILING_X
: return "X";
60 case I915_TILING_Y
: return "Y";
64 static int i915_gem_object_list_info(struct seq_file
*m
, void *data
)
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
;
76 seq_printf(m
, "Active:\n");
77 lock
= &dev_priv
->mm
.active_list_lock
;
78 head
= &dev_priv
->mm
.active_list
;
81 seq_printf(m
, "Inactive:\n");
82 head
= &dev_priv
->mm
.inactive_list
;
85 seq_printf(m
, "Flushing:\n");
86 head
= &dev_priv
->mm
.flushing_list
;
89 DRM_INFO("Ooops, unexpected list\n");
95 list_for_each_entry(obj_priv
, head
, list
)
97 struct drm_gem_object
*obj
= obj_priv
->obj
;
99 seq_printf(m
, " %p: %s %08x %08x %d",
101 get_pin_flag(obj_priv
),
102 obj
->read_domains
, obj
->write_domain
,
103 obj_priv
->last_rendering_seqno
);
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
);
120 static int i915_gem_request_info(struct seq_file
*m
, void *data
)
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
;
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",
131 (int) (jiffies
- gem_request
->emitted_jiffies
));
136 static int i915_gem_seqno_info(struct seq_file
*m
, void *data
)
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
;
142 if (dev_priv
->hw_status_page
!= NULL
) {
143 seq_printf(m
, "Current sequence: %d\n",
144 i915_get_gem_seqno(dev
));
146 seq_printf(m
, "Current sequence: hws uninitialized\n");
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
);
155 static int i915_interrupt_info(struct seq_file
*m
, void *data
)
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
;
161 seq_printf(m
, "Interrupt enable: %08x\n",
163 seq_printf(m
, "Interrupt identity: %08x\n",
165 seq_printf(m
, "Interrupt mask: %08x\n",
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
));
177 seq_printf(m
, "Current sequence: hws uninitialized\n");
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
);
186 static int i915_gem_fence_regs_info(struct seq_file
*m
, void *data
)
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
;
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
;
199 seq_printf(m
, "Fenced object[%2d] = unused\n", i
);
201 struct drm_i915_gem_object
*obj_priv
;
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
);
213 seq_printf(m
, " (name: %d)", obj
->name
);
221 static int i915_hws_info(struct seq_file
*m
, void *data
)
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
;
229 hws
= (volatile u32
*)dev_priv
->hw_status_page
;
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",
236 hws
[i
], hws
[i
+ 1], hws
[i
+ 2], hws
[i
+ 3]);
241 static void i915_dump_pages(struct seq_file
*m
, struct page
**pages
, int page_count
)
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]);
254 static int i915_batchbuffer_info(struct seq_file
*m
, void *data
)
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
;
263 spin_lock(&dev_priv
->mm
.active_list_lock
);
265 list_for_each_entry(obj_priv
, &dev_priv
->mm
.active_list
, list
) {
267 if (obj
->read_domains
& I915_GEM_DOMAIN_COMMAND
) {
268 ret
= i915_gem_object_get_pages(obj
);
270 DRM_ERROR("Failed to get pages: %d\n", ret
);
271 spin_unlock(&dev_priv
->mm
.active_list_lock
);
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
);
278 i915_gem_object_put_pages(obj
);
282 spin_unlock(&dev_priv
->mm
.active_list_lock
);
287 static int i915_ringbuffer_data(struct seq_file
*m
, void *data
)
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
;
295 if (!dev_priv
->ring
.ring_obj
) {
296 seq_printf(m
, "No ringbuffer setup\n");
300 virt
= dev_priv
->ring
.virtual_start
;
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
);
310 static int i915_ringbuffer_info(struct seq_file
*m
, void *data
)
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
;
317 head
= I915_READ(PRB0_HEAD
) & HEAD_ADDR
;
318 tail
= I915_READ(PRB0_TAIL
) & TAIL_ADDR
;
319 mask
= dev_priv
->ring
.tail_mask
;
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
));
330 static int i915_error_state(struct seq_file
*m
, void *unused
)
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
;
338 spin_lock_irqsave(&dev_priv
->error_lock
, flags
);
339 if (!dev_priv
->first_error
) {
340 seq_printf(m
, "no error state collected\n");
344 error
= dev_priv
->first_error
;
346 seq_printf(m
, "Time: %ld s %ld us\n", error
->time
.tv_sec
,
347 error
->time
.tv_usec
);
348 seq_printf(m
, "EIR: 0x%08x\n", error
->eir
);
349 seq_printf(m
, " PGTBL_ER: 0x%08x\n", error
->pgtbl_er
);
350 seq_printf(m
, " INSTPM: 0x%08x\n", error
->instpm
);
351 seq_printf(m
, " IPEIR: 0x%08x\n", error
->ipeir
);
352 seq_printf(m
, " IPEHR: 0x%08x\n", error
->ipehr
);
353 seq_printf(m
, " INSTDONE: 0x%08x\n", error
->instdone
);
354 seq_printf(m
, " ACTHD: 0x%08x\n", error
->acthd
);
356 seq_printf(m
, " INSTPS: 0x%08x\n", error
->instps
);
357 seq_printf(m
, " INSTDONE1: 0x%08x\n", error
->instdone1
);
361 spin_unlock_irqrestore(&dev_priv
->error_lock
, flags
);
366 static struct drm_info_list i915_gem_debugfs_list
[] = {
367 {"i915_gem_active", i915_gem_object_list_info
, 0, (void *) ACTIVE_LIST
},
368 {"i915_gem_flushing", i915_gem_object_list_info
, 0, (void *) FLUSHING_LIST
},
369 {"i915_gem_inactive", i915_gem_object_list_info
, 0, (void *) INACTIVE_LIST
},
370 {"i915_gem_request", i915_gem_request_info
, 0},
371 {"i915_gem_seqno", i915_gem_seqno_info
, 0},
372 {"i915_gem_fence_regs", i915_gem_fence_regs_info
, 0},
373 {"i915_gem_interrupt", i915_interrupt_info
, 0},
374 {"i915_gem_hws", i915_hws_info
, 0},
375 {"i915_ringbuffer_data", i915_ringbuffer_data
, 0},
376 {"i915_ringbuffer_info", i915_ringbuffer_info
, 0},
377 {"i915_batchbuffers", i915_batchbuffer_info
, 0},
378 {"i915_error_state", i915_error_state
, 0},
380 #define I915_GEM_DEBUGFS_ENTRIES ARRAY_SIZE(i915_gem_debugfs_list)
382 int i915_gem_debugfs_init(struct drm_minor
*minor
)
384 return drm_debugfs_create_files(i915_gem_debugfs_list
,
385 I915_GEM_DEBUGFS_ENTRIES
,
386 minor
->debugfs_root
, minor
);
389 void i915_gem_debugfs_cleanup(struct drm_minor
*minor
)
391 drm_debugfs_remove_files(i915_gem_debugfs_list
,
392 I915_GEM_DEBUGFS_ENTRIES
, minor
);
395 #endif /* CONFIG_DEBUG_FS */