blob: 204c19a4996963a57344601ebcf2005d215fc9fa [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 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010048 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010049};
Ben Gamari433e12f2009-02-17 20:08:51 -050050
Chris Wilson70d39fe2010-08-25 16:03:34 +010051static const char *yesno(int v)
52{
53 return v ? "yes" : "no";
54}
55
56static int i915_capabilities(struct seq_file *m, void *data)
57{
58 struct drm_info_node *node = (struct drm_info_node *) m->private;
59 struct drm_device *dev = node->minor->dev;
60 const struct intel_device_info *info = INTEL_INFO(dev);
61
62 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030063 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Daniel Vetterc96ea642012-08-08 22:01:51 +020064#define DEV_INFO_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
65#define DEV_INFO_SEP ;
66 DEV_INFO_FLAGS;
67#undef DEV_INFO_FLAG
68#undef DEV_INFO_SEP
Chris Wilson70d39fe2010-08-25 16:03:34 +010069
70 return 0;
71}
Ben Gamari433e12f2009-02-17 20:08:51 -050072
Chris Wilson05394f32010-11-08 19:18:58 +000073static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000074{
Chris Wilson05394f32010-11-08 19:18:58 +000075 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000076 return "P";
Chris Wilson05394f32010-11-08 19:18:58 +000077 else if (obj->pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000078 return "p";
79 else
80 return " ";
81}
82
Chris Wilson05394f32010-11-08 19:18:58 +000083static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000084{
Akshay Joshi0206e352011-08-16 15:34:10 -040085 switch (obj->tiling_mode) {
86 default:
87 case I915_TILING_NONE: return " ";
88 case I915_TILING_X: return "X";
89 case I915_TILING_Y: return "Y";
90 }
Chris Wilsona6172a82009-02-11 14:26:38 +000091}
92
Chris Wilson93dfb402011-03-29 16:59:50 -070093static const char *cache_level_str(int type)
Chris Wilson08c18322011-01-10 00:00:24 +000094{
95 switch (type) {
Chris Wilson93dfb402011-03-29 16:59:50 -070096 case I915_CACHE_NONE: return " uncached";
97 case I915_CACHE_LLC: return " snooped (LLC)";
98 case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
Chris Wilson08c18322011-01-10 00:00:24 +000099 default: return "";
100 }
101}
102
Chris Wilson37811fc2010-08-25 22:45:57 +0100103static void
104describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
105{
Chris Wilson0201f1e2012-07-20 12:41:01 +0100106 seq_printf(m, "%p: %s%s %8zdKiB %04x %04x %d %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100107 &obj->base,
108 get_pin_flag(obj),
109 get_tiling_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800110 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100111 obj->base.read_domains,
112 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100113 obj->last_read_seqno,
114 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000115 obj->last_fenced_seqno,
Chris Wilson93dfb402011-03-29 16:59:50 -0700116 cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100117 obj->dirty ? " dirty" : "",
118 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
119 if (obj->base.name)
120 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilsonc110a6d2012-08-11 15:41:02 +0100121 if (obj->pin_count)
122 seq_printf(m, " (pinned x %d)", obj->pin_count);
Chris Wilson37811fc2010-08-25 22:45:57 +0100123 if (obj->fence_reg != I915_FENCE_REG_NONE)
124 seq_printf(m, " (fence: %d)", obj->fence_reg);
125 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100126 seq_printf(m, " (gtt offset: %08x, size: %08x)",
127 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilson6299f992010-11-24 12:23:44 +0000128 if (obj->pin_mappable || obj->fault_mappable) {
129 char s[3], *t = s;
130 if (obj->pin_mappable)
131 *t++ = 'p';
132 if (obj->fault_mappable)
133 *t++ = 'f';
134 *t = '\0';
135 seq_printf(m, " (%s mappable)", s);
136 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100137 if (obj->ring != NULL)
138 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100139}
140
Ben Gamari433e12f2009-02-17 20:08:51 -0500141static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500142{
143 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500144 uintptr_t list = (uintptr_t) node->info_ent->data;
145 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500146 struct drm_device *dev = node->minor->dev;
147 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000148 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100149 size_t total_obj_size, total_gtt_size;
150 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100151
152 ret = mutex_lock_interruptible(&dev->struct_mutex);
153 if (ret)
154 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500155
Ben Gamari433e12f2009-02-17 20:08:51 -0500156 switch (list) {
157 case ACTIVE_LIST:
158 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100159 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500160 break;
161 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400162 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500163 head = &dev_priv->mm.inactive_list;
164 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500165 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100166 mutex_unlock(&dev->struct_mutex);
167 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500168 }
169
Chris Wilson8f2480f2010-09-26 11:44:19 +0100170 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000171 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100172 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000173 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800174 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000175 total_obj_size += obj->base.size;
176 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100177 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500178 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100179 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700180
Chris Wilson8f2480f2010-09-26 11:44:19 +0100181 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
182 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500183 return 0;
184}
185
Chris Wilson6299f992010-11-24 12:23:44 +0000186#define count_objects(list, member) do { \
187 list_for_each_entry(obj, list, member) { \
188 size += obj->gtt_space->size; \
189 ++count; \
190 if (obj->map_and_fenceable) { \
191 mappable_size += obj->gtt_space->size; \
192 ++mappable_count; \
193 } \
194 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400195} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000196
Chris Wilson73aa8082010-09-30 11:46:12 +0100197static int i915_gem_object_info(struct seq_file *m, void* data)
198{
199 struct drm_info_node *node = (struct drm_info_node *) m->private;
200 struct drm_device *dev = node->minor->dev;
201 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200202 u32 count, mappable_count, purgeable_count;
203 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000204 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100205 int ret;
206
207 ret = mutex_lock_interruptible(&dev->struct_mutex);
208 if (ret)
209 return ret;
210
Chris Wilson6299f992010-11-24 12:23:44 +0000211 seq_printf(m, "%u objects, %zu bytes\n",
212 dev_priv->mm.object_count,
213 dev_priv->mm.object_memory);
214
215 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200216 count_objects(&dev_priv->mm.bound_list, gtt_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000217 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
218 count, mappable_count, size, mappable_size);
219
220 size = count = mappable_size = mappable_count = 0;
221 count_objects(&dev_priv->mm.active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000222 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
223 count, mappable_count, size, mappable_size);
224
225 size = count = mappable_size = mappable_count = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000226 count_objects(&dev_priv->mm.inactive_list, mm_list);
227 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
228 count, mappable_count, size, mappable_size);
229
Chris Wilsonb7abb712012-08-20 11:33:30 +0200230 size = count = purgeable_size = purgeable_count = 0;
231 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200232 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200233 if (obj->madv == I915_MADV_DONTNEED)
234 purgeable_size += obj->base.size, ++purgeable_count;
235 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200236 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
237
Chris Wilson6299f992010-11-24 12:23:44 +0000238 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200239 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000240 if (obj->fault_mappable) {
241 size += obj->gtt_space->size;
242 ++count;
243 }
244 if (obj->pin_mappable) {
245 mappable_size += obj->gtt_space->size;
246 ++mappable_count;
247 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200248 if (obj->madv == I915_MADV_DONTNEED) {
249 purgeable_size += obj->base.size;
250 ++purgeable_count;
251 }
Chris Wilson6299f992010-11-24 12:23:44 +0000252 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200253 seq_printf(m, "%u purgeable objects, %zu bytes\n",
254 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000255 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
256 mappable_count, mappable_size);
257 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
258 count, size);
259
260 seq_printf(m, "%zu [%zu] gtt total\n",
261 dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
Chris Wilson73aa8082010-09-30 11:46:12 +0100262
263 mutex_unlock(&dev->struct_mutex);
264
265 return 0;
266}
267
Chris Wilson08c18322011-01-10 00:00:24 +0000268static int i915_gem_gtt_info(struct seq_file *m, void* data)
269{
270 struct drm_info_node *node = (struct drm_info_node *) m->private;
271 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100272 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000273 struct drm_i915_private *dev_priv = dev->dev_private;
274 struct drm_i915_gem_object *obj;
275 size_t total_obj_size, total_gtt_size;
276 int count, ret;
277
278 ret = mutex_lock_interruptible(&dev->struct_mutex);
279 if (ret)
280 return ret;
281
282 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200283 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100284 if (list == PINNED_LIST && obj->pin_count == 0)
285 continue;
286
Chris Wilson08c18322011-01-10 00:00:24 +0000287 seq_printf(m, " ");
288 describe_obj(m, obj);
289 seq_printf(m, "\n");
290 total_obj_size += obj->base.size;
291 total_gtt_size += obj->gtt_space->size;
292 count++;
293 }
294
295 mutex_unlock(&dev->struct_mutex);
296
297 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
298 count, total_obj_size, total_gtt_size);
299
300 return 0;
301}
302
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100303static int i915_gem_pageflip_info(struct seq_file *m, void *data)
304{
305 struct drm_info_node *node = (struct drm_info_node *) m->private;
306 struct drm_device *dev = node->minor->dev;
307 unsigned long flags;
308 struct intel_crtc *crtc;
309
310 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800311 const char pipe = pipe_name(crtc->pipe);
312 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100313 struct intel_unpin_work *work;
314
315 spin_lock_irqsave(&dev->event_lock, flags);
316 work = crtc->unpin_work;
317 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800318 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100319 pipe, plane);
320 } else {
321 if (!work->pending) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800322 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100323 pipe, plane);
324 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800325 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100326 pipe, plane);
327 }
328 if (work->enable_stall_check)
329 seq_printf(m, "Stall check enabled, ");
330 else
331 seq_printf(m, "Stall check waiting for page flip ioctl, ");
332 seq_printf(m, "%d prepares\n", work->pending);
333
334 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000335 struct drm_i915_gem_object *obj = work->old_fb_obj;
336 if (obj)
337 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100338 }
339 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000340 struct drm_i915_gem_object *obj = work->pending_flip_obj;
341 if (obj)
342 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100343 }
344 }
345 spin_unlock_irqrestore(&dev->event_lock, flags);
346 }
347
348 return 0;
349}
350
Ben Gamari20172632009-02-17 20:08:50 -0500351static int i915_gem_request_info(struct seq_file *m, void *data)
352{
353 struct drm_info_node *node = (struct drm_info_node *) m->private;
354 struct drm_device *dev = node->minor->dev;
355 drm_i915_private_t *dev_priv = dev->dev_private;
356 struct drm_i915_gem_request *gem_request;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100357 int ret, count;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100358
359 ret = mutex_lock_interruptible(&dev->struct_mutex);
360 if (ret)
361 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500362
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100363 count = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000364 if (!list_empty(&dev_priv->ring[RCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100365 seq_printf(m, "Render requests:\n");
366 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000367 &dev_priv->ring[RCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100368 list) {
369 seq_printf(m, " %d @ %d\n",
370 gem_request->seqno,
371 (int) (jiffies - gem_request->emitted_jiffies));
372 }
373 count++;
374 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000375 if (!list_empty(&dev_priv->ring[VCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100376 seq_printf(m, "BSD requests:\n");
377 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000378 &dev_priv->ring[VCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100379 list) {
380 seq_printf(m, " %d @ %d\n",
381 gem_request->seqno,
382 (int) (jiffies - gem_request->emitted_jiffies));
383 }
384 count++;
385 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000386 if (!list_empty(&dev_priv->ring[BCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100387 seq_printf(m, "BLT requests:\n");
388 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000389 &dev_priv->ring[BCS].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++;
Ben Gamari20172632009-02-17 20:08:50 -0500396 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100397 mutex_unlock(&dev->struct_mutex);
398
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100399 if (count == 0)
400 seq_printf(m, "No requests\n");
401
Ben Gamari20172632009-02-17 20:08:50 -0500402 return 0;
403}
404
Chris Wilsonb2223492010-10-27 15:27:33 +0100405static void i915_ring_seqno_info(struct seq_file *m,
406 struct intel_ring_buffer *ring)
407{
408 if (ring->get_seqno) {
409 seq_printf(m, "Current sequence (%s): %d\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100410 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100411 }
412}
413
Ben Gamari20172632009-02-17 20:08:50 -0500414static int i915_gem_seqno_info(struct seq_file *m, void *data)
415{
416 struct drm_info_node *node = (struct drm_info_node *) m->private;
417 struct drm_device *dev = node->minor->dev;
418 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000419 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100420
421 ret = mutex_lock_interruptible(&dev->struct_mutex);
422 if (ret)
423 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500424
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000425 for (i = 0; i < I915_NUM_RINGS; i++)
426 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100427
428 mutex_unlock(&dev->struct_mutex);
429
Ben Gamari20172632009-02-17 20:08:50 -0500430 return 0;
431}
432
433
434static int i915_interrupt_info(struct seq_file *m, void *data)
435{
436 struct drm_info_node *node = (struct drm_info_node *) m->private;
437 struct drm_device *dev = node->minor->dev;
438 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800439 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100440
441 ret = mutex_lock_interruptible(&dev->struct_mutex);
442 if (ret)
443 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500444
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700445 if (IS_VALLEYVIEW(dev)) {
446 seq_printf(m, "Display IER:\t%08x\n",
447 I915_READ(VLV_IER));
448 seq_printf(m, "Display IIR:\t%08x\n",
449 I915_READ(VLV_IIR));
450 seq_printf(m, "Display IIR_RW:\t%08x\n",
451 I915_READ(VLV_IIR_RW));
452 seq_printf(m, "Display IMR:\t%08x\n",
453 I915_READ(VLV_IMR));
454 for_each_pipe(pipe)
455 seq_printf(m, "Pipe %c stat:\t%08x\n",
456 pipe_name(pipe),
457 I915_READ(PIPESTAT(pipe)));
458
459 seq_printf(m, "Master IER:\t%08x\n",
460 I915_READ(VLV_MASTER_IER));
461
462 seq_printf(m, "Render IER:\t%08x\n",
463 I915_READ(GTIER));
464 seq_printf(m, "Render IIR:\t%08x\n",
465 I915_READ(GTIIR));
466 seq_printf(m, "Render IMR:\t%08x\n",
467 I915_READ(GTIMR));
468
469 seq_printf(m, "PM IER:\t\t%08x\n",
470 I915_READ(GEN6_PMIER));
471 seq_printf(m, "PM IIR:\t\t%08x\n",
472 I915_READ(GEN6_PMIIR));
473 seq_printf(m, "PM IMR:\t\t%08x\n",
474 I915_READ(GEN6_PMIMR));
475
476 seq_printf(m, "Port hotplug:\t%08x\n",
477 I915_READ(PORT_HOTPLUG_EN));
478 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
479 I915_READ(VLV_DPFLIPSTAT));
480 seq_printf(m, "DPINVGTT:\t%08x\n",
481 I915_READ(DPINVGTT));
482
483 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800484 seq_printf(m, "Interrupt enable: %08x\n",
485 I915_READ(IER));
486 seq_printf(m, "Interrupt identity: %08x\n",
487 I915_READ(IIR));
488 seq_printf(m, "Interrupt mask: %08x\n",
489 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800490 for_each_pipe(pipe)
491 seq_printf(m, "Pipe %c stat: %08x\n",
492 pipe_name(pipe),
493 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800494 } else {
495 seq_printf(m, "North Display Interrupt enable: %08x\n",
496 I915_READ(DEIER));
497 seq_printf(m, "North Display Interrupt identity: %08x\n",
498 I915_READ(DEIIR));
499 seq_printf(m, "North Display Interrupt mask: %08x\n",
500 I915_READ(DEIMR));
501 seq_printf(m, "South Display Interrupt enable: %08x\n",
502 I915_READ(SDEIER));
503 seq_printf(m, "South Display Interrupt identity: %08x\n",
504 I915_READ(SDEIIR));
505 seq_printf(m, "South Display Interrupt mask: %08x\n",
506 I915_READ(SDEIMR));
507 seq_printf(m, "Graphics Interrupt enable: %08x\n",
508 I915_READ(GTIER));
509 seq_printf(m, "Graphics Interrupt identity: %08x\n",
510 I915_READ(GTIIR));
511 seq_printf(m, "Graphics Interrupt mask: %08x\n",
512 I915_READ(GTIMR));
513 }
Ben Gamari20172632009-02-17 20:08:50 -0500514 seq_printf(m, "Interrupts received: %d\n",
515 atomic_read(&dev_priv->irq_received));
Chris Wilson9862e602011-01-04 22:22:17 +0000516 for (i = 0; i < I915_NUM_RINGS; i++) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700517 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilson9862e602011-01-04 22:22:17 +0000518 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
519 dev_priv->ring[i].name,
520 I915_READ_IMR(&dev_priv->ring[i]));
521 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000522 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilson9862e602011-01-04 22:22:17 +0000523 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100524 mutex_unlock(&dev->struct_mutex);
525
Ben Gamari20172632009-02-17 20:08:50 -0500526 return 0;
527}
528
Chris Wilsona6172a82009-02-11 14:26:38 +0000529static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
530{
531 struct drm_info_node *node = (struct drm_info_node *) m->private;
532 struct drm_device *dev = node->minor->dev;
533 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100534 int i, ret;
535
536 ret = mutex_lock_interruptible(&dev->struct_mutex);
537 if (ret)
538 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000539
540 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
541 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
542 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000543 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000544
Chris Wilson6c085a72012-08-20 11:40:46 +0200545 seq_printf(m, "Fence %d, pin count = %d, object = ",
546 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100547 if (obj == NULL)
548 seq_printf(m, "unused");
549 else
Chris Wilson05394f32010-11-08 19:18:58 +0000550 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100551 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000552 }
553
Chris Wilson05394f32010-11-08 19:18:58 +0000554 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000555 return 0;
556}
557
Ben Gamari20172632009-02-17 20:08:50 -0500558static int i915_hws_info(struct seq_file *m, void *data)
559{
560 struct drm_info_node *node = (struct drm_info_node *) m->private;
561 struct drm_device *dev = node->minor->dev;
562 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100563 struct intel_ring_buffer *ring;
Chris Wilson311bd682011-01-13 19:06:50 +0000564 const volatile u32 __iomem *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100565 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500566
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000567 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilson311bd682011-01-13 19:06:50 +0000568 hws = (volatile u32 __iomem *)ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500569 if (hws == NULL)
570 return 0;
571
572 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
573 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
574 i * 4,
575 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
576 }
577 return 0;
578}
579
Chris Wilsone5c65262010-11-01 11:35:28 +0000580static const char *ring_str(int ring)
581{
582 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100583 case RCS: return "render";
584 case VCS: return "bsd";
585 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000586 default: return "";
587 }
588}
589
Chris Wilson9df30792010-02-18 10:24:56 +0000590static const char *pin_flag(int pinned)
591{
592 if (pinned > 0)
593 return " P";
594 else if (pinned < 0)
595 return " p";
596 else
597 return "";
598}
599
600static const char *tiling_flag(int tiling)
601{
602 switch (tiling) {
603 default:
604 case I915_TILING_NONE: return "";
605 case I915_TILING_X: return " X";
606 case I915_TILING_Y: return " Y";
607 }
608}
609
610static const char *dirty_flag(int dirty)
611{
612 return dirty ? " dirty" : "";
613}
614
615static const char *purgeable_flag(int purgeable)
616{
617 return purgeable ? " purgeable" : "";
618}
619
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000620static void print_error_buffers(struct seq_file *m,
621 const char *name,
622 struct drm_i915_error_buffer *err,
623 int count)
624{
625 seq_printf(m, "%s [%d]:\n", name, count);
626
627 while (count--) {
Chris Wilson0201f1e2012-07-20 12:41:01 +0100628 seq_printf(m, " %08x %8u %04x %04x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000629 err->gtt_offset,
630 err->size,
631 err->read_domains,
632 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100633 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000634 pin_flag(err->pinned),
635 tiling_flag(err->tiling),
636 dirty_flag(err->dirty),
637 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100638 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000639 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700640 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000641
642 if (err->name)
643 seq_printf(m, " (name: %d)", err->name);
644 if (err->fence_reg != I915_FENCE_REG_NONE)
645 seq_printf(m, " (fence: %d)", err->fence_reg);
646
647 seq_printf(m, "\n");
648 err++;
649 }
650}
651
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100652static void i915_ring_error_state(struct seq_file *m,
653 struct drm_device *dev,
654 struct drm_i915_error_state *error,
655 unsigned ring)
656{
Ben Widawskyec34a012012-04-03 23:03:00 -0700657 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100658 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100659 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
660 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100661 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
662 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
663 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
664 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100665 if (ring == RCS && INTEL_INFO(dev)->gen >= 4) {
666 seq_printf(m, " INSTDONE1: 0x%08x\n", error->instdone1);
667 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100668 }
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100669 if (INTEL_INFO(dev)->gen >= 4)
670 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
671 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200672 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100673 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100674 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100675 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100676 seq_printf(m, " SYNC_0: 0x%08x\n",
677 error->semaphore_mboxes[ring][0]);
678 seq_printf(m, " SYNC_1: 0x%08x\n",
679 error->semaphore_mboxes[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100680 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100681 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Ben Widawsky9574b3f2012-04-26 16:03:01 -0700682 seq_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100683 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
684 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100685}
686
Daniel Vetterd5442302012-04-27 15:17:40 +0200687struct i915_error_state_file_priv {
688 struct drm_device *dev;
689 struct drm_i915_error_state *error;
690};
691
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700692static int i915_error_state(struct seq_file *m, void *unused)
693{
Daniel Vetterd5442302012-04-27 15:17:40 +0200694 struct i915_error_state_file_priv *error_priv = m->private;
695 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700696 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200697 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100698 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000699 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700700
Daniel Vetter742cbee2012-04-27 15:17:39 +0200701 if (!error) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700702 seq_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200703 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700704 }
705
Jesse Barnes8a905232009-07-11 16:48:03 -0400706 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
707 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000708 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100709 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700710 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100711 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700712 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000713
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100714 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100715 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
716
Daniel Vetter33f3f512011-12-14 13:57:39 +0100717 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100718 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100719 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
720 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100721
Chris Wilsonb4519512012-05-11 14:29:30 +0100722 for_each_ring(ring, dev_priv, i)
723 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100724
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000725 if (error->active_bo)
726 print_error_buffers(m, "Active",
727 error->active_bo,
728 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000729
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000730 if (error->pinned_bo)
731 print_error_buffers(m, "Pinned",
732 error->pinned_bo,
733 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000734
Chris Wilson52d39a22012-02-15 11:25:37 +0000735 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
736 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000737
Chris Wilson52d39a22012-02-15 11:25:37 +0000738 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000739 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
740 dev_priv->ring[i].name,
741 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000742 offset = 0;
743 for (page = 0; page < obj->page_count; page++) {
744 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
745 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
746 offset += 4;
747 }
748 }
749 }
Chris Wilson9df30792010-02-18 10:24:56 +0000750
Chris Wilson52d39a22012-02-15 11:25:37 +0000751 if (error->ring[i].num_requests) {
752 seq_printf(m, "%s --- %d requests\n",
753 dev_priv->ring[i].name,
754 error->ring[i].num_requests);
755 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000756 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000757 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000758 error->ring[i].requests[j].jiffies,
759 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000760 }
761 }
762
763 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000764 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
765 dev_priv->ring[i].name,
766 obj->gtt_offset);
767 offset = 0;
768 for (page = 0; page < obj->page_count; page++) {
769 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
770 seq_printf(m, "%08x : %08x\n",
771 offset,
772 obj->pages[page][elt]);
773 offset += 4;
774 }
Chris Wilson9df30792010-02-18 10:24:56 +0000775 }
776 }
777 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700778
Chris Wilson6ef3d422010-08-04 20:26:07 +0100779 if (error->overlay)
780 intel_overlay_print_error_state(m, error->overlay);
781
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000782 if (error->display)
783 intel_display_print_error_state(m, dev, error->display);
784
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700785 return 0;
786}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700787
Daniel Vetterd5442302012-04-27 15:17:40 +0200788static ssize_t
789i915_error_state_write(struct file *filp,
790 const char __user *ubuf,
791 size_t cnt,
792 loff_t *ppos)
793{
794 struct seq_file *m = filp->private_data;
795 struct i915_error_state_file_priv *error_priv = m->private;
796 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200797 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200798
799 DRM_DEBUG_DRIVER("Resetting error state\n");
800
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200801 ret = mutex_lock_interruptible(&dev->struct_mutex);
802 if (ret)
803 return ret;
804
Daniel Vetterd5442302012-04-27 15:17:40 +0200805 i915_destroy_error_state(dev);
806 mutex_unlock(&dev->struct_mutex);
807
808 return cnt;
809}
810
811static int i915_error_state_open(struct inode *inode, struct file *file)
812{
813 struct drm_device *dev = inode->i_private;
814 drm_i915_private_t *dev_priv = dev->dev_private;
815 struct i915_error_state_file_priv *error_priv;
816 unsigned long flags;
817
818 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
819 if (!error_priv)
820 return -ENOMEM;
821
822 error_priv->dev = dev;
823
824 spin_lock_irqsave(&dev_priv->error_lock, flags);
825 error_priv->error = dev_priv->first_error;
826 if (error_priv->error)
827 kref_get(&error_priv->error->ref);
828 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
829
830 return single_open(file, i915_error_state, error_priv);
831}
832
833static int i915_error_state_release(struct inode *inode, struct file *file)
834{
835 struct seq_file *m = file->private_data;
836 struct i915_error_state_file_priv *error_priv = m->private;
837
838 if (error_priv->error)
839 kref_put(&error_priv->error->ref, i915_error_state_free);
840 kfree(error_priv);
841
842 return single_release(inode, file);
843}
844
845static const struct file_operations i915_error_state_fops = {
846 .owner = THIS_MODULE,
847 .open = i915_error_state_open,
848 .read = seq_read,
849 .write = i915_error_state_write,
850 .llseek = default_llseek,
851 .release = i915_error_state_release,
852};
853
Jesse Barnesf97108d2010-01-29 11:27:07 -0800854static int i915_rstdby_delays(struct seq_file *m, void *unused)
855{
856 struct drm_info_node *node = (struct drm_info_node *) m->private;
857 struct drm_device *dev = node->minor->dev;
858 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700859 u16 crstanddelay;
860 int ret;
861
862 ret = mutex_lock_interruptible(&dev->struct_mutex);
863 if (ret)
864 return ret;
865
866 crstanddelay = I915_READ16(CRSTANDVID);
867
868 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800869
870 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
871
872 return 0;
873}
874
875static int i915_cur_delayinfo(struct seq_file *m, void *unused)
876{
877 struct drm_info_node *node = (struct drm_info_node *) m->private;
878 struct drm_device *dev = node->minor->dev;
879 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100880 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800881
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800882 if (IS_GEN5(dev)) {
883 u16 rgvswctl = I915_READ16(MEMSWCTL);
884 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
885
886 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
887 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
888 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
889 MEMSTAT_VID_SHIFT);
890 seq_printf(m, "Current P-state: %d\n",
891 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700892 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800893 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
894 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
895 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800896 u32 rpstat;
897 u32 rpupei, rpcurup, rpprevup;
898 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800899 int max_freq;
900
901 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100902 ret = mutex_lock_interruptible(&dev->struct_mutex);
903 if (ret)
904 return ret;
905
Ben Widawskyfcca7922011-04-25 11:23:07 -0700906 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800907
Jesse Barnesccab5c82011-01-18 15:49:25 -0800908 rpstat = I915_READ(GEN6_RPSTAT1);
909 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
910 rpcurup = I915_READ(GEN6_RP_CUR_UP);
911 rpprevup = I915_READ(GEN6_RP_PREV_UP);
912 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
913 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
914 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
915
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100916 gen6_gt_force_wake_put(dev_priv);
917 mutex_unlock(&dev->struct_mutex);
918
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800919 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800920 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800921 seq_printf(m, "Render p-state ratio: %d\n",
922 (gt_perf_status & 0xff00) >> 8);
923 seq_printf(m, "Render p-state VID: %d\n",
924 gt_perf_status & 0xff);
925 seq_printf(m, "Render p-state limit: %d\n",
926 rp_state_limits & 0xff);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800927 seq_printf(m, "CAGF: %dMHz\n", ((rpstat & GEN6_CAGF_MASK) >>
Jesse Barnese281fca2011-03-18 10:32:07 -0700928 GEN6_CAGF_SHIFT) * 50);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800929 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
930 GEN6_CURICONT_MASK);
931 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
932 GEN6_CURBSYTAVG_MASK);
933 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
934 GEN6_CURBSYTAVG_MASK);
935 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
936 GEN6_CURIAVG_MASK);
937 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
938 GEN6_CURBSYTAVG_MASK);
939 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
940 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800941
942 max_freq = (rp_state_cap & 0xff0000) >> 16;
943 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700944 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800945
946 max_freq = (rp_state_cap & 0xff00) >> 8;
947 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700948 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800949
950 max_freq = rp_state_cap & 0xff;
951 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700952 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800953 } else {
954 seq_printf(m, "no P-state info available\n");
955 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800956
957 return 0;
958}
959
960static int i915_delayfreq_table(struct seq_file *m, void *unused)
961{
962 struct drm_info_node *node = (struct drm_info_node *) m->private;
963 struct drm_device *dev = node->minor->dev;
964 drm_i915_private_t *dev_priv = dev->dev_private;
965 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700966 int ret, i;
967
968 ret = mutex_lock_interruptible(&dev->struct_mutex);
969 if (ret)
970 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800971
972 for (i = 0; i < 16; i++) {
973 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700974 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
975 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800976 }
977
Ben Widawsky616fdb52011-10-05 11:44:54 -0700978 mutex_unlock(&dev->struct_mutex);
979
Jesse Barnesf97108d2010-01-29 11:27:07 -0800980 return 0;
981}
982
983static inline int MAP_TO_MV(int map)
984{
985 return 1250 - (map * 25);
986}
987
988static int i915_inttoext_table(struct seq_file *m, void *unused)
989{
990 struct drm_info_node *node = (struct drm_info_node *) m->private;
991 struct drm_device *dev = node->minor->dev;
992 drm_i915_private_t *dev_priv = dev->dev_private;
993 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700994 int ret, i;
995
996 ret = mutex_lock_interruptible(&dev->struct_mutex);
997 if (ret)
998 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800999
1000 for (i = 1; i <= 32; i++) {
1001 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1002 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1003 }
1004
Ben Widawsky616fdb52011-10-05 11:44:54 -07001005 mutex_unlock(&dev->struct_mutex);
1006
Jesse Barnesf97108d2010-01-29 11:27:07 -08001007 return 0;
1008}
1009
Ben Widawsky4d855292011-12-12 19:34:16 -08001010static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001011{
1012 struct drm_info_node *node = (struct drm_info_node *) m->private;
1013 struct drm_device *dev = node->minor->dev;
1014 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001015 u32 rgvmodectl, rstdbyctl;
1016 u16 crstandvid;
1017 int ret;
1018
1019 ret = mutex_lock_interruptible(&dev->struct_mutex);
1020 if (ret)
1021 return ret;
1022
1023 rgvmodectl = I915_READ(MEMMODECTL);
1024 rstdbyctl = I915_READ(RSTDBYCTL);
1025 crstandvid = I915_READ16(CRSTANDVID);
1026
1027 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001028
1029 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1030 "yes" : "no");
1031 seq_printf(m, "Boost freq: %d\n",
1032 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1033 MEMMODE_BOOST_FREQ_SHIFT);
1034 seq_printf(m, "HW control enabled: %s\n",
1035 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1036 seq_printf(m, "SW control enabled: %s\n",
1037 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1038 seq_printf(m, "Gated voltage change: %s\n",
1039 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1040 seq_printf(m, "Starting frequency: P%d\n",
1041 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001042 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001043 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001044 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1045 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1046 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1047 seq_printf(m, "Render standby enabled: %s\n",
1048 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001049 seq_printf(m, "Current RS state: ");
1050 switch (rstdbyctl & RSX_STATUS_MASK) {
1051 case RSX_STATUS_ON:
1052 seq_printf(m, "on\n");
1053 break;
1054 case RSX_STATUS_RC1:
1055 seq_printf(m, "RC1\n");
1056 break;
1057 case RSX_STATUS_RC1E:
1058 seq_printf(m, "RC1E\n");
1059 break;
1060 case RSX_STATUS_RS1:
1061 seq_printf(m, "RS1\n");
1062 break;
1063 case RSX_STATUS_RS2:
1064 seq_printf(m, "RS2 (RC6)\n");
1065 break;
1066 case RSX_STATUS_RS3:
1067 seq_printf(m, "RC3 (RC6+)\n");
1068 break;
1069 default:
1070 seq_printf(m, "unknown\n");
1071 break;
1072 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001073
1074 return 0;
1075}
1076
Ben Widawsky4d855292011-12-12 19:34:16 -08001077static int gen6_drpc_info(struct seq_file *m)
1078{
1079
1080 struct drm_info_node *node = (struct drm_info_node *) m->private;
1081 struct drm_device *dev = node->minor->dev;
1082 struct drm_i915_private *dev_priv = dev->dev_private;
1083 u32 rpmodectl1, gt_core_status, rcctl1;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001084 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001085 int count=0, ret;
1086
1087
1088 ret = mutex_lock_interruptible(&dev->struct_mutex);
1089 if (ret)
1090 return ret;
1091
Daniel Vetter93b525d2012-01-25 13:52:43 +01001092 spin_lock_irq(&dev_priv->gt_lock);
1093 forcewake_count = dev_priv->forcewake_count;
1094 spin_unlock_irq(&dev_priv->gt_lock);
1095
1096 if (forcewake_count) {
1097 seq_printf(m, "RC information inaccurate because somebody "
1098 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001099 } else {
1100 /* NB: we cannot use forcewake, else we read the wrong values */
1101 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1102 udelay(10);
1103 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1104 }
1105
1106 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1107 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1108
1109 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1110 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1111 mutex_unlock(&dev->struct_mutex);
1112
1113 seq_printf(m, "Video Turbo Mode: %s\n",
1114 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1115 seq_printf(m, "HW control enabled: %s\n",
1116 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1117 seq_printf(m, "SW control enabled: %s\n",
1118 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1119 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001120 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001121 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1122 seq_printf(m, "RC6 Enabled: %s\n",
1123 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1124 seq_printf(m, "Deep RC6 Enabled: %s\n",
1125 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1126 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1127 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1128 seq_printf(m, "Current RC state: ");
1129 switch (gt_core_status & GEN6_RCn_MASK) {
1130 case GEN6_RC0:
1131 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1132 seq_printf(m, "Core Power Down\n");
1133 else
1134 seq_printf(m, "on\n");
1135 break;
1136 case GEN6_RC3:
1137 seq_printf(m, "RC3\n");
1138 break;
1139 case GEN6_RC6:
1140 seq_printf(m, "RC6\n");
1141 break;
1142 case GEN6_RC7:
1143 seq_printf(m, "RC7\n");
1144 break;
1145 default:
1146 seq_printf(m, "Unknown\n");
1147 break;
1148 }
1149
1150 seq_printf(m, "Core Power Down: %s\n",
1151 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001152
1153 /* Not exactly sure what this is */
1154 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1155 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1156 seq_printf(m, "RC6 residency since boot: %u\n",
1157 I915_READ(GEN6_GT_GFX_RC6));
1158 seq_printf(m, "RC6+ residency since boot: %u\n",
1159 I915_READ(GEN6_GT_GFX_RC6p));
1160 seq_printf(m, "RC6++ residency since boot: %u\n",
1161 I915_READ(GEN6_GT_GFX_RC6pp));
1162
Ben Widawsky4d855292011-12-12 19:34:16 -08001163 return 0;
1164}
1165
1166static int i915_drpc_info(struct seq_file *m, void *unused)
1167{
1168 struct drm_info_node *node = (struct drm_info_node *) m->private;
1169 struct drm_device *dev = node->minor->dev;
1170
1171 if (IS_GEN6(dev) || IS_GEN7(dev))
1172 return gen6_drpc_info(m);
1173 else
1174 return ironlake_drpc_info(m);
1175}
1176
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001177static int i915_fbc_status(struct seq_file *m, void *unused)
1178{
1179 struct drm_info_node *node = (struct drm_info_node *) m->private;
1180 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001181 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001182
Adam Jacksonee5382a2010-04-23 11:17:39 -04001183 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001184 seq_printf(m, "FBC unsupported on this chipset\n");
1185 return 0;
1186 }
1187
Adam Jacksonee5382a2010-04-23 11:17:39 -04001188 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001189 seq_printf(m, "FBC enabled\n");
1190 } else {
1191 seq_printf(m, "FBC disabled: ");
1192 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001193 case FBC_NO_OUTPUT:
1194 seq_printf(m, "no outputs");
1195 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001196 case FBC_STOLEN_TOO_SMALL:
1197 seq_printf(m, "not enough stolen memory");
1198 break;
1199 case FBC_UNSUPPORTED_MODE:
1200 seq_printf(m, "mode not supported");
1201 break;
1202 case FBC_MODE_TOO_LARGE:
1203 seq_printf(m, "mode too large");
1204 break;
1205 case FBC_BAD_PLANE:
1206 seq_printf(m, "FBC unsupported on plane");
1207 break;
1208 case FBC_NOT_TILED:
1209 seq_printf(m, "scanout buffer not tiled");
1210 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001211 case FBC_MULTIPLE_PIPES:
1212 seq_printf(m, "multiple pipes are enabled");
1213 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001214 case FBC_MODULE_PARAM:
1215 seq_printf(m, "disabled per module param (default off)");
1216 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001217 default:
1218 seq_printf(m, "unknown reason");
1219 }
1220 seq_printf(m, "\n");
1221 }
1222 return 0;
1223}
1224
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001225static int i915_sr_status(struct seq_file *m, void *unused)
1226{
1227 struct drm_info_node *node = (struct drm_info_node *) m->private;
1228 struct drm_device *dev = node->minor->dev;
1229 drm_i915_private_t *dev_priv = dev->dev_private;
1230 bool sr_enabled = false;
1231
Yuanhan Liu13982612010-12-15 15:42:31 +08001232 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001233 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001234 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001235 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1236 else if (IS_I915GM(dev))
1237 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1238 else if (IS_PINEVIEW(dev))
1239 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1240
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001241 seq_printf(m, "self-refresh: %s\n",
1242 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001243
1244 return 0;
1245}
1246
Jesse Barnes7648fa92010-05-20 14:28:11 -07001247static int i915_emon_status(struct seq_file *m, void *unused)
1248{
1249 struct drm_info_node *node = (struct drm_info_node *) m->private;
1250 struct drm_device *dev = node->minor->dev;
1251 drm_i915_private_t *dev_priv = dev->dev_private;
1252 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001253 int ret;
1254
Chris Wilson582be6b2012-04-30 19:35:02 +01001255 if (!IS_GEN5(dev))
1256 return -ENODEV;
1257
Chris Wilsonde227ef2010-07-03 07:58:38 +01001258 ret = mutex_lock_interruptible(&dev->struct_mutex);
1259 if (ret)
1260 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001261
1262 temp = i915_mch_val(dev_priv);
1263 chipset = i915_chipset_val(dev_priv);
1264 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001265 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001266
1267 seq_printf(m, "GMCH temp: %ld\n", temp);
1268 seq_printf(m, "Chipset power: %ld\n", chipset);
1269 seq_printf(m, "GFX power: %ld\n", gfx);
1270 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1271
1272 return 0;
1273}
1274
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001275static int i915_ring_freq_table(struct seq_file *m, void *unused)
1276{
1277 struct drm_info_node *node = (struct drm_info_node *) m->private;
1278 struct drm_device *dev = node->minor->dev;
1279 drm_i915_private_t *dev_priv = dev->dev_private;
1280 int ret;
1281 int gpu_freq, ia_freq;
1282
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001283 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001284 seq_printf(m, "unsupported on this chipset\n");
1285 return 0;
1286 }
1287
1288 ret = mutex_lock_interruptible(&dev->struct_mutex);
1289 if (ret)
1290 return ret;
1291
1292 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1293
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001294 for (gpu_freq = dev_priv->rps.min_delay;
1295 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001296 gpu_freq++) {
1297 I915_WRITE(GEN6_PCODE_DATA, gpu_freq);
1298 I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY |
1299 GEN6_PCODE_READ_MIN_FREQ_TABLE);
1300 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) &
1301 GEN6_PCODE_READY) == 0, 10)) {
1302 DRM_ERROR("pcode read of freq table timed out\n");
1303 continue;
1304 }
1305 ia_freq = I915_READ(GEN6_PCODE_DATA);
1306 seq_printf(m, "%d\t\t%d\n", gpu_freq * 50, ia_freq * 100);
1307 }
1308
1309 mutex_unlock(&dev->struct_mutex);
1310
1311 return 0;
1312}
1313
Jesse Barnes7648fa92010-05-20 14:28:11 -07001314static int i915_gfxec(struct seq_file *m, void *unused)
1315{
1316 struct drm_info_node *node = (struct drm_info_node *) m->private;
1317 struct drm_device *dev = node->minor->dev;
1318 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001319 int ret;
1320
1321 ret = mutex_lock_interruptible(&dev->struct_mutex);
1322 if (ret)
1323 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001324
1325 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1326
Ben Widawsky616fdb52011-10-05 11:44:54 -07001327 mutex_unlock(&dev->struct_mutex);
1328
Jesse Barnes7648fa92010-05-20 14:28:11 -07001329 return 0;
1330}
1331
Chris Wilson44834a62010-08-19 16:09:23 +01001332static int i915_opregion(struct seq_file *m, void *unused)
1333{
1334 struct drm_info_node *node = (struct drm_info_node *) m->private;
1335 struct drm_device *dev = node->minor->dev;
1336 drm_i915_private_t *dev_priv = dev->dev_private;
1337 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001338 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001339 int ret;
1340
Daniel Vetter0d38f002012-04-21 22:49:10 +02001341 if (data == NULL)
1342 return -ENOMEM;
1343
Chris Wilson44834a62010-08-19 16:09:23 +01001344 ret = mutex_lock_interruptible(&dev->struct_mutex);
1345 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001346 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001347
Daniel Vetter0d38f002012-04-21 22:49:10 +02001348 if (opregion->header) {
1349 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1350 seq_write(m, data, OPREGION_SIZE);
1351 }
Chris Wilson44834a62010-08-19 16:09:23 +01001352
1353 mutex_unlock(&dev->struct_mutex);
1354
Daniel Vetter0d38f002012-04-21 22:49:10 +02001355out:
1356 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001357 return 0;
1358}
1359
Chris Wilson37811fc2010-08-25 22:45:57 +01001360static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1361{
1362 struct drm_info_node *node = (struct drm_info_node *) m->private;
1363 struct drm_device *dev = node->minor->dev;
1364 drm_i915_private_t *dev_priv = dev->dev_private;
1365 struct intel_fbdev *ifbdev;
1366 struct intel_framebuffer *fb;
1367 int ret;
1368
1369 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1370 if (ret)
1371 return ret;
1372
1373 ifbdev = dev_priv->fbdev;
1374 fb = to_intel_framebuffer(ifbdev->helper.fb);
1375
1376 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1377 fb->base.width,
1378 fb->base.height,
1379 fb->base.depth,
1380 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001381 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001382 seq_printf(m, "\n");
1383
1384 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1385 if (&fb->base == ifbdev->helper.fb)
1386 continue;
1387
1388 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1389 fb->base.width,
1390 fb->base.height,
1391 fb->base.depth,
1392 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001393 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001394 seq_printf(m, "\n");
1395 }
1396
1397 mutex_unlock(&dev->mode_config.mutex);
1398
1399 return 0;
1400}
1401
Ben Widawskye76d3632011-03-19 18:14:29 -07001402static int i915_context_status(struct seq_file *m, void *unused)
1403{
1404 struct drm_info_node *node = (struct drm_info_node *) m->private;
1405 struct drm_device *dev = node->minor->dev;
1406 drm_i915_private_t *dev_priv = dev->dev_private;
1407 int ret;
1408
1409 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1410 if (ret)
1411 return ret;
1412
Ben Widawskydc501fb2011-06-29 11:41:51 -07001413 if (dev_priv->pwrctx) {
1414 seq_printf(m, "power context ");
1415 describe_obj(m, dev_priv->pwrctx);
1416 seq_printf(m, "\n");
1417 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001418
Ben Widawskydc501fb2011-06-29 11:41:51 -07001419 if (dev_priv->renderctx) {
1420 seq_printf(m, "render context ");
1421 describe_obj(m, dev_priv->renderctx);
1422 seq_printf(m, "\n");
1423 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001424
1425 mutex_unlock(&dev->mode_config.mutex);
1426
1427 return 0;
1428}
1429
Ben Widawsky6d794d42011-04-25 11:25:56 -07001430static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1431{
1432 struct drm_info_node *node = (struct drm_info_node *) m->private;
1433 struct drm_device *dev = node->minor->dev;
1434 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001435 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001436
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001437 spin_lock_irq(&dev_priv->gt_lock);
1438 forcewake_count = dev_priv->forcewake_count;
1439 spin_unlock_irq(&dev_priv->gt_lock);
1440
1441 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001442
1443 return 0;
1444}
1445
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001446static const char *swizzle_string(unsigned swizzle)
1447{
1448 switch(swizzle) {
1449 case I915_BIT_6_SWIZZLE_NONE:
1450 return "none";
1451 case I915_BIT_6_SWIZZLE_9:
1452 return "bit9";
1453 case I915_BIT_6_SWIZZLE_9_10:
1454 return "bit9/bit10";
1455 case I915_BIT_6_SWIZZLE_9_11:
1456 return "bit9/bit11";
1457 case I915_BIT_6_SWIZZLE_9_10_11:
1458 return "bit9/bit10/bit11";
1459 case I915_BIT_6_SWIZZLE_9_17:
1460 return "bit9/bit17";
1461 case I915_BIT_6_SWIZZLE_9_10_17:
1462 return "bit9/bit10/bit17";
1463 case I915_BIT_6_SWIZZLE_UNKNOWN:
1464 return "unkown";
1465 }
1466
1467 return "bug";
1468}
1469
1470static int i915_swizzle_info(struct seq_file *m, void *data)
1471{
1472 struct drm_info_node *node = (struct drm_info_node *) m->private;
1473 struct drm_device *dev = node->minor->dev;
1474 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001475 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001476
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001477 ret = mutex_lock_interruptible(&dev->struct_mutex);
1478 if (ret)
1479 return ret;
1480
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001481 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1482 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1483 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1484 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1485
1486 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1487 seq_printf(m, "DDC = 0x%08x\n",
1488 I915_READ(DCC));
1489 seq_printf(m, "C0DRB3 = 0x%04x\n",
1490 I915_READ16(C0DRB3));
1491 seq_printf(m, "C1DRB3 = 0x%04x\n",
1492 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001493 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1494 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1495 I915_READ(MAD_DIMM_C0));
1496 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1497 I915_READ(MAD_DIMM_C1));
1498 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1499 I915_READ(MAD_DIMM_C2));
1500 seq_printf(m, "TILECTL = 0x%08x\n",
1501 I915_READ(TILECTL));
1502 seq_printf(m, "ARB_MODE = 0x%08x\n",
1503 I915_READ(ARB_MODE));
1504 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1505 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001506 }
1507 mutex_unlock(&dev->struct_mutex);
1508
1509 return 0;
1510}
1511
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001512static int i915_ppgtt_info(struct seq_file *m, void *data)
1513{
1514 struct drm_info_node *node = (struct drm_info_node *) m->private;
1515 struct drm_device *dev = node->minor->dev;
1516 struct drm_i915_private *dev_priv = dev->dev_private;
1517 struct intel_ring_buffer *ring;
1518 int i, ret;
1519
1520
1521 ret = mutex_lock_interruptible(&dev->struct_mutex);
1522 if (ret)
1523 return ret;
1524 if (INTEL_INFO(dev)->gen == 6)
1525 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1526
1527 for (i = 0; i < I915_NUM_RINGS; i++) {
1528 ring = &dev_priv->ring[i];
1529
1530 seq_printf(m, "%s\n", ring->name);
1531 if (INTEL_INFO(dev)->gen == 7)
1532 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1533 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1534 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1535 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1536 }
1537 if (dev_priv->mm.aliasing_ppgtt) {
1538 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1539
1540 seq_printf(m, "aliasing PPGTT:\n");
1541 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1542 }
1543 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1544 mutex_unlock(&dev->struct_mutex);
1545
1546 return 0;
1547}
1548
Jesse Barnes57f350b2012-03-28 13:39:25 -07001549static int i915_dpio_info(struct seq_file *m, void *data)
1550{
1551 struct drm_info_node *node = (struct drm_info_node *) m->private;
1552 struct drm_device *dev = node->minor->dev;
1553 struct drm_i915_private *dev_priv = dev->dev_private;
1554 int ret;
1555
1556
1557 if (!IS_VALLEYVIEW(dev)) {
1558 seq_printf(m, "unsupported\n");
1559 return 0;
1560 }
1561
1562 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1563 if (ret)
1564 return ret;
1565
1566 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1567
1568 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1569 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1570 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1571 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1572
1573 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1574 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1575 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1576 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1577
1578 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1579 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1580 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1581 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1582
1583 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1584 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1585 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1586 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1587
1588 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1589 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1590
1591 mutex_unlock(&dev->mode_config.mutex);
1592
1593 return 0;
1594}
1595
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001596static ssize_t
1597i915_wedged_read(struct file *filp,
1598 char __user *ubuf,
1599 size_t max,
1600 loff_t *ppos)
1601{
1602 struct drm_device *dev = filp->private_data;
1603 drm_i915_private_t *dev_priv = dev->dev_private;
1604 char buf[80];
1605 int len;
1606
Akshay Joshi0206e352011-08-16 15:34:10 -04001607 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001608 "wedged : %d\n",
1609 atomic_read(&dev_priv->mm.wedged));
1610
Akshay Joshi0206e352011-08-16 15:34:10 -04001611 if (len > sizeof(buf))
1612 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001613
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001614 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1615}
1616
1617static ssize_t
1618i915_wedged_write(struct file *filp,
1619 const char __user *ubuf,
1620 size_t cnt,
1621 loff_t *ppos)
1622{
1623 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001624 char buf[20];
1625 int val = 1;
1626
1627 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001628 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001629 return -EINVAL;
1630
1631 if (copy_from_user(buf, ubuf, cnt))
1632 return -EFAULT;
1633 buf[cnt] = 0;
1634
1635 val = simple_strtoul(buf, NULL, 0);
1636 }
1637
1638 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001639 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001640
1641 return cnt;
1642}
1643
1644static const struct file_operations i915_wedged_fops = {
1645 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001646 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001647 .read = i915_wedged_read,
1648 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001649 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001650};
1651
Jesse Barnes358733e2011-07-27 11:53:01 -07001652static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001653i915_ring_stop_read(struct file *filp,
1654 char __user *ubuf,
1655 size_t max,
1656 loff_t *ppos)
1657{
1658 struct drm_device *dev = filp->private_data;
1659 drm_i915_private_t *dev_priv = dev->dev_private;
1660 char buf[20];
1661 int len;
1662
1663 len = snprintf(buf, sizeof(buf),
1664 "0x%08x\n", dev_priv->stop_rings);
1665
1666 if (len > sizeof(buf))
1667 len = sizeof(buf);
1668
1669 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1670}
1671
1672static ssize_t
1673i915_ring_stop_write(struct file *filp,
1674 const char __user *ubuf,
1675 size_t cnt,
1676 loff_t *ppos)
1677{
1678 struct drm_device *dev = filp->private_data;
1679 struct drm_i915_private *dev_priv = dev->dev_private;
1680 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001681 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001682
1683 if (cnt > 0) {
1684 if (cnt > sizeof(buf) - 1)
1685 return -EINVAL;
1686
1687 if (copy_from_user(buf, ubuf, cnt))
1688 return -EFAULT;
1689 buf[cnt] = 0;
1690
1691 val = simple_strtoul(buf, NULL, 0);
1692 }
1693
1694 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1695
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001696 ret = mutex_lock_interruptible(&dev->struct_mutex);
1697 if (ret)
1698 return ret;
1699
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001700 dev_priv->stop_rings = val;
1701 mutex_unlock(&dev->struct_mutex);
1702
1703 return cnt;
1704}
1705
1706static const struct file_operations i915_ring_stop_fops = {
1707 .owner = THIS_MODULE,
1708 .open = simple_open,
1709 .read = i915_ring_stop_read,
1710 .write = i915_ring_stop_write,
1711 .llseek = default_llseek,
1712};
Daniel Vetterd5442302012-04-27 15:17:40 +02001713
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001714static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001715i915_max_freq_read(struct file *filp,
1716 char __user *ubuf,
1717 size_t max,
1718 loff_t *ppos)
1719{
1720 struct drm_device *dev = filp->private_data;
1721 drm_i915_private_t *dev_priv = dev->dev_private;
1722 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001723 int len, ret;
1724
1725 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1726 return -ENODEV;
1727
1728 ret = mutex_lock_interruptible(&dev->struct_mutex);
1729 if (ret)
1730 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001731
Akshay Joshi0206e352011-08-16 15:34:10 -04001732 len = snprintf(buf, sizeof(buf),
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001733 "max freq: %d\n", dev_priv->rps.max_delay * 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001734 mutex_unlock(&dev->struct_mutex);
Jesse Barnes358733e2011-07-27 11:53:01 -07001735
Akshay Joshi0206e352011-08-16 15:34:10 -04001736 if (len > sizeof(buf))
1737 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001738
1739 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1740}
1741
1742static ssize_t
1743i915_max_freq_write(struct file *filp,
1744 const char __user *ubuf,
1745 size_t cnt,
1746 loff_t *ppos)
1747{
1748 struct drm_device *dev = filp->private_data;
1749 struct drm_i915_private *dev_priv = dev->dev_private;
1750 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001751 int val = 1, ret;
1752
1753 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1754 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001755
1756 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001757 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001758 return -EINVAL;
1759
1760 if (copy_from_user(buf, ubuf, cnt))
1761 return -EFAULT;
1762 buf[cnt] = 0;
1763
1764 val = simple_strtoul(buf, NULL, 0);
1765 }
1766
1767 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1768
Daniel Vetter004777c2012-08-09 15:07:01 +02001769 ret = mutex_lock_interruptible(&dev->struct_mutex);
1770 if (ret)
1771 return ret;
1772
Jesse Barnes358733e2011-07-27 11:53:01 -07001773 /*
1774 * Turbo will still be enabled, but won't go above the set value.
1775 */
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001776 dev_priv->rps.max_delay = val / 50;
Jesse Barnes358733e2011-07-27 11:53:01 -07001777
1778 gen6_set_rps(dev, val / 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001779 mutex_unlock(&dev->struct_mutex);
Jesse Barnes358733e2011-07-27 11:53:01 -07001780
1781 return cnt;
1782}
1783
1784static const struct file_operations i915_max_freq_fops = {
1785 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001786 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001787 .read = i915_max_freq_read,
1788 .write = i915_max_freq_write,
1789 .llseek = default_llseek,
1790};
1791
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001792static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001793i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1794 loff_t *ppos)
1795{
1796 struct drm_device *dev = filp->private_data;
1797 drm_i915_private_t *dev_priv = dev->dev_private;
1798 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001799 int len, ret;
1800
1801 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1802 return -ENODEV;
1803
1804 ret = mutex_lock_interruptible(&dev->struct_mutex);
1805 if (ret)
1806 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001807
1808 len = snprintf(buf, sizeof(buf),
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001809 "min freq: %d\n", dev_priv->rps.min_delay * 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001810 mutex_unlock(&dev->struct_mutex);
Jesse Barnes1523c312012-05-25 12:34:54 -07001811
1812 if (len > sizeof(buf))
1813 len = sizeof(buf);
1814
1815 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1816}
1817
1818static ssize_t
1819i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
1820 loff_t *ppos)
1821{
1822 struct drm_device *dev = filp->private_data;
1823 struct drm_i915_private *dev_priv = dev->dev_private;
1824 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001825 int val = 1, ret;
1826
1827 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1828 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07001829
1830 if (cnt > 0) {
1831 if (cnt > sizeof(buf) - 1)
1832 return -EINVAL;
1833
1834 if (copy_from_user(buf, ubuf, cnt))
1835 return -EFAULT;
1836 buf[cnt] = 0;
1837
1838 val = simple_strtoul(buf, NULL, 0);
1839 }
1840
1841 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
1842
Daniel Vetter004777c2012-08-09 15:07:01 +02001843 ret = mutex_lock_interruptible(&dev->struct_mutex);
1844 if (ret)
1845 return ret;
1846
Jesse Barnes1523c312012-05-25 12:34:54 -07001847 /*
1848 * Turbo will still be enabled, but won't go below the set value.
1849 */
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001850 dev_priv->rps.min_delay = val / 50;
Jesse Barnes1523c312012-05-25 12:34:54 -07001851
1852 gen6_set_rps(dev, val / 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001853 mutex_unlock(&dev->struct_mutex);
Jesse Barnes1523c312012-05-25 12:34:54 -07001854
1855 return cnt;
1856}
1857
1858static const struct file_operations i915_min_freq_fops = {
1859 .owner = THIS_MODULE,
1860 .open = simple_open,
1861 .read = i915_min_freq_read,
1862 .write = i915_min_freq_write,
1863 .llseek = default_llseek,
1864};
1865
1866static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001867i915_cache_sharing_read(struct file *filp,
1868 char __user *ubuf,
1869 size_t max,
1870 loff_t *ppos)
1871{
1872 struct drm_device *dev = filp->private_data;
1873 drm_i915_private_t *dev_priv = dev->dev_private;
1874 char buf[80];
1875 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001876 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001877
Daniel Vetter004777c2012-08-09 15:07:01 +02001878 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1879 return -ENODEV;
1880
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001881 ret = mutex_lock_interruptible(&dev->struct_mutex);
1882 if (ret)
1883 return ret;
1884
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001885 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1886 mutex_unlock(&dev_priv->dev->struct_mutex);
1887
Akshay Joshi0206e352011-08-16 15:34:10 -04001888 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001889 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
1890 GEN6_MBC_SNPCR_SHIFT);
1891
Akshay Joshi0206e352011-08-16 15:34:10 -04001892 if (len > sizeof(buf))
1893 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001894
1895 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1896}
1897
1898static ssize_t
1899i915_cache_sharing_write(struct file *filp,
1900 const char __user *ubuf,
1901 size_t cnt,
1902 loff_t *ppos)
1903{
1904 struct drm_device *dev = filp->private_data;
1905 struct drm_i915_private *dev_priv = dev->dev_private;
1906 char buf[20];
1907 u32 snpcr;
1908 int val = 1;
1909
Daniel Vetter004777c2012-08-09 15:07:01 +02001910 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1911 return -ENODEV;
1912
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001913 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001914 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001915 return -EINVAL;
1916
1917 if (copy_from_user(buf, ubuf, cnt))
1918 return -EFAULT;
1919 buf[cnt] = 0;
1920
1921 val = simple_strtoul(buf, NULL, 0);
1922 }
1923
1924 if (val < 0 || val > 3)
1925 return -EINVAL;
1926
1927 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
1928
1929 /* Update the cache sharing policy here as well */
1930 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1931 snpcr &= ~GEN6_MBC_SNPCR_MASK;
1932 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
1933 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
1934
1935 return cnt;
1936}
1937
1938static const struct file_operations i915_cache_sharing_fops = {
1939 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001940 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001941 .read = i915_cache_sharing_read,
1942 .write = i915_cache_sharing_write,
1943 .llseek = default_llseek,
1944};
1945
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001946/* As the drm_debugfs_init() routines are called before dev->dev_private is
1947 * allocated we need to hook into the minor for release. */
1948static int
1949drm_add_fake_info_node(struct drm_minor *minor,
1950 struct dentry *ent,
1951 const void *key)
1952{
1953 struct drm_info_node *node;
1954
1955 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
1956 if (node == NULL) {
1957 debugfs_remove(ent);
1958 return -ENOMEM;
1959 }
1960
1961 node->minor = minor;
1962 node->dent = ent;
1963 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01001964
1965 mutex_lock(&minor->debugfs_lock);
1966 list_add(&node->list, &minor->debugfs_list);
1967 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001968
1969 return 0;
1970}
1971
Ben Widawsky6d794d42011-04-25 11:25:56 -07001972static int i915_forcewake_open(struct inode *inode, struct file *file)
1973{
1974 struct drm_device *dev = inode->i_private;
1975 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001976
Daniel Vetter075edca2012-01-24 09:44:28 +01001977 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001978 return 0;
1979
Ben Widawsky6d794d42011-04-25 11:25:56 -07001980 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001981
1982 return 0;
1983}
1984
Ben Widawskyc43b5632012-04-16 14:07:40 -07001985static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001986{
1987 struct drm_device *dev = inode->i_private;
1988 struct drm_i915_private *dev_priv = dev->dev_private;
1989
Daniel Vetter075edca2012-01-24 09:44:28 +01001990 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001991 return 0;
1992
Ben Widawsky6d794d42011-04-25 11:25:56 -07001993 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001994
1995 return 0;
1996}
1997
1998static const struct file_operations i915_forcewake_fops = {
1999 .owner = THIS_MODULE,
2000 .open = i915_forcewake_open,
2001 .release = i915_forcewake_release,
2002};
2003
2004static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2005{
2006 struct drm_device *dev = minor->dev;
2007 struct dentry *ent;
2008
2009 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002010 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002011 root, dev,
2012 &i915_forcewake_fops);
2013 if (IS_ERR(ent))
2014 return PTR_ERR(ent);
2015
Ben Widawsky8eb57292011-05-11 15:10:58 -07002016 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002017}
2018
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002019static int i915_debugfs_create(struct dentry *root,
2020 struct drm_minor *minor,
2021 const char *name,
2022 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002023{
2024 struct drm_device *dev = minor->dev;
2025 struct dentry *ent;
2026
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002027 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002028 S_IRUGO | S_IWUSR,
2029 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002030 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002031 if (IS_ERR(ent))
2032 return PTR_ERR(ent);
2033
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002034 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002035}
2036
Ben Gamari27c202a2009-07-01 22:26:52 -04002037static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002038 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002039 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002040 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002041 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002042 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002043 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002044 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002045 {"i915_gem_request", i915_gem_request_info, 0},
2046 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002047 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002048 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002049 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2050 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2051 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002052 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2053 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2054 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2055 {"i915_inttoext_table", i915_inttoext_table, 0},
2056 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002057 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002058 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002059 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002060 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002061 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002062 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002063 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002064 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002065 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002066 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002067 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002068 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002069};
Ben Gamari27c202a2009-07-01 22:26:52 -04002070#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002071
Ben Gamari27c202a2009-07-01 22:26:52 -04002072int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002073{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002074 int ret;
2075
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002076 ret = i915_debugfs_create(minor->debugfs_root, minor,
2077 "i915_wedged",
2078 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002079 if (ret)
2080 return ret;
2081
Ben Widawsky6d794d42011-04-25 11:25:56 -07002082 ret = i915_forcewake_create(minor->debugfs_root, minor);
2083 if (ret)
2084 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002085
2086 ret = i915_debugfs_create(minor->debugfs_root, minor,
2087 "i915_max_freq",
2088 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002089 if (ret)
2090 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002091
2092 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002093 "i915_min_freq",
2094 &i915_min_freq_fops);
2095 if (ret)
2096 return ret;
2097
2098 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002099 "i915_cache_sharing",
2100 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002101 if (ret)
2102 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002103
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002104 ret = i915_debugfs_create(minor->debugfs_root, minor,
2105 "i915_ring_stop",
2106 &i915_ring_stop_fops);
2107 if (ret)
2108 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002109
Daniel Vetterd5442302012-04-27 15:17:40 +02002110 ret = i915_debugfs_create(minor->debugfs_root, minor,
2111 "i915_error_state",
2112 &i915_error_state_fops);
2113 if (ret)
2114 return ret;
2115
Ben Gamari27c202a2009-07-01 22:26:52 -04002116 return drm_debugfs_create_files(i915_debugfs_list,
2117 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002118 minor->debugfs_root, minor);
2119}
2120
Ben Gamari27c202a2009-07-01 22:26:52 -04002121void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002122{
Ben Gamari27c202a2009-07-01 22:26:52 -04002123 drm_debugfs_remove_files(i915_debugfs_list,
2124 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002125 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2126 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002127 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2128 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002129 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2130 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002131 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2132 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002133 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2134 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002135 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2136 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002137 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2138 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002139}
2140
2141#endif /* CONFIG_DEBUG_FS */