blob: 54a10667fe82b9f62d34426e2be93d0d1bb990c1 [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);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030065 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Chris Wilson70d39fe2010-08-25 16:03:34 +010066#define B(x) seq_printf(m, #x ": %s\n", yesno(info->x))
67 B(is_mobile);
Chris Wilson70d39fe2010-08-25 16:03:34 +010068 B(is_i85x);
69 B(is_i915g);
Chris Wilson70d39fe2010-08-25 16:03:34 +010070 B(is_i945gm);
Chris Wilson70d39fe2010-08-25 16:03:34 +010071 B(is_g33);
72 B(need_gfx_hws);
73 B(is_g4x);
74 B(is_pineview);
75 B(is_broadwater);
76 B(is_crestline);
Chris Wilson70d39fe2010-08-25 16:03:34 +010077 B(has_fbc);
Chris Wilson70d39fe2010-08-25 16:03:34 +010078 B(has_pipe_cxsr);
79 B(has_hotplug);
80 B(cursor_needs_physical);
81 B(has_overlay);
82 B(overlay_needs_physical);
Chris Wilsona6c45cf2010-09-17 00:32:17 +010083 B(supports_tv);
Chris Wilson549f7362010-10-19 11:19:32 +010084 B(has_bsd_ring);
85 B(has_blt_ring);
Eugeni Dodonov3d29b842012-01-17 14:43:53 -020086 B(has_llc);
Chris Wilson70d39fe2010-08-25 16:03:34 +010087#undef B
88
89 return 0;
90}
Ben Gamari433e12f2009-02-17 20:08:51 -050091
Chris Wilson05394f32010-11-08 19:18:58 +000092static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000093{
Chris Wilson05394f32010-11-08 19:18:58 +000094 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000095 return "P";
Chris Wilson05394f32010-11-08 19:18:58 +000096 else if (obj->pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000097 return "p";
98 else
99 return " ";
100}
101
Chris Wilson05394f32010-11-08 19:18:58 +0000102static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000103{
Akshay Joshi0206e352011-08-16 15:34:10 -0400104 switch (obj->tiling_mode) {
105 default:
106 case I915_TILING_NONE: return " ";
107 case I915_TILING_X: return "X";
108 case I915_TILING_Y: return "Y";
109 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000110}
111
Chris Wilson93dfb402011-03-29 16:59:50 -0700112static const char *cache_level_str(int type)
Chris Wilson08c18322011-01-10 00:00:24 +0000113{
114 switch (type) {
Chris Wilson93dfb402011-03-29 16:59:50 -0700115 case I915_CACHE_NONE: return " uncached";
116 case I915_CACHE_LLC: return " snooped (LLC)";
117 case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
Chris Wilson08c18322011-01-10 00:00:24 +0000118 default: return "";
119 }
120}
121
Chris Wilson37811fc2010-08-25 22:45:57 +0100122static void
123describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
124{
Eric Anholta05a5862011-12-20 08:54:15 -0800125 seq_printf(m, "%p: %s%s %8zdKiB %04x %04x %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100126 &obj->base,
127 get_pin_flag(obj),
128 get_tiling_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800129 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100130 obj->base.read_domains,
131 obj->base.write_domain,
132 obj->last_rendering_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000133 obj->last_fenced_seqno,
Chris Wilson93dfb402011-03-29 16:59:50 -0700134 cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100135 obj->dirty ? " dirty" : "",
136 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
137 if (obj->base.name)
138 seq_printf(m, " (name: %d)", obj->base.name);
139 if (obj->fence_reg != I915_FENCE_REG_NONE)
140 seq_printf(m, " (fence: %d)", obj->fence_reg);
141 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100142 seq_printf(m, " (gtt offset: %08x, size: %08x)",
143 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilson6299f992010-11-24 12:23:44 +0000144 if (obj->pin_mappable || obj->fault_mappable) {
145 char s[3], *t = s;
146 if (obj->pin_mappable)
147 *t++ = 'p';
148 if (obj->fault_mappable)
149 *t++ = 'f';
150 *t = '\0';
151 seq_printf(m, " (%s mappable)", s);
152 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100153 if (obj->ring != NULL)
154 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100155}
156
Ben Gamari433e12f2009-02-17 20:08:51 -0500157static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500158{
159 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500160 uintptr_t list = (uintptr_t) node->info_ent->data;
161 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500162 struct drm_device *dev = node->minor->dev;
163 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000164 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100165 size_t total_obj_size, total_gtt_size;
166 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100167
168 ret = mutex_lock_interruptible(&dev->struct_mutex);
169 if (ret)
170 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500171
Ben Gamari433e12f2009-02-17 20:08:51 -0500172 switch (list) {
173 case ACTIVE_LIST:
174 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100175 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500176 break;
177 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400178 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500179 head = &dev_priv->mm.inactive_list;
180 break;
Chris Wilsonf13d3f72010-09-20 17:36:15 +0100181 case PINNED_LIST:
182 seq_printf(m, "Pinned:\n");
183 head = &dev_priv->mm.pinned_list;
184 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500185 case FLUSHING_LIST:
186 seq_printf(m, "Flushing:\n");
187 head = &dev_priv->mm.flushing_list;
188 break;
Chris Wilsond21d5972010-09-26 11:19:33 +0100189 case DEFERRED_FREE_LIST:
190 seq_printf(m, "Deferred free:\n");
191 head = &dev_priv->mm.deferred_free_list;
192 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500193 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100194 mutex_unlock(&dev->struct_mutex);
195 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500196 }
197
Chris Wilson8f2480f2010-09-26 11:44:19 +0100198 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000199 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100200 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000201 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800202 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000203 total_obj_size += obj->base.size;
204 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100205 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500206 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100207 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700208
Chris Wilson8f2480f2010-09-26 11:44:19 +0100209 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
210 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500211 return 0;
212}
213
Chris Wilson6299f992010-11-24 12:23:44 +0000214#define count_objects(list, member) do { \
215 list_for_each_entry(obj, list, member) { \
216 size += obj->gtt_space->size; \
217 ++count; \
218 if (obj->map_and_fenceable) { \
219 mappable_size += obj->gtt_space->size; \
220 ++mappable_count; \
221 } \
222 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400223} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000224
Chris Wilson73aa8082010-09-30 11:46:12 +0100225static int i915_gem_object_info(struct seq_file *m, void* data)
226{
227 struct drm_info_node *node = (struct drm_info_node *) m->private;
228 struct drm_device *dev = node->minor->dev;
229 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson6299f992010-11-24 12:23:44 +0000230 u32 count, mappable_count;
231 size_t size, mappable_size;
232 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100233 int ret;
234
235 ret = mutex_lock_interruptible(&dev->struct_mutex);
236 if (ret)
237 return ret;
238
Chris Wilson6299f992010-11-24 12:23:44 +0000239 seq_printf(m, "%u objects, %zu bytes\n",
240 dev_priv->mm.object_count,
241 dev_priv->mm.object_memory);
242
243 size = count = mappable_size = mappable_count = 0;
244 count_objects(&dev_priv->mm.gtt_list, gtt_list);
245 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
246 count, mappable_count, size, mappable_size);
247
248 size = count = mappable_size = mappable_count = 0;
249 count_objects(&dev_priv->mm.active_list, mm_list);
250 count_objects(&dev_priv->mm.flushing_list, mm_list);
251 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
252 count, mappable_count, size, mappable_size);
253
254 size = count = mappable_size = mappable_count = 0;
255 count_objects(&dev_priv->mm.pinned_list, mm_list);
256 seq_printf(m, " %u [%u] pinned objects, %zu [%zu] bytes\n",
257 count, mappable_count, size, mappable_size);
258
259 size = count = mappable_size = mappable_count = 0;
260 count_objects(&dev_priv->mm.inactive_list, mm_list);
261 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
262 count, mappable_count, size, mappable_size);
263
264 size = count = mappable_size = mappable_count = 0;
265 count_objects(&dev_priv->mm.deferred_free_list, mm_list);
266 seq_printf(m, " %u [%u] freed objects, %zu [%zu] bytes\n",
267 count, mappable_count, size, mappable_size);
268
269 size = count = mappable_size = mappable_count = 0;
270 list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {
271 if (obj->fault_mappable) {
272 size += obj->gtt_space->size;
273 ++count;
274 }
275 if (obj->pin_mappable) {
276 mappable_size += obj->gtt_space->size;
277 ++mappable_count;
278 }
279 }
280 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
281 mappable_count, mappable_size);
282 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
283 count, size);
284
285 seq_printf(m, "%zu [%zu] gtt total\n",
286 dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
Chris Wilson73aa8082010-09-30 11:46:12 +0100287
288 mutex_unlock(&dev->struct_mutex);
289
290 return 0;
291}
292
Chris Wilson08c18322011-01-10 00:00:24 +0000293static int i915_gem_gtt_info(struct seq_file *m, void* data)
294{
295 struct drm_info_node *node = (struct drm_info_node *) m->private;
296 struct drm_device *dev = node->minor->dev;
297 struct drm_i915_private *dev_priv = dev->dev_private;
298 struct drm_i915_gem_object *obj;
299 size_t total_obj_size, total_gtt_size;
300 int count, ret;
301
302 ret = mutex_lock_interruptible(&dev->struct_mutex);
303 if (ret)
304 return ret;
305
306 total_obj_size = total_gtt_size = count = 0;
307 list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {
308 seq_printf(m, " ");
309 describe_obj(m, obj);
310 seq_printf(m, "\n");
311 total_obj_size += obj->base.size;
312 total_gtt_size += obj->gtt_space->size;
313 count++;
314 }
315
316 mutex_unlock(&dev->struct_mutex);
317
318 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
319 count, total_obj_size, total_gtt_size);
320
321 return 0;
322}
323
Chris Wilson73aa8082010-09-30 11:46:12 +0100324
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100325static int i915_gem_pageflip_info(struct seq_file *m, void *data)
326{
327 struct drm_info_node *node = (struct drm_info_node *) m->private;
328 struct drm_device *dev = node->minor->dev;
329 unsigned long flags;
330 struct intel_crtc *crtc;
331
332 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800333 const char pipe = pipe_name(crtc->pipe);
334 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100335 struct intel_unpin_work *work;
336
337 spin_lock_irqsave(&dev->event_lock, flags);
338 work = crtc->unpin_work;
339 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800340 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100341 pipe, plane);
342 } else {
343 if (!work->pending) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800344 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100345 pipe, plane);
346 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800347 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100348 pipe, plane);
349 }
350 if (work->enable_stall_check)
351 seq_printf(m, "Stall check enabled, ");
352 else
353 seq_printf(m, "Stall check waiting for page flip ioctl, ");
354 seq_printf(m, "%d prepares\n", work->pending);
355
356 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000357 struct drm_i915_gem_object *obj = work->old_fb_obj;
358 if (obj)
359 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100360 }
361 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000362 struct drm_i915_gem_object *obj = work->pending_flip_obj;
363 if (obj)
364 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100365 }
366 }
367 spin_unlock_irqrestore(&dev->event_lock, flags);
368 }
369
370 return 0;
371}
372
Ben Gamari20172632009-02-17 20:08:50 -0500373static int i915_gem_request_info(struct seq_file *m, void *data)
374{
375 struct drm_info_node *node = (struct drm_info_node *) m->private;
376 struct drm_device *dev = node->minor->dev;
377 drm_i915_private_t *dev_priv = dev->dev_private;
378 struct drm_i915_gem_request *gem_request;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100379 int ret, count;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100380
381 ret = mutex_lock_interruptible(&dev->struct_mutex);
382 if (ret)
383 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500384
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100385 count = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000386 if (!list_empty(&dev_priv->ring[RCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100387 seq_printf(m, "Render requests:\n");
388 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000389 &dev_priv->ring[RCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100390 list) {
391 seq_printf(m, " %d @ %d\n",
392 gem_request->seqno,
393 (int) (jiffies - gem_request->emitted_jiffies));
394 }
395 count++;
396 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000397 if (!list_empty(&dev_priv->ring[VCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100398 seq_printf(m, "BSD requests:\n");
399 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000400 &dev_priv->ring[VCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100401 list) {
402 seq_printf(m, " %d @ %d\n",
403 gem_request->seqno,
404 (int) (jiffies - gem_request->emitted_jiffies));
405 }
406 count++;
407 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000408 if (!list_empty(&dev_priv->ring[BCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100409 seq_printf(m, "BLT requests:\n");
410 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000411 &dev_priv->ring[BCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100412 list) {
413 seq_printf(m, " %d @ %d\n",
414 gem_request->seqno,
415 (int) (jiffies - gem_request->emitted_jiffies));
416 }
417 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500418 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100419 mutex_unlock(&dev->struct_mutex);
420
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100421 if (count == 0)
422 seq_printf(m, "No requests\n");
423
Ben Gamari20172632009-02-17 20:08:50 -0500424 return 0;
425}
426
Chris Wilsonb2223492010-10-27 15:27:33 +0100427static void i915_ring_seqno_info(struct seq_file *m,
428 struct intel_ring_buffer *ring)
429{
430 if (ring->get_seqno) {
431 seq_printf(m, "Current sequence (%s): %d\n",
432 ring->name, ring->get_seqno(ring));
433 seq_printf(m, "Waiter sequence (%s): %d\n",
434 ring->name, ring->waiting_seqno);
435 seq_printf(m, "IRQ sequence (%s): %d\n",
436 ring->name, ring->irq_seqno);
437 }
438}
439
Ben Gamari20172632009-02-17 20:08:50 -0500440static int i915_gem_seqno_info(struct seq_file *m, void *data)
441{
442 struct drm_info_node *node = (struct drm_info_node *) m->private;
443 struct drm_device *dev = node->minor->dev;
444 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000445 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100446
447 ret = mutex_lock_interruptible(&dev->struct_mutex);
448 if (ret)
449 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500450
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000451 for (i = 0; i < I915_NUM_RINGS; i++)
452 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100453
454 mutex_unlock(&dev->struct_mutex);
455
Ben Gamari20172632009-02-17 20:08:50 -0500456 return 0;
457}
458
459
460static int i915_interrupt_info(struct seq_file *m, void *data)
461{
462 struct drm_info_node *node = (struct drm_info_node *) m->private;
463 struct drm_device *dev = node->minor->dev;
464 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800465 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100466
467 ret = mutex_lock_interruptible(&dev->struct_mutex);
468 if (ret)
469 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500470
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700471 if (IS_VALLEYVIEW(dev)) {
472 seq_printf(m, "Display IER:\t%08x\n",
473 I915_READ(VLV_IER));
474 seq_printf(m, "Display IIR:\t%08x\n",
475 I915_READ(VLV_IIR));
476 seq_printf(m, "Display IIR_RW:\t%08x\n",
477 I915_READ(VLV_IIR_RW));
478 seq_printf(m, "Display IMR:\t%08x\n",
479 I915_READ(VLV_IMR));
480 for_each_pipe(pipe)
481 seq_printf(m, "Pipe %c stat:\t%08x\n",
482 pipe_name(pipe),
483 I915_READ(PIPESTAT(pipe)));
484
485 seq_printf(m, "Master IER:\t%08x\n",
486 I915_READ(VLV_MASTER_IER));
487
488 seq_printf(m, "Render IER:\t%08x\n",
489 I915_READ(GTIER));
490 seq_printf(m, "Render IIR:\t%08x\n",
491 I915_READ(GTIIR));
492 seq_printf(m, "Render IMR:\t%08x\n",
493 I915_READ(GTIMR));
494
495 seq_printf(m, "PM IER:\t\t%08x\n",
496 I915_READ(GEN6_PMIER));
497 seq_printf(m, "PM IIR:\t\t%08x\n",
498 I915_READ(GEN6_PMIIR));
499 seq_printf(m, "PM IMR:\t\t%08x\n",
500 I915_READ(GEN6_PMIMR));
501
502 seq_printf(m, "Port hotplug:\t%08x\n",
503 I915_READ(PORT_HOTPLUG_EN));
504 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
505 I915_READ(VLV_DPFLIPSTAT));
506 seq_printf(m, "DPINVGTT:\t%08x\n",
507 I915_READ(DPINVGTT));
508
509 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800510 seq_printf(m, "Interrupt enable: %08x\n",
511 I915_READ(IER));
512 seq_printf(m, "Interrupt identity: %08x\n",
513 I915_READ(IIR));
514 seq_printf(m, "Interrupt mask: %08x\n",
515 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800516 for_each_pipe(pipe)
517 seq_printf(m, "Pipe %c stat: %08x\n",
518 pipe_name(pipe),
519 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800520 } else {
521 seq_printf(m, "North Display Interrupt enable: %08x\n",
522 I915_READ(DEIER));
523 seq_printf(m, "North Display Interrupt identity: %08x\n",
524 I915_READ(DEIIR));
525 seq_printf(m, "North Display Interrupt mask: %08x\n",
526 I915_READ(DEIMR));
527 seq_printf(m, "South Display Interrupt enable: %08x\n",
528 I915_READ(SDEIER));
529 seq_printf(m, "South Display Interrupt identity: %08x\n",
530 I915_READ(SDEIIR));
531 seq_printf(m, "South Display Interrupt mask: %08x\n",
532 I915_READ(SDEIMR));
533 seq_printf(m, "Graphics Interrupt enable: %08x\n",
534 I915_READ(GTIER));
535 seq_printf(m, "Graphics Interrupt identity: %08x\n",
536 I915_READ(GTIIR));
537 seq_printf(m, "Graphics Interrupt mask: %08x\n",
538 I915_READ(GTIMR));
539 }
Ben Gamari20172632009-02-17 20:08:50 -0500540 seq_printf(m, "Interrupts received: %d\n",
541 atomic_read(&dev_priv->irq_received));
Chris Wilson9862e602011-01-04 22:22:17 +0000542 for (i = 0; i < I915_NUM_RINGS; i++) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700543 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilson9862e602011-01-04 22:22:17 +0000544 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
545 dev_priv->ring[i].name,
546 I915_READ_IMR(&dev_priv->ring[i]));
547 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000548 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilson9862e602011-01-04 22:22:17 +0000549 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100550 mutex_unlock(&dev->struct_mutex);
551
Ben Gamari20172632009-02-17 20:08:50 -0500552 return 0;
553}
554
Chris Wilsona6172a82009-02-11 14:26:38 +0000555static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
556{
557 struct drm_info_node *node = (struct drm_info_node *) m->private;
558 struct drm_device *dev = node->minor->dev;
559 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100560 int i, ret;
561
562 ret = mutex_lock_interruptible(&dev->struct_mutex);
563 if (ret)
564 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000565
566 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
567 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
568 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000569 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000570
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100571 seq_printf(m, "Fenced object[%2d] = ", i);
572 if (obj == NULL)
573 seq_printf(m, "unused");
574 else
Chris Wilson05394f32010-11-08 19:18:58 +0000575 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100576 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000577 }
578
Chris Wilson05394f32010-11-08 19:18:58 +0000579 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000580 return 0;
581}
582
Ben Gamari20172632009-02-17 20:08:50 -0500583static int i915_hws_info(struct seq_file *m, void *data)
584{
585 struct drm_info_node *node = (struct drm_info_node *) m->private;
586 struct drm_device *dev = node->minor->dev;
587 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100588 struct intel_ring_buffer *ring;
Chris Wilson311bd682011-01-13 19:06:50 +0000589 const volatile u32 __iomem *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100590 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500591
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000592 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilson311bd682011-01-13 19:06:50 +0000593 hws = (volatile u32 __iomem *)ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500594 if (hws == NULL)
595 return 0;
596
597 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
598 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
599 i * 4,
600 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
601 }
602 return 0;
603}
604
Chris Wilsone5c65262010-11-01 11:35:28 +0000605static const char *ring_str(int ring)
606{
607 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100608 case RCS: return "render";
609 case VCS: return "bsd";
610 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000611 default: return "";
612 }
613}
614
Chris Wilson9df30792010-02-18 10:24:56 +0000615static const char *pin_flag(int pinned)
616{
617 if (pinned > 0)
618 return " P";
619 else if (pinned < 0)
620 return " p";
621 else
622 return "";
623}
624
625static const char *tiling_flag(int tiling)
626{
627 switch (tiling) {
628 default:
629 case I915_TILING_NONE: return "";
630 case I915_TILING_X: return " X";
631 case I915_TILING_Y: return " Y";
632 }
633}
634
635static const char *dirty_flag(int dirty)
636{
637 return dirty ? " dirty" : "";
638}
639
640static const char *purgeable_flag(int purgeable)
641{
642 return purgeable ? " purgeable" : "";
643}
644
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000645static void print_error_buffers(struct seq_file *m,
646 const char *name,
647 struct drm_i915_error_buffer *err,
648 int count)
649{
650 seq_printf(m, "%s [%d]:\n", name, count);
651
652 while (count--) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100653 seq_printf(m, " %08x %8u %04x %04x %08x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000654 err->gtt_offset,
655 err->size,
656 err->read_domains,
657 err->write_domain,
658 err->seqno,
659 pin_flag(err->pinned),
660 tiling_flag(err->tiling),
661 dirty_flag(err->dirty),
662 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100663 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000664 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700665 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000666
667 if (err->name)
668 seq_printf(m, " (name: %d)", err->name);
669 if (err->fence_reg != I915_FENCE_REG_NONE)
670 seq_printf(m, " (fence: %d)", err->fence_reg);
671
672 seq_printf(m, "\n");
673 err++;
674 }
675}
676
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100677static void i915_ring_error_state(struct seq_file *m,
678 struct drm_device *dev,
679 struct drm_i915_error_state *error,
680 unsigned ring)
681{
Ben Widawskyec34a012012-04-03 23:03:00 -0700682 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100683 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100684 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
685 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100686 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
687 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
688 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
689 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100690 if (ring == RCS && INTEL_INFO(dev)->gen >= 4) {
691 seq_printf(m, " INSTDONE1: 0x%08x\n", error->instdone1);
692 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100693 }
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100694 if (INTEL_INFO(dev)->gen >= 4)
695 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
696 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200697 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100698 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter33f3f512011-12-14 13:57:39 +0100699 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100700 seq_printf(m, " SYNC_0: 0x%08x\n",
701 error->semaphore_mboxes[ring][0]);
702 seq_printf(m, " SYNC_1: 0x%08x\n",
703 error->semaphore_mboxes[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100704 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100705 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100706 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
707 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100708}
709
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700710static int i915_error_state(struct seq_file *m, void *unused)
711{
712 struct drm_info_node *node = (struct drm_info_node *) m->private;
713 struct drm_device *dev = node->minor->dev;
714 drm_i915_private_t *dev_priv = dev->dev_private;
715 struct drm_i915_error_state *error;
716 unsigned long flags;
Chris Wilson52d39a22012-02-15 11:25:37 +0000717 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700718
719 spin_lock_irqsave(&dev_priv->error_lock, flags);
720 if (!dev_priv->first_error) {
721 seq_printf(m, "no error state collected\n");
722 goto out;
723 }
724
725 error = dev_priv->first_error;
726
Jesse Barnes8a905232009-07-11 16:48:03 -0400727 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
728 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000729 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100730 seq_printf(m, "EIR: 0x%08x\n", error->eir);
731 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Chris Wilson9df30792010-02-18 10:24:56 +0000732
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100733 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100734 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
735
Daniel Vetter33f3f512011-12-14 13:57:39 +0100736 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100737 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100738 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
739 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100740
741 i915_ring_error_state(m, dev, error, RCS);
742 if (HAS_BLT(dev))
743 i915_ring_error_state(m, dev, error, BCS);
744 if (HAS_BSD(dev))
745 i915_ring_error_state(m, dev, error, VCS);
746
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000747 if (error->active_bo)
748 print_error_buffers(m, "Active",
749 error->active_bo,
750 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000751
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000752 if (error->pinned_bo)
753 print_error_buffers(m, "Pinned",
754 error->pinned_bo,
755 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000756
Chris Wilson52d39a22012-02-15 11:25:37 +0000757 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
758 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000759
Chris Wilson52d39a22012-02-15 11:25:37 +0000760 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000761 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
762 dev_priv->ring[i].name,
763 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000764 offset = 0;
765 for (page = 0; page < obj->page_count; page++) {
766 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
767 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
768 offset += 4;
769 }
770 }
771 }
Chris Wilson9df30792010-02-18 10:24:56 +0000772
Chris Wilson52d39a22012-02-15 11:25:37 +0000773 if (error->ring[i].num_requests) {
774 seq_printf(m, "%s --- %d requests\n",
775 dev_priv->ring[i].name,
776 error->ring[i].num_requests);
777 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000778 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000779 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000780 error->ring[i].requests[j].jiffies,
781 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000782 }
783 }
784
785 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000786 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
787 dev_priv->ring[i].name,
788 obj->gtt_offset);
789 offset = 0;
790 for (page = 0; page < obj->page_count; page++) {
791 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
792 seq_printf(m, "%08x : %08x\n",
793 offset,
794 obj->pages[page][elt]);
795 offset += 4;
796 }
Chris Wilson9df30792010-02-18 10:24:56 +0000797 }
798 }
799 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700800
Chris Wilson6ef3d422010-08-04 20:26:07 +0100801 if (error->overlay)
802 intel_overlay_print_error_state(m, error->overlay);
803
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000804 if (error->display)
805 intel_display_print_error_state(m, dev, error->display);
806
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700807out:
808 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
809
810 return 0;
811}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700812
Jesse Barnesf97108d2010-01-29 11:27:07 -0800813static int i915_rstdby_delays(struct seq_file *m, void *unused)
814{
815 struct drm_info_node *node = (struct drm_info_node *) m->private;
816 struct drm_device *dev = node->minor->dev;
817 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700818 u16 crstanddelay;
819 int ret;
820
821 ret = mutex_lock_interruptible(&dev->struct_mutex);
822 if (ret)
823 return ret;
824
825 crstanddelay = I915_READ16(CRSTANDVID);
826
827 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800828
829 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
830
831 return 0;
832}
833
834static int i915_cur_delayinfo(struct seq_file *m, void *unused)
835{
836 struct drm_info_node *node = (struct drm_info_node *) m->private;
837 struct drm_device *dev = node->minor->dev;
838 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100839 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800840
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800841 if (IS_GEN5(dev)) {
842 u16 rgvswctl = I915_READ16(MEMSWCTL);
843 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
844
845 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
846 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
847 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
848 MEMSTAT_VID_SHIFT);
849 seq_printf(m, "Current P-state: %d\n",
850 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700851 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800852 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
853 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
854 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800855 u32 rpstat;
856 u32 rpupei, rpcurup, rpprevup;
857 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800858 int max_freq;
859
860 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100861 ret = mutex_lock_interruptible(&dev->struct_mutex);
862 if (ret)
863 return ret;
864
Ben Widawskyfcca7922011-04-25 11:23:07 -0700865 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800866
Jesse Barnesccab5c82011-01-18 15:49:25 -0800867 rpstat = I915_READ(GEN6_RPSTAT1);
868 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
869 rpcurup = I915_READ(GEN6_RP_CUR_UP);
870 rpprevup = I915_READ(GEN6_RP_PREV_UP);
871 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
872 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
873 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
874
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100875 gen6_gt_force_wake_put(dev_priv);
876 mutex_unlock(&dev->struct_mutex);
877
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800878 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800879 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800880 seq_printf(m, "Render p-state ratio: %d\n",
881 (gt_perf_status & 0xff00) >> 8);
882 seq_printf(m, "Render p-state VID: %d\n",
883 gt_perf_status & 0xff);
884 seq_printf(m, "Render p-state limit: %d\n",
885 rp_state_limits & 0xff);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800886 seq_printf(m, "CAGF: %dMHz\n", ((rpstat & GEN6_CAGF_MASK) >>
Jesse Barnese281fca2011-03-18 10:32:07 -0700887 GEN6_CAGF_SHIFT) * 50);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800888 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
889 GEN6_CURICONT_MASK);
890 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
891 GEN6_CURBSYTAVG_MASK);
892 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
893 GEN6_CURBSYTAVG_MASK);
894 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
895 GEN6_CURIAVG_MASK);
896 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
897 GEN6_CURBSYTAVG_MASK);
898 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
899 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800900
901 max_freq = (rp_state_cap & 0xff0000) >> 16;
902 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700903 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800904
905 max_freq = (rp_state_cap & 0xff00) >> 8;
906 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700907 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800908
909 max_freq = rp_state_cap & 0xff;
910 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700911 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800912 } else {
913 seq_printf(m, "no P-state info available\n");
914 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800915
916 return 0;
917}
918
919static int i915_delayfreq_table(struct seq_file *m, void *unused)
920{
921 struct drm_info_node *node = (struct drm_info_node *) m->private;
922 struct drm_device *dev = node->minor->dev;
923 drm_i915_private_t *dev_priv = dev->dev_private;
924 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700925 int ret, i;
926
927 ret = mutex_lock_interruptible(&dev->struct_mutex);
928 if (ret)
929 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800930
931 for (i = 0; i < 16; i++) {
932 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700933 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
934 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800935 }
936
Ben Widawsky616fdb52011-10-05 11:44:54 -0700937 mutex_unlock(&dev->struct_mutex);
938
Jesse Barnesf97108d2010-01-29 11:27:07 -0800939 return 0;
940}
941
942static inline int MAP_TO_MV(int map)
943{
944 return 1250 - (map * 25);
945}
946
947static int i915_inttoext_table(struct seq_file *m, void *unused)
948{
949 struct drm_info_node *node = (struct drm_info_node *) m->private;
950 struct drm_device *dev = node->minor->dev;
951 drm_i915_private_t *dev_priv = dev->dev_private;
952 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700953 int ret, i;
954
955 ret = mutex_lock_interruptible(&dev->struct_mutex);
956 if (ret)
957 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800958
959 for (i = 1; i <= 32; i++) {
960 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
961 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
962 }
963
Ben Widawsky616fdb52011-10-05 11:44:54 -0700964 mutex_unlock(&dev->struct_mutex);
965
Jesse Barnesf97108d2010-01-29 11:27:07 -0800966 return 0;
967}
968
Ben Widawsky4d855292011-12-12 19:34:16 -0800969static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800970{
971 struct drm_info_node *node = (struct drm_info_node *) m->private;
972 struct drm_device *dev = node->minor->dev;
973 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700974 u32 rgvmodectl, rstdbyctl;
975 u16 crstandvid;
976 int ret;
977
978 ret = mutex_lock_interruptible(&dev->struct_mutex);
979 if (ret)
980 return ret;
981
982 rgvmodectl = I915_READ(MEMMODECTL);
983 rstdbyctl = I915_READ(RSTDBYCTL);
984 crstandvid = I915_READ16(CRSTANDVID);
985
986 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800987
988 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
989 "yes" : "no");
990 seq_printf(m, "Boost freq: %d\n",
991 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
992 MEMMODE_BOOST_FREQ_SHIFT);
993 seq_printf(m, "HW control enabled: %s\n",
994 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
995 seq_printf(m, "SW control enabled: %s\n",
996 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
997 seq_printf(m, "Gated voltage change: %s\n",
998 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
999 seq_printf(m, "Starting frequency: P%d\n",
1000 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001001 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001002 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001003 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1004 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1005 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1006 seq_printf(m, "Render standby enabled: %s\n",
1007 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001008 seq_printf(m, "Current RS state: ");
1009 switch (rstdbyctl & RSX_STATUS_MASK) {
1010 case RSX_STATUS_ON:
1011 seq_printf(m, "on\n");
1012 break;
1013 case RSX_STATUS_RC1:
1014 seq_printf(m, "RC1\n");
1015 break;
1016 case RSX_STATUS_RC1E:
1017 seq_printf(m, "RC1E\n");
1018 break;
1019 case RSX_STATUS_RS1:
1020 seq_printf(m, "RS1\n");
1021 break;
1022 case RSX_STATUS_RS2:
1023 seq_printf(m, "RS2 (RC6)\n");
1024 break;
1025 case RSX_STATUS_RS3:
1026 seq_printf(m, "RC3 (RC6+)\n");
1027 break;
1028 default:
1029 seq_printf(m, "unknown\n");
1030 break;
1031 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001032
1033 return 0;
1034}
1035
Ben Widawsky4d855292011-12-12 19:34:16 -08001036static int gen6_drpc_info(struct seq_file *m)
1037{
1038
1039 struct drm_info_node *node = (struct drm_info_node *) m->private;
1040 struct drm_device *dev = node->minor->dev;
1041 struct drm_i915_private *dev_priv = dev->dev_private;
1042 u32 rpmodectl1, gt_core_status, rcctl1;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001043 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001044 int count=0, ret;
1045
1046
1047 ret = mutex_lock_interruptible(&dev->struct_mutex);
1048 if (ret)
1049 return ret;
1050
Daniel Vetter93b525d2012-01-25 13:52:43 +01001051 spin_lock_irq(&dev_priv->gt_lock);
1052 forcewake_count = dev_priv->forcewake_count;
1053 spin_unlock_irq(&dev_priv->gt_lock);
1054
1055 if (forcewake_count) {
1056 seq_printf(m, "RC information inaccurate because somebody "
1057 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001058 } else {
1059 /* NB: we cannot use forcewake, else we read the wrong values */
1060 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1061 udelay(10);
1062 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1063 }
1064
1065 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1066 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1067
1068 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1069 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1070 mutex_unlock(&dev->struct_mutex);
1071
1072 seq_printf(m, "Video Turbo Mode: %s\n",
1073 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1074 seq_printf(m, "HW control enabled: %s\n",
1075 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1076 seq_printf(m, "SW control enabled: %s\n",
1077 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1078 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001079 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001080 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1081 seq_printf(m, "RC6 Enabled: %s\n",
1082 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1083 seq_printf(m, "Deep RC6 Enabled: %s\n",
1084 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1085 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1086 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1087 seq_printf(m, "Current RC state: ");
1088 switch (gt_core_status & GEN6_RCn_MASK) {
1089 case GEN6_RC0:
1090 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1091 seq_printf(m, "Core Power Down\n");
1092 else
1093 seq_printf(m, "on\n");
1094 break;
1095 case GEN6_RC3:
1096 seq_printf(m, "RC3\n");
1097 break;
1098 case GEN6_RC6:
1099 seq_printf(m, "RC6\n");
1100 break;
1101 case GEN6_RC7:
1102 seq_printf(m, "RC7\n");
1103 break;
1104 default:
1105 seq_printf(m, "Unknown\n");
1106 break;
1107 }
1108
1109 seq_printf(m, "Core Power Down: %s\n",
1110 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001111
1112 /* Not exactly sure what this is */
1113 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1114 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1115 seq_printf(m, "RC6 residency since boot: %u\n",
1116 I915_READ(GEN6_GT_GFX_RC6));
1117 seq_printf(m, "RC6+ residency since boot: %u\n",
1118 I915_READ(GEN6_GT_GFX_RC6p));
1119 seq_printf(m, "RC6++ residency since boot: %u\n",
1120 I915_READ(GEN6_GT_GFX_RC6pp));
1121
Ben Widawsky4d855292011-12-12 19:34:16 -08001122 return 0;
1123}
1124
1125static int i915_drpc_info(struct seq_file *m, void *unused)
1126{
1127 struct drm_info_node *node = (struct drm_info_node *) m->private;
1128 struct drm_device *dev = node->minor->dev;
1129
1130 if (IS_GEN6(dev) || IS_GEN7(dev))
1131 return gen6_drpc_info(m);
1132 else
1133 return ironlake_drpc_info(m);
1134}
1135
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001136static int i915_fbc_status(struct seq_file *m, void *unused)
1137{
1138 struct drm_info_node *node = (struct drm_info_node *) m->private;
1139 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001140 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001141
Adam Jacksonee5382a2010-04-23 11:17:39 -04001142 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001143 seq_printf(m, "FBC unsupported on this chipset\n");
1144 return 0;
1145 }
1146
Adam Jacksonee5382a2010-04-23 11:17:39 -04001147 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001148 seq_printf(m, "FBC enabled\n");
1149 } else {
1150 seq_printf(m, "FBC disabled: ");
1151 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001152 case FBC_NO_OUTPUT:
1153 seq_printf(m, "no outputs");
1154 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001155 case FBC_STOLEN_TOO_SMALL:
1156 seq_printf(m, "not enough stolen memory");
1157 break;
1158 case FBC_UNSUPPORTED_MODE:
1159 seq_printf(m, "mode not supported");
1160 break;
1161 case FBC_MODE_TOO_LARGE:
1162 seq_printf(m, "mode too large");
1163 break;
1164 case FBC_BAD_PLANE:
1165 seq_printf(m, "FBC unsupported on plane");
1166 break;
1167 case FBC_NOT_TILED:
1168 seq_printf(m, "scanout buffer not tiled");
1169 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001170 case FBC_MULTIPLE_PIPES:
1171 seq_printf(m, "multiple pipes are enabled");
1172 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001173 case FBC_MODULE_PARAM:
1174 seq_printf(m, "disabled per module param (default off)");
1175 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001176 default:
1177 seq_printf(m, "unknown reason");
1178 }
1179 seq_printf(m, "\n");
1180 }
1181 return 0;
1182}
1183
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001184static int i915_sr_status(struct seq_file *m, void *unused)
1185{
1186 struct drm_info_node *node = (struct drm_info_node *) m->private;
1187 struct drm_device *dev = node->minor->dev;
1188 drm_i915_private_t *dev_priv = dev->dev_private;
1189 bool sr_enabled = false;
1190
Yuanhan Liu13982612010-12-15 15:42:31 +08001191 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001192 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001193 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001194 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1195 else if (IS_I915GM(dev))
1196 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1197 else if (IS_PINEVIEW(dev))
1198 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1199
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001200 seq_printf(m, "self-refresh: %s\n",
1201 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001202
1203 return 0;
1204}
1205
Jesse Barnes7648fa92010-05-20 14:28:11 -07001206static int i915_emon_status(struct seq_file *m, void *unused)
1207{
1208 struct drm_info_node *node = (struct drm_info_node *) m->private;
1209 struct drm_device *dev = node->minor->dev;
1210 drm_i915_private_t *dev_priv = dev->dev_private;
1211 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001212 int ret;
1213
1214 ret = mutex_lock_interruptible(&dev->struct_mutex);
1215 if (ret)
1216 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001217
1218 temp = i915_mch_val(dev_priv);
1219 chipset = i915_chipset_val(dev_priv);
1220 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001221 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001222
1223 seq_printf(m, "GMCH temp: %ld\n", temp);
1224 seq_printf(m, "Chipset power: %ld\n", chipset);
1225 seq_printf(m, "GFX power: %ld\n", gfx);
1226 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1227
1228 return 0;
1229}
1230
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001231static int i915_ring_freq_table(struct seq_file *m, void *unused)
1232{
1233 struct drm_info_node *node = (struct drm_info_node *) m->private;
1234 struct drm_device *dev = node->minor->dev;
1235 drm_i915_private_t *dev_priv = dev->dev_private;
1236 int ret;
1237 int gpu_freq, ia_freq;
1238
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001239 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001240 seq_printf(m, "unsupported on this chipset\n");
1241 return 0;
1242 }
1243
1244 ret = mutex_lock_interruptible(&dev->struct_mutex);
1245 if (ret)
1246 return ret;
1247
1248 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1249
1250 for (gpu_freq = dev_priv->min_delay; gpu_freq <= dev_priv->max_delay;
1251 gpu_freq++) {
1252 I915_WRITE(GEN6_PCODE_DATA, gpu_freq);
1253 I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY |
1254 GEN6_PCODE_READ_MIN_FREQ_TABLE);
1255 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) &
1256 GEN6_PCODE_READY) == 0, 10)) {
1257 DRM_ERROR("pcode read of freq table timed out\n");
1258 continue;
1259 }
1260 ia_freq = I915_READ(GEN6_PCODE_DATA);
1261 seq_printf(m, "%d\t\t%d\n", gpu_freq * 50, ia_freq * 100);
1262 }
1263
1264 mutex_unlock(&dev->struct_mutex);
1265
1266 return 0;
1267}
1268
Jesse Barnes7648fa92010-05-20 14:28:11 -07001269static int i915_gfxec(struct seq_file *m, void *unused)
1270{
1271 struct drm_info_node *node = (struct drm_info_node *) m->private;
1272 struct drm_device *dev = node->minor->dev;
1273 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001274 int ret;
1275
1276 ret = mutex_lock_interruptible(&dev->struct_mutex);
1277 if (ret)
1278 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001279
1280 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1281
Ben Widawsky616fdb52011-10-05 11:44:54 -07001282 mutex_unlock(&dev->struct_mutex);
1283
Jesse Barnes7648fa92010-05-20 14:28:11 -07001284 return 0;
1285}
1286
Chris Wilson44834a62010-08-19 16:09:23 +01001287static int i915_opregion(struct seq_file *m, void *unused)
1288{
1289 struct drm_info_node *node = (struct drm_info_node *) m->private;
1290 struct drm_device *dev = node->minor->dev;
1291 drm_i915_private_t *dev_priv = dev->dev_private;
1292 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001293 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001294 int ret;
1295
Daniel Vetter0d38f002012-04-21 22:49:10 +02001296 if (data == NULL)
1297 return -ENOMEM;
1298
Chris Wilson44834a62010-08-19 16:09:23 +01001299 ret = mutex_lock_interruptible(&dev->struct_mutex);
1300 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001301 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001302
Daniel Vetter0d38f002012-04-21 22:49:10 +02001303 if (opregion->header) {
1304 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1305 seq_write(m, data, OPREGION_SIZE);
1306 }
Chris Wilson44834a62010-08-19 16:09:23 +01001307
1308 mutex_unlock(&dev->struct_mutex);
1309
Daniel Vetter0d38f002012-04-21 22:49:10 +02001310out:
1311 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001312 return 0;
1313}
1314
Chris Wilson37811fc2010-08-25 22:45:57 +01001315static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1316{
1317 struct drm_info_node *node = (struct drm_info_node *) m->private;
1318 struct drm_device *dev = node->minor->dev;
1319 drm_i915_private_t *dev_priv = dev->dev_private;
1320 struct intel_fbdev *ifbdev;
1321 struct intel_framebuffer *fb;
1322 int ret;
1323
1324 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1325 if (ret)
1326 return ret;
1327
1328 ifbdev = dev_priv->fbdev;
1329 fb = to_intel_framebuffer(ifbdev->helper.fb);
1330
1331 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1332 fb->base.width,
1333 fb->base.height,
1334 fb->base.depth,
1335 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001336 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001337 seq_printf(m, "\n");
1338
1339 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1340 if (&fb->base == ifbdev->helper.fb)
1341 continue;
1342
1343 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1344 fb->base.width,
1345 fb->base.height,
1346 fb->base.depth,
1347 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001348 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001349 seq_printf(m, "\n");
1350 }
1351
1352 mutex_unlock(&dev->mode_config.mutex);
1353
1354 return 0;
1355}
1356
Ben Widawskye76d3632011-03-19 18:14:29 -07001357static int i915_context_status(struct seq_file *m, void *unused)
1358{
1359 struct drm_info_node *node = (struct drm_info_node *) m->private;
1360 struct drm_device *dev = node->minor->dev;
1361 drm_i915_private_t *dev_priv = dev->dev_private;
1362 int ret;
1363
1364 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1365 if (ret)
1366 return ret;
1367
Ben Widawskydc501fb2011-06-29 11:41:51 -07001368 if (dev_priv->pwrctx) {
1369 seq_printf(m, "power context ");
1370 describe_obj(m, dev_priv->pwrctx);
1371 seq_printf(m, "\n");
1372 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001373
Ben Widawskydc501fb2011-06-29 11:41:51 -07001374 if (dev_priv->renderctx) {
1375 seq_printf(m, "render context ");
1376 describe_obj(m, dev_priv->renderctx);
1377 seq_printf(m, "\n");
1378 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001379
1380 mutex_unlock(&dev->mode_config.mutex);
1381
1382 return 0;
1383}
1384
Ben Widawsky6d794d42011-04-25 11:25:56 -07001385static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1386{
1387 struct drm_info_node *node = (struct drm_info_node *) m->private;
1388 struct drm_device *dev = node->minor->dev;
1389 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001390 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001391
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001392 spin_lock_irq(&dev_priv->gt_lock);
1393 forcewake_count = dev_priv->forcewake_count;
1394 spin_unlock_irq(&dev_priv->gt_lock);
1395
1396 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001397
1398 return 0;
1399}
1400
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001401static const char *swizzle_string(unsigned swizzle)
1402{
1403 switch(swizzle) {
1404 case I915_BIT_6_SWIZZLE_NONE:
1405 return "none";
1406 case I915_BIT_6_SWIZZLE_9:
1407 return "bit9";
1408 case I915_BIT_6_SWIZZLE_9_10:
1409 return "bit9/bit10";
1410 case I915_BIT_6_SWIZZLE_9_11:
1411 return "bit9/bit11";
1412 case I915_BIT_6_SWIZZLE_9_10_11:
1413 return "bit9/bit10/bit11";
1414 case I915_BIT_6_SWIZZLE_9_17:
1415 return "bit9/bit17";
1416 case I915_BIT_6_SWIZZLE_9_10_17:
1417 return "bit9/bit10/bit17";
1418 case I915_BIT_6_SWIZZLE_UNKNOWN:
1419 return "unkown";
1420 }
1421
1422 return "bug";
1423}
1424
1425static int i915_swizzle_info(struct seq_file *m, void *data)
1426{
1427 struct drm_info_node *node = (struct drm_info_node *) m->private;
1428 struct drm_device *dev = node->minor->dev;
1429 struct drm_i915_private *dev_priv = dev->dev_private;
1430
1431 mutex_lock(&dev->struct_mutex);
1432 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1433 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1434 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1435 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1436
1437 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1438 seq_printf(m, "DDC = 0x%08x\n",
1439 I915_READ(DCC));
1440 seq_printf(m, "C0DRB3 = 0x%04x\n",
1441 I915_READ16(C0DRB3));
1442 seq_printf(m, "C1DRB3 = 0x%04x\n",
1443 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001444 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1445 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1446 I915_READ(MAD_DIMM_C0));
1447 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1448 I915_READ(MAD_DIMM_C1));
1449 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1450 I915_READ(MAD_DIMM_C2));
1451 seq_printf(m, "TILECTL = 0x%08x\n",
1452 I915_READ(TILECTL));
1453 seq_printf(m, "ARB_MODE = 0x%08x\n",
1454 I915_READ(ARB_MODE));
1455 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1456 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001457 }
1458 mutex_unlock(&dev->struct_mutex);
1459
1460 return 0;
1461}
1462
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001463static int i915_ppgtt_info(struct seq_file *m, void *data)
1464{
1465 struct drm_info_node *node = (struct drm_info_node *) m->private;
1466 struct drm_device *dev = node->minor->dev;
1467 struct drm_i915_private *dev_priv = dev->dev_private;
1468 struct intel_ring_buffer *ring;
1469 int i, ret;
1470
1471
1472 ret = mutex_lock_interruptible(&dev->struct_mutex);
1473 if (ret)
1474 return ret;
1475 if (INTEL_INFO(dev)->gen == 6)
1476 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1477
1478 for (i = 0; i < I915_NUM_RINGS; i++) {
1479 ring = &dev_priv->ring[i];
1480
1481 seq_printf(m, "%s\n", ring->name);
1482 if (INTEL_INFO(dev)->gen == 7)
1483 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1484 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1485 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1486 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1487 }
1488 if (dev_priv->mm.aliasing_ppgtt) {
1489 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1490
1491 seq_printf(m, "aliasing PPGTT:\n");
1492 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1493 }
1494 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1495 mutex_unlock(&dev->struct_mutex);
1496
1497 return 0;
1498}
1499
Jesse Barnes57f350b2012-03-28 13:39:25 -07001500static int i915_dpio_info(struct seq_file *m, void *data)
1501{
1502 struct drm_info_node *node = (struct drm_info_node *) m->private;
1503 struct drm_device *dev = node->minor->dev;
1504 struct drm_i915_private *dev_priv = dev->dev_private;
1505 int ret;
1506
1507
1508 if (!IS_VALLEYVIEW(dev)) {
1509 seq_printf(m, "unsupported\n");
1510 return 0;
1511 }
1512
1513 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1514 if (ret)
1515 return ret;
1516
1517 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1518
1519 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1520 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1521 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1522 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1523
1524 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1525 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1526 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1527 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1528
1529 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1530 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1531 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1532 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1533
1534 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1535 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1536 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1537 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1538
1539 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1540 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1541
1542 mutex_unlock(&dev->mode_config.mutex);
1543
1544 return 0;
1545}
1546
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001547static ssize_t
1548i915_wedged_read(struct file *filp,
1549 char __user *ubuf,
1550 size_t max,
1551 loff_t *ppos)
1552{
1553 struct drm_device *dev = filp->private_data;
1554 drm_i915_private_t *dev_priv = dev->dev_private;
1555 char buf[80];
1556 int len;
1557
Akshay Joshi0206e352011-08-16 15:34:10 -04001558 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001559 "wedged : %d\n",
1560 atomic_read(&dev_priv->mm.wedged));
1561
Akshay Joshi0206e352011-08-16 15:34:10 -04001562 if (len > sizeof(buf))
1563 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001564
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001565 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1566}
1567
1568static ssize_t
1569i915_wedged_write(struct file *filp,
1570 const char __user *ubuf,
1571 size_t cnt,
1572 loff_t *ppos)
1573{
1574 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001575 char buf[20];
1576 int val = 1;
1577
1578 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001579 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001580 return -EINVAL;
1581
1582 if (copy_from_user(buf, ubuf, cnt))
1583 return -EFAULT;
1584 buf[cnt] = 0;
1585
1586 val = simple_strtoul(buf, NULL, 0);
1587 }
1588
1589 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001590 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001591
1592 return cnt;
1593}
1594
1595static const struct file_operations i915_wedged_fops = {
1596 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001597 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001598 .read = i915_wedged_read,
1599 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001600 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001601};
1602
Jesse Barnes358733e2011-07-27 11:53:01 -07001603static ssize_t
1604i915_max_freq_read(struct file *filp,
1605 char __user *ubuf,
1606 size_t max,
1607 loff_t *ppos)
1608{
1609 struct drm_device *dev = filp->private_data;
1610 drm_i915_private_t *dev_priv = dev->dev_private;
1611 char buf[80];
1612 int len;
1613
Akshay Joshi0206e352011-08-16 15:34:10 -04001614 len = snprintf(buf, sizeof(buf),
Jesse Barnes358733e2011-07-27 11:53:01 -07001615 "max freq: %d\n", dev_priv->max_delay * 50);
1616
Akshay Joshi0206e352011-08-16 15:34:10 -04001617 if (len > sizeof(buf))
1618 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001619
1620 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1621}
1622
1623static ssize_t
1624i915_max_freq_write(struct file *filp,
1625 const char __user *ubuf,
1626 size_t cnt,
1627 loff_t *ppos)
1628{
1629 struct drm_device *dev = filp->private_data;
1630 struct drm_i915_private *dev_priv = dev->dev_private;
1631 char buf[20];
1632 int val = 1;
1633
1634 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001635 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001636 return -EINVAL;
1637
1638 if (copy_from_user(buf, ubuf, cnt))
1639 return -EFAULT;
1640 buf[cnt] = 0;
1641
1642 val = simple_strtoul(buf, NULL, 0);
1643 }
1644
1645 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1646
1647 /*
1648 * Turbo will still be enabled, but won't go above the set value.
1649 */
1650 dev_priv->max_delay = val / 50;
1651
1652 gen6_set_rps(dev, val / 50);
1653
1654 return cnt;
1655}
1656
1657static const struct file_operations i915_max_freq_fops = {
1658 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001659 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001660 .read = i915_max_freq_read,
1661 .write = i915_max_freq_write,
1662 .llseek = default_llseek,
1663};
1664
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001665static ssize_t
1666i915_cache_sharing_read(struct file *filp,
1667 char __user *ubuf,
1668 size_t max,
1669 loff_t *ppos)
1670{
1671 struct drm_device *dev = filp->private_data;
1672 drm_i915_private_t *dev_priv = dev->dev_private;
1673 char buf[80];
1674 u32 snpcr;
1675 int len;
1676
1677 mutex_lock(&dev_priv->dev->struct_mutex);
1678 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1679 mutex_unlock(&dev_priv->dev->struct_mutex);
1680
Akshay Joshi0206e352011-08-16 15:34:10 -04001681 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001682 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
1683 GEN6_MBC_SNPCR_SHIFT);
1684
Akshay Joshi0206e352011-08-16 15:34:10 -04001685 if (len > sizeof(buf))
1686 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001687
1688 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1689}
1690
1691static ssize_t
1692i915_cache_sharing_write(struct file *filp,
1693 const char __user *ubuf,
1694 size_t cnt,
1695 loff_t *ppos)
1696{
1697 struct drm_device *dev = filp->private_data;
1698 struct drm_i915_private *dev_priv = dev->dev_private;
1699 char buf[20];
1700 u32 snpcr;
1701 int val = 1;
1702
1703 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001704 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001705 return -EINVAL;
1706
1707 if (copy_from_user(buf, ubuf, cnt))
1708 return -EFAULT;
1709 buf[cnt] = 0;
1710
1711 val = simple_strtoul(buf, NULL, 0);
1712 }
1713
1714 if (val < 0 || val > 3)
1715 return -EINVAL;
1716
1717 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
1718
1719 /* Update the cache sharing policy here as well */
1720 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1721 snpcr &= ~GEN6_MBC_SNPCR_MASK;
1722 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
1723 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
1724
1725 return cnt;
1726}
1727
1728static const struct file_operations i915_cache_sharing_fops = {
1729 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001730 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001731 .read = i915_cache_sharing_read,
1732 .write = i915_cache_sharing_write,
1733 .llseek = default_llseek,
1734};
1735
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001736/* As the drm_debugfs_init() routines are called before dev->dev_private is
1737 * allocated we need to hook into the minor for release. */
1738static int
1739drm_add_fake_info_node(struct drm_minor *minor,
1740 struct dentry *ent,
1741 const void *key)
1742{
1743 struct drm_info_node *node;
1744
1745 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
1746 if (node == NULL) {
1747 debugfs_remove(ent);
1748 return -ENOMEM;
1749 }
1750
1751 node->minor = minor;
1752 node->dent = ent;
1753 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01001754
1755 mutex_lock(&minor->debugfs_lock);
1756 list_add(&node->list, &minor->debugfs_list);
1757 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001758
1759 return 0;
1760}
1761
Ben Widawsky6d794d42011-04-25 11:25:56 -07001762static int i915_forcewake_open(struct inode *inode, struct file *file)
1763{
1764 struct drm_device *dev = inode->i_private;
1765 struct drm_i915_private *dev_priv = dev->dev_private;
1766 int ret;
1767
Daniel Vetter075edca2012-01-24 09:44:28 +01001768 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001769 return 0;
1770
1771 ret = mutex_lock_interruptible(&dev->struct_mutex);
1772 if (ret)
1773 return ret;
1774 gen6_gt_force_wake_get(dev_priv);
1775 mutex_unlock(&dev->struct_mutex);
1776
1777 return 0;
1778}
1779
Ben Widawskyc43b5632012-04-16 14:07:40 -07001780static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001781{
1782 struct drm_device *dev = inode->i_private;
1783 struct drm_i915_private *dev_priv = dev->dev_private;
1784
Daniel Vetter075edca2012-01-24 09:44:28 +01001785 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001786 return 0;
1787
1788 /*
1789 * It's bad that we can potentially hang userspace if struct_mutex gets
1790 * forever stuck. However, if we cannot acquire this lock it means that
1791 * almost certainly the driver has hung, is not unload-able. Therefore
1792 * hanging here is probably a minor inconvenience not to be seen my
1793 * almost every user.
1794 */
1795 mutex_lock(&dev->struct_mutex);
1796 gen6_gt_force_wake_put(dev_priv);
1797 mutex_unlock(&dev->struct_mutex);
1798
1799 return 0;
1800}
1801
1802static const struct file_operations i915_forcewake_fops = {
1803 .owner = THIS_MODULE,
1804 .open = i915_forcewake_open,
1805 .release = i915_forcewake_release,
1806};
1807
1808static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
1809{
1810 struct drm_device *dev = minor->dev;
1811 struct dentry *ent;
1812
1813 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07001814 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07001815 root, dev,
1816 &i915_forcewake_fops);
1817 if (IS_ERR(ent))
1818 return PTR_ERR(ent);
1819
Ben Widawsky8eb57292011-05-11 15:10:58 -07001820 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001821}
1822
Daniel Vetter6a9c3082011-12-14 13:57:11 +01001823static int i915_debugfs_create(struct dentry *root,
1824 struct drm_minor *minor,
1825 const char *name,
1826 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07001827{
1828 struct drm_device *dev = minor->dev;
1829 struct dentry *ent;
1830
Daniel Vetter6a9c3082011-12-14 13:57:11 +01001831 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07001832 S_IRUGO | S_IWUSR,
1833 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01001834 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07001835 if (IS_ERR(ent))
1836 return PTR_ERR(ent);
1837
Daniel Vetter6a9c3082011-12-14 13:57:11 +01001838 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001839}
1840
Ben Gamari27c202a2009-07-01 22:26:52 -04001841static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00001842 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01001843 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00001844 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Ben Gamari433e12f2009-02-17 20:08:51 -05001845 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
1846 {"i915_gem_flushing", i915_gem_object_list_info, 0, (void *) FLUSHING_LIST},
1847 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilsonf13d3f72010-09-20 17:36:15 +01001848 {"i915_gem_pinned", i915_gem_object_list_info, 0, (void *) PINNED_LIST},
Chris Wilsond21d5972010-09-26 11:19:33 +01001849 {"i915_gem_deferred_free", i915_gem_object_list_info, 0, (void *) DEFERRED_FREE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001850 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05001851 {"i915_gem_request", i915_gem_request_info, 0},
1852 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00001853 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05001854 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001855 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
1856 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
1857 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnes63eeaf32009-06-18 16:56:52 -07001858 {"i915_error_state", i915_error_state, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08001859 {"i915_rstdby_delays", i915_rstdby_delays, 0},
1860 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
1861 {"i915_delayfreq_table", i915_delayfreq_table, 0},
1862 {"i915_inttoext_table", i915_inttoext_table, 0},
1863 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07001864 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001865 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07001866 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001867 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001868 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01001869 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01001870 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07001871 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07001872 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001873 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001874 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07001875 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05001876};
Ben Gamari27c202a2009-07-01 22:26:52 -04001877#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05001878
Ben Gamari27c202a2009-07-01 22:26:52 -04001879int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05001880{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001881 int ret;
1882
Daniel Vetter6a9c3082011-12-14 13:57:11 +01001883 ret = i915_debugfs_create(minor->debugfs_root, minor,
1884 "i915_wedged",
1885 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001886 if (ret)
1887 return ret;
1888
Ben Widawsky6d794d42011-04-25 11:25:56 -07001889 ret = i915_forcewake_create(minor->debugfs_root, minor);
1890 if (ret)
1891 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01001892
1893 ret = i915_debugfs_create(minor->debugfs_root, minor,
1894 "i915_max_freq",
1895 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07001896 if (ret)
1897 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01001898
1899 ret = i915_debugfs_create(minor->debugfs_root, minor,
1900 "i915_cache_sharing",
1901 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001902 if (ret)
1903 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001904
Ben Gamari27c202a2009-07-01 22:26:52 -04001905 return drm_debugfs_create_files(i915_debugfs_list,
1906 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05001907 minor->debugfs_root, minor);
1908}
1909
Ben Gamari27c202a2009-07-01 22:26:52 -04001910void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05001911{
Ben Gamari27c202a2009-07-01 22:26:52 -04001912 drm_debugfs_remove_files(i915_debugfs_list,
1913 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001914 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
1915 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05001916 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
1917 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07001918 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
1919 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001920 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
1921 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05001922}
1923
1924#endif /* CONFIG_DEBUG_FS */