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>
30 #include <linux/debugfs.h>
36 #define DRM_I915_RING_DEBUG 1
39 #if defined(CONFIG_DEBUG_FS)
42 #define FLUSHING_LIST 2
43 #define INACTIVE_LIST 3
45 static const char *get_pin_flag(struct drm_i915_gem_object
*obj_priv
)
47 if (obj_priv
->user_pin_count
> 0)
49 else if (obj_priv
->pin_count
> 0)
55 static const char *get_tiling_flag(struct drm_i915_gem_object
*obj_priv
)
57 switch (obj_priv
->tiling_mode
) {
59 case I915_TILING_NONE
: return " ";
60 case I915_TILING_X
: return "X";
61 case I915_TILING_Y
: return "Y";
65 static int i915_gem_object_list_info(struct seq_file
*m
, void *data
)
67 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
68 uintptr_t list
= (uintptr_t) node
->info_ent
->data
;
69 struct list_head
*head
;
70 struct drm_device
*dev
= node
->minor
->dev
;
71 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
72 struct drm_i915_gem_object
*obj_priv
;
73 spinlock_t
*lock
= NULL
;
77 seq_printf(m
, "Active:\n");
78 lock
= &dev_priv
->mm
.active_list_lock
;
79 head
= &dev_priv
->mm
.active_list
;
82 seq_printf(m
, "Inactive:\n");
83 head
= &dev_priv
->mm
.inactive_list
;
86 seq_printf(m
, "Flushing:\n");
87 head
= &dev_priv
->mm
.flushing_list
;
90 DRM_INFO("Ooops, unexpected list\n");
96 list_for_each_entry(obj_priv
, head
, list
)
98 struct drm_gem_object
*obj
= obj_priv
->obj
;
100 seq_printf(m
, " %p: %s %8zd %08x %08x %d%s%s",
102 get_pin_flag(obj_priv
),
104 obj
->read_domains
, obj
->write_domain
,
105 obj_priv
->last_rendering_seqno
,
106 obj_priv
->dirty
? " dirty" : "",
107 obj_priv
->madv
== I915_MADV_DONTNEED
? " purgeable" : "");
110 seq_printf(m
, " (name: %d)", obj
->name
);
111 if (obj_priv
->fence_reg
!= I915_FENCE_REG_NONE
)
112 seq_printf(m
, " (fence: %d)", obj_priv
->fence_reg
);
113 if (obj_priv
->gtt_space
!= NULL
)
114 seq_printf(m
, " (gtt_offset: %08x)", obj_priv
->gtt_offset
);
124 static int i915_gem_request_info(struct seq_file
*m
, void *data
)
126 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
127 struct drm_device
*dev
= node
->minor
->dev
;
128 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
129 struct drm_i915_gem_request
*gem_request
;
131 seq_printf(m
, "Request:\n");
132 list_for_each_entry(gem_request
, &dev_priv
->mm
.request_list
, list
) {
133 seq_printf(m
, " %d @ %d\n",
135 (int) (jiffies
- gem_request
->emitted_jiffies
));
140 static int i915_gem_seqno_info(struct seq_file
*m
, void *data
)
142 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
143 struct drm_device
*dev
= node
->minor
->dev
;
144 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
146 if (dev_priv
->hw_status_page
!= NULL
) {
147 seq_printf(m
, "Current sequence: %d\n",
148 i915_get_gem_seqno(dev
));
150 seq_printf(m
, "Current sequence: hws uninitialized\n");
152 seq_printf(m
, "Waiter sequence: %d\n",
153 dev_priv
->mm
.waiting_gem_seqno
);
154 seq_printf(m
, "IRQ sequence: %d\n", dev_priv
->mm
.irq_gem_seqno
);
159 static int i915_interrupt_info(struct seq_file
*m
, void *data
)
161 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
162 struct drm_device
*dev
= node
->minor
->dev
;
163 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
165 if (!IS_IRONLAKE(dev
)) {
166 seq_printf(m
, "Interrupt enable: %08x\n",
168 seq_printf(m
, "Interrupt identity: %08x\n",
170 seq_printf(m
, "Interrupt mask: %08x\n",
172 seq_printf(m
, "Pipe A stat: %08x\n",
173 I915_READ(PIPEASTAT
));
174 seq_printf(m
, "Pipe B stat: %08x\n",
175 I915_READ(PIPEBSTAT
));
177 seq_printf(m
, "North Display Interrupt enable: %08x\n",
179 seq_printf(m
, "North Display Interrupt identity: %08x\n",
181 seq_printf(m
, "North Display Interrupt mask: %08x\n",
183 seq_printf(m
, "South Display Interrupt enable: %08x\n",
185 seq_printf(m
, "South Display Interrupt identity: %08x\n",
187 seq_printf(m
, "South Display Interrupt mask: %08x\n",
189 seq_printf(m
, "Graphics Interrupt enable: %08x\n",
191 seq_printf(m
, "Graphics Interrupt identity: %08x\n",
193 seq_printf(m
, "Graphics Interrupt mask: %08x\n",
196 seq_printf(m
, "Interrupts received: %d\n",
197 atomic_read(&dev_priv
->irq_received
));
198 if (dev_priv
->hw_status_page
!= NULL
) {
199 seq_printf(m
, "Current sequence: %d\n",
200 i915_get_gem_seqno(dev
));
202 seq_printf(m
, "Current sequence: hws uninitialized\n");
204 seq_printf(m
, "Waiter sequence: %d\n",
205 dev_priv
->mm
.waiting_gem_seqno
);
206 seq_printf(m
, "IRQ sequence: %d\n",
207 dev_priv
->mm
.irq_gem_seqno
);
211 static int i915_gem_fence_regs_info(struct seq_file
*m
, void *data
)
213 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
214 struct drm_device
*dev
= node
->minor
->dev
;
215 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
218 seq_printf(m
, "Reserved fences = %d\n", dev_priv
->fence_reg_start
);
219 seq_printf(m
, "Total fences = %d\n", dev_priv
->num_fence_regs
);
220 for (i
= 0; i
< dev_priv
->num_fence_regs
; i
++) {
221 struct drm_gem_object
*obj
= dev_priv
->fence_regs
[i
].obj
;
224 seq_printf(m
, "Fenced object[%2d] = unused\n", i
);
226 struct drm_i915_gem_object
*obj_priv
;
228 obj_priv
= obj
->driver_private
;
229 seq_printf(m
, "Fenced object[%2d] = %p: %s "
230 "%08x %08zx %08x %s %08x %08x %d",
231 i
, obj
, get_pin_flag(obj_priv
),
232 obj_priv
->gtt_offset
,
233 obj
->size
, obj_priv
->stride
,
234 get_tiling_flag(obj_priv
),
235 obj
->read_domains
, obj
->write_domain
,
236 obj_priv
->last_rendering_seqno
);
238 seq_printf(m
, " (name: %d)", obj
->name
);
246 static int i915_hws_info(struct seq_file
*m
, void *data
)
248 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
249 struct drm_device
*dev
= node
->minor
->dev
;
250 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
254 hws
= (volatile u32
*)dev_priv
->hw_status_page
;
258 for (i
= 0; i
< 4096 / sizeof(u32
) / 4; i
+= 4) {
259 seq_printf(m
, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
261 hws
[i
], hws
[i
+ 1], hws
[i
+ 2], hws
[i
+ 3]);
266 static void i915_dump_pages(struct seq_file
*m
, struct page
**pages
, int page_count
)
271 for (page
= 0; page
< page_count
; page
++) {
272 mem
= kmap_atomic(pages
[page
], KM_USER0
);
273 for (i
= 0; i
< PAGE_SIZE
; i
+= 4)
274 seq_printf(m
, "%08x : %08x\n", i
, mem
[i
/ 4]);
275 kunmap_atomic(mem
, KM_USER0
);
279 static int i915_batchbuffer_info(struct seq_file
*m
, void *data
)
281 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
282 struct drm_device
*dev
= node
->minor
->dev
;
283 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
284 struct drm_gem_object
*obj
;
285 struct drm_i915_gem_object
*obj_priv
;
288 spin_lock(&dev_priv
->mm
.active_list_lock
);
290 list_for_each_entry(obj_priv
, &dev_priv
->mm
.active_list
, list
) {
292 if (obj
->read_domains
& I915_GEM_DOMAIN_COMMAND
) {
293 ret
= i915_gem_object_get_pages(obj
, 0);
295 DRM_ERROR("Failed to get pages: %d\n", ret
);
296 spin_unlock(&dev_priv
->mm
.active_list_lock
);
300 seq_printf(m
, "--- gtt_offset = 0x%08x\n", obj_priv
->gtt_offset
);
301 i915_dump_pages(m
, obj_priv
->pages
, obj
->size
/ PAGE_SIZE
);
303 i915_gem_object_put_pages(obj
);
307 spin_unlock(&dev_priv
->mm
.active_list_lock
);
312 static int i915_ringbuffer_data(struct seq_file
*m
, void *data
)
314 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
315 struct drm_device
*dev
= node
->minor
->dev
;
316 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
320 if (!dev_priv
->ring
.ring_obj
) {
321 seq_printf(m
, "No ringbuffer setup\n");
325 virt
= dev_priv
->ring
.virtual_start
;
327 for (off
= 0; off
< dev_priv
->ring
.Size
; off
+= 4) {
328 ptr
= (uint32_t *)(virt
+ off
);
329 seq_printf(m
, "%08x : %08x\n", off
, *ptr
);
335 static int i915_ringbuffer_info(struct seq_file
*m
, void *data
)
337 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
338 struct drm_device
*dev
= node
->minor
->dev
;
339 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
340 unsigned int head
, tail
;
342 head
= I915_READ(PRB0_HEAD
) & HEAD_ADDR
;
343 tail
= I915_READ(PRB0_TAIL
) & TAIL_ADDR
;
345 seq_printf(m
, "RingHead : %08x\n", head
);
346 seq_printf(m
, "RingTail : %08x\n", tail
);
347 seq_printf(m
, "RingSize : %08lx\n", dev_priv
->ring
.Size
);
348 seq_printf(m
, "Acthd : %08x\n", I915_READ(IS_I965G(dev
) ? ACTHD_I965
: ACTHD
));
353 static int i915_error_state(struct seq_file
*m
, void *unused
)
355 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
356 struct drm_device
*dev
= node
->minor
->dev
;
357 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
358 struct drm_i915_error_state
*error
;
361 spin_lock_irqsave(&dev_priv
->error_lock
, flags
);
362 if (!dev_priv
->first_error
) {
363 seq_printf(m
, "no error state collected\n");
367 error
= dev_priv
->first_error
;
369 seq_printf(m
, "Time: %ld s %ld us\n", error
->time
.tv_sec
,
370 error
->time
.tv_usec
);
371 seq_printf(m
, "EIR: 0x%08x\n", error
->eir
);
372 seq_printf(m
, " PGTBL_ER: 0x%08x\n", error
->pgtbl_er
);
373 seq_printf(m
, " INSTPM: 0x%08x\n", error
->instpm
);
374 seq_printf(m
, " IPEIR: 0x%08x\n", error
->ipeir
);
375 seq_printf(m
, " IPEHR: 0x%08x\n", error
->ipehr
);
376 seq_printf(m
, " INSTDONE: 0x%08x\n", error
->instdone
);
377 seq_printf(m
, " ACTHD: 0x%08x\n", error
->acthd
);
379 seq_printf(m
, " INSTPS: 0x%08x\n", error
->instps
);
380 seq_printf(m
, " INSTDONE1: 0x%08x\n", error
->instdone1
);
384 spin_unlock_irqrestore(&dev_priv
->error_lock
, flags
);
390 i915_wedged_open(struct inode
*inode
,
393 filp
->private_data
= inode
->i_private
;
398 i915_wedged_read(struct file
*filp
,
403 struct drm_device
*dev
= filp
->private_data
;
404 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
408 len
= snprintf(buf
, sizeof (buf
),
410 atomic_read(&dev_priv
->mm
.wedged
));
412 return simple_read_from_buffer(ubuf
, max
, ppos
, buf
, len
);
416 i915_wedged_write(struct file
*filp
,
417 const char __user
*ubuf
,
421 struct drm_device
*dev
= filp
->private_data
;
422 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
427 if (cnt
> sizeof (buf
) - 1)
430 if (copy_from_user(buf
, ubuf
, cnt
))
434 val
= simple_strtoul(buf
, NULL
, 0);
437 DRM_INFO("Manually setting wedged to %d\n", val
);
439 atomic_set(&dev_priv
->mm
.wedged
, val
);
441 DRM_WAKEUP(&dev_priv
->irq_queue
);
442 queue_work(dev_priv
->wq
, &dev_priv
->error_work
);
448 static const struct file_operations i915_wedged_fops
= {
449 .owner
= THIS_MODULE
,
450 .open
= i915_wedged_open
,
451 .read
= i915_wedged_read
,
452 .write
= i915_wedged_write
,
455 /* As the drm_debugfs_init() routines are called before dev->dev_private is
456 * allocated we need to hook into the minor for release. */
458 drm_add_fake_info_node(struct drm_minor
*minor
,
462 struct drm_info_node
*node
;
464 node
= kmalloc(sizeof(struct drm_info_node
), GFP_KERNEL
);
472 node
->info_ent
= (void *) key
;
473 list_add(&node
->list
, &minor
->debugfs_nodes
.list
);
478 static int i915_wedged_create(struct dentry
*root
, struct drm_minor
*minor
)
480 struct drm_device
*dev
= minor
->dev
;
483 ent
= debugfs_create_file("i915_wedged",
490 return drm_add_fake_info_node(minor
, ent
, &i915_wedged_fops
);
493 static struct drm_info_list i915_debugfs_list
[] = {
494 {"i915_gem_active", i915_gem_object_list_info
, 0, (void *) ACTIVE_LIST
},
495 {"i915_gem_flushing", i915_gem_object_list_info
, 0, (void *) FLUSHING_LIST
},
496 {"i915_gem_inactive", i915_gem_object_list_info
, 0, (void *) INACTIVE_LIST
},
497 {"i915_gem_request", i915_gem_request_info
, 0},
498 {"i915_gem_seqno", i915_gem_seqno_info
, 0},
499 {"i915_gem_fence_regs", i915_gem_fence_regs_info
, 0},
500 {"i915_gem_interrupt", i915_interrupt_info
, 0},
501 {"i915_gem_hws", i915_hws_info
, 0},
502 {"i915_ringbuffer_data", i915_ringbuffer_data
, 0},
503 {"i915_ringbuffer_info", i915_ringbuffer_info
, 0},
504 {"i915_batchbuffers", i915_batchbuffer_info
, 0},
505 {"i915_error_state", i915_error_state
, 0},
507 #define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
509 int i915_debugfs_init(struct drm_minor
*minor
)
513 ret
= i915_wedged_create(minor
->debugfs_root
, minor
);
517 return drm_debugfs_create_files(i915_debugfs_list
,
518 I915_DEBUGFS_ENTRIES
,
519 minor
->debugfs_root
, minor
);
522 void i915_debugfs_cleanup(struct drm_minor
*minor
)
524 drm_debugfs_remove_files(i915_debugfs_list
,
525 I915_DEBUGFS_ENTRIES
, minor
);
526 drm_debugfs_remove_files((struct drm_info_list
*) &i915_wedged_fops
,
530 #endif /* CONFIG_DEBUG_FS */