blob: 749114881c234bb4244654860c8f199cdba48fdd [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
Daniel Vetter99584db2012-11-14 17:14:04 +0100817 spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
818 error_priv->error = dev_priv->gpu_error.first_error;
Daniel Vetterd5442302012-04-27 15:17:40 +0200819 if (error_priv->error)
820 kref_get(&error_priv->error->ref);
Daniel Vetter99584db2012-11-14 17:14:04 +0100821 spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
Daniel Vetterd5442302012-04-27 15:17:40 +0200822
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);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800960 u32 rpstat, cagf;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800961 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);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800979 if (IS_HASWELL(dev))
980 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
981 else
982 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
983 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800984
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100985 gen6_gt_force_wake_put(dev_priv);
986 mutex_unlock(&dev->struct_mutex);
987
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800988 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800989 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800990 seq_printf(m, "Render p-state ratio: %d\n",
991 (gt_perf_status & 0xff00) >> 8);
992 seq_printf(m, "Render p-state VID: %d\n",
993 gt_perf_status & 0xff);
994 seq_printf(m, "Render p-state limit: %d\n",
995 rp_state_limits & 0xff);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800996 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800997 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
998 GEN6_CURICONT_MASK);
999 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1000 GEN6_CURBSYTAVG_MASK);
1001 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1002 GEN6_CURBSYTAVG_MASK);
1003 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1004 GEN6_CURIAVG_MASK);
1005 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1006 GEN6_CURBSYTAVG_MASK);
1007 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1008 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001009
1010 max_freq = (rp_state_cap & 0xff0000) >> 16;
1011 seq_printf(m, "Lowest (RPN) 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 & 0xff00) >> 8;
1015 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001016 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001017
1018 max_freq = rp_state_cap & 0xff;
1019 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001020 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001021 } else {
1022 seq_printf(m, "no P-state info available\n");
1023 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001024
1025 return 0;
1026}
1027
1028static int i915_delayfreq_table(struct seq_file *m, void *unused)
1029{
1030 struct drm_info_node *node = (struct drm_info_node *) m->private;
1031 struct drm_device *dev = node->minor->dev;
1032 drm_i915_private_t *dev_priv = dev->dev_private;
1033 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001034 int ret, i;
1035
1036 ret = mutex_lock_interruptible(&dev->struct_mutex);
1037 if (ret)
1038 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001039
1040 for (i = 0; i < 16; i++) {
1041 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001042 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1043 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001044 }
1045
Ben Widawsky616fdb52011-10-05 11:44:54 -07001046 mutex_unlock(&dev->struct_mutex);
1047
Jesse Barnesf97108d2010-01-29 11:27:07 -08001048 return 0;
1049}
1050
1051static inline int MAP_TO_MV(int map)
1052{
1053 return 1250 - (map * 25);
1054}
1055
1056static int i915_inttoext_table(struct seq_file *m, void *unused)
1057{
1058 struct drm_info_node *node = (struct drm_info_node *) m->private;
1059 struct drm_device *dev = node->minor->dev;
1060 drm_i915_private_t *dev_priv = dev->dev_private;
1061 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001062 int ret, i;
1063
1064 ret = mutex_lock_interruptible(&dev->struct_mutex);
1065 if (ret)
1066 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001067
1068 for (i = 1; i <= 32; i++) {
1069 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1070 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1071 }
1072
Ben Widawsky616fdb52011-10-05 11:44:54 -07001073 mutex_unlock(&dev->struct_mutex);
1074
Jesse Barnesf97108d2010-01-29 11:27:07 -08001075 return 0;
1076}
1077
Ben Widawsky4d855292011-12-12 19:34:16 -08001078static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001079{
1080 struct drm_info_node *node = (struct drm_info_node *) m->private;
1081 struct drm_device *dev = node->minor->dev;
1082 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001083 u32 rgvmodectl, rstdbyctl;
1084 u16 crstandvid;
1085 int ret;
1086
1087 ret = mutex_lock_interruptible(&dev->struct_mutex);
1088 if (ret)
1089 return ret;
1090
1091 rgvmodectl = I915_READ(MEMMODECTL);
1092 rstdbyctl = I915_READ(RSTDBYCTL);
1093 crstandvid = I915_READ16(CRSTANDVID);
1094
1095 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001096
1097 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1098 "yes" : "no");
1099 seq_printf(m, "Boost freq: %d\n",
1100 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1101 MEMMODE_BOOST_FREQ_SHIFT);
1102 seq_printf(m, "HW control enabled: %s\n",
1103 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1104 seq_printf(m, "SW control enabled: %s\n",
1105 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1106 seq_printf(m, "Gated voltage change: %s\n",
1107 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1108 seq_printf(m, "Starting frequency: P%d\n",
1109 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001110 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001111 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001112 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1113 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1114 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1115 seq_printf(m, "Render standby enabled: %s\n",
1116 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001117 seq_printf(m, "Current RS state: ");
1118 switch (rstdbyctl & RSX_STATUS_MASK) {
1119 case RSX_STATUS_ON:
1120 seq_printf(m, "on\n");
1121 break;
1122 case RSX_STATUS_RC1:
1123 seq_printf(m, "RC1\n");
1124 break;
1125 case RSX_STATUS_RC1E:
1126 seq_printf(m, "RC1E\n");
1127 break;
1128 case RSX_STATUS_RS1:
1129 seq_printf(m, "RS1\n");
1130 break;
1131 case RSX_STATUS_RS2:
1132 seq_printf(m, "RS2 (RC6)\n");
1133 break;
1134 case RSX_STATUS_RS3:
1135 seq_printf(m, "RC3 (RC6+)\n");
1136 break;
1137 default:
1138 seq_printf(m, "unknown\n");
1139 break;
1140 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001141
1142 return 0;
1143}
1144
Ben Widawsky4d855292011-12-12 19:34:16 -08001145static int gen6_drpc_info(struct seq_file *m)
1146{
1147
1148 struct drm_info_node *node = (struct drm_info_node *) m->private;
1149 struct drm_device *dev = node->minor->dev;
1150 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001151 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001152 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001153 int count=0, ret;
1154
1155
1156 ret = mutex_lock_interruptible(&dev->struct_mutex);
1157 if (ret)
1158 return ret;
1159
Daniel Vetter93b525d2012-01-25 13:52:43 +01001160 spin_lock_irq(&dev_priv->gt_lock);
1161 forcewake_count = dev_priv->forcewake_count;
1162 spin_unlock_irq(&dev_priv->gt_lock);
1163
1164 if (forcewake_count) {
1165 seq_printf(m, "RC information inaccurate because somebody "
1166 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001167 } else {
1168 /* NB: we cannot use forcewake, else we read the wrong values */
1169 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1170 udelay(10);
1171 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1172 }
1173
1174 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1175 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1176
1177 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1178 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1179 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001180 mutex_lock(&dev_priv->rps.hw_lock);
1181 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1182 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001183
1184 seq_printf(m, "Video Turbo Mode: %s\n",
1185 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1186 seq_printf(m, "HW control enabled: %s\n",
1187 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1188 seq_printf(m, "SW control enabled: %s\n",
1189 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1190 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001191 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001192 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1193 seq_printf(m, "RC6 Enabled: %s\n",
1194 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1195 seq_printf(m, "Deep RC6 Enabled: %s\n",
1196 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1197 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1198 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1199 seq_printf(m, "Current RC state: ");
1200 switch (gt_core_status & GEN6_RCn_MASK) {
1201 case GEN6_RC0:
1202 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1203 seq_printf(m, "Core Power Down\n");
1204 else
1205 seq_printf(m, "on\n");
1206 break;
1207 case GEN6_RC3:
1208 seq_printf(m, "RC3\n");
1209 break;
1210 case GEN6_RC6:
1211 seq_printf(m, "RC6\n");
1212 break;
1213 case GEN6_RC7:
1214 seq_printf(m, "RC7\n");
1215 break;
1216 default:
1217 seq_printf(m, "Unknown\n");
1218 break;
1219 }
1220
1221 seq_printf(m, "Core Power Down: %s\n",
1222 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001223
1224 /* Not exactly sure what this is */
1225 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1226 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1227 seq_printf(m, "RC6 residency since boot: %u\n",
1228 I915_READ(GEN6_GT_GFX_RC6));
1229 seq_printf(m, "RC6+ residency since boot: %u\n",
1230 I915_READ(GEN6_GT_GFX_RC6p));
1231 seq_printf(m, "RC6++ residency since boot: %u\n",
1232 I915_READ(GEN6_GT_GFX_RC6pp));
1233
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001234 seq_printf(m, "RC6 voltage: %dmV\n",
1235 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1236 seq_printf(m, "RC6+ voltage: %dmV\n",
1237 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1238 seq_printf(m, "RC6++ voltage: %dmV\n",
1239 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001240 return 0;
1241}
1242
1243static int i915_drpc_info(struct seq_file *m, void *unused)
1244{
1245 struct drm_info_node *node = (struct drm_info_node *) m->private;
1246 struct drm_device *dev = node->minor->dev;
1247
1248 if (IS_GEN6(dev) || IS_GEN7(dev))
1249 return gen6_drpc_info(m);
1250 else
1251 return ironlake_drpc_info(m);
1252}
1253
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001254static int i915_fbc_status(struct seq_file *m, void *unused)
1255{
1256 struct drm_info_node *node = (struct drm_info_node *) m->private;
1257 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001258 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001259
Adam Jacksonee5382a2010-04-23 11:17:39 -04001260 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001261 seq_printf(m, "FBC unsupported on this chipset\n");
1262 return 0;
1263 }
1264
Adam Jacksonee5382a2010-04-23 11:17:39 -04001265 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001266 seq_printf(m, "FBC enabled\n");
1267 } else {
1268 seq_printf(m, "FBC disabled: ");
1269 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001270 case FBC_NO_OUTPUT:
1271 seq_printf(m, "no outputs");
1272 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001273 case FBC_STOLEN_TOO_SMALL:
1274 seq_printf(m, "not enough stolen memory");
1275 break;
1276 case FBC_UNSUPPORTED_MODE:
1277 seq_printf(m, "mode not supported");
1278 break;
1279 case FBC_MODE_TOO_LARGE:
1280 seq_printf(m, "mode too large");
1281 break;
1282 case FBC_BAD_PLANE:
1283 seq_printf(m, "FBC unsupported on plane");
1284 break;
1285 case FBC_NOT_TILED:
1286 seq_printf(m, "scanout buffer not tiled");
1287 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001288 case FBC_MULTIPLE_PIPES:
1289 seq_printf(m, "multiple pipes are enabled");
1290 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001291 case FBC_MODULE_PARAM:
1292 seq_printf(m, "disabled per module param (default off)");
1293 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001294 default:
1295 seq_printf(m, "unknown reason");
1296 }
1297 seq_printf(m, "\n");
1298 }
1299 return 0;
1300}
1301
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001302static int i915_sr_status(struct seq_file *m, void *unused)
1303{
1304 struct drm_info_node *node = (struct drm_info_node *) m->private;
1305 struct drm_device *dev = node->minor->dev;
1306 drm_i915_private_t *dev_priv = dev->dev_private;
1307 bool sr_enabled = false;
1308
Yuanhan Liu13982612010-12-15 15:42:31 +08001309 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001310 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001311 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001312 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1313 else if (IS_I915GM(dev))
1314 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1315 else if (IS_PINEVIEW(dev))
1316 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1317
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001318 seq_printf(m, "self-refresh: %s\n",
1319 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001320
1321 return 0;
1322}
1323
Jesse Barnes7648fa92010-05-20 14:28:11 -07001324static int i915_emon_status(struct seq_file *m, void *unused)
1325{
1326 struct drm_info_node *node = (struct drm_info_node *) m->private;
1327 struct drm_device *dev = node->minor->dev;
1328 drm_i915_private_t *dev_priv = dev->dev_private;
1329 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001330 int ret;
1331
Chris Wilson582be6b2012-04-30 19:35:02 +01001332 if (!IS_GEN5(dev))
1333 return -ENODEV;
1334
Chris Wilsonde227ef2010-07-03 07:58:38 +01001335 ret = mutex_lock_interruptible(&dev->struct_mutex);
1336 if (ret)
1337 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001338
1339 temp = i915_mch_val(dev_priv);
1340 chipset = i915_chipset_val(dev_priv);
1341 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001342 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001343
1344 seq_printf(m, "GMCH temp: %ld\n", temp);
1345 seq_printf(m, "Chipset power: %ld\n", chipset);
1346 seq_printf(m, "GFX power: %ld\n", gfx);
1347 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1348
1349 return 0;
1350}
1351
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001352static int i915_ring_freq_table(struct seq_file *m, void *unused)
1353{
1354 struct drm_info_node *node = (struct drm_info_node *) m->private;
1355 struct drm_device *dev = node->minor->dev;
1356 drm_i915_private_t *dev_priv = dev->dev_private;
1357 int ret;
1358 int gpu_freq, ia_freq;
1359
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001360 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001361 seq_printf(m, "unsupported on this chipset\n");
1362 return 0;
1363 }
1364
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001365 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001366 if (ret)
1367 return ret;
1368
1369 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1370
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001371 for (gpu_freq = dev_priv->rps.min_delay;
1372 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001373 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001374 ia_freq = gpu_freq;
1375 sandybridge_pcode_read(dev_priv,
1376 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1377 &ia_freq);
Ben Widawskyc8735b02012-09-07 19:43:39 -07001378 seq_printf(m, "%d\t\t%d\n", gpu_freq * GT_FREQUENCY_MULTIPLIER, ia_freq * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001379 }
1380
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001381 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001382
1383 return 0;
1384}
1385
Jesse Barnes7648fa92010-05-20 14:28:11 -07001386static int i915_gfxec(struct seq_file *m, void *unused)
1387{
1388 struct drm_info_node *node = (struct drm_info_node *) m->private;
1389 struct drm_device *dev = node->minor->dev;
1390 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001391 int ret;
1392
1393 ret = mutex_lock_interruptible(&dev->struct_mutex);
1394 if (ret)
1395 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001396
1397 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1398
Ben Widawsky616fdb52011-10-05 11:44:54 -07001399 mutex_unlock(&dev->struct_mutex);
1400
Jesse Barnes7648fa92010-05-20 14:28:11 -07001401 return 0;
1402}
1403
Chris Wilson44834a62010-08-19 16:09:23 +01001404static int i915_opregion(struct seq_file *m, void *unused)
1405{
1406 struct drm_info_node *node = (struct drm_info_node *) m->private;
1407 struct drm_device *dev = node->minor->dev;
1408 drm_i915_private_t *dev_priv = dev->dev_private;
1409 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001410 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001411 int ret;
1412
Daniel Vetter0d38f002012-04-21 22:49:10 +02001413 if (data == NULL)
1414 return -ENOMEM;
1415
Chris Wilson44834a62010-08-19 16:09:23 +01001416 ret = mutex_lock_interruptible(&dev->struct_mutex);
1417 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001418 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001419
Daniel Vetter0d38f002012-04-21 22:49:10 +02001420 if (opregion->header) {
1421 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1422 seq_write(m, data, OPREGION_SIZE);
1423 }
Chris Wilson44834a62010-08-19 16:09:23 +01001424
1425 mutex_unlock(&dev->struct_mutex);
1426
Daniel Vetter0d38f002012-04-21 22:49:10 +02001427out:
1428 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001429 return 0;
1430}
1431
Chris Wilson37811fc2010-08-25 22:45:57 +01001432static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1433{
1434 struct drm_info_node *node = (struct drm_info_node *) m->private;
1435 struct drm_device *dev = node->minor->dev;
1436 drm_i915_private_t *dev_priv = dev->dev_private;
1437 struct intel_fbdev *ifbdev;
1438 struct intel_framebuffer *fb;
1439 int ret;
1440
1441 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1442 if (ret)
1443 return ret;
1444
1445 ifbdev = dev_priv->fbdev;
1446 fb = to_intel_framebuffer(ifbdev->helper.fb);
1447
1448 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1449 fb->base.width,
1450 fb->base.height,
1451 fb->base.depth,
1452 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001453 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001454 seq_printf(m, "\n");
1455
1456 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1457 if (&fb->base == ifbdev->helper.fb)
1458 continue;
1459
1460 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1461 fb->base.width,
1462 fb->base.height,
1463 fb->base.depth,
1464 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001465 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001466 seq_printf(m, "\n");
1467 }
1468
1469 mutex_unlock(&dev->mode_config.mutex);
1470
1471 return 0;
1472}
1473
Ben Widawskye76d3632011-03-19 18:14:29 -07001474static int i915_context_status(struct seq_file *m, void *unused)
1475{
1476 struct drm_info_node *node = (struct drm_info_node *) m->private;
1477 struct drm_device *dev = node->minor->dev;
1478 drm_i915_private_t *dev_priv = dev->dev_private;
1479 int ret;
1480
1481 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1482 if (ret)
1483 return ret;
1484
Daniel Vetter3e373942012-11-02 19:55:04 +01001485 if (dev_priv->ips.pwrctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001486 seq_printf(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001487 describe_obj(m, dev_priv->ips.pwrctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001488 seq_printf(m, "\n");
1489 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001490
Daniel Vetter3e373942012-11-02 19:55:04 +01001491 if (dev_priv->ips.renderctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001492 seq_printf(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001493 describe_obj(m, dev_priv->ips.renderctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001494 seq_printf(m, "\n");
1495 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001496
1497 mutex_unlock(&dev->mode_config.mutex);
1498
1499 return 0;
1500}
1501
Ben Widawsky6d794d42011-04-25 11:25:56 -07001502static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1503{
1504 struct drm_info_node *node = (struct drm_info_node *) m->private;
1505 struct drm_device *dev = node->minor->dev;
1506 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001507 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001508
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001509 spin_lock_irq(&dev_priv->gt_lock);
1510 forcewake_count = dev_priv->forcewake_count;
1511 spin_unlock_irq(&dev_priv->gt_lock);
1512
1513 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001514
1515 return 0;
1516}
1517
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001518static const char *swizzle_string(unsigned swizzle)
1519{
1520 switch(swizzle) {
1521 case I915_BIT_6_SWIZZLE_NONE:
1522 return "none";
1523 case I915_BIT_6_SWIZZLE_9:
1524 return "bit9";
1525 case I915_BIT_6_SWIZZLE_9_10:
1526 return "bit9/bit10";
1527 case I915_BIT_6_SWIZZLE_9_11:
1528 return "bit9/bit11";
1529 case I915_BIT_6_SWIZZLE_9_10_11:
1530 return "bit9/bit10/bit11";
1531 case I915_BIT_6_SWIZZLE_9_17:
1532 return "bit9/bit17";
1533 case I915_BIT_6_SWIZZLE_9_10_17:
1534 return "bit9/bit10/bit17";
1535 case I915_BIT_6_SWIZZLE_UNKNOWN:
1536 return "unkown";
1537 }
1538
1539 return "bug";
1540}
1541
1542static int i915_swizzle_info(struct seq_file *m, void *data)
1543{
1544 struct drm_info_node *node = (struct drm_info_node *) m->private;
1545 struct drm_device *dev = node->minor->dev;
1546 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001547 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001548
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001549 ret = mutex_lock_interruptible(&dev->struct_mutex);
1550 if (ret)
1551 return ret;
1552
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001553 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1554 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1555 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1556 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1557
1558 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1559 seq_printf(m, "DDC = 0x%08x\n",
1560 I915_READ(DCC));
1561 seq_printf(m, "C0DRB3 = 0x%04x\n",
1562 I915_READ16(C0DRB3));
1563 seq_printf(m, "C1DRB3 = 0x%04x\n",
1564 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001565 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1566 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1567 I915_READ(MAD_DIMM_C0));
1568 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1569 I915_READ(MAD_DIMM_C1));
1570 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1571 I915_READ(MAD_DIMM_C2));
1572 seq_printf(m, "TILECTL = 0x%08x\n",
1573 I915_READ(TILECTL));
1574 seq_printf(m, "ARB_MODE = 0x%08x\n",
1575 I915_READ(ARB_MODE));
1576 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1577 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001578 }
1579 mutex_unlock(&dev->struct_mutex);
1580
1581 return 0;
1582}
1583
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001584static int i915_ppgtt_info(struct seq_file *m, void *data)
1585{
1586 struct drm_info_node *node = (struct drm_info_node *) m->private;
1587 struct drm_device *dev = node->minor->dev;
1588 struct drm_i915_private *dev_priv = dev->dev_private;
1589 struct intel_ring_buffer *ring;
1590 int i, ret;
1591
1592
1593 ret = mutex_lock_interruptible(&dev->struct_mutex);
1594 if (ret)
1595 return ret;
1596 if (INTEL_INFO(dev)->gen == 6)
1597 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1598
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001599 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001600 seq_printf(m, "%s\n", ring->name);
1601 if (INTEL_INFO(dev)->gen == 7)
1602 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1603 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1604 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1605 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1606 }
1607 if (dev_priv->mm.aliasing_ppgtt) {
1608 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1609
1610 seq_printf(m, "aliasing PPGTT:\n");
1611 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1612 }
1613 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1614 mutex_unlock(&dev->struct_mutex);
1615
1616 return 0;
1617}
1618
Jesse Barnes57f350b2012-03-28 13:39:25 -07001619static int i915_dpio_info(struct seq_file *m, void *data)
1620{
1621 struct drm_info_node *node = (struct drm_info_node *) m->private;
1622 struct drm_device *dev = node->minor->dev;
1623 struct drm_i915_private *dev_priv = dev->dev_private;
1624 int ret;
1625
1626
1627 if (!IS_VALLEYVIEW(dev)) {
1628 seq_printf(m, "unsupported\n");
1629 return 0;
1630 }
1631
Daniel Vetter09153002012-12-12 14:06:44 +01001632 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001633 if (ret)
1634 return ret;
1635
1636 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1637
1638 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1639 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1640 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1641 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1642
1643 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1644 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1645 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1646 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1647
1648 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1649 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1650 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1651 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1652
1653 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1654 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1655 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1656 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1657
1658 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1659 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1660
Daniel Vetter09153002012-12-12 14:06:44 +01001661 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001662
1663 return 0;
1664}
1665
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001666static ssize_t
1667i915_wedged_read(struct file *filp,
1668 char __user *ubuf,
1669 size_t max,
1670 loff_t *ppos)
1671{
1672 struct drm_device *dev = filp->private_data;
1673 drm_i915_private_t *dev_priv = dev->dev_private;
1674 char buf[80];
1675 int len;
1676
Akshay Joshi0206e352011-08-16 15:34:10 -04001677 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001678 "wedged : %d\n",
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001679 atomic_read(&dev_priv->gpu_error.reset_counter));
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001680
Akshay Joshi0206e352011-08-16 15:34:10 -04001681 if (len > sizeof(buf))
1682 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001683
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001684 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1685}
1686
1687static ssize_t
1688i915_wedged_write(struct file *filp,
1689 const char __user *ubuf,
1690 size_t cnt,
1691 loff_t *ppos)
1692{
1693 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001694 char buf[20];
1695 int val = 1;
1696
1697 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001698 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001699 return -EINVAL;
1700
1701 if (copy_from_user(buf, ubuf, cnt))
1702 return -EFAULT;
1703 buf[cnt] = 0;
1704
1705 val = simple_strtoul(buf, NULL, 0);
1706 }
1707
1708 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001709 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001710
1711 return cnt;
1712}
1713
1714static const struct file_operations i915_wedged_fops = {
1715 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001716 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001717 .read = i915_wedged_read,
1718 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001719 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001720};
1721
Jesse Barnes358733e2011-07-27 11:53:01 -07001722static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001723i915_ring_stop_read(struct file *filp,
1724 char __user *ubuf,
1725 size_t max,
1726 loff_t *ppos)
1727{
1728 struct drm_device *dev = filp->private_data;
1729 drm_i915_private_t *dev_priv = dev->dev_private;
1730 char buf[20];
1731 int len;
1732
1733 len = snprintf(buf, sizeof(buf),
Daniel Vetter99584db2012-11-14 17:14:04 +01001734 "0x%08x\n", dev_priv->gpu_error.stop_rings);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001735
1736 if (len > sizeof(buf))
1737 len = sizeof(buf);
1738
1739 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1740}
1741
1742static ssize_t
1743i915_ring_stop_write(struct file *filp,
1744 const char __user *ubuf,
1745 size_t cnt,
1746 loff_t *ppos)
1747{
1748 struct drm_device *dev = filp->private_data;
1749 struct drm_i915_private *dev_priv = dev->dev_private;
1750 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001751 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001752
1753 if (cnt > 0) {
1754 if (cnt > sizeof(buf) - 1)
1755 return -EINVAL;
1756
1757 if (copy_from_user(buf, ubuf, cnt))
1758 return -EFAULT;
1759 buf[cnt] = 0;
1760
1761 val = simple_strtoul(buf, NULL, 0);
1762 }
1763
1764 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1765
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001766 ret = mutex_lock_interruptible(&dev->struct_mutex);
1767 if (ret)
1768 return ret;
1769
Daniel Vetter99584db2012-11-14 17:14:04 +01001770 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001771 mutex_unlock(&dev->struct_mutex);
1772
1773 return cnt;
1774}
1775
1776static const struct file_operations i915_ring_stop_fops = {
1777 .owner = THIS_MODULE,
1778 .open = simple_open,
1779 .read = i915_ring_stop_read,
1780 .write = i915_ring_stop_write,
1781 .llseek = default_llseek,
1782};
Daniel Vetterd5442302012-04-27 15:17:40 +02001783
Chris Wilsondd624af2013-01-15 12:39:35 +00001784#define DROP_UNBOUND 0x1
1785#define DROP_BOUND 0x2
1786#define DROP_RETIRE 0x4
1787#define DROP_ACTIVE 0x8
1788#define DROP_ALL (DROP_UNBOUND | \
1789 DROP_BOUND | \
1790 DROP_RETIRE | \
1791 DROP_ACTIVE)
1792static ssize_t
1793i915_drop_caches_read(struct file *filp,
1794 char __user *ubuf,
1795 size_t max,
1796 loff_t *ppos)
1797{
1798 char buf[20];
1799 int len;
1800
1801 len = snprintf(buf, sizeof(buf), "0x%08x\n", DROP_ALL);
1802 if (len > sizeof(buf))
1803 len = sizeof(buf);
1804
1805 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1806}
1807
1808static ssize_t
1809i915_drop_caches_write(struct file *filp,
1810 const char __user *ubuf,
1811 size_t cnt,
1812 loff_t *ppos)
1813{
1814 struct drm_device *dev = filp->private_data;
1815 struct drm_i915_private *dev_priv = dev->dev_private;
1816 struct drm_i915_gem_object *obj, *next;
1817 char buf[20];
1818 int val = 0, ret;
1819
1820 if (cnt > 0) {
1821 if (cnt > sizeof(buf) - 1)
1822 return -EINVAL;
1823
1824 if (copy_from_user(buf, ubuf, cnt))
1825 return -EFAULT;
1826 buf[cnt] = 0;
1827
1828 val = simple_strtoul(buf, NULL, 0);
1829 }
1830
1831 DRM_DEBUG_DRIVER("Dropping caches: 0x%08x\n", val);
1832
1833 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1834 * on ioctls on -EAGAIN. */
1835 ret = mutex_lock_interruptible(&dev->struct_mutex);
1836 if (ret)
1837 return ret;
1838
1839 if (val & DROP_ACTIVE) {
1840 ret = i915_gpu_idle(dev);
1841 if (ret)
1842 goto unlock;
1843 }
1844
1845 if (val & (DROP_RETIRE | DROP_ACTIVE))
1846 i915_gem_retire_requests(dev);
1847
1848 if (val & DROP_BOUND) {
1849 list_for_each_entry_safe(obj, next, &dev_priv->mm.inactive_list, mm_list)
1850 if (obj->pin_count == 0) {
1851 ret = i915_gem_object_unbind(obj);
1852 if (ret)
1853 goto unlock;
1854 }
1855 }
1856
1857 if (val & DROP_UNBOUND) {
1858 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list, gtt_list)
1859 if (obj->pages_pin_count == 0) {
1860 ret = i915_gem_object_put_pages(obj);
1861 if (ret)
1862 goto unlock;
1863 }
1864 }
1865
1866unlock:
1867 mutex_unlock(&dev->struct_mutex);
1868
1869 return ret ?: cnt;
1870}
1871
1872static const struct file_operations i915_drop_caches_fops = {
1873 .owner = THIS_MODULE,
1874 .open = simple_open,
1875 .read = i915_drop_caches_read,
1876 .write = i915_drop_caches_write,
1877 .llseek = default_llseek,
1878};
1879
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001880static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001881i915_max_freq_read(struct file *filp,
1882 char __user *ubuf,
1883 size_t max,
1884 loff_t *ppos)
1885{
1886 struct drm_device *dev = filp->private_data;
1887 drm_i915_private_t *dev_priv = dev->dev_private;
1888 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001889 int len, ret;
1890
1891 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1892 return -ENODEV;
1893
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001894 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001895 if (ret)
1896 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001897
Akshay Joshi0206e352011-08-16 15:34:10 -04001898 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001899 "max freq: %d\n", dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001900 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001901
Akshay Joshi0206e352011-08-16 15:34:10 -04001902 if (len > sizeof(buf))
1903 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001904
1905 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1906}
1907
1908static ssize_t
1909i915_max_freq_write(struct file *filp,
1910 const char __user *ubuf,
1911 size_t cnt,
1912 loff_t *ppos)
1913{
1914 struct drm_device *dev = filp->private_data;
1915 struct drm_i915_private *dev_priv = dev->dev_private;
1916 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001917 int val = 1, ret;
1918
1919 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1920 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001921
1922 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001923 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001924 return -EINVAL;
1925
1926 if (copy_from_user(buf, ubuf, cnt))
1927 return -EFAULT;
1928 buf[cnt] = 0;
1929
1930 val = simple_strtoul(buf, NULL, 0);
1931 }
1932
1933 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1934
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001935 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001936 if (ret)
1937 return ret;
1938
Jesse Barnes358733e2011-07-27 11:53:01 -07001939 /*
1940 * Turbo will still be enabled, but won't go above the set value.
1941 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07001942 dev_priv->rps.max_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes358733e2011-07-27 11:53:01 -07001943
Ben Widawskyc8735b02012-09-07 19:43:39 -07001944 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001945 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001946
1947 return cnt;
1948}
1949
1950static const struct file_operations i915_max_freq_fops = {
1951 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001952 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001953 .read = i915_max_freq_read,
1954 .write = i915_max_freq_write,
1955 .llseek = default_llseek,
1956};
1957
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001958static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001959i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1960 loff_t *ppos)
1961{
1962 struct drm_device *dev = filp->private_data;
1963 drm_i915_private_t *dev_priv = dev->dev_private;
1964 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001965 int len, ret;
1966
1967 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1968 return -ENODEV;
1969
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001970 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001971 if (ret)
1972 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001973
1974 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001975 "min freq: %d\n", dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001976 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07001977
1978 if (len > sizeof(buf))
1979 len = sizeof(buf);
1980
1981 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1982}
1983
1984static ssize_t
1985i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
1986 loff_t *ppos)
1987{
1988 struct drm_device *dev = filp->private_data;
1989 struct drm_i915_private *dev_priv = dev->dev_private;
1990 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001991 int val = 1, ret;
1992
1993 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1994 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07001995
1996 if (cnt > 0) {
1997 if (cnt > sizeof(buf) - 1)
1998 return -EINVAL;
1999
2000 if (copy_from_user(buf, ubuf, cnt))
2001 return -EFAULT;
2002 buf[cnt] = 0;
2003
2004 val = simple_strtoul(buf, NULL, 0);
2005 }
2006
2007 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
2008
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002009 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002010 if (ret)
2011 return ret;
2012
Jesse Barnes1523c312012-05-25 12:34:54 -07002013 /*
2014 * Turbo will still be enabled, but won't go below the set value.
2015 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07002016 dev_priv->rps.min_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes1523c312012-05-25 12:34:54 -07002017
Ben Widawskyc8735b02012-09-07 19:43:39 -07002018 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002019 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002020
2021 return cnt;
2022}
2023
2024static const struct file_operations i915_min_freq_fops = {
2025 .owner = THIS_MODULE,
2026 .open = simple_open,
2027 .read = i915_min_freq_read,
2028 .write = i915_min_freq_write,
2029 .llseek = default_llseek,
2030};
2031
2032static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002033i915_cache_sharing_read(struct file *filp,
2034 char __user *ubuf,
2035 size_t max,
2036 loff_t *ppos)
2037{
2038 struct drm_device *dev = filp->private_data;
2039 drm_i915_private_t *dev_priv = dev->dev_private;
2040 char buf[80];
2041 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002042 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002043
Daniel Vetter004777c2012-08-09 15:07:01 +02002044 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2045 return -ENODEV;
2046
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002047 ret = mutex_lock_interruptible(&dev->struct_mutex);
2048 if (ret)
2049 return ret;
2050
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002051 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2052 mutex_unlock(&dev_priv->dev->struct_mutex);
2053
Akshay Joshi0206e352011-08-16 15:34:10 -04002054 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002055 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
2056 GEN6_MBC_SNPCR_SHIFT);
2057
Akshay Joshi0206e352011-08-16 15:34:10 -04002058 if (len > sizeof(buf))
2059 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002060
2061 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
2062}
2063
2064static ssize_t
2065i915_cache_sharing_write(struct file *filp,
2066 const char __user *ubuf,
2067 size_t cnt,
2068 loff_t *ppos)
2069{
2070 struct drm_device *dev = filp->private_data;
2071 struct drm_i915_private *dev_priv = dev->dev_private;
2072 char buf[20];
2073 u32 snpcr;
2074 int val = 1;
2075
Daniel Vetter004777c2012-08-09 15:07:01 +02002076 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2077 return -ENODEV;
2078
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002079 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04002080 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002081 return -EINVAL;
2082
2083 if (copy_from_user(buf, ubuf, cnt))
2084 return -EFAULT;
2085 buf[cnt] = 0;
2086
2087 val = simple_strtoul(buf, NULL, 0);
2088 }
2089
2090 if (val < 0 || val > 3)
2091 return -EINVAL;
2092
2093 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
2094
2095 /* Update the cache sharing policy here as well */
2096 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2097 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2098 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2099 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2100
2101 return cnt;
2102}
2103
2104static const struct file_operations i915_cache_sharing_fops = {
2105 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07002106 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002107 .read = i915_cache_sharing_read,
2108 .write = i915_cache_sharing_write,
2109 .llseek = default_llseek,
2110};
2111
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002112/* As the drm_debugfs_init() routines are called before dev->dev_private is
2113 * allocated we need to hook into the minor for release. */
2114static int
2115drm_add_fake_info_node(struct drm_minor *minor,
2116 struct dentry *ent,
2117 const void *key)
2118{
2119 struct drm_info_node *node;
2120
2121 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
2122 if (node == NULL) {
2123 debugfs_remove(ent);
2124 return -ENOMEM;
2125 }
2126
2127 node->minor = minor;
2128 node->dent = ent;
2129 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002130
2131 mutex_lock(&minor->debugfs_lock);
2132 list_add(&node->list, &minor->debugfs_list);
2133 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002134
2135 return 0;
2136}
2137
Ben Widawsky6d794d42011-04-25 11:25:56 -07002138static int i915_forcewake_open(struct inode *inode, struct file *file)
2139{
2140 struct drm_device *dev = inode->i_private;
2141 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002142
Daniel Vetter075edca2012-01-24 09:44:28 +01002143 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002144 return 0;
2145
Ben Widawsky6d794d42011-04-25 11:25:56 -07002146 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002147
2148 return 0;
2149}
2150
Ben Widawskyc43b5632012-04-16 14:07:40 -07002151static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002152{
2153 struct drm_device *dev = inode->i_private;
2154 struct drm_i915_private *dev_priv = dev->dev_private;
2155
Daniel Vetter075edca2012-01-24 09:44:28 +01002156 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002157 return 0;
2158
Ben Widawsky6d794d42011-04-25 11:25:56 -07002159 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002160
2161 return 0;
2162}
2163
2164static const struct file_operations i915_forcewake_fops = {
2165 .owner = THIS_MODULE,
2166 .open = i915_forcewake_open,
2167 .release = i915_forcewake_release,
2168};
2169
2170static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2171{
2172 struct drm_device *dev = minor->dev;
2173 struct dentry *ent;
2174
2175 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002176 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002177 root, dev,
2178 &i915_forcewake_fops);
2179 if (IS_ERR(ent))
2180 return PTR_ERR(ent);
2181
Ben Widawsky8eb57292011-05-11 15:10:58 -07002182 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002183}
2184
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002185static int i915_debugfs_create(struct dentry *root,
2186 struct drm_minor *minor,
2187 const char *name,
2188 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002189{
2190 struct drm_device *dev = minor->dev;
2191 struct dentry *ent;
2192
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002193 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002194 S_IRUGO | S_IWUSR,
2195 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002196 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002197 if (IS_ERR(ent))
2198 return PTR_ERR(ent);
2199
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002200 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002201}
2202
Ben Gamari27c202a2009-07-01 22:26:52 -04002203static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002204 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002205 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002206 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002207 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002208 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002209 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002210 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002211 {"i915_gem_request", i915_gem_request_info, 0},
2212 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002213 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002214 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002215 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2216 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2217 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002218 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2219 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2220 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2221 {"i915_inttoext_table", i915_inttoext_table, 0},
2222 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002223 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002224 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002225 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002226 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002227 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002228 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002229 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002230 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002231 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002232 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002233 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002234 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002235};
Ben Gamari27c202a2009-07-01 22:26:52 -04002236#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002237
Ben Gamari27c202a2009-07-01 22:26:52 -04002238int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002239{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002240 int ret;
2241
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002242 ret = i915_debugfs_create(minor->debugfs_root, minor,
2243 "i915_wedged",
2244 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002245 if (ret)
2246 return ret;
2247
Ben Widawsky6d794d42011-04-25 11:25:56 -07002248 ret = i915_forcewake_create(minor->debugfs_root, minor);
2249 if (ret)
2250 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002251
2252 ret = i915_debugfs_create(minor->debugfs_root, minor,
2253 "i915_max_freq",
2254 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002255 if (ret)
2256 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002257
2258 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002259 "i915_min_freq",
2260 &i915_min_freq_fops);
2261 if (ret)
2262 return ret;
2263
2264 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002265 "i915_cache_sharing",
2266 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002267 if (ret)
2268 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002269
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002270 ret = i915_debugfs_create(minor->debugfs_root, minor,
2271 "i915_ring_stop",
2272 &i915_ring_stop_fops);
2273 if (ret)
2274 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002275
Daniel Vetterd5442302012-04-27 15:17:40 +02002276 ret = i915_debugfs_create(minor->debugfs_root, minor,
Chris Wilsondd624af2013-01-15 12:39:35 +00002277 "i915_gem_drop_caches",
2278 &i915_drop_caches_fops);
2279 if (ret)
2280 return ret;
2281
2282 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetterd5442302012-04-27 15:17:40 +02002283 "i915_error_state",
2284 &i915_error_state_fops);
2285 if (ret)
2286 return ret;
2287
Mika Kuoppala40633212012-12-04 15:12:00 +02002288 ret = i915_debugfs_create(minor->debugfs_root, minor,
2289 "i915_next_seqno",
2290 &i915_next_seqno_fops);
2291 if (ret)
2292 return ret;
2293
Ben Gamari27c202a2009-07-01 22:26:52 -04002294 return drm_debugfs_create_files(i915_debugfs_list,
2295 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002296 minor->debugfs_root, minor);
2297}
2298
Ben Gamari27c202a2009-07-01 22:26:52 -04002299void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002300{
Ben Gamari27c202a2009-07-01 22:26:52 -04002301 drm_debugfs_remove_files(i915_debugfs_list,
2302 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002303 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2304 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002305 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2306 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002307 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2308 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002309 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2310 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002311 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2312 1, minor);
Chris Wilsondd624af2013-01-15 12:39:35 +00002313 drm_debugfs_remove_files((struct drm_info_list *) &i915_drop_caches_fops,
2314 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002315 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2316 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002317 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2318 1, minor);
Mika Kuoppala40633212012-12-04 15:12:00 +02002319 drm_debugfs_remove_files((struct drm_info_list *) &i915_next_seqno_fops,
2320 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002321}
2322
2323#endif /* CONFIG_DEBUG_FS */