blob: 7c65ab83914a0ce50274797b708f2b5ba35b27ee [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010030#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040032#include <linux/export.h>
Daniel Vetter4518f612013-01-23 16:16:35 +010033#include <generated/utsrelease.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010035#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000036#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050038#include "i915_drv.h"
39
40#define DRM_I915_RING_DEBUG 1
41
42
43#if defined(CONFIG_DEBUG_FS)
44
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010046 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010048 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010049};
Ben Gamari433e12f2009-02-17 20:08:51 -050050
Chris Wilson70d39fe2010-08-25 16:03:34 +010051static const char *yesno(int v)
52{
53 return v ? "yes" : "no";
54}
55
56static int i915_capabilities(struct seq_file *m, void *data)
57{
58 struct drm_info_node *node = (struct drm_info_node *) m->private;
59 struct drm_device *dev = node->minor->dev;
60 const struct intel_device_info *info = INTEL_INFO(dev);
61
62 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030063 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Daniel Vetterc96ea642012-08-08 22:01:51 +020064#define DEV_INFO_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
65#define DEV_INFO_SEP ;
66 DEV_INFO_FLAGS;
67#undef DEV_INFO_FLAG
68#undef DEV_INFO_SEP
Chris Wilson70d39fe2010-08-25 16:03:34 +010069
70 return 0;
71}
Ben Gamari433e12f2009-02-17 20:08:51 -050072
Chris Wilson05394f32010-11-08 19:18:58 +000073static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000074{
Chris Wilson05394f32010-11-08 19:18:58 +000075 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000076 return "P";
Chris Wilson05394f32010-11-08 19:18:58 +000077 else if (obj->pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000078 return "p";
79 else
80 return " ";
81}
82
Chris Wilson05394f32010-11-08 19:18:58 +000083static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000084{
Akshay Joshi0206e352011-08-16 15:34:10 -040085 switch (obj->tiling_mode) {
86 default:
87 case I915_TILING_NONE: return " ";
88 case I915_TILING_X: return "X";
89 case I915_TILING_Y: return "Y";
90 }
Chris Wilsona6172a82009-02-11 14:26:38 +000091}
92
Chris Wilson93dfb402011-03-29 16:59:50 -070093static const char *cache_level_str(int type)
Chris Wilson08c18322011-01-10 00:00:24 +000094{
95 switch (type) {
Chris Wilson93dfb402011-03-29 16:59:50 -070096 case I915_CACHE_NONE: return " uncached";
97 case I915_CACHE_LLC: return " snooped (LLC)";
98 case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
Chris Wilson08c18322011-01-10 00:00:24 +000099 default: return "";
100 }
101}
102
Chris Wilson37811fc2010-08-25 22:45:57 +0100103static void
104describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
105{
Chris Wilson04b97b32012-11-27 17:06:53 +0000106 seq_printf(m, "%p: %s%s %8zdKiB %02x %02x %d %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100107 &obj->base,
108 get_pin_flag(obj),
109 get_tiling_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800110 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100111 obj->base.read_domains,
112 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100113 obj->last_read_seqno,
114 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000115 obj->last_fenced_seqno,
Chris Wilson93dfb402011-03-29 16:59:50 -0700116 cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100117 obj->dirty ? " dirty" : "",
118 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
119 if (obj->base.name)
120 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilsonc110a6d2012-08-11 15:41:02 +0100121 if (obj->pin_count)
122 seq_printf(m, " (pinned x %d)", obj->pin_count);
Chris Wilson37811fc2010-08-25 22:45:57 +0100123 if (obj->fence_reg != I915_FENCE_REG_NONE)
124 seq_printf(m, " (fence: %d)", obj->fence_reg);
125 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100126 seq_printf(m, " (gtt offset: %08x, size: %08x)",
127 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000128 if (obj->stolen)
129 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000130 if (obj->pin_mappable || obj->fault_mappable) {
131 char s[3], *t = s;
132 if (obj->pin_mappable)
133 *t++ = 'p';
134 if (obj->fault_mappable)
135 *t++ = 'f';
136 *t = '\0';
137 seq_printf(m, " (%s mappable)", s);
138 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100139 if (obj->ring != NULL)
140 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100141}
142
Ben Gamari433e12f2009-02-17 20:08:51 -0500143static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500144{
145 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500146 uintptr_t list = (uintptr_t) node->info_ent->data;
147 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500148 struct drm_device *dev = node->minor->dev;
149 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000150 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100151 size_t total_obj_size, total_gtt_size;
152 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100153
154 ret = mutex_lock_interruptible(&dev->struct_mutex);
155 if (ret)
156 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500157
Ben Gamari433e12f2009-02-17 20:08:51 -0500158 switch (list) {
159 case ACTIVE_LIST:
160 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100161 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500162 break;
163 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400164 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500165 head = &dev_priv->mm.inactive_list;
166 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500167 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100168 mutex_unlock(&dev->struct_mutex);
169 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500170 }
171
Chris Wilson8f2480f2010-09-26 11:44:19 +0100172 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000173 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100174 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000175 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800176 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000177 total_obj_size += obj->base.size;
178 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100179 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500180 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100181 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700182
Chris Wilson8f2480f2010-09-26 11:44:19 +0100183 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
184 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500185 return 0;
186}
187
Chris Wilson6299f992010-11-24 12:23:44 +0000188#define count_objects(list, member) do { \
189 list_for_each_entry(obj, list, member) { \
190 size += obj->gtt_space->size; \
191 ++count; \
192 if (obj->map_and_fenceable) { \
193 mappable_size += obj->gtt_space->size; \
194 ++mappable_count; \
195 } \
196 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400197} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000198
Chris Wilson73aa8082010-09-30 11:46:12 +0100199static int i915_gem_object_info(struct seq_file *m, void* data)
200{
201 struct drm_info_node *node = (struct drm_info_node *) m->private;
202 struct drm_device *dev = node->minor->dev;
203 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200204 u32 count, mappable_count, purgeable_count;
205 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000206 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100207 int ret;
208
209 ret = mutex_lock_interruptible(&dev->struct_mutex);
210 if (ret)
211 return ret;
212
Chris Wilson6299f992010-11-24 12:23:44 +0000213 seq_printf(m, "%u objects, %zu bytes\n",
214 dev_priv->mm.object_count,
215 dev_priv->mm.object_memory);
216
217 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200218 count_objects(&dev_priv->mm.bound_list, gtt_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000219 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
220 count, mappable_count, size, mappable_size);
221
222 size = count = mappable_size = mappable_count = 0;
223 count_objects(&dev_priv->mm.active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000224 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
225 count, mappable_count, size, mappable_size);
226
227 size = count = mappable_size = mappable_count = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000228 count_objects(&dev_priv->mm.inactive_list, mm_list);
229 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
230 count, mappable_count, size, mappable_size);
231
Chris Wilsonb7abb712012-08-20 11:33:30 +0200232 size = count = purgeable_size = purgeable_count = 0;
233 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200234 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200235 if (obj->madv == I915_MADV_DONTNEED)
236 purgeable_size += obj->base.size, ++purgeable_count;
237 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200238 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
239
Chris Wilson6299f992010-11-24 12:23:44 +0000240 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200241 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000242 if (obj->fault_mappable) {
243 size += obj->gtt_space->size;
244 ++count;
245 }
246 if (obj->pin_mappable) {
247 mappable_size += obj->gtt_space->size;
248 ++mappable_count;
249 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200250 if (obj->madv == I915_MADV_DONTNEED) {
251 purgeable_size += obj->base.size;
252 ++purgeable_count;
253 }
Chris Wilson6299f992010-11-24 12:23:44 +0000254 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200255 seq_printf(m, "%u purgeable objects, %zu bytes\n",
256 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000257 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
258 mappable_count, mappable_size);
259 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
260 count, size);
261
Ben Widawsky93d18792013-01-17 12:45:17 -0800262 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky5d4545a2013-01-17 12:45:15 -0800263 dev_priv->gtt.total,
264 dev_priv->gtt.mappable_end - dev_priv->gtt.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100265
266 mutex_unlock(&dev->struct_mutex);
267
268 return 0;
269}
270
Chris Wilson08c18322011-01-10 00:00:24 +0000271static int i915_gem_gtt_info(struct seq_file *m, void* data)
272{
273 struct drm_info_node *node = (struct drm_info_node *) m->private;
274 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100275 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000276 struct drm_i915_private *dev_priv = dev->dev_private;
277 struct drm_i915_gem_object *obj;
278 size_t total_obj_size, total_gtt_size;
279 int count, ret;
280
281 ret = mutex_lock_interruptible(&dev->struct_mutex);
282 if (ret)
283 return ret;
284
285 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200286 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100287 if (list == PINNED_LIST && obj->pin_count == 0)
288 continue;
289
Chris Wilson08c18322011-01-10 00:00:24 +0000290 seq_printf(m, " ");
291 describe_obj(m, obj);
292 seq_printf(m, "\n");
293 total_obj_size += obj->base.size;
294 total_gtt_size += obj->gtt_space->size;
295 count++;
296 }
297
298 mutex_unlock(&dev->struct_mutex);
299
300 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
301 count, total_obj_size, total_gtt_size);
302
303 return 0;
304}
305
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100306static int i915_gem_pageflip_info(struct seq_file *m, void *data)
307{
308 struct drm_info_node *node = (struct drm_info_node *) m->private;
309 struct drm_device *dev = node->minor->dev;
310 unsigned long flags;
311 struct intel_crtc *crtc;
312
313 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800314 const char pipe = pipe_name(crtc->pipe);
315 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100316 struct intel_unpin_work *work;
317
318 spin_lock_irqsave(&dev->event_lock, flags);
319 work = crtc->unpin_work;
320 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800321 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100322 pipe, plane);
323 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000324 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800325 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100326 pipe, plane);
327 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800328 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100329 pipe, plane);
330 }
331 if (work->enable_stall_check)
332 seq_printf(m, "Stall check enabled, ");
333 else
334 seq_printf(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000335 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100336
337 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000338 struct drm_i915_gem_object *obj = work->old_fb_obj;
339 if (obj)
340 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100341 }
342 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000343 struct drm_i915_gem_object *obj = work->pending_flip_obj;
344 if (obj)
345 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100346 }
347 }
348 spin_unlock_irqrestore(&dev->event_lock, flags);
349 }
350
351 return 0;
352}
353
Ben Gamari20172632009-02-17 20:08:50 -0500354static int i915_gem_request_info(struct seq_file *m, void *data)
355{
356 struct drm_info_node *node = (struct drm_info_node *) m->private;
357 struct drm_device *dev = node->minor->dev;
358 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100359 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500360 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100361 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100362
363 ret = mutex_lock_interruptible(&dev->struct_mutex);
364 if (ret)
365 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500366
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100367 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100368 for_each_ring(ring, dev_priv, i) {
369 if (list_empty(&ring->request_list))
370 continue;
371
372 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100373 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100374 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100375 list) {
376 seq_printf(m, " %d @ %d\n",
377 gem_request->seqno,
378 (int) (jiffies - gem_request->emitted_jiffies));
379 }
380 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500381 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100382 mutex_unlock(&dev->struct_mutex);
383
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100384 if (count == 0)
385 seq_printf(m, "No requests\n");
386
Ben Gamari20172632009-02-17 20:08:50 -0500387 return 0;
388}
389
Chris Wilsonb2223492010-10-27 15:27:33 +0100390static void i915_ring_seqno_info(struct seq_file *m,
391 struct intel_ring_buffer *ring)
392{
393 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200394 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100395 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100396 }
397}
398
Ben Gamari20172632009-02-17 20:08:50 -0500399static int i915_gem_seqno_info(struct seq_file *m, void *data)
400{
401 struct drm_info_node *node = (struct drm_info_node *) m->private;
402 struct drm_device *dev = node->minor->dev;
403 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100404 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000405 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100406
407 ret = mutex_lock_interruptible(&dev->struct_mutex);
408 if (ret)
409 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500410
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100411 for_each_ring(ring, dev_priv, i)
412 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100413
414 mutex_unlock(&dev->struct_mutex);
415
Ben Gamari20172632009-02-17 20:08:50 -0500416 return 0;
417}
418
419
420static int i915_interrupt_info(struct seq_file *m, void *data)
421{
422 struct drm_info_node *node = (struct drm_info_node *) m->private;
423 struct drm_device *dev = node->minor->dev;
424 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100425 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800426 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100427
428 ret = mutex_lock_interruptible(&dev->struct_mutex);
429 if (ret)
430 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500431
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700432 if (IS_VALLEYVIEW(dev)) {
433 seq_printf(m, "Display IER:\t%08x\n",
434 I915_READ(VLV_IER));
435 seq_printf(m, "Display IIR:\t%08x\n",
436 I915_READ(VLV_IIR));
437 seq_printf(m, "Display IIR_RW:\t%08x\n",
438 I915_READ(VLV_IIR_RW));
439 seq_printf(m, "Display IMR:\t%08x\n",
440 I915_READ(VLV_IMR));
441 for_each_pipe(pipe)
442 seq_printf(m, "Pipe %c stat:\t%08x\n",
443 pipe_name(pipe),
444 I915_READ(PIPESTAT(pipe)));
445
446 seq_printf(m, "Master IER:\t%08x\n",
447 I915_READ(VLV_MASTER_IER));
448
449 seq_printf(m, "Render IER:\t%08x\n",
450 I915_READ(GTIER));
451 seq_printf(m, "Render IIR:\t%08x\n",
452 I915_READ(GTIIR));
453 seq_printf(m, "Render IMR:\t%08x\n",
454 I915_READ(GTIMR));
455
456 seq_printf(m, "PM IER:\t\t%08x\n",
457 I915_READ(GEN6_PMIER));
458 seq_printf(m, "PM IIR:\t\t%08x\n",
459 I915_READ(GEN6_PMIIR));
460 seq_printf(m, "PM IMR:\t\t%08x\n",
461 I915_READ(GEN6_PMIMR));
462
463 seq_printf(m, "Port hotplug:\t%08x\n",
464 I915_READ(PORT_HOTPLUG_EN));
465 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
466 I915_READ(VLV_DPFLIPSTAT));
467 seq_printf(m, "DPINVGTT:\t%08x\n",
468 I915_READ(DPINVGTT));
469
470 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800471 seq_printf(m, "Interrupt enable: %08x\n",
472 I915_READ(IER));
473 seq_printf(m, "Interrupt identity: %08x\n",
474 I915_READ(IIR));
475 seq_printf(m, "Interrupt mask: %08x\n",
476 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800477 for_each_pipe(pipe)
478 seq_printf(m, "Pipe %c stat: %08x\n",
479 pipe_name(pipe),
480 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800481 } else {
482 seq_printf(m, "North Display Interrupt enable: %08x\n",
483 I915_READ(DEIER));
484 seq_printf(m, "North Display Interrupt identity: %08x\n",
485 I915_READ(DEIIR));
486 seq_printf(m, "North Display Interrupt mask: %08x\n",
487 I915_READ(DEIMR));
488 seq_printf(m, "South Display Interrupt enable: %08x\n",
489 I915_READ(SDEIER));
490 seq_printf(m, "South Display Interrupt identity: %08x\n",
491 I915_READ(SDEIIR));
492 seq_printf(m, "South Display Interrupt mask: %08x\n",
493 I915_READ(SDEIMR));
494 seq_printf(m, "Graphics Interrupt enable: %08x\n",
495 I915_READ(GTIER));
496 seq_printf(m, "Graphics Interrupt identity: %08x\n",
497 I915_READ(GTIIR));
498 seq_printf(m, "Graphics Interrupt mask: %08x\n",
499 I915_READ(GTIMR));
500 }
Ben Gamari20172632009-02-17 20:08:50 -0500501 seq_printf(m, "Interrupts received: %d\n",
502 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100503 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700504 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100505 seq_printf(m,
506 "Graphics Interrupt mask (%s): %08x\n",
507 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000508 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100509 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000510 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100511 mutex_unlock(&dev->struct_mutex);
512
Ben Gamari20172632009-02-17 20:08:50 -0500513 return 0;
514}
515
Chris Wilsona6172a82009-02-11 14:26:38 +0000516static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
517{
518 struct drm_info_node *node = (struct drm_info_node *) m->private;
519 struct drm_device *dev = node->minor->dev;
520 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100521 int i, ret;
522
523 ret = mutex_lock_interruptible(&dev->struct_mutex);
524 if (ret)
525 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000526
527 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
528 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
529 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000530 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000531
Chris Wilson6c085a72012-08-20 11:40:46 +0200532 seq_printf(m, "Fence %d, pin count = %d, object = ",
533 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100534 if (obj == NULL)
535 seq_printf(m, "unused");
536 else
Chris Wilson05394f32010-11-08 19:18:58 +0000537 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100538 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000539 }
540
Chris Wilson05394f32010-11-08 19:18:58 +0000541 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000542 return 0;
543}
544
Ben Gamari20172632009-02-17 20:08:50 -0500545static int i915_hws_info(struct seq_file *m, void *data)
546{
547 struct drm_info_node *node = (struct drm_info_node *) m->private;
548 struct drm_device *dev = node->minor->dev;
549 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100550 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100551 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100552 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500553
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000554 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100555 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500556 if (hws == NULL)
557 return 0;
558
559 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
560 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
561 i * 4,
562 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
563 }
564 return 0;
565}
566
Chris Wilsone5c65262010-11-01 11:35:28 +0000567static const char *ring_str(int ring)
568{
569 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100570 case RCS: return "render";
571 case VCS: return "bsd";
572 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000573 default: return "";
574 }
575}
576
Chris Wilson9df30792010-02-18 10:24:56 +0000577static const char *pin_flag(int pinned)
578{
579 if (pinned > 0)
580 return " P";
581 else if (pinned < 0)
582 return " p";
583 else
584 return "";
585}
586
587static const char *tiling_flag(int tiling)
588{
589 switch (tiling) {
590 default:
591 case I915_TILING_NONE: return "";
592 case I915_TILING_X: return " X";
593 case I915_TILING_Y: return " Y";
594 }
595}
596
597static const char *dirty_flag(int dirty)
598{
599 return dirty ? " dirty" : "";
600}
601
602static const char *purgeable_flag(int purgeable)
603{
604 return purgeable ? " purgeable" : "";
605}
606
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000607static void print_error_buffers(struct seq_file *m,
608 const char *name,
609 struct drm_i915_error_buffer *err,
610 int count)
611{
612 seq_printf(m, "%s [%d]:\n", name, count);
613
614 while (count--) {
Chris Wilson04b97b32012-11-27 17:06:53 +0000615 seq_printf(m, " %08x %8u %02x %02x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000616 err->gtt_offset,
617 err->size,
618 err->read_domains,
619 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100620 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000621 pin_flag(err->pinned),
622 tiling_flag(err->tiling),
623 dirty_flag(err->dirty),
624 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100625 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000626 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700627 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000628
629 if (err->name)
630 seq_printf(m, " (name: %d)", err->name);
631 if (err->fence_reg != I915_FENCE_REG_NONE)
632 seq_printf(m, " (fence: %d)", err->fence_reg);
633
634 seq_printf(m, "\n");
635 err++;
636 }
637}
638
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100639static void i915_ring_error_state(struct seq_file *m,
640 struct drm_device *dev,
641 struct drm_i915_error_state *error,
642 unsigned ring)
643{
Ben Widawskyec34a012012-04-03 23:03:00 -0700644 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100645 seq_printf(m, "%s command stream:\n", ring_str(ring));
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100646 seq_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
647 seq_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
Chris Wilson0f3b6842013-01-15 12:05:55 +0000648 seq_printf(m, " CTL: 0x%08x\n", error->ctl[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100649 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
650 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
651 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
652 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Ben Widawsky050ee912012-08-22 11:32:15 -0700653 if (ring == RCS && INTEL_INFO(dev)->gen >= 4)
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100654 seq_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Ben Widawsky050ee912012-08-22 11:32:15 -0700655
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100656 if (INTEL_INFO(dev)->gen >= 4)
657 seq_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
658 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
Daniel Vetter9d2f41f2012-04-02 21:41:45 +0200659 seq_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100660 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilson12f55812012-07-05 17:14:01 +0100661 seq_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100662 seq_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
Chris Wilsondf2b23d2012-11-27 17:06:54 +0000663 seq_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
664 error->semaphore_mboxes[ring][0],
665 error->semaphore_seqno[ring][0]);
666 seq_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
667 error->semaphore_mboxes[ring][1],
668 error->semaphore_seqno[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100669 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100670 seq_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
Ben Widawsky9574b3f2012-04-26 16:03:01 -0700671 seq_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
Daniel Vetter7e3b8732012-02-01 22:26:45 +0100672 seq_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
673 seq_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100674}
675
Daniel Vetterd5442302012-04-27 15:17:40 +0200676struct i915_error_state_file_priv {
677 struct drm_device *dev;
678 struct drm_i915_error_state *error;
679};
680
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700681static int i915_error_state(struct seq_file *m, void *unused)
682{
Daniel Vetterd5442302012-04-27 15:17:40 +0200683 struct i915_error_state_file_priv *error_priv = m->private;
684 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700685 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200686 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100687 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000688 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700689
Daniel Vetter742cbee2012-04-27 15:17:39 +0200690 if (!error) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700691 seq_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200692 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700693 }
694
Jesse Barnes8a905232009-07-11 16:48:03 -0400695 seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
696 error->time.tv_usec);
Jani Nikulafdfa1752013-02-14 11:23:35 +0200697 seq_printf(m, "Kernel: " UTS_RELEASE "\n");
Chris Wilson9df30792010-02-18 10:24:56 +0000698 seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100699 seq_printf(m, "EIR: 0x%08x\n", error->eir);
Ben Widawskybe998e22012-04-26 16:03:00 -0700700 seq_printf(m, "IER: 0x%08x\n", error->ier);
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100701 seq_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
Chris Wilson0f3b6842013-01-15 12:05:55 +0000702 seq_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
703 seq_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
Ben Widawskyb9a39062012-06-04 14:42:52 -0700704 seq_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000705
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100706 for (i = 0; i < dev_priv->num_fence_regs; i++)
Chris Wilson748ebc62010-10-24 10:28:47 +0100707 seq_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
708
Ben Widawsky050ee912012-08-22 11:32:15 -0700709 for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
710 seq_printf(m, " INSTDONE_%d: 0x%08x\n", i, error->extra_instdone[i]);
711
Daniel Vetter33f3f512011-12-14 13:57:39 +0100712 if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100713 seq_printf(m, "ERROR: 0x%08x\n", error->error);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100714 seq_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
715 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100716
Ben Widawsky71e172e2012-08-20 16:15:13 -0700717 if (INTEL_INFO(dev)->gen == 7)
718 seq_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
719
Chris Wilsonb4519512012-05-11 14:29:30 +0100720 for_each_ring(ring, dev_priv, i)
721 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100722
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000723 if (error->active_bo)
724 print_error_buffers(m, "Active",
725 error->active_bo,
726 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000727
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000728 if (error->pinned_bo)
729 print_error_buffers(m, "Pinned",
730 error->pinned_bo,
731 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000732
Chris Wilson52d39a22012-02-15 11:25:37 +0000733 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
734 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000735
Chris Wilson52d39a22012-02-15 11:25:37 +0000736 if ((obj = error->ring[i].batchbuffer)) {
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000737 seq_printf(m, "%s --- gtt_offset = 0x%08x\n",
738 dev_priv->ring[i].name,
739 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000740 offset = 0;
741 for (page = 0; page < obj->page_count; page++) {
742 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
743 seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]);
744 offset += 4;
745 }
746 }
747 }
Chris Wilson9df30792010-02-18 10:24:56 +0000748
Chris Wilson52d39a22012-02-15 11:25:37 +0000749 if (error->ring[i].num_requests) {
750 seq_printf(m, "%s --- %d requests\n",
751 dev_priv->ring[i].name,
752 error->ring[i].num_requests);
753 for (j = 0; j < error->ring[i].num_requests; j++) {
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000754 seq_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000755 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000756 error->ring[i].requests[j].jiffies,
757 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000758 }
759 }
760
761 if ((obj = error->ring[i].ringbuffer)) {
Chris Wilsone2f973d2011-01-27 19:15:11 +0000762 seq_printf(m, "%s --- ringbuffer = 0x%08x\n",
763 dev_priv->ring[i].name,
764 obj->gtt_offset);
765 offset = 0;
766 for (page = 0; page < obj->page_count; page++) {
767 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
768 seq_printf(m, "%08x : %08x\n",
769 offset,
770 obj->pages[page][elt]);
771 offset += 4;
772 }
Chris Wilson9df30792010-02-18 10:24:56 +0000773 }
774 }
775 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700776
Chris Wilson6ef3d422010-08-04 20:26:07 +0100777 if (error->overlay)
778 intel_overlay_print_error_state(m, error->overlay);
779
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000780 if (error->display)
781 intel_display_print_error_state(m, dev, error->display);
782
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700783 return 0;
784}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700785
Daniel Vetterd5442302012-04-27 15:17:40 +0200786static ssize_t
787i915_error_state_write(struct file *filp,
788 const char __user *ubuf,
789 size_t cnt,
790 loff_t *ppos)
791{
792 struct seq_file *m = filp->private_data;
793 struct i915_error_state_file_priv *error_priv = m->private;
794 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200795 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200796
797 DRM_DEBUG_DRIVER("Resetting error state\n");
798
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200799 ret = mutex_lock_interruptible(&dev->struct_mutex);
800 if (ret)
801 return ret;
802
Daniel Vetterd5442302012-04-27 15:17:40 +0200803 i915_destroy_error_state(dev);
804 mutex_unlock(&dev->struct_mutex);
805
806 return cnt;
807}
808
809static int i915_error_state_open(struct inode *inode, struct file *file)
810{
811 struct drm_device *dev = inode->i_private;
812 drm_i915_private_t *dev_priv = dev->dev_private;
813 struct i915_error_state_file_priv *error_priv;
814 unsigned long flags;
815
816 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
817 if (!error_priv)
818 return -ENOMEM;
819
820 error_priv->dev = dev;
821
Daniel Vetter99584db2012-11-14 17:14:04 +0100822 spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
823 error_priv->error = dev_priv->gpu_error.first_error;
Daniel Vetterd5442302012-04-27 15:17:40 +0200824 if (error_priv->error)
825 kref_get(&error_priv->error->ref);
Daniel Vetter99584db2012-11-14 17:14:04 +0100826 spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
Daniel Vetterd5442302012-04-27 15:17:40 +0200827
828 return single_open(file, i915_error_state, error_priv);
829}
830
831static int i915_error_state_release(struct inode *inode, struct file *file)
832{
833 struct seq_file *m = file->private_data;
834 struct i915_error_state_file_priv *error_priv = m->private;
835
836 if (error_priv->error)
837 kref_put(&error_priv->error->ref, i915_error_state_free);
838 kfree(error_priv);
839
840 return single_release(inode, file);
841}
842
843static const struct file_operations i915_error_state_fops = {
844 .owner = THIS_MODULE,
845 .open = i915_error_state_open,
846 .read = seq_read,
847 .write = i915_error_state_write,
848 .llseek = default_llseek,
849 .release = i915_error_state_release,
850};
851
Mika Kuoppala40633212012-12-04 15:12:00 +0200852static ssize_t
853i915_next_seqno_read(struct file *filp,
854 char __user *ubuf,
855 size_t max,
856 loff_t *ppos)
857{
858 struct drm_device *dev = filp->private_data;
859 drm_i915_private_t *dev_priv = dev->dev_private;
860 char buf[80];
861 int len;
862 int ret;
863
864 ret = mutex_lock_interruptible(&dev->struct_mutex);
865 if (ret)
866 return ret;
867
868 len = snprintf(buf, sizeof(buf),
869 "next_seqno : 0x%x\n",
870 dev_priv->next_seqno);
871
872 mutex_unlock(&dev->struct_mutex);
873
874 if (len > sizeof(buf))
875 len = sizeof(buf);
876
877 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
878}
879
880static ssize_t
881i915_next_seqno_write(struct file *filp,
882 const char __user *ubuf,
883 size_t cnt,
884 loff_t *ppos)
885{
886 struct drm_device *dev = filp->private_data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200887 char buf[20];
888 u32 val = 1;
889 int ret;
890
891 if (cnt > 0) {
892 if (cnt > sizeof(buf) - 1)
893 return -EINVAL;
894
895 if (copy_from_user(buf, ubuf, cnt))
896 return -EFAULT;
897 buf[cnt] = 0;
898
899 ret = kstrtouint(buf, 0, &val);
900 if (ret < 0)
901 return ret;
902 }
903
Mika Kuoppala40633212012-12-04 15:12:00 +0200904 ret = mutex_lock_interruptible(&dev->struct_mutex);
905 if (ret)
906 return ret;
907
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200908 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200909
910 mutex_unlock(&dev->struct_mutex);
911
912 return ret ?: cnt;
913}
914
915static const struct file_operations i915_next_seqno_fops = {
916 .owner = THIS_MODULE,
917 .open = simple_open,
918 .read = i915_next_seqno_read,
919 .write = i915_next_seqno_write,
920 .llseek = default_llseek,
921};
922
Jesse Barnesf97108d2010-01-29 11:27:07 -0800923static int i915_rstdby_delays(struct seq_file *m, void *unused)
924{
925 struct drm_info_node *node = (struct drm_info_node *) m->private;
926 struct drm_device *dev = node->minor->dev;
927 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700928 u16 crstanddelay;
929 int ret;
930
931 ret = mutex_lock_interruptible(&dev->struct_mutex);
932 if (ret)
933 return ret;
934
935 crstanddelay = I915_READ16(CRSTANDVID);
936
937 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800938
939 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
940
941 return 0;
942}
943
944static int i915_cur_delayinfo(struct seq_file *m, void *unused)
945{
946 struct drm_info_node *node = (struct drm_info_node *) m->private;
947 struct drm_device *dev = node->minor->dev;
948 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100949 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800950
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800951 if (IS_GEN5(dev)) {
952 u16 rgvswctl = I915_READ16(MEMSWCTL);
953 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
954
955 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
956 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
957 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
958 MEMSTAT_VID_SHIFT);
959 seq_printf(m, "Current P-state: %d\n",
960 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes1c70c0c2011-06-29 13:34:36 -0700961 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800962 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
963 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
964 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800965 u32 rpstat, cagf;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800966 u32 rpupei, rpcurup, rpprevup;
967 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800968 int max_freq;
969
970 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100971 ret = mutex_lock_interruptible(&dev->struct_mutex);
972 if (ret)
973 return ret;
974
Ben Widawskyfcca7922011-04-25 11:23:07 -0700975 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800976
Jesse Barnesccab5c82011-01-18 15:49:25 -0800977 rpstat = I915_READ(GEN6_RPSTAT1);
978 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
979 rpcurup = I915_READ(GEN6_RP_CUR_UP);
980 rpprevup = I915_READ(GEN6_RP_PREV_UP);
981 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
982 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
983 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800984 if (IS_HASWELL(dev))
985 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
986 else
987 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
988 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800989
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100990 gen6_gt_force_wake_put(dev_priv);
991 mutex_unlock(&dev->struct_mutex);
992
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800993 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800994 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800995 seq_printf(m, "Render p-state ratio: %d\n",
996 (gt_perf_status & 0xff00) >> 8);
997 seq_printf(m, "Render p-state VID: %d\n",
998 gt_perf_status & 0xff);
999 seq_printf(m, "Render p-state limit: %d\n",
1000 rp_state_limits & 0xff);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001001 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001002 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1003 GEN6_CURICONT_MASK);
1004 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1005 GEN6_CURBSYTAVG_MASK);
1006 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1007 GEN6_CURBSYTAVG_MASK);
1008 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1009 GEN6_CURIAVG_MASK);
1010 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1011 GEN6_CURBSYTAVG_MASK);
1012 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1013 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001014
1015 max_freq = (rp_state_cap & 0xff0000) >> 16;
1016 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001017 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001018
1019 max_freq = (rp_state_cap & 0xff00) >> 8;
1020 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001021 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001022
1023 max_freq = rp_state_cap & 0xff;
1024 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001025 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001026 } else {
1027 seq_printf(m, "no P-state info available\n");
1028 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001029
1030 return 0;
1031}
1032
1033static int i915_delayfreq_table(struct seq_file *m, void *unused)
1034{
1035 struct drm_info_node *node = (struct drm_info_node *) m->private;
1036 struct drm_device *dev = node->minor->dev;
1037 drm_i915_private_t *dev_priv = dev->dev_private;
1038 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001039 int ret, i;
1040
1041 ret = mutex_lock_interruptible(&dev->struct_mutex);
1042 if (ret)
1043 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001044
1045 for (i = 0; i < 16; i++) {
1046 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001047 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1048 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001049 }
1050
Ben Widawsky616fdb52011-10-05 11:44:54 -07001051 mutex_unlock(&dev->struct_mutex);
1052
Jesse Barnesf97108d2010-01-29 11:27:07 -08001053 return 0;
1054}
1055
1056static inline int MAP_TO_MV(int map)
1057{
1058 return 1250 - (map * 25);
1059}
1060
1061static int i915_inttoext_table(struct seq_file *m, void *unused)
1062{
1063 struct drm_info_node *node = (struct drm_info_node *) m->private;
1064 struct drm_device *dev = node->minor->dev;
1065 drm_i915_private_t *dev_priv = dev->dev_private;
1066 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001067 int ret, i;
1068
1069 ret = mutex_lock_interruptible(&dev->struct_mutex);
1070 if (ret)
1071 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001072
1073 for (i = 1; i <= 32; i++) {
1074 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1075 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1076 }
1077
Ben Widawsky616fdb52011-10-05 11:44:54 -07001078 mutex_unlock(&dev->struct_mutex);
1079
Jesse Barnesf97108d2010-01-29 11:27:07 -08001080 return 0;
1081}
1082
Ben Widawsky4d855292011-12-12 19:34:16 -08001083static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001084{
1085 struct drm_info_node *node = (struct drm_info_node *) m->private;
1086 struct drm_device *dev = node->minor->dev;
1087 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001088 u32 rgvmodectl, rstdbyctl;
1089 u16 crstandvid;
1090 int ret;
1091
1092 ret = mutex_lock_interruptible(&dev->struct_mutex);
1093 if (ret)
1094 return ret;
1095
1096 rgvmodectl = I915_READ(MEMMODECTL);
1097 rstdbyctl = I915_READ(RSTDBYCTL);
1098 crstandvid = I915_READ16(CRSTANDVID);
1099
1100 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001101
1102 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1103 "yes" : "no");
1104 seq_printf(m, "Boost freq: %d\n",
1105 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1106 MEMMODE_BOOST_FREQ_SHIFT);
1107 seq_printf(m, "HW control enabled: %s\n",
1108 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1109 seq_printf(m, "SW control enabled: %s\n",
1110 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1111 seq_printf(m, "Gated voltage change: %s\n",
1112 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1113 seq_printf(m, "Starting frequency: P%d\n",
1114 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001115 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001116 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001117 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1118 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1119 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1120 seq_printf(m, "Render standby enabled: %s\n",
1121 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001122 seq_printf(m, "Current RS state: ");
1123 switch (rstdbyctl & RSX_STATUS_MASK) {
1124 case RSX_STATUS_ON:
1125 seq_printf(m, "on\n");
1126 break;
1127 case RSX_STATUS_RC1:
1128 seq_printf(m, "RC1\n");
1129 break;
1130 case RSX_STATUS_RC1E:
1131 seq_printf(m, "RC1E\n");
1132 break;
1133 case RSX_STATUS_RS1:
1134 seq_printf(m, "RS1\n");
1135 break;
1136 case RSX_STATUS_RS2:
1137 seq_printf(m, "RS2 (RC6)\n");
1138 break;
1139 case RSX_STATUS_RS3:
1140 seq_printf(m, "RC3 (RC6+)\n");
1141 break;
1142 default:
1143 seq_printf(m, "unknown\n");
1144 break;
1145 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001146
1147 return 0;
1148}
1149
Ben Widawsky4d855292011-12-12 19:34:16 -08001150static int gen6_drpc_info(struct seq_file *m)
1151{
1152
1153 struct drm_info_node *node = (struct drm_info_node *) m->private;
1154 struct drm_device *dev = node->minor->dev;
1155 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001156 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001157 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001158 int count=0, ret;
1159
1160
1161 ret = mutex_lock_interruptible(&dev->struct_mutex);
1162 if (ret)
1163 return ret;
1164
Daniel Vetter93b525d2012-01-25 13:52:43 +01001165 spin_lock_irq(&dev_priv->gt_lock);
1166 forcewake_count = dev_priv->forcewake_count;
1167 spin_unlock_irq(&dev_priv->gt_lock);
1168
1169 if (forcewake_count) {
1170 seq_printf(m, "RC information inaccurate because somebody "
1171 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001172 } else {
1173 /* NB: we cannot use forcewake, else we read the wrong values */
1174 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1175 udelay(10);
1176 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1177 }
1178
1179 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1180 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1181
1182 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1183 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1184 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001185 mutex_lock(&dev_priv->rps.hw_lock);
1186 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1187 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001188
1189 seq_printf(m, "Video Turbo Mode: %s\n",
1190 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1191 seq_printf(m, "HW control enabled: %s\n",
1192 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1193 seq_printf(m, "SW control enabled: %s\n",
1194 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1195 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001196 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001197 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1198 seq_printf(m, "RC6 Enabled: %s\n",
1199 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1200 seq_printf(m, "Deep RC6 Enabled: %s\n",
1201 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1202 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1203 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1204 seq_printf(m, "Current RC state: ");
1205 switch (gt_core_status & GEN6_RCn_MASK) {
1206 case GEN6_RC0:
1207 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1208 seq_printf(m, "Core Power Down\n");
1209 else
1210 seq_printf(m, "on\n");
1211 break;
1212 case GEN6_RC3:
1213 seq_printf(m, "RC3\n");
1214 break;
1215 case GEN6_RC6:
1216 seq_printf(m, "RC6\n");
1217 break;
1218 case GEN6_RC7:
1219 seq_printf(m, "RC7\n");
1220 break;
1221 default:
1222 seq_printf(m, "Unknown\n");
1223 break;
1224 }
1225
1226 seq_printf(m, "Core Power Down: %s\n",
1227 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001228
1229 /* Not exactly sure what this is */
1230 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1231 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1232 seq_printf(m, "RC6 residency since boot: %u\n",
1233 I915_READ(GEN6_GT_GFX_RC6));
1234 seq_printf(m, "RC6+ residency since boot: %u\n",
1235 I915_READ(GEN6_GT_GFX_RC6p));
1236 seq_printf(m, "RC6++ residency since boot: %u\n",
1237 I915_READ(GEN6_GT_GFX_RC6pp));
1238
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001239 seq_printf(m, "RC6 voltage: %dmV\n",
1240 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1241 seq_printf(m, "RC6+ voltage: %dmV\n",
1242 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1243 seq_printf(m, "RC6++ voltage: %dmV\n",
1244 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001245 return 0;
1246}
1247
1248static int i915_drpc_info(struct seq_file *m, void *unused)
1249{
1250 struct drm_info_node *node = (struct drm_info_node *) m->private;
1251 struct drm_device *dev = node->minor->dev;
1252
1253 if (IS_GEN6(dev) || IS_GEN7(dev))
1254 return gen6_drpc_info(m);
1255 else
1256 return ironlake_drpc_info(m);
1257}
1258
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001259static int i915_fbc_status(struct seq_file *m, void *unused)
1260{
1261 struct drm_info_node *node = (struct drm_info_node *) m->private;
1262 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001263 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001264
Adam Jacksonee5382a2010-04-23 11:17:39 -04001265 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001266 seq_printf(m, "FBC unsupported on this chipset\n");
1267 return 0;
1268 }
1269
Adam Jacksonee5382a2010-04-23 11:17:39 -04001270 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001271 seq_printf(m, "FBC enabled\n");
1272 } else {
1273 seq_printf(m, "FBC disabled: ");
1274 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001275 case FBC_NO_OUTPUT:
1276 seq_printf(m, "no outputs");
1277 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001278 case FBC_STOLEN_TOO_SMALL:
1279 seq_printf(m, "not enough stolen memory");
1280 break;
1281 case FBC_UNSUPPORTED_MODE:
1282 seq_printf(m, "mode not supported");
1283 break;
1284 case FBC_MODE_TOO_LARGE:
1285 seq_printf(m, "mode too large");
1286 break;
1287 case FBC_BAD_PLANE:
1288 seq_printf(m, "FBC unsupported on plane");
1289 break;
1290 case FBC_NOT_TILED:
1291 seq_printf(m, "scanout buffer not tiled");
1292 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001293 case FBC_MULTIPLE_PIPES:
1294 seq_printf(m, "multiple pipes are enabled");
1295 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001296 case FBC_MODULE_PARAM:
1297 seq_printf(m, "disabled per module param (default off)");
1298 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001299 default:
1300 seq_printf(m, "unknown reason");
1301 }
1302 seq_printf(m, "\n");
1303 }
1304 return 0;
1305}
1306
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001307static int i915_sr_status(struct seq_file *m, void *unused)
1308{
1309 struct drm_info_node *node = (struct drm_info_node *) m->private;
1310 struct drm_device *dev = node->minor->dev;
1311 drm_i915_private_t *dev_priv = dev->dev_private;
1312 bool sr_enabled = false;
1313
Yuanhan Liu13982612010-12-15 15:42:31 +08001314 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001315 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001316 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001317 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1318 else if (IS_I915GM(dev))
1319 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1320 else if (IS_PINEVIEW(dev))
1321 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1322
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001323 seq_printf(m, "self-refresh: %s\n",
1324 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001325
1326 return 0;
1327}
1328
Jesse Barnes7648fa92010-05-20 14:28:11 -07001329static int i915_emon_status(struct seq_file *m, void *unused)
1330{
1331 struct drm_info_node *node = (struct drm_info_node *) m->private;
1332 struct drm_device *dev = node->minor->dev;
1333 drm_i915_private_t *dev_priv = dev->dev_private;
1334 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001335 int ret;
1336
Chris Wilson582be6b2012-04-30 19:35:02 +01001337 if (!IS_GEN5(dev))
1338 return -ENODEV;
1339
Chris Wilsonde227ef2010-07-03 07:58:38 +01001340 ret = mutex_lock_interruptible(&dev->struct_mutex);
1341 if (ret)
1342 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001343
1344 temp = i915_mch_val(dev_priv);
1345 chipset = i915_chipset_val(dev_priv);
1346 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001347 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001348
1349 seq_printf(m, "GMCH temp: %ld\n", temp);
1350 seq_printf(m, "Chipset power: %ld\n", chipset);
1351 seq_printf(m, "GFX power: %ld\n", gfx);
1352 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1353
1354 return 0;
1355}
1356
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001357static int i915_ring_freq_table(struct seq_file *m, void *unused)
1358{
1359 struct drm_info_node *node = (struct drm_info_node *) m->private;
1360 struct drm_device *dev = node->minor->dev;
1361 drm_i915_private_t *dev_priv = dev->dev_private;
1362 int ret;
1363 int gpu_freq, ia_freq;
1364
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001365 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001366 seq_printf(m, "unsupported on this chipset\n");
1367 return 0;
1368 }
1369
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001370 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001371 if (ret)
1372 return ret;
1373
1374 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\n");
1375
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001376 for (gpu_freq = dev_priv->rps.min_delay;
1377 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001378 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001379 ia_freq = gpu_freq;
1380 sandybridge_pcode_read(dev_priv,
1381 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1382 &ia_freq);
Ben Widawskyc8735b02012-09-07 19:43:39 -07001383 seq_printf(m, "%d\t\t%d\n", gpu_freq * GT_FREQUENCY_MULTIPLIER, ia_freq * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001384 }
1385
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001386 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001387
1388 return 0;
1389}
1390
Jesse Barnes7648fa92010-05-20 14:28:11 -07001391static int i915_gfxec(struct seq_file *m, void *unused)
1392{
1393 struct drm_info_node *node = (struct drm_info_node *) m->private;
1394 struct drm_device *dev = node->minor->dev;
1395 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001396 int ret;
1397
1398 ret = mutex_lock_interruptible(&dev->struct_mutex);
1399 if (ret)
1400 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001401
1402 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1403
Ben Widawsky616fdb52011-10-05 11:44:54 -07001404 mutex_unlock(&dev->struct_mutex);
1405
Jesse Barnes7648fa92010-05-20 14:28:11 -07001406 return 0;
1407}
1408
Chris Wilson44834a62010-08-19 16:09:23 +01001409static int i915_opregion(struct seq_file *m, void *unused)
1410{
1411 struct drm_info_node *node = (struct drm_info_node *) m->private;
1412 struct drm_device *dev = node->minor->dev;
1413 drm_i915_private_t *dev_priv = dev->dev_private;
1414 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001415 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001416 int ret;
1417
Daniel Vetter0d38f002012-04-21 22:49:10 +02001418 if (data == NULL)
1419 return -ENOMEM;
1420
Chris Wilson44834a62010-08-19 16:09:23 +01001421 ret = mutex_lock_interruptible(&dev->struct_mutex);
1422 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001423 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001424
Daniel Vetter0d38f002012-04-21 22:49:10 +02001425 if (opregion->header) {
1426 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1427 seq_write(m, data, OPREGION_SIZE);
1428 }
Chris Wilson44834a62010-08-19 16:09:23 +01001429
1430 mutex_unlock(&dev->struct_mutex);
1431
Daniel Vetter0d38f002012-04-21 22:49:10 +02001432out:
1433 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001434 return 0;
1435}
1436
Chris Wilson37811fc2010-08-25 22:45:57 +01001437static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1438{
1439 struct drm_info_node *node = (struct drm_info_node *) m->private;
1440 struct drm_device *dev = node->minor->dev;
1441 drm_i915_private_t *dev_priv = dev->dev_private;
1442 struct intel_fbdev *ifbdev;
1443 struct intel_framebuffer *fb;
1444 int ret;
1445
1446 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1447 if (ret)
1448 return ret;
1449
1450 ifbdev = dev_priv->fbdev;
1451 fb = to_intel_framebuffer(ifbdev->helper.fb);
1452
Daniel Vetter623f9782012-12-11 16:21:38 +01001453 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001454 fb->base.width,
1455 fb->base.height,
1456 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001457 fb->base.bits_per_pixel,
1458 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001459 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001460 seq_printf(m, "\n");
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001461 mutex_unlock(&dev->mode_config.mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001462
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001463 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001464 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1465 if (&fb->base == ifbdev->helper.fb)
1466 continue;
1467
Daniel Vetter623f9782012-12-11 16:21:38 +01001468 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001469 fb->base.width,
1470 fb->base.height,
1471 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001472 fb->base.bits_per_pixel,
1473 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001474 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001475 seq_printf(m, "\n");
1476 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001477 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001478
1479 return 0;
1480}
1481
Ben Widawskye76d3632011-03-19 18:14:29 -07001482static int i915_context_status(struct seq_file *m, void *unused)
1483{
1484 struct drm_info_node *node = (struct drm_info_node *) m->private;
1485 struct drm_device *dev = node->minor->dev;
1486 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskya168c292013-02-14 15:05:12 -08001487 struct intel_ring_buffer *ring;
1488 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001489
1490 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1491 if (ret)
1492 return ret;
1493
Daniel Vetter3e373942012-11-02 19:55:04 +01001494 if (dev_priv->ips.pwrctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001495 seq_printf(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001496 describe_obj(m, dev_priv->ips.pwrctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001497 seq_printf(m, "\n");
1498 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001499
Daniel Vetter3e373942012-11-02 19:55:04 +01001500 if (dev_priv->ips.renderctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001501 seq_printf(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001502 describe_obj(m, dev_priv->ips.renderctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001503 seq_printf(m, "\n");
1504 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001505
Ben Widawskya168c292013-02-14 15:05:12 -08001506 for_each_ring(ring, dev_priv, i) {
1507 if (ring->default_context) {
1508 seq_printf(m, "HW default context %s ring ", ring->name);
1509 describe_obj(m, ring->default_context->obj);
1510 seq_printf(m, "\n");
1511 }
1512 }
1513
Ben Widawskye76d3632011-03-19 18:14:29 -07001514 mutex_unlock(&dev->mode_config.mutex);
1515
1516 return 0;
1517}
1518
Ben Widawsky6d794d42011-04-25 11:25:56 -07001519static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1520{
1521 struct drm_info_node *node = (struct drm_info_node *) m->private;
1522 struct drm_device *dev = node->minor->dev;
1523 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001524 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001525
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001526 spin_lock_irq(&dev_priv->gt_lock);
1527 forcewake_count = dev_priv->forcewake_count;
1528 spin_unlock_irq(&dev_priv->gt_lock);
1529
1530 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001531
1532 return 0;
1533}
1534
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001535static const char *swizzle_string(unsigned swizzle)
1536{
1537 switch(swizzle) {
1538 case I915_BIT_6_SWIZZLE_NONE:
1539 return "none";
1540 case I915_BIT_6_SWIZZLE_9:
1541 return "bit9";
1542 case I915_BIT_6_SWIZZLE_9_10:
1543 return "bit9/bit10";
1544 case I915_BIT_6_SWIZZLE_9_11:
1545 return "bit9/bit11";
1546 case I915_BIT_6_SWIZZLE_9_10_11:
1547 return "bit9/bit10/bit11";
1548 case I915_BIT_6_SWIZZLE_9_17:
1549 return "bit9/bit17";
1550 case I915_BIT_6_SWIZZLE_9_10_17:
1551 return "bit9/bit10/bit17";
1552 case I915_BIT_6_SWIZZLE_UNKNOWN:
1553 return "unkown";
1554 }
1555
1556 return "bug";
1557}
1558
1559static int i915_swizzle_info(struct seq_file *m, void *data)
1560{
1561 struct drm_info_node *node = (struct drm_info_node *) m->private;
1562 struct drm_device *dev = node->minor->dev;
1563 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001564 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001565
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001566 ret = mutex_lock_interruptible(&dev->struct_mutex);
1567 if (ret)
1568 return ret;
1569
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001570 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1571 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1572 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1573 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1574
1575 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1576 seq_printf(m, "DDC = 0x%08x\n",
1577 I915_READ(DCC));
1578 seq_printf(m, "C0DRB3 = 0x%04x\n",
1579 I915_READ16(C0DRB3));
1580 seq_printf(m, "C1DRB3 = 0x%04x\n",
1581 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001582 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1583 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1584 I915_READ(MAD_DIMM_C0));
1585 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1586 I915_READ(MAD_DIMM_C1));
1587 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1588 I915_READ(MAD_DIMM_C2));
1589 seq_printf(m, "TILECTL = 0x%08x\n",
1590 I915_READ(TILECTL));
1591 seq_printf(m, "ARB_MODE = 0x%08x\n",
1592 I915_READ(ARB_MODE));
1593 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1594 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001595 }
1596 mutex_unlock(&dev->struct_mutex);
1597
1598 return 0;
1599}
1600
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001601static int i915_ppgtt_info(struct seq_file *m, void *data)
1602{
1603 struct drm_info_node *node = (struct drm_info_node *) m->private;
1604 struct drm_device *dev = node->minor->dev;
1605 struct drm_i915_private *dev_priv = dev->dev_private;
1606 struct intel_ring_buffer *ring;
1607 int i, ret;
1608
1609
1610 ret = mutex_lock_interruptible(&dev->struct_mutex);
1611 if (ret)
1612 return ret;
1613 if (INTEL_INFO(dev)->gen == 6)
1614 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1615
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001616 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001617 seq_printf(m, "%s\n", ring->name);
1618 if (INTEL_INFO(dev)->gen == 7)
1619 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1620 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1621 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1622 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1623 }
1624 if (dev_priv->mm.aliasing_ppgtt) {
1625 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1626
1627 seq_printf(m, "aliasing PPGTT:\n");
1628 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1629 }
1630 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1631 mutex_unlock(&dev->struct_mutex);
1632
1633 return 0;
1634}
1635
Jesse Barnes57f350b2012-03-28 13:39:25 -07001636static int i915_dpio_info(struct seq_file *m, void *data)
1637{
1638 struct drm_info_node *node = (struct drm_info_node *) m->private;
1639 struct drm_device *dev = node->minor->dev;
1640 struct drm_i915_private *dev_priv = dev->dev_private;
1641 int ret;
1642
1643
1644 if (!IS_VALLEYVIEW(dev)) {
1645 seq_printf(m, "unsupported\n");
1646 return 0;
1647 }
1648
Daniel Vetter09153002012-12-12 14:06:44 +01001649 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001650 if (ret)
1651 return ret;
1652
1653 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1654
1655 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
1656 intel_dpio_read(dev_priv, _DPIO_DIV_A));
1657 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
1658 intel_dpio_read(dev_priv, _DPIO_DIV_B));
1659
1660 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
1661 intel_dpio_read(dev_priv, _DPIO_REFSFR_A));
1662 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
1663 intel_dpio_read(dev_priv, _DPIO_REFSFR_B));
1664
1665 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
1666 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
1667 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
1668 intel_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
1669
1670 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
1671 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
1672 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
1673 intel_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
1674
1675 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
1676 intel_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
1677
Daniel Vetter09153002012-12-12 14:06:44 +01001678 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001679
1680 return 0;
1681}
1682
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001683static ssize_t
1684i915_wedged_read(struct file *filp,
1685 char __user *ubuf,
1686 size_t max,
1687 loff_t *ppos)
1688{
1689 struct drm_device *dev = filp->private_data;
1690 drm_i915_private_t *dev_priv = dev->dev_private;
1691 char buf[80];
1692 int len;
1693
Akshay Joshi0206e352011-08-16 15:34:10 -04001694 len = snprintf(buf, sizeof(buf),
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001695 "wedged : %d\n",
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001696 atomic_read(&dev_priv->gpu_error.reset_counter));
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001697
Akshay Joshi0206e352011-08-16 15:34:10 -04001698 if (len > sizeof(buf))
1699 len = sizeof(buf);
Dan Carpenterf4433a82010-09-08 21:44:47 +02001700
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001701 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1702}
1703
1704static ssize_t
1705i915_wedged_write(struct file *filp,
1706 const char __user *ubuf,
1707 size_t cnt,
1708 loff_t *ppos)
1709{
1710 struct drm_device *dev = filp->private_data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001711 char buf[20];
1712 int val = 1;
1713
1714 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001715 if (cnt > sizeof(buf) - 1)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001716 return -EINVAL;
1717
1718 if (copy_from_user(buf, ubuf, cnt))
1719 return -EFAULT;
1720 buf[cnt] = 0;
1721
1722 val = simple_strtoul(buf, NULL, 0);
1723 }
1724
1725 DRM_INFO("Manually setting wedged to %d\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001726 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001727
1728 return cnt;
1729}
1730
1731static const struct file_operations i915_wedged_fops = {
1732 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001733 .open = simple_open,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001734 .read = i915_wedged_read,
1735 .write = i915_wedged_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001736 .llseek = default_llseek,
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001737};
1738
Jesse Barnes358733e2011-07-27 11:53:01 -07001739static ssize_t
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001740i915_ring_stop_read(struct file *filp,
1741 char __user *ubuf,
1742 size_t max,
1743 loff_t *ppos)
1744{
1745 struct drm_device *dev = filp->private_data;
1746 drm_i915_private_t *dev_priv = dev->dev_private;
1747 char buf[20];
1748 int len;
1749
1750 len = snprintf(buf, sizeof(buf),
Daniel Vetter99584db2012-11-14 17:14:04 +01001751 "0x%08x\n", dev_priv->gpu_error.stop_rings);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001752
1753 if (len > sizeof(buf))
1754 len = sizeof(buf);
1755
1756 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1757}
1758
1759static ssize_t
1760i915_ring_stop_write(struct file *filp,
1761 const char __user *ubuf,
1762 size_t cnt,
1763 loff_t *ppos)
1764{
1765 struct drm_device *dev = filp->private_data;
1766 struct drm_i915_private *dev_priv = dev->dev_private;
1767 char buf[20];
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001768 int val = 0, ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001769
1770 if (cnt > 0) {
1771 if (cnt > sizeof(buf) - 1)
1772 return -EINVAL;
1773
1774 if (copy_from_user(buf, ubuf, cnt))
1775 return -EFAULT;
1776 buf[cnt] = 0;
1777
1778 val = simple_strtoul(buf, NULL, 0);
1779 }
1780
1781 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val);
1782
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001783 ret = mutex_lock_interruptible(&dev->struct_mutex);
1784 if (ret)
1785 return ret;
1786
Daniel Vetter99584db2012-11-14 17:14:04 +01001787 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001788 mutex_unlock(&dev->struct_mutex);
1789
1790 return cnt;
1791}
1792
1793static const struct file_operations i915_ring_stop_fops = {
1794 .owner = THIS_MODULE,
1795 .open = simple_open,
1796 .read = i915_ring_stop_read,
1797 .write = i915_ring_stop_write,
1798 .llseek = default_llseek,
1799};
Daniel Vetterd5442302012-04-27 15:17:40 +02001800
Chris Wilsondd624af2013-01-15 12:39:35 +00001801#define DROP_UNBOUND 0x1
1802#define DROP_BOUND 0x2
1803#define DROP_RETIRE 0x4
1804#define DROP_ACTIVE 0x8
1805#define DROP_ALL (DROP_UNBOUND | \
1806 DROP_BOUND | \
1807 DROP_RETIRE | \
1808 DROP_ACTIVE)
1809static ssize_t
1810i915_drop_caches_read(struct file *filp,
1811 char __user *ubuf,
1812 size_t max,
1813 loff_t *ppos)
1814{
1815 char buf[20];
1816 int len;
1817
1818 len = snprintf(buf, sizeof(buf), "0x%08x\n", DROP_ALL);
1819 if (len > sizeof(buf))
1820 len = sizeof(buf);
1821
1822 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1823}
1824
1825static ssize_t
1826i915_drop_caches_write(struct file *filp,
1827 const char __user *ubuf,
1828 size_t cnt,
1829 loff_t *ppos)
1830{
1831 struct drm_device *dev = filp->private_data;
1832 struct drm_i915_private *dev_priv = dev->dev_private;
1833 struct drm_i915_gem_object *obj, *next;
1834 char buf[20];
1835 int val = 0, ret;
1836
1837 if (cnt > 0) {
1838 if (cnt > sizeof(buf) - 1)
1839 return -EINVAL;
1840
1841 if (copy_from_user(buf, ubuf, cnt))
1842 return -EFAULT;
1843 buf[cnt] = 0;
1844
1845 val = simple_strtoul(buf, NULL, 0);
1846 }
1847
1848 DRM_DEBUG_DRIVER("Dropping caches: 0x%08x\n", val);
1849
1850 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1851 * on ioctls on -EAGAIN. */
1852 ret = mutex_lock_interruptible(&dev->struct_mutex);
1853 if (ret)
1854 return ret;
1855
1856 if (val & DROP_ACTIVE) {
1857 ret = i915_gpu_idle(dev);
1858 if (ret)
1859 goto unlock;
1860 }
1861
1862 if (val & (DROP_RETIRE | DROP_ACTIVE))
1863 i915_gem_retire_requests(dev);
1864
1865 if (val & DROP_BOUND) {
1866 list_for_each_entry_safe(obj, next, &dev_priv->mm.inactive_list, mm_list)
1867 if (obj->pin_count == 0) {
1868 ret = i915_gem_object_unbind(obj);
1869 if (ret)
1870 goto unlock;
1871 }
1872 }
1873
1874 if (val & DROP_UNBOUND) {
1875 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list, gtt_list)
1876 if (obj->pages_pin_count == 0) {
1877 ret = i915_gem_object_put_pages(obj);
1878 if (ret)
1879 goto unlock;
1880 }
1881 }
1882
1883unlock:
1884 mutex_unlock(&dev->struct_mutex);
1885
1886 return ret ?: cnt;
1887}
1888
1889static const struct file_operations i915_drop_caches_fops = {
1890 .owner = THIS_MODULE,
1891 .open = simple_open,
1892 .read = i915_drop_caches_read,
1893 .write = i915_drop_caches_write,
1894 .llseek = default_llseek,
1895};
1896
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001897static ssize_t
Jesse Barnes358733e2011-07-27 11:53:01 -07001898i915_max_freq_read(struct file *filp,
1899 char __user *ubuf,
1900 size_t max,
1901 loff_t *ppos)
1902{
1903 struct drm_device *dev = filp->private_data;
1904 drm_i915_private_t *dev_priv = dev->dev_private;
1905 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001906 int len, ret;
1907
1908 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1909 return -ENODEV;
1910
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001911 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001912 if (ret)
1913 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001914
Akshay Joshi0206e352011-08-16 15:34:10 -04001915 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001916 "max freq: %d\n", dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001917 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001918
Akshay Joshi0206e352011-08-16 15:34:10 -04001919 if (len > sizeof(buf))
1920 len = sizeof(buf);
Jesse Barnes358733e2011-07-27 11:53:01 -07001921
1922 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1923}
1924
1925static ssize_t
1926i915_max_freq_write(struct file *filp,
1927 const char __user *ubuf,
1928 size_t cnt,
1929 loff_t *ppos)
1930{
1931 struct drm_device *dev = filp->private_data;
1932 struct drm_i915_private *dev_priv = dev->dev_private;
1933 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02001934 int val = 1, ret;
1935
1936 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1937 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001938
1939 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001940 if (cnt > sizeof(buf) - 1)
Jesse Barnes358733e2011-07-27 11:53:01 -07001941 return -EINVAL;
1942
1943 if (copy_from_user(buf, ubuf, cnt))
1944 return -EFAULT;
1945 buf[cnt] = 0;
1946
1947 val = simple_strtoul(buf, NULL, 0);
1948 }
1949
1950 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1951
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001952 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001953 if (ret)
1954 return ret;
1955
Jesse Barnes358733e2011-07-27 11:53:01 -07001956 /*
1957 * Turbo will still be enabled, but won't go above the set value.
1958 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07001959 dev_priv->rps.max_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes358733e2011-07-27 11:53:01 -07001960
Ben Widawskyc8735b02012-09-07 19:43:39 -07001961 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001962 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001963
1964 return cnt;
1965}
1966
1967static const struct file_operations i915_max_freq_fops = {
1968 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07001969 .open = simple_open,
Jesse Barnes358733e2011-07-27 11:53:01 -07001970 .read = i915_max_freq_read,
1971 .write = i915_max_freq_write,
1972 .llseek = default_llseek,
1973};
1974
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07001975static ssize_t
Jesse Barnes1523c312012-05-25 12:34:54 -07001976i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
1977 loff_t *ppos)
1978{
1979 struct drm_device *dev = filp->private_data;
1980 drm_i915_private_t *dev_priv = dev->dev_private;
1981 char buf[80];
Daniel Vetter004777c2012-08-09 15:07:01 +02001982 int len, ret;
1983
1984 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1985 return -ENODEV;
1986
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001987 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001988 if (ret)
1989 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001990
1991 len = snprintf(buf, sizeof(buf),
Ben Widawskyc8735b02012-09-07 19:43:39 -07001992 "min freq: %d\n", dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001993 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07001994
1995 if (len > sizeof(buf))
1996 len = sizeof(buf);
1997
1998 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1999}
2000
2001static ssize_t
2002i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
2003 loff_t *ppos)
2004{
2005 struct drm_device *dev = filp->private_data;
2006 struct drm_i915_private *dev_priv = dev->dev_private;
2007 char buf[20];
Daniel Vetter004777c2012-08-09 15:07:01 +02002008 int val = 1, ret;
2009
2010 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2011 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07002012
2013 if (cnt > 0) {
2014 if (cnt > sizeof(buf) - 1)
2015 return -EINVAL;
2016
2017 if (copy_from_user(buf, ubuf, cnt))
2018 return -EFAULT;
2019 buf[cnt] = 0;
2020
2021 val = simple_strtoul(buf, NULL, 0);
2022 }
2023
2024 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
2025
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002026 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002027 if (ret)
2028 return ret;
2029
Jesse Barnes1523c312012-05-25 12:34:54 -07002030 /*
2031 * Turbo will still be enabled, but won't go below the set value.
2032 */
Ben Widawskyc8735b02012-09-07 19:43:39 -07002033 dev_priv->rps.min_delay = val / GT_FREQUENCY_MULTIPLIER;
Jesse Barnes1523c312012-05-25 12:34:54 -07002034
Ben Widawskyc8735b02012-09-07 19:43:39 -07002035 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002036 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002037
2038 return cnt;
2039}
2040
2041static const struct file_operations i915_min_freq_fops = {
2042 .owner = THIS_MODULE,
2043 .open = simple_open,
2044 .read = i915_min_freq_read,
2045 .write = i915_min_freq_write,
2046 .llseek = default_llseek,
2047};
2048
2049static ssize_t
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002050i915_cache_sharing_read(struct file *filp,
2051 char __user *ubuf,
2052 size_t max,
2053 loff_t *ppos)
2054{
2055 struct drm_device *dev = filp->private_data;
2056 drm_i915_private_t *dev_priv = dev->dev_private;
2057 char buf[80];
2058 u32 snpcr;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002059 int len, ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002060
Daniel Vetter004777c2012-08-09 15:07:01 +02002061 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2062 return -ENODEV;
2063
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002064 ret = mutex_lock_interruptible(&dev->struct_mutex);
2065 if (ret)
2066 return ret;
2067
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002068 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2069 mutex_unlock(&dev_priv->dev->struct_mutex);
2070
Akshay Joshi0206e352011-08-16 15:34:10 -04002071 len = snprintf(buf, sizeof(buf),
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002072 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
2073 GEN6_MBC_SNPCR_SHIFT);
2074
Akshay Joshi0206e352011-08-16 15:34:10 -04002075 if (len > sizeof(buf))
2076 len = sizeof(buf);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002077
2078 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
2079}
2080
2081static ssize_t
2082i915_cache_sharing_write(struct file *filp,
2083 const char __user *ubuf,
2084 size_t cnt,
2085 loff_t *ppos)
2086{
2087 struct drm_device *dev = filp->private_data;
2088 struct drm_i915_private *dev_priv = dev->dev_private;
2089 char buf[20];
2090 u32 snpcr;
2091 int val = 1;
2092
Daniel Vetter004777c2012-08-09 15:07:01 +02002093 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2094 return -ENODEV;
2095
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002096 if (cnt > 0) {
Akshay Joshi0206e352011-08-16 15:34:10 -04002097 if (cnt > sizeof(buf) - 1)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002098 return -EINVAL;
2099
2100 if (copy_from_user(buf, ubuf, cnt))
2101 return -EFAULT;
2102 buf[cnt] = 0;
2103
2104 val = simple_strtoul(buf, NULL, 0);
2105 }
2106
2107 if (val < 0 || val > 3)
2108 return -EINVAL;
2109
2110 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val);
2111
2112 /* Update the cache sharing policy here as well */
2113 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2114 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2115 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2116 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2117
2118 return cnt;
2119}
2120
2121static const struct file_operations i915_cache_sharing_fops = {
2122 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07002123 .open = simple_open,
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002124 .read = i915_cache_sharing_read,
2125 .write = i915_cache_sharing_write,
2126 .llseek = default_llseek,
2127};
2128
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002129/* As the drm_debugfs_init() routines are called before dev->dev_private is
2130 * allocated we need to hook into the minor for release. */
2131static int
2132drm_add_fake_info_node(struct drm_minor *minor,
2133 struct dentry *ent,
2134 const void *key)
2135{
2136 struct drm_info_node *node;
2137
2138 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
2139 if (node == NULL) {
2140 debugfs_remove(ent);
2141 return -ENOMEM;
2142 }
2143
2144 node->minor = minor;
2145 node->dent = ent;
2146 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002147
2148 mutex_lock(&minor->debugfs_lock);
2149 list_add(&node->list, &minor->debugfs_list);
2150 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002151
2152 return 0;
2153}
2154
Ben Widawsky6d794d42011-04-25 11:25:56 -07002155static int i915_forcewake_open(struct inode *inode, struct file *file)
2156{
2157 struct drm_device *dev = inode->i_private;
2158 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002159
Daniel Vetter075edca2012-01-24 09:44:28 +01002160 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002161 return 0;
2162
Ben Widawsky6d794d42011-04-25 11:25:56 -07002163 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002164
2165 return 0;
2166}
2167
Ben Widawskyc43b5632012-04-16 14:07:40 -07002168static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002169{
2170 struct drm_device *dev = inode->i_private;
2171 struct drm_i915_private *dev_priv = dev->dev_private;
2172
Daniel Vetter075edca2012-01-24 09:44:28 +01002173 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002174 return 0;
2175
Ben Widawsky6d794d42011-04-25 11:25:56 -07002176 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002177
2178 return 0;
2179}
2180
2181static const struct file_operations i915_forcewake_fops = {
2182 .owner = THIS_MODULE,
2183 .open = i915_forcewake_open,
2184 .release = i915_forcewake_release,
2185};
2186
2187static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2188{
2189 struct drm_device *dev = minor->dev;
2190 struct dentry *ent;
2191
2192 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002193 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002194 root, dev,
2195 &i915_forcewake_fops);
2196 if (IS_ERR(ent))
2197 return PTR_ERR(ent);
2198
Ben Widawsky8eb57292011-05-11 15:10:58 -07002199 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002200}
2201
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002202static int i915_debugfs_create(struct dentry *root,
2203 struct drm_minor *minor,
2204 const char *name,
2205 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002206{
2207 struct drm_device *dev = minor->dev;
2208 struct dentry *ent;
2209
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002210 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002211 S_IRUGO | S_IWUSR,
2212 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002213 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002214 if (IS_ERR(ent))
2215 return PTR_ERR(ent);
2216
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002217 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002218}
2219
Ben Gamari27c202a2009-07-01 22:26:52 -04002220static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002221 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002222 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002223 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002224 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002225 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002226 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002227 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002228 {"i915_gem_request", i915_gem_request_info, 0},
2229 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002230 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002231 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002232 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2233 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2234 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002235 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2236 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2237 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2238 {"i915_inttoext_table", i915_inttoext_table, 0},
2239 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002240 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002241 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002242 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002243 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002244 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002245 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002246 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002247 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002248 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002249 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002250 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002251 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002252};
Ben Gamari27c202a2009-07-01 22:26:52 -04002253#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002254
Ben Gamari27c202a2009-07-01 22:26:52 -04002255int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002256{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002257 int ret;
2258
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002259 ret = i915_debugfs_create(minor->debugfs_root, minor,
2260 "i915_wedged",
2261 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002262 if (ret)
2263 return ret;
2264
Ben Widawsky6d794d42011-04-25 11:25:56 -07002265 ret = i915_forcewake_create(minor->debugfs_root, minor);
2266 if (ret)
2267 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002268
2269 ret = i915_debugfs_create(minor->debugfs_root, minor,
2270 "i915_max_freq",
2271 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002272 if (ret)
2273 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002274
2275 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002276 "i915_min_freq",
2277 &i915_min_freq_fops);
2278 if (ret)
2279 return ret;
2280
2281 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002282 "i915_cache_sharing",
2283 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002284 if (ret)
2285 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002286
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002287 ret = i915_debugfs_create(minor->debugfs_root, minor,
2288 "i915_ring_stop",
2289 &i915_ring_stop_fops);
2290 if (ret)
2291 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002292
Daniel Vetterd5442302012-04-27 15:17:40 +02002293 ret = i915_debugfs_create(minor->debugfs_root, minor,
Chris Wilsondd624af2013-01-15 12:39:35 +00002294 "i915_gem_drop_caches",
2295 &i915_drop_caches_fops);
2296 if (ret)
2297 return ret;
2298
2299 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetterd5442302012-04-27 15:17:40 +02002300 "i915_error_state",
2301 &i915_error_state_fops);
2302 if (ret)
2303 return ret;
2304
Mika Kuoppala40633212012-12-04 15:12:00 +02002305 ret = i915_debugfs_create(minor->debugfs_root, minor,
2306 "i915_next_seqno",
2307 &i915_next_seqno_fops);
2308 if (ret)
2309 return ret;
2310
Ben Gamari27c202a2009-07-01 22:26:52 -04002311 return drm_debugfs_create_files(i915_debugfs_list,
2312 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002313 minor->debugfs_root, minor);
2314}
2315
Ben Gamari27c202a2009-07-01 22:26:52 -04002316void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002317{
Ben Gamari27c202a2009-07-01 22:26:52 -04002318 drm_debugfs_remove_files(i915_debugfs_list,
2319 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002320 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2321 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002322 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2323 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002324 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2325 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002326 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2327 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002328 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2329 1, minor);
Chris Wilsondd624af2013-01-15 12:39:35 +00002330 drm_debugfs_remove_files((struct drm_info_list *) &i915_drop_caches_fops,
2331 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002332 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2333 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002334 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2335 1, minor);
Mika Kuoppala40633212012-12-04 15:12:00 +02002336 drm_debugfs_remove_files((struct drm_info_list *) &i915_next_seqno_fops,
2337 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002338}
2339
2340#endif /* CONFIG_DEBUG_FS */