blob: f94418bd1ed2efa12ce4df99eb169904f5cd29a3 [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
261 seq_printf(m, "%zu [%zu] gtt total\n",
262 dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
Chris Wilson73aa8082010-09-30 11:46:12 +0100263
264 mutex_unlock(&dev->struct_mutex);
265
266 return 0;
267}
268
Chris Wilson08c18322011-01-10 00:00:24 +0000269static int i915_gem_gtt_info(struct seq_file *m, void* data)
270{
271 struct drm_info_node *node = (struct drm_info_node *) m->private;
272 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100273 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000274 struct drm_i915_private *dev_priv = dev->dev_private;
275 struct drm_i915_gem_object *obj;
276 size_t total_obj_size, total_gtt_size;
277 int count, ret;
278
279 ret = mutex_lock_interruptible(&dev->struct_mutex);
280 if (ret)
281 return ret;
282
283 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200284 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100285 if (list == PINNED_LIST && obj->pin_count == 0)
286 continue;
287
Chris Wilson08c18322011-01-10 00:00:24 +0000288 seq_printf(m, " ");
289 describe_obj(m, obj);
290 seq_printf(m, "\n");
291 total_obj_size += obj->base.size;
292 total_gtt_size += obj->gtt_space->size;
293 count++;
294 }
295
296 mutex_unlock(&dev->struct_mutex);
297
298 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
299 count, total_obj_size, total_gtt_size);
300
301 return 0;
302}
303
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100304static int i915_gem_pageflip_info(struct seq_file *m, void *data)
305{
306 struct drm_info_node *node = (struct drm_info_node *) m->private;
307 struct drm_device *dev = node->minor->dev;
308 unsigned long flags;
309 struct intel_crtc *crtc;
310
311 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800312 const char pipe = pipe_name(crtc->pipe);
313 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100314 struct intel_unpin_work *work;
315
316 spin_lock_irqsave(&dev->event_lock, flags);
317 work = crtc->unpin_work;
318 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800319 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100320 pipe, plane);
321 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000322 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800323 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100324 pipe, plane);
325 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800326 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100327 pipe, plane);
328 }
329 if (work->enable_stall_check)
330 seq_printf(m, "Stall check enabled, ");
331 else
332 seq_printf(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000333 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100334
335 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000336 struct drm_i915_gem_object *obj = work->old_fb_obj;
337 if (obj)
338 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100339 }
340 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000341 struct drm_i915_gem_object *obj = work->pending_flip_obj;
342 if (obj)
343 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100344 }
345 }
346 spin_unlock_irqrestore(&dev->event_lock, flags);
347 }
348
349 return 0;
350}
351
Ben Gamari20172632009-02-17 20:08:50 -0500352static int i915_gem_request_info(struct seq_file *m, void *data)
353{
354 struct drm_info_node *node = (struct drm_info_node *) m->private;
355 struct drm_device *dev = node->minor->dev;
356 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100357 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500358 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100359 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100360
361 ret = mutex_lock_interruptible(&dev->struct_mutex);
362 if (ret)
363 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500364
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100365 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100366 for_each_ring(ring, dev_priv, i) {
367 if (list_empty(&ring->request_list))
368 continue;
369
370 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100371 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100372 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100373 list) {
374 seq_printf(m, " %d @ %d\n",
375 gem_request->seqno,
376 (int) (jiffies - gem_request->emitted_jiffies));
377 }
378 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500379 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100380 mutex_unlock(&dev->struct_mutex);
381
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100382 if (count == 0)
383 seq_printf(m, "No requests\n");
384
Ben Gamari20172632009-02-17 20:08:50 -0500385 return 0;
386}
387
Chris Wilsonb2223492010-10-27 15:27:33 +0100388static void i915_ring_seqno_info(struct seq_file *m,
389 struct intel_ring_buffer *ring)
390{
391 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200392 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100393 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100394 }
395}
396
Ben Gamari20172632009-02-17 20:08:50 -0500397static int i915_gem_seqno_info(struct seq_file *m, void *data)
398{
399 struct drm_info_node *node = (struct drm_info_node *) m->private;
400 struct drm_device *dev = node->minor->dev;
401 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100402 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000403 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100404
405 ret = mutex_lock_interruptible(&dev->struct_mutex);
406 if (ret)
407 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500408
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100409 for_each_ring(ring, dev_priv, i)
410 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100411
412 mutex_unlock(&dev->struct_mutex);
413
Ben Gamari20172632009-02-17 20:08:50 -0500414 return 0;
415}
416
417
418static int i915_interrupt_info(struct seq_file *m, void *data)
419{
420 struct drm_info_node *node = (struct drm_info_node *) m->private;
421 struct drm_device *dev = node->minor->dev;
422 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100423 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800424 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100425
426 ret = mutex_lock_interruptible(&dev->struct_mutex);
427 if (ret)
428 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500429
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700430 if (IS_VALLEYVIEW(dev)) {
431 seq_printf(m, "Display IER:\t%08x\n",
432 I915_READ(VLV_IER));
433 seq_printf(m, "Display IIR:\t%08x\n",
434 I915_READ(VLV_IIR));
435 seq_printf(m, "Display IIR_RW:\t%08x\n",
436 I915_READ(VLV_IIR_RW));
437 seq_printf(m, "Display IMR:\t%08x\n",
438 I915_READ(VLV_IMR));
439 for_each_pipe(pipe)
440 seq_printf(m, "Pipe %c stat:\t%08x\n",
441 pipe_name(pipe),
442 I915_READ(PIPESTAT(pipe)));
443
444 seq_printf(m, "Master IER:\t%08x\n",
445 I915_READ(VLV_MASTER_IER));
446
447 seq_printf(m, "Render IER:\t%08x\n",
448 I915_READ(GTIER));
449 seq_printf(m, "Render IIR:\t%08x\n",
450 I915_READ(GTIIR));
451 seq_printf(m, "Render IMR:\t%08x\n",
452 I915_READ(GTIMR));
453
454 seq_printf(m, "PM IER:\t\t%08x\n",
455 I915_READ(GEN6_PMIER));
456 seq_printf(m, "PM IIR:\t\t%08x\n",
457 I915_READ(GEN6_PMIIR));
458 seq_printf(m, "PM IMR:\t\t%08x\n",
459 I915_READ(GEN6_PMIMR));
460
461 seq_printf(m, "Port hotplug:\t%08x\n",
462 I915_READ(PORT_HOTPLUG_EN));
463 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
464 I915_READ(VLV_DPFLIPSTAT));
465 seq_printf(m, "DPINVGTT:\t%08x\n",
466 I915_READ(DPINVGTT));
467
468 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800469 seq_printf(m, "Interrupt enable: %08x\n",
470 I915_READ(IER));
471 seq_printf(m, "Interrupt identity: %08x\n",
472 I915_READ(IIR));
473 seq_printf(m, "Interrupt mask: %08x\n",
474 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800475 for_each_pipe(pipe)
476 seq_printf(m, "Pipe %c stat: %08x\n",
477 pipe_name(pipe),
478 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800479 } else {
480 seq_printf(m, "North Display Interrupt enable: %08x\n",
481 I915_READ(DEIER));
482 seq_printf(m, "North Display Interrupt identity: %08x\n",
483 I915_READ(DEIIR));
484 seq_printf(m, "North Display Interrupt mask: %08x\n",
485 I915_READ(DEIMR));
486 seq_printf(m, "South Display Interrupt enable: %08x\n",
487 I915_READ(SDEIER));
488 seq_printf(m, "South Display Interrupt identity: %08x\n",
489 I915_READ(SDEIIR));
490 seq_printf(m, "South Display Interrupt mask: %08x\n",
491 I915_READ(SDEIMR));
492 seq_printf(m, "Graphics Interrupt enable: %08x\n",
493 I915_READ(GTIER));
494 seq_printf(m, "Graphics Interrupt identity: %08x\n",
495 I915_READ(GTIIR));
496 seq_printf(m, "Graphics Interrupt mask: %08x\n",
497 I915_READ(GTIMR));
498 }
Ben Gamari20172632009-02-17 20:08:50 -0500499 seq_printf(m, "Interrupts received: %d\n",
500 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100501 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700502 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100503 seq_printf(m,
504 "Graphics Interrupt mask (%s): %08x\n",
505 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000506 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100507 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000508 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100509 mutex_unlock(&dev->struct_mutex);
510
Ben Gamari20172632009-02-17 20:08:50 -0500511 return 0;
512}
513
Chris Wilsona6172a82009-02-11 14:26:38 +0000514static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
515{
516 struct drm_info_node *node = (struct drm_info_node *) m->private;
517 struct drm_device *dev = node->minor->dev;
518 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100519 int i, ret;
520
521 ret = mutex_lock_interruptible(&dev->struct_mutex);
522 if (ret)
523 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000524
525 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
526 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
527 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000528 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000529
Chris Wilson6c085a72012-08-20 11:40:46 +0200530 seq_printf(m, "Fence %d, pin count = %d, object = ",
531 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100532 if (obj == NULL)
533 seq_printf(m, "unused");
534 else
Chris Wilson05394f32010-11-08 19:18:58 +0000535 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100536 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000537 }
538
Chris Wilson05394f32010-11-08 19:18:58 +0000539 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000540 return 0;
541}
542
Ben Gamari20172632009-02-17 20:08:50 -0500543static int i915_hws_info(struct seq_file *m, void *data)
544{
545 struct drm_info_node *node = (struct drm_info_node *) m->private;
546 struct drm_device *dev = node->minor->dev;
547 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100548 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100549 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100550 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500551
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000552 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100553 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500554 if (hws == NULL)
555 return 0;
556
557 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
558 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
559 i * 4,
560 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
561 }
562 return 0;
563}
564
Chris Wilsone5c65262010-11-01 11:35:28 +0000565static const char *ring_str(int ring)
566{
567 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100568 case RCS: return "render";
569 case VCS: return "bsd";
570 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000571 default: return "";
572 }
573}
574
Chris Wilson9df30792010-02-18 10:24:56 +0000575static const char *pin_flag(int pinned)
576{
577 if (pinned > 0)
578 return " P";
579 else if (pinned < 0)
580 return " p";
581 else
582 return "";
583}
584
585static const char *tiling_flag(int tiling)
586{
587 switch (tiling) {
588 default:
589 case I915_TILING_NONE: return "";
590 case I915_TILING_X: return " X";
591 case I915_TILING_Y: return " Y";
592 }
593}
594
595static const char *dirty_flag(int dirty)
596{
597 return dirty ? " dirty" : "";
598}
599
600static const char *purgeable_flag(int purgeable)
601{
602 return purgeable ? " purgeable" : "";
603}
604
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000605static void print_error_buffers(struct seq_file *m,
606 const char *name,
607 struct drm_i915_error_buffer *err,
608 int count)
609{
610 seq_printf(m, "%s [%d]:\n", name, count);
611
612 while (count--) {
Chris Wilson04b97b32012-11-27 17:06:53 +0000613 seq_printf(m, " %08x %8u %02x %02x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000614 err->gtt_offset,
615 err->size,
616 err->read_domains,
617 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100618 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000619 pin_flag(err->pinned),
620 tiling_flag(err->tiling),
621 dirty_flag(err->dirty),
622 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100623 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000624 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700625 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000626
627 if (err->name)
628 seq_printf(m, " (name: %d)", err->name);
629 if (err->fence_reg != I915_FENCE_REG_NONE)
630 seq_printf(m, " (fence: %d)", err->fence_reg);
631
632 seq_printf(m, "\n");
633 err++;
634 }
635}
636
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100637static void i915_ring_error_state(struct seq_file *m,
638 struct drm_device *dev,
639 struct drm_i915_error_state *error,
640 unsigned ring)
641{
Ben Widawskyec34a012012-04-03 23:03:00 -0700642 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100643 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100644 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
645 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100646 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
647 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
648 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
649 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Ben Widawsky050ee912012-08-22 11:32:15 -0700650 if (ring == RCS && INTEL_INFO(dev)->gen >= 4)
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100651 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Ben Widawsky050ee912012-08-22 11:32:15 -0700652
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100653 if (INTEL_INFO(dev)->gen >= 4)
654 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
655 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200656 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100657 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100658 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100659 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Chris Wilsondf2b23d2012-11-27 17:06:54 +0000660 seq_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
661 error->semaphore_mboxes[ring][0],
662 error->semaphore_seqno[ring][0]);
663 seq_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
664 error->semaphore_mboxes[ring][1],
665 error->semaphore_seqno[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100666 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100667 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Ben Widawsky9574b3f2012-04-26 16:03:01 -0700668 seq_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100669 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
670 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100671}
672
Daniel Vetterd5442302012-04-27 15:17:40 +0200673struct i915_error_state_file_priv {
674 struct drm_device *dev;
675 struct drm_i915_error_state *error;
676};
677
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700678static int i915_error_state(struct seq_file *m, void *unused)
679{
Daniel Vetterd5442302012-04-27 15:17:40 +0200680 struct i915_error_state_file_priv *error_priv = m->private;
681 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700682 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200683 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100684 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000685 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700686
Daniel Vetter742cbee2012-04-27 15:17:39 +0200687 if (!error) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700688 seq_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200689 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700690 }
691
Jesse Barnes8a905232009-07-11 16:48:03 -0400692 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
693 error->time.tv_usec);
Chris Wilson9df30792010-02-18 10:24:56 +0000694 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100695 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700696 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100697 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700698 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000699
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100700 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100701 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
702
Ben Widawsky050ee912012-08-22 11:32:15 -0700703 for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
704 seq_printf(m, " INSTDONE_%d: 0x%08x\n", i, error->extra_instdone[i]);
705
Daniel Vetter33f3f512011-12-14 13:57:39 +0100706 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100707 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100708 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
709 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100710
Ben Widawsky71e172e2012-08-20 16:15:13 -0700711 if (INTEL_INFO(dev)->gen == 7)
712 seq_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
713
Chris Wilsonb4519512012-05-11 14:29:30 +0100714 for_each_ring(ring, dev_priv, i)
715 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100716
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000717 if (error->active_bo)
718 print_error_buffers(m, "Active",
719 error->active_bo,
720 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000721
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000722 if (error->pinned_bo)
723 print_error_buffers(m, "Pinned",
724 error->pinned_bo,
725 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000726
Chris Wilson52d39a22012-02-15 11:25:37 +0000727 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
728 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000729
Chris Wilson52d39a22012-02-15 11:25:37 +0000730 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000731 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
732 dev_priv->ring[i].name,
733 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000734 offset = 0;
735 for (page = 0; page < obj->page_count; page++) {
736 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
737 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
738 offset += 4;
739 }
740 }
741 }
Chris Wilson9df30792010-02-18 10:24:56 +0000742
Chris Wilson52d39a22012-02-15 11:25:37 +0000743 if (error->ring[i].num_requests) {
744 seq_printf(m, "%s --- %d requests\n",
745 dev_priv->ring[i].name,
746 error->ring[i].num_requests);
747 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000748 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000749 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000750 error->ring[i].requests[j].jiffies,
751 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000752 }
753 }
754
755 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000756 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
757 dev_priv->ring[i].name,
758 obj->gtt_offset);
759 offset = 0;
760 for (page = 0; page < obj->page_count; page++) {
761 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
762 seq_printf(m, "%08x : %08x\n",
763 offset,
764 obj->pages[page][elt]);
765 offset += 4;
766 }
Chris Wilson9df30792010-02-18 10:24:56 +0000767 }
768 }
769 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700770
Chris Wilson6ef3d422010-08-04 20:26:07 +0100771 if (error->overlay)
772 intel_overlay_print_error_state(m, error->overlay);
773
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000774 if (error->display)
775 intel_display_print_error_state(m, dev, error->display);
776
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700777 return 0;
778}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700779
Daniel Vetterd5442302012-04-27 15:17:40 +0200780static ssize_t
781i915_error_state_write(struct file *filp,
782 const char __user *ubuf,
783 size_t cnt,
784 loff_t *ppos)
785{
786 struct seq_file *m = filp->private_data;
787 struct i915_error_state_file_priv *error_priv = m->private;
788 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200789 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200790
791 DRM_DEBUG_DRIVER("Resetting error state\n");
792
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200793 ret = mutex_lock_interruptible(&dev->struct_mutex);
794 if (ret)
795 return ret;
796
Daniel Vetterd5442302012-04-27 15:17:40 +0200797 i915_destroy_error_state(dev);
798 mutex_unlock(&dev->struct_mutex);
799
800 return cnt;
801}
802
803static int i915_error_state_open(struct inode *inode, struct file *file)
804{
805 struct drm_device *dev = inode->i_private;
806 drm_i915_private_t *dev_priv = dev->dev_private;
807 struct i915_error_state_file_priv *error_priv;
808 unsigned long flags;
809
810 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
811 if (!error_priv)
812 return -ENOMEM;
813
814 error_priv->dev = dev;
815
816 spin_lock_irqsave(&dev_priv->error_lock, flags);
817 error_priv->error = dev_priv->first_error;
818 if (error_priv->error)
819 kref_get(&error_priv->error->ref);
820 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
821
822 return single_open(file, i915_error_state, error_priv);
823}
824
825static int i915_error_state_release(struct inode *inode, struct file *file)
826{
827 struct seq_file *m = file->private_data;
828 struct i915_error_state_file_priv *error_priv = m->private;
829
830 if (error_priv->error)
831 kref_put(&error_priv->error->ref, i915_error_state_free);
832 kfree(error_priv);
833
834 return single_release(inode, file);
835}
836
837static const struct file_operations i915_error_state_fops = {
838 .owner = THIS_MODULE,
839 .open = i915_error_state_open,
840 .read = seq_read,
841 .write = i915_error_state_write,
842 .llseek = default_llseek,
843 .release = i915_error_state_release,
844};
845
Mika Kuoppala40633212012-12-04 15:12:00 +0200846static ssize_t
847i915_next_seqno_read(struct file *filp,
848 char __user *ubuf,
849 size_t max,
850 loff_t *ppos)
851{
852 struct drm_device *dev = filp->private_data;
853 drm_i915_private_t *dev_priv = dev->dev_private;
854 char buf[80];
855 int len;
856 int ret;
857
858 ret = mutex_lock_interruptible(&dev->struct_mutex);
859 if (ret)
860 return ret;
861
862 len = snprintf(buf, sizeof(buf),
863 "next_seqno : 0x%x\n",
864 dev_priv->next_seqno);
865
866 mutex_unlock(&dev->struct_mutex);
867
868 if (len > sizeof(buf))
869 len = sizeof(buf);
870
871 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
872}
873
874static ssize_t
875i915_next_seqno_write(struct file *filp,
876 const char __user *ubuf,
877 size_t cnt,
878 loff_t *ppos)
879{
880 struct drm_device *dev = filp->private_data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200881 char buf[20];
882 u32 val = 1;
883 int ret;
884
885 if (cnt > 0) {
886 if (cnt > sizeof(buf) - 1)
887 return -EINVAL;
888
889 if (copy_from_user(buf, ubuf, cnt))
890 return -EFAULT;
891 buf[cnt] = 0;
892
893 ret = kstrtouint(buf, 0, &val);
894 if (ret < 0)
895 return ret;
896 }
897
Mika Kuoppala40633212012-12-04 15:12:00 +0200898 ret = mutex_lock_interruptible(&dev->struct_mutex);
899 if (ret)
900 return ret;
901
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200902 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200903
904 mutex_unlock(&dev->struct_mutex);
905
906 return ret ?: cnt;
907}
908
909static const struct file_operations i915_next_seqno_fops = {
910 .owner = THIS_MODULE,
911 .open = simple_open,
912 .read = i915_next_seqno_read,
913 .write = i915_next_seqno_write,
914 .llseek = default_llseek,
915};
916
Jesse Barnesf97108d2010-01-29 11:27:07 -0800917static int i915_rstdby_delays(struct seq_file *m, void *unused)
918{
919 struct drm_info_node *node = (struct drm_info_node *) m->private;
920 struct drm_device *dev = node->minor->dev;
921 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700922 u16 crstanddelay;
923 int ret;
924
925 ret = mutex_lock_interruptible(&dev->struct_mutex);
926 if (ret)
927 return ret;
928
929 crstanddelay = I915_READ16(CRSTANDVID);
930
931 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800932
933 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
934
935 return 0;
936}
937
938static int i915_cur_delayinfo(struct seq_file *m, void *unused)
939{
940 struct drm_info_node *node = (struct drm_info_node *) m->private;
941 struct drm_device *dev = node->minor->dev;
942 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100943 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800944
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800945 if (IS_GEN5(dev)) {
946 u16 rgvswctl = I915_READ16(MEMSWCTL);
947 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
948
949 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
950 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
951 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
952 MEMSTAT_VID_SHIFT);
953 seq_printf(m, "Current P-state: %d\n",
954 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700955 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800956 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
957 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
958 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800959 u32 rpstat;
960 u32 rpupei, rpcurup, rpprevup;
961 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800962 int max_freq;
963
964 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100965 ret = mutex_lock_interruptible(&dev->struct_mutex);
966 if (ret)
967 return ret;
968
Ben Widawskyfcca7922011-04-25 11:23:07 -0700969 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800970
Jesse Barnesccab5c82011-01-18 15:49:25 -0800971 rpstat = I915_READ(GEN6_RPSTAT1);
972 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
973 rpcurup = I915_READ(GEN6_RP_CUR_UP);
974 rpprevup = I915_READ(GEN6_RP_PREV_UP);
975 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
976 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
977 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
978
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100979 gen6_gt_force_wake_put(dev_priv);
980 mutex_unlock(&dev->struct_mutex);
981
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800982 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800983 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800984 seq_printf(m, "Render p-state ratio: %d\n",
985 (gt_perf_status & 0xff00) >> 8);
986 seq_printf(m, "Render p-state VID: %d\n",
987 gt_perf_status & 0xff);
988 seq_printf(m, "Render p-state limit: %d\n",
989 rp_state_limits & 0xff);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800990 seq_printf(m, "CAGF: %dMHz\n", ((rpstat & GEN6_CAGF_MASK) >>
Ben Widawskyc8735b02012-09-07 19:43:39 -0700991 GEN6_CAGF_SHIFT) * GT_FREQUENCY_MULTIPLIER);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800992 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
993 GEN6_CURICONT_MASK);
994 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
995 GEN6_CURBSYTAVG_MASK);
996 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
997 GEN6_CURBSYTAVG_MASK);
998 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
999 GEN6_CURIAVG_MASK);
1000 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1001 GEN6_CURBSYTAVG_MASK);
1002 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1003 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001004
1005 max_freq = (rp_state_cap & 0xff0000) >> 16;
1006 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001007 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001008
1009 max_freq = (rp_state_cap & 0xff00) >> 8;
1010 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001011 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001012
1013 max_freq = rp_state_cap & 0xff;
1014 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001015 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001016 } else {
1017 seq_printf(m, "no P-state info available\n");
1018 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001019
1020 return 0;
1021}
1022
1023static int i915_delayfreq_table(struct seq_file *m, void *unused)
1024{
1025 struct drm_info_node *node = (struct drm_info_node *) m->private;
1026 struct drm_device *dev = node->minor->dev;
1027 drm_i915_private_t *dev_priv = dev->dev_private;
1028 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001029 int ret, i;
1030
1031 ret = mutex_lock_interruptible(&dev->struct_mutex);
1032 if (ret)
1033 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001034
1035 for (i = 0; i < 16; i++) {
1036 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001037 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1038 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001039 }
1040
Ben Widawsky616fdb52011-10-05 11:44:54 -07001041 mutex_unlock(&dev->struct_mutex);
1042
Jesse Barnesf97108d2010-01-29 11:27:07 -08001043 return 0;
1044}
1045
1046static inline int MAP_TO_MV(int map)
1047{
1048 return 1250 - (map * 25);
1049}
1050
1051static int i915_inttoext_table(struct seq_file *m, void *unused)
1052{
1053 struct drm_info_node *node = (struct drm_info_node *) m->private;
1054 struct drm_device *dev = node->minor->dev;
1055 drm_i915_private_t *dev_priv = dev->dev_private;
1056 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001057 int ret, i;
1058
1059 ret = mutex_lock_interruptible(&dev->struct_mutex);
1060 if (ret)
1061 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001062
1063 for (i = 1; i <= 32; i++) {
1064 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1065 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1066 }
1067
Ben Widawsky616fdb52011-10-05 11:44:54 -07001068 mutex_unlock(&dev->struct_mutex);
1069
Jesse Barnesf97108d2010-01-29 11:27:07 -08001070 return 0;
1071}
1072
Ben Widawsky4d855292011-12-12 19:34:16 -08001073static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001074{
1075 struct drm_info_node *node = (struct drm_info_node *) m->private;
1076 struct drm_device *dev = node->minor->dev;
1077 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001078 u32 rgvmodectl, rstdbyctl;
1079 u16 crstandvid;
1080 int ret;
1081
1082 ret = mutex_lock_interruptible(&dev->struct_mutex);
1083 if (ret)
1084 return ret;
1085
1086 rgvmodectl = I915_READ(MEMMODECTL);
1087 rstdbyctl = I915_READ(RSTDBYCTL);
1088 crstandvid = I915_READ16(CRSTANDVID);
1089
1090 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001091
1092 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1093 "yes" : "no");
1094 seq_printf(m, "Boost freq: %d\n",
1095 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1096 MEMMODE_BOOST_FREQ_SHIFT);
1097 seq_printf(m, "HW control enabled: %s\n",
1098 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1099 seq_printf(m, "SW control enabled: %s\n",
1100 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1101 seq_printf(m, "Gated voltage change: %s\n",
1102 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1103 seq_printf(m, "Starting frequency: P%d\n",
1104 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001105 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001106 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001107 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1108 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1109 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1110 seq_printf(m, "Render standby enabled: %s\n",
1111 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001112 seq_printf(m, "Current RS state: ");
1113 switch (rstdbyctl & RSX_STATUS_MASK) {
1114 case RSX_STATUS_ON:
1115 seq_printf(m, "on\n");
1116 break;
1117 case RSX_STATUS_RC1:
1118 seq_printf(m, "RC1\n");
1119 break;
1120 case RSX_STATUS_RC1E:
1121 seq_printf(m, "RC1E\n");
1122 break;
1123 case RSX_STATUS_RS1:
1124 seq_printf(m, "RS1\n");
1125 break;
1126 case RSX_STATUS_RS2:
1127 seq_printf(m, "RS2 (RC6)\n");
1128 break;
1129 case RSX_STATUS_RS3:
1130 seq_printf(m, "RC3 (RC6+)\n");
1131 break;
1132 default:
1133 seq_printf(m, "unknown\n");
1134 break;
1135 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001136
1137 return 0;
1138}
1139
Ben Widawsky4d855292011-12-12 19:34:16 -08001140static int gen6_drpc_info(struct seq_file *m)
1141{
1142
1143 struct drm_info_node *node = (struct drm_info_node *) m->private;
1144 struct drm_device *dev = node->minor->dev;
1145 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001146 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001147 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001148 int count=0, ret;
1149
1150
1151 ret = mutex_lock_interruptible(&dev->struct_mutex);
1152 if (ret)
1153 return ret;
1154
Daniel Vetter93b525d2012-01-25 13:52:43 +01001155 spin_lock_irq(&dev_priv->gt_lock);
1156 forcewake_count = dev_priv->forcewake_count;
1157 spin_unlock_irq(&dev_priv->gt_lock);
1158
1159 if (forcewake_count) {
1160 seq_printf(m, "RC information inaccurate because somebody "
1161 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001162 } else {
1163 /* NB: we cannot use forcewake, else we read the wrong values */
1164 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1165 udelay(10);
1166 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1167 }
1168
1169 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1170 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1171
1172 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1173 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1174 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001175 mutex_lock(&dev_priv->rps.hw_lock);
1176 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1177 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001178
1179 seq_printf(m, "Video Turbo Mode: %s\n",
1180 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1181 seq_printf(m, "HW control enabled: %s\n",
1182 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1183 seq_printf(m, "SW control enabled: %s\n",
1184 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1185 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001186 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001187 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1188 seq_printf(m, "RC6 Enabled: %s\n",
1189 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1190 seq_printf(m, "Deep RC6 Enabled: %s\n",
1191 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1192 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1193 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1194 seq_printf(m, "Current RC state: ");
1195 switch (gt_core_status & GEN6_RCn_MASK) {
1196 case GEN6_RC0:
1197 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1198 seq_printf(m, "Core Power Down\n");
1199 else
1200 seq_printf(m, "on\n");
1201 break;
1202 case GEN6_RC3:
1203 seq_printf(m, "RC3\n");
1204 break;
1205 case GEN6_RC6:
1206 seq_printf(m, "RC6\n");
1207 break;
1208 case GEN6_RC7:
1209 seq_printf(m, "RC7\n");
1210 break;
1211 default:
1212 seq_printf(m, "Unknown\n");
1213 break;
1214 }
1215
1216 seq_printf(m, "Core Power Down: %s\n",
1217 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001218
1219 /* Not exactly sure what this is */
1220 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1221 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1222 seq_printf(m, "RC6 residency since boot: %u\n",
1223 I915_READ(GEN6_GT_GFX_RC6));
1224 seq_printf(m, "RC6+ residency since boot: %u\n",
1225 I915_READ(GEN6_GT_GFX_RC6p));
1226 seq_printf(m, "RC6++ residency since boot: %u\n",
1227 I915_READ(GEN6_GT_GFX_RC6pp));
1228
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001229 seq_printf(m, "RC6 voltage: %dmV\n",
1230 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1231 seq_printf(m, "RC6+ voltage: %dmV\n",
1232 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1233 seq_printf(m, "RC6++ voltage: %dmV\n",
1234 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001235 return 0;
1236}
1237
1238static int i915_drpc_info(struct seq_file *m, void *unused)
1239{
1240 struct drm_info_node *node = (struct drm_info_node *) m->private;
1241 struct drm_device *dev = node->minor->dev;
1242
1243 if (IS_GEN6(dev) || IS_GEN7(dev))
1244 return gen6_drpc_info(m);
1245 else
1246 return ironlake_drpc_info(m);
1247}
1248
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001249static int i915_fbc_status(struct seq_file *m, void *unused)
1250{
1251 struct drm_info_node *node = (struct drm_info_node *) m->private;
1252 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001253 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001254
Adam Jacksonee5382a2010-04-23 11:17:39 -04001255 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001256 seq_printf(m, "FBC unsupported on this chipset\n");
1257 return 0;
1258 }
1259
Adam Jacksonee5382a2010-04-23 11:17:39 -04001260 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001261 seq_printf(m, "FBC enabled\n");
1262 } else {
1263 seq_printf(m, "FBC disabled: ");
1264 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001265 case FBC_NO_OUTPUT:
1266 seq_printf(m, "no outputs");
1267 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001268 case FBC_STOLEN_TOO_SMALL:
1269 seq_printf(m, "not enough stolen memory");
1270 break;
1271 case FBC_UNSUPPORTED_MODE:
1272 seq_printf(m, "mode not supported");
1273 break;
1274 case FBC_MODE_TOO_LARGE:
1275 seq_printf(m, "mode too large");
1276 break;
1277 case FBC_BAD_PLANE:
1278 seq_printf(m, "FBC unsupported on plane");
1279 break;
1280 case FBC_NOT_TILED:
1281 seq_printf(m, "scanout buffer not tiled");
1282 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001283 case FBC_MULTIPLE_PIPES:
1284 seq_printf(m, "multiple pipes are enabled");
1285 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001286 case FBC_MODULE_PARAM:
1287 seq_printf(m, "disabled per module param (default off)");
1288 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001289 default:
1290 seq_printf(m, "unknown reason");
1291 }
1292 seq_printf(m, "\n");
1293 }
1294 return 0;
1295}
1296
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001297static int i915_sr_status(struct seq_file *m, void *unused)
1298{
1299 struct drm_info_node *node = (struct drm_info_node *) m->private;
1300 struct drm_device *dev = node->minor->dev;
1301 drm_i915_private_t *dev_priv = dev->dev_private;
1302 bool sr_enabled = false;
1303
Yuanhan Liu13982612010-12-15 15:42:31 +08001304 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001305 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001306 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001307 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1308 else if (IS_I915GM(dev))
1309 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1310 else if (IS_PINEVIEW(dev))
1311 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1312
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001313 seq_printf(m, "self-refresh: %s\n",
1314 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001315
1316 return 0;
1317}
1318
Jesse Barnes7648fa92010-05-20 14:28:11 -07001319static int i915_emon_status(struct seq_file *m, void *unused)
1320{
1321 struct drm_info_node *node = (struct drm_info_node *) m->private;
1322 struct drm_device *dev = node->minor->dev;
1323 drm_i915_private_t *dev_priv = dev->dev_private;
1324 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001325 int ret;
1326
Chris Wilson582be6b2012-04-30 19:35:02 +01001327 if (!IS_GEN5(dev))
1328 return -ENODEV;
1329
Chris Wilsonde227ef2010-07-03 07:58:38 +01001330 ret = mutex_lock_interruptible(&dev->struct_mutex);
1331 if (ret)
1332 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001333
1334 temp = i915_mch_val(dev_priv);
1335 chipset = i915_chipset_val(dev_priv);
1336 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001337 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001338
1339 seq_printf(m, "GMCH temp: %ld\n", temp);
1340 seq_printf(m, "Chipset power: %ld\n", chipset);
1341 seq_printf(m, "GFX power: %ld\n", gfx);
1342 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1343
1344 return 0;
1345}
1346
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001347static int i915_ring_freq_table(struct seq_file *m, void *unused)
1348{
1349 struct drm_info_node *node = (struct drm_info_node *) m->private;
1350 struct drm_device *dev = node->minor->dev;
1351 drm_i915_private_t *dev_priv = dev->dev_private;
1352 int ret;
1353 int gpu_freq, ia_freq;
1354
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001355 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001356 seq_printf(m, "unsupported on this chipset\n");
1357 return 0;
1358 }
1359
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001360 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001361 if (ret)
1362 return ret;
1363
1364 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1365
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001366 for (gpu_freq = dev_priv->rps.min_delay;
1367 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001368 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001369 ia_freq = gpu_freq;
1370 sandybridge_pcode_read(dev_priv,
1371 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1372 &ia_freq);
Ben Widawskyc8735b02012-09-07 19:43:39 -07001373 seq_printf(m, "%d\t\t%d\n", gpu_freq * GT_FREQUENCY_MULTIPLIER, ia_freq * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001374 }
1375
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001376 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001377
1378 return 0;
1379}
1380
Jesse Barnes7648fa92010-05-20 14:28:11 -07001381static int i915_gfxec(struct seq_file *m, void *unused)
1382{
1383 struct drm_info_node *node = (struct drm_info_node *) m->private;
1384 struct drm_device *dev = node->minor->dev;
1385 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001386 int ret;
1387
1388 ret = mutex_lock_interruptible(&dev->struct_mutex);
1389 if (ret)
1390 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001391
1392 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1393
Ben Widawsky616fdb52011-10-05 11:44:54 -07001394 mutex_unlock(&dev->struct_mutex);
1395
Jesse Barnes7648fa92010-05-20 14:28:11 -07001396 return 0;
1397}
1398
Chris Wilson44834a62010-08-19 16:09:23 +01001399static int i915_opregion(struct seq_file *m, void *unused)
1400{
1401 struct drm_info_node *node = (struct drm_info_node *) m->private;
1402 struct drm_device *dev = node->minor->dev;
1403 drm_i915_private_t *dev_priv = dev->dev_private;
1404 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001405 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001406 int ret;
1407
Daniel Vetter0d38f002012-04-21 22:49:10 +02001408 if (data == NULL)
1409 return -ENOMEM;
1410
Chris Wilson44834a62010-08-19 16:09:23 +01001411 ret = mutex_lock_interruptible(&dev->struct_mutex);
1412 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001413 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001414
Daniel Vetter0d38f002012-04-21 22:49:10 +02001415 if (opregion->header) {
1416 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1417 seq_write(m, data, OPREGION_SIZE);
1418 }
Chris Wilson44834a62010-08-19 16:09:23 +01001419
1420 mutex_unlock(&dev->struct_mutex);
1421
Daniel Vetter0d38f002012-04-21 22:49:10 +02001422out:
1423 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001424 return 0;
1425}
1426
Chris Wilson37811fc2010-08-25 22:45:57 +01001427static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1428{
1429 struct drm_info_node *node = (struct drm_info_node *) m->private;
1430 struct drm_device *dev = node->minor->dev;
1431 drm_i915_private_t *dev_priv = dev->dev_private;
1432 struct intel_fbdev *ifbdev;
1433 struct intel_framebuffer *fb;
1434 int ret;
1435
1436 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1437 if (ret)
1438 return ret;
1439
1440 ifbdev = dev_priv->fbdev;
1441 fb = to_intel_framebuffer(ifbdev->helper.fb);
1442
1443 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, obj ",
1444 fb->base.width,
1445 fb->base.height,
1446 fb->base.depth,
1447 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001448 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001449 seq_printf(m, "\n");
1450
1451 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1452 if (&fb->base == ifbdev->helper.fb)
1453 continue;
1454
1455 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, obj ",
1456 fb->base.width,
1457 fb->base.height,
1458 fb->base.depth,
1459 fb->base.bits_per_pixel);
Chris Wilson05394f32010-11-08 19:18:58 +00001460 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001461 seq_printf(m, "\n");
1462 }
1463
1464 mutex_unlock(&dev->mode_config.mutex);
1465
1466 return 0;
1467}
1468
Ben Widawskye76d3632011-03-19 18:14:29 -07001469static int i915_context_status(struct seq_file *m, void *unused)
1470{
1471 struct drm_info_node *node = (struct drm_info_node *) m->private;
1472 struct drm_device *dev = node->minor->dev;
1473 drm_i915_private_t *dev_priv = dev->dev_private;
1474 int ret;
1475
1476 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1477 if (ret)
1478 return ret;
1479
Daniel Vetter3e373942012-11-02 19:55:04 +01001480 if (dev_priv->ips.pwrctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001481 seq_printf(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001482 describe_obj(m, dev_priv->ips.pwrctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001483 seq_printf(m, "\n");
1484 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001485
Daniel Vetter3e373942012-11-02 19:55:04 +01001486 if (dev_priv->ips.renderctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001487 seq_printf(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001488 describe_obj(m, dev_priv->ips.renderctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001489 seq_printf(m, "\n");
1490 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001491
1492 mutex_unlock(&dev->mode_config.mutex);
1493
1494 return 0;
1495}
1496
Ben Widawsky6d794d42011-04-25 11:25:56 -07001497static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1498{
1499 struct drm_info_node *node = (struct drm_info_node *) m->private;
1500 struct drm_device *dev = node->minor->dev;
1501 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001502 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001503
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001504 spin_lock_irq(&dev_priv->gt_lock);
1505 forcewake_count = dev_priv->forcewake_count;
1506 spin_unlock_irq(&dev_priv->gt_lock);
1507
1508 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001509
1510 return 0;
1511}
1512
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001513static const char *swizzle_string(unsigned swizzle)
1514{
1515 switch(swizzle) {
1516 case I915_BIT_6_SWIZZLE_NONE:
1517 return "none";
1518 case I915_BIT_6_SWIZZLE_9:
1519 return "bit9";
1520 case I915_BIT_6_SWIZZLE_9_10:
1521 return "bit9/bit10";
1522 case I915_BIT_6_SWIZZLE_9_11:
1523 return "bit9/bit11";
1524 case I915_BIT_6_SWIZZLE_9_10_11:
1525 return "bit9/bit10/bit11";
1526 case I915_BIT_6_SWIZZLE_9_17:
1527 return "bit9/bit17";
1528 case I915_BIT_6_SWIZZLE_9_10_17:
1529 return "bit9/bit10/bit17";
1530 case I915_BIT_6_SWIZZLE_UNKNOWN:
1531 return "unkown";
1532 }
1533
1534 return "bug";
1535}
1536
1537static int i915_swizzle_info(struct seq_file *m, void *data)
1538{
1539 struct drm_info_node *node = (struct drm_info_node *) m->private;
1540 struct drm_device *dev = node->minor->dev;
1541 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001542 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001543
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001544 ret = mutex_lock_interruptible(&dev->struct_mutex);
1545 if (ret)
1546 return ret;
1547
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001548 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1549 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1550 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1551 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1552
1553 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1554 seq_printf(m, "DDC = 0x%08x\n",
1555 I915_READ(DCC));
1556 seq_printf(m, "C0DRB3 = 0x%04x\n",
1557 I915_READ16(C0DRB3));
1558 seq_printf(m, "C1DRB3 = 0x%04x\n",
1559 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001560 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1561 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1562 I915_READ(MAD_DIMM_C0));
1563 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1564 I915_READ(MAD_DIMM_C1));
1565 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1566 I915_READ(MAD_DIMM_C2));
1567 seq_printf(m, "TILECTL = 0x%08x\n",
1568 I915_READ(TILECTL));
1569 seq_printf(m, "ARB_MODE = 0x%08x\n",
1570 I915_READ(ARB_MODE));
1571 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1572 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001573 }
1574 mutex_unlock(&dev->struct_mutex);
1575
1576 return 0;
1577}
1578
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001579static int i915_ppgtt_info(struct seq_file *m, void *data)
1580{
1581 struct drm_info_node *node = (struct drm_info_node *) m->private;
1582 struct drm_device *dev = node->minor->dev;
1583 struct drm_i915_private *dev_priv = dev->dev_private;
1584 struct intel_ring_buffer *ring;
1585 int i, ret;
1586
1587
1588 ret = mutex_lock_interruptible(&dev->struct_mutex);
1589 if (ret)
1590 return ret;
1591 if (INTEL_INFO(dev)->gen == 6)
1592 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1593
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001594 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001595 seq_printf(m, "%s\n", ring->name);
1596 if (INTEL_INFO(dev)->gen == 7)
1597 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1598 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1599 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1600 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1601 }
1602 if (dev_priv->mm.aliasing_ppgtt) {
1603 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1604
1605 seq_printf(m, "aliasing PPGTT:\n");
1606 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1607 }
1608 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1609 mutex_unlock(&dev->struct_mutex);
1610
1611 return 0;
1612}
1613
Jesse Barnes57f350b2012-03-28 13:39:25 -07001614static int i915_dpio_info(struct seq_file *m, void *data)
1615{
1616 struct drm_info_node *node = (struct drm_info_node *) m->private;
1617 struct drm_device *dev = node->minor->dev;
1618 struct drm_i915_private *dev_priv = dev->dev_private;
1619 int ret;
1620
1621
1622 if (!IS_VALLEYVIEW(dev)) {
1623 seq_printf(m, "unsupported\n");
1624 return 0;
1625 }
1626
Daniel Vetter09153002012-12-12 14:06:44 +01001627 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001628 if (ret)
1629 return ret;
1630
1631 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1632
1633 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1634 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1635 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1636 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1637
1638 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1639 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1640 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1641 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1642
1643 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1644 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1645 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1646 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1647
1648 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1649 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1650 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1651 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1652
1653 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1654 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1655
Daniel Vetter09153002012-12-12 14:06:44 +01001656 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001657
1658 return 0;
1659}
1660
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001661static ssize_t
1662i915_wedged_read(struct file *filp,
1663 char __user *ubuf,
1664 size_t max,
1665 loff_t *ppos)
1666{
1667 struct drm_device *dev = filp->private_data;
1668 drm_i915_private_t *dev_priv = dev->dev_private;
1669 char buf[80];
1670 int len;
1671
Akshay Joshi0206e352011-08-16 15:34:10 -04001672 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001673 "wedged : %d\n",
1674 atomic_read(&dev_priv->mm.wedged));
1675
Akshay Joshi0206e352011-08-16 15:34:10 -04001676 if (len > sizeof(buf))
1677 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001678
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001679 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1680}
1681
1682static ssize_t
1683i915_wedged_write(struct file *filp,
1684 const char __user *ubuf,
1685 size_t cnt,
1686 loff_t *ppos)
1687{
1688 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001689 char buf[20];
1690 int val = 1;
1691
1692 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001693 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001694 return -EINVAL;
1695
1696 if (copy_from_user(buf, ubuf, cnt))
1697 return -EFAULT;
1698 buf[cnt] = 0;
1699
1700 val = simple_strtoul(buf, NULL, 0);
1701 }
1702
1703 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001704 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001705
1706 return cnt;
1707}
1708
1709static const struct file_operations i915_wedged_fops = {
1710 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001711 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001712 .read = i915_wedged_read,
1713 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001714 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001715};
1716
Jesse Barnes358733e2011-07-27 11:53:01 -07001717static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001718i915_ring_stop_read(struct file *filp,
1719 char __user *ubuf,
1720 size_t max,
1721 loff_t *ppos)
1722{
1723 struct drm_device *dev = filp->private_data;
1724 drm_i915_private_t *dev_priv = dev->dev_private;
1725 char buf[20];
1726 int len;
1727
1728 len = snprintf(buf, sizeof(buf),
1729 "0x%08x\n", dev_priv->stop_rings);
1730
1731 if (len > sizeof(buf))
1732 len = sizeof(buf);
1733
1734 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1735}
1736
1737static ssize_t
1738i915_ring_stop_write(struct file *filp,
1739 const char __user *ubuf,
1740 size_t cnt,
1741 loff_t *ppos)
1742{
1743 struct drm_device *dev = filp->private_data;
1744 struct drm_i915_private *dev_priv = dev->dev_private;
1745 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001746 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001747
1748 if (cnt > 0) {
1749 if (cnt > sizeof(buf) - 1)
1750 return -EINVAL;
1751
1752 if (copy_from_user(buf, ubuf, cnt))
1753 return -EFAULT;
1754 buf[cnt] = 0;
1755
1756 val = simple_strtoul(buf, NULL, 0);
1757 }
1758
1759 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1760
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001761 ret = mutex_lock_interruptible(&dev->struct_mutex);
1762 if (ret)
1763 return ret;
1764
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001765 dev_priv->stop_rings = val;
1766 mutex_unlock(&dev->struct_mutex);
1767
1768 return cnt;
1769}
1770
1771static const struct file_operations i915_ring_stop_fops = {
1772 .owner = THIS_MODULE,
1773 .open = simple_open,
1774 .read = i915_ring_stop_read,
1775 .write = i915_ring_stop_write,
1776 .llseek = default_llseek,
1777};
Daniel Vetterd5442302012-04-27 15:17:40 +02001778
Chris Wilsondd624af2013-01-15 12:39:35 +00001779#define DROP_UNBOUND 0x1
1780#define DROP_BOUND 0x2
1781#define DROP_RETIRE 0x4
1782#define DROP_ACTIVE 0x8
1783#define DROP_ALL (DROP_UNBOUND | \
1784 DROP_BOUND | \
1785 DROP_RETIRE | \
1786 DROP_ACTIVE)
1787static ssize_t
1788i915_drop_caches_read(struct file *filp,
1789 char __user *ubuf,
1790 size_t max,
1791 loff_t *ppos)
1792{
1793 char buf[20];
1794 int len;
1795
1796 len = snprintf(buf, sizeof(buf), "0x%08x\n", DROP_ALL);
1797 if (len > sizeof(buf))
1798 len = sizeof(buf);
1799
1800 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1801}
1802
1803static ssize_t
1804i915_drop_caches_write(struct file *filp,
1805 const char __user *ubuf,
1806 size_t cnt,
1807 loff_t *ppos)
1808{
1809 struct drm_device *dev = filp->private_data;
1810 struct drm_i915_private *dev_priv = dev->dev_private;
1811 struct drm_i915_gem_object *obj, *next;
1812 char buf[20];
1813 int val = 0, ret;
1814
1815 if (cnt > 0) {
1816 if (cnt > sizeof(buf) - 1)
1817 return -EINVAL;
1818
1819 if (copy_from_user(buf, ubuf, cnt))
1820 return -EFAULT;
1821 buf[cnt] = 0;
1822
1823 val = simple_strtoul(buf, NULL, 0);
1824 }
1825
1826 DRM_DEBUG_DRIVER("Dropping caches: 0x%08x\n", val);
1827
1828 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1829 * on ioctls on -EAGAIN. */
1830 ret = mutex_lock_interruptible(&dev->struct_mutex);
1831 if (ret)
1832 return ret;
1833
1834 if (val & DROP_ACTIVE) {
1835 ret = i915_gpu_idle(dev);
1836 if (ret)
1837 goto unlock;
1838 }
1839
1840 if (val & (DROP_RETIRE | DROP_ACTIVE))
1841 i915_gem_retire_requests(dev);
1842
1843 if (val & DROP_BOUND) {
1844 list_for_each_entry_safe(obj, next, &dev_priv->mm.inactive_list, mm_list)
1845 if (obj->pin_count == 0) {
1846 ret = i915_gem_object_unbind(obj);
1847 if (ret)
1848 goto unlock;
1849 }
1850 }
1851
1852 if (val & DROP_UNBOUND) {
1853 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list, gtt_list)
1854 if (obj->pages_pin_count == 0) {
1855 ret = i915_gem_object_put_pages(obj);
1856 if (ret)
1857 goto unlock;
1858 }
1859 }
1860
1861unlock:
1862 mutex_unlock(&dev->struct_mutex);
1863
1864 return ret ?: cnt;
1865}
1866
1867static const struct file_operations i915_drop_caches_fops = {
1868 .owner = THIS_MODULE,
1869 .open = simple_open,
1870 .read = i915_drop_caches_read,
1871 .write = i915_drop_caches_write,
1872 .llseek = default_llseek,
1873};
1874
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001875static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001876i915_max_freq_read(struct file *filp,
1877 char __user *ubuf,
1878 size_t max,
1879 loff_t *ppos)
1880{
1881 struct drm_device *dev = filp->private_data;
1882 drm_i915_private_t *dev_priv = dev->dev_private;
1883 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001884 int len, ret;
1885
1886 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1887 return -ENODEV;
1888
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001889 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001890 if (ret)
1891 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001892
Akshay Joshi0206e352011-08-16 15:34:10 -04001893 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001894 "max freq: %d\n", dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001895 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001896
Akshay Joshi0206e352011-08-16 15:34:10 -04001897 if (len > sizeof(buf))
1898 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001899
1900 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1901}
1902
1903static ssize_t
1904i915_max_freq_write(struct file *filp,
1905 const char __user *ubuf,
1906 size_t cnt,
1907 loff_t *ppos)
1908{
1909 struct drm_device *dev = filp->private_data;
1910 struct drm_i915_private *dev_priv = dev->dev_private;
1911 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001912 int val = 1, ret;
1913
1914 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1915 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001916
1917 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001918 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001919 return -EINVAL;
1920
1921 if (copy_from_user(buf, ubuf, cnt))
1922 return -EFAULT;
1923 buf[cnt] = 0;
1924
1925 val = simple_strtoul(buf, NULL, 0);
1926 }
1927
1928 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1929
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001930 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001931 if (ret)
1932 return ret;
1933
Jesse Barnes358733e2011-07-27 11:53:01 -07001934 /*
1935 * Turbo will still be enabled, but won't go above the set value.
1936 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07001937 dev_priv->rps.max_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes358733e2011-07-27 11:53:01 -07001938
Ben Widawskyc8735b02012-09-07 19:43:39 -07001939 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001940 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001941
1942 return cnt;
1943}
1944
1945static const struct file_operations i915_max_freq_fops = {
1946 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001947 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001948 .read = i915_max_freq_read,
1949 .write = i915_max_freq_write,
1950 .llseek = default_llseek,
1951};
1952
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001953static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001954i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1955 loff_t *ppos)
1956{
1957 struct drm_device *dev = filp->private_data;
1958 drm_i915_private_t *dev_priv = dev->dev_private;
1959 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001960 int len, ret;
1961
1962 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1963 return -ENODEV;
1964
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001965 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001966 if (ret)
1967 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001968
1969 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001970 "min freq: %d\n", dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001971 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07001972
1973 if (len > sizeof(buf))
1974 len = sizeof(buf);
1975
1976 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1977}
1978
1979static ssize_t
1980i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
1981 loff_t *ppos)
1982{
1983 struct drm_device *dev = filp->private_data;
1984 struct drm_i915_private *dev_priv = dev->dev_private;
1985 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001986 int val = 1, ret;
1987
1988 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1989 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07001990
1991 if (cnt > 0) {
1992 if (cnt > sizeof(buf) - 1)
1993 return -EINVAL;
1994
1995 if (copy_from_user(buf, ubuf, cnt))
1996 return -EFAULT;
1997 buf[cnt] = 0;
1998
1999 val = simple_strtoul(buf, NULL, 0);
2000 }
2001
2002 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
2003
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002004 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002005 if (ret)
2006 return ret;
2007
Jesse Barnes1523c312012-05-25 12:34:54 -07002008 /*
2009 * Turbo will still be enabled, but won't go below the set value.
2010 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07002011 dev_priv->rps.min_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes1523c312012-05-25 12:34:54 -07002012
Ben Widawskyc8735b02012-09-07 19:43:39 -07002013 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002014 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002015
2016 return cnt;
2017}
2018
2019static const struct file_operations i915_min_freq_fops = {
2020 .owner = THIS_MODULE,
2021 .open = simple_open,
2022 .read = i915_min_freq_read,
2023 .write = i915_min_freq_write,
2024 .llseek = default_llseek,
2025};
2026
2027static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002028i915_cache_sharing_read(struct file *filp,
2029 char __user *ubuf,
2030 size_t max,
2031 loff_t *ppos)
2032{
2033 struct drm_device *dev = filp->private_data;
2034 drm_i915_private_t *dev_priv = dev->dev_private;
2035 char buf[80];
2036 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002037 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002038
Daniel Vetter004777c2012-08-09 15:07:01 +02002039 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2040 return -ENODEV;
2041
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002042 ret = mutex_lock_interruptible(&dev->struct_mutex);
2043 if (ret)
2044 return ret;
2045
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002046 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2047 mutex_unlock(&dev_priv->dev->struct_mutex);
2048
Akshay Joshi0206e352011-08-16 15:34:10 -04002049 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002050 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
2051 GEN6_MBC_SNPCR_SHIFT);
2052
Akshay Joshi0206e352011-08-16 15:34:10 -04002053 if (len > sizeof(buf))
2054 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002055
2056 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
2057}
2058
2059static ssize_t
2060i915_cache_sharing_write(struct file *filp,
2061 const char __user *ubuf,
2062 size_t cnt,
2063 loff_t *ppos)
2064{
2065 struct drm_device *dev = filp->private_data;
2066 struct drm_i915_private *dev_priv = dev->dev_private;
2067 char buf[20];
2068 u32 snpcr;
2069 int val = 1;
2070
Daniel Vetter004777c2012-08-09 15:07:01 +02002071 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2072 return -ENODEV;
2073
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002074 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04002075 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002076 return -EINVAL;
2077
2078 if (copy_from_user(buf, ubuf, cnt))
2079 return -EFAULT;
2080 buf[cnt] = 0;
2081
2082 val = simple_strtoul(buf, NULL, 0);
2083 }
2084
2085 if (val < 0 || val > 3)
2086 return -EINVAL;
2087
2088 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
2089
2090 /* Update the cache sharing policy here as well */
2091 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2092 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2093 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2094 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2095
2096 return cnt;
2097}
2098
2099static const struct file_operations i915_cache_sharing_fops = {
2100 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07002101 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002102 .read = i915_cache_sharing_read,
2103 .write = i915_cache_sharing_write,
2104 .llseek = default_llseek,
2105};
2106
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002107/* As the drm_debugfs_init() routines are called before dev->dev_private is
2108 * allocated we need to hook into the minor for release. */
2109static int
2110drm_add_fake_info_node(struct drm_minor *minor,
2111 struct dentry *ent,
2112 const void *key)
2113{
2114 struct drm_info_node *node;
2115
2116 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
2117 if (node == NULL) {
2118 debugfs_remove(ent);
2119 return -ENOMEM;
2120 }
2121
2122 node->minor = minor;
2123 node->dent = ent;
2124 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002125
2126 mutex_lock(&minor->debugfs_lock);
2127 list_add(&node->list, &minor->debugfs_list);
2128 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002129
2130 return 0;
2131}
2132
Ben Widawsky6d794d42011-04-25 11:25:56 -07002133static int i915_forcewake_open(struct inode *inode, struct file *file)
2134{
2135 struct drm_device *dev = inode->i_private;
2136 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002137
Daniel Vetter075edca2012-01-24 09:44:28 +01002138 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002139 return 0;
2140
Ben Widawsky6d794d42011-04-25 11:25:56 -07002141 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002142
2143 return 0;
2144}
2145
Ben Widawskyc43b5632012-04-16 14:07:40 -07002146static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002147{
2148 struct drm_device *dev = inode->i_private;
2149 struct drm_i915_private *dev_priv = dev->dev_private;
2150
Daniel Vetter075edca2012-01-24 09:44:28 +01002151 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002152 return 0;
2153
Ben Widawsky6d794d42011-04-25 11:25:56 -07002154 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002155
2156 return 0;
2157}
2158
2159static const struct file_operations i915_forcewake_fops = {
2160 .owner = THIS_MODULE,
2161 .open = i915_forcewake_open,
2162 .release = i915_forcewake_release,
2163};
2164
2165static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2166{
2167 struct drm_device *dev = minor->dev;
2168 struct dentry *ent;
2169
2170 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002171 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002172 root, dev,
2173 &i915_forcewake_fops);
2174 if (IS_ERR(ent))
2175 return PTR_ERR(ent);
2176
Ben Widawsky8eb57292011-05-11 15:10:58 -07002177 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002178}
2179
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002180static int i915_debugfs_create(struct dentry *root,
2181 struct drm_minor *minor,
2182 const char *name,
2183 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002184{
2185 struct drm_device *dev = minor->dev;
2186 struct dentry *ent;
2187
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002188 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002189 S_IRUGO | S_IWUSR,
2190 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002191 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002192 if (IS_ERR(ent))
2193 return PTR_ERR(ent);
2194
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002195 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002196}
2197
Ben Gamari27c202a2009-07-01 22:26:52 -04002198static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002199 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002200 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002201 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002202 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002203 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002204 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002205 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002206 {"i915_gem_request", i915_gem_request_info, 0},
2207 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002208 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002209 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002210 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2211 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2212 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002213 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2214 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2215 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2216 {"i915_inttoext_table", i915_inttoext_table, 0},
2217 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002218 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002219 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002220 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002221 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002222 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002223 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002224 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002225 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002226 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002227 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002228 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002229 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002230};
Ben Gamari27c202a2009-07-01 22:26:52 -04002231#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002232
Ben Gamari27c202a2009-07-01 22:26:52 -04002233int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002234{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002235 int ret;
2236
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002237 ret = i915_debugfs_create(minor->debugfs_root, minor,
2238 "i915_wedged",
2239 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002240 if (ret)
2241 return ret;
2242
Ben Widawsky6d794d42011-04-25 11:25:56 -07002243 ret = i915_forcewake_create(minor->debugfs_root, minor);
2244 if (ret)
2245 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002246
2247 ret = i915_debugfs_create(minor->debugfs_root, minor,
2248 "i915_max_freq",
2249 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002250 if (ret)
2251 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002252
2253 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002254 "i915_min_freq",
2255 &i915_min_freq_fops);
2256 if (ret)
2257 return ret;
2258
2259 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002260 "i915_cache_sharing",
2261 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002262 if (ret)
2263 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002264
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002265 ret = i915_debugfs_create(minor->debugfs_root, minor,
2266 "i915_ring_stop",
2267 &i915_ring_stop_fops);
2268 if (ret)
2269 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002270
Daniel Vetterd5442302012-04-27 15:17:40 +02002271 ret = i915_debugfs_create(minor->debugfs_root, minor,
Chris Wilsondd624af2013-01-15 12:39:35 +00002272 "i915_gem_drop_caches",
2273 &i915_drop_caches_fops);
2274 if (ret)
2275 return ret;
2276
2277 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetterd5442302012-04-27 15:17:40 +02002278 "i915_error_state",
2279 &i915_error_state_fops);
2280 if (ret)
2281 return ret;
2282
Mika Kuoppala40633212012-12-04 15:12:00 +02002283 ret = i915_debugfs_create(minor->debugfs_root, minor,
2284 "i915_next_seqno",
2285 &i915_next_seqno_fops);
2286 if (ret)
2287 return ret;
2288
Ben Gamari27c202a2009-07-01 22:26:52 -04002289 return drm_debugfs_create_files(i915_debugfs_list,
2290 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002291 minor->debugfs_root, minor);
2292}
2293
Ben Gamari27c202a2009-07-01 22:26:52 -04002294void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002295{
Ben Gamari27c202a2009-07-01 22:26:52 -04002296 drm_debugfs_remove_files(i915_debugfs_list,
2297 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002298 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2299 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002300 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2301 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002302 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2303 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002304 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2305 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002306 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2307 1, minor);
Chris Wilsondd624af2013-01-15 12:39:35 +00002308 drm_debugfs_remove_files((struct drm_info_list *) &i915_drop_caches_fops,
2309 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002310 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2311 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002312 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2313 1, minor);
Mika Kuoppala40633212012-12-04 15:12:00 +02002314 drm_debugfs_remove_files((struct drm_info_list *) &i915_next_seqno_fops,
2315 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002316}
2317
2318#endif /* CONFIG_DEBUG_FS */