blob: 90a6fc506dd5b2c39d724e0b7f508d991562d531 [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>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010034#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000035#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010036#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050037#include "i915_drv.h"
38
39#define DRM_I915_RING_DEBUG 1
40
41
42#if defined(CONFIG_DEBUG_FS)
43
Chris Wilsonf13d3f72010-09-20 17:36:15 +010044enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010045 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010046 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010047 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010048};
Ben Gamari433e12f2009-02-17 20:08:51 -050049
Chris Wilson70d39fe2010-08-25 16:03:34 +010050static const char *yesno(int v)
51{
52 return v ? "yes" : "no";
53}
54
55static int i915_capabilities(struct seq_file *m, void *data)
56{
57 struct drm_info_node *node = (struct drm_info_node *) m->private;
58 struct drm_device *dev = node->minor->dev;
59 const struct intel_device_info *info = INTEL_INFO(dev);
60
61 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030062 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Daniel Vetterc96ea642012-08-08 22:01:51 +020063#define DEV_INFO_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
64#define DEV_INFO_SEP ;
65 DEV_INFO_FLAGS;
66#undef DEV_INFO_FLAG
67#undef DEV_INFO_SEP
Chris Wilson70d39fe2010-08-25 16:03:34 +010068
69 return 0;
70}
Ben Gamari433e12f2009-02-17 20:08:51 -050071
Chris Wilson05394f32010-11-08 19:18:58 +000072static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000073{
Chris Wilson05394f32010-11-08 19:18:58 +000074 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000075 return "P";
Chris Wilson05394f32010-11-08 19:18:58 +000076 else if (obj->pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000077 return "p";
78 else
79 return " ";
80}
81
Chris Wilson05394f32010-11-08 19:18:58 +000082static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000083{
Akshay Joshi0206e352011-08-16 15:34:10 -040084 switch (obj->tiling_mode) {
85 default:
86 case I915_TILING_NONE: return " ";
87 case I915_TILING_X: return "X";
88 case I915_TILING_Y: return "Y";
89 }
Chris Wilsona6172a82009-02-11 14:26:38 +000090}
91
Chris Wilson93dfb402011-03-29 16:59:50 -070092static const char *cache_level_str(int type)
Chris Wilson08c18322011-01-10 00:00:24 +000093{
94 switch (type) {
Chris Wilson93dfb402011-03-29 16:59:50 -070095 case I915_CACHE_NONE: return " uncached";
96 case I915_CACHE_LLC: return " snooped (LLC)";
97 case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
Chris Wilson08c18322011-01-10 00:00:24 +000098 default: return "";
99 }
100}
101
Chris Wilson37811fc2010-08-25 22:45:57 +0100102static void
103describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
104{
Chris Wilson04b97b32012-11-27 17:06:53 +0000105 seq_printf(m, "%p: %s%s %8zdKiB %02x %02x %d %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100106 &obj->base,
107 get_pin_flag(obj),
108 get_tiling_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800109 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100110 obj->base.read_domains,
111 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100112 obj->last_read_seqno,
113 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000114 obj->last_fenced_seqno,
Chris Wilson93dfb402011-03-29 16:59:50 -0700115 cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100116 obj->dirty ? " dirty" : "",
117 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
118 if (obj->base.name)
119 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilsonc110a6d2012-08-11 15:41:02 +0100120 if (obj->pin_count)
121 seq_printf(m, " (pinned x %d)", obj->pin_count);
Chris Wilson37811fc2010-08-25 22:45:57 +0100122 if (obj->fence_reg != I915_FENCE_REG_NONE)
123 seq_printf(m, " (fence: %d)", obj->fence_reg);
124 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100125 seq_printf(m, " (gtt offset: %08x, size: %08x)",
126 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000127 if (obj->stolen)
128 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000129 if (obj->pin_mappable || obj->fault_mappable) {
130 char s[3], *t = s;
131 if (obj->pin_mappable)
132 *t++ = 'p';
133 if (obj->fault_mappable)
134 *t++ = 'f';
135 *t = '\0';
136 seq_printf(m, " (%s mappable)", s);
137 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100138 if (obj->ring != NULL)
139 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100140}
141
Ben Gamari433e12f2009-02-17 20:08:51 -0500142static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500143{
144 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500145 uintptr_t list = (uintptr_t) node->info_ent->data;
146 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500147 struct drm_device *dev = node->minor->dev;
148 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000149 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100150 size_t total_obj_size, total_gtt_size;
151 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100152
153 ret = mutex_lock_interruptible(&dev->struct_mutex);
154 if (ret)
155 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500156
Ben Gamari433e12f2009-02-17 20:08:51 -0500157 switch (list) {
158 case ACTIVE_LIST:
159 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100160 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500161 break;
162 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400163 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500164 head = &dev_priv->mm.inactive_list;
165 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500166 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100167 mutex_unlock(&dev->struct_mutex);
168 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500169 }
170
Chris Wilson8f2480f2010-09-26 11:44:19 +0100171 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000172 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100173 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000174 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800175 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000176 total_obj_size += obj->base.size;
177 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100178 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500179 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100180 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700181
Chris Wilson8f2480f2010-09-26 11:44:19 +0100182 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
183 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500184 return 0;
185}
186
Chris Wilson6299f992010-11-24 12:23:44 +0000187#define count_objects(list, member) do { \
188 list_for_each_entry(obj, list, member) { \
189 size += obj->gtt_space->size; \
190 ++count; \
191 if (obj->map_and_fenceable) { \
192 mappable_size += obj->gtt_space->size; \
193 ++mappable_count; \
194 } \
195 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400196} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000197
Chris Wilson73aa8082010-09-30 11:46:12 +0100198static int i915_gem_object_info(struct seq_file *m, void* data)
199{
200 struct drm_info_node *node = (struct drm_info_node *) m->private;
201 struct drm_device *dev = node->minor->dev;
202 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200203 u32 count, mappable_count, purgeable_count;
204 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000205 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100206 int ret;
207
208 ret = mutex_lock_interruptible(&dev->struct_mutex);
209 if (ret)
210 return ret;
211
Chris Wilson6299f992010-11-24 12:23:44 +0000212 seq_printf(m, "%u objects, %zu bytes\n",
213 dev_priv->mm.object_count,
214 dev_priv->mm.object_memory);
215
216 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200217 count_objects(&dev_priv->mm.bound_list, gtt_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000218 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
219 count, mappable_count, size, mappable_size);
220
221 size = count = mappable_size = mappable_count = 0;
222 count_objects(&dev_priv->mm.active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000223 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
224 count, mappable_count, size, mappable_size);
225
226 size = count = mappable_size = mappable_count = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000227 count_objects(&dev_priv->mm.inactive_list, mm_list);
228 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
229 count, mappable_count, size, mappable_size);
230
Chris Wilsonb7abb712012-08-20 11:33:30 +0200231 size = count = purgeable_size = purgeable_count = 0;
232 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200233 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200234 if (obj->madv == I915_MADV_DONTNEED)
235 purgeable_size += obj->base.size, ++purgeable_count;
236 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200237 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
238
Chris Wilson6299f992010-11-24 12:23:44 +0000239 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200240 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000241 if (obj->fault_mappable) {
242 size += obj->gtt_space->size;
243 ++count;
244 }
245 if (obj->pin_mappable) {
246 mappable_size += obj->gtt_space->size;
247 ++mappable_count;
248 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200249 if (obj->madv == I915_MADV_DONTNEED) {
250 purgeable_size += obj->base.size;
251 ++purgeable_count;
252 }
Chris Wilson6299f992010-11-24 12:23:44 +0000253 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200254 seq_printf(m, "%u purgeable objects, %zu bytes\n",
255 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000256 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
257 mappable_count, mappable_size);
258 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
259 count, size);
260
Ben Widawsky93d18792013-01-17 12:45:17 -0800261 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky5d4545a2013-01-17 12:45:15 -0800262 dev_priv->gtt.total,
263 dev_priv->gtt.mappable_end - dev_priv->gtt.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100264
265 mutex_unlock(&dev->struct_mutex);
266
267 return 0;
268}
269
Chris Wilson08c18322011-01-10 00:00:24 +0000270static int i915_gem_gtt_info(struct seq_file *m, void* data)
271{
272 struct drm_info_node *node = (struct drm_info_node *) m->private;
273 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100274 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000275 struct drm_i915_private *dev_priv = dev->dev_private;
276 struct drm_i915_gem_object *obj;
277 size_t total_obj_size, total_gtt_size;
278 int count, ret;
279
280 ret = mutex_lock_interruptible(&dev->struct_mutex);
281 if (ret)
282 return ret;
283
284 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200285 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100286 if (list == PINNED_LIST && obj->pin_count == 0)
287 continue;
288
Chris Wilson08c18322011-01-10 00:00:24 +0000289 seq_printf(m, " ");
290 describe_obj(m, obj);
291 seq_printf(m, "\n");
292 total_obj_size += obj->base.size;
293 total_gtt_size += obj->gtt_space->size;
294 count++;
295 }
296
297 mutex_unlock(&dev->struct_mutex);
298
299 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
300 count, total_obj_size, total_gtt_size);
301
302 return 0;
303}
304
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100305static int i915_gem_pageflip_info(struct seq_file *m, void *data)
306{
307 struct drm_info_node *node = (struct drm_info_node *) m->private;
308 struct drm_device *dev = node->minor->dev;
309 unsigned long flags;
310 struct intel_crtc *crtc;
311
312 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800313 const char pipe = pipe_name(crtc->pipe);
314 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100315 struct intel_unpin_work *work;
316
317 spin_lock_irqsave(&dev->event_lock, flags);
318 work = crtc->unpin_work;
319 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800320 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100321 pipe, plane);
322 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000323 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800324 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100325 pipe, plane);
326 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800327 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100328 pipe, plane);
329 }
330 if (work->enable_stall_check)
331 seq_printf(m, "Stall check enabled, ");
332 else
333 seq_printf(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000334 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100335
336 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000337 struct drm_i915_gem_object *obj = work->old_fb_obj;
338 if (obj)
339 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100340 }
341 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000342 struct drm_i915_gem_object *obj = work->pending_flip_obj;
343 if (obj)
344 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100345 }
346 }
347 spin_unlock_irqrestore(&dev->event_lock, flags);
348 }
349
350 return 0;
351}
352
Ben Gamari20172632009-02-17 20:08:50 -0500353static int i915_gem_request_info(struct seq_file *m, void *data)
354{
355 struct drm_info_node *node = (struct drm_info_node *) m->private;
356 struct drm_device *dev = node->minor->dev;
357 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100358 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500359 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100360 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100361
362 ret = mutex_lock_interruptible(&dev->struct_mutex);
363 if (ret)
364 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500365
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100366 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100367 for_each_ring(ring, dev_priv, i) {
368 if (list_empty(&ring->request_list))
369 continue;
370
371 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100372 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100373 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100374 list) {
375 seq_printf(m, " %d @ %d\n",
376 gem_request->seqno,
377 (int) (jiffies - gem_request->emitted_jiffies));
378 }
379 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500380 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100381 mutex_unlock(&dev->struct_mutex);
382
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100383 if (count == 0)
384 seq_printf(m, "No requests\n");
385
Ben Gamari20172632009-02-17 20:08:50 -0500386 return 0;
387}
388
Chris Wilsonb2223492010-10-27 15:27:33 +0100389static void i915_ring_seqno_info(struct seq_file *m,
390 struct intel_ring_buffer *ring)
391{
392 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200393 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100394 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100395 }
396}
397
Ben Gamari20172632009-02-17 20:08:50 -0500398static int i915_gem_seqno_info(struct seq_file *m, void *data)
399{
400 struct drm_info_node *node = (struct drm_info_node *) m->private;
401 struct drm_device *dev = node->minor->dev;
402 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100403 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000404 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100405
406 ret = mutex_lock_interruptible(&dev->struct_mutex);
407 if (ret)
408 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500409
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100410 for_each_ring(ring, dev_priv, i)
411 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100412
413 mutex_unlock(&dev->struct_mutex);
414
Ben Gamari20172632009-02-17 20:08:50 -0500415 return 0;
416}
417
418
419static int i915_interrupt_info(struct seq_file *m, void *data)
420{
421 struct drm_info_node *node = (struct drm_info_node *) m->private;
422 struct drm_device *dev = node->minor->dev;
423 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100424 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800425 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100426
427 ret = mutex_lock_interruptible(&dev->struct_mutex);
428 if (ret)
429 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500430
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700431 if (IS_VALLEYVIEW(dev)) {
432 seq_printf(m, "Display IER:\t%08x\n",
433 I915_READ(VLV_IER));
434 seq_printf(m, "Display IIR:\t%08x\n",
435 I915_READ(VLV_IIR));
436 seq_printf(m, "Display IIR_RW:\t%08x\n",
437 I915_READ(VLV_IIR_RW));
438 seq_printf(m, "Display IMR:\t%08x\n",
439 I915_READ(VLV_IMR));
440 for_each_pipe(pipe)
441 seq_printf(m, "Pipe %c stat:\t%08x\n",
442 pipe_name(pipe),
443 I915_READ(PIPESTAT(pipe)));
444
445 seq_printf(m, "Master IER:\t%08x\n",
446 I915_READ(VLV_MASTER_IER));
447
448 seq_printf(m, "Render IER:\t%08x\n",
449 I915_READ(GTIER));
450 seq_printf(m, "Render IIR:\t%08x\n",
451 I915_READ(GTIIR));
452 seq_printf(m, "Render IMR:\t%08x\n",
453 I915_READ(GTIMR));
454
455 seq_printf(m, "PM IER:\t\t%08x\n",
456 I915_READ(GEN6_PMIER));
457 seq_printf(m, "PM IIR:\t\t%08x\n",
458 I915_READ(GEN6_PMIIR));
459 seq_printf(m, "PM IMR:\t\t%08x\n",
460 I915_READ(GEN6_PMIMR));
461
462 seq_printf(m, "Port hotplug:\t%08x\n",
463 I915_READ(PORT_HOTPLUG_EN));
464 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
465 I915_READ(VLV_DPFLIPSTAT));
466 seq_printf(m, "DPINVGTT:\t%08x\n",
467 I915_READ(DPINVGTT));
468
469 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800470 seq_printf(m, "Interrupt enable: %08x\n",
471 I915_READ(IER));
472 seq_printf(m, "Interrupt identity: %08x\n",
473 I915_READ(IIR));
474 seq_printf(m, "Interrupt mask: %08x\n",
475 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800476 for_each_pipe(pipe)
477 seq_printf(m, "Pipe %c stat: %08x\n",
478 pipe_name(pipe),
479 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800480 } else {
481 seq_printf(m, "North Display Interrupt enable: %08x\n",
482 I915_READ(DEIER));
483 seq_printf(m, "North Display Interrupt identity: %08x\n",
484 I915_READ(DEIIR));
485 seq_printf(m, "North Display Interrupt mask: %08x\n",
486 I915_READ(DEIMR));
487 seq_printf(m, "South Display Interrupt enable: %08x\n",
488 I915_READ(SDEIER));
489 seq_printf(m, "South Display Interrupt identity: %08x\n",
490 I915_READ(SDEIIR));
491 seq_printf(m, "South Display Interrupt mask: %08x\n",
492 I915_READ(SDEIMR));
493 seq_printf(m, "Graphics Interrupt enable: %08x\n",
494 I915_READ(GTIER));
495 seq_printf(m, "Graphics Interrupt identity: %08x\n",
496 I915_READ(GTIIR));
497 seq_printf(m, "Graphics Interrupt mask: %08x\n",
498 I915_READ(GTIMR));
499 }
Ben Gamari20172632009-02-17 20:08:50 -0500500 seq_printf(m, "Interrupts received: %d\n",
501 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100502 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700503 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100504 seq_printf(m,
505 "Graphics Interrupt mask (%s): %08x\n",
506 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000507 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100508 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000509 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100510 mutex_unlock(&dev->struct_mutex);
511
Ben Gamari20172632009-02-17 20:08:50 -0500512 return 0;
513}
514
Chris Wilsona6172a82009-02-11 14:26:38 +0000515static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
516{
517 struct drm_info_node *node = (struct drm_info_node *) m->private;
518 struct drm_device *dev = node->minor->dev;
519 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100520 int i, ret;
521
522 ret = mutex_lock_interruptible(&dev->struct_mutex);
523 if (ret)
524 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000525
526 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
527 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
528 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000529 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000530
Chris Wilson6c085a72012-08-20 11:40:46 +0200531 seq_printf(m, "Fence %d, pin count = %d, object = ",
532 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100533 if (obj == NULL)
534 seq_printf(m, "unused");
535 else
Chris Wilson05394f32010-11-08 19:18:58 +0000536 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100537 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000538 }
539
Chris Wilson05394f32010-11-08 19:18:58 +0000540 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000541 return 0;
542}
543
Ben Gamari20172632009-02-17 20:08:50 -0500544static int i915_hws_info(struct seq_file *m, void *data)
545{
546 struct drm_info_node *node = (struct drm_info_node *) m->private;
547 struct drm_device *dev = node->minor->dev;
548 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100549 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100550 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100551 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500552
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000553 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100554 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500555 if (hws == NULL)
556 return 0;
557
558 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
559 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
560 i * 4,
561 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
562 }
563 return 0;
564}
565
Chris Wilsone5c65262010-11-01 11:35:28 +0000566static const char *ring_str(int ring)
567{
568 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100569 case RCS: return "render";
570 case VCS: return "bsd";
571 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000572 default: return "";
573 }
574}
575
Chris Wilson9df30792010-02-18 10:24:56 +0000576static const char *pin_flag(int pinned)
577{
578 if (pinned > 0)
579 return " P";
580 else if (pinned < 0)
581 return " p";
582 else
583 return "";
584}
585
586static const char *tiling_flag(int tiling)
587{
588 switch (tiling) {
589 default:
590 case I915_TILING_NONE: return "";
591 case I915_TILING_X: return " X";
592 case I915_TILING_Y: return " Y";
593 }
594}
595
596static const char *dirty_flag(int dirty)
597{
598 return dirty ? " dirty" : "";
599}
600
601static const char *purgeable_flag(int purgeable)
602{
603 return purgeable ? " purgeable" : "";
604}
605
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000606static void print_error_buffers(struct seq_file *m,
607 const char *name,
608 struct drm_i915_error_buffer *err,
609 int count)
610{
611 seq_printf(m, "%s [%d]:\n", name, count);
612
613 while (count--) {
Chris Wilson04b97b32012-11-27 17:06:53 +0000614 seq_printf(m, " %08x %8u %02x %02x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000615 err->gtt_offset,
616 err->size,
617 err->read_domains,
618 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100619 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000620 pin_flag(err->pinned),
621 tiling_flag(err->tiling),
622 dirty_flag(err->dirty),
623 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100624 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000625 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700626 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000627
628 if (err->name)
629 seq_printf(m, " (name: %d)", err->name);
630 if (err->fence_reg != I915_FENCE_REG_NONE)
631 seq_printf(m, " (fence: %d)", err->fence_reg);
632
633 seq_printf(m, "\n");
634 err++;
635 }
636}
637
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100638static void i915_ring_error_state(struct seq_file *m,
639 struct drm_device *dev,
640 struct drm_i915_error_state *error,
641 unsigned ring)
642{
Ben Widawskyec34a012012-04-03 23:03:00 -0700643 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100644 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100645 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
646 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100647 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
648 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
649 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
650 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Ben Widawsky050ee912012-08-22 11:32:15 -0700651 if (ring == RCS && INTEL_INFO(dev)->gen >= 4)
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100652 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Ben Widawsky050ee912012-08-22 11:32:15 -0700653
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100654 if (INTEL_INFO(dev)->gen >= 4)
655 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
656 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200657 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100658 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100659 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100660 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Chris Wilsondf2b23d2012-11-27 17:06:54 +0000661 seq_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
662 error->semaphore_mboxes[ring][0],
663 error->semaphore_seqno[ring][0]);
664 seq_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
665 error->semaphore_mboxes[ring][1],
666 error->semaphore_seqno[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100667 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100668 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Ben Widawsky9574b3f2012-04-26 16:03:01 -0700669 seq_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100670 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
671 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100672}
673
Daniel Vetterd5442302012-04-27 15:17:40 +0200674struct i915_error_state_file_priv {
675 struct drm_device *dev;
676 struct drm_i915_error_state *error;
677};
678
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700679static int i915_error_state(struct seq_file *m, void *unused)
680{
Daniel Vetterd5442302012-04-27 15:17:40 +0200681 struct i915_error_state_file_priv *error_priv = m->private;
682 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700683 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200684 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100685 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000686 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700687
Daniel Vetter742cbee2012-04-27 15:17:39 +0200688 if (!error) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700689 seq_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200690 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700691 }
692
Jesse Barnes8a905232009-07-11 16:48:03 -0400693 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
694 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000695 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100696 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700697 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100698 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700699 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000700
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100701 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100702 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
703
Ben Widawsky050ee912012-08-22 11:32:15 -0700704 for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
705 seq_printf(m, " INSTDONE_%d: 0x%08x\n", i, error->extra_instdone[i]);
706
Daniel Vetter33f3f512011-12-14 13:57:39 +0100707 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100708 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100709 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
710 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100711
Ben Widawsky71e172e2012-08-20 16:15:13 -0700712 if (INTEL_INFO(dev)->gen == 7)
713 seq_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
714
Chris Wilsonb4519512012-05-11 14:29:30 +0100715 for_each_ring(ring, dev_priv, i)
716 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100717
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000718 if (error->active_bo)
719 print_error_buffers(m, "Active",
720 error->active_bo,
721 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000722
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000723 if (error->pinned_bo)
724 print_error_buffers(m, "Pinned",
725 error->pinned_bo,
726 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000727
Chris Wilson52d39a22012-02-15 11:25:37 +0000728 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
729 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000730
Chris Wilson52d39a22012-02-15 11:25:37 +0000731 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000732 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
733 dev_priv->ring[i].name,
734 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000735 offset = 0;
736 for (page = 0; page < obj->page_count; page++) {
737 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
738 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
739 offset += 4;
740 }
741 }
742 }
Chris Wilson9df30792010-02-18 10:24:56 +0000743
Chris Wilson52d39a22012-02-15 11:25:37 +0000744 if (error->ring[i].num_requests) {
745 seq_printf(m, "%s --- %d requests\n",
746 dev_priv->ring[i].name,
747 error->ring[i].num_requests);
748 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000749 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000750 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000751 error->ring[i].requests[j].jiffies,
752 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000753 }
754 }
755
756 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000757 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
758 dev_priv->ring[i].name,
759 obj->gtt_offset);
760 offset = 0;
761 for (page = 0; page < obj->page_count; page++) {
762 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
763 seq_printf(m, "%08x : %08x\n",
764 offset,
765 obj->pages[page][elt]);
766 offset += 4;
767 }
Chris Wilson9df30792010-02-18 10:24:56 +0000768 }
769 }
770 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700771
Chris Wilson6ef3d422010-08-04 20:26:07 +0100772 if (error->overlay)
773 intel_overlay_print_error_state(m, error->overlay);
774
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000775 if (error->display)
776 intel_display_print_error_state(m, dev, error->display);
777
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700778 return 0;
779}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700780
Daniel Vetterd5442302012-04-27 15:17:40 +0200781static ssize_t
782i915_error_state_write(struct file *filp,
783 const char __user *ubuf,
784 size_t cnt,
785 loff_t *ppos)
786{
787 struct seq_file *m = filp->private_data;
788 struct i915_error_state_file_priv *error_priv = m->private;
789 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200790 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200791
792 DRM_DEBUG_DRIVER("Resetting error state\n");
793
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200794 ret = mutex_lock_interruptible(&dev->struct_mutex);
795 if (ret)
796 return ret;
797
Daniel Vetterd5442302012-04-27 15:17:40 +0200798 i915_destroy_error_state(dev);
799 mutex_unlock(&dev->struct_mutex);
800
801 return cnt;
802}
803
804static int i915_error_state_open(struct inode *inode, struct file *file)
805{
806 struct drm_device *dev = inode->i_private;
807 drm_i915_private_t *dev_priv = dev->dev_private;
808 struct i915_error_state_file_priv *error_priv;
809 unsigned long flags;
810
811 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
812 if (!error_priv)
813 return -ENOMEM;
814
815 error_priv->dev = dev;
816
817 spin_lock_irqsave(&dev_priv->error_lock, flags);
818 error_priv->error = dev_priv->first_error;
819 if (error_priv->error)
820 kref_get(&error_priv->error->ref);
821 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
822
823 return single_open(file, i915_error_state, error_priv);
824}
825
826static int i915_error_state_release(struct inode *inode, struct file *file)
827{
828 struct seq_file *m = file->private_data;
829 struct i915_error_state_file_priv *error_priv = m->private;
830
831 if (error_priv->error)
832 kref_put(&error_priv->error->ref, i915_error_state_free);
833 kfree(error_priv);
834
835 return single_release(inode, file);
836}
837
838static const struct file_operations i915_error_state_fops = {
839 .owner = THIS_MODULE,
840 .open = i915_error_state_open,
841 .read = seq_read,
842 .write = i915_error_state_write,
843 .llseek = default_llseek,
844 .release = i915_error_state_release,
845};
846
Mika Kuoppala40633212012-12-04 15:12:00 +0200847static ssize_t
848i915_next_seqno_read(struct file *filp,
849 char __user *ubuf,
850 size_t max,
851 loff_t *ppos)
852{
853 struct drm_device *dev = filp->private_data;
854 drm_i915_private_t *dev_priv = dev->dev_private;
855 char buf[80];
856 int len;
857 int ret;
858
859 ret = mutex_lock_interruptible(&dev->struct_mutex);
860 if (ret)
861 return ret;
862
863 len = snprintf(buf, sizeof(buf),
864 "next_seqno : 0x%x\n",
865 dev_priv->next_seqno);
866
867 mutex_unlock(&dev->struct_mutex);
868
869 if (len > sizeof(buf))
870 len = sizeof(buf);
871
872 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
873}
874
875static ssize_t
876i915_next_seqno_write(struct file *filp,
877 const char __user *ubuf,
878 size_t cnt,
879 loff_t *ppos)
880{
881 struct drm_device *dev = filp->private_data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200882 char buf[20];
883 u32 val = 1;
884 int ret;
885
886 if (cnt > 0) {
887 if (cnt > sizeof(buf) - 1)
888 return -EINVAL;
889
890 if (copy_from_user(buf, ubuf, cnt))
891 return -EFAULT;
892 buf[cnt] = 0;
893
894 ret = kstrtouint(buf, 0, &val);
895 if (ret < 0)
896 return ret;
897 }
898
Mika Kuoppala40633212012-12-04 15:12:00 +0200899 ret = mutex_lock_interruptible(&dev->struct_mutex);
900 if (ret)
901 return ret;
902
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200903 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200904
905 mutex_unlock(&dev->struct_mutex);
906
907 return ret ?: cnt;
908}
909
910static const struct file_operations i915_next_seqno_fops = {
911 .owner = THIS_MODULE,
912 .open = simple_open,
913 .read = i915_next_seqno_read,
914 .write = i915_next_seqno_write,
915 .llseek = default_llseek,
916};
917
Jesse Barnesf97108d2010-01-29 11:27:07 -0800918static int i915_rstdby_delays(struct seq_file *m, void *unused)
919{
920 struct drm_info_node *node = (struct drm_info_node *) m->private;
921 struct drm_device *dev = node->minor->dev;
922 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700923 u16 crstanddelay;
924 int ret;
925
926 ret = mutex_lock_interruptible(&dev->struct_mutex);
927 if (ret)
928 return ret;
929
930 crstanddelay = I915_READ16(CRSTANDVID);
931
932 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800933
934 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
935
936 return 0;
937}
938
939static int i915_cur_delayinfo(struct seq_file *m, void *unused)
940{
941 struct drm_info_node *node = (struct drm_info_node *) m->private;
942 struct drm_device *dev = node->minor->dev;
943 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100944 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800945
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800946 if (IS_GEN5(dev)) {
947 u16 rgvswctl = I915_READ16(MEMSWCTL);
948 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
949
950 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
951 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
952 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
953 MEMSTAT_VID_SHIFT);
954 seq_printf(m, "Current P-state: %d\n",
955 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700956 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800957 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
958 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
959 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800960 u32 rpstat;
961 u32 rpupei, rpcurup, rpprevup;
962 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800963 int max_freq;
964
965 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100966 ret = mutex_lock_interruptible(&dev->struct_mutex);
967 if (ret)
968 return ret;
969
Ben Widawskyfcca7922011-04-25 11:23:07 -0700970 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800971
Jesse Barnesccab5c82011-01-18 15:49:25 -0800972 rpstat = I915_READ(GEN6_RPSTAT1);
973 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
974 rpcurup = I915_READ(GEN6_RP_CUR_UP);
975 rpprevup = I915_READ(GEN6_RP_PREV_UP);
976 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
977 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
978 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
979
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100980 gen6_gt_force_wake_put(dev_priv);
981 mutex_unlock(&dev->struct_mutex);
982
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800983 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800984 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800985 seq_printf(m, "Render p-state ratio: %d\n",
986 (gt_perf_status & 0xff00) >> 8);
987 seq_printf(m, "Render p-state VID: %d\n",
988 gt_perf_status & 0xff);
989 seq_printf(m, "Render p-state limit: %d\n",
990 rp_state_limits & 0xff);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800991 seq_printf(m, "CAGF: %dMHz\n", ((rpstat & GEN6_CAGF_MASK) >>
Ben Widawskyc8735b02012-09-07 19:43:39 -0700992 GEN6_CAGF_SHIFT) * GT_FREQUENCY_MULTIPLIER);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800993 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
994 GEN6_CURICONT_MASK);
995 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
996 GEN6_CURBSYTAVG_MASK);
997 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
998 GEN6_CURBSYTAVG_MASK);
999 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1000 GEN6_CURIAVG_MASK);
1001 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1002 GEN6_CURBSYTAVG_MASK);
1003 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1004 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001005
1006 max_freq = (rp_state_cap & 0xff0000) >> 16;
1007 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001008 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001009
1010 max_freq = (rp_state_cap & 0xff00) >> 8;
1011 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001012 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001013
1014 max_freq = rp_state_cap & 0xff;
1015 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001016 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001017 } else {
1018 seq_printf(m, "no P-state info available\n");
1019 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001020
1021 return 0;
1022}
1023
1024static int i915_delayfreq_table(struct seq_file *m, void *unused)
1025{
1026 struct drm_info_node *node = (struct drm_info_node *) m->private;
1027 struct drm_device *dev = node->minor->dev;
1028 drm_i915_private_t *dev_priv = dev->dev_private;
1029 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001030 int ret, i;
1031
1032 ret = mutex_lock_interruptible(&dev->struct_mutex);
1033 if (ret)
1034 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001035
1036 for (i = 0; i < 16; i++) {
1037 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001038 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1039 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001040 }
1041
Ben Widawsky616fdb52011-10-05 11:44:54 -07001042 mutex_unlock(&dev->struct_mutex);
1043
Jesse Barnesf97108d2010-01-29 11:27:07 -08001044 return 0;
1045}
1046
1047static inline int MAP_TO_MV(int map)
1048{
1049 return 1250 - (map * 25);
1050}
1051
1052static int i915_inttoext_table(struct seq_file *m, void *unused)
1053{
1054 struct drm_info_node *node = (struct drm_info_node *) m->private;
1055 struct drm_device *dev = node->minor->dev;
1056 drm_i915_private_t *dev_priv = dev->dev_private;
1057 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001058 int ret, i;
1059
1060 ret = mutex_lock_interruptible(&dev->struct_mutex);
1061 if (ret)
1062 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001063
1064 for (i = 1; i <= 32; i++) {
1065 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1066 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1067 }
1068
Ben Widawsky616fdb52011-10-05 11:44:54 -07001069 mutex_unlock(&dev->struct_mutex);
1070
Jesse Barnesf97108d2010-01-29 11:27:07 -08001071 return 0;
1072}
1073
Ben Widawsky4d855292011-12-12 19:34:16 -08001074static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001075{
1076 struct drm_info_node *node = (struct drm_info_node *) m->private;
1077 struct drm_device *dev = node->minor->dev;
1078 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001079 u32 rgvmodectl, rstdbyctl;
1080 u16 crstandvid;
1081 int ret;
1082
1083 ret = mutex_lock_interruptible(&dev->struct_mutex);
1084 if (ret)
1085 return ret;
1086
1087 rgvmodectl = I915_READ(MEMMODECTL);
1088 rstdbyctl = I915_READ(RSTDBYCTL);
1089 crstandvid = I915_READ16(CRSTANDVID);
1090
1091 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001092
1093 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1094 "yes" : "no");
1095 seq_printf(m, "Boost freq: %d\n",
1096 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1097 MEMMODE_BOOST_FREQ_SHIFT);
1098 seq_printf(m, "HW control enabled: %s\n",
1099 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1100 seq_printf(m, "SW control enabled: %s\n",
1101 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1102 seq_printf(m, "Gated voltage change: %s\n",
1103 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1104 seq_printf(m, "Starting frequency: P%d\n",
1105 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001106 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001107 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001108 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1109 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1110 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1111 seq_printf(m, "Render standby enabled: %s\n",
1112 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001113 seq_printf(m, "Current RS state: ");
1114 switch (rstdbyctl & RSX_STATUS_MASK) {
1115 case RSX_STATUS_ON:
1116 seq_printf(m, "on\n");
1117 break;
1118 case RSX_STATUS_RC1:
1119 seq_printf(m, "RC1\n");
1120 break;
1121 case RSX_STATUS_RC1E:
1122 seq_printf(m, "RC1E\n");
1123 break;
1124 case RSX_STATUS_RS1:
1125 seq_printf(m, "RS1\n");
1126 break;
1127 case RSX_STATUS_RS2:
1128 seq_printf(m, "RS2 (RC6)\n");
1129 break;
1130 case RSX_STATUS_RS3:
1131 seq_printf(m, "RC3 (RC6+)\n");
1132 break;
1133 default:
1134 seq_printf(m, "unknown\n");
1135 break;
1136 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001137
1138 return 0;
1139}
1140
Ben Widawsky4d855292011-12-12 19:34:16 -08001141static int gen6_drpc_info(struct seq_file *m)
1142{
1143
1144 struct drm_info_node *node = (struct drm_info_node *) m->private;
1145 struct drm_device *dev = node->minor->dev;
1146 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001147 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001148 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001149 int count=0, ret;
1150
1151
1152 ret = mutex_lock_interruptible(&dev->struct_mutex);
1153 if (ret)
1154 return ret;
1155
Daniel Vetter93b525d2012-01-25 13:52:43 +01001156 spin_lock_irq(&dev_priv->gt_lock);
1157 forcewake_count = dev_priv->forcewake_count;
1158 spin_unlock_irq(&dev_priv->gt_lock);
1159
1160 if (forcewake_count) {
1161 seq_printf(m, "RC information inaccurate because somebody "
1162 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001163 } else {
1164 /* NB: we cannot use forcewake, else we read the wrong values */
1165 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1166 udelay(10);
1167 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1168 }
1169
1170 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1171 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1172
1173 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1174 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1175 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001176 mutex_lock(&dev_priv->rps.hw_lock);
1177 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1178 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001179
1180 seq_printf(m, "Video Turbo Mode: %s\n",
1181 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1182 seq_printf(m, "HW control enabled: %s\n",
1183 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1184 seq_printf(m, "SW control enabled: %s\n",
1185 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1186 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001187 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001188 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1189 seq_printf(m, "RC6 Enabled: %s\n",
1190 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1191 seq_printf(m, "Deep RC6 Enabled: %s\n",
1192 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1193 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1194 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1195 seq_printf(m, "Current RC state: ");
1196 switch (gt_core_status & GEN6_RCn_MASK) {
1197 case GEN6_RC0:
1198 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1199 seq_printf(m, "Core Power Down\n");
1200 else
1201 seq_printf(m, "on\n");
1202 break;
1203 case GEN6_RC3:
1204 seq_printf(m, "RC3\n");
1205 break;
1206 case GEN6_RC6:
1207 seq_printf(m, "RC6\n");
1208 break;
1209 case GEN6_RC7:
1210 seq_printf(m, "RC7\n");
1211 break;
1212 default:
1213 seq_printf(m, "Unknown\n");
1214 break;
1215 }
1216
1217 seq_printf(m, "Core Power Down: %s\n",
1218 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001219
1220 /* Not exactly sure what this is */
1221 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1222 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1223 seq_printf(m, "RC6 residency since boot: %u\n",
1224 I915_READ(GEN6_GT_GFX_RC6));
1225 seq_printf(m, "RC6+ residency since boot: %u\n",
1226 I915_READ(GEN6_GT_GFX_RC6p));
1227 seq_printf(m, "RC6++ residency since boot: %u\n",
1228 I915_READ(GEN6_GT_GFX_RC6pp));
1229
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001230 seq_printf(m, "RC6 voltage: %dmV\n",
1231 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1232 seq_printf(m, "RC6+ voltage: %dmV\n",
1233 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1234 seq_printf(m, "RC6++ voltage: %dmV\n",
1235 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001236 return 0;
1237}
1238
1239static int i915_drpc_info(struct seq_file *m, void *unused)
1240{
1241 struct drm_info_node *node = (struct drm_info_node *) m->private;
1242 struct drm_device *dev = node->minor->dev;
1243
1244 if (IS_GEN6(dev) || IS_GEN7(dev))
1245 return gen6_drpc_info(m);
1246 else
1247 return ironlake_drpc_info(m);
1248}
1249
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001250static int i915_fbc_status(struct seq_file *m, void *unused)
1251{
1252 struct drm_info_node *node = (struct drm_info_node *) m->private;
1253 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001254 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001255
Adam Jacksonee5382a2010-04-23 11:17:39 -04001256 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001257 seq_printf(m, "FBC unsupported on this chipset\n");
1258 return 0;
1259 }
1260
Adam Jacksonee5382a2010-04-23 11:17:39 -04001261 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001262 seq_printf(m, "FBC enabled\n");
1263 } else {
1264 seq_printf(m, "FBC disabled: ");
1265 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001266 case FBC_NO_OUTPUT:
1267 seq_printf(m, "no outputs");
1268 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001269 case FBC_STOLEN_TOO_SMALL:
1270 seq_printf(m, "not enough stolen memory");
1271 break;
1272 case FBC_UNSUPPORTED_MODE:
1273 seq_printf(m, "mode not supported");
1274 break;
1275 case FBC_MODE_TOO_LARGE:
1276 seq_printf(m, "mode too large");
1277 break;
1278 case FBC_BAD_PLANE:
1279 seq_printf(m, "FBC unsupported on plane");
1280 break;
1281 case FBC_NOT_TILED:
1282 seq_printf(m, "scanout buffer not tiled");
1283 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001284 case FBC_MULTIPLE_PIPES:
1285 seq_printf(m, "multiple pipes are enabled");
1286 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001287 case FBC_MODULE_PARAM:
1288 seq_printf(m, "disabled per module param (default off)");
1289 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001290 default:
1291 seq_printf(m, "unknown reason");
1292 }
1293 seq_printf(m, "\n");
1294 }
1295 return 0;
1296}
1297
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001298static int i915_sr_status(struct seq_file *m, void *unused)
1299{
1300 struct drm_info_node *node = (struct drm_info_node *) m->private;
1301 struct drm_device *dev = node->minor->dev;
1302 drm_i915_private_t *dev_priv = dev->dev_private;
1303 bool sr_enabled = false;
1304
Yuanhan Liu13982612010-12-15 15:42:31 +08001305 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001306 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001307 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001308 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1309 else if (IS_I915GM(dev))
1310 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1311 else if (IS_PINEVIEW(dev))
1312 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1313
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001314 seq_printf(m, "self-refresh: %s\n",
1315 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001316
1317 return 0;
1318}
1319
Jesse Barnes7648fa92010-05-20 14:28:11 -07001320static int i915_emon_status(struct seq_file *m, void *unused)
1321{
1322 struct drm_info_node *node = (struct drm_info_node *) m->private;
1323 struct drm_device *dev = node->minor->dev;
1324 drm_i915_private_t *dev_priv = dev->dev_private;
1325 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001326 int ret;
1327
Chris Wilson582be6b2012-04-30 19:35:02 +01001328 if (!IS_GEN5(dev))
1329 return -ENODEV;
1330
Chris Wilsonde227ef2010-07-03 07:58:38 +01001331 ret = mutex_lock_interruptible(&dev->struct_mutex);
1332 if (ret)
1333 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001334
1335 temp = i915_mch_val(dev_priv);
1336 chipset = i915_chipset_val(dev_priv);
1337 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001338 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001339
1340 seq_printf(m, "GMCH temp: %ld\n", temp);
1341 seq_printf(m, "Chipset power: %ld\n", chipset);
1342 seq_printf(m, "GFX power: %ld\n", gfx);
1343 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1344
1345 return 0;
1346}
1347
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001348static int i915_ring_freq_table(struct seq_file *m, void *unused)
1349{
1350 struct drm_info_node *node = (struct drm_info_node *) m->private;
1351 struct drm_device *dev = node->minor->dev;
1352 drm_i915_private_t *dev_priv = dev->dev_private;
1353 int ret;
1354 int gpu_freq, ia_freq;
1355
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001356 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001357 seq_printf(m, "unsupported on this chipset\n");
1358 return 0;
1359 }
1360
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001361 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001362 if (ret)
1363 return ret;
1364
1365 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1366
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001367 for (gpu_freq = dev_priv->rps.min_delay;
1368 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001369 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001370 ia_freq = gpu_freq;
1371 sandybridge_pcode_read(dev_priv,
1372 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1373 &ia_freq);
Ben Widawskyc8735b02012-09-07 19:43:39 -07001374 seq_printf(m, "%d\t\t%d\n", gpu_freq * GT_FREQUENCY_MULTIPLIER, ia_freq * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001375 }
1376
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001377 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001378
1379 return 0;
1380}
1381
Jesse Barnes7648fa92010-05-20 14:28:11 -07001382static int i915_gfxec(struct seq_file *m, void *unused)
1383{
1384 struct drm_info_node *node = (struct drm_info_node *) m->private;
1385 struct drm_device *dev = node->minor->dev;
1386 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001387 int ret;
1388
1389 ret = mutex_lock_interruptible(&dev->struct_mutex);
1390 if (ret)
1391 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001392
1393 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1394
Ben Widawsky616fdb52011-10-05 11:44:54 -07001395 mutex_unlock(&dev->struct_mutex);
1396
Jesse Barnes7648fa92010-05-20 14:28:11 -07001397 return 0;
1398}
1399
Chris Wilson44834a62010-08-19 16:09:23 +01001400static int i915_opregion(struct seq_file *m, void *unused)
1401{
1402 struct drm_info_node *node = (struct drm_info_node *) m->private;
1403 struct drm_device *dev = node->minor->dev;
1404 drm_i915_private_t *dev_priv = dev->dev_private;
1405 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001406 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001407 int ret;
1408
Daniel Vetter0d38f002012-04-21 22:49:10 +02001409 if (data == NULL)
1410 return -ENOMEM;
1411
Chris Wilson44834a62010-08-19 16:09:23 +01001412 ret = mutex_lock_interruptible(&dev->struct_mutex);
1413 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001414 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001415
Daniel Vetter0d38f002012-04-21 22:49:10 +02001416 if (opregion->header) {
1417 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1418 seq_write(m, data, OPREGION_SIZE);
1419 }
Chris Wilson44834a62010-08-19 16:09:23 +01001420
1421 mutex_unlock(&dev->struct_mutex);
1422
Daniel Vetter0d38f002012-04-21 22:49:10 +02001423out:
1424 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001425 return 0;
1426}
1427
Chris Wilson37811fc2010-08-25 22:45:57 +01001428static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1429{
1430 struct drm_info_node *node = (struct drm_info_node *) m->private;
1431 struct drm_device *dev = node->minor->dev;
1432 drm_i915_private_t *dev_priv = dev->dev_private;
1433 struct intel_fbdev *ifbdev;
1434 struct intel_framebuffer *fb;
1435 int ret;
1436
1437 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1438 if (ret)
1439 return ret;
1440
1441 ifbdev = dev_priv->fbdev;
1442 fb = to_intel_framebuffer(ifbdev->helper.fb);
1443
1444 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1445 fb->base.width,
1446 fb->base.height,
1447 fb->base.depth,
1448 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001449 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001450 seq_printf(m, "\n");
1451
1452 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1453 if (&fb->base == ifbdev->helper.fb)
1454 continue;
1455
1456 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1457 fb->base.width,
1458 fb->base.height,
1459 fb->base.depth,
1460 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001461 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001462 seq_printf(m, "\n");
1463 }
1464
1465 mutex_unlock(&dev->mode_config.mutex);
1466
1467 return 0;
1468}
1469
Ben Widawskye76d3632011-03-19 18:14:29 -07001470static int i915_context_status(struct seq_file *m, void *unused)
1471{
1472 struct drm_info_node *node = (struct drm_info_node *) m->private;
1473 struct drm_device *dev = node->minor->dev;
1474 drm_i915_private_t *dev_priv = dev->dev_private;
1475 int ret;
1476
1477 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1478 if (ret)
1479 return ret;
1480
Daniel Vetter3e373942012-11-02 19:55:04 +01001481 if (dev_priv->ips.pwrctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001482 seq_printf(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001483 describe_obj(m, dev_priv->ips.pwrctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001484 seq_printf(m, "\n");
1485 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001486
Daniel Vetter3e373942012-11-02 19:55:04 +01001487 if (dev_priv->ips.renderctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001488 seq_printf(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001489 describe_obj(m, dev_priv->ips.renderctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001490 seq_printf(m, "\n");
1491 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001492
1493 mutex_unlock(&dev->mode_config.mutex);
1494
1495 return 0;
1496}
1497
Ben Widawsky6d794d42011-04-25 11:25:56 -07001498static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1499{
1500 struct drm_info_node *node = (struct drm_info_node *) m->private;
1501 struct drm_device *dev = node->minor->dev;
1502 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001503 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001504
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001505 spin_lock_irq(&dev_priv->gt_lock);
1506 forcewake_count = dev_priv->forcewake_count;
1507 spin_unlock_irq(&dev_priv->gt_lock);
1508
1509 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001510
1511 return 0;
1512}
1513
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001514static const char *swizzle_string(unsigned swizzle)
1515{
1516 switch(swizzle) {
1517 case I915_BIT_6_SWIZZLE_NONE:
1518 return "none";
1519 case I915_BIT_6_SWIZZLE_9:
1520 return "bit9";
1521 case I915_BIT_6_SWIZZLE_9_10:
1522 return "bit9/bit10";
1523 case I915_BIT_6_SWIZZLE_9_11:
1524 return "bit9/bit11";
1525 case I915_BIT_6_SWIZZLE_9_10_11:
1526 return "bit9/bit10/bit11";
1527 case I915_BIT_6_SWIZZLE_9_17:
1528 return "bit9/bit17";
1529 case I915_BIT_6_SWIZZLE_9_10_17:
1530 return "bit9/bit10/bit17";
1531 case I915_BIT_6_SWIZZLE_UNKNOWN:
1532 return "unkown";
1533 }
1534
1535 return "bug";
1536}
1537
1538static int i915_swizzle_info(struct seq_file *m, void *data)
1539{
1540 struct drm_info_node *node = (struct drm_info_node *) m->private;
1541 struct drm_device *dev = node->minor->dev;
1542 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001543 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001544
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001545 ret = mutex_lock_interruptible(&dev->struct_mutex);
1546 if (ret)
1547 return ret;
1548
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001549 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1550 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1551 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1552 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1553
1554 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1555 seq_printf(m, "DDC = 0x%08x\n",
1556 I915_READ(DCC));
1557 seq_printf(m, "C0DRB3 = 0x%04x\n",
1558 I915_READ16(C0DRB3));
1559 seq_printf(m, "C1DRB3 = 0x%04x\n",
1560 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001561 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1562 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1563 I915_READ(MAD_DIMM_C0));
1564 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1565 I915_READ(MAD_DIMM_C1));
1566 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1567 I915_READ(MAD_DIMM_C2));
1568 seq_printf(m, "TILECTL = 0x%08x\n",
1569 I915_READ(TILECTL));
1570 seq_printf(m, "ARB_MODE = 0x%08x\n",
1571 I915_READ(ARB_MODE));
1572 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1573 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001574 }
1575 mutex_unlock(&dev->struct_mutex);
1576
1577 return 0;
1578}
1579
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001580static int i915_ppgtt_info(struct seq_file *m, void *data)
1581{
1582 struct drm_info_node *node = (struct drm_info_node *) m->private;
1583 struct drm_device *dev = node->minor->dev;
1584 struct drm_i915_private *dev_priv = dev->dev_private;
1585 struct intel_ring_buffer *ring;
1586 int i, ret;
1587
1588
1589 ret = mutex_lock_interruptible(&dev->struct_mutex);
1590 if (ret)
1591 return ret;
1592 if (INTEL_INFO(dev)->gen == 6)
1593 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1594
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001595 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001596 seq_printf(m, "%s\n", ring->name);
1597 if (INTEL_INFO(dev)->gen == 7)
1598 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1599 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1600 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1601 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1602 }
1603 if (dev_priv->mm.aliasing_ppgtt) {
1604 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1605
1606 seq_printf(m, "aliasing PPGTT:\n");
1607 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1608 }
1609 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1610 mutex_unlock(&dev->struct_mutex);
1611
1612 return 0;
1613}
1614
Jesse Barnes57f350b2012-03-28 13:39:25 -07001615static int i915_dpio_info(struct seq_file *m, void *data)
1616{
1617 struct drm_info_node *node = (struct drm_info_node *) m->private;
1618 struct drm_device *dev = node->minor->dev;
1619 struct drm_i915_private *dev_priv = dev->dev_private;
1620 int ret;
1621
1622
1623 if (!IS_VALLEYVIEW(dev)) {
1624 seq_printf(m, "unsupported\n");
1625 return 0;
1626 }
1627
Daniel Vetter09153002012-12-12 14:06:44 +01001628 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001629 if (ret)
1630 return ret;
1631
1632 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1633
1634 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1635 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1636 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1637 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1638
1639 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1640 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1641 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1642 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1643
1644 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1645 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1646 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1647 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1648
1649 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1650 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1651 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1652 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1653
1654 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1655 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1656
Daniel Vetter09153002012-12-12 14:06:44 +01001657 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001658
1659 return 0;
1660}
1661
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001662static ssize_t
1663i915_wedged_read(struct file *filp,
1664 char __user *ubuf,
1665 size_t max,
1666 loff_t *ppos)
1667{
1668 struct drm_device *dev = filp->private_data;
1669 drm_i915_private_t *dev_priv = dev->dev_private;
1670 char buf[80];
1671 int len;
1672
Akshay Joshi0206e352011-08-16 15:34:10 -04001673 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001674 "wedged : %d\n",
1675 atomic_read(&dev_priv->mm.wedged));
1676
Akshay Joshi0206e352011-08-16 15:34:10 -04001677 if (len > sizeof(buf))
1678 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001679
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001680 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1681}
1682
1683static ssize_t
1684i915_wedged_write(struct file *filp,
1685 const char __user *ubuf,
1686 size_t cnt,
1687 loff_t *ppos)
1688{
1689 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001690 char buf[20];
1691 int val = 1;
1692
1693 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001694 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001695 return -EINVAL;
1696
1697 if (copy_from_user(buf, ubuf, cnt))
1698 return -EFAULT;
1699 buf[cnt] = 0;
1700
1701 val = simple_strtoul(buf, NULL, 0);
1702 }
1703
1704 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001705 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001706
1707 return cnt;
1708}
1709
1710static const struct file_operations i915_wedged_fops = {
1711 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001712 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001713 .read = i915_wedged_read,
1714 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001715 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001716};
1717
Jesse Barnes358733e2011-07-27 11:53:01 -07001718static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001719i915_ring_stop_read(struct file *filp,
1720 char __user *ubuf,
1721 size_t max,
1722 loff_t *ppos)
1723{
1724 struct drm_device *dev = filp->private_data;
1725 drm_i915_private_t *dev_priv = dev->dev_private;
1726 char buf[20];
1727 int len;
1728
1729 len = snprintf(buf, sizeof(buf),
1730 "0x%08x\n", dev_priv->stop_rings);
1731
1732 if (len > sizeof(buf))
1733 len = sizeof(buf);
1734
1735 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1736}
1737
1738static ssize_t
1739i915_ring_stop_write(struct file *filp,
1740 const char __user *ubuf,
1741 size_t cnt,
1742 loff_t *ppos)
1743{
1744 struct drm_device *dev = filp->private_data;
1745 struct drm_i915_private *dev_priv = dev->dev_private;
1746 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001747 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001748
1749 if (cnt > 0) {
1750 if (cnt > sizeof(buf) - 1)
1751 return -EINVAL;
1752
1753 if (copy_from_user(buf, ubuf, cnt))
1754 return -EFAULT;
1755 buf[cnt] = 0;
1756
1757 val = simple_strtoul(buf, NULL, 0);
1758 }
1759
1760 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1761
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001762 ret = mutex_lock_interruptible(&dev->struct_mutex);
1763 if (ret)
1764 return ret;
1765
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001766 dev_priv->stop_rings = val;
1767 mutex_unlock(&dev->struct_mutex);
1768
1769 return cnt;
1770}
1771
1772static const struct file_operations i915_ring_stop_fops = {
1773 .owner = THIS_MODULE,
1774 .open = simple_open,
1775 .read = i915_ring_stop_read,
1776 .write = i915_ring_stop_write,
1777 .llseek = default_llseek,
1778};
Daniel Vetterd5442302012-04-27 15:17:40 +02001779
Chris Wilsondd624af2013-01-15 12:39:35 +00001780#define DROP_UNBOUND 0x1
1781#define DROP_BOUND 0x2
1782#define DROP_RETIRE 0x4
1783#define DROP_ACTIVE 0x8
1784#define DROP_ALL (DROP_UNBOUND | \
1785 DROP_BOUND | \
1786 DROP_RETIRE | \
1787 DROP_ACTIVE)
1788static ssize_t
1789i915_drop_caches_read(struct file *filp,
1790 char __user *ubuf,
1791 size_t max,
1792 loff_t *ppos)
1793{
1794 char buf[20];
1795 int len;
1796
1797 len = snprintf(buf, sizeof(buf), "0x%08x\n", DROP_ALL);
1798 if (len > sizeof(buf))
1799 len = sizeof(buf);
1800
1801 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1802}
1803
1804static ssize_t
1805i915_drop_caches_write(struct file *filp,
1806 const char __user *ubuf,
1807 size_t cnt,
1808 loff_t *ppos)
1809{
1810 struct drm_device *dev = filp->private_data;
1811 struct drm_i915_private *dev_priv = dev->dev_private;
1812 struct drm_i915_gem_object *obj, *next;
1813 char buf[20];
1814 int val = 0, ret;
1815
1816 if (cnt > 0) {
1817 if (cnt > sizeof(buf) - 1)
1818 return -EINVAL;
1819
1820 if (copy_from_user(buf, ubuf, cnt))
1821 return -EFAULT;
1822 buf[cnt] = 0;
1823
1824 val = simple_strtoul(buf, NULL, 0);
1825 }
1826
1827 DRM_DEBUG_DRIVER("Dropping caches: 0x%08x\n", val);
1828
1829 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1830 * on ioctls on -EAGAIN. */
1831 ret = mutex_lock_interruptible(&dev->struct_mutex);
1832 if (ret)
1833 return ret;
1834
1835 if (val & DROP_ACTIVE) {
1836 ret = i915_gpu_idle(dev);
1837 if (ret)
1838 goto unlock;
1839 }
1840
1841 if (val & (DROP_RETIRE | DROP_ACTIVE))
1842 i915_gem_retire_requests(dev);
1843
1844 if (val & DROP_BOUND) {
1845 list_for_each_entry_safe(obj, next, &dev_priv->mm.inactive_list, mm_list)
1846 if (obj->pin_count == 0) {
1847 ret = i915_gem_object_unbind(obj);
1848 if (ret)
1849 goto unlock;
1850 }
1851 }
1852
1853 if (val & DROP_UNBOUND) {
1854 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list, gtt_list)
1855 if (obj->pages_pin_count == 0) {
1856 ret = i915_gem_object_put_pages(obj);
1857 if (ret)
1858 goto unlock;
1859 }
1860 }
1861
1862unlock:
1863 mutex_unlock(&dev->struct_mutex);
1864
1865 return ret ?: cnt;
1866}
1867
1868static const struct file_operations i915_drop_caches_fops = {
1869 .owner = THIS_MODULE,
1870 .open = simple_open,
1871 .read = i915_drop_caches_read,
1872 .write = i915_drop_caches_write,
1873 .llseek = default_llseek,
1874};
1875
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001876static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001877i915_max_freq_read(struct file *filp,
1878 char __user *ubuf,
1879 size_t max,
1880 loff_t *ppos)
1881{
1882 struct drm_device *dev = filp->private_data;
1883 drm_i915_private_t *dev_priv = dev->dev_private;
1884 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001885 int len, ret;
1886
1887 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1888 return -ENODEV;
1889
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001890 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001891 if (ret)
1892 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001893
Akshay Joshi0206e352011-08-16 15:34:10 -04001894 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001895 "max freq: %d\n", dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001896 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001897
Akshay Joshi0206e352011-08-16 15:34:10 -04001898 if (len > sizeof(buf))
1899 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001900
1901 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1902}
1903
1904static ssize_t
1905i915_max_freq_write(struct file *filp,
1906 const char __user *ubuf,
1907 size_t cnt,
1908 loff_t *ppos)
1909{
1910 struct drm_device *dev = filp->private_data;
1911 struct drm_i915_private *dev_priv = dev->dev_private;
1912 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001913 int val = 1, ret;
1914
1915 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1916 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001917
1918 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001919 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001920 return -EINVAL;
1921
1922 if (copy_from_user(buf, ubuf, cnt))
1923 return -EFAULT;
1924 buf[cnt] = 0;
1925
1926 val = simple_strtoul(buf, NULL, 0);
1927 }
1928
1929 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1930
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001931 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001932 if (ret)
1933 return ret;
1934
Jesse Barnes358733e2011-07-27 11:53:01 -07001935 /*
1936 * Turbo will still be enabled, but won't go above the set value.
1937 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07001938 dev_priv->rps.max_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes358733e2011-07-27 11:53:01 -07001939
Ben Widawskyc8735b02012-09-07 19:43:39 -07001940 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001941 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001942
1943 return cnt;
1944}
1945
1946static const struct file_operations i915_max_freq_fops = {
1947 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001948 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001949 .read = i915_max_freq_read,
1950 .write = i915_max_freq_write,
1951 .llseek = default_llseek,
1952};
1953
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001954static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001955i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1956 loff_t *ppos)
1957{
1958 struct drm_device *dev = filp->private_data;
1959 drm_i915_private_t *dev_priv = dev->dev_private;
1960 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001961 int len, ret;
1962
1963 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1964 return -ENODEV;
1965
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001966 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001967 if (ret)
1968 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001969
1970 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001971 "min freq: %d\n", dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001972 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07001973
1974 if (len > sizeof(buf))
1975 len = sizeof(buf);
1976
1977 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1978}
1979
1980static ssize_t
1981i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
1982 loff_t *ppos)
1983{
1984 struct drm_device *dev = filp->private_data;
1985 struct drm_i915_private *dev_priv = dev->dev_private;
1986 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001987 int val = 1, ret;
1988
1989 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1990 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07001991
1992 if (cnt > 0) {
1993 if (cnt > sizeof(buf) - 1)
1994 return -EINVAL;
1995
1996 if (copy_from_user(buf, ubuf, cnt))
1997 return -EFAULT;
1998 buf[cnt] = 0;
1999
2000 val = simple_strtoul(buf, NULL, 0);
2001 }
2002
2003 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
2004
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002005 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002006 if (ret)
2007 return ret;
2008
Jesse Barnes1523c312012-05-25 12:34:54 -07002009 /*
2010 * Turbo will still be enabled, but won't go below the set value.
2011 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07002012 dev_priv->rps.min_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes1523c312012-05-25 12:34:54 -07002013
Ben Widawskyc8735b02012-09-07 19:43:39 -07002014 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002015 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002016
2017 return cnt;
2018}
2019
2020static const struct file_operations i915_min_freq_fops = {
2021 .owner = THIS_MODULE,
2022 .open = simple_open,
2023 .read = i915_min_freq_read,
2024 .write = i915_min_freq_write,
2025 .llseek = default_llseek,
2026};
2027
2028static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002029i915_cache_sharing_read(struct file *filp,
2030 char __user *ubuf,
2031 size_t max,
2032 loff_t *ppos)
2033{
2034 struct drm_device *dev = filp->private_data;
2035 drm_i915_private_t *dev_priv = dev->dev_private;
2036 char buf[80];
2037 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002038 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002039
Daniel Vetter004777c2012-08-09 15:07:01 +02002040 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2041 return -ENODEV;
2042
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002043 ret = mutex_lock_interruptible(&dev->struct_mutex);
2044 if (ret)
2045 return ret;
2046
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002047 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2048 mutex_unlock(&dev_priv->dev->struct_mutex);
2049
Akshay Joshi0206e352011-08-16 15:34:10 -04002050 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002051 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
2052 GEN6_MBC_SNPCR_SHIFT);
2053
Akshay Joshi0206e352011-08-16 15:34:10 -04002054 if (len > sizeof(buf))
2055 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002056
2057 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
2058}
2059
2060static ssize_t
2061i915_cache_sharing_write(struct file *filp,
2062 const char __user *ubuf,
2063 size_t cnt,
2064 loff_t *ppos)
2065{
2066 struct drm_device *dev = filp->private_data;
2067 struct drm_i915_private *dev_priv = dev->dev_private;
2068 char buf[20];
2069 u32 snpcr;
2070 int val = 1;
2071
Daniel Vetter004777c2012-08-09 15:07:01 +02002072 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2073 return -ENODEV;
2074
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002075 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04002076 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002077 return -EINVAL;
2078
2079 if (copy_from_user(buf, ubuf, cnt))
2080 return -EFAULT;
2081 buf[cnt] = 0;
2082
2083 val = simple_strtoul(buf, NULL, 0);
2084 }
2085
2086 if (val < 0 || val > 3)
2087 return -EINVAL;
2088
2089 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
2090
2091 /* Update the cache sharing policy here as well */
2092 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2093 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2094 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2095 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2096
2097 return cnt;
2098}
2099
2100static const struct file_operations i915_cache_sharing_fops = {
2101 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07002102 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002103 .read = i915_cache_sharing_read,
2104 .write = i915_cache_sharing_write,
2105 .llseek = default_llseek,
2106};
2107
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002108/* As the drm_debugfs_init() routines are called before dev->dev_private is
2109 * allocated we need to hook into the minor for release. */
2110static int
2111drm_add_fake_info_node(struct drm_minor *minor,
2112 struct dentry *ent,
2113 const void *key)
2114{
2115 struct drm_info_node *node;
2116
2117 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
2118 if (node == NULL) {
2119 debugfs_remove(ent);
2120 return -ENOMEM;
2121 }
2122
2123 node->minor = minor;
2124 node->dent = ent;
2125 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002126
2127 mutex_lock(&minor->debugfs_lock);
2128 list_add(&node->list, &minor->debugfs_list);
2129 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002130
2131 return 0;
2132}
2133
Ben Widawsky6d794d42011-04-25 11:25:56 -07002134static int i915_forcewake_open(struct inode *inode, struct file *file)
2135{
2136 struct drm_device *dev = inode->i_private;
2137 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002138
Daniel Vetter075edca2012-01-24 09:44:28 +01002139 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002140 return 0;
2141
Ben Widawsky6d794d42011-04-25 11:25:56 -07002142 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002143
2144 return 0;
2145}
2146
Ben Widawskyc43b5632012-04-16 14:07:40 -07002147static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002148{
2149 struct drm_device *dev = inode->i_private;
2150 struct drm_i915_private *dev_priv = dev->dev_private;
2151
Daniel Vetter075edca2012-01-24 09:44:28 +01002152 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002153 return 0;
2154
Ben Widawsky6d794d42011-04-25 11:25:56 -07002155 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002156
2157 return 0;
2158}
2159
2160static const struct file_operations i915_forcewake_fops = {
2161 .owner = THIS_MODULE,
2162 .open = i915_forcewake_open,
2163 .release = i915_forcewake_release,
2164};
2165
2166static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2167{
2168 struct drm_device *dev = minor->dev;
2169 struct dentry *ent;
2170
2171 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002172 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002173 root, dev,
2174 &i915_forcewake_fops);
2175 if (IS_ERR(ent))
2176 return PTR_ERR(ent);
2177
Ben Widawsky8eb57292011-05-11 15:10:58 -07002178 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002179}
2180
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002181static int i915_debugfs_create(struct dentry *root,
2182 struct drm_minor *minor,
2183 const char *name,
2184 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002185{
2186 struct drm_device *dev = minor->dev;
2187 struct dentry *ent;
2188
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002189 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002190 S_IRUGO | S_IWUSR,
2191 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002192 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002193 if (IS_ERR(ent))
2194 return PTR_ERR(ent);
2195
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002196 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002197}
2198
Ben Gamari27c202a2009-07-01 22:26:52 -04002199static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002200 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002201 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002202 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002203 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002204 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002205 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002206 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002207 {"i915_gem_request", i915_gem_request_info, 0},
2208 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002209 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002210 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002211 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2212 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2213 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002214 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2215 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2216 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2217 {"i915_inttoext_table", i915_inttoext_table, 0},
2218 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002219 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002220 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002221 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002222 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002223 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002224 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002225 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002226 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002227 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002228 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002229 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002230 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002231};
Ben Gamari27c202a2009-07-01 22:26:52 -04002232#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002233
Ben Gamari27c202a2009-07-01 22:26:52 -04002234int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002235{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002236 int ret;
2237
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002238 ret = i915_debugfs_create(minor->debugfs_root, minor,
2239 "i915_wedged",
2240 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002241 if (ret)
2242 return ret;
2243
Ben Widawsky6d794d42011-04-25 11:25:56 -07002244 ret = i915_forcewake_create(minor->debugfs_root, minor);
2245 if (ret)
2246 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002247
2248 ret = i915_debugfs_create(minor->debugfs_root, minor,
2249 "i915_max_freq",
2250 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002251 if (ret)
2252 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002253
2254 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002255 "i915_min_freq",
2256 &i915_min_freq_fops);
2257 if (ret)
2258 return ret;
2259
2260 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002261 "i915_cache_sharing",
2262 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002263 if (ret)
2264 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002265
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002266 ret = i915_debugfs_create(minor->debugfs_root, minor,
2267 "i915_ring_stop",
2268 &i915_ring_stop_fops);
2269 if (ret)
2270 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002271
Daniel Vetterd5442302012-04-27 15:17:40 +02002272 ret = i915_debugfs_create(minor->debugfs_root, minor,
Chris Wilsondd624af2013-01-15 12:39:35 +00002273 "i915_gem_drop_caches",
2274 &i915_drop_caches_fops);
2275 if (ret)
2276 return ret;
2277
2278 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetterd5442302012-04-27 15:17:40 +02002279 "i915_error_state",
2280 &i915_error_state_fops);
2281 if (ret)
2282 return ret;
2283
Mika Kuoppala40633212012-12-04 15:12:00 +02002284 ret = i915_debugfs_create(minor->debugfs_root, minor,
2285 "i915_next_seqno",
2286 &i915_next_seqno_fops);
2287 if (ret)
2288 return ret;
2289
Ben Gamari27c202a2009-07-01 22:26:52 -04002290 return drm_debugfs_create_files(i915_debugfs_list,
2291 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002292 minor->debugfs_root, minor);
2293}
2294
Ben Gamari27c202a2009-07-01 22:26:52 -04002295void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002296{
Ben Gamari27c202a2009-07-01 22:26:52 -04002297 drm_debugfs_remove_files(i915_debugfs_list,
2298 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002299 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2300 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002301 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2302 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002303 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2304 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002305 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2306 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002307 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2308 1, minor);
Chris Wilsondd624af2013-01-15 12:39:35 +00002309 drm_debugfs_remove_files((struct drm_info_list *) &i915_drop_caches_fops,
2310 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002311 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2312 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002313 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2314 1, minor);
Mika Kuoppala40633212012-12-04 15:12:00 +02002315 drm_debugfs_remove_files((struct drm_info_list *) &i915_next_seqno_fops,
2316 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002317}
2318
2319#endif /* CONFIG_DEBUG_FS */