blob: d14b44e13f5190e73077a70c48508010fb311602 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
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>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010030#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040032#include <linux/export.h>
Ben Gamari20172632009-02-17 20:08:50 -050033#include "drmP.h"
34#include "drm.h"
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010035#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000036#include "intel_ringbuffer.h"
Ben Gamari20172632009-02-17 20:08:50 -050037#include "i915_drm.h"
38#include "i915_drv.h"
39
40#define DRM_I915_RING_DEBUG 1
41
42
43#if defined(CONFIG_DEBUG_FS)
44
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010046 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047 FLUSHING_LIST,
48 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010049 PINNED_LIST,
50 DEFERRED_FREE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010051};
Ben Gamari433e12f2009-02-17 20:08:51 -050052
Chris Wilson70d39fe2010-08-25 16:03:34 +010053static const char *yesno(int v)
54{
55 return v ? "yes" : "no";
56}
57
58static int i915_capabilities(struct seq_file *m, void *data)
59{
60 struct drm_info_node *node = (struct drm_info_node *) m->private;
61 struct drm_device *dev = node->minor->dev;
62 const struct intel_device_info *info = INTEL_INFO(dev);
63
64 seq_printf(m, "gen: %d\n", info->gen);
65#define B(x) seq_printf(m, #x ": %s\n", yesno(info->x))
66 B(is_mobile);
Chris Wilson70d39fe2010-08-25 16:03:34 +010067 B(is_i85x);
68 B(is_i915g);
Chris Wilson70d39fe2010-08-25 16:03:34 +010069 B(is_i945gm);
Chris Wilson70d39fe2010-08-25 16:03:34 +010070 B(is_g33);
71 B(need_gfx_hws);
72 B(is_g4x);
73 B(is_pineview);
74 B(is_broadwater);
75 B(is_crestline);
Chris Wilson70d39fe2010-08-25 16:03:34 +010076 B(has_fbc);
Chris Wilson70d39fe2010-08-25 16:03:34 +010077 B(has_pipe_cxsr);
78 B(has_hotplug);
79 B(cursor_needs_physical);
80 B(has_overlay);
81 B(overlay_needs_physical);
Chris Wilsona6c45cf2010-09-17 00:32:17 +010082 B(supports_tv);
Chris Wilson549f7362010-10-19 11:19:32 +010083 B(has_bsd_ring);
84 B(has_blt_ring);
Chris Wilson70d39fe2010-08-25 16:03:34 +010085#undef B
86
87 return 0;
88}
Ben Gamari433e12f2009-02-17 20:08:51 -050089
Chris Wilson05394f32010-11-08 19:18:58 +000090static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000091{
Chris Wilson05394f32010-11-08 19:18:58 +000092 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000093 return "P";
Chris Wilson05394f32010-11-08 19:18:58 +000094 else if (obj->pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000095 return "p";
96 else
97 return " ";
98}
99
Chris Wilson05394f32010-11-08 19:18:58 +0000100static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000101{
Akshay Joshi0206e352011-08-16 15:34:10 -0400102 switch (obj->tiling_mode) {
103 default:
104 case I915_TILING_NONE: return " ";
105 case I915_TILING_X: return "X";
106 case I915_TILING_Y: return "Y";
107 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000108}
109
Chris Wilson93dfb402011-03-29 16:59:50 -0700110static const char *cache_level_str(int type)
Chris Wilson08c18322011-01-10 00:00:24 +0000111{
112 switch (type) {
Chris Wilson93dfb402011-03-29 16:59:50 -0700113 case I915_CACHE_NONE: return " uncached";
114 case I915_CACHE_LLC: return " snooped (LLC)";
115 case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
Chris Wilson08c18322011-01-10 00:00:24 +0000116 default: return "";
117 }
118}
119
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Chris Wilson08c18322011-01-10 00:00:24 +0000123 seq_printf(m, "%p: %s%s %8zd %04x %04x %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100124 &obj->base,
125 get_pin_flag(obj),
126 get_tiling_flag(obj),
127 obj->base.size,
128 obj->base.read_domains,
129 obj->base.write_domain,
130 obj->last_rendering_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000131 obj->last_fenced_seqno,
Chris Wilson93dfb402011-03-29 16:59:50 -0700132 cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100133 obj->dirty ? " dirty" : "",
134 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
135 if (obj->base.name)
136 seq_printf(m, " (name: %d)", obj->base.name);
137 if (obj->fence_reg != I915_FENCE_REG_NONE)
138 seq_printf(m, " (fence: %d)", obj->fence_reg);
139 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100140 seq_printf(m, " (gtt offset: %08x, size: %08x)",
141 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilson6299f992010-11-24 12:23:44 +0000142 if (obj->pin_mappable || obj->fault_mappable) {
143 char s[3], *t = s;
144 if (obj->pin_mappable)
145 *t++ = 'p';
146 if (obj->fault_mappable)
147 *t++ = 'f';
148 *t = '\0';
149 seq_printf(m, " (%s mappable)", s);
150 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100151 if (obj->ring != NULL)
152 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100153}
154
Ben Gamari433e12f2009-02-17 20:08:51 -0500155static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500156{
157 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500158 uintptr_t list = (uintptr_t) node->info_ent->data;
159 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500160 struct drm_device *dev = node->minor->dev;
161 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000162 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100163 size_t total_obj_size, total_gtt_size;
164 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100165
166 ret = mutex_lock_interruptible(&dev->struct_mutex);
167 if (ret)
168 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500169
Ben Gamari433e12f2009-02-17 20:08:51 -0500170 switch (list) {
171 case ACTIVE_LIST:
172 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100173 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500174 break;
175 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400176 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500177 head = &dev_priv->mm.inactive_list;
178 break;
Chris Wilsonf13d3f72010-09-20 17:36:15 +0100179 case PINNED_LIST:
180 seq_printf(m, "Pinned:\n");
181 head = &dev_priv->mm.pinned_list;
182 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500183 case FLUSHING_LIST:
184 seq_printf(m, "Flushing:\n");
185 head = &dev_priv->mm.flushing_list;
186 break;
Chris Wilsond21d5972010-09-26 11:19:33 +0100187 case DEFERRED_FREE_LIST:
188 seq_printf(m, "Deferred free:\n");
189 head = &dev_priv->mm.deferred_free_list;
190 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500191 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100192 mutex_unlock(&dev->struct_mutex);
193 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500194 }
195
Chris Wilson8f2480f2010-09-26 11:44:19 +0100196 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000197 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100198 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000199 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800200 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000201 total_obj_size += obj->base.size;
202 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100203 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500204 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100205 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700206
Chris Wilson8f2480f2010-09-26 11:44:19 +0100207 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
208 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500209 return 0;
210}
211
Chris Wilson6299f992010-11-24 12:23:44 +0000212#define count_objects(list, member) do { \
213 list_for_each_entry(obj, list, member) { \
214 size += obj->gtt_space->size; \
215 ++count; \
216 if (obj->map_and_fenceable) { \
217 mappable_size += obj->gtt_space->size; \
218 ++mappable_count; \
219 } \
220 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400221} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000222
Chris Wilson73aa8082010-09-30 11:46:12 +0100223static int i915_gem_object_info(struct seq_file *m, void* data)
224{
225 struct drm_info_node *node = (struct drm_info_node *) m->private;
226 struct drm_device *dev = node->minor->dev;
227 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson6299f992010-11-24 12:23:44 +0000228 u32 count, mappable_count;
229 size_t size, mappable_size;
230 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100231 int ret;
232
233 ret = mutex_lock_interruptible(&dev->struct_mutex);
234 if (ret)
235 return ret;
236
Chris Wilson6299f992010-11-24 12:23:44 +0000237 seq_printf(m, "%u objects, %zu bytes\n",
238 dev_priv->mm.object_count,
239 dev_priv->mm.object_memory);
240
241 size = count = mappable_size = mappable_count = 0;
242 count_objects(&dev_priv->mm.gtt_list, gtt_list);
243 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
244 count, mappable_count, size, mappable_size);
245
246 size = count = mappable_size = mappable_count = 0;
247 count_objects(&dev_priv->mm.active_list, mm_list);
248 count_objects(&dev_priv->mm.flushing_list, mm_list);
249 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
250 count, mappable_count, size, mappable_size);
251
252 size = count = mappable_size = mappable_count = 0;
253 count_objects(&dev_priv->mm.pinned_list, mm_list);
254 seq_printf(m, " %u [%u] pinned objects, %zu [%zu] bytes\n",
255 count, mappable_count, size, mappable_size);
256
257 size = count = mappable_size = mappable_count = 0;
258 count_objects(&dev_priv->mm.inactive_list, mm_list);
259 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
260 count, mappable_count, size, mappable_size);
261
262 size = count = mappable_size = mappable_count = 0;
263 count_objects(&dev_priv->mm.deferred_free_list, mm_list);
264 seq_printf(m, " %u [%u] freed objects, %zu [%zu] bytes\n",
265 count, mappable_count, size, mappable_size);
266
267 size = count = mappable_size = mappable_count = 0;
268 list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {
269 if (obj->fault_mappable) {
270 size += obj->gtt_space->size;
271 ++count;
272 }
273 if (obj->pin_mappable) {
274 mappable_size += obj->gtt_space->size;
275 ++mappable_count;
276 }
277 }
278 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
279 mappable_count, mappable_size);
280 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
281 count, size);
282
283 seq_printf(m, "%zu [%zu] gtt total\n",
284 dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
Chris Wilson73aa8082010-09-30 11:46:12 +0100285
286 mutex_unlock(&dev->struct_mutex);
287
288 return 0;
289}
290
Chris Wilson08c18322011-01-10 00:00:24 +0000291static int i915_gem_gtt_info(struct seq_file *m, void* data)
292{
293 struct drm_info_node *node = (struct drm_info_node *) m->private;
294 struct drm_device *dev = node->minor->dev;
295 struct drm_i915_private *dev_priv = dev->dev_private;
296 struct drm_i915_gem_object *obj;
297 size_t total_obj_size, total_gtt_size;
298 int count, ret;
299
300 ret = mutex_lock_interruptible(&dev->struct_mutex);
301 if (ret)
302 return ret;
303
304 total_obj_size = total_gtt_size = count = 0;
305 list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {
306 seq_printf(m, " ");
307 describe_obj(m, obj);
308 seq_printf(m, "\n");
309 total_obj_size += obj->base.size;
310 total_gtt_size += obj->gtt_space->size;
311 count++;
312 }
313
314 mutex_unlock(&dev->struct_mutex);
315
316 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
317 count, total_obj_size, total_gtt_size);
318
319 return 0;
320}
321
Chris Wilson73aa8082010-09-30 11:46:12 +0100322
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100323static int i915_gem_pageflip_info(struct seq_file *m, void *data)
324{
325 struct drm_info_node *node = (struct drm_info_node *) m->private;
326 struct drm_device *dev = node->minor->dev;
327 unsigned long flags;
328 struct intel_crtc *crtc;
329
330 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800331 const char pipe = pipe_name(crtc->pipe);
332 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100333 struct intel_unpin_work *work;
334
335 spin_lock_irqsave(&dev->event_lock, flags);
336 work = crtc->unpin_work;
337 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800338 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100339 pipe, plane);
340 } else {
341 if (!work->pending) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800342 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100343 pipe, plane);
344 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800345 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100346 pipe, plane);
347 }
348 if (work->enable_stall_check)
349 seq_printf(m, "Stall check enabled, ");
350 else
351 seq_printf(m, "Stall check waiting for page flip ioctl, ");
352 seq_printf(m, "%d prepares\n", work->pending);
353
354 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000355 struct drm_i915_gem_object *obj = work->old_fb_obj;
356 if (obj)
357 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100358 }
359 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000360 struct drm_i915_gem_object *obj = work->pending_flip_obj;
361 if (obj)
362 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100363 }
364 }
365 spin_unlock_irqrestore(&dev->event_lock, flags);
366 }
367
368 return 0;
369}
370
Ben Gamari20172632009-02-17 20:08:50 -0500371static int i915_gem_request_info(struct seq_file *m, void *data)
372{
373 struct drm_info_node *node = (struct drm_info_node *) m->private;
374 struct drm_device *dev = node->minor->dev;
375 drm_i915_private_t *dev_priv = dev->dev_private;
376 struct drm_i915_gem_request *gem_request;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100377 int ret, count;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100378
379 ret = mutex_lock_interruptible(&dev->struct_mutex);
380 if (ret)
381 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500382
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100383 count = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000384 if (!list_empty(&dev_priv->ring[RCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100385 seq_printf(m, "Render requests:\n");
386 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000387 &dev_priv->ring[RCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100388 list) {
389 seq_printf(m, " %d @ %d\n",
390 gem_request->seqno,
391 (int) (jiffies - gem_request->emitted_jiffies));
392 }
393 count++;
394 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000395 if (!list_empty(&dev_priv->ring[VCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100396 seq_printf(m, "BSD requests:\n");
397 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000398 &dev_priv->ring[VCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100399 list) {
400 seq_printf(m, " %d @ %d\n",
401 gem_request->seqno,
402 (int) (jiffies - gem_request->emitted_jiffies));
403 }
404 count++;
405 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000406 if (!list_empty(&dev_priv->ring[BCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100407 seq_printf(m, "BLT requests:\n");
408 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000409 &dev_priv->ring[BCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100410 list) {
411 seq_printf(m, " %d @ %d\n",
412 gem_request->seqno,
413 (int) (jiffies - gem_request->emitted_jiffies));
414 }
415 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500416 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100417 mutex_unlock(&dev->struct_mutex);
418
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100419 if (count == 0)
420 seq_printf(m, "No requests\n");
421
Ben Gamari20172632009-02-17 20:08:50 -0500422 return 0;
423}
424
Chris Wilsonb2223492010-10-27 15:27:33 +0100425static void i915_ring_seqno_info(struct seq_file *m,
426 struct intel_ring_buffer *ring)
427{
428 if (ring->get_seqno) {
429 seq_printf(m, "Current sequence (%s): %d\n",
430 ring->name, ring->get_seqno(ring));
431 seq_printf(m, "Waiter sequence (%s): %d\n",
432 ring->name, ring->waiting_seqno);
433 seq_printf(m, "IRQ sequence (%s): %d\n",
434 ring->name, ring->irq_seqno);
435 }
436}
437
Ben Gamari20172632009-02-17 20:08:50 -0500438static int i915_gem_seqno_info(struct seq_file *m, void *data)
439{
440 struct drm_info_node *node = (struct drm_info_node *) m->private;
441 struct drm_device *dev = node->minor->dev;
442 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000443 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100444
445 ret = mutex_lock_interruptible(&dev->struct_mutex);
446 if (ret)
447 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500448
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000449 for (i = 0; i < I915_NUM_RINGS; i++)
450 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100451
452 mutex_unlock(&dev->struct_mutex);
453
Ben Gamari20172632009-02-17 20:08:50 -0500454 return 0;
455}
456
457
458static int i915_interrupt_info(struct seq_file *m, void *data)
459{
460 struct drm_info_node *node = (struct drm_info_node *) m->private;
461 struct drm_device *dev = node->minor->dev;
462 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800463 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100464
465 ret = mutex_lock_interruptible(&dev->struct_mutex);
466 if (ret)
467 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500468
Eric Anholtbad720f2009-10-22 16:11:14 -0700469 if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800470 seq_printf(m, "Interrupt enable: %08x\n",
471 I915_READ(IER));
472 seq_printf(m, "Interrupt identity: %08x\n",
473 I915_READ(IIR));
474 seq_printf(m, "Interrupt mask: %08x\n",
475 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800476 for_each_pipe(pipe)
477 seq_printf(m, "Pipe %c stat: %08x\n",
478 pipe_name(pipe),
479 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800480 } else {
481 seq_printf(m, "North Display Interrupt enable: %08x\n",
482 I915_READ(DEIER));
483 seq_printf(m, "North Display Interrupt identity: %08x\n",
484 I915_READ(DEIIR));
485 seq_printf(m, "North Display Interrupt mask: %08x\n",
486 I915_READ(DEIMR));
487 seq_printf(m, "South Display Interrupt enable: %08x\n",
488 I915_READ(SDEIER));
489 seq_printf(m, "South Display Interrupt identity: %08x\n",
490 I915_READ(SDEIIR));
491 seq_printf(m, "South Display Interrupt mask: %08x\n",
492 I915_READ(SDEIMR));
493 seq_printf(m, "Graphics Interrupt enable: %08x\n",
494 I915_READ(GTIER));
495 seq_printf(m, "Graphics Interrupt identity: %08x\n",
496 I915_READ(GTIIR));
497 seq_printf(m, "Graphics Interrupt mask: %08x\n",
498 I915_READ(GTIMR));
499 }
Ben Gamari20172632009-02-17 20:08:50 -0500500 seq_printf(m, "Interrupts received: %d\n",
501 atomic_read(&dev_priv->irq_received));
Chris Wilson9862e602011-01-04 22:22:17 +0000502 for (i = 0; i < I915_NUM_RINGS; i++) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700503 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilson9862e602011-01-04 22:22:17 +0000504 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
505 dev_priv->ring[i].name,
506 I915_READ_IMR(&dev_priv->ring[i]));
507 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000508 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilson9862e602011-01-04 22:22:17 +0000509 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100510 mutex_unlock(&dev->struct_mutex);
511
Ben Gamari20172632009-02-17 20:08:50 -0500512 return 0;
513}
514
Chris Wilsona6172a82009-02-11 14:26:38 +0000515static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
516{
517 struct drm_info_node *node = (struct drm_info_node *) m->private;
518 struct drm_device *dev = node->minor->dev;
519 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100520 int i, ret;
521
522 ret = mutex_lock_interruptible(&dev->struct_mutex);
523 if (ret)
524 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000525
526 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
527 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
528 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000529 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000530
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100531 seq_printf(m, "Fenced object[%2d] = ", i);
532 if (obj == NULL)
533 seq_printf(m, "unused");
534 else
Chris Wilson05394f32010-11-08 19:18:58 +0000535 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100536 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000537 }
538
Chris Wilson05394f32010-11-08 19:18:58 +0000539 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000540 return 0;
541}
542
Ben Gamari20172632009-02-17 20:08:50 -0500543static int i915_hws_info(struct seq_file *m, void *data)
544{
545 struct drm_info_node *node = (struct drm_info_node *) m->private;
546 struct drm_device *dev = node->minor->dev;
547 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100548 struct intel_ring_buffer *ring;
Chris Wilson311bd682011-01-13 19:06:50 +0000549 const volatile u32 __iomem *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100550 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500551
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000552 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilson311bd682011-01-13 19:06:50 +0000553 hws = (volatile u32 __iomem *)ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500554 if (hws == NULL)
555 return 0;
556
557 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
558 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
559 i * 4,
560 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
561 }
562 return 0;
563}
564
Chris Wilson5cdf5882010-09-27 15:51:07 +0100565static void i915_dump_object(struct seq_file *m,
566 struct io_mapping *mapping,
Chris Wilson05394f32010-11-08 19:18:58 +0000567 struct drm_i915_gem_object *obj)
Ben Gamari6911a9b2009-04-02 11:24:54 -0700568{
Chris Wilson5cdf5882010-09-27 15:51:07 +0100569 int page, page_count, i;
Ben Gamari6911a9b2009-04-02 11:24:54 -0700570
Chris Wilson05394f32010-11-08 19:18:58 +0000571 page_count = obj->base.size / PAGE_SIZE;
Ben Gamari6911a9b2009-04-02 11:24:54 -0700572 for (page = 0; page < page_count; page++) {
Chris Wilson5cdf5882010-09-27 15:51:07 +0100573 u32 *mem = io_mapping_map_wc(mapping,
Chris Wilson05394f32010-11-08 19:18:58 +0000574 obj->gtt_offset + page * PAGE_SIZE);
Ben Gamari6911a9b2009-04-02 11:24:54 -0700575 for (i = 0; i < PAGE_SIZE; i += 4)
576 seq_printf(m, "%08x : %08x\n", i, mem[i / 4]);
Chris Wilson5cdf5882010-09-27 15:51:07 +0100577 io_mapping_unmap(mem);
Ben Gamari6911a9b2009-04-02 11:24:54 -0700578 }
579}
580
581static int i915_batchbuffer_info(struct seq_file *m, void *data)
582{
583 struct drm_info_node *node = (struct drm_info_node *) m->private;
584 struct drm_device *dev = node->minor->dev;
585 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000586 struct drm_i915_gem_object *obj;
Ben Gamari6911a9b2009-04-02 11:24:54 -0700587 int ret;
588
Chris Wilsonde227ef2010-07-03 07:58:38 +0100589 ret = mutex_lock_interruptible(&dev->struct_mutex);
590 if (ret)
591 return ret;
Ben Gamari6911a9b2009-04-02 11:24:54 -0700592
Chris Wilson05394f32010-11-08 19:18:58 +0000593 list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
594 if (obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) {
595 seq_printf(m, "--- gtt_offset = 0x%08x\n", obj->gtt_offset);
596 i915_dump_object(m, dev_priv->mm.gtt_mapping, obj);
Ben Gamari6911a9b2009-04-02 11:24:54 -0700597 }
598 }
599
Chris Wilsonde227ef2010-07-03 07:58:38 +0100600 mutex_unlock(&dev->struct_mutex);
Ben Gamari6911a9b2009-04-02 11:24:54 -0700601 return 0;
602}
603
604static int i915_ringbuffer_data(struct seq_file *m, void *data)
605{
606 struct drm_info_node *node = (struct drm_info_node *) m->private;
607 struct drm_device *dev = node->minor->dev;
608 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100609 struct intel_ring_buffer *ring;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100610 int ret;
611
612 ret = mutex_lock_interruptible(&dev->struct_mutex);
613 if (ret)
614 return ret;
Ben Gamari6911a9b2009-04-02 11:24:54 -0700615
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000616 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilson05394f32010-11-08 19:18:58 +0000617 if (!ring->obj) {
Ben Gamari6911a9b2009-04-02 11:24:54 -0700618 seq_printf(m, "No ringbuffer setup\n");
Chris Wilsonde227ef2010-07-03 07:58:38 +0100619 } else {
Chris Wilson311bd682011-01-13 19:06:50 +0000620 const u8 __iomem *virt = ring->virtual_start;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100621 uint32_t off;
Ben Gamari6911a9b2009-04-02 11:24:54 -0700622
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100623 for (off = 0; off < ring->size; off += 4) {
Chris Wilsonde227ef2010-07-03 07:58:38 +0100624 uint32_t *ptr = (uint32_t *)(virt + off);
625 seq_printf(m, "%08x : %08x\n", off, *ptr);
626 }
Ben Gamari6911a9b2009-04-02 11:24:54 -0700627 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100628 mutex_unlock(&dev->struct_mutex);
Ben Gamari6911a9b2009-04-02 11:24:54 -0700629
630 return 0;
631}
632
633static int i915_ringbuffer_info(struct seq_file *m, void *data)
634{
635 struct drm_info_node *node = (struct drm_info_node *) m->private;
636 struct drm_device *dev = node->minor->dev;
637 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100638 struct intel_ring_buffer *ring;
Ben Gamari6911a9b2009-04-02 11:24:54 -0700639
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000640 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100641 if (ring->size == 0)
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000642 return 0;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100643
644 seq_printf(m, "Ring %s:\n", ring->name);
645 seq_printf(m, " Head : %08x\n", I915_READ_HEAD(ring) & HEAD_ADDR);
646 seq_printf(m, " Tail : %08x\n", I915_READ_TAIL(ring) & TAIL_ADDR);
647 seq_printf(m, " Size : %08x\n", ring->size);
648 seq_printf(m, " Active : %08x\n", intel_ring_get_active_head(ring));
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000649 seq_printf(m, " NOPID : %08x\n", I915_READ_NOPID(ring));
650 if (IS_GEN6(dev)) {
651 seq_printf(m, " Sync 0 : %08x\n", I915_READ_SYNC_0(ring));
652 seq_printf(m, " Sync 1 : %08x\n", I915_READ_SYNC_1(ring));
653 }
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100654 seq_printf(m, " Control : %08x\n", I915_READ_CTL(ring));
655 seq_printf(m, " Start : %08x\n", I915_READ_START(ring));
Ben Gamari6911a9b2009-04-02 11:24:54 -0700656
657 return 0;
658}
659
Chris Wilsone5c65262010-11-01 11:35:28 +0000660static const char *ring_str(int ring)
661{
662 switch (ring) {
Chris Wilson36850922010-11-23 08:49:38 +0000663 case RING_RENDER: return " render";
664 case RING_BSD: return " bsd";
665 case RING_BLT: return " blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000666 default: return "";
667 }
668}
669
Chris Wilson9df30792010-02-18 10:24:56 +0000670static const char *pin_flag(int pinned)
671{
672 if (pinned > 0)
673 return " P";
674 else if (pinned < 0)
675 return " p";
676 else
677 return "";
678}
679
680static const char *tiling_flag(int tiling)
681{
682 switch (tiling) {
683 default:
684 case I915_TILING_NONE: return "";
685 case I915_TILING_X: return " X";
686 case I915_TILING_Y: return " Y";
687 }
688}
689
690static const char *dirty_flag(int dirty)
691{
692 return dirty ? " dirty" : "";
693}
694
695static const char *purgeable_flag(int purgeable)
696{
697 return purgeable ? " purgeable" : "";
698}
699
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000700static void print_error_buffers(struct seq_file *m,
701 const char *name,
702 struct drm_i915_error_buffer *err,
703 int count)
704{
705 seq_printf(m, "%s [%d]:\n", name, count);
706
707 while (count--) {
Chris Wilson833bcb02011-01-12 12:14:13 +0000708 seq_printf(m, " %08x %8u %04x %04x %08x%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000709 err->gtt_offset,
710 err->size,
711 err->read_domains,
712 err->write_domain,
713 err->seqno,
714 pin_flag(err->pinned),
715 tiling_flag(err->tiling),
716 dirty_flag(err->dirty),
717 purgeable_flag(err->purgeable),
Chris Wilsona779e5a2011-01-09 21:07:49 +0000718 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700719 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000720
721 if (err->name)
722 seq_printf(m, " (name: %d)", err->name);
723 if (err->fence_reg != I915_FENCE_REG_NONE)
724 seq_printf(m, " (fence: %d)", err->fence_reg);
725
726 seq_printf(m, "\n");
727 err++;
728 }
729}
730
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700731static int i915_error_state(struct seq_file *m, void *unused)
732{
733 struct drm_info_node *node = (struct drm_info_node *) m->private;
734 struct drm_device *dev = node->minor->dev;
735 drm_i915_private_t *dev_priv = dev->dev_private;
736 struct drm_i915_error_state *error;
737 unsigned long flags;
Chris Wilson9df30792010-02-18 10:24:56 +0000738 int i, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700739
740 spin_lock_irqsave(&dev_priv->error_lock, flags);
741 if (!dev_priv->first_error) {
742 seq_printf(m, "no error state collected\n");
743 goto out;
744 }
745
746 error = dev_priv->first_error;
747
Jesse Barnes8a905232009-07-11 16:48:03 -0400748 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
749 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000750 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100751 seq_printf(m, "EIR: 0x%08x\n", error->eir);
752 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Chris Wilsonf4068392010-10-27 20:36:41 +0100753 if (INTEL_INFO(dev)->gen >= 6) {
754 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100755 seq_printf(m, "Blitter command stream:\n");
756 seq_printf(m, " ACTHD: 0x%08x\n", error->bcs_acthd);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100757 seq_printf(m, " IPEIR: 0x%08x\n", error->bcs_ipeir);
Chris Wilsone5c65262010-11-01 11:35:28 +0000758 seq_printf(m, " IPEHR: 0x%08x\n", error->bcs_ipehr);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100759 seq_printf(m, " INSTDONE: 0x%08x\n", error->bcs_instdone);
760 seq_printf(m, " seqno: 0x%08x\n", error->bcs_seqno);
Chris Wilsonadd354d2010-10-29 19:00:51 +0100761 seq_printf(m, "Video (BSD) command stream:\n");
762 seq_printf(m, " ACTHD: 0x%08x\n", error->vcs_acthd);
Chris Wilsonadd354d2010-10-29 19:00:51 +0100763 seq_printf(m, " IPEIR: 0x%08x\n", error->vcs_ipeir);
Chris Wilsone5c65262010-11-01 11:35:28 +0000764 seq_printf(m, " IPEHR: 0x%08x\n", error->vcs_ipehr);
Chris Wilsonadd354d2010-10-29 19:00:51 +0100765 seq_printf(m, " INSTDONE: 0x%08x\n", error->vcs_instdone);
766 seq_printf(m, " seqno: 0x%08x\n", error->vcs_seqno);
Chris Wilsonf4068392010-10-27 20:36:41 +0100767 }
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100768 seq_printf(m, "Render command stream:\n");
769 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd);
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700770 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir);
771 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr);
772 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100773 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700774 seq_printf(m, " INSTDONE1: 0x%08x\n", error->instdone1);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100775 seq_printf(m, " INSTPS: 0x%08x\n", error->instps);
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700776 }
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100777 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm);
778 seq_printf(m, " seqno: 0x%08x\n", error->seqno);
Chris Wilson9df30792010-02-18 10:24:56 +0000779
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100780 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100781 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
782
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000783 if (error->active_bo)
784 print_error_buffers(m, "Active",
785 error->active_bo,
786 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000787
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000788 if (error->pinned_bo)
789 print_error_buffers(m, "Pinned",
790 error->pinned_bo,
791 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000792
793 for (i = 0; i < ARRAY_SIZE(error->batchbuffer); i++) {
794 if (error->batchbuffer[i]) {
795 struct drm_i915_error_object *obj = error->batchbuffer[i];
796
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000797 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
798 dev_priv->ring[i].name,
799 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000800 offset = 0;
801 for (page = 0; page < obj->page_count; page++) {
802 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
803 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
804 offset += 4;
805 }
806 }
807 }
808 }
809
Chris Wilsone2f973d2011-01-27 19:15:11 +0000810 for (i = 0; i < ARRAY_SIZE(error->ringbuffer); i++) {
811 if (error->ringbuffer[i]) {
812 struct drm_i915_error_object *obj = error->ringbuffer[i];
813 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
814 dev_priv->ring[i].name,
815 obj->gtt_offset);
816 offset = 0;
817 for (page = 0; page < obj->page_count; page++) {
818 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
819 seq_printf(m, "%08x : %08x\n",
820 offset,
821 obj->pages[page][elt]);
822 offset += 4;
823 }
Chris Wilson9df30792010-02-18 10:24:56 +0000824 }
825 }
826 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700827
Chris Wilson6ef3d422010-08-04 20:26:07 +0100828 if (error->overlay)
829 intel_overlay_print_error_state(m, error->overlay);
830
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000831 if (error->display)
832 intel_display_print_error_state(m, dev, error->display);
833
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700834out:
835 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
836
837 return 0;
838}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700839
Jesse Barnesf97108d2010-01-29 11:27:07 -0800840static int i915_rstdby_delays(struct seq_file *m, void *unused)
841{
842 struct drm_info_node *node = (struct drm_info_node *) m->private;
843 struct drm_device *dev = node->minor->dev;
844 drm_i915_private_t *dev_priv = dev->dev_private;
845 u16 crstanddelay = I915_READ16(CRSTANDVID);
846
847 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
848
849 return 0;
850}
851
852static int i915_cur_delayinfo(struct seq_file *m, void *unused)
853{
854 struct drm_info_node *node = (struct drm_info_node *) m->private;
855 struct drm_device *dev = node->minor->dev;
856 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100857 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800858
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800859 if (IS_GEN5(dev)) {
860 u16 rgvswctl = I915_READ16(MEMSWCTL);
861 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
862
863 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
864 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
865 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
866 MEMSTAT_VID_SHIFT);
867 seq_printf(m, "Current P-state: %d\n",
868 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700869 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800870 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
871 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
872 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800873 u32 rpstat;
874 u32 rpupei, rpcurup, rpprevup;
875 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800876 int max_freq;
877
878 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100879 ret = mutex_lock_interruptible(&dev->struct_mutex);
880 if (ret)
881 return ret;
882
Ben Widawskyfcca7922011-04-25 11:23:07 -0700883 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800884
Jesse Barnesccab5c82011-01-18 15:49:25 -0800885 rpstat = I915_READ(GEN6_RPSTAT1);
886 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
887 rpcurup = I915_READ(GEN6_RP_CUR_UP);
888 rpprevup = I915_READ(GEN6_RP_PREV_UP);
889 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
890 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
891 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
892
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100893 gen6_gt_force_wake_put(dev_priv);
894 mutex_unlock(&dev->struct_mutex);
895
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800896 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800897 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800898 seq_printf(m, "Render p-state ratio: %d\n",
899 (gt_perf_status & 0xff00) >> 8);
900 seq_printf(m, "Render p-state VID: %d\n",
901 gt_perf_status & 0xff);
902 seq_printf(m, "Render p-state limit: %d\n",
903 rp_state_limits & 0xff);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800904 seq_printf(m, "CAGF: %dMHz\n", ((rpstat & GEN6_CAGF_MASK) >>
Jesse Barnese281fca2011-03-18 10:32:07 -0700905 GEN6_CAGF_SHIFT) * 50);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800906 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
907 GEN6_CURICONT_MASK);
908 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
909 GEN6_CURBSYTAVG_MASK);
910 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
911 GEN6_CURBSYTAVG_MASK);
912 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
913 GEN6_CURIAVG_MASK);
914 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
915 GEN6_CURBSYTAVG_MASK);
916 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
917 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800918
919 max_freq = (rp_state_cap & 0xff0000) >> 16;
920 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700921 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800922
923 max_freq = (rp_state_cap & 0xff00) >> 8;
924 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700925 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800926
927 max_freq = rp_state_cap & 0xff;
928 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700929 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800930 } else {
931 seq_printf(m, "no P-state info available\n");
932 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800933
934 return 0;
935}
936
937static int i915_delayfreq_table(struct seq_file *m, void *unused)
938{
939 struct drm_info_node *node = (struct drm_info_node *) m->private;
940 struct drm_device *dev = node->minor->dev;
941 drm_i915_private_t *dev_priv = dev->dev_private;
942 u32 delayfreq;
943 int i;
944
945 for (i = 0; i < 16; i++) {
946 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700947 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
948 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800949 }
950
951 return 0;
952}
953
954static inline int MAP_TO_MV(int map)
955{
956 return 1250 - (map * 25);
957}
958
959static int i915_inttoext_table(struct seq_file *m, void *unused)
960{
961 struct drm_info_node *node = (struct drm_info_node *) m->private;
962 struct drm_device *dev = node->minor->dev;
963 drm_i915_private_t *dev_priv = dev->dev_private;
964 u32 inttoext;
965 int i;
966
967 for (i = 1; i <= 32; i++) {
968 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
969 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
970 }
971
972 return 0;
973}
974
975static int i915_drpc_info(struct seq_file *m, void *unused)
976{
977 struct drm_info_node *node = (struct drm_info_node *) m->private;
978 struct drm_device *dev = node->minor->dev;
979 drm_i915_private_t *dev_priv = dev->dev_private;
980 u32 rgvmodectl = I915_READ(MEMMODECTL);
Jesse Barnes88271da2011-01-05 12:01:24 -0800981 u32 rstdbyctl = I915_READ(RSTDBYCTL);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700982 u16 crstandvid = I915_READ16(CRSTANDVID);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800983
984 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
985 "yes" : "no");
986 seq_printf(m, "Boost freq: %d\n",
987 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
988 MEMMODE_BOOST_FREQ_SHIFT);
989 seq_printf(m, "HW control enabled: %s\n",
990 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
991 seq_printf(m, "SW control enabled: %s\n",
992 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
993 seq_printf(m, "Gated voltage change: %s\n",
994 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
995 seq_printf(m, "Starting frequency: P%d\n",
996 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700997 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -0800998 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700999 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1000 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1001 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1002 seq_printf(m, "Render standby enabled: %s\n",
1003 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001004 seq_printf(m, "Current RS state: ");
1005 switch (rstdbyctl & RSX_STATUS_MASK) {
1006 case RSX_STATUS_ON:
1007 seq_printf(m, "on\n");
1008 break;
1009 case RSX_STATUS_RC1:
1010 seq_printf(m, "RC1\n");
1011 break;
1012 case RSX_STATUS_RC1E:
1013 seq_printf(m, "RC1E\n");
1014 break;
1015 case RSX_STATUS_RS1:
1016 seq_printf(m, "RS1\n");
1017 break;
1018 case RSX_STATUS_RS2:
1019 seq_printf(m, "RS2 (RC6)\n");
1020 break;
1021 case RSX_STATUS_RS3:
1022 seq_printf(m, "RC3 (RC6+)\n");
1023 break;
1024 default:
1025 seq_printf(m, "unknown\n");
1026 break;
1027 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001028
1029 return 0;
1030}
1031
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001032static int i915_fbc_status(struct seq_file *m, void *unused)
1033{
1034 struct drm_info_node *node = (struct drm_info_node *) m->private;
1035 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001036 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001037
Adam Jacksonee5382a2010-04-23 11:17:39 -04001038 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001039 seq_printf(m, "FBC unsupported on this chipset\n");
1040 return 0;
1041 }
1042
Adam Jacksonee5382a2010-04-23 11:17:39 -04001043 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001044 seq_printf(m, "FBC enabled\n");
1045 } else {
1046 seq_printf(m, "FBC disabled: ");
1047 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001048 case FBC_NO_OUTPUT:
1049 seq_printf(m, "no outputs");
1050 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001051 case FBC_STOLEN_TOO_SMALL:
1052 seq_printf(m, "not enough stolen memory");
1053 break;
1054 case FBC_UNSUPPORTED_MODE:
1055 seq_printf(m, "mode not supported");
1056 break;
1057 case FBC_MODE_TOO_LARGE:
1058 seq_printf(m, "mode too large");
1059 break;
1060 case FBC_BAD_PLANE:
1061 seq_printf(m, "FBC unsupported on plane");
1062 break;
1063 case FBC_NOT_TILED:
1064 seq_printf(m, "scanout buffer not tiled");
1065 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001066 case FBC_MULTIPLE_PIPES:
1067 seq_printf(m, "multiple pipes are enabled");
1068 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001069 case FBC_MODULE_PARAM:
1070 seq_printf(m, "disabled per module param (default off)");
1071 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001072 default:
1073 seq_printf(m, "unknown reason");
1074 }
1075 seq_printf(m, "\n");
1076 }
1077 return 0;
1078}
1079
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001080static int i915_sr_status(struct seq_file *m, void *unused)
1081{
1082 struct drm_info_node *node = (struct drm_info_node *) m->private;
1083 struct drm_device *dev = node->minor->dev;
1084 drm_i915_private_t *dev_priv = dev->dev_private;
1085 bool sr_enabled = false;
1086
Yuanhan Liu13982612010-12-15 15:42:31 +08001087 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001088 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001089 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001090 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1091 else if (IS_I915GM(dev))
1092 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1093 else if (IS_PINEVIEW(dev))
1094 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1095
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001096 seq_printf(m, "self-refresh: %s\n",
1097 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001098
1099 return 0;
1100}
1101
Jesse Barnes7648fa92010-05-20 14:28:11 -07001102static int i915_emon_status(struct seq_file *m, void *unused)
1103{
1104 struct drm_info_node *node = (struct drm_info_node *) m->private;
1105 struct drm_device *dev = node->minor->dev;
1106 drm_i915_private_t *dev_priv = dev->dev_private;
1107 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001108 int ret;
1109
1110 ret = mutex_lock_interruptible(&dev->struct_mutex);
1111 if (ret)
1112 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001113
1114 temp = i915_mch_val(dev_priv);
1115 chipset = i915_chipset_val(dev_priv);
1116 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001117 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001118
1119 seq_printf(m, "GMCH temp: %ld\n", temp);
1120 seq_printf(m, "Chipset power: %ld\n", chipset);
1121 seq_printf(m, "GFX power: %ld\n", gfx);
1122 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1123
1124 return 0;
1125}
1126
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001127static int i915_ring_freq_table(struct seq_file *m, void *unused)
1128{
1129 struct drm_info_node *node = (struct drm_info_node *) m->private;
1130 struct drm_device *dev = node->minor->dev;
1131 drm_i915_private_t *dev_priv = dev->dev_private;
1132 int ret;
1133 int gpu_freq, ia_freq;
1134
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001135 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001136 seq_printf(m, "unsupported on this chipset\n");
1137 return 0;
1138 }
1139
1140 ret = mutex_lock_interruptible(&dev->struct_mutex);
1141 if (ret)
1142 return ret;
1143
1144 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1145
1146 for (gpu_freq = dev_priv->min_delay; gpu_freq <= dev_priv->max_delay;
1147 gpu_freq++) {
1148 I915_WRITE(GEN6_PCODE_DATA, gpu_freq);
1149 I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY |
1150 GEN6_PCODE_READ_MIN_FREQ_TABLE);
1151 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) &
1152 GEN6_PCODE_READY) == 0, 10)) {
1153 DRM_ERROR("pcode read of freq table timed out\n");
1154 continue;
1155 }
1156 ia_freq = I915_READ(GEN6_PCODE_DATA);
1157 seq_printf(m, "%d\t\t%d\n", gpu_freq * 50, ia_freq * 100);
1158 }
1159
1160 mutex_unlock(&dev->struct_mutex);
1161
1162 return 0;
1163}
1164
Jesse Barnes7648fa92010-05-20 14:28:11 -07001165static int i915_gfxec(struct seq_file *m, void *unused)
1166{
1167 struct drm_info_node *node = (struct drm_info_node *) m->private;
1168 struct drm_device *dev = node->minor->dev;
1169 drm_i915_private_t *dev_priv = dev->dev_private;
1170
1171 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1172
1173 return 0;
1174}
1175
Chris Wilson44834a62010-08-19 16:09:23 +01001176static int i915_opregion(struct seq_file *m, void *unused)
1177{
1178 struct drm_info_node *node = (struct drm_info_node *) m->private;
1179 struct drm_device *dev = node->minor->dev;
1180 drm_i915_private_t *dev_priv = dev->dev_private;
1181 struct intel_opregion *opregion = &dev_priv->opregion;
1182 int ret;
1183
1184 ret = mutex_lock_interruptible(&dev->struct_mutex);
1185 if (ret)
1186 return ret;
1187
1188 if (opregion->header)
1189 seq_write(m, opregion->header, OPREGION_SIZE);
1190
1191 mutex_unlock(&dev->struct_mutex);
1192
1193 return 0;
1194}
1195
Chris Wilson37811fc2010-08-25 22:45:57 +01001196static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1197{
1198 struct drm_info_node *node = (struct drm_info_node *) m->private;
1199 struct drm_device *dev = node->minor->dev;
1200 drm_i915_private_t *dev_priv = dev->dev_private;
1201 struct intel_fbdev *ifbdev;
1202 struct intel_framebuffer *fb;
1203 int ret;
1204
1205 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1206 if (ret)
1207 return ret;
1208
1209 ifbdev = dev_priv->fbdev;
1210 fb = to_intel_framebuffer(ifbdev->helper.fb);
1211
1212 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1213 fb->base.width,
1214 fb->base.height,
1215 fb->base.depth,
1216 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001217 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001218 seq_printf(m, "\n");
1219
1220 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1221 if (&fb->base == ifbdev->helper.fb)
1222 continue;
1223
1224 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1225 fb->base.width,
1226 fb->base.height,
1227 fb->base.depth,
1228 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001229 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001230 seq_printf(m, "\n");
1231 }
1232
1233 mutex_unlock(&dev->mode_config.mutex);
1234
1235 return 0;
1236}
1237
Ben Widawskye76d3632011-03-19 18:14:29 -07001238static int i915_context_status(struct seq_file *m, void *unused)
1239{
1240 struct drm_info_node *node = (struct drm_info_node *) m->private;
1241 struct drm_device *dev = node->minor->dev;
1242 drm_i915_private_t *dev_priv = dev->dev_private;
1243 int ret;
1244
1245 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1246 if (ret)
1247 return ret;
1248
Ben Widawskydc501fb2011-06-29 11:41:51 -07001249 if (dev_priv->pwrctx) {
1250 seq_printf(m, "power context ");
1251 describe_obj(m, dev_priv->pwrctx);
1252 seq_printf(m, "\n");
1253 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001254
Ben Widawskydc501fb2011-06-29 11:41:51 -07001255 if (dev_priv->renderctx) {
1256 seq_printf(m, "render context ");
1257 describe_obj(m, dev_priv->renderctx);
1258 seq_printf(m, "\n");
1259 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001260
1261 mutex_unlock(&dev->mode_config.mutex);
1262
1263 return 0;
1264}
1265
Ben Widawsky6d794d42011-04-25 11:25:56 -07001266static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1267{
1268 struct drm_info_node *node = (struct drm_info_node *) m->private;
1269 struct drm_device *dev = node->minor->dev;
1270 struct drm_i915_private *dev_priv = dev->dev_private;
1271
1272 seq_printf(m, "forcewake count = %d\n",
1273 atomic_read(&dev_priv->forcewake_count));
1274
1275 return 0;
1276}
1277
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001278static int
1279i915_wedged_open(struct inode *inode,
1280 struct file *filp)
1281{
1282 filp->private_data = inode->i_private;
1283 return 0;
1284}
1285
1286static ssize_t
1287i915_wedged_read(struct file *filp,
1288 char __user *ubuf,
1289 size_t max,
1290 loff_t *ppos)
1291{
1292 struct drm_device *dev = filp->private_data;
1293 drm_i915_private_t *dev_priv = dev->dev_private;
1294 char buf[80];
1295 int len;
1296
Akshay Joshi0206e352011-08-16 15:34:10 -04001297 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001298 "wedged : %d\n",
1299 atomic_read(&dev_priv->mm.wedged));
1300
Akshay Joshi0206e352011-08-16 15:34:10 -04001301 if (len > sizeof(buf))
1302 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001303
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001304 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1305}
1306
1307static ssize_t
1308i915_wedged_write(struct file *filp,
1309 const char __user *ubuf,
1310 size_t cnt,
1311 loff_t *ppos)
1312{
1313 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001314 char buf[20];
1315 int val = 1;
1316
1317 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001318 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001319 return -EINVAL;
1320
1321 if (copy_from_user(buf, ubuf, cnt))
1322 return -EFAULT;
1323 buf[cnt] = 0;
1324
1325 val = simple_strtoul(buf, NULL, 0);
1326 }
1327
1328 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001329 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001330
1331 return cnt;
1332}
1333
1334static const struct file_operations i915_wedged_fops = {
1335 .owner = THIS_MODULE,
1336 .open = i915_wedged_open,
1337 .read = i915_wedged_read,
1338 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001339 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001340};
1341
Jesse Barnes358733e2011-07-27 11:53:01 -07001342static int
1343i915_max_freq_open(struct inode *inode,
1344 struct file *filp)
1345{
1346 filp->private_data = inode->i_private;
1347 return 0;
1348}
1349
1350static ssize_t
1351i915_max_freq_read(struct file *filp,
1352 char __user *ubuf,
1353 size_t max,
1354 loff_t *ppos)
1355{
1356 struct drm_device *dev = filp->private_data;
1357 drm_i915_private_t *dev_priv = dev->dev_private;
1358 char buf[80];
1359 int len;
1360
Akshay Joshi0206e352011-08-16 15:34:10 -04001361 len = snprintf(buf, sizeof(buf),
Jesse Barnes358733e2011-07-27 11:53:01 -07001362 "max freq: %d\n", dev_priv->max_delay * 50);
1363
Akshay Joshi0206e352011-08-16 15:34:10 -04001364 if (len > sizeof(buf))
1365 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001366
1367 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1368}
1369
1370static ssize_t
1371i915_max_freq_write(struct file *filp,
1372 const char __user *ubuf,
1373 size_t cnt,
1374 loff_t *ppos)
1375{
1376 struct drm_device *dev = filp->private_data;
1377 struct drm_i915_private *dev_priv = dev->dev_private;
1378 char buf[20];
1379 int val = 1;
1380
1381 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001382 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001383 return -EINVAL;
1384
1385 if (copy_from_user(buf, ubuf, cnt))
1386 return -EFAULT;
1387 buf[cnt] = 0;
1388
1389 val = simple_strtoul(buf, NULL, 0);
1390 }
1391
1392 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1393
1394 /*
1395 * Turbo will still be enabled, but won't go above the set value.
1396 */
1397 dev_priv->max_delay = val / 50;
1398
1399 gen6_set_rps(dev, val / 50);
1400
1401 return cnt;
1402}
1403
1404static const struct file_operations i915_max_freq_fops = {
1405 .owner = THIS_MODULE,
1406 .open = i915_max_freq_open,
1407 .read = i915_max_freq_read,
1408 .write = i915_max_freq_write,
1409 .llseek = default_llseek,
1410};
1411
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001412static int
1413i915_cache_sharing_open(struct inode *inode,
1414 struct file *filp)
1415{
1416 filp->private_data = inode->i_private;
1417 return 0;
1418}
1419
1420static ssize_t
1421i915_cache_sharing_read(struct file *filp,
1422 char __user *ubuf,
1423 size_t max,
1424 loff_t *ppos)
1425{
1426 struct drm_device *dev = filp->private_data;
1427 drm_i915_private_t *dev_priv = dev->dev_private;
1428 char buf[80];
1429 u32 snpcr;
1430 int len;
1431
1432 mutex_lock(&dev_priv->dev->struct_mutex);
1433 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1434 mutex_unlock(&dev_priv->dev->struct_mutex);
1435
Akshay Joshi0206e352011-08-16 15:34:10 -04001436 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001437 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
1438 GEN6_MBC_SNPCR_SHIFT);
1439
Akshay Joshi0206e352011-08-16 15:34:10 -04001440 if (len > sizeof(buf))
1441 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001442
1443 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1444}
1445
1446static ssize_t
1447i915_cache_sharing_write(struct file *filp,
1448 const char __user *ubuf,
1449 size_t cnt,
1450 loff_t *ppos)
1451{
1452 struct drm_device *dev = filp->private_data;
1453 struct drm_i915_private *dev_priv = dev->dev_private;
1454 char buf[20];
1455 u32 snpcr;
1456 int val = 1;
1457
1458 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001459 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001460 return -EINVAL;
1461
1462 if (copy_from_user(buf, ubuf, cnt))
1463 return -EFAULT;
1464 buf[cnt] = 0;
1465
1466 val = simple_strtoul(buf, NULL, 0);
1467 }
1468
1469 if (val < 0 || val > 3)
1470 return -EINVAL;
1471
1472 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
1473
1474 /* Update the cache sharing policy here as well */
1475 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1476 snpcr &= ~GEN6_MBC_SNPCR_MASK;
1477 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
1478 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
1479
1480 return cnt;
1481}
1482
1483static const struct file_operations i915_cache_sharing_fops = {
1484 .owner = THIS_MODULE,
1485 .open = i915_cache_sharing_open,
1486 .read = i915_cache_sharing_read,
1487 .write = i915_cache_sharing_write,
1488 .llseek = default_llseek,
1489};
1490
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001491/* As the drm_debugfs_init() routines are called before dev->dev_private is
1492 * allocated we need to hook into the minor for release. */
1493static int
1494drm_add_fake_info_node(struct drm_minor *minor,
1495 struct dentry *ent,
1496 const void *key)
1497{
1498 struct drm_info_node *node;
1499
1500 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
1501 if (node == NULL) {
1502 debugfs_remove(ent);
1503 return -ENOMEM;
1504 }
1505
1506 node->minor = minor;
1507 node->dent = ent;
1508 node->info_ent = (void *) key;
1509 list_add(&node->list, &minor->debugfs_nodes.list);
1510
1511 return 0;
1512}
1513
1514static int i915_wedged_create(struct dentry *root, struct drm_minor *minor)
1515{
1516 struct drm_device *dev = minor->dev;
1517 struct dentry *ent;
1518
1519 ent = debugfs_create_file("i915_wedged",
1520 S_IRUGO | S_IWUSR,
1521 root, dev,
1522 &i915_wedged_fops);
1523 if (IS_ERR(ent))
1524 return PTR_ERR(ent);
1525
1526 return drm_add_fake_info_node(minor, ent, &i915_wedged_fops);
1527}
Ben Gamari9e3a6d12009-07-01 22:26:53 -04001528
Ben Widawsky6d794d42011-04-25 11:25:56 -07001529static int i915_forcewake_open(struct inode *inode, struct file *file)
1530{
1531 struct drm_device *dev = inode->i_private;
1532 struct drm_i915_private *dev_priv = dev->dev_private;
1533 int ret;
1534
1535 if (!IS_GEN6(dev))
1536 return 0;
1537
1538 ret = mutex_lock_interruptible(&dev->struct_mutex);
1539 if (ret)
1540 return ret;
1541 gen6_gt_force_wake_get(dev_priv);
1542 mutex_unlock(&dev->struct_mutex);
1543
1544 return 0;
1545}
1546
1547int i915_forcewake_release(struct inode *inode, struct file *file)
1548{
1549 struct drm_device *dev = inode->i_private;
1550 struct drm_i915_private *dev_priv = dev->dev_private;
1551
1552 if (!IS_GEN6(dev))
1553 return 0;
1554
1555 /*
1556 * It's bad that we can potentially hang userspace if struct_mutex gets
1557 * forever stuck. However, if we cannot acquire this lock it means that
1558 * almost certainly the driver has hung, is not unload-able. Therefore
1559 * hanging here is probably a minor inconvenience not to be seen my
1560 * almost every user.
1561 */
1562 mutex_lock(&dev->struct_mutex);
1563 gen6_gt_force_wake_put(dev_priv);
1564 mutex_unlock(&dev->struct_mutex);
1565
1566 return 0;
1567}
1568
1569static const struct file_operations i915_forcewake_fops = {
1570 .owner = THIS_MODULE,
1571 .open = i915_forcewake_open,
1572 .release = i915_forcewake_release,
1573};
1574
1575static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
1576{
1577 struct drm_device *dev = minor->dev;
1578 struct dentry *ent;
1579
1580 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07001581 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07001582 root, dev,
1583 &i915_forcewake_fops);
1584 if (IS_ERR(ent))
1585 return PTR_ERR(ent);
1586
Ben Widawsky8eb57292011-05-11 15:10:58 -07001587 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001588}
1589
Jesse Barnes358733e2011-07-27 11:53:01 -07001590static int i915_max_freq_create(struct dentry *root, struct drm_minor *minor)
1591{
1592 struct drm_device *dev = minor->dev;
1593 struct dentry *ent;
1594
1595 ent = debugfs_create_file("i915_max_freq",
1596 S_IRUGO | S_IWUSR,
1597 root, dev,
1598 &i915_max_freq_fops);
1599 if (IS_ERR(ent))
1600 return PTR_ERR(ent);
1601
1602 return drm_add_fake_info_node(minor, ent, &i915_max_freq_fops);
1603}
1604
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001605static int i915_cache_sharing_create(struct dentry *root, struct drm_minor *minor)
1606{
1607 struct drm_device *dev = minor->dev;
1608 struct dentry *ent;
1609
1610 ent = debugfs_create_file("i915_cache_sharing",
1611 S_IRUGO | S_IWUSR,
1612 root, dev,
1613 &i915_cache_sharing_fops);
1614 if (IS_ERR(ent))
1615 return PTR_ERR(ent);
1616
1617 return drm_add_fake_info_node(minor, ent, &i915_cache_sharing_fops);
1618}
1619
Ben Gamari27c202a2009-07-01 22:26:52 -04001620static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00001621 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01001622 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00001623 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Ben Gamari433e12f2009-02-17 20:08:51 -05001624 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
1625 {"i915_gem_flushing", i915_gem_object_list_info, 0, (void *) FLUSHING_LIST},
1626 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilsonf13d3f72010-09-20 17:36:15 +01001627 {"i915_gem_pinned", i915_gem_object_list_info, 0, (void *) PINNED_LIST},
Chris Wilsond21d5972010-09-26 11:19:33 +01001628 {"i915_gem_deferred_free", i915_gem_object_list_info, 0, (void *) DEFERRED_FREE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001629 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05001630 {"i915_gem_request", i915_gem_request_info, 0},
1631 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00001632 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05001633 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001634 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
1635 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
1636 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
1637 {"i915_ringbuffer_data", i915_ringbuffer_data, 0, (void *)RCS},
1638 {"i915_ringbuffer_info", i915_ringbuffer_info, 0, (void *)RCS},
1639 {"i915_bsd_ringbuffer_data", i915_ringbuffer_data, 0, (void *)VCS},
1640 {"i915_bsd_ringbuffer_info", i915_ringbuffer_info, 0, (void *)VCS},
1641 {"i915_blt_ringbuffer_data", i915_ringbuffer_data, 0, (void *)BCS},
1642 {"i915_blt_ringbuffer_info", i915_ringbuffer_info, 0, (void *)BCS},
Ben Gamari6911a9b2009-04-02 11:24:54 -07001643 {"i915_batchbuffers", i915_batchbuffer_info, 0},
Jesse Barnes63eeaf32009-06-18 16:56:52 -07001644 {"i915_error_state", i915_error_state, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08001645 {"i915_rstdby_delays", i915_rstdby_delays, 0},
1646 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
1647 {"i915_delayfreq_table", i915_delayfreq_table, 0},
1648 {"i915_inttoext_table", i915_inttoext_table, 0},
1649 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07001650 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001651 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07001652 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001653 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001654 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01001655 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01001656 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07001657 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07001658 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05001659};
Ben Gamari27c202a2009-07-01 22:26:52 -04001660#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05001661
Ben Gamari27c202a2009-07-01 22:26:52 -04001662int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05001663{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001664 int ret;
1665
1666 ret = i915_wedged_create(minor->debugfs_root, minor);
1667 if (ret)
1668 return ret;
1669
Ben Widawsky6d794d42011-04-25 11:25:56 -07001670 ret = i915_forcewake_create(minor->debugfs_root, minor);
1671 if (ret)
1672 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001673 ret = i915_max_freq_create(minor->debugfs_root, minor);
1674 if (ret)
1675 return ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001676 ret = i915_cache_sharing_create(minor->debugfs_root, minor);
1677 if (ret)
1678 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001679
Ben Gamari27c202a2009-07-01 22:26:52 -04001680 return drm_debugfs_create_files(i915_debugfs_list,
1681 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05001682 minor->debugfs_root, minor);
1683}
1684
Ben Gamari27c202a2009-07-01 22:26:52 -04001685void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05001686{
Ben Gamari27c202a2009-07-01 22:26:52 -04001687 drm_debugfs_remove_files(i915_debugfs_list,
1688 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001689 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
1690 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05001691 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
1692 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07001693 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
1694 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001695 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
1696 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05001697}
1698
1699#endif /* CONFIG_DEBUG_FS */