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;
79 head = &dev_priv->mm.active_list;
82 seq_printf(m, "Inctive:\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");
94 list_for_each_entry(obj_priv, head, list)
96 struct drm_gem_object *obj = obj_priv->obj;
98 seq_printf(m, " %p: %s %08x %08x %d",
100 get_pin_flag(obj_priv),
101 obj->read_domains, obj->write_domain,
102 obj_priv->last_rendering_seqno);
105 seq_printf(m, " (name: %d)", obj->name);
106 if (obj_priv->fence_reg != I915_FENCE_REG_NONE)
107 seq_printf(m, " (fence: %d)\n", obj_priv->fence_reg);
116 static int i915_gem_request_info(struct seq_file *m, void *data)
118 struct drm_info_node *node = (struct drm_info_node *) m->private;
119 struct drm_device *dev = node->minor->dev;
120 drm_i915_private_t *dev_priv = dev->dev_private;
121 struct drm_i915_gem_request *gem_request;
123 seq_printf(m, "Request:\n");
124 list_for_each_entry(gem_request, &dev_priv->mm.request_list, list) {
125 seq_printf(m, " %d @ %d\n",
127 (int) (jiffies - gem_request->emitted_jiffies));
132 static int i915_gem_seqno_info(struct seq_file *m, void *data)
134 struct drm_info_node *node = (struct drm_info_node *) m->private;
135 struct drm_device *dev = node->minor->dev;
136 drm_i915_private_t *dev_priv = dev->dev_private;
138 if (dev_priv->hw_status_page != NULL) {
139 seq_printf(m, "Current sequence: %d\n",
140 i915_get_gem_seqno(dev));
142 seq_printf(m, "Current sequence: hws uninitialized\n");
144 seq_printf(m, "Waiter sequence: %d\n",
145 dev_priv->mm.waiting_gem_seqno);
146 seq_printf(m, "IRQ sequence: %d\n", dev_priv->mm.irq_gem_seqno);
151 static int i915_interrupt_info(struct seq_file *m, void *data)
153 struct drm_info_node *node = (struct drm_info_node *) m->private;
154 struct drm_device *dev = node->minor->dev;
155 drm_i915_private_t *dev_priv = dev->dev_private;
157 seq_printf(m, "Interrupt enable: %08x\n",
159 seq_printf(m, "Interrupt identity: %08x\n",
161 seq_printf(m, "Interrupt mask: %08x\n",
163 seq_printf(m, "Pipe A stat: %08x\n",
164 I915_READ(PIPEASTAT));
165 seq_printf(m, "Pipe B stat: %08x\n",
166 I915_READ(PIPEBSTAT));
167 seq_printf(m, "Interrupts received: %d\n",
168 atomic_read(&dev_priv->irq_received));
169 if (dev_priv->hw_status_page != NULL) {
170 seq_printf(m, "Current sequence: %d\n",
171 i915_get_gem_seqno(dev));
173 seq_printf(m, "Current sequence: hws uninitialized\n");
175 seq_printf(m, "Waiter sequence: %d\n",
176 dev_priv->mm.waiting_gem_seqno);
177 seq_printf(m, "IRQ sequence: %d\n",
178 dev_priv->mm.irq_gem_seqno);
182 static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
184 struct drm_info_node *node = (struct drm_info_node *) m->private;
185 struct drm_device *dev = node->minor->dev;
186 drm_i915_private_t *dev_priv = dev->dev_private;
189 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
190 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
191 for (i = 0; i < dev_priv->num_fence_regs; i++) {
192 struct drm_gem_object *obj = dev_priv->fence_regs[i].obj;
195 seq_printf(m, "Fenced object[%2d] = unused\n", i);
197 struct drm_i915_gem_object *obj_priv;
199 obj_priv = obj->driver_private;
200 seq_printf(m, "Fenced object[%2d] = %p: %s "
201 "%08x %08zx %08x %s %08x %08x %d",
202 i, obj, get_pin_flag(obj_priv),
203 obj_priv->gtt_offset,
204 obj->size, obj_priv->stride,
205 get_tiling_flag(obj_priv),
206 obj->read_domains, obj->write_domain,
207 obj_priv->last_rendering_seqno);
209 seq_printf(m, " (name: %d)", obj->name);
217 static int i915_hws_info(struct seq_file *m, void *data)
219 struct drm_info_node *node = (struct drm_info_node *) m->private;
220 struct drm_device *dev = node->minor->dev;
221 drm_i915_private_t *dev_priv = dev->dev_private;
225 hws = (volatile u32 *)dev_priv->hw_status_page;
229 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
230 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
232 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
237 static void i915_dump_pages(struct seq_file *m, struct page **pages, int page_count)
242 for (page = 0; page < page_count; page++) {
243 mem = kmap(pages[page]);
244 for (i = 0; i < PAGE_SIZE; i += 4)
245 seq_printf(m, "%08x : %08x\n", i, mem[i / 4]);
250 static int i915_batchbuffer_info(struct seq_file *m, void *data)
252 struct drm_info_node *node = (struct drm_info_node *) m->private;
253 struct drm_device *dev = node->minor->dev;
254 drm_i915_private_t *dev_priv = dev->dev_private;
255 struct drm_gem_object *obj;
256 struct drm_i915_gem_object *obj_priv;
259 spin_lock(&dev_priv->mm.active_list_lock);
261 list_for_each_entry(obj_priv, &dev_priv->mm.active_list, list) {
263 if (obj->read_domains & I915_GEM_DOMAIN_COMMAND) {
264 ret = i915_gem_object_get_pages(obj);
266 DRM_ERROR("Failed to get pages: %d\n", ret);
267 spin_unlock(&dev_priv->mm.active_list_lock);
271 seq_printf(m, "--- gtt_offset = 0x%08x\n", obj_priv->gtt_offset);
272 i915_dump_pages(m, obj_priv->pages, obj->size / PAGE_SIZE);
274 i915_gem_object_put_pages(obj);
278 spin_unlock(&dev_priv->mm.active_list_lock);
283 static int i915_ringbuffer_data(struct seq_file *m, void *data)
285 struct drm_info_node *node = (struct drm_info_node *) m->private;
286 struct drm_device *dev = node->minor->dev;
287 drm_i915_private_t *dev_priv = dev->dev_private;
291 if (!dev_priv->ring.ring_obj) {
292 seq_printf(m, "No ringbuffer setup\n");
296 virt = dev_priv->ring.virtual_start;
298 for (off = 0; off < dev_priv->ring.Size; off += 4) {
299 ptr = (uint32_t *)(virt + off);
300 seq_printf(m, "%08x : %08x\n", off, *ptr);
306 static int i915_ringbuffer_info(struct seq_file *m, void *data)
308 struct drm_info_node *node = (struct drm_info_node *) m->private;
309 struct drm_device *dev = node->minor->dev;
310 drm_i915_private_t *dev_priv = dev->dev_private;
311 unsigned int head, tail, mask;
313 head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
314 tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
315 mask = dev_priv->ring.tail_mask;
317 seq_printf(m, "RingHead : %08x\n", head);
318 seq_printf(m, "RingTail : %08x\n", tail);
319 seq_printf(m, "RingMask : %08x\n", mask);
320 seq_printf(m, "RingSize : %08lx\n", dev_priv->ring.Size);
321 seq_printf(m, "Acthd : %08x\n", I915_READ(IS_I965G(dev) ? ACTHD_I965 : ACTHD));
327 static struct drm_info_list i915_gem_debugfs_list[] = {
328 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
329 {"i915_gem_flushing", i915_gem_object_list_info, 0, (void *) FLUSHING_LIST},
330 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
331 {"i915_gem_request", i915_gem_request_info, 0},
332 {"i915_gem_seqno", i915_gem_seqno_info, 0},
333 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
334 {"i915_gem_interrupt", i915_interrupt_info, 0},
335 {"i915_gem_hws", i915_hws_info, 0},
336 {"i915_ringbuffer_data", i915_ringbuffer_data, 0},
337 {"i915_ringbuffer_info", i915_ringbuffer_info, 0},
338 {"i915_batchbuffers", i915_batchbuffer_info, 0},
340 #define I915_GEM_DEBUGFS_ENTRIES ARRAY_SIZE(i915_gem_debugfs_list)
342 int i915_gem_debugfs_init(struct drm_minor *minor)
344 return drm_debugfs_create_files(i915_gem_debugfs_list,
345 I915_GEM_DEBUGFS_ENTRIES,
346 minor->debugfs_root, minor);
349 void i915_gem_debugfs_cleanup(struct drm_minor *minor)
351 drm_debugfs_remove_files(i915_gem_debugfs_list,
352 I915_GEM_DEBUGFS_ENTRIES, minor);
355 #endif /* CONFIG_DEBUG_FS */