blob: 3c5710f95a1d168b51122b6864a030fa93338287 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010030#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040032#include <linux/export.h>
Ben Gamari20172632009-02-17 20:08:50 -050033#include "drmP.h"
34#include "drm.h"
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010035#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000036#include "intel_ringbuffer.h"
Ben Gamari20172632009-02-17 20:08:50 -050037#include "i915_drm.h"
38#include "i915_drv.h"
39
40#define DRM_I915_RING_DEBUG 1
41
42
43#if defined(CONFIG_DEBUG_FS)
44
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010046 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010048 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010049};
Ben Gamari433e12f2009-02-17 20:08:51 -050050
Chris Wilson70d39fe2010-08-25 16:03:34 +010051static const char *yesno(int v)
52{
53 return v ? "yes" : "no";
54}
55
56static int i915_capabilities(struct seq_file *m, void *data)
57{
58 struct drm_info_node *node = (struct drm_info_node *) m->private;
59 struct drm_device *dev = node->minor->dev;
60 const struct intel_device_info *info = INTEL_INFO(dev);
61
62 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030063 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Daniel Vetterc96ea642012-08-08 22:01:51 +020064#define DEV_INFO_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
65#define DEV_INFO_SEP ;
66 DEV_INFO_FLAGS;
67#undef DEV_INFO_FLAG
68#undef DEV_INFO_SEP
Chris Wilson70d39fe2010-08-25 16:03:34 +010069
70 return 0;
71}
Ben Gamari433e12f2009-02-17 20:08:51 -050072
Chris Wilson05394f32010-11-08 19:18:58 +000073static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000074{
Chris Wilson05394f32010-11-08 19:18:58 +000075 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000076 return "P";
Chris Wilson05394f32010-11-08 19:18:58 +000077 else if (obj->pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000078 return "p";
79 else
80 return " ";
81}
82
Chris Wilson05394f32010-11-08 19:18:58 +000083static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000084{
Akshay Joshi0206e352011-08-16 15:34:10 -040085 switch (obj->tiling_mode) {
86 default:
87 case I915_TILING_NONE: return " ";
88 case I915_TILING_X: return "X";
89 case I915_TILING_Y: return "Y";
90 }
Chris Wilsona6172a82009-02-11 14:26:38 +000091}
92
Chris Wilson93dfb402011-03-29 16:59:50 -070093static const char *cache_level_str(int type)
Chris Wilson08c18322011-01-10 00:00:24 +000094{
95 switch (type) {
Chris Wilson93dfb402011-03-29 16:59:50 -070096 case I915_CACHE_NONE: return " uncached";
97 case I915_CACHE_LLC: return " snooped (LLC)";
98 case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
Chris Wilson08c18322011-01-10 00:00:24 +000099 default: return "";
100 }
101}
102
Chris Wilson37811fc2010-08-25 22:45:57 +0100103static void
104describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
105{
Chris Wilson0201f1e2012-07-20 12:41:01 +0100106 seq_printf(m, "%p: %s%s %8zdKiB %04x %04x %d %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100107 &obj->base,
108 get_pin_flag(obj),
109 get_tiling_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800110 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100111 obj->base.read_domains,
112 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100113 obj->last_read_seqno,
114 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000115 obj->last_fenced_seqno,
Chris Wilson93dfb402011-03-29 16:59:50 -0700116 cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100117 obj->dirty ? " dirty" : "",
118 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
119 if (obj->base.name)
120 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilsonc110a6d2012-08-11 15:41:02 +0100121 if (obj->pin_count)
122 seq_printf(m, " (pinned x %d)", obj->pin_count);
Chris Wilson37811fc2010-08-25 22:45:57 +0100123 if (obj->fence_reg != I915_FENCE_REG_NONE)
124 seq_printf(m, " (fence: %d)", obj->fence_reg);
125 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100126 seq_printf(m, " (gtt offset: %08x, size: %08x)",
127 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilson6299f992010-11-24 12:23:44 +0000128 if (obj->pin_mappable || obj->fault_mappable) {
129 char s[3], *t = s;
130 if (obj->pin_mappable)
131 *t++ = 'p';
132 if (obj->fault_mappable)
133 *t++ = 'f';
134 *t = '\0';
135 seq_printf(m, " (%s mappable)", s);
136 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100137 if (obj->ring != NULL)
138 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100139}
140
Ben Gamari433e12f2009-02-17 20:08:51 -0500141static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500142{
143 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500144 uintptr_t list = (uintptr_t) node->info_ent->data;
145 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500146 struct drm_device *dev = node->minor->dev;
147 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000148 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100149 size_t total_obj_size, total_gtt_size;
150 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100151
152 ret = mutex_lock_interruptible(&dev->struct_mutex);
153 if (ret)
154 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500155
Ben Gamari433e12f2009-02-17 20:08:51 -0500156 switch (list) {
157 case ACTIVE_LIST:
158 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100159 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500160 break;
161 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400162 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500163 head = &dev_priv->mm.inactive_list;
164 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500165 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100166 mutex_unlock(&dev->struct_mutex);
167 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500168 }
169
Chris Wilson8f2480f2010-09-26 11:44:19 +0100170 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000171 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100172 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000173 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800174 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000175 total_obj_size += obj->base.size;
176 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100177 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500178 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100179 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700180
Chris Wilson8f2480f2010-09-26 11:44:19 +0100181 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
182 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500183 return 0;
184}
185
Chris Wilson6299f992010-11-24 12:23:44 +0000186#define count_objects(list, member) do { \
187 list_for_each_entry(obj, list, member) { \
188 size += obj->gtt_space->size; \
189 ++count; \
190 if (obj->map_and_fenceable) { \
191 mappable_size += obj->gtt_space->size; \
192 ++mappable_count; \
193 } \
194 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400195} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000196
Chris Wilson73aa8082010-09-30 11:46:12 +0100197static int i915_gem_object_info(struct seq_file *m, void* data)
198{
199 struct drm_info_node *node = (struct drm_info_node *) m->private;
200 struct drm_device *dev = node->minor->dev;
201 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200202 u32 count, mappable_count, purgeable_count;
203 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000204 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100205 int ret;
206
207 ret = mutex_lock_interruptible(&dev->struct_mutex);
208 if (ret)
209 return ret;
210
Chris Wilson6299f992010-11-24 12:23:44 +0000211 seq_printf(m, "%u objects, %zu bytes\n",
212 dev_priv->mm.object_count,
213 dev_priv->mm.object_memory);
214
215 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200216 count_objects(&dev_priv->mm.bound_list, gtt_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000217 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
218 count, mappable_count, size, mappable_size);
219
220 size = count = mappable_size = mappable_count = 0;
221 count_objects(&dev_priv->mm.active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000222 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
223 count, mappable_count, size, mappable_size);
224
225 size = count = mappable_size = mappable_count = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000226 count_objects(&dev_priv->mm.inactive_list, mm_list);
227 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
228 count, mappable_count, size, mappable_size);
229
Chris Wilsonb7abb712012-08-20 11:33:30 +0200230 size = count = purgeable_size = purgeable_count = 0;
231 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200232 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200233 if (obj->madv == I915_MADV_DONTNEED)
234 purgeable_size += obj->base.size, ++purgeable_count;
235 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200236 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
237
Chris Wilson6299f992010-11-24 12:23:44 +0000238 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200239 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000240 if (obj->fault_mappable) {
241 size += obj->gtt_space->size;
242 ++count;
243 }
244 if (obj->pin_mappable) {
245 mappable_size += obj->gtt_space->size;
246 ++mappable_count;
247 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200248 if (obj->madv == I915_MADV_DONTNEED) {
249 purgeable_size += obj->base.size;
250 ++purgeable_count;
251 }
Chris Wilson6299f992010-11-24 12:23:44 +0000252 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200253 seq_printf(m, "%u purgeable objects, %zu bytes\n",
254 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000255 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
256 mappable_count, mappable_size);
257 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
258 count, size);
259
260 seq_printf(m, "%zu [%zu] gtt total\n",
261 dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
Chris Wilson73aa8082010-09-30 11:46:12 +0100262
263 mutex_unlock(&dev->struct_mutex);
264
265 return 0;
266}
267
Chris Wilson08c18322011-01-10 00:00:24 +0000268static int i915_gem_gtt_info(struct seq_file *m, void* data)
269{
270 struct drm_info_node *node = (struct drm_info_node *) m->private;
271 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100272 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000273 struct drm_i915_private *dev_priv = dev->dev_private;
274 struct drm_i915_gem_object *obj;
275 size_t total_obj_size, total_gtt_size;
276 int count, ret;
277
278 ret = mutex_lock_interruptible(&dev->struct_mutex);
279 if (ret)
280 return ret;
281
282 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200283 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100284 if (list == PINNED_LIST && obj->pin_count == 0)
285 continue;
286
Chris Wilson08c18322011-01-10 00:00:24 +0000287 seq_printf(m, " ");
288 describe_obj(m, obj);
289 seq_printf(m, "\n");
290 total_obj_size += obj->base.size;
291 total_gtt_size += obj->gtt_space->size;
292 count++;
293 }
294
295 mutex_unlock(&dev->struct_mutex);
296
297 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
298 count, total_obj_size, total_gtt_size);
299
300 return 0;
301}
302
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100303static int i915_gem_pageflip_info(struct seq_file *m, void *data)
304{
305 struct drm_info_node *node = (struct drm_info_node *) m->private;
306 struct drm_device *dev = node->minor->dev;
307 unsigned long flags;
308 struct intel_crtc *crtc;
309
310 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800311 const char pipe = pipe_name(crtc->pipe);
312 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100313 struct intel_unpin_work *work;
314
315 spin_lock_irqsave(&dev->event_lock, flags);
316 work = crtc->unpin_work;
317 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800318 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100319 pipe, plane);
320 } else {
321 if (!work->pending) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800322 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100323 pipe, plane);
324 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800325 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100326 pipe, plane);
327 }
328 if (work->enable_stall_check)
329 seq_printf(m, "Stall check enabled, ");
330 else
331 seq_printf(m, "Stall check waiting for page flip ioctl, ");
332 seq_printf(m, "%d prepares\n", work->pending);
333
334 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000335 struct drm_i915_gem_object *obj = work->old_fb_obj;
336 if (obj)
337 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100338 }
339 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000340 struct drm_i915_gem_object *obj = work->pending_flip_obj;
341 if (obj)
342 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100343 }
344 }
345 spin_unlock_irqrestore(&dev->event_lock, flags);
346 }
347
348 return 0;
349}
350
Ben Gamari20172632009-02-17 20:08:50 -0500351static int i915_gem_request_info(struct seq_file *m, void *data)
352{
353 struct drm_info_node *node = (struct drm_info_node *) m->private;
354 struct drm_device *dev = node->minor->dev;
355 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100356 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500357 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100358 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100359
360 ret = mutex_lock_interruptible(&dev->struct_mutex);
361 if (ret)
362 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500363
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100364 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100365 for_each_ring(ring, dev_priv, i) {
366 if (list_empty(&ring->request_list))
367 continue;
368
369 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100370 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100371 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100372 list) {
373 seq_printf(m, " %d @ %d\n",
374 gem_request->seqno,
375 (int) (jiffies - gem_request->emitted_jiffies));
376 }
377 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500378 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100379 mutex_unlock(&dev->struct_mutex);
380
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100381 if (count == 0)
382 seq_printf(m, "No requests\n");
383
Ben Gamari20172632009-02-17 20:08:50 -0500384 return 0;
385}
386
Chris Wilsonb2223492010-10-27 15:27:33 +0100387static void i915_ring_seqno_info(struct seq_file *m,
388 struct intel_ring_buffer *ring)
389{
390 if (ring->get_seqno) {
391 seq_printf(m, "Current sequence (%s): %d\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100392 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100393 }
394}
395
Ben Gamari20172632009-02-17 20:08:50 -0500396static int i915_gem_seqno_info(struct seq_file *m, void *data)
397{
398 struct drm_info_node *node = (struct drm_info_node *) m->private;
399 struct drm_device *dev = node->minor->dev;
400 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100401 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000402 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100403
404 ret = mutex_lock_interruptible(&dev->struct_mutex);
405 if (ret)
406 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500407
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100408 for_each_ring(ring, dev_priv, i)
409 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100410
411 mutex_unlock(&dev->struct_mutex);
412
Ben Gamari20172632009-02-17 20:08:50 -0500413 return 0;
414}
415
416
417static int i915_interrupt_info(struct seq_file *m, void *data)
418{
419 struct drm_info_node *node = (struct drm_info_node *) m->private;
420 struct drm_device *dev = node->minor->dev;
421 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100422 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800423 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100424
425 ret = mutex_lock_interruptible(&dev->struct_mutex);
426 if (ret)
427 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500428
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700429 if (IS_VALLEYVIEW(dev)) {
430 seq_printf(m, "Display IER:\t%08x\n",
431 I915_READ(VLV_IER));
432 seq_printf(m, "Display IIR:\t%08x\n",
433 I915_READ(VLV_IIR));
434 seq_printf(m, "Display IIR_RW:\t%08x\n",
435 I915_READ(VLV_IIR_RW));
436 seq_printf(m, "Display IMR:\t%08x\n",
437 I915_READ(VLV_IMR));
438 for_each_pipe(pipe)
439 seq_printf(m, "Pipe %c stat:\t%08x\n",
440 pipe_name(pipe),
441 I915_READ(PIPESTAT(pipe)));
442
443 seq_printf(m, "Master IER:\t%08x\n",
444 I915_READ(VLV_MASTER_IER));
445
446 seq_printf(m, "Render IER:\t%08x\n",
447 I915_READ(GTIER));
448 seq_printf(m, "Render IIR:\t%08x\n",
449 I915_READ(GTIIR));
450 seq_printf(m, "Render IMR:\t%08x\n",
451 I915_READ(GTIMR));
452
453 seq_printf(m, "PM IER:\t\t%08x\n",
454 I915_READ(GEN6_PMIER));
455 seq_printf(m, "PM IIR:\t\t%08x\n",
456 I915_READ(GEN6_PMIIR));
457 seq_printf(m, "PM IMR:\t\t%08x\n",
458 I915_READ(GEN6_PMIMR));
459
460 seq_printf(m, "Port hotplug:\t%08x\n",
461 I915_READ(PORT_HOTPLUG_EN));
462 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
463 I915_READ(VLV_DPFLIPSTAT));
464 seq_printf(m, "DPINVGTT:\t%08x\n",
465 I915_READ(DPINVGTT));
466
467 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800468 seq_printf(m, "Interrupt enable: %08x\n",
469 I915_READ(IER));
470 seq_printf(m, "Interrupt identity: %08x\n",
471 I915_READ(IIR));
472 seq_printf(m, "Interrupt mask: %08x\n",
473 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800474 for_each_pipe(pipe)
475 seq_printf(m, "Pipe %c stat: %08x\n",
476 pipe_name(pipe),
477 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800478 } else {
479 seq_printf(m, "North Display Interrupt enable: %08x\n",
480 I915_READ(DEIER));
481 seq_printf(m, "North Display Interrupt identity: %08x\n",
482 I915_READ(DEIIR));
483 seq_printf(m, "North Display Interrupt mask: %08x\n",
484 I915_READ(DEIMR));
485 seq_printf(m, "South Display Interrupt enable: %08x\n",
486 I915_READ(SDEIER));
487 seq_printf(m, "South Display Interrupt identity: %08x\n",
488 I915_READ(SDEIIR));
489 seq_printf(m, "South Display Interrupt mask: %08x\n",
490 I915_READ(SDEIMR));
491 seq_printf(m, "Graphics Interrupt enable: %08x\n",
492 I915_READ(GTIER));
493 seq_printf(m, "Graphics Interrupt identity: %08x\n",
494 I915_READ(GTIIR));
495 seq_printf(m, "Graphics Interrupt mask: %08x\n",
496 I915_READ(GTIMR));
497 }
Ben Gamari20172632009-02-17 20:08:50 -0500498 seq_printf(m, "Interrupts received: %d\n",
499 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100500 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700501 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100502 seq_printf(m,
503 "Graphics Interrupt mask (%s): %08x\n",
504 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000505 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100506 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000507 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100508 mutex_unlock(&dev->struct_mutex);
509
Ben Gamari20172632009-02-17 20:08:50 -0500510 return 0;
511}
512
Chris Wilsona6172a82009-02-11 14:26:38 +0000513static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
514{
515 struct drm_info_node *node = (struct drm_info_node *) m->private;
516 struct drm_device *dev = node->minor->dev;
517 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100518 int i, ret;
519
520 ret = mutex_lock_interruptible(&dev->struct_mutex);
521 if (ret)
522 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000523
524 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
525 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
526 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000527 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000528
Chris Wilson6c085a72012-08-20 11:40:46 +0200529 seq_printf(m, "Fence %d, pin count = %d, object = ",
530 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100531 if (obj == NULL)
532 seq_printf(m, "unused");
533 else
Chris Wilson05394f32010-11-08 19:18:58 +0000534 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100535 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000536 }
537
Chris Wilson05394f32010-11-08 19:18:58 +0000538 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000539 return 0;
540}
541
Ben Gamari20172632009-02-17 20:08:50 -0500542static int i915_hws_info(struct seq_file *m, void *data)
543{
544 struct drm_info_node *node = (struct drm_info_node *) m->private;
545 struct drm_device *dev = node->minor->dev;
546 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100547 struct intel_ring_buffer *ring;
Chris Wilson311bd682011-01-13 19:06:50 +0000548 const volatile u32 __iomem *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100549 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500550
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000551 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Chris Wilson311bd682011-01-13 19:06:50 +0000552 hws = (volatile u32 __iomem *)ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500553 if (hws == NULL)
554 return 0;
555
556 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
557 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
558 i * 4,
559 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
560 }
561 return 0;
562}
563
Chris Wilsone5c65262010-11-01 11:35:28 +0000564static const char *ring_str(int ring)
565{
566 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100567 case RCS: return "render";
568 case VCS: return "bsd";
569 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000570 default: return "";
571 }
572}
573
Chris Wilson9df30792010-02-18 10:24:56 +0000574static const char *pin_flag(int pinned)
575{
576 if (pinned > 0)
577 return " P";
578 else if (pinned < 0)
579 return " p";
580 else
581 return "";
582}
583
584static const char *tiling_flag(int tiling)
585{
586 switch (tiling) {
587 default:
588 case I915_TILING_NONE: return "";
589 case I915_TILING_X: return " X";
590 case I915_TILING_Y: return " Y";
591 }
592}
593
594static const char *dirty_flag(int dirty)
595{
596 return dirty ? " dirty" : "";
597}
598
599static const char *purgeable_flag(int purgeable)
600{
601 return purgeable ? " purgeable" : "";
602}
603
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000604static void print_error_buffers(struct seq_file *m,
605 const char *name,
606 struct drm_i915_error_buffer *err,
607 int count)
608{
609 seq_printf(m, "%s [%d]:\n", name, count);
610
611 while (count--) {
Chris Wilson0201f1e2012-07-20 12:41:01 +0100612 seq_printf(m, " %08x %8u %04x %04x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000613 err->gtt_offset,
614 err->size,
615 err->read_domains,
616 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100617 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000618 pin_flag(err->pinned),
619 tiling_flag(err->tiling),
620 dirty_flag(err->dirty),
621 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100622 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000623 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700624 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000625
626 if (err->name)
627 seq_printf(m, " (name: %d)", err->name);
628 if (err->fence_reg != I915_FENCE_REG_NONE)
629 seq_printf(m, " (fence: %d)", err->fence_reg);
630
631 seq_printf(m, "\n");
632 err++;
633 }
634}
635
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100636static void i915_ring_error_state(struct seq_file *m,
637 struct drm_device *dev,
638 struct drm_i915_error_state *error,
639 unsigned ring)
640{
Ben Widawskyec34a012012-04-03 23:03:00 -0700641 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100642 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100643 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
644 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100645 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
646 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
647 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
648 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Ben Widawsky050ee912012-08-22 11:32:15 -0700649 if (ring == RCS && INTEL_INFO(dev)->gen >= 4)
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100650 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Ben Widawsky050ee912012-08-22 11:32:15 -0700651
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100652 if (INTEL_INFO(dev)->gen >= 4)
653 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
654 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200655 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100656 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100657 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100658 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100659 seq_printf(m, " SYNC_0: 0x%08x\n",
660 error->semaphore_mboxes[ring][0]);
661 seq_printf(m, " SYNC_1: 0x%08x\n",
662 error->semaphore_mboxes[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100663 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100664 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Ben Widawsky9574b3f2012-04-26 16:03:01 -0700665 seq_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100666 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
667 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100668}
669
Daniel Vetterd5442302012-04-27 15:17:40 +0200670struct i915_error_state_file_priv {
671 struct drm_device *dev;
672 struct drm_i915_error_state *error;
673};
674
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700675static int i915_error_state(struct seq_file *m, void *unused)
676{
Daniel Vetterd5442302012-04-27 15:17:40 +0200677 struct i915_error_state_file_priv *error_priv = m->private;
678 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700679 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200680 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100681 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000682 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700683
Daniel Vetter742cbee2012-04-27 15:17:39 +0200684 if (!error) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700685 seq_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200686 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700687 }
688
Jesse Barnes8a905232009-07-11 16:48:03 -0400689 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
690 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000691 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100692 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700693 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100694 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700695 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000696
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100697 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100698 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
699
Ben Widawsky050ee912012-08-22 11:32:15 -0700700 for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
701 seq_printf(m, " INSTDONE_%d: 0x%08x\n", i, error->extra_instdone[i]);
702
Daniel Vetter33f3f512011-12-14 13:57:39 +0100703 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100704 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100705 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
706 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100707
Ben Widawsky71e172e2012-08-20 16:15:13 -0700708 if (INTEL_INFO(dev)->gen == 7)
709 seq_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
710
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) >>
Ben Widawskyc8735b02012-09-07 19:43:39 -0700917 GEN6_CAGF_SHIFT) * GT_FREQUENCY_MULTIPLIER);
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",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700933 max_freq * GT_FREQUENCY_MULTIPLIER);
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",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700937 max_freq * GT_FREQUENCY_MULTIPLIER);
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",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700941 max_freq * GT_FREQUENCY_MULTIPLIER);
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;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001072 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
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);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001100 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
Ben Widawsky4d855292011-12-12 19:34:16 -08001101 mutex_unlock(&dev->struct_mutex);
1102
1103 seq_printf(m, "Video Turbo Mode: %s\n",
1104 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1105 seq_printf(m, "HW control enabled: %s\n",
1106 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1107 seq_printf(m, "SW control enabled: %s\n",
1108 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1109 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001110 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001111 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1112 seq_printf(m, "RC6 Enabled: %s\n",
1113 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1114 seq_printf(m, "Deep RC6 Enabled: %s\n",
1115 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1116 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1117 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1118 seq_printf(m, "Current RC state: ");
1119 switch (gt_core_status & GEN6_RCn_MASK) {
1120 case GEN6_RC0:
1121 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1122 seq_printf(m, "Core Power Down\n");
1123 else
1124 seq_printf(m, "on\n");
1125 break;
1126 case GEN6_RC3:
1127 seq_printf(m, "RC3\n");
1128 break;
1129 case GEN6_RC6:
1130 seq_printf(m, "RC6\n");
1131 break;
1132 case GEN6_RC7:
1133 seq_printf(m, "RC7\n");
1134 break;
1135 default:
1136 seq_printf(m, "Unknown\n");
1137 break;
1138 }
1139
1140 seq_printf(m, "Core Power Down: %s\n",
1141 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001142
1143 /* Not exactly sure what this is */
1144 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1145 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1146 seq_printf(m, "RC6 residency since boot: %u\n",
1147 I915_READ(GEN6_GT_GFX_RC6));
1148 seq_printf(m, "RC6+ residency since boot: %u\n",
1149 I915_READ(GEN6_GT_GFX_RC6p));
1150 seq_printf(m, "RC6++ residency since boot: %u\n",
1151 I915_READ(GEN6_GT_GFX_RC6pp));
1152
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001153 seq_printf(m, "RC6 voltage: %dmV\n",
1154 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1155 seq_printf(m, "RC6+ voltage: %dmV\n",
1156 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1157 seq_printf(m, "RC6++ voltage: %dmV\n",
1158 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001159 return 0;
1160}
1161
1162static int i915_drpc_info(struct seq_file *m, void *unused)
1163{
1164 struct drm_info_node *node = (struct drm_info_node *) m->private;
1165 struct drm_device *dev = node->minor->dev;
1166
1167 if (IS_GEN6(dev) || IS_GEN7(dev))
1168 return gen6_drpc_info(m);
1169 else
1170 return ironlake_drpc_info(m);
1171}
1172
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001173static int i915_fbc_status(struct seq_file *m, void *unused)
1174{
1175 struct drm_info_node *node = (struct drm_info_node *) m->private;
1176 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001177 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001178
Adam Jacksonee5382a2010-04-23 11:17:39 -04001179 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001180 seq_printf(m, "FBC unsupported on this chipset\n");
1181 return 0;
1182 }
1183
Adam Jacksonee5382a2010-04-23 11:17:39 -04001184 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001185 seq_printf(m, "FBC enabled\n");
1186 } else {
1187 seq_printf(m, "FBC disabled: ");
1188 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001189 case FBC_NO_OUTPUT:
1190 seq_printf(m, "no outputs");
1191 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001192 case FBC_STOLEN_TOO_SMALL:
1193 seq_printf(m, "not enough stolen memory");
1194 break;
1195 case FBC_UNSUPPORTED_MODE:
1196 seq_printf(m, "mode not supported");
1197 break;
1198 case FBC_MODE_TOO_LARGE:
1199 seq_printf(m, "mode too large");
1200 break;
1201 case FBC_BAD_PLANE:
1202 seq_printf(m, "FBC unsupported on plane");
1203 break;
1204 case FBC_NOT_TILED:
1205 seq_printf(m, "scanout buffer not tiled");
1206 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001207 case FBC_MULTIPLE_PIPES:
1208 seq_printf(m, "multiple pipes are enabled");
1209 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001210 case FBC_MODULE_PARAM:
1211 seq_printf(m, "disabled per module param (default off)");
1212 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001213 default:
1214 seq_printf(m, "unknown reason");
1215 }
1216 seq_printf(m, "\n");
1217 }
1218 return 0;
1219}
1220
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001221static int i915_sr_status(struct seq_file *m, void *unused)
1222{
1223 struct drm_info_node *node = (struct drm_info_node *) m->private;
1224 struct drm_device *dev = node->minor->dev;
1225 drm_i915_private_t *dev_priv = dev->dev_private;
1226 bool sr_enabled = false;
1227
Yuanhan Liu13982612010-12-15 15:42:31 +08001228 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001229 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001230 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001231 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1232 else if (IS_I915GM(dev))
1233 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1234 else if (IS_PINEVIEW(dev))
1235 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1236
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001237 seq_printf(m, "self-refresh: %s\n",
1238 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001239
1240 return 0;
1241}
1242
Jesse Barnes7648fa92010-05-20 14:28:11 -07001243static int i915_emon_status(struct seq_file *m, void *unused)
1244{
1245 struct drm_info_node *node = (struct drm_info_node *) m->private;
1246 struct drm_device *dev = node->minor->dev;
1247 drm_i915_private_t *dev_priv = dev->dev_private;
1248 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001249 int ret;
1250
Chris Wilson582be6b2012-04-30 19:35:02 +01001251 if (!IS_GEN5(dev))
1252 return -ENODEV;
1253
Chris Wilsonde227ef2010-07-03 07:58:38 +01001254 ret = mutex_lock_interruptible(&dev->struct_mutex);
1255 if (ret)
1256 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001257
1258 temp = i915_mch_val(dev_priv);
1259 chipset = i915_chipset_val(dev_priv);
1260 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001261 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001262
1263 seq_printf(m, "GMCH temp: %ld\n", temp);
1264 seq_printf(m, "Chipset power: %ld\n", chipset);
1265 seq_printf(m, "GFX power: %ld\n", gfx);
1266 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1267
1268 return 0;
1269}
1270
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001271static int i915_ring_freq_table(struct seq_file *m, void *unused)
1272{
1273 struct drm_info_node *node = (struct drm_info_node *) m->private;
1274 struct drm_device *dev = node->minor->dev;
1275 drm_i915_private_t *dev_priv = dev->dev_private;
1276 int ret;
1277 int gpu_freq, ia_freq;
1278
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001279 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001280 seq_printf(m, "unsupported on this chipset\n");
1281 return 0;
1282 }
1283
1284 ret = mutex_lock_interruptible(&dev->struct_mutex);
1285 if (ret)
1286 return ret;
1287
1288 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1289
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001290 for (gpu_freq = dev_priv->rps.min_delay;
1291 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001292 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001293 ia_freq = gpu_freq;
1294 sandybridge_pcode_read(dev_priv,
1295 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1296 &ia_freq);
Ben Widawskyc8735b02012-09-07 19:43:39 -07001297 seq_printf(m, "%d\t\t%d\n", gpu_freq * GT_FREQUENCY_MULTIPLIER, ia_freq * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001298 }
1299
1300 mutex_unlock(&dev->struct_mutex);
1301
1302 return 0;
1303}
1304
Jesse Barnes7648fa92010-05-20 14:28:11 -07001305static int i915_gfxec(struct seq_file *m, void *unused)
1306{
1307 struct drm_info_node *node = (struct drm_info_node *) m->private;
1308 struct drm_device *dev = node->minor->dev;
1309 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001310 int ret;
1311
1312 ret = mutex_lock_interruptible(&dev->struct_mutex);
1313 if (ret)
1314 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001315
1316 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1317
Ben Widawsky616fdb52011-10-05 11:44:54 -07001318 mutex_unlock(&dev->struct_mutex);
1319
Jesse Barnes7648fa92010-05-20 14:28:11 -07001320 return 0;
1321}
1322
Chris Wilson44834a62010-08-19 16:09:23 +01001323static int i915_opregion(struct seq_file *m, void *unused)
1324{
1325 struct drm_info_node *node = (struct drm_info_node *) m->private;
1326 struct drm_device *dev = node->minor->dev;
1327 drm_i915_private_t *dev_priv = dev->dev_private;
1328 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001329 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001330 int ret;
1331
Daniel Vetter0d38f002012-04-21 22:49:10 +02001332 if (data == NULL)
1333 return -ENOMEM;
1334
Chris Wilson44834a62010-08-19 16:09:23 +01001335 ret = mutex_lock_interruptible(&dev->struct_mutex);
1336 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001337 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001338
Daniel Vetter0d38f002012-04-21 22:49:10 +02001339 if (opregion->header) {
1340 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1341 seq_write(m, data, OPREGION_SIZE);
1342 }
Chris Wilson44834a62010-08-19 16:09:23 +01001343
1344 mutex_unlock(&dev->struct_mutex);
1345
Daniel Vetter0d38f002012-04-21 22:49:10 +02001346out:
1347 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001348 return 0;
1349}
1350
Chris Wilson37811fc2010-08-25 22:45:57 +01001351static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1352{
1353 struct drm_info_node *node = (struct drm_info_node *) m->private;
1354 struct drm_device *dev = node->minor->dev;
1355 drm_i915_private_t *dev_priv = dev->dev_private;
1356 struct intel_fbdev *ifbdev;
1357 struct intel_framebuffer *fb;
1358 int ret;
1359
1360 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1361 if (ret)
1362 return ret;
1363
1364 ifbdev = dev_priv->fbdev;
1365 fb = to_intel_framebuffer(ifbdev->helper.fb);
1366
1367 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1368 fb->base.width,
1369 fb->base.height,
1370 fb->base.depth,
1371 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001372 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001373 seq_printf(m, "\n");
1374
1375 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1376 if (&fb->base == ifbdev->helper.fb)
1377 continue;
1378
1379 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1380 fb->base.width,
1381 fb->base.height,
1382 fb->base.depth,
1383 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001384 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001385 seq_printf(m, "\n");
1386 }
1387
1388 mutex_unlock(&dev->mode_config.mutex);
1389
1390 return 0;
1391}
1392
Ben Widawskye76d3632011-03-19 18:14:29 -07001393static int i915_context_status(struct seq_file *m, void *unused)
1394{
1395 struct drm_info_node *node = (struct drm_info_node *) m->private;
1396 struct drm_device *dev = node->minor->dev;
1397 drm_i915_private_t *dev_priv = dev->dev_private;
1398 int ret;
1399
1400 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1401 if (ret)
1402 return ret;
1403
Ben Widawskydc501fb2011-06-29 11:41:51 -07001404 if (dev_priv->pwrctx) {
1405 seq_printf(m, "power context ");
1406 describe_obj(m, dev_priv->pwrctx);
1407 seq_printf(m, "\n");
1408 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001409
Ben Widawskydc501fb2011-06-29 11:41:51 -07001410 if (dev_priv->renderctx) {
1411 seq_printf(m, "render context ");
1412 describe_obj(m, dev_priv->renderctx);
1413 seq_printf(m, "\n");
1414 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001415
1416 mutex_unlock(&dev->mode_config.mutex);
1417
1418 return 0;
1419}
1420
Ben Widawsky6d794d42011-04-25 11:25:56 -07001421static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1422{
1423 struct drm_info_node *node = (struct drm_info_node *) m->private;
1424 struct drm_device *dev = node->minor->dev;
1425 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001426 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001427
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001428 spin_lock_irq(&dev_priv->gt_lock);
1429 forcewake_count = dev_priv->forcewake_count;
1430 spin_unlock_irq(&dev_priv->gt_lock);
1431
1432 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001433
1434 return 0;
1435}
1436
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001437static const char *swizzle_string(unsigned swizzle)
1438{
1439 switch(swizzle) {
1440 case I915_BIT_6_SWIZZLE_NONE:
1441 return "none";
1442 case I915_BIT_6_SWIZZLE_9:
1443 return "bit9";
1444 case I915_BIT_6_SWIZZLE_9_10:
1445 return "bit9/bit10";
1446 case I915_BIT_6_SWIZZLE_9_11:
1447 return "bit9/bit11";
1448 case I915_BIT_6_SWIZZLE_9_10_11:
1449 return "bit9/bit10/bit11";
1450 case I915_BIT_6_SWIZZLE_9_17:
1451 return "bit9/bit17";
1452 case I915_BIT_6_SWIZZLE_9_10_17:
1453 return "bit9/bit10/bit17";
1454 case I915_BIT_6_SWIZZLE_UNKNOWN:
1455 return "unkown";
1456 }
1457
1458 return "bug";
1459}
1460
1461static int i915_swizzle_info(struct seq_file *m, void *data)
1462{
1463 struct drm_info_node *node = (struct drm_info_node *) m->private;
1464 struct drm_device *dev = node->minor->dev;
1465 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001466 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001467
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001468 ret = mutex_lock_interruptible(&dev->struct_mutex);
1469 if (ret)
1470 return ret;
1471
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001472 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1473 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1474 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1475 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1476
1477 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1478 seq_printf(m, "DDC = 0x%08x\n",
1479 I915_READ(DCC));
1480 seq_printf(m, "C0DRB3 = 0x%04x\n",
1481 I915_READ16(C0DRB3));
1482 seq_printf(m, "C1DRB3 = 0x%04x\n",
1483 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001484 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1485 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1486 I915_READ(MAD_DIMM_C0));
1487 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1488 I915_READ(MAD_DIMM_C1));
1489 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1490 I915_READ(MAD_DIMM_C2));
1491 seq_printf(m, "TILECTL = 0x%08x\n",
1492 I915_READ(TILECTL));
1493 seq_printf(m, "ARB_MODE = 0x%08x\n",
1494 I915_READ(ARB_MODE));
1495 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1496 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001497 }
1498 mutex_unlock(&dev->struct_mutex);
1499
1500 return 0;
1501}
1502
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001503static int i915_ppgtt_info(struct seq_file *m, void *data)
1504{
1505 struct drm_info_node *node = (struct drm_info_node *) m->private;
1506 struct drm_device *dev = node->minor->dev;
1507 struct drm_i915_private *dev_priv = dev->dev_private;
1508 struct intel_ring_buffer *ring;
1509 int i, ret;
1510
1511
1512 ret = mutex_lock_interruptible(&dev->struct_mutex);
1513 if (ret)
1514 return ret;
1515 if (INTEL_INFO(dev)->gen == 6)
1516 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1517
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001518 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001519 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),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001722 "max freq: %d\n", dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER);
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 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07001765 dev_priv->rps.max_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes358733e2011-07-27 11:53:01 -07001766
Ben Widawskyc8735b02012-09-07 19:43:39 -07001767 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
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),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001798 "min freq: %d\n", dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER);
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 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07001839 dev_priv->rps.min_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes1523c312012-05-25 12:34:54 -07001840
Ben Widawskyc8735b02012-09-07 19:43:39 -07001841 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
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 */