blob: 5548b02f40bbe0a3e7fdf821d3701a2086574259 [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);
121 if (obj->fence_reg != I915_FENCE_REG_NONE)
122 seq_printf(m, " (fence: %d)", obj->fence_reg);
123 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100124 seq_printf(m, " (gtt offset: %08x, size: %08x)",
125 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilson6299f992010-11-24 12:23:44 +0000126 if (obj->pin_mappable || obj->fault_mappable) {
127 char s[3], *t = s;
128 if (obj->pin_mappable)
129 *t++ = 'p';
130 if (obj->fault_mappable)
131 *t++ = 'f';
132 *t = '\0';
133 seq_printf(m, " (%s mappable)", s);
134 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100135 if (obj->ring != NULL)
136 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100137}
138
Ben Gamari433e12f2009-02-17 20:08:51 -0500139static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500140{
141 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500142 uintptr_t list = (uintptr_t) node->info_ent->data;
143 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500144 struct drm_device *dev = node->minor->dev;
145 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000146 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100147 size_t total_obj_size, total_gtt_size;
148 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100149
150 ret = mutex_lock_interruptible(&dev->struct_mutex);
151 if (ret)
152 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500153
Ben Gamari433e12f2009-02-17 20:08:51 -0500154 switch (list) {
155 case ACTIVE_LIST:
156 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100157 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500158 break;
159 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400160 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500161 head = &dev_priv->mm.inactive_list;
162 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500163 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100164 mutex_unlock(&dev->struct_mutex);
165 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500166 }
167
Chris Wilson8f2480f2010-09-26 11:44:19 +0100168 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000169 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100170 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000171 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800172 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000173 total_obj_size += obj->base.size;
174 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100175 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500176 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100177 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700178
Chris Wilson8f2480f2010-09-26 11:44:19 +0100179 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
180 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500181 return 0;
182}
183
Chris Wilson6299f992010-11-24 12:23:44 +0000184#define count_objects(list, member) do { \
185 list_for_each_entry(obj, list, member) { \
186 size += obj->gtt_space->size; \
187 ++count; \
188 if (obj->map_and_fenceable) { \
189 mappable_size += obj->gtt_space->size; \
190 ++mappable_count; \
191 } \
192 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400193} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000194
Chris Wilson73aa8082010-09-30 11:46:12 +0100195static int i915_gem_object_info(struct seq_file *m, void* data)
196{
197 struct drm_info_node *node = (struct drm_info_node *) m->private;
198 struct drm_device *dev = node->minor->dev;
199 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200200 u32 count, mappable_count, purgeable_count;
201 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000202 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100203 int ret;
204
205 ret = mutex_lock_interruptible(&dev->struct_mutex);
206 if (ret)
207 return ret;
208
Chris Wilson6299f992010-11-24 12:23:44 +0000209 seq_printf(m, "%u objects, %zu bytes\n",
210 dev_priv->mm.object_count,
211 dev_priv->mm.object_memory);
212
213 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200214 count_objects(&dev_priv->mm.bound_list, gtt_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000215 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
216 count, mappable_count, size, mappable_size);
217
218 size = count = mappable_size = mappable_count = 0;
219 count_objects(&dev_priv->mm.active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000220 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
221 count, mappable_count, size, mappable_size);
222
223 size = count = mappable_size = mappable_count = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000224 count_objects(&dev_priv->mm.inactive_list, mm_list);
225 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
226 count, mappable_count, size, mappable_size);
227
Chris Wilsonb7abb712012-08-20 11:33:30 +0200228 size = count = purgeable_size = purgeable_count = 0;
229 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200230 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200231 if (obj->madv == I915_MADV_DONTNEED)
232 purgeable_size += obj->base.size, ++purgeable_count;
233 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200234 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
235
Chris Wilson6299f992010-11-24 12:23:44 +0000236 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200237 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000238 if (obj->fault_mappable) {
239 size += obj->gtt_space->size;
240 ++count;
241 }
242 if (obj->pin_mappable) {
243 mappable_size += obj->gtt_space->size;
244 ++mappable_count;
245 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200246 if (obj->madv == I915_MADV_DONTNEED) {
247 purgeable_size += obj->base.size;
248 ++purgeable_count;
249 }
Chris Wilson6299f992010-11-24 12:23:44 +0000250 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200251 seq_printf(m, "%u purgeable objects, %zu bytes\n",
252 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000253 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
254 mappable_count, mappable_size);
255 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
256 count, size);
257
258 seq_printf(m, "%zu [%zu] gtt total\n",
259 dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
Chris Wilson73aa8082010-09-30 11:46:12 +0100260
261 mutex_unlock(&dev->struct_mutex);
262
263 return 0;
264}
265
Chris Wilson08c18322011-01-10 00:00:24 +0000266static int i915_gem_gtt_info(struct seq_file *m, void* data)
267{
268 struct drm_info_node *node = (struct drm_info_node *) m->private;
269 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100270 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000271 struct drm_i915_private *dev_priv = dev->dev_private;
272 struct drm_i915_gem_object *obj;
273 size_t total_obj_size, total_gtt_size;
274 int count, ret;
275
276 ret = mutex_lock_interruptible(&dev->struct_mutex);
277 if (ret)
278 return ret;
279
280 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200281 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100282 if (list == PINNED_LIST && obj->pin_count == 0)
283 continue;
284
Chris Wilson08c18322011-01-10 00:00:24 +0000285 seq_printf(m, " ");
286 describe_obj(m, obj);
287 seq_printf(m, "\n");
288 total_obj_size += obj->base.size;
289 total_gtt_size += obj->gtt_space->size;
290 count++;
291 }
292
293 mutex_unlock(&dev->struct_mutex);
294
295 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
296 count, total_obj_size, total_gtt_size);
297
298 return 0;
299}
300
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100301static int i915_gem_pageflip_info(struct seq_file *m, void *data)
302{
303 struct drm_info_node *node = (struct drm_info_node *) m->private;
304 struct drm_device *dev = node->minor->dev;
305 unsigned long flags;
306 struct intel_crtc *crtc;
307
308 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800309 const char pipe = pipe_name(crtc->pipe);
310 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100311 struct intel_unpin_work *work;
312
313 spin_lock_irqsave(&dev->event_lock, flags);
314 work = crtc->unpin_work;
315 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800316 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100317 pipe, plane);
318 } else {
319 if (!work->pending) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800320 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100321 pipe, plane);
322 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800323 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100324 pipe, plane);
325 }
326 if (work->enable_stall_check)
327 seq_printf(m, "Stall check enabled, ");
328 else
329 seq_printf(m, "Stall check waiting for page flip ioctl, ");
330 seq_printf(m, "%d prepares\n", work->pending);
331
332 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000333 struct drm_i915_gem_object *obj = work->old_fb_obj;
334 if (obj)
335 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100336 }
337 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000338 struct drm_i915_gem_object *obj = work->pending_flip_obj;
339 if (obj)
340 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100341 }
342 }
343 spin_unlock_irqrestore(&dev->event_lock, flags);
344 }
345
346 return 0;
347}
348
Ben Gamari20172632009-02-17 20:08:50 -0500349static int i915_gem_request_info(struct seq_file *m, void *data)
350{
351 struct drm_info_node *node = (struct drm_info_node *) m->private;
352 struct drm_device *dev = node->minor->dev;
353 drm_i915_private_t *dev_priv = dev->dev_private;
354 struct drm_i915_gem_request *gem_request;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100355 int ret, count;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100356
357 ret = mutex_lock_interruptible(&dev->struct_mutex);
358 if (ret)
359 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500360
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100361 count = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000362 if (!list_empty(&dev_priv->ring[RCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100363 seq_printf(m, "Render requests:\n");
364 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000365 &dev_priv->ring[RCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100366 list) {
367 seq_printf(m, " %d @ %d\n",
368 gem_request->seqno,
369 (int) (jiffies - gem_request->emitted_jiffies));
370 }
371 count++;
372 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000373 if (!list_empty(&dev_priv->ring[VCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100374 seq_printf(m, "BSD requests:\n");
375 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000376 &dev_priv->ring[VCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100377 list) {
378 seq_printf(m, " %d @ %d\n",
379 gem_request->seqno,
380 (int) (jiffies - gem_request->emitted_jiffies));
381 }
382 count++;
383 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000384 if (!list_empty(&dev_priv->ring[BCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100385 seq_printf(m, "BLT requests:\n");
386 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000387 &dev_priv->ring[BCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100388 list) {
389 seq_printf(m, " %d @ %d\n",
390 gem_request->seqno,
391 (int) (jiffies - gem_request->emitted_jiffies));
392 }
393 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500394 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100395 mutex_unlock(&dev->struct_mutex);
396
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100397 if (count == 0)
398 seq_printf(m, "No requests\n");
399
Ben Gamari20172632009-02-17 20:08:50 -0500400 return 0;
401}
402
Chris Wilsonb2223492010-10-27 15:27:33 +0100403static void i915_ring_seqno_info(struct seq_file *m,
404 struct intel_ring_buffer *ring)
405{
406 if (ring->get_seqno) {
407 seq_printf(m, "Current sequence (%s): %d\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100408 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100409 }
410}
411
Ben Gamari20172632009-02-17 20:08:50 -0500412static int i915_gem_seqno_info(struct seq_file *m, void *data)
413{
414 struct drm_info_node *node = (struct drm_info_node *) m->private;
415 struct drm_device *dev = node->minor->dev;
416 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000417 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100418
419 ret = mutex_lock_interruptible(&dev->struct_mutex);
420 if (ret)
421 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500422
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000423 for (i = 0; i < I915_NUM_RINGS; i++)
424 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100425
426 mutex_unlock(&dev->struct_mutex);
427
Ben Gamari20172632009-02-17 20:08:50 -0500428 return 0;
429}
430
431
432static int i915_interrupt_info(struct seq_file *m, void *data)
433{
434 struct drm_info_node *node = (struct drm_info_node *) m->private;
435 struct drm_device *dev = node->minor->dev;
436 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800437 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100438
439 ret = mutex_lock_interruptible(&dev->struct_mutex);
440 if (ret)
441 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500442
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700443 if (IS_VALLEYVIEW(dev)) {
444 seq_printf(m, "Display IER:\t%08x\n",
445 I915_READ(VLV_IER));
446 seq_printf(m, "Display IIR:\t%08x\n",
447 I915_READ(VLV_IIR));
448 seq_printf(m, "Display IIR_RW:\t%08x\n",
449 I915_READ(VLV_IIR_RW));
450 seq_printf(m, "Display IMR:\t%08x\n",
451 I915_READ(VLV_IMR));
452 for_each_pipe(pipe)
453 seq_printf(m, "Pipe %c stat:\t%08x\n",
454 pipe_name(pipe),
455 I915_READ(PIPESTAT(pipe)));
456
457 seq_printf(m, "Master IER:\t%08x\n",
458 I915_READ(VLV_MASTER_IER));
459
460 seq_printf(m, "Render IER:\t%08x\n",
461 I915_READ(GTIER));
462 seq_printf(m, "Render IIR:\t%08x\n",
463 I915_READ(GTIIR));
464 seq_printf(m, "Render IMR:\t%08x\n",
465 I915_READ(GTIMR));
466
467 seq_printf(m, "PM IER:\t\t%08x\n",
468 I915_READ(GEN6_PMIER));
469 seq_printf(m, "PM IIR:\t\t%08x\n",
470 I915_READ(GEN6_PMIIR));
471 seq_printf(m, "PM IMR:\t\t%08x\n",
472 I915_READ(GEN6_PMIMR));
473
474 seq_printf(m, "Port hotplug:\t%08x\n",
475 I915_READ(PORT_HOTPLUG_EN));
476 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
477 I915_READ(VLV_DPFLIPSTAT));
478 seq_printf(m, "DPINVGTT:\t%08x\n",
479 I915_READ(DPINVGTT));
480
481 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800482 seq_printf(m, "Interrupt enable: %08x\n",
483 I915_READ(IER));
484 seq_printf(m, "Interrupt identity: %08x\n",
485 I915_READ(IIR));
486 seq_printf(m, "Interrupt mask: %08x\n",
487 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800488 for_each_pipe(pipe)
489 seq_printf(m, "Pipe %c stat: %08x\n",
490 pipe_name(pipe),
491 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800492 } else {
493 seq_printf(m, "North Display Interrupt enable: %08x\n",
494 I915_READ(DEIER));
495 seq_printf(m, "North Display Interrupt identity: %08x\n",
496 I915_READ(DEIIR));
497 seq_printf(m, "North Display Interrupt mask: %08x\n",
498 I915_READ(DEIMR));
499 seq_printf(m, "South Display Interrupt enable: %08x\n",
500 I915_READ(SDEIER));
501 seq_printf(m, "South Display Interrupt identity: %08x\n",
502 I915_READ(SDEIIR));
503 seq_printf(m, "South Display Interrupt mask: %08x\n",
504 I915_READ(SDEIMR));
505 seq_printf(m, "Graphics Interrupt enable: %08x\n",
506 I915_READ(GTIER));
507 seq_printf(m, "Graphics Interrupt identity: %08x\n",
508 I915_READ(GTIIR));
509 seq_printf(m, "Graphics Interrupt mask: %08x\n",
510 I915_READ(GTIMR));
511 }
Ben Gamari20172632009-02-17 20:08:50 -0500512 seq_printf(m, "Interrupts received: %d\n",
513 atomic_read(&dev_priv->irq_received));
Chris Wilson9862e602011-01-04 22:22:17 +0000514 for (i = 0; i < I915_NUM_RINGS; i++) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700515 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilson9862e602011-01-04 22:22:17 +0000516 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
517 dev_priv->ring[i].name,
518 I915_READ_IMR(&dev_priv->ring[i]));
519 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000520 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilson9862e602011-01-04 22:22:17 +0000521 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100522 mutex_unlock(&dev->struct_mutex);
523
Ben Gamari20172632009-02-17 20:08:50 -0500524 return 0;
525}
526
Chris Wilsona6172a82009-02-11 14:26:38 +0000527static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
528{
529 struct drm_info_node *node = (struct drm_info_node *) m->private;
530 struct drm_device *dev = node->minor->dev;
531 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100532 int i, ret;
533
534 ret = mutex_lock_interruptible(&dev->struct_mutex);
535 if (ret)
536 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000537
538 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
539 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
540 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000541 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000542
Chris Wilson6c085a72012-08-20 11:40:46 +0200543 seq_printf(m, "Fence %d, pin count = %d, object = ",
544 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100545 if (obj == NULL)
546 seq_printf(m, "unused");
547 else
Chris Wilson05394f32010-11-08 19:18:58 +0000548 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100549 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000550 }
551
Chris Wilson05394f32010-11-08 19:18:58 +0000552 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000553 return 0;
554}
555
Ben Gamari20172632009-02-17 20:08:50 -0500556static int i915_hws_info(struct seq_file *m, void *data)
557{
558 struct drm_info_node *node = (struct drm_info_node *) m->private;
559 struct drm_device *dev = node->minor->dev;
560 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100561 struct intel_ring_buffer *ring;
Chris Wilson311bd682011-01-13 19:06:50 +0000562 const volatile u32 __iomem *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100563 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500564
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000565 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilson311bd682011-01-13 19:06:50 +0000566 hws = (volatile u32 __iomem *)ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500567 if (hws == NULL)
568 return 0;
569
570 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
571 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
572 i * 4,
573 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
574 }
575 return 0;
576}
577
Chris Wilsone5c65262010-11-01 11:35:28 +0000578static const char *ring_str(int ring)
579{
580 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100581 case RCS: return "render";
582 case VCS: return "bsd";
583 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000584 default: return "";
585 }
586}
587
Chris Wilson9df30792010-02-18 10:24:56 +0000588static const char *pin_flag(int pinned)
589{
590 if (pinned > 0)
591 return " P";
592 else if (pinned < 0)
593 return " p";
594 else
595 return "";
596}
597
598static const char *tiling_flag(int tiling)
599{
600 switch (tiling) {
601 default:
602 case I915_TILING_NONE: return "";
603 case I915_TILING_X: return " X";
604 case I915_TILING_Y: return " Y";
605 }
606}
607
608static const char *dirty_flag(int dirty)
609{
610 return dirty ? " dirty" : "";
611}
612
613static const char *purgeable_flag(int purgeable)
614{
615 return purgeable ? " purgeable" : "";
616}
617
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000618static void print_error_buffers(struct seq_file *m,
619 const char *name,
620 struct drm_i915_error_buffer *err,
621 int count)
622{
623 seq_printf(m, "%s [%d]:\n", name, count);
624
625 while (count--) {
Chris Wilson0201f1e2012-07-20 12:41:01 +0100626 seq_printf(m, " %08x %8u %04x %04x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000627 err->gtt_offset,
628 err->size,
629 err->read_domains,
630 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100631 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000632 pin_flag(err->pinned),
633 tiling_flag(err->tiling),
634 dirty_flag(err->dirty),
635 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100636 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000637 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700638 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000639
640 if (err->name)
641 seq_printf(m, " (name: %d)", err->name);
642 if (err->fence_reg != I915_FENCE_REG_NONE)
643 seq_printf(m, " (fence: %d)", err->fence_reg);
644
645 seq_printf(m, "\n");
646 err++;
647 }
648}
649
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100650static void i915_ring_error_state(struct seq_file *m,
651 struct drm_device *dev,
652 struct drm_i915_error_state *error,
653 unsigned ring)
654{
Ben Widawskyec34a012012-04-03 23:03:00 -0700655 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100656 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100657 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
658 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100659 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
660 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
661 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
662 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100663 if (ring == RCS && INTEL_INFO(dev)->gen >= 4) {
664 seq_printf(m, " INSTDONE1: 0x%08x\n", error->instdone1);
665 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100666 }
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100667 if (INTEL_INFO(dev)->gen >= 4)
668 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
669 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200670 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100671 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100672 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100673 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100674 seq_printf(m, " SYNC_0: 0x%08x\n",
675 error->semaphore_mboxes[ring][0]);
676 seq_printf(m, " SYNC_1: 0x%08x\n",
677 error->semaphore_mboxes[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100678 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100679 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Ben Widawsky9574b3f2012-04-26 16:03:01 -0700680 seq_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100681 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
682 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100683}
684
Daniel Vetterd5442302012-04-27 15:17:40 +0200685struct i915_error_state_file_priv {
686 struct drm_device *dev;
687 struct drm_i915_error_state *error;
688};
689
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700690static int i915_error_state(struct seq_file *m, void *unused)
691{
Daniel Vetterd5442302012-04-27 15:17:40 +0200692 struct i915_error_state_file_priv *error_priv = m->private;
693 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700694 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200695 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100696 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000697 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700698
Daniel Vetter742cbee2012-04-27 15:17:39 +0200699 if (!error) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700700 seq_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200701 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700702 }
703
Jesse Barnes8a905232009-07-11 16:48:03 -0400704 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
705 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000706 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100707 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700708 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100709 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700710 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000711
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100712 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100713 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
714
Daniel Vetter33f3f512011-12-14 13:57:39 +0100715 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100716 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100717 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
718 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100719
Chris Wilsonb4519512012-05-11 14:29:30 +0100720 for_each_ring(ring, dev_priv, i)
721 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100722
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000723 if (error->active_bo)
724 print_error_buffers(m, "Active",
725 error->active_bo,
726 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000727
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000728 if (error->pinned_bo)
729 print_error_buffers(m, "Pinned",
730 error->pinned_bo,
731 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000732
Chris Wilson52d39a22012-02-15 11:25:37 +0000733 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
734 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000735
Chris Wilson52d39a22012-02-15 11:25:37 +0000736 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000737 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
738 dev_priv->ring[i].name,
739 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000740 offset = 0;
741 for (page = 0; page < obj->page_count; page++) {
742 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
743 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
744 offset += 4;
745 }
746 }
747 }
Chris Wilson9df30792010-02-18 10:24:56 +0000748
Chris Wilson52d39a22012-02-15 11:25:37 +0000749 if (error->ring[i].num_requests) {
750 seq_printf(m, "%s --- %d requests\n",
751 dev_priv->ring[i].name,
752 error->ring[i].num_requests);
753 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000754 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000755 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000756 error->ring[i].requests[j].jiffies,
757 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000758 }
759 }
760
761 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000762 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
763 dev_priv->ring[i].name,
764 obj->gtt_offset);
765 offset = 0;
766 for (page = 0; page < obj->page_count; page++) {
767 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
768 seq_printf(m, "%08x : %08x\n",
769 offset,
770 obj->pages[page][elt]);
771 offset += 4;
772 }
Chris Wilson9df30792010-02-18 10:24:56 +0000773 }
774 }
775 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700776
Chris Wilson6ef3d422010-08-04 20:26:07 +0100777 if (error->overlay)
778 intel_overlay_print_error_state(m, error->overlay);
779
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000780 if (error->display)
781 intel_display_print_error_state(m, dev, error->display);
782
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700783 return 0;
784}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700785
Daniel Vetterd5442302012-04-27 15:17:40 +0200786static ssize_t
787i915_error_state_write(struct file *filp,
788 const char __user *ubuf,
789 size_t cnt,
790 loff_t *ppos)
791{
792 struct seq_file *m = filp->private_data;
793 struct i915_error_state_file_priv *error_priv = m->private;
794 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200795 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200796
797 DRM_DEBUG_DRIVER("Resetting error state\n");
798
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200799 ret = mutex_lock_interruptible(&dev->struct_mutex);
800 if (ret)
801 return ret;
802
Daniel Vetterd5442302012-04-27 15:17:40 +0200803 i915_destroy_error_state(dev);
804 mutex_unlock(&dev->struct_mutex);
805
806 return cnt;
807}
808
809static int i915_error_state_open(struct inode *inode, struct file *file)
810{
811 struct drm_device *dev = inode->i_private;
812 drm_i915_private_t *dev_priv = dev->dev_private;
813 struct i915_error_state_file_priv *error_priv;
814 unsigned long flags;
815
816 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
817 if (!error_priv)
818 return -ENOMEM;
819
820 error_priv->dev = dev;
821
822 spin_lock_irqsave(&dev_priv->error_lock, flags);
823 error_priv->error = dev_priv->first_error;
824 if (error_priv->error)
825 kref_get(&error_priv->error->ref);
826 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
827
828 return single_open(file, i915_error_state, error_priv);
829}
830
831static int i915_error_state_release(struct inode *inode, struct file *file)
832{
833 struct seq_file *m = file->private_data;
834 struct i915_error_state_file_priv *error_priv = m->private;
835
836 if (error_priv->error)
837 kref_put(&error_priv->error->ref, i915_error_state_free);
838 kfree(error_priv);
839
840 return single_release(inode, file);
841}
842
843static const struct file_operations i915_error_state_fops = {
844 .owner = THIS_MODULE,
845 .open = i915_error_state_open,
846 .read = seq_read,
847 .write = i915_error_state_write,
848 .llseek = default_llseek,
849 .release = i915_error_state_release,
850};
851
Jesse Barnesf97108d2010-01-29 11:27:07 -0800852static int i915_rstdby_delays(struct seq_file *m, void *unused)
853{
854 struct drm_info_node *node = (struct drm_info_node *) m->private;
855 struct drm_device *dev = node->minor->dev;
856 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700857 u16 crstanddelay;
858 int ret;
859
860 ret = mutex_lock_interruptible(&dev->struct_mutex);
861 if (ret)
862 return ret;
863
864 crstanddelay = I915_READ16(CRSTANDVID);
865
866 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800867
868 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
869
870 return 0;
871}
872
873static int i915_cur_delayinfo(struct seq_file *m, void *unused)
874{
875 struct drm_info_node *node = (struct drm_info_node *) m->private;
876 struct drm_device *dev = node->minor->dev;
877 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100878 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800879
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800880 if (IS_GEN5(dev)) {
881 u16 rgvswctl = I915_READ16(MEMSWCTL);
882 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
883
884 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
885 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
886 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
887 MEMSTAT_VID_SHIFT);
888 seq_printf(m, "Current P-state: %d\n",
889 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700890 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800891 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
892 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
893 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800894 u32 rpstat;
895 u32 rpupei, rpcurup, rpprevup;
896 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800897 int max_freq;
898
899 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100900 ret = mutex_lock_interruptible(&dev->struct_mutex);
901 if (ret)
902 return ret;
903
Ben Widawskyfcca7922011-04-25 11:23:07 -0700904 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800905
Jesse Barnesccab5c82011-01-18 15:49:25 -0800906 rpstat = I915_READ(GEN6_RPSTAT1);
907 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
908 rpcurup = I915_READ(GEN6_RP_CUR_UP);
909 rpprevup = I915_READ(GEN6_RP_PREV_UP);
910 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
911 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
912 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
913
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100914 gen6_gt_force_wake_put(dev_priv);
915 mutex_unlock(&dev->struct_mutex);
916
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800917 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800918 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800919 seq_printf(m, "Render p-state ratio: %d\n",
920 (gt_perf_status & 0xff00) >> 8);
921 seq_printf(m, "Render p-state VID: %d\n",
922 gt_perf_status & 0xff);
923 seq_printf(m, "Render p-state limit: %d\n",
924 rp_state_limits & 0xff);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800925 seq_printf(m, "CAGF: %dMHz\n", ((rpstat & GEN6_CAGF_MASK) >>
Jesse Barnese281fca2011-03-18 10:32:07 -0700926 GEN6_CAGF_SHIFT) * 50);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800927 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
928 GEN6_CURICONT_MASK);
929 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
930 GEN6_CURBSYTAVG_MASK);
931 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
932 GEN6_CURBSYTAVG_MASK);
933 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
934 GEN6_CURIAVG_MASK);
935 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
936 GEN6_CURBSYTAVG_MASK);
937 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
938 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800939
940 max_freq = (rp_state_cap & 0xff0000) >> 16;
941 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700942 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800943
944 max_freq = (rp_state_cap & 0xff00) >> 8;
945 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700946 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800947
948 max_freq = rp_state_cap & 0xff;
949 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700950 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800951 } else {
952 seq_printf(m, "no P-state info available\n");
953 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800954
955 return 0;
956}
957
958static int i915_delayfreq_table(struct seq_file *m, void *unused)
959{
960 struct drm_info_node *node = (struct drm_info_node *) m->private;
961 struct drm_device *dev = node->minor->dev;
962 drm_i915_private_t *dev_priv = dev->dev_private;
963 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700964 int ret, i;
965
966 ret = mutex_lock_interruptible(&dev->struct_mutex);
967 if (ret)
968 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800969
970 for (i = 0; i < 16; i++) {
971 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700972 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
973 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800974 }
975
Ben Widawsky616fdb52011-10-05 11:44:54 -0700976 mutex_unlock(&dev->struct_mutex);
977
Jesse Barnesf97108d2010-01-29 11:27:07 -0800978 return 0;
979}
980
981static inline int MAP_TO_MV(int map)
982{
983 return 1250 - (map * 25);
984}
985
986static int i915_inttoext_table(struct seq_file *m, void *unused)
987{
988 struct drm_info_node *node = (struct drm_info_node *) m->private;
989 struct drm_device *dev = node->minor->dev;
990 drm_i915_private_t *dev_priv = dev->dev_private;
991 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700992 int ret, i;
993
994 ret = mutex_lock_interruptible(&dev->struct_mutex);
995 if (ret)
996 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800997
998 for (i = 1; i <= 32; i++) {
999 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1000 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1001 }
1002
Ben Widawsky616fdb52011-10-05 11:44:54 -07001003 mutex_unlock(&dev->struct_mutex);
1004
Jesse Barnesf97108d2010-01-29 11:27:07 -08001005 return 0;
1006}
1007
Ben Widawsky4d855292011-12-12 19:34:16 -08001008static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001009{
1010 struct drm_info_node *node = (struct drm_info_node *) m->private;
1011 struct drm_device *dev = node->minor->dev;
1012 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001013 u32 rgvmodectl, rstdbyctl;
1014 u16 crstandvid;
1015 int ret;
1016
1017 ret = mutex_lock_interruptible(&dev->struct_mutex);
1018 if (ret)
1019 return ret;
1020
1021 rgvmodectl = I915_READ(MEMMODECTL);
1022 rstdbyctl = I915_READ(RSTDBYCTL);
1023 crstandvid = I915_READ16(CRSTANDVID);
1024
1025 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001026
1027 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1028 "yes" : "no");
1029 seq_printf(m, "Boost freq: %d\n",
1030 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1031 MEMMODE_BOOST_FREQ_SHIFT);
1032 seq_printf(m, "HW control enabled: %s\n",
1033 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1034 seq_printf(m, "SW control enabled: %s\n",
1035 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1036 seq_printf(m, "Gated voltage change: %s\n",
1037 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1038 seq_printf(m, "Starting frequency: P%d\n",
1039 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001040 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001041 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001042 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1043 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1044 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1045 seq_printf(m, "Render standby enabled: %s\n",
1046 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001047 seq_printf(m, "Current RS state: ");
1048 switch (rstdbyctl & RSX_STATUS_MASK) {
1049 case RSX_STATUS_ON:
1050 seq_printf(m, "on\n");
1051 break;
1052 case RSX_STATUS_RC1:
1053 seq_printf(m, "RC1\n");
1054 break;
1055 case RSX_STATUS_RC1E:
1056 seq_printf(m, "RC1E\n");
1057 break;
1058 case RSX_STATUS_RS1:
1059 seq_printf(m, "RS1\n");
1060 break;
1061 case RSX_STATUS_RS2:
1062 seq_printf(m, "RS2 (RC6)\n");
1063 break;
1064 case RSX_STATUS_RS3:
1065 seq_printf(m, "RC3 (RC6+)\n");
1066 break;
1067 default:
1068 seq_printf(m, "unknown\n");
1069 break;
1070 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001071
1072 return 0;
1073}
1074
Ben Widawsky4d855292011-12-12 19:34:16 -08001075static int gen6_drpc_info(struct seq_file *m)
1076{
1077
1078 struct drm_info_node *node = (struct drm_info_node *) m->private;
1079 struct drm_device *dev = node->minor->dev;
1080 struct drm_i915_private *dev_priv = dev->dev_private;
1081 u32 rpmodectl1, gt_core_status, rcctl1;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001082 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001083 int count=0, ret;
1084
1085
1086 ret = mutex_lock_interruptible(&dev->struct_mutex);
1087 if (ret)
1088 return ret;
1089
Daniel Vetter93b525d2012-01-25 13:52:43 +01001090 spin_lock_irq(&dev_priv->gt_lock);
1091 forcewake_count = dev_priv->forcewake_count;
1092 spin_unlock_irq(&dev_priv->gt_lock);
1093
1094 if (forcewake_count) {
1095 seq_printf(m, "RC information inaccurate because somebody "
1096 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001097 } else {
1098 /* NB: we cannot use forcewake, else we read the wrong values */
1099 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1100 udelay(10);
1101 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1102 }
1103
1104 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1105 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1106
1107 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1108 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1109 mutex_unlock(&dev->struct_mutex);
1110
1111 seq_printf(m, "Video Turbo Mode: %s\n",
1112 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1113 seq_printf(m, "HW control enabled: %s\n",
1114 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1115 seq_printf(m, "SW control enabled: %s\n",
1116 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1117 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001118 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001119 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1120 seq_printf(m, "RC6 Enabled: %s\n",
1121 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1122 seq_printf(m, "Deep RC6 Enabled: %s\n",
1123 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1124 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1125 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1126 seq_printf(m, "Current RC state: ");
1127 switch (gt_core_status & GEN6_RCn_MASK) {
1128 case GEN6_RC0:
1129 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1130 seq_printf(m, "Core Power Down\n");
1131 else
1132 seq_printf(m, "on\n");
1133 break;
1134 case GEN6_RC3:
1135 seq_printf(m, "RC3\n");
1136 break;
1137 case GEN6_RC6:
1138 seq_printf(m, "RC6\n");
1139 break;
1140 case GEN6_RC7:
1141 seq_printf(m, "RC7\n");
1142 break;
1143 default:
1144 seq_printf(m, "Unknown\n");
1145 break;
1146 }
1147
1148 seq_printf(m, "Core Power Down: %s\n",
1149 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001150
1151 /* Not exactly sure what this is */
1152 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1153 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1154 seq_printf(m, "RC6 residency since boot: %u\n",
1155 I915_READ(GEN6_GT_GFX_RC6));
1156 seq_printf(m, "RC6+ residency since boot: %u\n",
1157 I915_READ(GEN6_GT_GFX_RC6p));
1158 seq_printf(m, "RC6++ residency since boot: %u\n",
1159 I915_READ(GEN6_GT_GFX_RC6pp));
1160
Ben Widawsky4d855292011-12-12 19:34:16 -08001161 return 0;
1162}
1163
1164static int i915_drpc_info(struct seq_file *m, void *unused)
1165{
1166 struct drm_info_node *node = (struct drm_info_node *) m->private;
1167 struct drm_device *dev = node->minor->dev;
1168
1169 if (IS_GEN6(dev) || IS_GEN7(dev))
1170 return gen6_drpc_info(m);
1171 else
1172 return ironlake_drpc_info(m);
1173}
1174
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001175static int i915_fbc_status(struct seq_file *m, void *unused)
1176{
1177 struct drm_info_node *node = (struct drm_info_node *) m->private;
1178 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001179 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001180
Adam Jacksonee5382a2010-04-23 11:17:39 -04001181 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001182 seq_printf(m, "FBC unsupported on this chipset\n");
1183 return 0;
1184 }
1185
Adam Jacksonee5382a2010-04-23 11:17:39 -04001186 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001187 seq_printf(m, "FBC enabled\n");
1188 } else {
1189 seq_printf(m, "FBC disabled: ");
1190 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001191 case FBC_NO_OUTPUT:
1192 seq_printf(m, "no outputs");
1193 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001194 case FBC_STOLEN_TOO_SMALL:
1195 seq_printf(m, "not enough stolen memory");
1196 break;
1197 case FBC_UNSUPPORTED_MODE:
1198 seq_printf(m, "mode not supported");
1199 break;
1200 case FBC_MODE_TOO_LARGE:
1201 seq_printf(m, "mode too large");
1202 break;
1203 case FBC_BAD_PLANE:
1204 seq_printf(m, "FBC unsupported on plane");
1205 break;
1206 case FBC_NOT_TILED:
1207 seq_printf(m, "scanout buffer not tiled");
1208 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001209 case FBC_MULTIPLE_PIPES:
1210 seq_printf(m, "multiple pipes are enabled");
1211 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001212 case FBC_MODULE_PARAM:
1213 seq_printf(m, "disabled per module param (default off)");
1214 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001215 default:
1216 seq_printf(m, "unknown reason");
1217 }
1218 seq_printf(m, "\n");
1219 }
1220 return 0;
1221}
1222
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001223static int i915_sr_status(struct seq_file *m, void *unused)
1224{
1225 struct drm_info_node *node = (struct drm_info_node *) m->private;
1226 struct drm_device *dev = node->minor->dev;
1227 drm_i915_private_t *dev_priv = dev->dev_private;
1228 bool sr_enabled = false;
1229
Yuanhan Liu13982612010-12-15 15:42:31 +08001230 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001231 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001232 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001233 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1234 else if (IS_I915GM(dev))
1235 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1236 else if (IS_PINEVIEW(dev))
1237 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1238
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001239 seq_printf(m, "self-refresh: %s\n",
1240 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001241
1242 return 0;
1243}
1244
Jesse Barnes7648fa92010-05-20 14:28:11 -07001245static int i915_emon_status(struct seq_file *m, void *unused)
1246{
1247 struct drm_info_node *node = (struct drm_info_node *) m->private;
1248 struct drm_device *dev = node->minor->dev;
1249 drm_i915_private_t *dev_priv = dev->dev_private;
1250 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001251 int ret;
1252
Chris Wilson582be6b2012-04-30 19:35:02 +01001253 if (!IS_GEN5(dev))
1254 return -ENODEV;
1255
Chris Wilsonde227ef2010-07-03 07:58:38 +01001256 ret = mutex_lock_interruptible(&dev->struct_mutex);
1257 if (ret)
1258 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001259
1260 temp = i915_mch_val(dev_priv);
1261 chipset = i915_chipset_val(dev_priv);
1262 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001263 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001264
1265 seq_printf(m, "GMCH temp: %ld\n", temp);
1266 seq_printf(m, "Chipset power: %ld\n", chipset);
1267 seq_printf(m, "GFX power: %ld\n", gfx);
1268 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1269
1270 return 0;
1271}
1272
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001273static int i915_ring_freq_table(struct seq_file *m, void *unused)
1274{
1275 struct drm_info_node *node = (struct drm_info_node *) m->private;
1276 struct drm_device *dev = node->minor->dev;
1277 drm_i915_private_t *dev_priv = dev->dev_private;
1278 int ret;
1279 int gpu_freq, ia_freq;
1280
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001281 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001282 seq_printf(m, "unsupported on this chipset\n");
1283 return 0;
1284 }
1285
1286 ret = mutex_lock_interruptible(&dev->struct_mutex);
1287 if (ret)
1288 return ret;
1289
1290 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1291
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001292 for (gpu_freq = dev_priv->rps.min_delay;
1293 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001294 gpu_freq++) {
1295 I915_WRITE(GEN6_PCODE_DATA, gpu_freq);
1296 I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY |
1297 GEN6_PCODE_READ_MIN_FREQ_TABLE);
1298 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) &
1299 GEN6_PCODE_READY) == 0, 10)) {
1300 DRM_ERROR("pcode read of freq table timed out\n");
1301 continue;
1302 }
1303 ia_freq = I915_READ(GEN6_PCODE_DATA);
1304 seq_printf(m, "%d\t\t%d\n", gpu_freq * 50, ia_freq * 100);
1305 }
1306
1307 mutex_unlock(&dev->struct_mutex);
1308
1309 return 0;
1310}
1311
Jesse Barnes7648fa92010-05-20 14:28:11 -07001312static int i915_gfxec(struct seq_file *m, void *unused)
1313{
1314 struct drm_info_node *node = (struct drm_info_node *) m->private;
1315 struct drm_device *dev = node->minor->dev;
1316 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001317 int ret;
1318
1319 ret = mutex_lock_interruptible(&dev->struct_mutex);
1320 if (ret)
1321 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001322
1323 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1324
Ben Widawsky616fdb52011-10-05 11:44:54 -07001325 mutex_unlock(&dev->struct_mutex);
1326
Jesse Barnes7648fa92010-05-20 14:28:11 -07001327 return 0;
1328}
1329
Chris Wilson44834a62010-08-19 16:09:23 +01001330static int i915_opregion(struct seq_file *m, void *unused)
1331{
1332 struct drm_info_node *node = (struct drm_info_node *) m->private;
1333 struct drm_device *dev = node->minor->dev;
1334 drm_i915_private_t *dev_priv = dev->dev_private;
1335 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001336 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001337 int ret;
1338
Daniel Vetter0d38f002012-04-21 22:49:10 +02001339 if (data == NULL)
1340 return -ENOMEM;
1341
Chris Wilson44834a62010-08-19 16:09:23 +01001342 ret = mutex_lock_interruptible(&dev->struct_mutex);
1343 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001344 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001345
Daniel Vetter0d38f002012-04-21 22:49:10 +02001346 if (opregion->header) {
1347 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1348 seq_write(m, data, OPREGION_SIZE);
1349 }
Chris Wilson44834a62010-08-19 16:09:23 +01001350
1351 mutex_unlock(&dev->struct_mutex);
1352
Daniel Vetter0d38f002012-04-21 22:49:10 +02001353out:
1354 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001355 return 0;
1356}
1357
Chris Wilson37811fc2010-08-25 22:45:57 +01001358static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1359{
1360 struct drm_info_node *node = (struct drm_info_node *) m->private;
1361 struct drm_device *dev = node->minor->dev;
1362 drm_i915_private_t *dev_priv = dev->dev_private;
1363 struct intel_fbdev *ifbdev;
1364 struct intel_framebuffer *fb;
1365 int ret;
1366
1367 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1368 if (ret)
1369 return ret;
1370
1371 ifbdev = dev_priv->fbdev;
1372 fb = to_intel_framebuffer(ifbdev->helper.fb);
1373
1374 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1375 fb->base.width,
1376 fb->base.height,
1377 fb->base.depth,
1378 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001379 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001380 seq_printf(m, "\n");
1381
1382 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1383 if (&fb->base == ifbdev->helper.fb)
1384 continue;
1385
1386 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1387 fb->base.width,
1388 fb->base.height,
1389 fb->base.depth,
1390 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001391 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001392 seq_printf(m, "\n");
1393 }
1394
1395 mutex_unlock(&dev->mode_config.mutex);
1396
1397 return 0;
1398}
1399
Ben Widawskye76d3632011-03-19 18:14:29 -07001400static int i915_context_status(struct seq_file *m, void *unused)
1401{
1402 struct drm_info_node *node = (struct drm_info_node *) m->private;
1403 struct drm_device *dev = node->minor->dev;
1404 drm_i915_private_t *dev_priv = dev->dev_private;
1405 int ret;
1406
1407 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1408 if (ret)
1409 return ret;
1410
Ben Widawskydc501fb2011-06-29 11:41:51 -07001411 if (dev_priv->pwrctx) {
1412 seq_printf(m, "power context ");
1413 describe_obj(m, dev_priv->pwrctx);
1414 seq_printf(m, "\n");
1415 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001416
Ben Widawskydc501fb2011-06-29 11:41:51 -07001417 if (dev_priv->renderctx) {
1418 seq_printf(m, "render context ");
1419 describe_obj(m, dev_priv->renderctx);
1420 seq_printf(m, "\n");
1421 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001422
1423 mutex_unlock(&dev->mode_config.mutex);
1424
1425 return 0;
1426}
1427
Ben Widawsky6d794d42011-04-25 11:25:56 -07001428static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1429{
1430 struct drm_info_node *node = (struct drm_info_node *) m->private;
1431 struct drm_device *dev = node->minor->dev;
1432 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001433 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001434
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001435 spin_lock_irq(&dev_priv->gt_lock);
1436 forcewake_count = dev_priv->forcewake_count;
1437 spin_unlock_irq(&dev_priv->gt_lock);
1438
1439 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001440
1441 return 0;
1442}
1443
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001444static const char *swizzle_string(unsigned swizzle)
1445{
1446 switch(swizzle) {
1447 case I915_BIT_6_SWIZZLE_NONE:
1448 return "none";
1449 case I915_BIT_6_SWIZZLE_9:
1450 return "bit9";
1451 case I915_BIT_6_SWIZZLE_9_10:
1452 return "bit9/bit10";
1453 case I915_BIT_6_SWIZZLE_9_11:
1454 return "bit9/bit11";
1455 case I915_BIT_6_SWIZZLE_9_10_11:
1456 return "bit9/bit10/bit11";
1457 case I915_BIT_6_SWIZZLE_9_17:
1458 return "bit9/bit17";
1459 case I915_BIT_6_SWIZZLE_9_10_17:
1460 return "bit9/bit10/bit17";
1461 case I915_BIT_6_SWIZZLE_UNKNOWN:
1462 return "unkown";
1463 }
1464
1465 return "bug";
1466}
1467
1468static int i915_swizzle_info(struct seq_file *m, void *data)
1469{
1470 struct drm_info_node *node = (struct drm_info_node *) m->private;
1471 struct drm_device *dev = node->minor->dev;
1472 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001473 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001474
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001475 ret = mutex_lock_interruptible(&dev->struct_mutex);
1476 if (ret)
1477 return ret;
1478
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001479 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1480 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1481 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1482 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1483
1484 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1485 seq_printf(m, "DDC = 0x%08x\n",
1486 I915_READ(DCC));
1487 seq_printf(m, "C0DRB3 = 0x%04x\n",
1488 I915_READ16(C0DRB3));
1489 seq_printf(m, "C1DRB3 = 0x%04x\n",
1490 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001491 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1492 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1493 I915_READ(MAD_DIMM_C0));
1494 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1495 I915_READ(MAD_DIMM_C1));
1496 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1497 I915_READ(MAD_DIMM_C2));
1498 seq_printf(m, "TILECTL = 0x%08x\n",
1499 I915_READ(TILECTL));
1500 seq_printf(m, "ARB_MODE = 0x%08x\n",
1501 I915_READ(ARB_MODE));
1502 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1503 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001504 }
1505 mutex_unlock(&dev->struct_mutex);
1506
1507 return 0;
1508}
1509
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001510static int i915_ppgtt_info(struct seq_file *m, void *data)
1511{
1512 struct drm_info_node *node = (struct drm_info_node *) m->private;
1513 struct drm_device *dev = node->minor->dev;
1514 struct drm_i915_private *dev_priv = dev->dev_private;
1515 struct intel_ring_buffer *ring;
1516 int i, ret;
1517
1518
1519 ret = mutex_lock_interruptible(&dev->struct_mutex);
1520 if (ret)
1521 return ret;
1522 if (INTEL_INFO(dev)->gen == 6)
1523 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1524
1525 for (i = 0; i < I915_NUM_RINGS; i++) {
1526 ring = &dev_priv->ring[i];
1527
1528 seq_printf(m, "%s\n", ring->name);
1529 if (INTEL_INFO(dev)->gen == 7)
1530 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1531 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1532 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1533 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1534 }
1535 if (dev_priv->mm.aliasing_ppgtt) {
1536 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1537
1538 seq_printf(m, "aliasing PPGTT:\n");
1539 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1540 }
1541 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1542 mutex_unlock(&dev->struct_mutex);
1543
1544 return 0;
1545}
1546
Jesse Barnes57f350b2012-03-28 13:39:25 -07001547static int i915_dpio_info(struct seq_file *m, void *data)
1548{
1549 struct drm_info_node *node = (struct drm_info_node *) m->private;
1550 struct drm_device *dev = node->minor->dev;
1551 struct drm_i915_private *dev_priv = dev->dev_private;
1552 int ret;
1553
1554
1555 if (!IS_VALLEYVIEW(dev)) {
1556 seq_printf(m, "unsupported\n");
1557 return 0;
1558 }
1559
1560 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1561 if (ret)
1562 return ret;
1563
1564 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1565
1566 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1567 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1568 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1569 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1570
1571 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1572 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1573 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1574 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1575
1576 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1577 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1578 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1579 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1580
1581 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1582 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1583 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1584 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1585
1586 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1587 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1588
1589 mutex_unlock(&dev->mode_config.mutex);
1590
1591 return 0;
1592}
1593
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001594static ssize_t
1595i915_wedged_read(struct file *filp,
1596 char __user *ubuf,
1597 size_t max,
1598 loff_t *ppos)
1599{
1600 struct drm_device *dev = filp->private_data;
1601 drm_i915_private_t *dev_priv = dev->dev_private;
1602 char buf[80];
1603 int len;
1604
Akshay Joshi0206e352011-08-16 15:34:10 -04001605 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001606 "wedged : %d\n",
1607 atomic_read(&dev_priv->mm.wedged));
1608
Akshay Joshi0206e352011-08-16 15:34:10 -04001609 if (len > sizeof(buf))
1610 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001611
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001612 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1613}
1614
1615static ssize_t
1616i915_wedged_write(struct file *filp,
1617 const char __user *ubuf,
1618 size_t cnt,
1619 loff_t *ppos)
1620{
1621 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001622 char buf[20];
1623 int val = 1;
1624
1625 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001626 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001627 return -EINVAL;
1628
1629 if (copy_from_user(buf, ubuf, cnt))
1630 return -EFAULT;
1631 buf[cnt] = 0;
1632
1633 val = simple_strtoul(buf, NULL, 0);
1634 }
1635
1636 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001637 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001638
1639 return cnt;
1640}
1641
1642static const struct file_operations i915_wedged_fops = {
1643 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001644 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001645 .read = i915_wedged_read,
1646 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001647 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001648};
1649
Jesse Barnes358733e2011-07-27 11:53:01 -07001650static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001651i915_ring_stop_read(struct file *filp,
1652 char __user *ubuf,
1653 size_t max,
1654 loff_t *ppos)
1655{
1656 struct drm_device *dev = filp->private_data;
1657 drm_i915_private_t *dev_priv = dev->dev_private;
1658 char buf[20];
1659 int len;
1660
1661 len = snprintf(buf, sizeof(buf),
1662 "0x%08x\n", dev_priv->stop_rings);
1663
1664 if (len > sizeof(buf))
1665 len = sizeof(buf);
1666
1667 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1668}
1669
1670static ssize_t
1671i915_ring_stop_write(struct file *filp,
1672 const char __user *ubuf,
1673 size_t cnt,
1674 loff_t *ppos)
1675{
1676 struct drm_device *dev = filp->private_data;
1677 struct drm_i915_private *dev_priv = dev->dev_private;
1678 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001679 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001680
1681 if (cnt > 0) {
1682 if (cnt > sizeof(buf) - 1)
1683 return -EINVAL;
1684
1685 if (copy_from_user(buf, ubuf, cnt))
1686 return -EFAULT;
1687 buf[cnt] = 0;
1688
1689 val = simple_strtoul(buf, NULL, 0);
1690 }
1691
1692 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1693
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001694 ret = mutex_lock_interruptible(&dev->struct_mutex);
1695 if (ret)
1696 return ret;
1697
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001698 dev_priv->stop_rings = val;
1699 mutex_unlock(&dev->struct_mutex);
1700
1701 return cnt;
1702}
1703
1704static const struct file_operations i915_ring_stop_fops = {
1705 .owner = THIS_MODULE,
1706 .open = simple_open,
1707 .read = i915_ring_stop_read,
1708 .write = i915_ring_stop_write,
1709 .llseek = default_llseek,
1710};
Daniel Vetterd5442302012-04-27 15:17:40 +02001711
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001712static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001713i915_max_freq_read(struct file *filp,
1714 char __user *ubuf,
1715 size_t max,
1716 loff_t *ppos)
1717{
1718 struct drm_device *dev = filp->private_data;
1719 drm_i915_private_t *dev_priv = dev->dev_private;
1720 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001721 int len, ret;
1722
1723 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1724 return -ENODEV;
1725
1726 ret = mutex_lock_interruptible(&dev->struct_mutex);
1727 if (ret)
1728 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001729
Akshay Joshi0206e352011-08-16 15:34:10 -04001730 len = snprintf(buf, sizeof(buf),
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001731 "max freq: %d\n", dev_priv->rps.max_delay * 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001732 mutex_unlock(&dev->struct_mutex);
Jesse Barnes358733e2011-07-27 11:53:01 -07001733
Akshay Joshi0206e352011-08-16 15:34:10 -04001734 if (len > sizeof(buf))
1735 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001736
1737 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1738}
1739
1740static ssize_t
1741i915_max_freq_write(struct file *filp,
1742 const char __user *ubuf,
1743 size_t cnt,
1744 loff_t *ppos)
1745{
1746 struct drm_device *dev = filp->private_data;
1747 struct drm_i915_private *dev_priv = dev->dev_private;
1748 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001749 int val = 1, ret;
1750
1751 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1752 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001753
1754 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001755 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001756 return -EINVAL;
1757
1758 if (copy_from_user(buf, ubuf, cnt))
1759 return -EFAULT;
1760 buf[cnt] = 0;
1761
1762 val = simple_strtoul(buf, NULL, 0);
1763 }
1764
1765 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1766
Daniel Vetter004777c2012-08-09 15:07:01 +02001767 ret = mutex_lock_interruptible(&dev->struct_mutex);
1768 if (ret)
1769 return ret;
1770
Jesse Barnes358733e2011-07-27 11:53:01 -07001771 /*
1772 * Turbo will still be enabled, but won't go above the set value.
1773 */
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001774 dev_priv->rps.max_delay = val / 50;
Jesse Barnes358733e2011-07-27 11:53:01 -07001775
1776 gen6_set_rps(dev, val / 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001777 mutex_unlock(&dev->struct_mutex);
Jesse Barnes358733e2011-07-27 11:53:01 -07001778
1779 return cnt;
1780}
1781
1782static const struct file_operations i915_max_freq_fops = {
1783 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001784 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001785 .read = i915_max_freq_read,
1786 .write = i915_max_freq_write,
1787 .llseek = default_llseek,
1788};
1789
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001790static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001791i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1792 loff_t *ppos)
1793{
1794 struct drm_device *dev = filp->private_data;
1795 drm_i915_private_t *dev_priv = dev->dev_private;
1796 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001797 int len, ret;
1798
1799 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1800 return -ENODEV;
1801
1802 ret = mutex_lock_interruptible(&dev->struct_mutex);
1803 if (ret)
1804 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001805
1806 len = snprintf(buf, sizeof(buf),
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001807 "min freq: %d\n", dev_priv->rps.min_delay * 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001808 mutex_unlock(&dev->struct_mutex);
Jesse Barnes1523c312012-05-25 12:34:54 -07001809
1810 if (len > sizeof(buf))
1811 len = sizeof(buf);
1812
1813 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1814}
1815
1816static ssize_t
1817i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
1818 loff_t *ppos)
1819{
1820 struct drm_device *dev = filp->private_data;
1821 struct drm_i915_private *dev_priv = dev->dev_private;
1822 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001823 int val = 1, ret;
1824
1825 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1826 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07001827
1828 if (cnt > 0) {
1829 if (cnt > sizeof(buf) - 1)
1830 return -EINVAL;
1831
1832 if (copy_from_user(buf, ubuf, cnt))
1833 return -EFAULT;
1834 buf[cnt] = 0;
1835
1836 val = simple_strtoul(buf, NULL, 0);
1837 }
1838
1839 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
1840
Daniel Vetter004777c2012-08-09 15:07:01 +02001841 ret = mutex_lock_interruptible(&dev->struct_mutex);
1842 if (ret)
1843 return ret;
1844
Jesse Barnes1523c312012-05-25 12:34:54 -07001845 /*
1846 * Turbo will still be enabled, but won't go below the set value.
1847 */
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001848 dev_priv->rps.min_delay = val / 50;
Jesse Barnes1523c312012-05-25 12:34:54 -07001849
1850 gen6_set_rps(dev, val / 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001851 mutex_unlock(&dev->struct_mutex);
Jesse Barnes1523c312012-05-25 12:34:54 -07001852
1853 return cnt;
1854}
1855
1856static const struct file_operations i915_min_freq_fops = {
1857 .owner = THIS_MODULE,
1858 .open = simple_open,
1859 .read = i915_min_freq_read,
1860 .write = i915_min_freq_write,
1861 .llseek = default_llseek,
1862};
1863
1864static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001865i915_cache_sharing_read(struct file *filp,
1866 char __user *ubuf,
1867 size_t max,
1868 loff_t *ppos)
1869{
1870 struct drm_device *dev = filp->private_data;
1871 drm_i915_private_t *dev_priv = dev->dev_private;
1872 char buf[80];
1873 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001874 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001875
Daniel Vetter004777c2012-08-09 15:07:01 +02001876 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1877 return -ENODEV;
1878
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001879 ret = mutex_lock_interruptible(&dev->struct_mutex);
1880 if (ret)
1881 return ret;
1882
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001883 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1884 mutex_unlock(&dev_priv->dev->struct_mutex);
1885
Akshay Joshi0206e352011-08-16 15:34:10 -04001886 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001887 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
1888 GEN6_MBC_SNPCR_SHIFT);
1889
Akshay Joshi0206e352011-08-16 15:34:10 -04001890 if (len > sizeof(buf))
1891 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001892
1893 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1894}
1895
1896static ssize_t
1897i915_cache_sharing_write(struct file *filp,
1898 const char __user *ubuf,
1899 size_t cnt,
1900 loff_t *ppos)
1901{
1902 struct drm_device *dev = filp->private_data;
1903 struct drm_i915_private *dev_priv = dev->dev_private;
1904 char buf[20];
1905 u32 snpcr;
1906 int val = 1;
1907
Daniel Vetter004777c2012-08-09 15:07:01 +02001908 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1909 return -ENODEV;
1910
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001911 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001912 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001913 return -EINVAL;
1914
1915 if (copy_from_user(buf, ubuf, cnt))
1916 return -EFAULT;
1917 buf[cnt] = 0;
1918
1919 val = simple_strtoul(buf, NULL, 0);
1920 }
1921
1922 if (val < 0 || val > 3)
1923 return -EINVAL;
1924
1925 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
1926
1927 /* Update the cache sharing policy here as well */
1928 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1929 snpcr &= ~GEN6_MBC_SNPCR_MASK;
1930 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
1931 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
1932
1933 return cnt;
1934}
1935
1936static const struct file_operations i915_cache_sharing_fops = {
1937 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001938 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001939 .read = i915_cache_sharing_read,
1940 .write = i915_cache_sharing_write,
1941 .llseek = default_llseek,
1942};
1943
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001944/* As the drm_debugfs_init() routines are called before dev->dev_private is
1945 * allocated we need to hook into the minor for release. */
1946static int
1947drm_add_fake_info_node(struct drm_minor *minor,
1948 struct dentry *ent,
1949 const void *key)
1950{
1951 struct drm_info_node *node;
1952
1953 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
1954 if (node == NULL) {
1955 debugfs_remove(ent);
1956 return -ENOMEM;
1957 }
1958
1959 node->minor = minor;
1960 node->dent = ent;
1961 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01001962
1963 mutex_lock(&minor->debugfs_lock);
1964 list_add(&node->list, &minor->debugfs_list);
1965 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001966
1967 return 0;
1968}
1969
Ben Widawsky6d794d42011-04-25 11:25:56 -07001970static int i915_forcewake_open(struct inode *inode, struct file *file)
1971{
1972 struct drm_device *dev = inode->i_private;
1973 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001974
Daniel Vetter075edca2012-01-24 09:44:28 +01001975 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001976 return 0;
1977
Ben Widawsky6d794d42011-04-25 11:25:56 -07001978 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001979
1980 return 0;
1981}
1982
Ben Widawskyc43b5632012-04-16 14:07:40 -07001983static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001984{
1985 struct drm_device *dev = inode->i_private;
1986 struct drm_i915_private *dev_priv = dev->dev_private;
1987
Daniel Vetter075edca2012-01-24 09:44:28 +01001988 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001989 return 0;
1990
Ben Widawsky6d794d42011-04-25 11:25:56 -07001991 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001992
1993 return 0;
1994}
1995
1996static const struct file_operations i915_forcewake_fops = {
1997 .owner = THIS_MODULE,
1998 .open = i915_forcewake_open,
1999 .release = i915_forcewake_release,
2000};
2001
2002static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2003{
2004 struct drm_device *dev = minor->dev;
2005 struct dentry *ent;
2006
2007 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002008 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002009 root, dev,
2010 &i915_forcewake_fops);
2011 if (IS_ERR(ent))
2012 return PTR_ERR(ent);
2013
Ben Widawsky8eb57292011-05-11 15:10:58 -07002014 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002015}
2016
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002017static int i915_debugfs_create(struct dentry *root,
2018 struct drm_minor *minor,
2019 const char *name,
2020 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002021{
2022 struct drm_device *dev = minor->dev;
2023 struct dentry *ent;
2024
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002025 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002026 S_IRUGO | S_IWUSR,
2027 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002028 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002029 if (IS_ERR(ent))
2030 return PTR_ERR(ent);
2031
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002032 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002033}
2034
Ben Gamari27c202a2009-07-01 22:26:52 -04002035static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002036 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002037 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002038 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002039 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002040 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002041 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002042 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002043 {"i915_gem_request", i915_gem_request_info, 0},
2044 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002045 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002046 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002047 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2048 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2049 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002050 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2051 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2052 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2053 {"i915_inttoext_table", i915_inttoext_table, 0},
2054 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002055 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002056 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002057 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002058 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002059 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002060 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002061 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002062 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002063 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002064 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002065 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002066 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002067};
Ben Gamari27c202a2009-07-01 22:26:52 -04002068#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002069
Ben Gamari27c202a2009-07-01 22:26:52 -04002070int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002071{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002072 int ret;
2073
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002074 ret = i915_debugfs_create(minor->debugfs_root, minor,
2075 "i915_wedged",
2076 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002077 if (ret)
2078 return ret;
2079
Ben Widawsky6d794d42011-04-25 11:25:56 -07002080 ret = i915_forcewake_create(minor->debugfs_root, minor);
2081 if (ret)
2082 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002083
2084 ret = i915_debugfs_create(minor->debugfs_root, minor,
2085 "i915_max_freq",
2086 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002087 if (ret)
2088 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002089
2090 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002091 "i915_min_freq",
2092 &i915_min_freq_fops);
2093 if (ret)
2094 return ret;
2095
2096 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002097 "i915_cache_sharing",
2098 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002099 if (ret)
2100 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002101
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002102 ret = i915_debugfs_create(minor->debugfs_root, minor,
2103 "i915_ring_stop",
2104 &i915_ring_stop_fops);
2105 if (ret)
2106 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002107
Daniel Vetterd5442302012-04-27 15:17:40 +02002108 ret = i915_debugfs_create(minor->debugfs_root, minor,
2109 "i915_error_state",
2110 &i915_error_state_fops);
2111 if (ret)
2112 return ret;
2113
Ben Gamari27c202a2009-07-01 22:26:52 -04002114 return drm_debugfs_create_files(i915_debugfs_list,
2115 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002116 minor->debugfs_root, minor);
2117}
2118
Ben Gamari27c202a2009-07-01 22:26:52 -04002119void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002120{
Ben Gamari27c202a2009-07-01 22:26:52 -04002121 drm_debugfs_remove_files(i915_debugfs_list,
2122 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002123 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2124 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002125 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2126 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002127 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2128 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002129 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2130 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002131 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2132 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002133 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2134 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002135 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2136 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002137}
2138
2139#endif /* CONFIG_DEBUG_FS */