blob: 608d3ae2b5ba5dc50be4ee3615f398be67260959 [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 Wilson6299f992010-11-24 12:23:44 +0000200 u32 count, mappable_count;
201 size_t size, mappable_size;
202 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 Wilson6c085a72012-08-20 11:40:46 +0200228 size = count = 0;
229 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list)
230 size += obj->base.size, ++count;
231 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
232
Chris Wilson6299f992010-11-24 12:23:44 +0000233 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200234 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000235 if (obj->fault_mappable) {
236 size += obj->gtt_space->size;
237 ++count;
238 }
239 if (obj->pin_mappable) {
240 mappable_size += obj->gtt_space->size;
241 ++mappable_count;
242 }
243 }
244 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
245 mappable_count, mappable_size);
246 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
247 count, size);
248
249 seq_printf(m, "%zu [%zu] gtt total\n",
250 dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
Chris Wilson73aa8082010-09-30 11:46:12 +0100251
252 mutex_unlock(&dev->struct_mutex);
253
254 return 0;
255}
256
Chris Wilson08c18322011-01-10 00:00:24 +0000257static int i915_gem_gtt_info(struct seq_file *m, void* data)
258{
259 struct drm_info_node *node = (struct drm_info_node *) m->private;
260 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100261 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000262 struct drm_i915_private *dev_priv = dev->dev_private;
263 struct drm_i915_gem_object *obj;
264 size_t total_obj_size, total_gtt_size;
265 int count, ret;
266
267 ret = mutex_lock_interruptible(&dev->struct_mutex);
268 if (ret)
269 return ret;
270
271 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200272 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100273 if (list == PINNED_LIST && obj->pin_count == 0)
274 continue;
275
Chris Wilson08c18322011-01-10 00:00:24 +0000276 seq_printf(m, " ");
277 describe_obj(m, obj);
278 seq_printf(m, "\n");
279 total_obj_size += obj->base.size;
280 total_gtt_size += obj->gtt_space->size;
281 count++;
282 }
283
284 mutex_unlock(&dev->struct_mutex);
285
286 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
287 count, total_obj_size, total_gtt_size);
288
289 return 0;
290}
291
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100292static int i915_gem_pageflip_info(struct seq_file *m, void *data)
293{
294 struct drm_info_node *node = (struct drm_info_node *) m->private;
295 struct drm_device *dev = node->minor->dev;
296 unsigned long flags;
297 struct intel_crtc *crtc;
298
299 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800300 const char pipe = pipe_name(crtc->pipe);
301 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100302 struct intel_unpin_work *work;
303
304 spin_lock_irqsave(&dev->event_lock, flags);
305 work = crtc->unpin_work;
306 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800307 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100308 pipe, plane);
309 } else {
310 if (!work->pending) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800311 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100312 pipe, plane);
313 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800314 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100315 pipe, plane);
316 }
317 if (work->enable_stall_check)
318 seq_printf(m, "Stall check enabled, ");
319 else
320 seq_printf(m, "Stall check waiting for page flip ioctl, ");
321 seq_printf(m, "%d prepares\n", work->pending);
322
323 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000324 struct drm_i915_gem_object *obj = work->old_fb_obj;
325 if (obj)
326 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100327 }
328 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000329 struct drm_i915_gem_object *obj = work->pending_flip_obj;
330 if (obj)
331 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100332 }
333 }
334 spin_unlock_irqrestore(&dev->event_lock, flags);
335 }
336
337 return 0;
338}
339
Ben Gamari20172632009-02-17 20:08:50 -0500340static int i915_gem_request_info(struct seq_file *m, void *data)
341{
342 struct drm_info_node *node = (struct drm_info_node *) m->private;
343 struct drm_device *dev = node->minor->dev;
344 drm_i915_private_t *dev_priv = dev->dev_private;
345 struct drm_i915_gem_request *gem_request;
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100346 int ret, count;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100347
348 ret = mutex_lock_interruptible(&dev->struct_mutex);
349 if (ret)
350 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500351
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100352 count = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000353 if (!list_empty(&dev_priv->ring[RCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100354 seq_printf(m, "Render requests:\n");
355 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000356 &dev_priv->ring[RCS].request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100357 list) {
358 seq_printf(m, " %d @ %d\n",
359 gem_request->seqno,
360 (int) (jiffies - gem_request->emitted_jiffies));
361 }
362 count++;
363 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000364 if (!list_empty(&dev_priv->ring[VCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100365 seq_printf(m, "BSD requests:\n");
366 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000367 &dev_priv->ring[VCS].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[BCS].request_list)) {
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100376 seq_printf(m, "BLT requests:\n");
377 list_for_each_entry(gem_request,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000378 &dev_priv->ring[BCS].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++;
Ben Gamari20172632009-02-17 20:08:50 -0500385 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100386 mutex_unlock(&dev->struct_mutex);
387
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100388 if (count == 0)
389 seq_printf(m, "No requests\n");
390
Ben Gamari20172632009-02-17 20:08:50 -0500391 return 0;
392}
393
Chris Wilsonb2223492010-10-27 15:27:33 +0100394static void i915_ring_seqno_info(struct seq_file *m,
395 struct intel_ring_buffer *ring)
396{
397 if (ring->get_seqno) {
398 seq_printf(m, "Current sequence (%s): %d\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100399 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100400 }
401}
402
Ben Gamari20172632009-02-17 20:08:50 -0500403static int i915_gem_seqno_info(struct seq_file *m, void *data)
404{
405 struct drm_info_node *node = (struct drm_info_node *) m->private;
406 struct drm_device *dev = node->minor->dev;
407 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000408 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100409
410 ret = mutex_lock_interruptible(&dev->struct_mutex);
411 if (ret)
412 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500413
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000414 for (i = 0; i < I915_NUM_RINGS; i++)
415 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100416
417 mutex_unlock(&dev->struct_mutex);
418
Ben Gamari20172632009-02-17 20:08:50 -0500419 return 0;
420}
421
422
423static int i915_interrupt_info(struct seq_file *m, void *data)
424{
425 struct drm_info_node *node = (struct drm_info_node *) m->private;
426 struct drm_device *dev = node->minor->dev;
427 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800428 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100429
430 ret = mutex_lock_interruptible(&dev->struct_mutex);
431 if (ret)
432 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500433
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700434 if (IS_VALLEYVIEW(dev)) {
435 seq_printf(m, "Display IER:\t%08x\n",
436 I915_READ(VLV_IER));
437 seq_printf(m, "Display IIR:\t%08x\n",
438 I915_READ(VLV_IIR));
439 seq_printf(m, "Display IIR_RW:\t%08x\n",
440 I915_READ(VLV_IIR_RW));
441 seq_printf(m, "Display IMR:\t%08x\n",
442 I915_READ(VLV_IMR));
443 for_each_pipe(pipe)
444 seq_printf(m, "Pipe %c stat:\t%08x\n",
445 pipe_name(pipe),
446 I915_READ(PIPESTAT(pipe)));
447
448 seq_printf(m, "Master IER:\t%08x\n",
449 I915_READ(VLV_MASTER_IER));
450
451 seq_printf(m, "Render IER:\t%08x\n",
452 I915_READ(GTIER));
453 seq_printf(m, "Render IIR:\t%08x\n",
454 I915_READ(GTIIR));
455 seq_printf(m, "Render IMR:\t%08x\n",
456 I915_READ(GTIMR));
457
458 seq_printf(m, "PM IER:\t\t%08x\n",
459 I915_READ(GEN6_PMIER));
460 seq_printf(m, "PM IIR:\t\t%08x\n",
461 I915_READ(GEN6_PMIIR));
462 seq_printf(m, "PM IMR:\t\t%08x\n",
463 I915_READ(GEN6_PMIMR));
464
465 seq_printf(m, "Port hotplug:\t%08x\n",
466 I915_READ(PORT_HOTPLUG_EN));
467 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
468 I915_READ(VLV_DPFLIPSTAT));
469 seq_printf(m, "DPINVGTT:\t%08x\n",
470 I915_READ(DPINVGTT));
471
472 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800473 seq_printf(m, "Interrupt enable: %08x\n",
474 I915_READ(IER));
475 seq_printf(m, "Interrupt identity: %08x\n",
476 I915_READ(IIR));
477 seq_printf(m, "Interrupt mask: %08x\n",
478 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800479 for_each_pipe(pipe)
480 seq_printf(m, "Pipe %c stat: %08x\n",
481 pipe_name(pipe),
482 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800483 } else {
484 seq_printf(m, "North Display Interrupt enable: %08x\n",
485 I915_READ(DEIER));
486 seq_printf(m, "North Display Interrupt identity: %08x\n",
487 I915_READ(DEIIR));
488 seq_printf(m, "North Display Interrupt mask: %08x\n",
489 I915_READ(DEIMR));
490 seq_printf(m, "South Display Interrupt enable: %08x\n",
491 I915_READ(SDEIER));
492 seq_printf(m, "South Display Interrupt identity: %08x\n",
493 I915_READ(SDEIIR));
494 seq_printf(m, "South Display Interrupt mask: %08x\n",
495 I915_READ(SDEIMR));
496 seq_printf(m, "Graphics Interrupt enable: %08x\n",
497 I915_READ(GTIER));
498 seq_printf(m, "Graphics Interrupt identity: %08x\n",
499 I915_READ(GTIIR));
500 seq_printf(m, "Graphics Interrupt mask: %08x\n",
501 I915_READ(GTIMR));
502 }
Ben Gamari20172632009-02-17 20:08:50 -0500503 seq_printf(m, "Interrupts received: %d\n",
504 atomic_read(&dev_priv->irq_received));
Chris Wilson9862e602011-01-04 22:22:17 +0000505 for (i = 0; i < I915_NUM_RINGS; i++) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700506 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilson9862e602011-01-04 22:22:17 +0000507 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
508 dev_priv->ring[i].name,
509 I915_READ_IMR(&dev_priv->ring[i]));
510 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000511 i915_ring_seqno_info(m, &dev_priv->ring[i]);
Chris Wilson9862e602011-01-04 22:22:17 +0000512 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100513 mutex_unlock(&dev->struct_mutex);
514
Ben Gamari20172632009-02-17 20:08:50 -0500515 return 0;
516}
517
Chris Wilsona6172a82009-02-11 14:26:38 +0000518static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
519{
520 struct drm_info_node *node = (struct drm_info_node *) m->private;
521 struct drm_device *dev = node->minor->dev;
522 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100523 int i, ret;
524
525 ret = mutex_lock_interruptible(&dev->struct_mutex);
526 if (ret)
527 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000528
529 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
530 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
531 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000532 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000533
Chris Wilson6c085a72012-08-20 11:40:46 +0200534 seq_printf(m, "Fence %d, pin count = %d, object = ",
535 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100536 if (obj == NULL)
537 seq_printf(m, "unused");
538 else
Chris Wilson05394f32010-11-08 19:18:58 +0000539 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100540 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000541 }
542
Chris Wilson05394f32010-11-08 19:18:58 +0000543 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000544 return 0;
545}
546
Ben Gamari20172632009-02-17 20:08:50 -0500547static int i915_hws_info(struct seq_file *m, void *data)
548{
549 struct drm_info_node *node = (struct drm_info_node *) m->private;
550 struct drm_device *dev = node->minor->dev;
551 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100552 struct intel_ring_buffer *ring;
Chris Wilson311bd682011-01-13 19:06:50 +0000553 const volatile u32 __iomem *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100554 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500555
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000556 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilson311bd682011-01-13 19:06:50 +0000557 hws = (volatile u32 __iomem *)ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500558 if (hws == NULL)
559 return 0;
560
561 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
562 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
563 i * 4,
564 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
565 }
566 return 0;
567}
568
Chris Wilsone5c65262010-11-01 11:35:28 +0000569static const char *ring_str(int ring)
570{
571 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100572 case RCS: return "render";
573 case VCS: return "bsd";
574 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000575 default: return "";
576 }
577}
578
Chris Wilson9df30792010-02-18 10:24:56 +0000579static const char *pin_flag(int pinned)
580{
581 if (pinned > 0)
582 return " P";
583 else if (pinned < 0)
584 return " p";
585 else
586 return "";
587}
588
589static const char *tiling_flag(int tiling)
590{
591 switch (tiling) {
592 default:
593 case I915_TILING_NONE: return "";
594 case I915_TILING_X: return " X";
595 case I915_TILING_Y: return " Y";
596 }
597}
598
599static const char *dirty_flag(int dirty)
600{
601 return dirty ? " dirty" : "";
602}
603
604static const char *purgeable_flag(int purgeable)
605{
606 return purgeable ? " purgeable" : "";
607}
608
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000609static void print_error_buffers(struct seq_file *m,
610 const char *name,
611 struct drm_i915_error_buffer *err,
612 int count)
613{
614 seq_printf(m, "%s [%d]:\n", name, count);
615
616 while (count--) {
Chris Wilson0201f1e2012-07-20 12:41:01 +0100617 seq_printf(m, " %08x %8u %04x %04x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000618 err->gtt_offset,
619 err->size,
620 err->read_domains,
621 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100622 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000623 pin_flag(err->pinned),
624 tiling_flag(err->tiling),
625 dirty_flag(err->dirty),
626 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100627 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000628 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700629 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000630
631 if (err->name)
632 seq_printf(m, " (name: %d)", err->name);
633 if (err->fence_reg != I915_FENCE_REG_NONE)
634 seq_printf(m, " (fence: %d)", err->fence_reg);
635
636 seq_printf(m, "\n");
637 err++;
638 }
639}
640
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100641static void i915_ring_error_state(struct seq_file *m,
642 struct drm_device *dev,
643 struct drm_i915_error_state *error,
644 unsigned ring)
645{
Ben Widawskyec34a012012-04-03 23:03:00 -0700646 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100647 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100648 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
649 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100650 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
651 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
652 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
653 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100654 if (ring == RCS && INTEL_INFO(dev)->gen >= 4) {
655 seq_printf(m, " INSTDONE1: 0x%08x\n", error->instdone1);
656 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100657 }
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100658 if (INTEL_INFO(dev)->gen >= 4)
659 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
660 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200661 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100662 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100663 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100664 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100665 seq_printf(m, " SYNC_0: 0x%08x\n",
666 error->semaphore_mboxes[ring][0]);
667 seq_printf(m, " SYNC_1: 0x%08x\n",
668 error->semaphore_mboxes[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100669 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100670 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Ben Widawsky9574b3f2012-04-26 16:03:01 -0700671 seq_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100672 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
673 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100674}
675
Daniel Vetterd5442302012-04-27 15:17:40 +0200676struct i915_error_state_file_priv {
677 struct drm_device *dev;
678 struct drm_i915_error_state *error;
679};
680
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700681static int i915_error_state(struct seq_file *m, void *unused)
682{
Daniel Vetterd5442302012-04-27 15:17:40 +0200683 struct i915_error_state_file_priv *error_priv = m->private;
684 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700685 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200686 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100687 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000688 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700689
Daniel Vetter742cbee2012-04-27 15:17:39 +0200690 if (!error) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700691 seq_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200692 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700693 }
694
Jesse Barnes8a905232009-07-11 16:48:03 -0400695 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
696 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000697 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100698 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700699 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100700 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700701 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000702
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100703 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100704 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
705
Daniel Vetter33f3f512011-12-14 13:57:39 +0100706 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100707 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100708 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
709 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100710
Chris Wilsonb4519512012-05-11 14:29:30 +0100711 for_each_ring(ring, dev_priv, i)
712 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100713
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000714 if (error->active_bo)
715 print_error_buffers(m, "Active",
716 error->active_bo,
717 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000718
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000719 if (error->pinned_bo)
720 print_error_buffers(m, "Pinned",
721 error->pinned_bo,
722 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000723
Chris Wilson52d39a22012-02-15 11:25:37 +0000724 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
725 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000726
Chris Wilson52d39a22012-02-15 11:25:37 +0000727 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000728 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
729 dev_priv->ring[i].name,
730 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000731 offset = 0;
732 for (page = 0; page < obj->page_count; page++) {
733 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
734 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
735 offset += 4;
736 }
737 }
738 }
Chris Wilson9df30792010-02-18 10:24:56 +0000739
Chris Wilson52d39a22012-02-15 11:25:37 +0000740 if (error->ring[i].num_requests) {
741 seq_printf(m, "%s --- %d requests\n",
742 dev_priv->ring[i].name,
743 error->ring[i].num_requests);
744 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000745 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000746 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000747 error->ring[i].requests[j].jiffies,
748 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000749 }
750 }
751
752 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000753 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
754 dev_priv->ring[i].name,
755 obj->gtt_offset);
756 offset = 0;
757 for (page = 0; page < obj->page_count; page++) {
758 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
759 seq_printf(m, "%08x : %08x\n",
760 offset,
761 obj->pages[page][elt]);
762 offset += 4;
763 }
Chris Wilson9df30792010-02-18 10:24:56 +0000764 }
765 }
766 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700767
Chris Wilson6ef3d422010-08-04 20:26:07 +0100768 if (error->overlay)
769 intel_overlay_print_error_state(m, error->overlay);
770
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000771 if (error->display)
772 intel_display_print_error_state(m, dev, error->display);
773
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700774 return 0;
775}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700776
Daniel Vetterd5442302012-04-27 15:17:40 +0200777static ssize_t
778i915_error_state_write(struct file *filp,
779 const char __user *ubuf,
780 size_t cnt,
781 loff_t *ppos)
782{
783 struct seq_file *m = filp->private_data;
784 struct i915_error_state_file_priv *error_priv = m->private;
785 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200786 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200787
788 DRM_DEBUG_DRIVER("Resetting error state\n");
789
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200790 ret = mutex_lock_interruptible(&dev->struct_mutex);
791 if (ret)
792 return ret;
793
Daniel Vetterd5442302012-04-27 15:17:40 +0200794 i915_destroy_error_state(dev);
795 mutex_unlock(&dev->struct_mutex);
796
797 return cnt;
798}
799
800static int i915_error_state_open(struct inode *inode, struct file *file)
801{
802 struct drm_device *dev = inode->i_private;
803 drm_i915_private_t *dev_priv = dev->dev_private;
804 struct i915_error_state_file_priv *error_priv;
805 unsigned long flags;
806
807 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
808 if (!error_priv)
809 return -ENOMEM;
810
811 error_priv->dev = dev;
812
813 spin_lock_irqsave(&dev_priv->error_lock, flags);
814 error_priv->error = dev_priv->first_error;
815 if (error_priv->error)
816 kref_get(&error_priv->error->ref);
817 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
818
819 return single_open(file, i915_error_state, error_priv);
820}
821
822static int i915_error_state_release(struct inode *inode, struct file *file)
823{
824 struct seq_file *m = file->private_data;
825 struct i915_error_state_file_priv *error_priv = m->private;
826
827 if (error_priv->error)
828 kref_put(&error_priv->error->ref, i915_error_state_free);
829 kfree(error_priv);
830
831 return single_release(inode, file);
832}
833
834static const struct file_operations i915_error_state_fops = {
835 .owner = THIS_MODULE,
836 .open = i915_error_state_open,
837 .read = seq_read,
838 .write = i915_error_state_write,
839 .llseek = default_llseek,
840 .release = i915_error_state_release,
841};
842
Jesse Barnesf97108d2010-01-29 11:27:07 -0800843static int i915_rstdby_delays(struct seq_file *m, void *unused)
844{
845 struct drm_info_node *node = (struct drm_info_node *) m->private;
846 struct drm_device *dev = node->minor->dev;
847 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700848 u16 crstanddelay;
849 int ret;
850
851 ret = mutex_lock_interruptible(&dev->struct_mutex);
852 if (ret)
853 return ret;
854
855 crstanddelay = I915_READ16(CRSTANDVID);
856
857 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800858
859 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
860
861 return 0;
862}
863
864static int i915_cur_delayinfo(struct seq_file *m, void *unused)
865{
866 struct drm_info_node *node = (struct drm_info_node *) m->private;
867 struct drm_device *dev = node->minor->dev;
868 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100869 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800870
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800871 if (IS_GEN5(dev)) {
872 u16 rgvswctl = I915_READ16(MEMSWCTL);
873 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
874
875 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
876 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
877 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
878 MEMSTAT_VID_SHIFT);
879 seq_printf(m, "Current P-state: %d\n",
880 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700881 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800882 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
883 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
884 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800885 u32 rpstat;
886 u32 rpupei, rpcurup, rpprevup;
887 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800888 int max_freq;
889
890 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100891 ret = mutex_lock_interruptible(&dev->struct_mutex);
892 if (ret)
893 return ret;
894
Ben Widawskyfcca7922011-04-25 11:23:07 -0700895 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800896
Jesse Barnesccab5c82011-01-18 15:49:25 -0800897 rpstat = I915_READ(GEN6_RPSTAT1);
898 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
899 rpcurup = I915_READ(GEN6_RP_CUR_UP);
900 rpprevup = I915_READ(GEN6_RP_PREV_UP);
901 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
902 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
903 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
904
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100905 gen6_gt_force_wake_put(dev_priv);
906 mutex_unlock(&dev->struct_mutex);
907
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800908 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800909 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800910 seq_printf(m, "Render p-state ratio: %d\n",
911 (gt_perf_status & 0xff00) >> 8);
912 seq_printf(m, "Render p-state VID: %d\n",
913 gt_perf_status & 0xff);
914 seq_printf(m, "Render p-state limit: %d\n",
915 rp_state_limits & 0xff);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800916 seq_printf(m, "CAGF: %dMHz\n", ((rpstat & GEN6_CAGF_MASK) >>
Jesse Barnese281fca2011-03-18 10:32:07 -0700917 GEN6_CAGF_SHIFT) * 50);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800918 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
919 GEN6_CURICONT_MASK);
920 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
921 GEN6_CURBSYTAVG_MASK);
922 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
923 GEN6_CURBSYTAVG_MASK);
924 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
925 GEN6_CURIAVG_MASK);
926 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
927 GEN6_CURBSYTAVG_MASK);
928 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
929 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800930
931 max_freq = (rp_state_cap & 0xff0000) >> 16;
932 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700933 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800934
935 max_freq = (rp_state_cap & 0xff00) >> 8;
936 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700937 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800938
939 max_freq = rp_state_cap & 0xff;
940 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Jesse Barnese281fca2011-03-18 10:32:07 -0700941 max_freq * 50);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800942 } else {
943 seq_printf(m, "no P-state info available\n");
944 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800945
946 return 0;
947}
948
949static int i915_delayfreq_table(struct seq_file *m, void *unused)
950{
951 struct drm_info_node *node = (struct drm_info_node *) m->private;
952 struct drm_device *dev = node->minor->dev;
953 drm_i915_private_t *dev_priv = dev->dev_private;
954 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700955 int ret, i;
956
957 ret = mutex_lock_interruptible(&dev->struct_mutex);
958 if (ret)
959 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800960
961 for (i = 0; i < 16; i++) {
962 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700963 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
964 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800965 }
966
Ben Widawsky616fdb52011-10-05 11:44:54 -0700967 mutex_unlock(&dev->struct_mutex);
968
Jesse Barnesf97108d2010-01-29 11:27:07 -0800969 return 0;
970}
971
972static inline int MAP_TO_MV(int map)
973{
974 return 1250 - (map * 25);
975}
976
977static int i915_inttoext_table(struct seq_file *m, void *unused)
978{
979 struct drm_info_node *node = (struct drm_info_node *) m->private;
980 struct drm_device *dev = node->minor->dev;
981 drm_i915_private_t *dev_priv = dev->dev_private;
982 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700983 int ret, i;
984
985 ret = mutex_lock_interruptible(&dev->struct_mutex);
986 if (ret)
987 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800988
989 for (i = 1; i <= 32; i++) {
990 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
991 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
992 }
993
Ben Widawsky616fdb52011-10-05 11:44:54 -0700994 mutex_unlock(&dev->struct_mutex);
995
Jesse Barnesf97108d2010-01-29 11:27:07 -0800996 return 0;
997}
998
Ben Widawsky4d855292011-12-12 19:34:16 -0800999static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001000{
1001 struct drm_info_node *node = (struct drm_info_node *) m->private;
1002 struct drm_device *dev = node->minor->dev;
1003 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001004 u32 rgvmodectl, rstdbyctl;
1005 u16 crstandvid;
1006 int ret;
1007
1008 ret = mutex_lock_interruptible(&dev->struct_mutex);
1009 if (ret)
1010 return ret;
1011
1012 rgvmodectl = I915_READ(MEMMODECTL);
1013 rstdbyctl = I915_READ(RSTDBYCTL);
1014 crstandvid = I915_READ16(CRSTANDVID);
1015
1016 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001017
1018 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1019 "yes" : "no");
1020 seq_printf(m, "Boost freq: %d\n",
1021 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1022 MEMMODE_BOOST_FREQ_SHIFT);
1023 seq_printf(m, "HW control enabled: %s\n",
1024 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1025 seq_printf(m, "SW control enabled: %s\n",
1026 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1027 seq_printf(m, "Gated voltage change: %s\n",
1028 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1029 seq_printf(m, "Starting frequency: P%d\n",
1030 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001031 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001032 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001033 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1034 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1035 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1036 seq_printf(m, "Render standby enabled: %s\n",
1037 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001038 seq_printf(m, "Current RS state: ");
1039 switch (rstdbyctl & RSX_STATUS_MASK) {
1040 case RSX_STATUS_ON:
1041 seq_printf(m, "on\n");
1042 break;
1043 case RSX_STATUS_RC1:
1044 seq_printf(m, "RC1\n");
1045 break;
1046 case RSX_STATUS_RC1E:
1047 seq_printf(m, "RC1E\n");
1048 break;
1049 case RSX_STATUS_RS1:
1050 seq_printf(m, "RS1\n");
1051 break;
1052 case RSX_STATUS_RS2:
1053 seq_printf(m, "RS2 (RC6)\n");
1054 break;
1055 case RSX_STATUS_RS3:
1056 seq_printf(m, "RC3 (RC6+)\n");
1057 break;
1058 default:
1059 seq_printf(m, "unknown\n");
1060 break;
1061 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001062
1063 return 0;
1064}
1065
Ben Widawsky4d855292011-12-12 19:34:16 -08001066static int gen6_drpc_info(struct seq_file *m)
1067{
1068
1069 struct drm_info_node *node = (struct drm_info_node *) m->private;
1070 struct drm_device *dev = node->minor->dev;
1071 struct drm_i915_private *dev_priv = dev->dev_private;
1072 u32 rpmodectl1, gt_core_status, rcctl1;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001073 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001074 int count=0, ret;
1075
1076
1077 ret = mutex_lock_interruptible(&dev->struct_mutex);
1078 if (ret)
1079 return ret;
1080
Daniel Vetter93b525d2012-01-25 13:52:43 +01001081 spin_lock_irq(&dev_priv->gt_lock);
1082 forcewake_count = dev_priv->forcewake_count;
1083 spin_unlock_irq(&dev_priv->gt_lock);
1084
1085 if (forcewake_count) {
1086 seq_printf(m, "RC information inaccurate because somebody "
1087 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001088 } else {
1089 /* NB: we cannot use forcewake, else we read the wrong values */
1090 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1091 udelay(10);
1092 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1093 }
1094
1095 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1096 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1097
1098 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1099 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1100 mutex_unlock(&dev->struct_mutex);
1101
1102 seq_printf(m, "Video Turbo Mode: %s\n",
1103 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1104 seq_printf(m, "HW control enabled: %s\n",
1105 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1106 seq_printf(m, "SW control enabled: %s\n",
1107 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1108 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001109 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001110 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1111 seq_printf(m, "RC6 Enabled: %s\n",
1112 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1113 seq_printf(m, "Deep RC6 Enabled: %s\n",
1114 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1115 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1116 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1117 seq_printf(m, "Current RC state: ");
1118 switch (gt_core_status & GEN6_RCn_MASK) {
1119 case GEN6_RC0:
1120 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1121 seq_printf(m, "Core Power Down\n");
1122 else
1123 seq_printf(m, "on\n");
1124 break;
1125 case GEN6_RC3:
1126 seq_printf(m, "RC3\n");
1127 break;
1128 case GEN6_RC6:
1129 seq_printf(m, "RC6\n");
1130 break;
1131 case GEN6_RC7:
1132 seq_printf(m, "RC7\n");
1133 break;
1134 default:
1135 seq_printf(m, "Unknown\n");
1136 break;
1137 }
1138
1139 seq_printf(m, "Core Power Down: %s\n",
1140 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001141
1142 /* Not exactly sure what this is */
1143 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1144 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1145 seq_printf(m, "RC6 residency since boot: %u\n",
1146 I915_READ(GEN6_GT_GFX_RC6));
1147 seq_printf(m, "RC6+ residency since boot: %u\n",
1148 I915_READ(GEN6_GT_GFX_RC6p));
1149 seq_printf(m, "RC6++ residency since boot: %u\n",
1150 I915_READ(GEN6_GT_GFX_RC6pp));
1151
Ben Widawsky4d855292011-12-12 19:34:16 -08001152 return 0;
1153}
1154
1155static int i915_drpc_info(struct seq_file *m, void *unused)
1156{
1157 struct drm_info_node *node = (struct drm_info_node *) m->private;
1158 struct drm_device *dev = node->minor->dev;
1159
1160 if (IS_GEN6(dev) || IS_GEN7(dev))
1161 return gen6_drpc_info(m);
1162 else
1163 return ironlake_drpc_info(m);
1164}
1165
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001166static int i915_fbc_status(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;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001170 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001171
Adam Jacksonee5382a2010-04-23 11:17:39 -04001172 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001173 seq_printf(m, "FBC unsupported on this chipset\n");
1174 return 0;
1175 }
1176
Adam Jacksonee5382a2010-04-23 11:17:39 -04001177 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001178 seq_printf(m, "FBC enabled\n");
1179 } else {
1180 seq_printf(m, "FBC disabled: ");
1181 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001182 case FBC_NO_OUTPUT:
1183 seq_printf(m, "no outputs");
1184 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001185 case FBC_STOLEN_TOO_SMALL:
1186 seq_printf(m, "not enough stolen memory");
1187 break;
1188 case FBC_UNSUPPORTED_MODE:
1189 seq_printf(m, "mode not supported");
1190 break;
1191 case FBC_MODE_TOO_LARGE:
1192 seq_printf(m, "mode too large");
1193 break;
1194 case FBC_BAD_PLANE:
1195 seq_printf(m, "FBC unsupported on plane");
1196 break;
1197 case FBC_NOT_TILED:
1198 seq_printf(m, "scanout buffer not tiled");
1199 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001200 case FBC_MULTIPLE_PIPES:
1201 seq_printf(m, "multiple pipes are enabled");
1202 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001203 case FBC_MODULE_PARAM:
1204 seq_printf(m, "disabled per module param (default off)");
1205 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001206 default:
1207 seq_printf(m, "unknown reason");
1208 }
1209 seq_printf(m, "\n");
1210 }
1211 return 0;
1212}
1213
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001214static int i915_sr_status(struct seq_file *m, void *unused)
1215{
1216 struct drm_info_node *node = (struct drm_info_node *) m->private;
1217 struct drm_device *dev = node->minor->dev;
1218 drm_i915_private_t *dev_priv = dev->dev_private;
1219 bool sr_enabled = false;
1220
Yuanhan Liu13982612010-12-15 15:42:31 +08001221 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001222 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001223 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001224 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1225 else if (IS_I915GM(dev))
1226 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1227 else if (IS_PINEVIEW(dev))
1228 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1229
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001230 seq_printf(m, "self-refresh: %s\n",
1231 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001232
1233 return 0;
1234}
1235
Jesse Barnes7648fa92010-05-20 14:28:11 -07001236static int i915_emon_status(struct seq_file *m, void *unused)
1237{
1238 struct drm_info_node *node = (struct drm_info_node *) m->private;
1239 struct drm_device *dev = node->minor->dev;
1240 drm_i915_private_t *dev_priv = dev->dev_private;
1241 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001242 int ret;
1243
Chris Wilson582be6b2012-04-30 19:35:02 +01001244 if (!IS_GEN5(dev))
1245 return -ENODEV;
1246
Chris Wilsonde227ef2010-07-03 07:58:38 +01001247 ret = mutex_lock_interruptible(&dev->struct_mutex);
1248 if (ret)
1249 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001250
1251 temp = i915_mch_val(dev_priv);
1252 chipset = i915_chipset_val(dev_priv);
1253 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001254 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001255
1256 seq_printf(m, "GMCH temp: %ld\n", temp);
1257 seq_printf(m, "Chipset power: %ld\n", chipset);
1258 seq_printf(m, "GFX power: %ld\n", gfx);
1259 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1260
1261 return 0;
1262}
1263
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001264static int i915_ring_freq_table(struct seq_file *m, void *unused)
1265{
1266 struct drm_info_node *node = (struct drm_info_node *) m->private;
1267 struct drm_device *dev = node->minor->dev;
1268 drm_i915_private_t *dev_priv = dev->dev_private;
1269 int ret;
1270 int gpu_freq, ia_freq;
1271
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001272 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001273 seq_printf(m, "unsupported on this chipset\n");
1274 return 0;
1275 }
1276
1277 ret = mutex_lock_interruptible(&dev->struct_mutex);
1278 if (ret)
1279 return ret;
1280
1281 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1282
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001283 for (gpu_freq = dev_priv->rps.min_delay;
1284 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001285 gpu_freq++) {
1286 I915_WRITE(GEN6_PCODE_DATA, gpu_freq);
1287 I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY |
1288 GEN6_PCODE_READ_MIN_FREQ_TABLE);
1289 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) &
1290 GEN6_PCODE_READY) == 0, 10)) {
1291 DRM_ERROR("pcode read of freq table timed out\n");
1292 continue;
1293 }
1294 ia_freq = I915_READ(GEN6_PCODE_DATA);
1295 seq_printf(m, "%d\t\t%d\n", gpu_freq * 50, ia_freq * 100);
1296 }
1297
1298 mutex_unlock(&dev->struct_mutex);
1299
1300 return 0;
1301}
1302
Jesse Barnes7648fa92010-05-20 14:28:11 -07001303static int i915_gfxec(struct seq_file *m, void *unused)
1304{
1305 struct drm_info_node *node = (struct drm_info_node *) m->private;
1306 struct drm_device *dev = node->minor->dev;
1307 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001308 int ret;
1309
1310 ret = mutex_lock_interruptible(&dev->struct_mutex);
1311 if (ret)
1312 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001313
1314 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1315
Ben Widawsky616fdb52011-10-05 11:44:54 -07001316 mutex_unlock(&dev->struct_mutex);
1317
Jesse Barnes7648fa92010-05-20 14:28:11 -07001318 return 0;
1319}
1320
Chris Wilson44834a62010-08-19 16:09:23 +01001321static int i915_opregion(struct seq_file *m, void *unused)
1322{
1323 struct drm_info_node *node = (struct drm_info_node *) m->private;
1324 struct drm_device *dev = node->minor->dev;
1325 drm_i915_private_t *dev_priv = dev->dev_private;
1326 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001327 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001328 int ret;
1329
Daniel Vetter0d38f002012-04-21 22:49:10 +02001330 if (data == NULL)
1331 return -ENOMEM;
1332
Chris Wilson44834a62010-08-19 16:09:23 +01001333 ret = mutex_lock_interruptible(&dev->struct_mutex);
1334 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001335 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001336
Daniel Vetter0d38f002012-04-21 22:49:10 +02001337 if (opregion->header) {
1338 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1339 seq_write(m, data, OPREGION_SIZE);
1340 }
Chris Wilson44834a62010-08-19 16:09:23 +01001341
1342 mutex_unlock(&dev->struct_mutex);
1343
Daniel Vetter0d38f002012-04-21 22:49:10 +02001344out:
1345 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001346 return 0;
1347}
1348
Chris Wilson37811fc2010-08-25 22:45:57 +01001349static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1350{
1351 struct drm_info_node *node = (struct drm_info_node *) m->private;
1352 struct drm_device *dev = node->minor->dev;
1353 drm_i915_private_t *dev_priv = dev->dev_private;
1354 struct intel_fbdev *ifbdev;
1355 struct intel_framebuffer *fb;
1356 int ret;
1357
1358 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1359 if (ret)
1360 return ret;
1361
1362 ifbdev = dev_priv->fbdev;
1363 fb = to_intel_framebuffer(ifbdev->helper.fb);
1364
1365 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1366 fb->base.width,
1367 fb->base.height,
1368 fb->base.depth,
1369 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001370 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001371 seq_printf(m, "\n");
1372
1373 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1374 if (&fb->base == ifbdev->helper.fb)
1375 continue;
1376
1377 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1378 fb->base.width,
1379 fb->base.height,
1380 fb->base.depth,
1381 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001382 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001383 seq_printf(m, "\n");
1384 }
1385
1386 mutex_unlock(&dev->mode_config.mutex);
1387
1388 return 0;
1389}
1390
Ben Widawskye76d3632011-03-19 18:14:29 -07001391static int i915_context_status(struct seq_file *m, void *unused)
1392{
1393 struct drm_info_node *node = (struct drm_info_node *) m->private;
1394 struct drm_device *dev = node->minor->dev;
1395 drm_i915_private_t *dev_priv = dev->dev_private;
1396 int ret;
1397
1398 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1399 if (ret)
1400 return ret;
1401
Ben Widawskydc501fb2011-06-29 11:41:51 -07001402 if (dev_priv->pwrctx) {
1403 seq_printf(m, "power context ");
1404 describe_obj(m, dev_priv->pwrctx);
1405 seq_printf(m, "\n");
1406 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001407
Ben Widawskydc501fb2011-06-29 11:41:51 -07001408 if (dev_priv->renderctx) {
1409 seq_printf(m, "render context ");
1410 describe_obj(m, dev_priv->renderctx);
1411 seq_printf(m, "\n");
1412 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001413
1414 mutex_unlock(&dev->mode_config.mutex);
1415
1416 return 0;
1417}
1418
Ben Widawsky6d794d42011-04-25 11:25:56 -07001419static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1420{
1421 struct drm_info_node *node = (struct drm_info_node *) m->private;
1422 struct drm_device *dev = node->minor->dev;
1423 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001424 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001425
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001426 spin_lock_irq(&dev_priv->gt_lock);
1427 forcewake_count = dev_priv->forcewake_count;
1428 spin_unlock_irq(&dev_priv->gt_lock);
1429
1430 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001431
1432 return 0;
1433}
1434
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001435static const char *swizzle_string(unsigned swizzle)
1436{
1437 switch(swizzle) {
1438 case I915_BIT_6_SWIZZLE_NONE:
1439 return "none";
1440 case I915_BIT_6_SWIZZLE_9:
1441 return "bit9";
1442 case I915_BIT_6_SWIZZLE_9_10:
1443 return "bit9/bit10";
1444 case I915_BIT_6_SWIZZLE_9_11:
1445 return "bit9/bit11";
1446 case I915_BIT_6_SWIZZLE_9_10_11:
1447 return "bit9/bit10/bit11";
1448 case I915_BIT_6_SWIZZLE_9_17:
1449 return "bit9/bit17";
1450 case I915_BIT_6_SWIZZLE_9_10_17:
1451 return "bit9/bit10/bit17";
1452 case I915_BIT_6_SWIZZLE_UNKNOWN:
1453 return "unkown";
1454 }
1455
1456 return "bug";
1457}
1458
1459static int i915_swizzle_info(struct seq_file *m, void *data)
1460{
1461 struct drm_info_node *node = (struct drm_info_node *) m->private;
1462 struct drm_device *dev = node->minor->dev;
1463 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001464 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001465
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001466 ret = mutex_lock_interruptible(&dev->struct_mutex);
1467 if (ret)
1468 return ret;
1469
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001470 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1471 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1472 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1473 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1474
1475 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1476 seq_printf(m, "DDC = 0x%08x\n",
1477 I915_READ(DCC));
1478 seq_printf(m, "C0DRB3 = 0x%04x\n",
1479 I915_READ16(C0DRB3));
1480 seq_printf(m, "C1DRB3 = 0x%04x\n",
1481 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001482 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1483 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1484 I915_READ(MAD_DIMM_C0));
1485 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1486 I915_READ(MAD_DIMM_C1));
1487 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1488 I915_READ(MAD_DIMM_C2));
1489 seq_printf(m, "TILECTL = 0x%08x\n",
1490 I915_READ(TILECTL));
1491 seq_printf(m, "ARB_MODE = 0x%08x\n",
1492 I915_READ(ARB_MODE));
1493 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1494 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001495 }
1496 mutex_unlock(&dev->struct_mutex);
1497
1498 return 0;
1499}
1500
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001501static int i915_ppgtt_info(struct seq_file *m, void *data)
1502{
1503 struct drm_info_node *node = (struct drm_info_node *) m->private;
1504 struct drm_device *dev = node->minor->dev;
1505 struct drm_i915_private *dev_priv = dev->dev_private;
1506 struct intel_ring_buffer *ring;
1507 int i, ret;
1508
1509
1510 ret = mutex_lock_interruptible(&dev->struct_mutex);
1511 if (ret)
1512 return ret;
1513 if (INTEL_INFO(dev)->gen == 6)
1514 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1515
1516 for (i = 0; i < I915_NUM_RINGS; i++) {
1517 ring = &dev_priv->ring[i];
1518
1519 seq_printf(m, "%s\n", ring->name);
1520 if (INTEL_INFO(dev)->gen == 7)
1521 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1522 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1523 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1524 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1525 }
1526 if (dev_priv->mm.aliasing_ppgtt) {
1527 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1528
1529 seq_printf(m, "aliasing PPGTT:\n");
1530 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1531 }
1532 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1533 mutex_unlock(&dev->struct_mutex);
1534
1535 return 0;
1536}
1537
Jesse Barnes57f350b2012-03-28 13:39:25 -07001538static int i915_dpio_info(struct seq_file *m, void *data)
1539{
1540 struct drm_info_node *node = (struct drm_info_node *) m->private;
1541 struct drm_device *dev = node->minor->dev;
1542 struct drm_i915_private *dev_priv = dev->dev_private;
1543 int ret;
1544
1545
1546 if (!IS_VALLEYVIEW(dev)) {
1547 seq_printf(m, "unsupported\n");
1548 return 0;
1549 }
1550
1551 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1552 if (ret)
1553 return ret;
1554
1555 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1556
1557 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1558 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1559 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1560 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1561
1562 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1563 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1564 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1565 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1566
1567 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1568 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1569 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1570 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1571
1572 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1573 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1574 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1575 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1576
1577 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1578 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1579
1580 mutex_unlock(&dev->mode_config.mutex);
1581
1582 return 0;
1583}
1584
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001585static ssize_t
1586i915_wedged_read(struct file *filp,
1587 char __user *ubuf,
1588 size_t max,
1589 loff_t *ppos)
1590{
1591 struct drm_device *dev = filp->private_data;
1592 drm_i915_private_t *dev_priv = dev->dev_private;
1593 char buf[80];
1594 int len;
1595
Akshay Joshi0206e352011-08-16 15:34:10 -04001596 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001597 "wedged : %d\n",
1598 atomic_read(&dev_priv->mm.wedged));
1599
Akshay Joshi0206e352011-08-16 15:34:10 -04001600 if (len > sizeof(buf))
1601 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001602
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001603 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1604}
1605
1606static ssize_t
1607i915_wedged_write(struct file *filp,
1608 const char __user *ubuf,
1609 size_t cnt,
1610 loff_t *ppos)
1611{
1612 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001613 char buf[20];
1614 int val = 1;
1615
1616 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001617 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001618 return -EINVAL;
1619
1620 if (copy_from_user(buf, ubuf, cnt))
1621 return -EFAULT;
1622 buf[cnt] = 0;
1623
1624 val = simple_strtoul(buf, NULL, 0);
1625 }
1626
1627 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001628 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001629
1630 return cnt;
1631}
1632
1633static const struct file_operations i915_wedged_fops = {
1634 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001635 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001636 .read = i915_wedged_read,
1637 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001638 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001639};
1640
Jesse Barnes358733e2011-07-27 11:53:01 -07001641static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001642i915_ring_stop_read(struct file *filp,
1643 char __user *ubuf,
1644 size_t max,
1645 loff_t *ppos)
1646{
1647 struct drm_device *dev = filp->private_data;
1648 drm_i915_private_t *dev_priv = dev->dev_private;
1649 char buf[20];
1650 int len;
1651
1652 len = snprintf(buf, sizeof(buf),
1653 "0x%08x\n", dev_priv->stop_rings);
1654
1655 if (len > sizeof(buf))
1656 len = sizeof(buf);
1657
1658 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1659}
1660
1661static ssize_t
1662i915_ring_stop_write(struct file *filp,
1663 const char __user *ubuf,
1664 size_t cnt,
1665 loff_t *ppos)
1666{
1667 struct drm_device *dev = filp->private_data;
1668 struct drm_i915_private *dev_priv = dev->dev_private;
1669 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001670 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001671
1672 if (cnt > 0) {
1673 if (cnt > sizeof(buf) - 1)
1674 return -EINVAL;
1675
1676 if (copy_from_user(buf, ubuf, cnt))
1677 return -EFAULT;
1678 buf[cnt] = 0;
1679
1680 val = simple_strtoul(buf, NULL, 0);
1681 }
1682
1683 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1684
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001685 ret = mutex_lock_interruptible(&dev->struct_mutex);
1686 if (ret)
1687 return ret;
1688
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001689 dev_priv->stop_rings = val;
1690 mutex_unlock(&dev->struct_mutex);
1691
1692 return cnt;
1693}
1694
1695static const struct file_operations i915_ring_stop_fops = {
1696 .owner = THIS_MODULE,
1697 .open = simple_open,
1698 .read = i915_ring_stop_read,
1699 .write = i915_ring_stop_write,
1700 .llseek = default_llseek,
1701};
Daniel Vetterd5442302012-04-27 15:17:40 +02001702
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001703static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001704i915_max_freq_read(struct file *filp,
1705 char __user *ubuf,
1706 size_t max,
1707 loff_t *ppos)
1708{
1709 struct drm_device *dev = filp->private_data;
1710 drm_i915_private_t *dev_priv = dev->dev_private;
1711 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001712 int len, ret;
1713
1714 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1715 return -ENODEV;
1716
1717 ret = mutex_lock_interruptible(&dev->struct_mutex);
1718 if (ret)
1719 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001720
Akshay Joshi0206e352011-08-16 15:34:10 -04001721 len = snprintf(buf, sizeof(buf),
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001722 "max freq: %d\n", dev_priv->rps.max_delay * 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001723 mutex_unlock(&dev->struct_mutex);
Jesse Barnes358733e2011-07-27 11:53:01 -07001724
Akshay Joshi0206e352011-08-16 15:34:10 -04001725 if (len > sizeof(buf))
1726 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001727
1728 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1729}
1730
1731static ssize_t
1732i915_max_freq_write(struct file *filp,
1733 const char __user *ubuf,
1734 size_t cnt,
1735 loff_t *ppos)
1736{
1737 struct drm_device *dev = filp->private_data;
1738 struct drm_i915_private *dev_priv = dev->dev_private;
1739 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001740 int val = 1, ret;
1741
1742 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1743 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001744
1745 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001746 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001747 return -EINVAL;
1748
1749 if (copy_from_user(buf, ubuf, cnt))
1750 return -EFAULT;
1751 buf[cnt] = 0;
1752
1753 val = simple_strtoul(buf, NULL, 0);
1754 }
1755
1756 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1757
Daniel Vetter004777c2012-08-09 15:07:01 +02001758 ret = mutex_lock_interruptible(&dev->struct_mutex);
1759 if (ret)
1760 return ret;
1761
Jesse Barnes358733e2011-07-27 11:53:01 -07001762 /*
1763 * Turbo will still be enabled, but won't go above the set value.
1764 */
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001765 dev_priv->rps.max_delay = val / 50;
Jesse Barnes358733e2011-07-27 11:53:01 -07001766
1767 gen6_set_rps(dev, val / 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001768 mutex_unlock(&dev->struct_mutex);
Jesse Barnes358733e2011-07-27 11:53:01 -07001769
1770 return cnt;
1771}
1772
1773static const struct file_operations i915_max_freq_fops = {
1774 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001775 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001776 .read = i915_max_freq_read,
1777 .write = i915_max_freq_write,
1778 .llseek = default_llseek,
1779};
1780
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001781static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001782i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1783 loff_t *ppos)
1784{
1785 struct drm_device *dev = filp->private_data;
1786 drm_i915_private_t *dev_priv = dev->dev_private;
1787 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001788 int len, ret;
1789
1790 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1791 return -ENODEV;
1792
1793 ret = mutex_lock_interruptible(&dev->struct_mutex);
1794 if (ret)
1795 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001796
1797 len = snprintf(buf, sizeof(buf),
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001798 "min freq: %d\n", dev_priv->rps.min_delay * 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001799 mutex_unlock(&dev->struct_mutex);
Jesse Barnes1523c312012-05-25 12:34:54 -07001800
1801 if (len > sizeof(buf))
1802 len = sizeof(buf);
1803
1804 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1805}
1806
1807static ssize_t
1808i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
1809 loff_t *ppos)
1810{
1811 struct drm_device *dev = filp->private_data;
1812 struct drm_i915_private *dev_priv = dev->dev_private;
1813 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001814 int val = 1, ret;
1815
1816 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1817 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07001818
1819 if (cnt > 0) {
1820 if (cnt > sizeof(buf) - 1)
1821 return -EINVAL;
1822
1823 if (copy_from_user(buf, ubuf, cnt))
1824 return -EFAULT;
1825 buf[cnt] = 0;
1826
1827 val = simple_strtoul(buf, NULL, 0);
1828 }
1829
1830 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
1831
Daniel Vetter004777c2012-08-09 15:07:01 +02001832 ret = mutex_lock_interruptible(&dev->struct_mutex);
1833 if (ret)
1834 return ret;
1835
Jesse Barnes1523c312012-05-25 12:34:54 -07001836 /*
1837 * Turbo will still be enabled, but won't go below the set value.
1838 */
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001839 dev_priv->rps.min_delay = val / 50;
Jesse Barnes1523c312012-05-25 12:34:54 -07001840
1841 gen6_set_rps(dev, val / 50);
Daniel Vetter004777c2012-08-09 15:07:01 +02001842 mutex_unlock(&dev->struct_mutex);
Jesse Barnes1523c312012-05-25 12:34:54 -07001843
1844 return cnt;
1845}
1846
1847static const struct file_operations i915_min_freq_fops = {
1848 .owner = THIS_MODULE,
1849 .open = simple_open,
1850 .read = i915_min_freq_read,
1851 .write = i915_min_freq_write,
1852 .llseek = default_llseek,
1853};
1854
1855static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001856i915_cache_sharing_read(struct file *filp,
1857 char __user *ubuf,
1858 size_t max,
1859 loff_t *ppos)
1860{
1861 struct drm_device *dev = filp->private_data;
1862 drm_i915_private_t *dev_priv = dev->dev_private;
1863 char buf[80];
1864 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001865 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001866
Daniel Vetter004777c2012-08-09 15:07:01 +02001867 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1868 return -ENODEV;
1869
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001870 ret = mutex_lock_interruptible(&dev->struct_mutex);
1871 if (ret)
1872 return ret;
1873
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001874 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1875 mutex_unlock(&dev_priv->dev->struct_mutex);
1876
Akshay Joshi0206e352011-08-16 15:34:10 -04001877 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001878 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
1879 GEN6_MBC_SNPCR_SHIFT);
1880
Akshay Joshi0206e352011-08-16 15:34:10 -04001881 if (len > sizeof(buf))
1882 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001883
1884 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1885}
1886
1887static ssize_t
1888i915_cache_sharing_write(struct file *filp,
1889 const char __user *ubuf,
1890 size_t cnt,
1891 loff_t *ppos)
1892{
1893 struct drm_device *dev = filp->private_data;
1894 struct drm_i915_private *dev_priv = dev->dev_private;
1895 char buf[20];
1896 u32 snpcr;
1897 int val = 1;
1898
Daniel Vetter004777c2012-08-09 15:07:01 +02001899 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1900 return -ENODEV;
1901
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001902 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001903 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001904 return -EINVAL;
1905
1906 if (copy_from_user(buf, ubuf, cnt))
1907 return -EFAULT;
1908 buf[cnt] = 0;
1909
1910 val = simple_strtoul(buf, NULL, 0);
1911 }
1912
1913 if (val < 0 || val > 3)
1914 return -EINVAL;
1915
1916 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
1917
1918 /* Update the cache sharing policy here as well */
1919 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
1920 snpcr &= ~GEN6_MBC_SNPCR_MASK;
1921 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
1922 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
1923
1924 return cnt;
1925}
1926
1927static const struct file_operations i915_cache_sharing_fops = {
1928 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001929 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001930 .read = i915_cache_sharing_read,
1931 .write = i915_cache_sharing_write,
1932 .llseek = default_llseek,
1933};
1934
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001935/* As the drm_debugfs_init() routines are called before dev->dev_private is
1936 * allocated we need to hook into the minor for release. */
1937static int
1938drm_add_fake_info_node(struct drm_minor *minor,
1939 struct dentry *ent,
1940 const void *key)
1941{
1942 struct drm_info_node *node;
1943
1944 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
1945 if (node == NULL) {
1946 debugfs_remove(ent);
1947 return -ENOMEM;
1948 }
1949
1950 node->minor = minor;
1951 node->dent = ent;
1952 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01001953
1954 mutex_lock(&minor->debugfs_lock);
1955 list_add(&node->list, &minor->debugfs_list);
1956 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001957
1958 return 0;
1959}
1960
Ben Widawsky6d794d42011-04-25 11:25:56 -07001961static int i915_forcewake_open(struct inode *inode, struct file *file)
1962{
1963 struct drm_device *dev = inode->i_private;
1964 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001965
Daniel Vetter075edca2012-01-24 09:44:28 +01001966 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001967 return 0;
1968
Ben Widawsky6d794d42011-04-25 11:25:56 -07001969 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001970
1971 return 0;
1972}
1973
Ben Widawskyc43b5632012-04-16 14:07:40 -07001974static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001975{
1976 struct drm_device *dev = inode->i_private;
1977 struct drm_i915_private *dev_priv = dev->dev_private;
1978
Daniel Vetter075edca2012-01-24 09:44:28 +01001979 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07001980 return 0;
1981
Ben Widawsky6d794d42011-04-25 11:25:56 -07001982 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001983
1984 return 0;
1985}
1986
1987static const struct file_operations i915_forcewake_fops = {
1988 .owner = THIS_MODULE,
1989 .open = i915_forcewake_open,
1990 .release = i915_forcewake_release,
1991};
1992
1993static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
1994{
1995 struct drm_device *dev = minor->dev;
1996 struct dentry *ent;
1997
1998 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07001999 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002000 root, dev,
2001 &i915_forcewake_fops);
2002 if (IS_ERR(ent))
2003 return PTR_ERR(ent);
2004
Ben Widawsky8eb57292011-05-11 15:10:58 -07002005 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002006}
2007
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002008static int i915_debugfs_create(struct dentry *root,
2009 struct drm_minor *minor,
2010 const char *name,
2011 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002012{
2013 struct drm_device *dev = minor->dev;
2014 struct dentry *ent;
2015
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002016 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002017 S_IRUGO | S_IWUSR,
2018 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002019 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002020 if (IS_ERR(ent))
2021 return PTR_ERR(ent);
2022
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002023 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002024}
2025
Ben Gamari27c202a2009-07-01 22:26:52 -04002026static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002027 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002028 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002029 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002030 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002031 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002032 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002033 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002034 {"i915_gem_request", i915_gem_request_info, 0},
2035 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002036 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002037 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002038 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2039 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2040 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002041 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2042 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2043 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2044 {"i915_inttoext_table", i915_inttoext_table, 0},
2045 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002046 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002047 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002048 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002049 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002050 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002051 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002052 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002053 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002054 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002055 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002056 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002057 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002058};
Ben Gamari27c202a2009-07-01 22:26:52 -04002059#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002060
Ben Gamari27c202a2009-07-01 22:26:52 -04002061int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002062{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002063 int ret;
2064
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002065 ret = i915_debugfs_create(minor->debugfs_root, minor,
2066 "i915_wedged",
2067 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002068 if (ret)
2069 return ret;
2070
Ben Widawsky6d794d42011-04-25 11:25:56 -07002071 ret = i915_forcewake_create(minor->debugfs_root, minor);
2072 if (ret)
2073 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002074
2075 ret = i915_debugfs_create(minor->debugfs_root, minor,
2076 "i915_max_freq",
2077 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002078 if (ret)
2079 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002080
2081 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002082 "i915_min_freq",
2083 &i915_min_freq_fops);
2084 if (ret)
2085 return ret;
2086
2087 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002088 "i915_cache_sharing",
2089 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002090 if (ret)
2091 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002092
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002093 ret = i915_debugfs_create(minor->debugfs_root, minor,
2094 "i915_ring_stop",
2095 &i915_ring_stop_fops);
2096 if (ret)
2097 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002098
Daniel Vetterd5442302012-04-27 15:17:40 +02002099 ret = i915_debugfs_create(minor->debugfs_root, minor,
2100 "i915_error_state",
2101 &i915_error_state_fops);
2102 if (ret)
2103 return ret;
2104
Ben Gamari27c202a2009-07-01 22:26:52 -04002105 return drm_debugfs_create_files(i915_debugfs_list,
2106 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002107 minor->debugfs_root, minor);
2108}
2109
Ben Gamari27c202a2009-07-01 22:26:52 -04002110void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002111{
Ben Gamari27c202a2009-07-01 22:26:52 -04002112 drm_debugfs_remove_files(i915_debugfs_list,
2113 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002114 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2115 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002116 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2117 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002118 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2119 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002120 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2121 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002122 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2123 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002124 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2125 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002126 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2127 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002128}
2129
2130#endif /* CONFIG_DEBUG_FS */