blob: c92ae7ff47189b5e9aebf9a1ccae5fa1c71c1305 [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>
Daniel Vetter4518f612013-01-23 16:16:35 +010033#include <generated/utsrelease.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.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"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050038#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 Wilson04b97b32012-11-27 17:06:53 +0000106 seq_printf(m, "%p: %s%s %8zdKiB %02x %02x %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 Wilsonc1ad11f2012-11-15 11:32:21 +0000128 if (obj->stolen)
129 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000130 if (obj->pin_mappable || obj->fault_mappable) {
131 char s[3], *t = s;
132 if (obj->pin_mappable)
133 *t++ = 'p';
134 if (obj->fault_mappable)
135 *t++ = 'f';
136 *t = '\0';
137 seq_printf(m, " (%s mappable)", s);
138 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100139 if (obj->ring != NULL)
140 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100141}
142
Ben Gamari433e12f2009-02-17 20:08:51 -0500143static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500144{
145 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500146 uintptr_t list = (uintptr_t) node->info_ent->data;
147 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500148 struct drm_device *dev = node->minor->dev;
149 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000150 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100151 size_t total_obj_size, total_gtt_size;
152 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100153
154 ret = mutex_lock_interruptible(&dev->struct_mutex);
155 if (ret)
156 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500157
Ben Gamari433e12f2009-02-17 20:08:51 -0500158 switch (list) {
159 case ACTIVE_LIST:
160 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100161 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500162 break;
163 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400164 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500165 head = &dev_priv->mm.inactive_list;
166 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500167 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100168 mutex_unlock(&dev->struct_mutex);
169 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500170 }
171
Chris Wilson8f2480f2010-09-26 11:44:19 +0100172 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000173 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100174 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000175 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800176 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000177 total_obj_size += obj->base.size;
178 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100179 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500180 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100181 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700182
Chris Wilson8f2480f2010-09-26 11:44:19 +0100183 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
184 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500185 return 0;
186}
187
Chris Wilson6299f992010-11-24 12:23:44 +0000188#define count_objects(list, member) do { \
189 list_for_each_entry(obj, list, member) { \
190 size += obj->gtt_space->size; \
191 ++count; \
192 if (obj->map_and_fenceable) { \
193 mappable_size += obj->gtt_space->size; \
194 ++mappable_count; \
195 } \
196 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400197} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000198
Chris Wilson73aa8082010-09-30 11:46:12 +0100199static int i915_gem_object_info(struct seq_file *m, void* data)
200{
201 struct drm_info_node *node = (struct drm_info_node *) m->private;
202 struct drm_device *dev = node->minor->dev;
203 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200204 u32 count, mappable_count, purgeable_count;
205 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000206 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100207 int ret;
208
209 ret = mutex_lock_interruptible(&dev->struct_mutex);
210 if (ret)
211 return ret;
212
Chris Wilson6299f992010-11-24 12:23:44 +0000213 seq_printf(m, "%u objects, %zu bytes\n",
214 dev_priv->mm.object_count,
215 dev_priv->mm.object_memory);
216
217 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200218 count_objects(&dev_priv->mm.bound_list, gtt_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000219 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
220 count, mappable_count, size, mappable_size);
221
222 size = count = mappable_size = mappable_count = 0;
223 count_objects(&dev_priv->mm.active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000224 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
225 count, mappable_count, size, mappable_size);
226
227 size = count = mappable_size = mappable_count = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000228 count_objects(&dev_priv->mm.inactive_list, mm_list);
229 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
230 count, mappable_count, size, mappable_size);
231
Chris Wilsonb7abb712012-08-20 11:33:30 +0200232 size = count = purgeable_size = purgeable_count = 0;
233 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200234 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200235 if (obj->madv == I915_MADV_DONTNEED)
236 purgeable_size += obj->base.size, ++purgeable_count;
237 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200238 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
239
Chris Wilson6299f992010-11-24 12:23:44 +0000240 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200241 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000242 if (obj->fault_mappable) {
243 size += obj->gtt_space->size;
244 ++count;
245 }
246 if (obj->pin_mappable) {
247 mappable_size += obj->gtt_space->size;
248 ++mappable_count;
249 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200250 if (obj->madv == I915_MADV_DONTNEED) {
251 purgeable_size += obj->base.size;
252 ++purgeable_count;
253 }
Chris Wilson6299f992010-11-24 12:23:44 +0000254 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200255 seq_printf(m, "%u purgeable objects, %zu bytes\n",
256 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000257 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
258 mappable_count, mappable_size);
259 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
260 count, size);
261
Ben Widawsky93d18792013-01-17 12:45:17 -0800262 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky5d4545a2013-01-17 12:45:15 -0800263 dev_priv->gtt.total,
264 dev_priv->gtt.mappable_end - dev_priv->gtt.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100265
266 mutex_unlock(&dev->struct_mutex);
267
268 return 0;
269}
270
Chris Wilson08c18322011-01-10 00:00:24 +0000271static int i915_gem_gtt_info(struct seq_file *m, void* data)
272{
273 struct drm_info_node *node = (struct drm_info_node *) m->private;
274 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100275 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000276 struct drm_i915_private *dev_priv = dev->dev_private;
277 struct drm_i915_gem_object *obj;
278 size_t total_obj_size, total_gtt_size;
279 int count, ret;
280
281 ret = mutex_lock_interruptible(&dev->struct_mutex);
282 if (ret)
283 return ret;
284
285 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200286 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100287 if (list == PINNED_LIST && obj->pin_count == 0)
288 continue;
289
Chris Wilson08c18322011-01-10 00:00:24 +0000290 seq_printf(m, " ");
291 describe_obj(m, obj);
292 seq_printf(m, "\n");
293 total_obj_size += obj->base.size;
294 total_gtt_size += obj->gtt_space->size;
295 count++;
296 }
297
298 mutex_unlock(&dev->struct_mutex);
299
300 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
301 count, total_obj_size, total_gtt_size);
302
303 return 0;
304}
305
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100306static int i915_gem_pageflip_info(struct seq_file *m, void *data)
307{
308 struct drm_info_node *node = (struct drm_info_node *) m->private;
309 struct drm_device *dev = node->minor->dev;
310 unsigned long flags;
311 struct intel_crtc *crtc;
312
313 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800314 const char pipe = pipe_name(crtc->pipe);
315 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100316 struct intel_unpin_work *work;
317
318 spin_lock_irqsave(&dev->event_lock, flags);
319 work = crtc->unpin_work;
320 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800321 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100322 pipe, plane);
323 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000324 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800325 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100326 pipe, plane);
327 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800328 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100329 pipe, plane);
330 }
331 if (work->enable_stall_check)
332 seq_printf(m, "Stall check enabled, ");
333 else
334 seq_printf(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000335 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100336
337 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000338 struct drm_i915_gem_object *obj = work->old_fb_obj;
339 if (obj)
340 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100341 }
342 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000343 struct drm_i915_gem_object *obj = work->pending_flip_obj;
344 if (obj)
345 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100346 }
347 }
348 spin_unlock_irqrestore(&dev->event_lock, flags);
349 }
350
351 return 0;
352}
353
Ben Gamari20172632009-02-17 20:08:50 -0500354static int i915_gem_request_info(struct seq_file *m, void *data)
355{
356 struct drm_info_node *node = (struct drm_info_node *) m->private;
357 struct drm_device *dev = node->minor->dev;
358 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100359 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500360 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100361 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100362
363 ret = mutex_lock_interruptible(&dev->struct_mutex);
364 if (ret)
365 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500366
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100367 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100368 for_each_ring(ring, dev_priv, i) {
369 if (list_empty(&ring->request_list))
370 continue;
371
372 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100373 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100374 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100375 list) {
376 seq_printf(m, " %d @ %d\n",
377 gem_request->seqno,
378 (int) (jiffies - gem_request->emitted_jiffies));
379 }
380 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500381 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100382 mutex_unlock(&dev->struct_mutex);
383
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100384 if (count == 0)
385 seq_printf(m, "No requests\n");
386
Ben Gamari20172632009-02-17 20:08:50 -0500387 return 0;
388}
389
Chris Wilsonb2223492010-10-27 15:27:33 +0100390static void i915_ring_seqno_info(struct seq_file *m,
391 struct intel_ring_buffer *ring)
392{
393 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200394 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100395 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100396 }
397}
398
Ben Gamari20172632009-02-17 20:08:50 -0500399static int i915_gem_seqno_info(struct seq_file *m, void *data)
400{
401 struct drm_info_node *node = (struct drm_info_node *) m->private;
402 struct drm_device *dev = node->minor->dev;
403 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100404 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000405 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100406
407 ret = mutex_lock_interruptible(&dev->struct_mutex);
408 if (ret)
409 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500410
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100411 for_each_ring(ring, dev_priv, i)
412 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100413
414 mutex_unlock(&dev->struct_mutex);
415
Ben Gamari20172632009-02-17 20:08:50 -0500416 return 0;
417}
418
419
420static int i915_interrupt_info(struct seq_file *m, void *data)
421{
422 struct drm_info_node *node = (struct drm_info_node *) m->private;
423 struct drm_device *dev = node->minor->dev;
424 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100425 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800426 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100427
428 ret = mutex_lock_interruptible(&dev->struct_mutex);
429 if (ret)
430 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500431
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700432 if (IS_VALLEYVIEW(dev)) {
433 seq_printf(m, "Display IER:\t%08x\n",
434 I915_READ(VLV_IER));
435 seq_printf(m, "Display IIR:\t%08x\n",
436 I915_READ(VLV_IIR));
437 seq_printf(m, "Display IIR_RW:\t%08x\n",
438 I915_READ(VLV_IIR_RW));
439 seq_printf(m, "Display IMR:\t%08x\n",
440 I915_READ(VLV_IMR));
441 for_each_pipe(pipe)
442 seq_printf(m, "Pipe %c stat:\t%08x\n",
443 pipe_name(pipe),
444 I915_READ(PIPESTAT(pipe)));
445
446 seq_printf(m, "Master IER:\t%08x\n",
447 I915_READ(VLV_MASTER_IER));
448
449 seq_printf(m, "Render IER:\t%08x\n",
450 I915_READ(GTIER));
451 seq_printf(m, "Render IIR:\t%08x\n",
452 I915_READ(GTIIR));
453 seq_printf(m, "Render IMR:\t%08x\n",
454 I915_READ(GTIMR));
455
456 seq_printf(m, "PM IER:\t\t%08x\n",
457 I915_READ(GEN6_PMIER));
458 seq_printf(m, "PM IIR:\t\t%08x\n",
459 I915_READ(GEN6_PMIIR));
460 seq_printf(m, "PM IMR:\t\t%08x\n",
461 I915_READ(GEN6_PMIMR));
462
463 seq_printf(m, "Port hotplug:\t%08x\n",
464 I915_READ(PORT_HOTPLUG_EN));
465 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
466 I915_READ(VLV_DPFLIPSTAT));
467 seq_printf(m, "DPINVGTT:\t%08x\n",
468 I915_READ(DPINVGTT));
469
470 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800471 seq_printf(m, "Interrupt enable: %08x\n",
472 I915_READ(IER));
473 seq_printf(m, "Interrupt identity: %08x\n",
474 I915_READ(IIR));
475 seq_printf(m, "Interrupt mask: %08x\n",
476 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800477 for_each_pipe(pipe)
478 seq_printf(m, "Pipe %c stat: %08x\n",
479 pipe_name(pipe),
480 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800481 } else {
482 seq_printf(m, "North Display Interrupt enable: %08x\n",
483 I915_READ(DEIER));
484 seq_printf(m, "North Display Interrupt identity: %08x\n",
485 I915_READ(DEIIR));
486 seq_printf(m, "North Display Interrupt mask: %08x\n",
487 I915_READ(DEIMR));
488 seq_printf(m, "South Display Interrupt enable: %08x\n",
489 I915_READ(SDEIER));
490 seq_printf(m, "South Display Interrupt identity: %08x\n",
491 I915_READ(SDEIIR));
492 seq_printf(m, "South Display Interrupt mask: %08x\n",
493 I915_READ(SDEIMR));
494 seq_printf(m, "Graphics Interrupt enable: %08x\n",
495 I915_READ(GTIER));
496 seq_printf(m, "Graphics Interrupt identity: %08x\n",
497 I915_READ(GTIIR));
498 seq_printf(m, "Graphics Interrupt mask: %08x\n",
499 I915_READ(GTIMR));
500 }
Ben Gamari20172632009-02-17 20:08:50 -0500501 seq_printf(m, "Interrupts received: %d\n",
502 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100503 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700504 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100505 seq_printf(m,
506 "Graphics Interrupt mask (%s): %08x\n",
507 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000508 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100509 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000510 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100511 mutex_unlock(&dev->struct_mutex);
512
Ben Gamari20172632009-02-17 20:08:50 -0500513 return 0;
514}
515
Chris Wilsona6172a82009-02-11 14:26:38 +0000516static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
517{
518 struct drm_info_node *node = (struct drm_info_node *) m->private;
519 struct drm_device *dev = node->minor->dev;
520 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100521 int i, ret;
522
523 ret = mutex_lock_interruptible(&dev->struct_mutex);
524 if (ret)
525 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000526
527 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
528 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
529 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000530 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000531
Chris Wilson6c085a72012-08-20 11:40:46 +0200532 seq_printf(m, "Fence %d, pin count = %d, object = ",
533 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100534 if (obj == NULL)
535 seq_printf(m, "unused");
536 else
Chris Wilson05394f32010-11-08 19:18:58 +0000537 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100538 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000539 }
540
Chris Wilson05394f32010-11-08 19:18:58 +0000541 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000542 return 0;
543}
544
Ben Gamari20172632009-02-17 20:08:50 -0500545static int i915_hws_info(struct seq_file *m, void *data)
546{
547 struct drm_info_node *node = (struct drm_info_node *) m->private;
548 struct drm_device *dev = node->minor->dev;
549 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100550 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100551 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100552 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500553
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000554 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100555 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500556 if (hws == NULL)
557 return 0;
558
559 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
560 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
561 i * 4,
562 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
563 }
564 return 0;
565}
566
Chris Wilsone5c65262010-11-01 11:35:28 +0000567static const char *ring_str(int ring)
568{
569 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100570 case RCS: return "render";
571 case VCS: return "bsd";
572 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000573 default: return "";
574 }
575}
576
Chris Wilson9df30792010-02-18 10:24:56 +0000577static const char *pin_flag(int pinned)
578{
579 if (pinned > 0)
580 return " P";
581 else if (pinned < 0)
582 return " p";
583 else
584 return "";
585}
586
587static const char *tiling_flag(int tiling)
588{
589 switch (tiling) {
590 default:
591 case I915_TILING_NONE: return "";
592 case I915_TILING_X: return " X";
593 case I915_TILING_Y: return " Y";
594 }
595}
596
597static const char *dirty_flag(int dirty)
598{
599 return dirty ? " dirty" : "";
600}
601
602static const char *purgeable_flag(int purgeable)
603{
604 return purgeable ? " purgeable" : "";
605}
606
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000607static void print_error_buffers(struct seq_file *m,
608 const char *name,
609 struct drm_i915_error_buffer *err,
610 int count)
611{
612 seq_printf(m, "%s [%d]:\n", name, count);
613
614 while (count--) {
Chris Wilson04b97b32012-11-27 17:06:53 +0000615 seq_printf(m, " %08x %8u %02x %02x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000616 err->gtt_offset,
617 err->size,
618 err->read_domains,
619 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100620 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000621 pin_flag(err->pinned),
622 tiling_flag(err->tiling),
623 dirty_flag(err->dirty),
624 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100625 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000626 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700627 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000628
629 if (err->name)
630 seq_printf(m, " (name: %d)", err->name);
631 if (err->fence_reg != I915_FENCE_REG_NONE)
632 seq_printf(m, " (fence: %d)", err->fence_reg);
633
634 seq_printf(m, "\n");
635 err++;
636 }
637}
638
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100639static void i915_ring_error_state(struct seq_file *m,
640 struct drm_device *dev,
641 struct drm_i915_error_state *error,
642 unsigned ring)
643{
Ben Widawskyec34a012012-04-03 23:03:00 -0700644 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100645 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100646 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
647 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Chris Wilson0f3b6842013-01-15 12:05:55 +0000648 seq_printf(m, " CTL: 0x%08x\n", error->ctl[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100649 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
650 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
651 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
652 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Ben Widawsky050ee912012-08-22 11:32:15 -0700653 if (ring == RCS && INTEL_INFO(dev)->gen >= 4)
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100654 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Ben Widawsky050ee912012-08-22 11:32:15 -0700655
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100656 if (INTEL_INFO(dev)->gen >= 4)
657 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
658 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200659 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100660 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100661 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100662 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Chris Wilsondf2b23d2012-11-27 17:06:54 +0000663 seq_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
664 error->semaphore_mboxes[ring][0],
665 error->semaphore_seqno[ring][0]);
666 seq_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
667 error->semaphore_mboxes[ring][1],
668 error->semaphore_seqno[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);
Jani Nikulafdfa1752013-02-14 11:23:35 +0200697 seq_printf(m, "Kernel: " UTS_RELEASE "\n");
Chris Wilson9df30792010-02-18 10:24:56 +0000698 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100699 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700700 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100701 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Chris Wilson0f3b6842013-01-15 12:05:55 +0000702 seq_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
703 seq_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700704 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000705
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100706 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100707 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
708
Ben Widawsky050ee912012-08-22 11:32:15 -0700709 for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
710 seq_printf(m, " INSTDONE_%d: 0x%08x\n", i, error->extra_instdone[i]);
711
Daniel Vetter33f3f512011-12-14 13:57:39 +0100712 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100713 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100714 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
715 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100716
Ben Widawsky71e172e2012-08-20 16:15:13 -0700717 if (INTEL_INFO(dev)->gen == 7)
718 seq_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
719
Chris Wilsonb4519512012-05-11 14:29:30 +0100720 for_each_ring(ring, dev_priv, i)
721 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100722
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000723 if (error->active_bo)
724 print_error_buffers(m, "Active",
725 error->active_bo,
726 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000727
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000728 if (error->pinned_bo)
729 print_error_buffers(m, "Pinned",
730 error->pinned_bo,
731 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000732
Chris Wilson52d39a22012-02-15 11:25:37 +0000733 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
734 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000735
Chris Wilson52d39a22012-02-15 11:25:37 +0000736 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000737 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
738 dev_priv->ring[i].name,
739 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000740 offset = 0;
741 for (page = 0; page < obj->page_count; page++) {
742 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
743 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
744 offset += 4;
745 }
746 }
747 }
Chris Wilson9df30792010-02-18 10:24:56 +0000748
Chris Wilson52d39a22012-02-15 11:25:37 +0000749 if (error->ring[i].num_requests) {
750 seq_printf(m, "%s --- %d requests\n",
751 dev_priv->ring[i].name,
752 error->ring[i].num_requests);
753 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000754 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000755 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000756 error->ring[i].requests[j].jiffies,
757 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000758 }
759 }
760
761 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000762 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
763 dev_priv->ring[i].name,
764 obj->gtt_offset);
765 offset = 0;
766 for (page = 0; page < obj->page_count; page++) {
767 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
768 seq_printf(m, "%08x : %08x\n",
769 offset,
770 obj->pages[page][elt]);
771 offset += 4;
772 }
Chris Wilson9df30792010-02-18 10:24:56 +0000773 }
774 }
Ben Widawsky8c123e52013-03-04 17:00:29 -0800775
776 obj = error->ring[i].ctx;
777 if (obj) {
778 seq_printf(m, "%s --- HW Context = 0x%08x\n",
779 dev_priv->ring[i].name,
780 obj->gtt_offset);
781 offset = 0;
782 for (elt = 0; elt < PAGE_SIZE/16; elt += 4) {
783 seq_printf(m, "[%04x] %08x %08x %08x %08x\n",
784 offset,
785 obj->pages[0][elt],
786 obj->pages[0][elt+1],
787 obj->pages[0][elt+2],
788 obj->pages[0][elt+3]);
789 offset += 16;
790 }
791 }
Chris Wilson9df30792010-02-18 10:24:56 +0000792 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700793
Chris Wilson6ef3d422010-08-04 20:26:07 +0100794 if (error->overlay)
795 intel_overlay_print_error_state(m, error->overlay);
796
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000797 if (error->display)
798 intel_display_print_error_state(m, dev, error->display);
799
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700800 return 0;
801}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700802
Daniel Vetterd5442302012-04-27 15:17:40 +0200803static ssize_t
804i915_error_state_write(struct file *filp,
805 const char __user *ubuf,
806 size_t cnt,
807 loff_t *ppos)
808{
809 struct seq_file *m = filp->private_data;
810 struct i915_error_state_file_priv *error_priv = m->private;
811 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200812 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200813
814 DRM_DEBUG_DRIVER("Resetting error state\n");
815
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200816 ret = mutex_lock_interruptible(&dev->struct_mutex);
817 if (ret)
818 return ret;
819
Daniel Vetterd5442302012-04-27 15:17:40 +0200820 i915_destroy_error_state(dev);
821 mutex_unlock(&dev->struct_mutex);
822
823 return cnt;
824}
825
826static int i915_error_state_open(struct inode *inode, struct file *file)
827{
828 struct drm_device *dev = inode->i_private;
829 drm_i915_private_t *dev_priv = dev->dev_private;
830 struct i915_error_state_file_priv *error_priv;
831 unsigned long flags;
832
833 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
834 if (!error_priv)
835 return -ENOMEM;
836
837 error_priv->dev = dev;
838
Daniel Vetter99584db2012-11-14 17:14:04 +0100839 spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
840 error_priv->error = dev_priv->gpu_error.first_error;
Daniel Vetterd5442302012-04-27 15:17:40 +0200841 if (error_priv->error)
842 kref_get(&error_priv->error->ref);
Daniel Vetter99584db2012-11-14 17:14:04 +0100843 spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
Daniel Vetterd5442302012-04-27 15:17:40 +0200844
845 return single_open(file, i915_error_state, error_priv);
846}
847
848static int i915_error_state_release(struct inode *inode, struct file *file)
849{
850 struct seq_file *m = file->private_data;
851 struct i915_error_state_file_priv *error_priv = m->private;
852
853 if (error_priv->error)
854 kref_put(&error_priv->error->ref, i915_error_state_free);
855 kfree(error_priv);
856
857 return single_release(inode, file);
858}
859
860static const struct file_operations i915_error_state_fops = {
861 .owner = THIS_MODULE,
862 .open = i915_error_state_open,
863 .read = seq_read,
864 .write = i915_error_state_write,
865 .llseek = default_llseek,
866 .release = i915_error_state_release,
867};
868
Mika Kuoppala40633212012-12-04 15:12:00 +0200869static ssize_t
870i915_next_seqno_read(struct file *filp,
871 char __user *ubuf,
872 size_t max,
873 loff_t *ppos)
874{
875 struct drm_device *dev = filp->private_data;
876 drm_i915_private_t *dev_priv = dev->dev_private;
877 char buf[80];
878 int len;
879 int ret;
880
881 ret = mutex_lock_interruptible(&dev->struct_mutex);
882 if (ret)
883 return ret;
884
885 len = snprintf(buf, sizeof(buf),
886 "next_seqno : 0x%x\n",
887 dev_priv->next_seqno);
888
889 mutex_unlock(&dev->struct_mutex);
890
891 if (len > sizeof(buf))
892 len = sizeof(buf);
893
894 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
895}
896
897static ssize_t
898i915_next_seqno_write(struct file *filp,
899 const char __user *ubuf,
900 size_t cnt,
901 loff_t *ppos)
902{
903 struct drm_device *dev = filp->private_data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200904 char buf[20];
905 u32 val = 1;
906 int ret;
907
908 if (cnt > 0) {
909 if (cnt > sizeof(buf) - 1)
910 return -EINVAL;
911
912 if (copy_from_user(buf, ubuf, cnt))
913 return -EFAULT;
914 buf[cnt] = 0;
915
916 ret = kstrtouint(buf, 0, &val);
917 if (ret < 0)
918 return ret;
919 }
920
Mika Kuoppala40633212012-12-04 15:12:00 +0200921 ret = mutex_lock_interruptible(&dev->struct_mutex);
922 if (ret)
923 return ret;
924
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200925 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200926
927 mutex_unlock(&dev->struct_mutex);
928
929 return ret ?: cnt;
930}
931
932static const struct file_operations i915_next_seqno_fops = {
933 .owner = THIS_MODULE,
934 .open = simple_open,
935 .read = i915_next_seqno_read,
936 .write = i915_next_seqno_write,
937 .llseek = default_llseek,
938};
939
Jesse Barnesf97108d2010-01-29 11:27:07 -0800940static int i915_rstdby_delays(struct seq_file *m, void *unused)
941{
942 struct drm_info_node *node = (struct drm_info_node *) m->private;
943 struct drm_device *dev = node->minor->dev;
944 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700945 u16 crstanddelay;
946 int ret;
947
948 ret = mutex_lock_interruptible(&dev->struct_mutex);
949 if (ret)
950 return ret;
951
952 crstanddelay = I915_READ16(CRSTANDVID);
953
954 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800955
956 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
957
958 return 0;
959}
960
961static int i915_cur_delayinfo(struct seq_file *m, void *unused)
962{
963 struct drm_info_node *node = (struct drm_info_node *) m->private;
964 struct drm_device *dev = node->minor->dev;
965 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100966 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800967
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800968 if (IS_GEN5(dev)) {
969 u16 rgvswctl = I915_READ16(MEMSWCTL);
970 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
971
972 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
973 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
974 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
975 MEMSTAT_VID_SHIFT);
976 seq_printf(m, "Current P-state: %d\n",
977 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700978 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800979 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
980 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
981 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800982 u32 rpstat, cagf;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800983 u32 rpupei, rpcurup, rpprevup;
984 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800985 int max_freq;
986
987 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100988 ret = mutex_lock_interruptible(&dev->struct_mutex);
989 if (ret)
990 return ret;
991
Ben Widawskyfcca7922011-04-25 11:23:07 -0700992 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800993
Jesse Barnesccab5c82011-01-18 15:49:25 -0800994 rpstat = I915_READ(GEN6_RPSTAT1);
995 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
996 rpcurup = I915_READ(GEN6_RP_CUR_UP);
997 rpprevup = I915_READ(GEN6_RP_PREV_UP);
998 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
999 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1000 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001001 if (IS_HASWELL(dev))
1002 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1003 else
1004 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1005 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001006
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001007 gen6_gt_force_wake_put(dev_priv);
1008 mutex_unlock(&dev->struct_mutex);
1009
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001010 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001011 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001012 seq_printf(m, "Render p-state ratio: %d\n",
1013 (gt_perf_status & 0xff00) >> 8);
1014 seq_printf(m, "Render p-state VID: %d\n",
1015 gt_perf_status & 0xff);
1016 seq_printf(m, "Render p-state limit: %d\n",
1017 rp_state_limits & 0xff);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001018 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001019 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1020 GEN6_CURICONT_MASK);
1021 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1022 GEN6_CURBSYTAVG_MASK);
1023 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1024 GEN6_CURBSYTAVG_MASK);
1025 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1026 GEN6_CURIAVG_MASK);
1027 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1028 GEN6_CURBSYTAVG_MASK);
1029 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1030 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001031
1032 max_freq = (rp_state_cap & 0xff0000) >> 16;
1033 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001034 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001035
1036 max_freq = (rp_state_cap & 0xff00) >> 8;
1037 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001038 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001039
1040 max_freq = rp_state_cap & 0xff;
1041 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001042 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001043 } else {
1044 seq_printf(m, "no P-state info available\n");
1045 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001046
1047 return 0;
1048}
1049
1050static int i915_delayfreq_table(struct seq_file *m, void *unused)
1051{
1052 struct drm_info_node *node = (struct drm_info_node *) m->private;
1053 struct drm_device *dev = node->minor->dev;
1054 drm_i915_private_t *dev_priv = dev->dev_private;
1055 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001056 int ret, i;
1057
1058 ret = mutex_lock_interruptible(&dev->struct_mutex);
1059 if (ret)
1060 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001061
1062 for (i = 0; i < 16; i++) {
1063 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001064 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1065 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001066 }
1067
Ben Widawsky616fdb52011-10-05 11:44:54 -07001068 mutex_unlock(&dev->struct_mutex);
1069
Jesse Barnesf97108d2010-01-29 11:27:07 -08001070 return 0;
1071}
1072
1073static inline int MAP_TO_MV(int map)
1074{
1075 return 1250 - (map * 25);
1076}
1077
1078static int i915_inttoext_table(struct seq_file *m, void *unused)
1079{
1080 struct drm_info_node *node = (struct drm_info_node *) m->private;
1081 struct drm_device *dev = node->minor->dev;
1082 drm_i915_private_t *dev_priv = dev->dev_private;
1083 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001084 int ret, i;
1085
1086 ret = mutex_lock_interruptible(&dev->struct_mutex);
1087 if (ret)
1088 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001089
1090 for (i = 1; i <= 32; i++) {
1091 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1092 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1093 }
1094
Ben Widawsky616fdb52011-10-05 11:44:54 -07001095 mutex_unlock(&dev->struct_mutex);
1096
Jesse Barnesf97108d2010-01-29 11:27:07 -08001097 return 0;
1098}
1099
Ben Widawsky4d855292011-12-12 19:34:16 -08001100static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001101{
1102 struct drm_info_node *node = (struct drm_info_node *) m->private;
1103 struct drm_device *dev = node->minor->dev;
1104 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001105 u32 rgvmodectl, rstdbyctl;
1106 u16 crstandvid;
1107 int ret;
1108
1109 ret = mutex_lock_interruptible(&dev->struct_mutex);
1110 if (ret)
1111 return ret;
1112
1113 rgvmodectl = I915_READ(MEMMODECTL);
1114 rstdbyctl = I915_READ(RSTDBYCTL);
1115 crstandvid = I915_READ16(CRSTANDVID);
1116
1117 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001118
1119 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1120 "yes" : "no");
1121 seq_printf(m, "Boost freq: %d\n",
1122 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1123 MEMMODE_BOOST_FREQ_SHIFT);
1124 seq_printf(m, "HW control enabled: %s\n",
1125 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1126 seq_printf(m, "SW control enabled: %s\n",
1127 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1128 seq_printf(m, "Gated voltage change: %s\n",
1129 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1130 seq_printf(m, "Starting frequency: P%d\n",
1131 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001132 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001133 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001134 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1135 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1136 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1137 seq_printf(m, "Render standby enabled: %s\n",
1138 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001139 seq_printf(m, "Current RS state: ");
1140 switch (rstdbyctl & RSX_STATUS_MASK) {
1141 case RSX_STATUS_ON:
1142 seq_printf(m, "on\n");
1143 break;
1144 case RSX_STATUS_RC1:
1145 seq_printf(m, "RC1\n");
1146 break;
1147 case RSX_STATUS_RC1E:
1148 seq_printf(m, "RC1E\n");
1149 break;
1150 case RSX_STATUS_RS1:
1151 seq_printf(m, "RS1\n");
1152 break;
1153 case RSX_STATUS_RS2:
1154 seq_printf(m, "RS2 (RC6)\n");
1155 break;
1156 case RSX_STATUS_RS3:
1157 seq_printf(m, "RC3 (RC6+)\n");
1158 break;
1159 default:
1160 seq_printf(m, "unknown\n");
1161 break;
1162 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001163
1164 return 0;
1165}
1166
Ben Widawsky4d855292011-12-12 19:34:16 -08001167static int gen6_drpc_info(struct seq_file *m)
1168{
1169
1170 struct drm_info_node *node = (struct drm_info_node *) m->private;
1171 struct drm_device *dev = node->minor->dev;
1172 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001173 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001174 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001175 int count=0, ret;
1176
1177
1178 ret = mutex_lock_interruptible(&dev->struct_mutex);
1179 if (ret)
1180 return ret;
1181
Daniel Vetter93b525d2012-01-25 13:52:43 +01001182 spin_lock_irq(&dev_priv->gt_lock);
1183 forcewake_count = dev_priv->forcewake_count;
1184 spin_unlock_irq(&dev_priv->gt_lock);
1185
1186 if (forcewake_count) {
1187 seq_printf(m, "RC information inaccurate because somebody "
1188 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001189 } else {
1190 /* NB: we cannot use forcewake, else we read the wrong values */
1191 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1192 udelay(10);
1193 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1194 }
1195
1196 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1197 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1198
1199 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1200 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1201 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001202 mutex_lock(&dev_priv->rps.hw_lock);
1203 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1204 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001205
1206 seq_printf(m, "Video Turbo Mode: %s\n",
1207 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1208 seq_printf(m, "HW control enabled: %s\n",
1209 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1210 seq_printf(m, "SW control enabled: %s\n",
1211 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1212 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001213 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001214 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1215 seq_printf(m, "RC6 Enabled: %s\n",
1216 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1217 seq_printf(m, "Deep RC6 Enabled: %s\n",
1218 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1219 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1220 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1221 seq_printf(m, "Current RC state: ");
1222 switch (gt_core_status & GEN6_RCn_MASK) {
1223 case GEN6_RC0:
1224 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1225 seq_printf(m, "Core Power Down\n");
1226 else
1227 seq_printf(m, "on\n");
1228 break;
1229 case GEN6_RC3:
1230 seq_printf(m, "RC3\n");
1231 break;
1232 case GEN6_RC6:
1233 seq_printf(m, "RC6\n");
1234 break;
1235 case GEN6_RC7:
1236 seq_printf(m, "RC7\n");
1237 break;
1238 default:
1239 seq_printf(m, "Unknown\n");
1240 break;
1241 }
1242
1243 seq_printf(m, "Core Power Down: %s\n",
1244 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001245
1246 /* Not exactly sure what this is */
1247 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1248 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1249 seq_printf(m, "RC6 residency since boot: %u\n",
1250 I915_READ(GEN6_GT_GFX_RC6));
1251 seq_printf(m, "RC6+ residency since boot: %u\n",
1252 I915_READ(GEN6_GT_GFX_RC6p));
1253 seq_printf(m, "RC6++ residency since boot: %u\n",
1254 I915_READ(GEN6_GT_GFX_RC6pp));
1255
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001256 seq_printf(m, "RC6 voltage: %dmV\n",
1257 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1258 seq_printf(m, "RC6+ voltage: %dmV\n",
1259 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1260 seq_printf(m, "RC6++ voltage: %dmV\n",
1261 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001262 return 0;
1263}
1264
1265static int i915_drpc_info(struct seq_file *m, void *unused)
1266{
1267 struct drm_info_node *node = (struct drm_info_node *) m->private;
1268 struct drm_device *dev = node->minor->dev;
1269
1270 if (IS_GEN6(dev) || IS_GEN7(dev))
1271 return gen6_drpc_info(m);
1272 else
1273 return ironlake_drpc_info(m);
1274}
1275
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001276static int i915_fbc_status(struct seq_file *m, void *unused)
1277{
1278 struct drm_info_node *node = (struct drm_info_node *) m->private;
1279 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001280 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001281
Adam Jacksonee5382a2010-04-23 11:17:39 -04001282 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001283 seq_printf(m, "FBC unsupported on this chipset\n");
1284 return 0;
1285 }
1286
Adam Jacksonee5382a2010-04-23 11:17:39 -04001287 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001288 seq_printf(m, "FBC enabled\n");
1289 } else {
1290 seq_printf(m, "FBC disabled: ");
1291 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001292 case FBC_NO_OUTPUT:
1293 seq_printf(m, "no outputs");
1294 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001295 case FBC_STOLEN_TOO_SMALL:
1296 seq_printf(m, "not enough stolen memory");
1297 break;
1298 case FBC_UNSUPPORTED_MODE:
1299 seq_printf(m, "mode not supported");
1300 break;
1301 case FBC_MODE_TOO_LARGE:
1302 seq_printf(m, "mode too large");
1303 break;
1304 case FBC_BAD_PLANE:
1305 seq_printf(m, "FBC unsupported on plane");
1306 break;
1307 case FBC_NOT_TILED:
1308 seq_printf(m, "scanout buffer not tiled");
1309 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001310 case FBC_MULTIPLE_PIPES:
1311 seq_printf(m, "multiple pipes are enabled");
1312 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001313 case FBC_MODULE_PARAM:
1314 seq_printf(m, "disabled per module param (default off)");
1315 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001316 default:
1317 seq_printf(m, "unknown reason");
1318 }
1319 seq_printf(m, "\n");
1320 }
1321 return 0;
1322}
1323
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001324static int i915_sr_status(struct seq_file *m, void *unused)
1325{
1326 struct drm_info_node *node = (struct drm_info_node *) m->private;
1327 struct drm_device *dev = node->minor->dev;
1328 drm_i915_private_t *dev_priv = dev->dev_private;
1329 bool sr_enabled = false;
1330
Yuanhan Liu13982612010-12-15 15:42:31 +08001331 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001332 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001333 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001334 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1335 else if (IS_I915GM(dev))
1336 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1337 else if (IS_PINEVIEW(dev))
1338 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1339
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001340 seq_printf(m, "self-refresh: %s\n",
1341 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001342
1343 return 0;
1344}
1345
Jesse Barnes7648fa92010-05-20 14:28:11 -07001346static int i915_emon_status(struct seq_file *m, void *unused)
1347{
1348 struct drm_info_node *node = (struct drm_info_node *) m->private;
1349 struct drm_device *dev = node->minor->dev;
1350 drm_i915_private_t *dev_priv = dev->dev_private;
1351 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001352 int ret;
1353
Chris Wilson582be6b2012-04-30 19:35:02 +01001354 if (!IS_GEN5(dev))
1355 return -ENODEV;
1356
Chris Wilsonde227ef2010-07-03 07:58:38 +01001357 ret = mutex_lock_interruptible(&dev->struct_mutex);
1358 if (ret)
1359 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001360
1361 temp = i915_mch_val(dev_priv);
1362 chipset = i915_chipset_val(dev_priv);
1363 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001364 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001365
1366 seq_printf(m, "GMCH temp: %ld\n", temp);
1367 seq_printf(m, "Chipset power: %ld\n", chipset);
1368 seq_printf(m, "GFX power: %ld\n", gfx);
1369 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1370
1371 return 0;
1372}
1373
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001374static int i915_ring_freq_table(struct seq_file *m, void *unused)
1375{
1376 struct drm_info_node *node = (struct drm_info_node *) m->private;
1377 struct drm_device *dev = node->minor->dev;
1378 drm_i915_private_t *dev_priv = dev->dev_private;
1379 int ret;
1380 int gpu_freq, ia_freq;
1381
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001382 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001383 seq_printf(m, "unsupported on this chipset\n");
1384 return 0;
1385 }
1386
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001387 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001388 if (ret)
1389 return ret;
1390
1391 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1392
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001393 for (gpu_freq = dev_priv->rps.min_delay;
1394 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001395 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001396 ia_freq = gpu_freq;
1397 sandybridge_pcode_read(dev_priv,
1398 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1399 &ia_freq);
Ben Widawskyc8735b02012-09-07 19:43:39 -07001400 seq_printf(m, "%d\t\t%d\n", gpu_freq * GT_FREQUENCY_MULTIPLIER, ia_freq * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001401 }
1402
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001403 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001404
1405 return 0;
1406}
1407
Jesse Barnes7648fa92010-05-20 14:28:11 -07001408static int i915_gfxec(struct seq_file *m, void *unused)
1409{
1410 struct drm_info_node *node = (struct drm_info_node *) m->private;
1411 struct drm_device *dev = node->minor->dev;
1412 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001413 int ret;
1414
1415 ret = mutex_lock_interruptible(&dev->struct_mutex);
1416 if (ret)
1417 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001418
1419 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1420
Ben Widawsky616fdb52011-10-05 11:44:54 -07001421 mutex_unlock(&dev->struct_mutex);
1422
Jesse Barnes7648fa92010-05-20 14:28:11 -07001423 return 0;
1424}
1425
Chris Wilson44834a62010-08-19 16:09:23 +01001426static int i915_opregion(struct seq_file *m, void *unused)
1427{
1428 struct drm_info_node *node = (struct drm_info_node *) m->private;
1429 struct drm_device *dev = node->minor->dev;
1430 drm_i915_private_t *dev_priv = dev->dev_private;
1431 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001432 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001433 int ret;
1434
Daniel Vetter0d38f002012-04-21 22:49:10 +02001435 if (data == NULL)
1436 return -ENOMEM;
1437
Chris Wilson44834a62010-08-19 16:09:23 +01001438 ret = mutex_lock_interruptible(&dev->struct_mutex);
1439 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001440 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001441
Daniel Vetter0d38f002012-04-21 22:49:10 +02001442 if (opregion->header) {
1443 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1444 seq_write(m, data, OPREGION_SIZE);
1445 }
Chris Wilson44834a62010-08-19 16:09:23 +01001446
1447 mutex_unlock(&dev->struct_mutex);
1448
Daniel Vetter0d38f002012-04-21 22:49:10 +02001449out:
1450 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001451 return 0;
1452}
1453
Chris Wilson37811fc2010-08-25 22:45:57 +01001454static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1455{
1456 struct drm_info_node *node = (struct drm_info_node *) m->private;
1457 struct drm_device *dev = node->minor->dev;
1458 drm_i915_private_t *dev_priv = dev->dev_private;
1459 struct intel_fbdev *ifbdev;
1460 struct intel_framebuffer *fb;
1461 int ret;
1462
1463 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1464 if (ret)
1465 return ret;
1466
1467 ifbdev = dev_priv->fbdev;
1468 fb = to_intel_framebuffer(ifbdev->helper.fb);
1469
Daniel Vetter623f9782012-12-11 16:21:38 +01001470 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001471 fb->base.width,
1472 fb->base.height,
1473 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001474 fb->base.bits_per_pixel,
1475 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001476 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001477 seq_printf(m, "\n");
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001478 mutex_unlock(&dev->mode_config.mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001479
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001480 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001481 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1482 if (&fb->base == ifbdev->helper.fb)
1483 continue;
1484
Daniel Vetter623f9782012-12-11 16:21:38 +01001485 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001486 fb->base.width,
1487 fb->base.height,
1488 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001489 fb->base.bits_per_pixel,
1490 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001491 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001492 seq_printf(m, "\n");
1493 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001494 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001495
1496 return 0;
1497}
1498
Ben Widawskye76d3632011-03-19 18:14:29 -07001499static int i915_context_status(struct seq_file *m, void *unused)
1500{
1501 struct drm_info_node *node = (struct drm_info_node *) m->private;
1502 struct drm_device *dev = node->minor->dev;
1503 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskya168c292013-02-14 15:05:12 -08001504 struct intel_ring_buffer *ring;
1505 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001506
1507 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1508 if (ret)
1509 return ret;
1510
Daniel Vetter3e373942012-11-02 19:55:04 +01001511 if (dev_priv->ips.pwrctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001512 seq_printf(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001513 describe_obj(m, dev_priv->ips.pwrctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001514 seq_printf(m, "\n");
1515 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001516
Daniel Vetter3e373942012-11-02 19:55:04 +01001517 if (dev_priv->ips.renderctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001518 seq_printf(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001519 describe_obj(m, dev_priv->ips.renderctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001520 seq_printf(m, "\n");
1521 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001522
Ben Widawskya168c292013-02-14 15:05:12 -08001523 for_each_ring(ring, dev_priv, i) {
1524 if (ring->default_context) {
1525 seq_printf(m, "HW default context %s ring ", ring->name);
1526 describe_obj(m, ring->default_context->obj);
1527 seq_printf(m, "\n");
1528 }
1529 }
1530
Ben Widawskye76d3632011-03-19 18:14:29 -07001531 mutex_unlock(&dev->mode_config.mutex);
1532
1533 return 0;
1534}
1535
Ben Widawsky6d794d42011-04-25 11:25:56 -07001536static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1537{
1538 struct drm_info_node *node = (struct drm_info_node *) m->private;
1539 struct drm_device *dev = node->minor->dev;
1540 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001541 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001542
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001543 spin_lock_irq(&dev_priv->gt_lock);
1544 forcewake_count = dev_priv->forcewake_count;
1545 spin_unlock_irq(&dev_priv->gt_lock);
1546
1547 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001548
1549 return 0;
1550}
1551
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001552static const char *swizzle_string(unsigned swizzle)
1553{
1554 switch(swizzle) {
1555 case I915_BIT_6_SWIZZLE_NONE:
1556 return "none";
1557 case I915_BIT_6_SWIZZLE_9:
1558 return "bit9";
1559 case I915_BIT_6_SWIZZLE_9_10:
1560 return "bit9/bit10";
1561 case I915_BIT_6_SWIZZLE_9_11:
1562 return "bit9/bit11";
1563 case I915_BIT_6_SWIZZLE_9_10_11:
1564 return "bit9/bit10/bit11";
1565 case I915_BIT_6_SWIZZLE_9_17:
1566 return "bit9/bit17";
1567 case I915_BIT_6_SWIZZLE_9_10_17:
1568 return "bit9/bit10/bit17";
1569 case I915_BIT_6_SWIZZLE_UNKNOWN:
1570 return "unkown";
1571 }
1572
1573 return "bug";
1574}
1575
1576static int i915_swizzle_info(struct seq_file *m, void *data)
1577{
1578 struct drm_info_node *node = (struct drm_info_node *) m->private;
1579 struct drm_device *dev = node->minor->dev;
1580 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001581 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001582
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001583 ret = mutex_lock_interruptible(&dev->struct_mutex);
1584 if (ret)
1585 return ret;
1586
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001587 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1588 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1589 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1590 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1591
1592 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1593 seq_printf(m, "DDC = 0x%08x\n",
1594 I915_READ(DCC));
1595 seq_printf(m, "C0DRB3 = 0x%04x\n",
1596 I915_READ16(C0DRB3));
1597 seq_printf(m, "C1DRB3 = 0x%04x\n",
1598 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001599 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1600 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1601 I915_READ(MAD_DIMM_C0));
1602 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1603 I915_READ(MAD_DIMM_C1));
1604 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1605 I915_READ(MAD_DIMM_C2));
1606 seq_printf(m, "TILECTL = 0x%08x\n",
1607 I915_READ(TILECTL));
1608 seq_printf(m, "ARB_MODE = 0x%08x\n",
1609 I915_READ(ARB_MODE));
1610 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1611 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001612 }
1613 mutex_unlock(&dev->struct_mutex);
1614
1615 return 0;
1616}
1617
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001618static int i915_ppgtt_info(struct seq_file *m, void *data)
1619{
1620 struct drm_info_node *node = (struct drm_info_node *) m->private;
1621 struct drm_device *dev = node->minor->dev;
1622 struct drm_i915_private *dev_priv = dev->dev_private;
1623 struct intel_ring_buffer *ring;
1624 int i, ret;
1625
1626
1627 ret = mutex_lock_interruptible(&dev->struct_mutex);
1628 if (ret)
1629 return ret;
1630 if (INTEL_INFO(dev)->gen == 6)
1631 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1632
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001633 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001634 seq_printf(m, "%s\n", ring->name);
1635 if (INTEL_INFO(dev)->gen == 7)
1636 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1637 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1638 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1639 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1640 }
1641 if (dev_priv->mm.aliasing_ppgtt) {
1642 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1643
1644 seq_printf(m, "aliasing PPGTT:\n");
1645 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1646 }
1647 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1648 mutex_unlock(&dev->struct_mutex);
1649
1650 return 0;
1651}
1652
Jesse Barnes57f350b2012-03-28 13:39:25 -07001653static int i915_dpio_info(struct seq_file *m, void *data)
1654{
1655 struct drm_info_node *node = (struct drm_info_node *) m->private;
1656 struct drm_device *dev = node->minor->dev;
1657 struct drm_i915_private *dev_priv = dev->dev_private;
1658 int ret;
1659
1660
1661 if (!IS_VALLEYVIEW(dev)) {
1662 seq_printf(m, "unsupported\n");
1663 return 0;
1664 }
1665
Daniel Vetter09153002012-12-12 14:06:44 +01001666 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001667 if (ret)
1668 return ret;
1669
1670 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1671
1672 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1673 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1674 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1675 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1676
1677 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1678 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1679 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1680 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1681
1682 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1683 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1684 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1685 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1686
1687 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1688 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1689 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1690 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1691
1692 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1693 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1694
Daniel Vetter09153002012-12-12 14:06:44 +01001695 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001696
1697 return 0;
1698}
1699
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001700static ssize_t
1701i915_wedged_read(struct file *filp,
1702 char __user *ubuf,
1703 size_t max,
1704 loff_t *ppos)
1705{
1706 struct drm_device *dev = filp->private_data;
1707 drm_i915_private_t *dev_priv = dev->dev_private;
1708 char buf[80];
1709 int len;
1710
Akshay Joshi0206e352011-08-16 15:34:10 -04001711 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001712 "wedged : %d\n",
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001713 atomic_read(&dev_priv->gpu_error.reset_counter));
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001714
Akshay Joshi0206e352011-08-16 15:34:10 -04001715 if (len > sizeof(buf))
1716 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001717
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001718 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1719}
1720
1721static ssize_t
1722i915_wedged_write(struct file *filp,
1723 const char __user *ubuf,
1724 size_t cnt,
1725 loff_t *ppos)
1726{
1727 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001728 char buf[20];
1729 int val = 1;
1730
1731 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001732 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001733 return -EINVAL;
1734
1735 if (copy_from_user(buf, ubuf, cnt))
1736 return -EFAULT;
1737 buf[cnt] = 0;
1738
1739 val = simple_strtoul(buf, NULL, 0);
1740 }
1741
1742 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001743 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001744
1745 return cnt;
1746}
1747
1748static const struct file_operations i915_wedged_fops = {
1749 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001750 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001751 .read = i915_wedged_read,
1752 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001753 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001754};
1755
Jesse Barnes358733e2011-07-27 11:53:01 -07001756static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001757i915_ring_stop_read(struct file *filp,
1758 char __user *ubuf,
1759 size_t max,
1760 loff_t *ppos)
1761{
1762 struct drm_device *dev = filp->private_data;
1763 drm_i915_private_t *dev_priv = dev->dev_private;
1764 char buf[20];
1765 int len;
1766
1767 len = snprintf(buf, sizeof(buf),
Daniel Vetter99584db2012-11-14 17:14:04 +01001768 "0x%08x\n", dev_priv->gpu_error.stop_rings);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001769
1770 if (len > sizeof(buf))
1771 len = sizeof(buf);
1772
1773 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1774}
1775
1776static ssize_t
1777i915_ring_stop_write(struct file *filp,
1778 const char __user *ubuf,
1779 size_t cnt,
1780 loff_t *ppos)
1781{
1782 struct drm_device *dev = filp->private_data;
1783 struct drm_i915_private *dev_priv = dev->dev_private;
1784 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001785 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001786
1787 if (cnt > 0) {
1788 if (cnt > sizeof(buf) - 1)
1789 return -EINVAL;
1790
1791 if (copy_from_user(buf, ubuf, cnt))
1792 return -EFAULT;
1793 buf[cnt] = 0;
1794
1795 val = simple_strtoul(buf, NULL, 0);
1796 }
1797
1798 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1799
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001800 ret = mutex_lock_interruptible(&dev->struct_mutex);
1801 if (ret)
1802 return ret;
1803
Daniel Vetter99584db2012-11-14 17:14:04 +01001804 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001805 mutex_unlock(&dev->struct_mutex);
1806
1807 return cnt;
1808}
1809
1810static const struct file_operations i915_ring_stop_fops = {
1811 .owner = THIS_MODULE,
1812 .open = simple_open,
1813 .read = i915_ring_stop_read,
1814 .write = i915_ring_stop_write,
1815 .llseek = default_llseek,
1816};
Daniel Vetterd5442302012-04-27 15:17:40 +02001817
Chris Wilsondd624af2013-01-15 12:39:35 +00001818#define DROP_UNBOUND 0x1
1819#define DROP_BOUND 0x2
1820#define DROP_RETIRE 0x4
1821#define DROP_ACTIVE 0x8
1822#define DROP_ALL (DROP_UNBOUND | \
1823 DROP_BOUND | \
1824 DROP_RETIRE | \
1825 DROP_ACTIVE)
1826static ssize_t
1827i915_drop_caches_read(struct file *filp,
1828 char __user *ubuf,
1829 size_t max,
1830 loff_t *ppos)
1831{
1832 char buf[20];
1833 int len;
1834
1835 len = snprintf(buf, sizeof(buf), "0x%08x\n", DROP_ALL);
1836 if (len > sizeof(buf))
1837 len = sizeof(buf);
1838
1839 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1840}
1841
1842static ssize_t
1843i915_drop_caches_write(struct file *filp,
1844 const char __user *ubuf,
1845 size_t cnt,
1846 loff_t *ppos)
1847{
1848 struct drm_device *dev = filp->private_data;
1849 struct drm_i915_private *dev_priv = dev->dev_private;
1850 struct drm_i915_gem_object *obj, *next;
1851 char buf[20];
1852 int val = 0, ret;
1853
1854 if (cnt > 0) {
1855 if (cnt > sizeof(buf) - 1)
1856 return -EINVAL;
1857
1858 if (copy_from_user(buf, ubuf, cnt))
1859 return -EFAULT;
1860 buf[cnt] = 0;
1861
1862 val = simple_strtoul(buf, NULL, 0);
1863 }
1864
1865 DRM_DEBUG_DRIVER("Dropping caches: 0x%08x\n", val);
1866
1867 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1868 * on ioctls on -EAGAIN. */
1869 ret = mutex_lock_interruptible(&dev->struct_mutex);
1870 if (ret)
1871 return ret;
1872
1873 if (val & DROP_ACTIVE) {
1874 ret = i915_gpu_idle(dev);
1875 if (ret)
1876 goto unlock;
1877 }
1878
1879 if (val & (DROP_RETIRE | DROP_ACTIVE))
1880 i915_gem_retire_requests(dev);
1881
1882 if (val & DROP_BOUND) {
1883 list_for_each_entry_safe(obj, next, &dev_priv->mm.inactive_list, mm_list)
1884 if (obj->pin_count == 0) {
1885 ret = i915_gem_object_unbind(obj);
1886 if (ret)
1887 goto unlock;
1888 }
1889 }
1890
1891 if (val & DROP_UNBOUND) {
1892 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list, gtt_list)
1893 if (obj->pages_pin_count == 0) {
1894 ret = i915_gem_object_put_pages(obj);
1895 if (ret)
1896 goto unlock;
1897 }
1898 }
1899
1900unlock:
1901 mutex_unlock(&dev->struct_mutex);
1902
1903 return ret ?: cnt;
1904}
1905
1906static const struct file_operations i915_drop_caches_fops = {
1907 .owner = THIS_MODULE,
1908 .open = simple_open,
1909 .read = i915_drop_caches_read,
1910 .write = i915_drop_caches_write,
1911 .llseek = default_llseek,
1912};
1913
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001914static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001915i915_max_freq_read(struct file *filp,
1916 char __user *ubuf,
1917 size_t max,
1918 loff_t *ppos)
1919{
1920 struct drm_device *dev = filp->private_data;
1921 drm_i915_private_t *dev_priv = dev->dev_private;
1922 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001923 int len, ret;
1924
1925 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1926 return -ENODEV;
1927
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001928 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001929 if (ret)
1930 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001931
Akshay Joshi0206e352011-08-16 15:34:10 -04001932 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001933 "max freq: %d\n", dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001934 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001935
Akshay Joshi0206e352011-08-16 15:34:10 -04001936 if (len > sizeof(buf))
1937 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001938
1939 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1940}
1941
1942static ssize_t
1943i915_max_freq_write(struct file *filp,
1944 const char __user *ubuf,
1945 size_t cnt,
1946 loff_t *ppos)
1947{
1948 struct drm_device *dev = filp->private_data;
1949 struct drm_i915_private *dev_priv = dev->dev_private;
1950 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001951 int val = 1, ret;
1952
1953 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1954 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001955
1956 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001957 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001958 return -EINVAL;
1959
1960 if (copy_from_user(buf, ubuf, cnt))
1961 return -EFAULT;
1962 buf[cnt] = 0;
1963
1964 val = simple_strtoul(buf, NULL, 0);
1965 }
1966
1967 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1968
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001969 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001970 if (ret)
1971 return ret;
1972
Jesse Barnes358733e2011-07-27 11:53:01 -07001973 /*
1974 * Turbo will still be enabled, but won't go above the set value.
1975 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07001976 dev_priv->rps.max_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes358733e2011-07-27 11:53:01 -07001977
Ben Widawskyc8735b02012-09-07 19:43:39 -07001978 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001979 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001980
1981 return cnt;
1982}
1983
1984static const struct file_operations i915_max_freq_fops = {
1985 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001986 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001987 .read = i915_max_freq_read,
1988 .write = i915_max_freq_write,
1989 .llseek = default_llseek,
1990};
1991
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001992static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001993i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1994 loff_t *ppos)
1995{
1996 struct drm_device *dev = filp->private_data;
1997 drm_i915_private_t *dev_priv = dev->dev_private;
1998 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001999 int len, ret;
2000
2001 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2002 return -ENODEV;
2003
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002004 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002005 if (ret)
2006 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07002007
2008 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07002009 "min freq: %d\n", dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002010 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002011
2012 if (len > sizeof(buf))
2013 len = sizeof(buf);
2014
2015 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
2016}
2017
2018static ssize_t
2019i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
2020 loff_t *ppos)
2021{
2022 struct drm_device *dev = filp->private_data;
2023 struct drm_i915_private *dev_priv = dev->dev_private;
2024 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02002025 int val = 1, ret;
2026
2027 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2028 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07002029
2030 if (cnt > 0) {
2031 if (cnt > sizeof(buf) - 1)
2032 return -EINVAL;
2033
2034 if (copy_from_user(buf, ubuf, cnt))
2035 return -EFAULT;
2036 buf[cnt] = 0;
2037
2038 val = simple_strtoul(buf, NULL, 0);
2039 }
2040
2041 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
2042
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002043 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002044 if (ret)
2045 return ret;
2046
Jesse Barnes1523c312012-05-25 12:34:54 -07002047 /*
2048 * Turbo will still be enabled, but won't go below the set value.
2049 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07002050 dev_priv->rps.min_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes1523c312012-05-25 12:34:54 -07002051
Ben Widawskyc8735b02012-09-07 19:43:39 -07002052 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002053 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002054
2055 return cnt;
2056}
2057
2058static const struct file_operations i915_min_freq_fops = {
2059 .owner = THIS_MODULE,
2060 .open = simple_open,
2061 .read = i915_min_freq_read,
2062 .write = i915_min_freq_write,
2063 .llseek = default_llseek,
2064};
2065
2066static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002067i915_cache_sharing_read(struct file *filp,
2068 char __user *ubuf,
2069 size_t max,
2070 loff_t *ppos)
2071{
2072 struct drm_device *dev = filp->private_data;
2073 drm_i915_private_t *dev_priv = dev->dev_private;
2074 char buf[80];
2075 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002076 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002077
Daniel Vetter004777c2012-08-09 15:07:01 +02002078 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2079 return -ENODEV;
2080
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002081 ret = mutex_lock_interruptible(&dev->struct_mutex);
2082 if (ret)
2083 return ret;
2084
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002085 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2086 mutex_unlock(&dev_priv->dev->struct_mutex);
2087
Akshay Joshi0206e352011-08-16 15:34:10 -04002088 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002089 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
2090 GEN6_MBC_SNPCR_SHIFT);
2091
Akshay Joshi0206e352011-08-16 15:34:10 -04002092 if (len > sizeof(buf))
2093 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002094
2095 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
2096}
2097
2098static ssize_t
2099i915_cache_sharing_write(struct file *filp,
2100 const char __user *ubuf,
2101 size_t cnt,
2102 loff_t *ppos)
2103{
2104 struct drm_device *dev = filp->private_data;
2105 struct drm_i915_private *dev_priv = dev->dev_private;
2106 char buf[20];
2107 u32 snpcr;
2108 int val = 1;
2109
Daniel Vetter004777c2012-08-09 15:07:01 +02002110 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2111 return -ENODEV;
2112
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002113 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04002114 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002115 return -EINVAL;
2116
2117 if (copy_from_user(buf, ubuf, cnt))
2118 return -EFAULT;
2119 buf[cnt] = 0;
2120
2121 val = simple_strtoul(buf, NULL, 0);
2122 }
2123
2124 if (val < 0 || val > 3)
2125 return -EINVAL;
2126
2127 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
2128
2129 /* Update the cache sharing policy here as well */
2130 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2131 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2132 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2133 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2134
2135 return cnt;
2136}
2137
2138static const struct file_operations i915_cache_sharing_fops = {
2139 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07002140 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002141 .read = i915_cache_sharing_read,
2142 .write = i915_cache_sharing_write,
2143 .llseek = default_llseek,
2144};
2145
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002146/* As the drm_debugfs_init() routines are called before dev->dev_private is
2147 * allocated we need to hook into the minor for release. */
2148static int
2149drm_add_fake_info_node(struct drm_minor *minor,
2150 struct dentry *ent,
2151 const void *key)
2152{
2153 struct drm_info_node *node;
2154
2155 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
2156 if (node == NULL) {
2157 debugfs_remove(ent);
2158 return -ENOMEM;
2159 }
2160
2161 node->minor = minor;
2162 node->dent = ent;
2163 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002164
2165 mutex_lock(&minor->debugfs_lock);
2166 list_add(&node->list, &minor->debugfs_list);
2167 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002168
2169 return 0;
2170}
2171
Ben Widawsky6d794d42011-04-25 11:25:56 -07002172static int i915_forcewake_open(struct inode *inode, struct file *file)
2173{
2174 struct drm_device *dev = inode->i_private;
2175 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002176
Daniel Vetter075edca2012-01-24 09:44:28 +01002177 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002178 return 0;
2179
Ben Widawsky6d794d42011-04-25 11:25:56 -07002180 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002181
2182 return 0;
2183}
2184
Ben Widawskyc43b5632012-04-16 14:07:40 -07002185static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002186{
2187 struct drm_device *dev = inode->i_private;
2188 struct drm_i915_private *dev_priv = dev->dev_private;
2189
Daniel Vetter075edca2012-01-24 09:44:28 +01002190 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002191 return 0;
2192
Ben Widawsky6d794d42011-04-25 11:25:56 -07002193 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002194
2195 return 0;
2196}
2197
2198static const struct file_operations i915_forcewake_fops = {
2199 .owner = THIS_MODULE,
2200 .open = i915_forcewake_open,
2201 .release = i915_forcewake_release,
2202};
2203
2204static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2205{
2206 struct drm_device *dev = minor->dev;
2207 struct dentry *ent;
2208
2209 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002210 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002211 root, dev,
2212 &i915_forcewake_fops);
2213 if (IS_ERR(ent))
2214 return PTR_ERR(ent);
2215
Ben Widawsky8eb57292011-05-11 15:10:58 -07002216 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002217}
2218
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002219static int i915_debugfs_create(struct dentry *root,
2220 struct drm_minor *minor,
2221 const char *name,
2222 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002223{
2224 struct drm_device *dev = minor->dev;
2225 struct dentry *ent;
2226
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002227 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002228 S_IRUGO | S_IWUSR,
2229 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002230 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002231 if (IS_ERR(ent))
2232 return PTR_ERR(ent);
2233
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002234 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002235}
2236
Ben Gamari27c202a2009-07-01 22:26:52 -04002237static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002238 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002239 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002240 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002241 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002242 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002243 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002244 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002245 {"i915_gem_request", i915_gem_request_info, 0},
2246 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002247 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002248 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002249 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2250 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2251 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002252 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2253 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2254 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2255 {"i915_inttoext_table", i915_inttoext_table, 0},
2256 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002257 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002258 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002259 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002260 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002261 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002262 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002263 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002264 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002265 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002266 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002267 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002268 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002269};
Ben Gamari27c202a2009-07-01 22:26:52 -04002270#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002271
Ben Gamari27c202a2009-07-01 22:26:52 -04002272int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002273{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002274 int ret;
2275
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002276 ret = i915_debugfs_create(minor->debugfs_root, minor,
2277 "i915_wedged",
2278 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002279 if (ret)
2280 return ret;
2281
Ben Widawsky6d794d42011-04-25 11:25:56 -07002282 ret = i915_forcewake_create(minor->debugfs_root, minor);
2283 if (ret)
2284 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002285
2286 ret = i915_debugfs_create(minor->debugfs_root, minor,
2287 "i915_max_freq",
2288 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002289 if (ret)
2290 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002291
2292 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002293 "i915_min_freq",
2294 &i915_min_freq_fops);
2295 if (ret)
2296 return ret;
2297
2298 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002299 "i915_cache_sharing",
2300 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002301 if (ret)
2302 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002303
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002304 ret = i915_debugfs_create(minor->debugfs_root, minor,
2305 "i915_ring_stop",
2306 &i915_ring_stop_fops);
2307 if (ret)
2308 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002309
Daniel Vetterd5442302012-04-27 15:17:40 +02002310 ret = i915_debugfs_create(minor->debugfs_root, minor,
Chris Wilsondd624af2013-01-15 12:39:35 +00002311 "i915_gem_drop_caches",
2312 &i915_drop_caches_fops);
2313 if (ret)
2314 return ret;
2315
2316 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetterd5442302012-04-27 15:17:40 +02002317 "i915_error_state",
2318 &i915_error_state_fops);
2319 if (ret)
2320 return ret;
2321
Mika Kuoppala40633212012-12-04 15:12:00 +02002322 ret = i915_debugfs_create(minor->debugfs_root, minor,
2323 "i915_next_seqno",
2324 &i915_next_seqno_fops);
2325 if (ret)
2326 return ret;
2327
Ben Gamari27c202a2009-07-01 22:26:52 -04002328 return drm_debugfs_create_files(i915_debugfs_list,
2329 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002330 minor->debugfs_root, minor);
2331}
2332
Ben Gamari27c202a2009-07-01 22:26:52 -04002333void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002334{
Ben Gamari27c202a2009-07-01 22:26:52 -04002335 drm_debugfs_remove_files(i915_debugfs_list,
2336 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002337 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2338 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002339 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2340 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002341 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2342 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002343 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2344 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002345 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2346 1, minor);
Chris Wilsondd624af2013-01-15 12:39:35 +00002347 drm_debugfs_remove_files((struct drm_info_list *) &i915_drop_caches_fops,
2348 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002349 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2350 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002351 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2352 1, minor);
Mika Kuoppala40633212012-12-04 15:12:00 +02002353 drm_debugfs_remove_files((struct drm_info_list *) &i915_next_seqno_fops,
2354 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002355}
2356
2357#endif /* CONFIG_DEBUG_FS */