blob: 58c6fd4c8610580ed3da4c423fa23c8c22b5cc46 [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>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b8882013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Ben Gamari20172632009-02-17 20:08:50 -050043#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));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010064#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
65#define SEP_SEMICOLON ;
66 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
67#undef PRINT_FLAG
68#undef SEP_SEMICOLON
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
Ben Widawsky1d693bc2013-07-31 17:00:00 -070093static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
94{
95 return obj->has_global_gtt_mapping ? "g" : " ";
96}
97
Chris Wilson37811fc2010-08-25 22:45:57 +010098static void
99describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
100{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700101 struct i915_vma *vma;
Ville Syrjäläfb1ae912013-08-22 19:21:30 +0300102 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %u %u %u%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100103 &obj->base,
104 get_pin_flag(obj),
105 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700106 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800107 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100108 obj->base.read_domains,
109 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100110 obj->last_read_seqno,
111 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000112 obj->last_fenced_seqno,
Mika Kuoppala84734a02013-07-12 16:50:57 +0300113 i915_cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100114 obj->dirty ? " dirty" : "",
115 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
116 if (obj->base.name)
117 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilsonc110a6d2012-08-11 15:41:02 +0100118 if (obj->pin_count)
119 seq_printf(m, " (pinned x %d)", obj->pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100120 if (obj->pin_display)
121 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100122 if (obj->fence_reg != I915_FENCE_REG_NONE)
123 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700124 list_for_each_entry(vma, &obj->vma_list, vma_link) {
125 if (!i915_is_ggtt(vma->vm))
126 seq_puts(m, " (pp");
127 else
128 seq_puts(m, " (g");
129 seq_printf(m, "gtt offset: %08lx, size: %08lx)",
130 vma->node.start, vma->node.size);
131 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000132 if (obj->stolen)
133 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000134 if (obj->pin_mappable || obj->fault_mappable) {
135 char s[3], *t = s;
136 if (obj->pin_mappable)
137 *t++ = 'p';
138 if (obj->fault_mappable)
139 *t++ = 'f';
140 *t = '\0';
141 seq_printf(m, " (%s mappable)", s);
142 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100143 if (obj->ring != NULL)
144 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100145}
146
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700147static void describe_ctx(struct seq_file *m, struct i915_hw_context *ctx)
148{
149 seq_putc(m, ctx->is_initialized ? 'I' : 'i');
150 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
151 seq_putc(m, ' ');
152}
153
Ben Gamari433e12f2009-02-17 20:08:51 -0500154static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500155{
156 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500157 uintptr_t list = (uintptr_t) node->info_ent->data;
158 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500159 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700160 struct drm_i915_private *dev_priv = dev->dev_private;
161 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700162 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100163 size_t total_obj_size, total_gtt_size;
164 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100165
166 ret = mutex_lock_interruptible(&dev->struct_mutex);
167 if (ret)
168 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500169
Ben Widawskyca191b12013-07-31 17:00:14 -0700170 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500171 switch (list) {
172 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100173 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700174 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500175 break;
176 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100177 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700178 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500179 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500180 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100181 mutex_unlock(&dev->struct_mutex);
182 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500183 }
184
Chris Wilson8f2480f2010-09-26 11:44:19 +0100185 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700186 list_for_each_entry(vma, head, mm_list) {
187 seq_printf(m, " ");
188 describe_obj(m, vma->obj);
189 seq_printf(m, "\n");
190 total_obj_size += vma->obj->base.size;
191 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100192 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500193 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100194 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700195
Chris Wilson8f2480f2010-09-26 11:44:19 +0100196 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
197 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500198 return 0;
199}
200
Chris Wilson6d2b8882013-08-07 18:30:54 +0100201static int obj_rank_by_stolen(void *priv,
202 struct list_head *A, struct list_head *B)
203{
204 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200205 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100206 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200207 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100208
209 return a->stolen->start - b->stolen->start;
210}
211
212static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
213{
214 struct drm_info_node *node = (struct drm_info_node *) m->private;
215 struct drm_device *dev = node->minor->dev;
216 struct drm_i915_private *dev_priv = dev->dev_private;
217 struct drm_i915_gem_object *obj;
218 size_t total_obj_size, total_gtt_size;
219 LIST_HEAD(stolen);
220 int count, ret;
221
222 ret = mutex_lock_interruptible(&dev->struct_mutex);
223 if (ret)
224 return ret;
225
226 total_obj_size = total_gtt_size = count = 0;
227 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
228 if (obj->stolen == NULL)
229 continue;
230
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200231 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100232
233 total_obj_size += obj->base.size;
234 total_gtt_size += i915_gem_obj_ggtt_size(obj);
235 count++;
236 }
237 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
238 if (obj->stolen == NULL)
239 continue;
240
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200241 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100242
243 total_obj_size += obj->base.size;
244 count++;
245 }
246 list_sort(NULL, &stolen, obj_rank_by_stolen);
247 seq_puts(m, "Stolen:\n");
248 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200249 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100250 seq_puts(m, " ");
251 describe_obj(m, obj);
252 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200253 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100254 }
255 mutex_unlock(&dev->struct_mutex);
256
257 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
258 count, total_obj_size, total_gtt_size);
259 return 0;
260}
261
Chris Wilson6299f992010-11-24 12:23:44 +0000262#define count_objects(list, member) do { \
263 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700264 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000265 ++count; \
266 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700267 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000268 ++mappable_count; \
269 } \
270 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400271} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000272
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100273struct file_stats {
274 int count;
275 size_t total, active, inactive, unbound;
276};
277
278static int per_file_stats(int id, void *ptr, void *data)
279{
280 struct drm_i915_gem_object *obj = ptr;
281 struct file_stats *stats = data;
282
283 stats->count++;
284 stats->total += obj->base.size;
285
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700286 if (i915_gem_obj_ggtt_bound(obj)) {
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100287 if (!list_empty(&obj->ring_list))
288 stats->active += obj->base.size;
289 else
290 stats->inactive += obj->base.size;
291 } else {
292 if (!list_empty(&obj->global_list))
293 stats->unbound += obj->base.size;
294 }
295
296 return 0;
297}
298
Ben Widawskyca191b12013-07-31 17:00:14 -0700299#define count_vmas(list, member) do { \
300 list_for_each_entry(vma, list, member) { \
301 size += i915_gem_obj_ggtt_size(vma->obj); \
302 ++count; \
303 if (vma->obj->map_and_fenceable) { \
304 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
305 ++mappable_count; \
306 } \
307 } \
308} while (0)
309
310static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100311{
312 struct drm_info_node *node = (struct drm_info_node *) m->private;
313 struct drm_device *dev = node->minor->dev;
314 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200315 u32 count, mappable_count, purgeable_count;
316 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000317 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700318 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100319 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700320 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100321 int ret;
322
323 ret = mutex_lock_interruptible(&dev->struct_mutex);
324 if (ret)
325 return ret;
326
Chris Wilson6299f992010-11-24 12:23:44 +0000327 seq_printf(m, "%u objects, %zu bytes\n",
328 dev_priv->mm.object_count,
329 dev_priv->mm.object_memory);
330
331 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700332 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000333 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
334 count, mappable_count, size, mappable_size);
335
336 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700337 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000338 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
339 count, mappable_count, size, mappable_size);
340
341 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700342 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000343 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
344 count, mappable_count, size, mappable_size);
345
Chris Wilsonb7abb712012-08-20 11:33:30 +0200346 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700347 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200348 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200349 if (obj->madv == I915_MADV_DONTNEED)
350 purgeable_size += obj->base.size, ++purgeable_count;
351 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200352 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
353
Chris Wilson6299f992010-11-24 12:23:44 +0000354 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700355 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000356 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700357 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000358 ++count;
359 }
360 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700361 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000362 ++mappable_count;
363 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200364 if (obj->madv == I915_MADV_DONTNEED) {
365 purgeable_size += obj->base.size;
366 ++purgeable_count;
367 }
Chris Wilson6299f992010-11-24 12:23:44 +0000368 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200369 seq_printf(m, "%u purgeable objects, %zu bytes\n",
370 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000371 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
372 mappable_count, mappable_size);
373 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
374 count, size);
375
Ben Widawsky93d18792013-01-17 12:45:17 -0800376 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700377 dev_priv->gtt.base.total,
378 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100379
Damien Lespiau267f0c92013-06-24 22:59:48 +0100380 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100381 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
382 struct file_stats stats;
383
384 memset(&stats, 0, sizeof(stats));
385 idr_for_each(&file->object_idr, per_file_stats, &stats);
386 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu unbound)\n",
387 get_pid_task(file->pid, PIDTYPE_PID)->comm,
388 stats.count,
389 stats.total,
390 stats.active,
391 stats.inactive,
392 stats.unbound);
393 }
394
Chris Wilson73aa8082010-09-30 11:46:12 +0100395 mutex_unlock(&dev->struct_mutex);
396
397 return 0;
398}
399
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100400static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000401{
402 struct drm_info_node *node = (struct drm_info_node *) m->private;
403 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100404 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000405 struct drm_i915_private *dev_priv = dev->dev_private;
406 struct drm_i915_gem_object *obj;
407 size_t total_obj_size, total_gtt_size;
408 int count, ret;
409
410 ret = mutex_lock_interruptible(&dev->struct_mutex);
411 if (ret)
412 return ret;
413
414 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700415 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100416 if (list == PINNED_LIST && obj->pin_count == 0)
417 continue;
418
Damien Lespiau267f0c92013-06-24 22:59:48 +0100419 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000420 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100421 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000422 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700423 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000424 count++;
425 }
426
427 mutex_unlock(&dev->struct_mutex);
428
429 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
430 count, total_obj_size, total_gtt_size);
431
432 return 0;
433}
434
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100435static int i915_gem_pageflip_info(struct seq_file *m, void *data)
436{
437 struct drm_info_node *node = (struct drm_info_node *) m->private;
438 struct drm_device *dev = node->minor->dev;
439 unsigned long flags;
440 struct intel_crtc *crtc;
441
442 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800443 const char pipe = pipe_name(crtc->pipe);
444 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100445 struct intel_unpin_work *work;
446
447 spin_lock_irqsave(&dev->event_lock, flags);
448 work = crtc->unpin_work;
449 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800450 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100451 pipe, plane);
452 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000453 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800454 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100455 pipe, plane);
456 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800457 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100458 pipe, plane);
459 }
460 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100461 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100462 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100463 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000464 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100465
466 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000467 struct drm_i915_gem_object *obj = work->old_fb_obj;
468 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700469 seq_printf(m, "Old framebuffer gtt_offset 0x%08lx\n",
470 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100471 }
472 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000473 struct drm_i915_gem_object *obj = work->pending_flip_obj;
474 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700475 seq_printf(m, "New framebuffer gtt_offset 0x%08lx\n",
476 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100477 }
478 }
479 spin_unlock_irqrestore(&dev->event_lock, flags);
480 }
481
482 return 0;
483}
484
Ben Gamari20172632009-02-17 20:08:50 -0500485static int i915_gem_request_info(struct seq_file *m, void *data)
486{
487 struct drm_info_node *node = (struct drm_info_node *) m->private;
488 struct drm_device *dev = node->minor->dev;
489 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100490 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500491 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100492 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100493
494 ret = mutex_lock_interruptible(&dev->struct_mutex);
495 if (ret)
496 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500497
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100498 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100499 for_each_ring(ring, dev_priv, i) {
500 if (list_empty(&ring->request_list))
501 continue;
502
503 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100504 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100505 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100506 list) {
507 seq_printf(m, " %d @ %d\n",
508 gem_request->seqno,
509 (int) (jiffies - gem_request->emitted_jiffies));
510 }
511 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500512 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100513 mutex_unlock(&dev->struct_mutex);
514
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100515 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100516 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100517
Ben Gamari20172632009-02-17 20:08:50 -0500518 return 0;
519}
520
Chris Wilsonb2223492010-10-27 15:27:33 +0100521static void i915_ring_seqno_info(struct seq_file *m,
522 struct intel_ring_buffer *ring)
523{
524 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200525 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100526 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100527 }
528}
529
Ben Gamari20172632009-02-17 20:08:50 -0500530static int i915_gem_seqno_info(struct seq_file *m, void *data)
531{
532 struct drm_info_node *node = (struct drm_info_node *) m->private;
533 struct drm_device *dev = node->minor->dev;
534 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100535 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000536 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100537
538 ret = mutex_lock_interruptible(&dev->struct_mutex);
539 if (ret)
540 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500541
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100542 for_each_ring(ring, dev_priv, i)
543 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100544
545 mutex_unlock(&dev->struct_mutex);
546
Ben Gamari20172632009-02-17 20:08:50 -0500547 return 0;
548}
549
550
551static int i915_interrupt_info(struct seq_file *m, void *data)
552{
553 struct drm_info_node *node = (struct drm_info_node *) m->private;
554 struct drm_device *dev = node->minor->dev;
555 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100556 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800557 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100558
559 ret = mutex_lock_interruptible(&dev->struct_mutex);
560 if (ret)
561 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500562
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700563 if (IS_VALLEYVIEW(dev)) {
564 seq_printf(m, "Display IER:\t%08x\n",
565 I915_READ(VLV_IER));
566 seq_printf(m, "Display IIR:\t%08x\n",
567 I915_READ(VLV_IIR));
568 seq_printf(m, "Display IIR_RW:\t%08x\n",
569 I915_READ(VLV_IIR_RW));
570 seq_printf(m, "Display IMR:\t%08x\n",
571 I915_READ(VLV_IMR));
572 for_each_pipe(pipe)
573 seq_printf(m, "Pipe %c stat:\t%08x\n",
574 pipe_name(pipe),
575 I915_READ(PIPESTAT(pipe)));
576
577 seq_printf(m, "Master IER:\t%08x\n",
578 I915_READ(VLV_MASTER_IER));
579
580 seq_printf(m, "Render IER:\t%08x\n",
581 I915_READ(GTIER));
582 seq_printf(m, "Render IIR:\t%08x\n",
583 I915_READ(GTIIR));
584 seq_printf(m, "Render IMR:\t%08x\n",
585 I915_READ(GTIMR));
586
587 seq_printf(m, "PM IER:\t\t%08x\n",
588 I915_READ(GEN6_PMIER));
589 seq_printf(m, "PM IIR:\t\t%08x\n",
590 I915_READ(GEN6_PMIIR));
591 seq_printf(m, "PM IMR:\t\t%08x\n",
592 I915_READ(GEN6_PMIMR));
593
594 seq_printf(m, "Port hotplug:\t%08x\n",
595 I915_READ(PORT_HOTPLUG_EN));
596 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
597 I915_READ(VLV_DPFLIPSTAT));
598 seq_printf(m, "DPINVGTT:\t%08x\n",
599 I915_READ(DPINVGTT));
600
601 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800602 seq_printf(m, "Interrupt enable: %08x\n",
603 I915_READ(IER));
604 seq_printf(m, "Interrupt identity: %08x\n",
605 I915_READ(IIR));
606 seq_printf(m, "Interrupt mask: %08x\n",
607 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800608 for_each_pipe(pipe)
609 seq_printf(m, "Pipe %c stat: %08x\n",
610 pipe_name(pipe),
611 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800612 } else {
613 seq_printf(m, "North Display Interrupt enable: %08x\n",
614 I915_READ(DEIER));
615 seq_printf(m, "North Display Interrupt identity: %08x\n",
616 I915_READ(DEIIR));
617 seq_printf(m, "North Display Interrupt mask: %08x\n",
618 I915_READ(DEIMR));
619 seq_printf(m, "South Display Interrupt enable: %08x\n",
620 I915_READ(SDEIER));
621 seq_printf(m, "South Display Interrupt identity: %08x\n",
622 I915_READ(SDEIIR));
623 seq_printf(m, "South Display Interrupt mask: %08x\n",
624 I915_READ(SDEIMR));
625 seq_printf(m, "Graphics Interrupt enable: %08x\n",
626 I915_READ(GTIER));
627 seq_printf(m, "Graphics Interrupt identity: %08x\n",
628 I915_READ(GTIIR));
629 seq_printf(m, "Graphics Interrupt mask: %08x\n",
630 I915_READ(GTIMR));
631 }
Ben Gamari20172632009-02-17 20:08:50 -0500632 seq_printf(m, "Interrupts received: %d\n",
633 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100634 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700635 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100636 seq_printf(m,
637 "Graphics Interrupt mask (%s): %08x\n",
638 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000639 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100640 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000641 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100642 mutex_unlock(&dev->struct_mutex);
643
Ben Gamari20172632009-02-17 20:08:50 -0500644 return 0;
645}
646
Chris Wilsona6172a82009-02-11 14:26:38 +0000647static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
648{
649 struct drm_info_node *node = (struct drm_info_node *) m->private;
650 struct drm_device *dev = node->minor->dev;
651 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100652 int i, ret;
653
654 ret = mutex_lock_interruptible(&dev->struct_mutex);
655 if (ret)
656 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000657
658 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
659 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
660 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000661 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000662
Chris Wilson6c085a72012-08-20 11:40:46 +0200663 seq_printf(m, "Fence %d, pin count = %d, object = ",
664 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100665 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100666 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100667 else
Chris Wilson05394f32010-11-08 19:18:58 +0000668 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100669 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000670 }
671
Chris Wilson05394f32010-11-08 19:18:58 +0000672 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000673 return 0;
674}
675
Ben Gamari20172632009-02-17 20:08:50 -0500676static int i915_hws_info(struct seq_file *m, void *data)
677{
678 struct drm_info_node *node = (struct drm_info_node *) m->private;
679 struct drm_device *dev = node->minor->dev;
680 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100681 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100682 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100683 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500684
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000685 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100686 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500687 if (hws == NULL)
688 return 0;
689
690 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
691 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
692 i * 4,
693 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
694 }
695 return 0;
696}
697
Daniel Vetterd5442302012-04-27 15:17:40 +0200698static ssize_t
699i915_error_state_write(struct file *filp,
700 const char __user *ubuf,
701 size_t cnt,
702 loff_t *ppos)
703{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300704 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200705 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200706 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200707
708 DRM_DEBUG_DRIVER("Resetting error state\n");
709
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200710 ret = mutex_lock_interruptible(&dev->struct_mutex);
711 if (ret)
712 return ret;
713
Daniel Vetterd5442302012-04-27 15:17:40 +0200714 i915_destroy_error_state(dev);
715 mutex_unlock(&dev->struct_mutex);
716
717 return cnt;
718}
719
720static int i915_error_state_open(struct inode *inode, struct file *file)
721{
722 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200723 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200724
725 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
726 if (!error_priv)
727 return -ENOMEM;
728
729 error_priv->dev = dev;
730
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300731 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200732
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300733 file->private_data = error_priv;
734
735 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200736}
737
738static int i915_error_state_release(struct inode *inode, struct file *file)
739{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300740 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200741
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300742 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200743 kfree(error_priv);
744
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300745 return 0;
746}
747
748static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
749 size_t count, loff_t *pos)
750{
751 struct i915_error_state_file_priv *error_priv = file->private_data;
752 struct drm_i915_error_state_buf error_str;
753 loff_t tmp_pos = 0;
754 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300755 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300756
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300757 ret = i915_error_state_buf_init(&error_str, count, *pos);
758 if (ret)
759 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300760
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300761 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300762 if (ret)
763 goto out;
764
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300765 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
766 error_str.buf,
767 error_str.bytes);
768
769 if (ret_count < 0)
770 ret = ret_count;
771 else
772 *pos = error_str.start + ret_count;
773out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300774 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300775 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200776}
777
778static const struct file_operations i915_error_state_fops = {
779 .owner = THIS_MODULE,
780 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300781 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200782 .write = i915_error_state_write,
783 .llseek = default_llseek,
784 .release = i915_error_state_release,
785};
786
Kees Cook647416f2013-03-10 14:10:06 -0700787static int
788i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200789{
Kees Cook647416f2013-03-10 14:10:06 -0700790 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200791 drm_i915_private_t *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200792 int ret;
793
794 ret = mutex_lock_interruptible(&dev->struct_mutex);
795 if (ret)
796 return ret;
797
Kees Cook647416f2013-03-10 14:10:06 -0700798 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200799 mutex_unlock(&dev->struct_mutex);
800
Kees Cook647416f2013-03-10 14:10:06 -0700801 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200802}
803
Kees Cook647416f2013-03-10 14:10:06 -0700804static int
805i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200806{
Kees Cook647416f2013-03-10 14:10:06 -0700807 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200808 int ret;
809
Mika Kuoppala40633212012-12-04 15:12:00 +0200810 ret = mutex_lock_interruptible(&dev->struct_mutex);
811 if (ret)
812 return ret;
813
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200814 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200815 mutex_unlock(&dev->struct_mutex);
816
Kees Cook647416f2013-03-10 14:10:06 -0700817 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200818}
819
Kees Cook647416f2013-03-10 14:10:06 -0700820DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
821 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +0300822 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +0200823
Jesse Barnesf97108d2010-01-29 11:27:07 -0800824static int i915_rstdby_delays(struct seq_file *m, void *unused)
825{
826 struct drm_info_node *node = (struct drm_info_node *) m->private;
827 struct drm_device *dev = node->minor->dev;
828 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700829 u16 crstanddelay;
830 int ret;
831
832 ret = mutex_lock_interruptible(&dev->struct_mutex);
833 if (ret)
834 return ret;
835
836 crstanddelay = I915_READ16(CRSTANDVID);
837
838 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800839
840 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
841
842 return 0;
843}
844
845static int i915_cur_delayinfo(struct seq_file *m, void *unused)
846{
847 struct drm_info_node *node = (struct drm_info_node *) m->private;
848 struct drm_device *dev = node->minor->dev;
849 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100850 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800851
Tom O'Rourke5c9669c2013-09-16 14:56:43 -0700852 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
853
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800854 if (IS_GEN5(dev)) {
855 u16 rgvswctl = I915_READ16(MEMSWCTL);
856 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
857
858 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
859 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
860 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
861 MEMSTAT_VID_SHIFT);
862 seq_printf(m, "Current P-state: %d\n",
863 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700864 } else if ((IS_GEN6(dev) || IS_GEN7(dev)) && !IS_VALLEYVIEW(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800865 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
866 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
867 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson8e8c06c2013-08-26 19:51:01 -0300868 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800869 u32 rpupei, rpcurup, rpprevup;
870 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800871 int max_freq;
872
873 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100874 ret = mutex_lock_interruptible(&dev->struct_mutex);
875 if (ret)
876 return ret;
877
Ben Widawskyfcca7922011-04-25 11:23:07 -0700878 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800879
Chris Wilson8e8c06c2013-08-26 19:51:01 -0300880 reqf = I915_READ(GEN6_RPNSWREQ);
881 reqf &= ~GEN6_TURBO_DISABLE;
882 if (IS_HASWELL(dev))
883 reqf >>= 24;
884 else
885 reqf >>= 25;
886 reqf *= GT_FREQUENCY_MULTIPLIER;
887
Jesse Barnesccab5c82011-01-18 15:49:25 -0800888 rpstat = I915_READ(GEN6_RPSTAT1);
889 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
890 rpcurup = I915_READ(GEN6_RP_CUR_UP);
891 rpprevup = I915_READ(GEN6_RP_PREV_UP);
892 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
893 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
894 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800895 if (IS_HASWELL(dev))
896 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
897 else
898 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
899 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800900
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100901 gen6_gt_force_wake_put(dev_priv);
902 mutex_unlock(&dev->struct_mutex);
903
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800904 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800905 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800906 seq_printf(m, "Render p-state ratio: %d\n",
907 (gt_perf_status & 0xff00) >> 8);
908 seq_printf(m, "Render p-state VID: %d\n",
909 gt_perf_status & 0xff);
910 seq_printf(m, "Render p-state limit: %d\n",
911 rp_state_limits & 0xff);
Chris Wilson8e8c06c2013-08-26 19:51:01 -0300912 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800913 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800914 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
915 GEN6_CURICONT_MASK);
916 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
917 GEN6_CURBSYTAVG_MASK);
918 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
919 GEN6_CURBSYTAVG_MASK);
920 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
921 GEN6_CURIAVG_MASK);
922 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
923 GEN6_CURBSYTAVG_MASK);
924 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
925 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800926
927 max_freq = (rp_state_cap & 0xff0000) >> 16;
928 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700929 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800930
931 max_freq = (rp_state_cap & 0xff00) >> 8;
932 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700933 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800934
935 max_freq = rp_state_cap & 0xff;
936 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700937 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -0700938
939 seq_printf(m, "Max overclocked frequency: %dMHz\n",
940 dev_priv->rps.hw_max * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700941 } else if (IS_VALLEYVIEW(dev)) {
942 u32 freq_sts, val;
943
Jesse Barnes259bd5d2013-04-22 15:59:30 -0700944 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +0300945 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700946 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
947 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
948
Jani Nikula64936252013-05-22 15:36:20 +0300949 val = vlv_punit_read(dev_priv, PUNIT_FUSE_BUS1);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700950 seq_printf(m, "max GPU freq: %d MHz\n",
951 vlv_gpu_freq(dev_priv->mem_freq, val));
952
Jani Nikula64936252013-05-22 15:36:20 +0300953 val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700954 seq_printf(m, "min GPU freq: %d MHz\n",
955 vlv_gpu_freq(dev_priv->mem_freq, val));
956
957 seq_printf(m, "current GPU freq: %d MHz\n",
958 vlv_gpu_freq(dev_priv->mem_freq,
959 (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -0700960 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800961 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +0100962 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800963 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800964
965 return 0;
966}
967
968static int i915_delayfreq_table(struct seq_file *m, void *unused)
969{
970 struct drm_info_node *node = (struct drm_info_node *) m->private;
971 struct drm_device *dev = node->minor->dev;
972 drm_i915_private_t *dev_priv = dev->dev_private;
973 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700974 int ret, i;
975
976 ret = mutex_lock_interruptible(&dev->struct_mutex);
977 if (ret)
978 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800979
980 for (i = 0; i < 16; i++) {
981 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700982 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
983 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800984 }
985
Ben Widawsky616fdb52011-10-05 11:44:54 -0700986 mutex_unlock(&dev->struct_mutex);
987
Jesse Barnesf97108d2010-01-29 11:27:07 -0800988 return 0;
989}
990
991static inline int MAP_TO_MV(int map)
992{
993 return 1250 - (map * 25);
994}
995
996static int i915_inttoext_table(struct seq_file *m, void *unused)
997{
998 struct drm_info_node *node = (struct drm_info_node *) m->private;
999 struct drm_device *dev = node->minor->dev;
1000 drm_i915_private_t *dev_priv = dev->dev_private;
1001 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001002 int ret, i;
1003
1004 ret = mutex_lock_interruptible(&dev->struct_mutex);
1005 if (ret)
1006 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001007
1008 for (i = 1; i <= 32; i++) {
1009 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1010 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1011 }
1012
Ben Widawsky616fdb52011-10-05 11:44:54 -07001013 mutex_unlock(&dev->struct_mutex);
1014
Jesse Barnesf97108d2010-01-29 11:27:07 -08001015 return 0;
1016}
1017
Ben Widawsky4d855292011-12-12 19:34:16 -08001018static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001019{
1020 struct drm_info_node *node = (struct drm_info_node *) m->private;
1021 struct drm_device *dev = node->minor->dev;
1022 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001023 u32 rgvmodectl, rstdbyctl;
1024 u16 crstandvid;
1025 int ret;
1026
1027 ret = mutex_lock_interruptible(&dev->struct_mutex);
1028 if (ret)
1029 return ret;
1030
1031 rgvmodectl = I915_READ(MEMMODECTL);
1032 rstdbyctl = I915_READ(RSTDBYCTL);
1033 crstandvid = I915_READ16(CRSTANDVID);
1034
1035 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001036
1037 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1038 "yes" : "no");
1039 seq_printf(m, "Boost freq: %d\n",
1040 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1041 MEMMODE_BOOST_FREQ_SHIFT);
1042 seq_printf(m, "HW control enabled: %s\n",
1043 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1044 seq_printf(m, "SW control enabled: %s\n",
1045 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1046 seq_printf(m, "Gated voltage change: %s\n",
1047 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1048 seq_printf(m, "Starting frequency: P%d\n",
1049 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001050 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001051 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001052 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1053 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1054 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1055 seq_printf(m, "Render standby enabled: %s\n",
1056 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001057 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001058 switch (rstdbyctl & RSX_STATUS_MASK) {
1059 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001060 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001061 break;
1062 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001063 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001064 break;
1065 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001066 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001067 break;
1068 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001069 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001070 break;
1071 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001072 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001073 break;
1074 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001075 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001076 break;
1077 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001078 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001079 break;
1080 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001081
1082 return 0;
1083}
1084
Ben Widawsky4d855292011-12-12 19:34:16 -08001085static int gen6_drpc_info(struct seq_file *m)
1086{
1087
1088 struct drm_info_node *node = (struct drm_info_node *) m->private;
1089 struct drm_device *dev = node->minor->dev;
1090 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001091 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001092 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001093 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001094
1095 ret = mutex_lock_interruptible(&dev->struct_mutex);
1096 if (ret)
1097 return ret;
1098
Chris Wilson907b28c2013-07-19 20:36:52 +01001099 spin_lock_irq(&dev_priv->uncore.lock);
1100 forcewake_count = dev_priv->uncore.forcewake_count;
1101 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001102
1103 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001104 seq_puts(m, "RC information inaccurate because somebody "
1105 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001106 } else {
1107 /* NB: we cannot use forcewake, else we read the wrong values */
1108 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1109 udelay(10);
1110 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1111 }
1112
1113 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001114 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001115
1116 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1117 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1118 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001119 mutex_lock(&dev_priv->rps.hw_lock);
1120 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1121 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001122
1123 seq_printf(m, "Video Turbo Mode: %s\n",
1124 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1125 seq_printf(m, "HW control enabled: %s\n",
1126 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1127 seq_printf(m, "SW control enabled: %s\n",
1128 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1129 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001130 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001131 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1132 seq_printf(m, "RC6 Enabled: %s\n",
1133 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1134 seq_printf(m, "Deep RC6 Enabled: %s\n",
1135 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1136 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1137 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001138 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001139 switch (gt_core_status & GEN6_RCn_MASK) {
1140 case GEN6_RC0:
1141 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001142 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001143 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001144 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001145 break;
1146 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001147 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001148 break;
1149 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001150 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001151 break;
1152 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001153 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001154 break;
1155 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001156 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001157 break;
1158 }
1159
1160 seq_printf(m, "Core Power Down: %s\n",
1161 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001162
1163 /* Not exactly sure what this is */
1164 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1165 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1166 seq_printf(m, "RC6 residency since boot: %u\n",
1167 I915_READ(GEN6_GT_GFX_RC6));
1168 seq_printf(m, "RC6+ residency since boot: %u\n",
1169 I915_READ(GEN6_GT_GFX_RC6p));
1170 seq_printf(m, "RC6++ residency since boot: %u\n",
1171 I915_READ(GEN6_GT_GFX_RC6pp));
1172
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001173 seq_printf(m, "RC6 voltage: %dmV\n",
1174 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1175 seq_printf(m, "RC6+ voltage: %dmV\n",
1176 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1177 seq_printf(m, "RC6++ voltage: %dmV\n",
1178 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001179 return 0;
1180}
1181
1182static int i915_drpc_info(struct seq_file *m, void *unused)
1183{
1184 struct drm_info_node *node = (struct drm_info_node *) m->private;
1185 struct drm_device *dev = node->minor->dev;
1186
1187 if (IS_GEN6(dev) || IS_GEN7(dev))
1188 return gen6_drpc_info(m);
1189 else
1190 return ironlake_drpc_info(m);
1191}
1192
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001193static int i915_fbc_status(struct seq_file *m, void *unused)
1194{
1195 struct drm_info_node *node = (struct drm_info_node *) m->private;
1196 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001197 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001198
Adam Jacksonee5382a2010-04-23 11:17:39 -04001199 if (!I915_HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001200 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001201 return 0;
1202 }
1203
Adam Jacksonee5382a2010-04-23 11:17:39 -04001204 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001205 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001206 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001207 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001208 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001209 case FBC_OK:
1210 seq_puts(m, "FBC actived, but currently disabled in hardware");
1211 break;
1212 case FBC_UNSUPPORTED:
1213 seq_puts(m, "unsupported by this chipset");
1214 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001215 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001216 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001217 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001218 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001219 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001220 break;
1221 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001222 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001223 break;
1224 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001225 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001226 break;
1227 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001228 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001229 break;
1230 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001231 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001232 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001233 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001234 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001235 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001236 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001237 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001238 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001239 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001240 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001241 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001242 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001243 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001244 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001245 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001246 }
1247 return 0;
1248}
1249
Paulo Zanoni92d44622013-05-31 16:33:24 -03001250static int i915_ips_status(struct seq_file *m, void *unused)
1251{
1252 struct drm_info_node *node = (struct drm_info_node *) m->private;
1253 struct drm_device *dev = node->minor->dev;
1254 struct drm_i915_private *dev_priv = dev->dev_private;
1255
Damien Lespiauf5adf942013-06-24 18:29:34 +01001256 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001257 seq_puts(m, "not supported\n");
1258 return 0;
1259 }
1260
1261 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1262 seq_puts(m, "enabled\n");
1263 else
1264 seq_puts(m, "disabled\n");
1265
1266 return 0;
1267}
1268
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001269static int i915_sr_status(struct seq_file *m, void *unused)
1270{
1271 struct drm_info_node *node = (struct drm_info_node *) m->private;
1272 struct drm_device *dev = node->minor->dev;
1273 drm_i915_private_t *dev_priv = dev->dev_private;
1274 bool sr_enabled = false;
1275
Yuanhan Liu13982612010-12-15 15:42:31 +08001276 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001277 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001278 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001279 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1280 else if (IS_I915GM(dev))
1281 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1282 else if (IS_PINEVIEW(dev))
1283 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1284
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001285 seq_printf(m, "self-refresh: %s\n",
1286 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001287
1288 return 0;
1289}
1290
Jesse Barnes7648fa92010-05-20 14:28:11 -07001291static int i915_emon_status(struct seq_file *m, void *unused)
1292{
1293 struct drm_info_node *node = (struct drm_info_node *) m->private;
1294 struct drm_device *dev = node->minor->dev;
1295 drm_i915_private_t *dev_priv = dev->dev_private;
1296 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001297 int ret;
1298
Chris Wilson582be6b2012-04-30 19:35:02 +01001299 if (!IS_GEN5(dev))
1300 return -ENODEV;
1301
Chris Wilsonde227ef2010-07-03 07:58:38 +01001302 ret = mutex_lock_interruptible(&dev->struct_mutex);
1303 if (ret)
1304 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001305
1306 temp = i915_mch_val(dev_priv);
1307 chipset = i915_chipset_val(dev_priv);
1308 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001309 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001310
1311 seq_printf(m, "GMCH temp: %ld\n", temp);
1312 seq_printf(m, "Chipset power: %ld\n", chipset);
1313 seq_printf(m, "GFX power: %ld\n", gfx);
1314 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1315
1316 return 0;
1317}
1318
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001319static int i915_ring_freq_table(struct seq_file *m, void *unused)
1320{
1321 struct drm_info_node *node = (struct drm_info_node *) m->private;
1322 struct drm_device *dev = node->minor->dev;
1323 drm_i915_private_t *dev_priv = dev->dev_private;
1324 int ret;
1325 int gpu_freq, ia_freq;
1326
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001327 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001328 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001329 return 0;
1330 }
1331
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001332 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1333
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001334 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001335 if (ret)
1336 return ret;
1337
Damien Lespiau267f0c92013-06-24 22:59:48 +01001338 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001339
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001340 for (gpu_freq = dev_priv->rps.min_delay;
1341 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001342 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001343 ia_freq = gpu_freq;
1344 sandybridge_pcode_read(dev_priv,
1345 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1346 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001347 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1348 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1349 ((ia_freq >> 0) & 0xff) * 100,
1350 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001351 }
1352
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001353 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001354
1355 return 0;
1356}
1357
Jesse Barnes7648fa92010-05-20 14:28:11 -07001358static int i915_gfxec(struct seq_file *m, void *unused)
1359{
1360 struct drm_info_node *node = (struct drm_info_node *) m->private;
1361 struct drm_device *dev = node->minor->dev;
1362 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001363 int ret;
1364
1365 ret = mutex_lock_interruptible(&dev->struct_mutex);
1366 if (ret)
1367 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001368
1369 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1370
Ben Widawsky616fdb52011-10-05 11:44:54 -07001371 mutex_unlock(&dev->struct_mutex);
1372
Jesse Barnes7648fa92010-05-20 14:28:11 -07001373 return 0;
1374}
1375
Chris Wilson44834a62010-08-19 16:09:23 +01001376static int i915_opregion(struct seq_file *m, void *unused)
1377{
1378 struct drm_info_node *node = (struct drm_info_node *) m->private;
1379 struct drm_device *dev = node->minor->dev;
1380 drm_i915_private_t *dev_priv = dev->dev_private;
1381 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001382 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001383 int ret;
1384
Daniel Vetter0d38f002012-04-21 22:49:10 +02001385 if (data == NULL)
1386 return -ENOMEM;
1387
Chris Wilson44834a62010-08-19 16:09:23 +01001388 ret = mutex_lock_interruptible(&dev->struct_mutex);
1389 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001390 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001391
Daniel Vetter0d38f002012-04-21 22:49:10 +02001392 if (opregion->header) {
1393 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1394 seq_write(m, data, OPREGION_SIZE);
1395 }
Chris Wilson44834a62010-08-19 16:09:23 +01001396
1397 mutex_unlock(&dev->struct_mutex);
1398
Daniel Vetter0d38f002012-04-21 22:49:10 +02001399out:
1400 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001401 return 0;
1402}
1403
Chris Wilson37811fc2010-08-25 22:45:57 +01001404static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1405{
1406 struct drm_info_node *node = (struct drm_info_node *) m->private;
1407 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001408 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001409 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001410
Daniel Vetter4520f532013-10-09 09:18:51 +02001411#ifdef CONFIG_DRM_I915_FBDEV
1412 struct drm_i915_private *dev_priv = dev->dev_private;
1413 int ret = mutex_lock_interruptible(&dev->mode_config.mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001414 if (ret)
1415 return ret;
1416
1417 ifbdev = dev_priv->fbdev;
1418 fb = to_intel_framebuffer(ifbdev->helper.fb);
1419
Daniel Vetter623f9782012-12-11 16:21:38 +01001420 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001421 fb->base.width,
1422 fb->base.height,
1423 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001424 fb->base.bits_per_pixel,
1425 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001426 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001427 seq_putc(m, '\n');
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001428 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter4520f532013-10-09 09:18:51 +02001429#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001430
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001431 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001432 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1433 if (&fb->base == ifbdev->helper.fb)
1434 continue;
1435
Daniel Vetter623f9782012-12-11 16:21:38 +01001436 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001437 fb->base.width,
1438 fb->base.height,
1439 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001440 fb->base.bits_per_pixel,
1441 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001442 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001443 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001444 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001445 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001446
1447 return 0;
1448}
1449
Ben Widawskye76d3632011-03-19 18:14:29 -07001450static int i915_context_status(struct seq_file *m, void *unused)
1451{
1452 struct drm_info_node *node = (struct drm_info_node *) m->private;
1453 struct drm_device *dev = node->minor->dev;
1454 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskya168c292013-02-14 15:05:12 -08001455 struct intel_ring_buffer *ring;
Ben Widawskya33afea2013-09-17 21:12:45 -07001456 struct i915_hw_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001457 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001458
1459 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1460 if (ret)
1461 return ret;
1462
Daniel Vetter3e373942012-11-02 19:55:04 +01001463 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001464 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001465 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001466 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001467 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001468
Daniel Vetter3e373942012-11-02 19:55:04 +01001469 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001470 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001471 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001472 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001473 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001474
Ben Widawskya33afea2013-09-17 21:12:45 -07001475 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1476 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001477 describe_ctx(m, ctx);
Ben Widawskya33afea2013-09-17 21:12:45 -07001478 for_each_ring(ring, dev_priv, i)
1479 if (ring->default_context == ctx)
1480 seq_printf(m, "(default context %s) ", ring->name);
1481
1482 describe_obj(m, ctx->obj);
1483 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001484 }
1485
Ben Widawskye76d3632011-03-19 18:14:29 -07001486 mutex_unlock(&dev->mode_config.mutex);
1487
1488 return 0;
1489}
1490
Ben Widawsky6d794d42011-04-25 11:25:56 -07001491static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1492{
1493 struct drm_info_node *node = (struct drm_info_node *) m->private;
1494 struct drm_device *dev = node->minor->dev;
1495 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001496 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001497
Chris Wilson907b28c2013-07-19 20:36:52 +01001498 spin_lock_irq(&dev_priv->uncore.lock);
1499 forcewake_count = dev_priv->uncore.forcewake_count;
1500 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001501
1502 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001503
1504 return 0;
1505}
1506
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001507static const char *swizzle_string(unsigned swizzle)
1508{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001509 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001510 case I915_BIT_6_SWIZZLE_NONE:
1511 return "none";
1512 case I915_BIT_6_SWIZZLE_9:
1513 return "bit9";
1514 case I915_BIT_6_SWIZZLE_9_10:
1515 return "bit9/bit10";
1516 case I915_BIT_6_SWIZZLE_9_11:
1517 return "bit9/bit11";
1518 case I915_BIT_6_SWIZZLE_9_10_11:
1519 return "bit9/bit10/bit11";
1520 case I915_BIT_6_SWIZZLE_9_17:
1521 return "bit9/bit17";
1522 case I915_BIT_6_SWIZZLE_9_10_17:
1523 return "bit9/bit10/bit17";
1524 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001525 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001526 }
1527
1528 return "bug";
1529}
1530
1531static int i915_swizzle_info(struct seq_file *m, void *data)
1532{
1533 struct drm_info_node *node = (struct drm_info_node *) m->private;
1534 struct drm_device *dev = node->minor->dev;
1535 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001536 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001537
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001538 ret = mutex_lock_interruptible(&dev->struct_mutex);
1539 if (ret)
1540 return ret;
1541
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001542 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1543 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1544 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1545 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1546
1547 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1548 seq_printf(m, "DDC = 0x%08x\n",
1549 I915_READ(DCC));
1550 seq_printf(m, "C0DRB3 = 0x%04x\n",
1551 I915_READ16(C0DRB3));
1552 seq_printf(m, "C1DRB3 = 0x%04x\n",
1553 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001554 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1555 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1556 I915_READ(MAD_DIMM_C0));
1557 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1558 I915_READ(MAD_DIMM_C1));
1559 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1560 I915_READ(MAD_DIMM_C2));
1561 seq_printf(m, "TILECTL = 0x%08x\n",
1562 I915_READ(TILECTL));
1563 seq_printf(m, "ARB_MODE = 0x%08x\n",
1564 I915_READ(ARB_MODE));
1565 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1566 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001567 }
1568 mutex_unlock(&dev->struct_mutex);
1569
1570 return 0;
1571}
1572
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001573static int i915_ppgtt_info(struct seq_file *m, void *data)
1574{
1575 struct drm_info_node *node = (struct drm_info_node *) m->private;
1576 struct drm_device *dev = node->minor->dev;
1577 struct drm_i915_private *dev_priv = dev->dev_private;
1578 struct intel_ring_buffer *ring;
1579 int i, ret;
1580
1581
1582 ret = mutex_lock_interruptible(&dev->struct_mutex);
1583 if (ret)
1584 return ret;
1585 if (INTEL_INFO(dev)->gen == 6)
1586 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1587
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001588 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001589 seq_printf(m, "%s\n", ring->name);
1590 if (INTEL_INFO(dev)->gen == 7)
1591 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1592 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1593 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1594 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1595 }
1596 if (dev_priv->mm.aliasing_ppgtt) {
1597 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1598
Damien Lespiau267f0c92013-06-24 22:59:48 +01001599 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001600 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1601 }
1602 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1603 mutex_unlock(&dev->struct_mutex);
1604
1605 return 0;
1606}
1607
Jesse Barnes57f350b2012-03-28 13:39:25 -07001608static int i915_dpio_info(struct seq_file *m, void *data)
1609{
1610 struct drm_info_node *node = (struct drm_info_node *) m->private;
1611 struct drm_device *dev = node->minor->dev;
1612 struct drm_i915_private *dev_priv = dev->dev_private;
1613 int ret;
1614
1615
1616 if (!IS_VALLEYVIEW(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001617 seq_puts(m, "unsupported\n");
Jesse Barnes57f350b2012-03-28 13:39:25 -07001618 return 0;
1619 }
1620
Daniel Vetter09153002012-12-12 14:06:44 +01001621 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001622 if (ret)
1623 return ret;
1624
1625 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1626
1627 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001628 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_DIV_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001629 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001630 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_DIV_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001631
1632 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001633 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_REFSFR_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001634 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001635 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_REFSFR_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001636
1637 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001638 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_CORE_CLK_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001639 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001640 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_CORE_CLK_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001641
Ville Syrjälä4abb2c32013-06-14 14:02:53 +03001642 seq_printf(m, "DPIO_LPF_COEFF_A: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001643 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_LPF_COEFF_A));
Ville Syrjälä4abb2c32013-06-14 14:02:53 +03001644 seq_printf(m, "DPIO_LPF_COEFF_B: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001645 vlv_dpio_read(dev_priv, PIPE_A, _DPIO_LPF_COEFF_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001646
1647 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001648 vlv_dpio_read(dev_priv, PIPE_A, DPIO_FASTCLK_DISABLE));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001649
Daniel Vetter09153002012-12-12 14:06:44 +01001650 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001651
1652 return 0;
1653}
1654
Ben Widawsky63573eb2013-07-04 11:02:07 -07001655static int i915_llc(struct seq_file *m, void *data)
1656{
1657 struct drm_info_node *node = (struct drm_info_node *) m->private;
1658 struct drm_device *dev = node->minor->dev;
1659 struct drm_i915_private *dev_priv = dev->dev_private;
1660
1661 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1662 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1663 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1664
1665 return 0;
1666}
1667
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001668static int i915_edp_psr_status(struct seq_file *m, void *data)
1669{
1670 struct drm_info_node *node = m->private;
1671 struct drm_device *dev = node->minor->dev;
1672 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03001673 u32 psrperf = 0;
1674 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001675
Rodrigo Vivia031d702013-10-03 16:15:06 -03001676 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
1677 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001678
Rodrigo Vivia031d702013-10-03 16:15:06 -03001679 enabled = HAS_PSR(dev) &&
1680 I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
1681 seq_printf(m, "Enabled: %s\n", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001682
Rodrigo Vivia031d702013-10-03 16:15:06 -03001683 if (HAS_PSR(dev))
1684 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
1685 EDP_PSR_PERF_CNT_MASK;
1686 seq_printf(m, "Performance_Counter: %u\n", psrperf);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001687
1688 return 0;
1689}
1690
Jesse Barnesec013e72013-08-20 10:29:23 +01001691static int i915_energy_uJ(struct seq_file *m, void *data)
1692{
1693 struct drm_info_node *node = m->private;
1694 struct drm_device *dev = node->minor->dev;
1695 struct drm_i915_private *dev_priv = dev->dev_private;
1696 u64 power;
1697 u32 units;
1698
1699 if (INTEL_INFO(dev)->gen < 6)
1700 return -ENODEV;
1701
1702 rdmsrl(MSR_RAPL_POWER_UNIT, power);
1703 power = (power & 0x1f00) >> 8;
1704 units = 1000000 / (1 << power); /* convert to uJ */
1705 power = I915_READ(MCH_SECP_NRG_STTS);
1706 power *= units;
1707
1708 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03001709
1710 return 0;
1711}
1712
1713static int i915_pc8_status(struct seq_file *m, void *unused)
1714{
1715 struct drm_info_node *node = (struct drm_info_node *) m->private;
1716 struct drm_device *dev = node->minor->dev;
1717 struct drm_i915_private *dev_priv = dev->dev_private;
1718
1719 if (!IS_HASWELL(dev)) {
1720 seq_puts(m, "not supported\n");
1721 return 0;
1722 }
1723
1724 mutex_lock(&dev_priv->pc8.lock);
1725 seq_printf(m, "Requirements met: %s\n",
1726 yesno(dev_priv->pc8.requirements_met));
1727 seq_printf(m, "GPU idle: %s\n", yesno(dev_priv->pc8.gpu_idle));
1728 seq_printf(m, "Disable count: %d\n", dev_priv->pc8.disable_count);
1729 seq_printf(m, "IRQs disabled: %s\n",
1730 yesno(dev_priv->pc8.irqs_disabled));
1731 seq_printf(m, "Enabled: %s\n", yesno(dev_priv->pc8.enabled));
1732 mutex_unlock(&dev_priv->pc8.lock);
1733
Jesse Barnesec013e72013-08-20 10:29:23 +01001734 return 0;
1735}
1736
Shuang He8bf1e9f2013-10-15 18:55:27 +01001737static int i915_pipe_crc(struct seq_file *m, void *data)
1738{
1739 struct drm_info_node *node = (struct drm_info_node *) m->private;
1740 struct drm_device *dev = node->minor->dev;
1741 struct drm_i915_private *dev_priv = dev->dev_private;
1742 enum pipe pipe = (enum pipe)node->info_ent->data;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001743 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1744 int head, tail;
Shuang He8bf1e9f2013-10-15 18:55:27 +01001745
Daniel Vetter926321d2013-10-16 13:30:34 +02001746 if (dev_priv->pipe_crc[pipe].source == INTEL_PIPE_CRC_SOURCE_NONE) {
1747 seq_puts(m, "none\n");
Shuang He8bf1e9f2013-10-15 18:55:27 +01001748 return 0;
1749 }
1750
Damien Lespiauac2300d2013-10-15 18:55:30 +01001751 seq_puts(m, " frame CRC1 CRC2 CRC3 CRC4 CRC5\n");
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001752 head = atomic_read(&pipe_crc->head);
1753 tail = atomic_read(&pipe_crc->tail);
1754
1755 while (CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) >= 1) {
1756 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001757
Damien Lespiauac2300d2013-10-15 18:55:30 +01001758 seq_printf(m, "%8u %8x %8x %8x %8x %8x\n", entry->frame,
Shuang He8bf1e9f2013-10-15 18:55:27 +01001759 entry->crc[0], entry->crc[1], entry->crc[2],
1760 entry->crc[3], entry->crc[4]);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001761
1762 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
1763 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1764 atomic_set(&pipe_crc->tail, tail);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001765 }
1766
1767 return 0;
1768}
1769
Daniel Vetter926321d2013-10-16 13:30:34 +02001770static const char *pipe_crc_sources[] = {
1771 "none",
1772 "plane1",
1773 "plane2",
1774 "pf",
1775};
1776
1777static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
1778{
1779 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
1780 return pipe_crc_sources[source];
1781}
1782
1783static int pipe_crc_ctl_show(struct seq_file *m, void *data)
1784{
1785 struct drm_device *dev = m->private;
1786 struct drm_i915_private *dev_priv = dev->dev_private;
1787 int i;
1788
1789 for (i = 0; i < I915_MAX_PIPES; i++)
1790 seq_printf(m, "%c %s\n", pipe_name(i),
1791 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
1792
1793 return 0;
1794}
1795
1796static int pipe_crc_ctl_open(struct inode *inode, struct file *file)
1797{
1798 struct drm_device *dev = inode->i_private;
1799
1800 return single_open(file, pipe_crc_ctl_show, dev);
1801}
1802
1803static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
1804 enum intel_pipe_crc_source source)
1805{
1806 struct drm_i915_private *dev_priv = dev->dev_private;
1807 u32 val;
1808
1809
1810 return -ENODEV;
1811
1812 if (!IS_IVYBRIDGE(dev))
1813 return -ENODEV;
1814
1815 dev_priv->pipe_crc[pipe].source = source;
1816
1817 switch (source) {
1818 case INTEL_PIPE_CRC_SOURCE_PLANE1:
1819 val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
1820 break;
1821 case INTEL_PIPE_CRC_SOURCE_PLANE2:
1822 val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
1823 break;
1824 case INTEL_PIPE_CRC_SOURCE_PF:
1825 val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
1826 break;
1827 case INTEL_PIPE_CRC_SOURCE_NONE:
1828 default:
1829 val = 0;
1830 break;
1831 }
1832
1833 I915_WRITE(PIPE_CRC_CTL(pipe), val);
1834 POSTING_READ(PIPE_CRC_CTL(pipe));
1835
1836 return 0;
1837}
1838
1839/*
1840 * Parse pipe CRC command strings:
1841 * command: wsp* pipe wsp+ source wsp*
1842 * pipe: (A | B | C)
1843 * source: (none | plane1 | plane2 | pf)
1844 * wsp: (#0x20 | #0x9 | #0xA)+
1845 *
1846 * eg.:
1847 * "A plane1" -> Start CRC computations on plane1 of pipe A
1848 * "A none" -> Stop CRC
1849 */
1850static int pipe_crc_ctl_tokenize(char *buf, char *words[], int max_words)
1851{
1852 int n_words = 0;
1853
1854 while (*buf) {
1855 char *end;
1856
1857 /* skip leading white space */
1858 buf = skip_spaces(buf);
1859 if (!*buf)
1860 break; /* end of buffer */
1861
1862 /* find end of word */
1863 for (end = buf; *end && !isspace(*end); end++)
1864 ;
1865
1866 if (n_words == max_words) {
1867 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
1868 max_words);
1869 return -EINVAL; /* ran out of words[] before bytes */
1870 }
1871
1872 if (*end)
1873 *end++ = '\0';
1874 words[n_words++] = buf;
1875 buf = end;
1876 }
1877
1878 return n_words;
1879}
1880
1881static int pipe_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
1882{
1883 const char name = buf[0];
1884
1885 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
1886 return -EINVAL;
1887
1888 *pipe = name - 'A';
1889
1890 return 0;
1891}
1892
1893static int
1894pipe_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *source)
1895{
1896 int i;
1897
1898 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
1899 if (!strcmp(buf, pipe_crc_sources[i])) {
1900 *source = i;
1901 return 0;
1902 }
1903
1904 return -EINVAL;
1905}
1906
1907static int pipe_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
1908{
1909#define MAX_WORDS 2
1910 int n_words;
1911 char *words[MAX_WORDS];
1912 enum pipe pipe;
1913 enum intel_pipe_crc_source source;
1914
1915 n_words = pipe_crc_ctl_tokenize(buf, words, MAX_WORDS);
1916 if (n_words != 2) {
1917 DRM_DEBUG_DRIVER("tokenize failed, a command is 2 words\n");
1918 return -EINVAL;
1919 }
1920
1921 if (pipe_crc_ctl_parse_pipe(words[0], &pipe) < 0) {
1922 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[0]);
1923 return -EINVAL;
1924 }
1925
1926 if (pipe_crc_ctl_parse_source(words[1], &source) < 0) {
1927 DRM_DEBUG_DRIVER("unknown source %s\n", words[1]);
1928 return -EINVAL;
1929 }
1930
1931 return pipe_crc_set_source(dev, pipe, source);
1932}
1933
1934static ssize_t pipe_crc_ctl_write(struct file *file, const char __user *ubuf,
1935 size_t len, loff_t *offp)
1936{
1937 struct seq_file *m = file->private_data;
1938 struct drm_device *dev = m->private;
1939 char *tmpbuf;
1940 int ret;
1941
1942 if (len == 0)
1943 return 0;
1944
1945 if (len > PAGE_SIZE - 1) {
1946 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
1947 PAGE_SIZE);
1948 return -E2BIG;
1949 }
1950
1951 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
1952 if (!tmpbuf)
1953 return -ENOMEM;
1954
1955 if (copy_from_user(tmpbuf, ubuf, len)) {
1956 ret = -EFAULT;
1957 goto out;
1958 }
1959 tmpbuf[len] = '\0';
1960
1961 ret = pipe_crc_ctl_parse(dev, tmpbuf, len);
1962
1963out:
1964 kfree(tmpbuf);
1965 if (ret < 0)
1966 return ret;
1967
1968 *offp += len;
1969 return len;
1970}
1971
1972static const struct file_operations i915_pipe_crc_ctl_fops = {
1973 .owner = THIS_MODULE,
1974 .open = pipe_crc_ctl_open,
1975 .read = seq_read,
1976 .llseek = seq_lseek,
1977 .release = single_release,
1978 .write = pipe_crc_ctl_write
1979};
1980
Kees Cook647416f2013-03-10 14:10:06 -07001981static int
1982i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001983{
Kees Cook647416f2013-03-10 14:10:06 -07001984 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001985 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001986
Kees Cook647416f2013-03-10 14:10:06 -07001987 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001988
Kees Cook647416f2013-03-10 14:10:06 -07001989 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001990}
1991
Kees Cook647416f2013-03-10 14:10:06 -07001992static int
1993i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001994{
Kees Cook647416f2013-03-10 14:10:06 -07001995 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001996
Kees Cook647416f2013-03-10 14:10:06 -07001997 DRM_INFO("Manually setting wedged to %llu\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001998 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001999
Kees Cook647416f2013-03-10 14:10:06 -07002000 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002001}
2002
Kees Cook647416f2013-03-10 14:10:06 -07002003DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
2004 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002005 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002006
Kees Cook647416f2013-03-10 14:10:06 -07002007static int
2008i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002009{
Kees Cook647416f2013-03-10 14:10:06 -07002010 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002011 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002012
Kees Cook647416f2013-03-10 14:10:06 -07002013 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002014
Kees Cook647416f2013-03-10 14:10:06 -07002015 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002016}
2017
Kees Cook647416f2013-03-10 14:10:06 -07002018static int
2019i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002020{
Kees Cook647416f2013-03-10 14:10:06 -07002021 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002022 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002023 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002024
Kees Cook647416f2013-03-10 14:10:06 -07002025 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002026
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002027 ret = mutex_lock_interruptible(&dev->struct_mutex);
2028 if (ret)
2029 return ret;
2030
Daniel Vetter99584db2012-11-14 17:14:04 +01002031 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002032 mutex_unlock(&dev->struct_mutex);
2033
Kees Cook647416f2013-03-10 14:10:06 -07002034 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002035}
2036
Kees Cook647416f2013-03-10 14:10:06 -07002037DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
2038 i915_ring_stop_get, i915_ring_stop_set,
2039 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02002040
Chris Wilson094f9a52013-09-25 17:34:55 +01002041static int
2042i915_ring_missed_irq_get(void *data, u64 *val)
2043{
2044 struct drm_device *dev = data;
2045 struct drm_i915_private *dev_priv = dev->dev_private;
2046
2047 *val = dev_priv->gpu_error.missed_irq_rings;
2048 return 0;
2049}
2050
2051static int
2052i915_ring_missed_irq_set(void *data, u64 val)
2053{
2054 struct drm_device *dev = data;
2055 struct drm_i915_private *dev_priv = dev->dev_private;
2056 int ret;
2057
2058 /* Lock against concurrent debugfs callers */
2059 ret = mutex_lock_interruptible(&dev->struct_mutex);
2060 if (ret)
2061 return ret;
2062 dev_priv->gpu_error.missed_irq_rings = val;
2063 mutex_unlock(&dev->struct_mutex);
2064
2065 return 0;
2066}
2067
2068DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
2069 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
2070 "0x%08llx\n");
2071
2072static int
2073i915_ring_test_irq_get(void *data, u64 *val)
2074{
2075 struct drm_device *dev = data;
2076 struct drm_i915_private *dev_priv = dev->dev_private;
2077
2078 *val = dev_priv->gpu_error.test_irq_rings;
2079
2080 return 0;
2081}
2082
2083static int
2084i915_ring_test_irq_set(void *data, u64 val)
2085{
2086 struct drm_device *dev = data;
2087 struct drm_i915_private *dev_priv = dev->dev_private;
2088 int ret;
2089
2090 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
2091
2092 /* Lock against concurrent debugfs callers */
2093 ret = mutex_lock_interruptible(&dev->struct_mutex);
2094 if (ret)
2095 return ret;
2096
2097 dev_priv->gpu_error.test_irq_rings = val;
2098 mutex_unlock(&dev->struct_mutex);
2099
2100 return 0;
2101}
2102
2103DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
2104 i915_ring_test_irq_get, i915_ring_test_irq_set,
2105 "0x%08llx\n");
2106
Chris Wilsondd624af2013-01-15 12:39:35 +00002107#define DROP_UNBOUND 0x1
2108#define DROP_BOUND 0x2
2109#define DROP_RETIRE 0x4
2110#define DROP_ACTIVE 0x8
2111#define DROP_ALL (DROP_UNBOUND | \
2112 DROP_BOUND | \
2113 DROP_RETIRE | \
2114 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07002115static int
2116i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00002117{
Kees Cook647416f2013-03-10 14:10:06 -07002118 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00002119
Kees Cook647416f2013-03-10 14:10:06 -07002120 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00002121}
2122
Kees Cook647416f2013-03-10 14:10:06 -07002123static int
2124i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00002125{
Kees Cook647416f2013-03-10 14:10:06 -07002126 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00002127 struct drm_i915_private *dev_priv = dev->dev_private;
2128 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07002129 struct i915_address_space *vm;
2130 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07002131 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00002132
Kees Cook647416f2013-03-10 14:10:06 -07002133 DRM_DEBUG_DRIVER("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00002134
2135 /* No need to check and wait for gpu resets, only libdrm auto-restarts
2136 * on ioctls on -EAGAIN. */
2137 ret = mutex_lock_interruptible(&dev->struct_mutex);
2138 if (ret)
2139 return ret;
2140
2141 if (val & DROP_ACTIVE) {
2142 ret = i915_gpu_idle(dev);
2143 if (ret)
2144 goto unlock;
2145 }
2146
2147 if (val & (DROP_RETIRE | DROP_ACTIVE))
2148 i915_gem_retire_requests(dev);
2149
2150 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07002151 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
2152 list_for_each_entry_safe(vma, x, &vm->inactive_list,
2153 mm_list) {
2154 if (vma->obj->pin_count)
2155 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07002156
Ben Widawskyca191b12013-07-31 17:00:14 -07002157 ret = i915_vma_unbind(vma);
2158 if (ret)
2159 goto unlock;
2160 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07002161 }
Chris Wilsondd624af2013-01-15 12:39:35 +00002162 }
2163
2164 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07002165 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
2166 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00002167 if (obj->pages_pin_count == 0) {
2168 ret = i915_gem_object_put_pages(obj);
2169 if (ret)
2170 goto unlock;
2171 }
2172 }
2173
2174unlock:
2175 mutex_unlock(&dev->struct_mutex);
2176
Kees Cook647416f2013-03-10 14:10:06 -07002177 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00002178}
2179
Kees Cook647416f2013-03-10 14:10:06 -07002180DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
2181 i915_drop_caches_get, i915_drop_caches_set,
2182 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00002183
Kees Cook647416f2013-03-10 14:10:06 -07002184static int
2185i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07002186{
Kees Cook647416f2013-03-10 14:10:06 -07002187 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07002188 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002189 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002190
2191 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2192 return -ENODEV;
2193
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002194 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2195
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002196 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002197 if (ret)
2198 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07002199
Jesse Barnes0a073b82013-04-17 15:54:58 -07002200 if (IS_VALLEYVIEW(dev))
2201 *val = vlv_gpu_freq(dev_priv->mem_freq,
2202 dev_priv->rps.max_delay);
2203 else
2204 *val = dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002205 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07002206
Kees Cook647416f2013-03-10 14:10:06 -07002207 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07002208}
2209
Kees Cook647416f2013-03-10 14:10:06 -07002210static int
2211i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07002212{
Kees Cook647416f2013-03-10 14:10:06 -07002213 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07002214 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002215 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002216
2217 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2218 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07002219
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002220 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2221
Kees Cook647416f2013-03-10 14:10:06 -07002222 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07002223
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002224 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002225 if (ret)
2226 return ret;
2227
Jesse Barnes358733e2011-07-27 11:53:01 -07002228 /*
2229 * Turbo will still be enabled, but won't go above the set value.
2230 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07002231 if (IS_VALLEYVIEW(dev)) {
2232 val = vlv_freq_opcode(dev_priv->mem_freq, val);
2233 dev_priv->rps.max_delay = val;
2234 gen6_set_rps(dev, val);
2235 } else {
2236 do_div(val, GT_FREQUENCY_MULTIPLIER);
2237 dev_priv->rps.max_delay = val;
2238 gen6_set_rps(dev, val);
2239 }
2240
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002241 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07002242
Kees Cook647416f2013-03-10 14:10:06 -07002243 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07002244}
2245
Kees Cook647416f2013-03-10 14:10:06 -07002246DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
2247 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002248 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07002249
Kees Cook647416f2013-03-10 14:10:06 -07002250static int
2251i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07002252{
Kees Cook647416f2013-03-10 14:10:06 -07002253 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07002254 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002255 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002256
2257 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2258 return -ENODEV;
2259
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002260 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2261
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002262 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002263 if (ret)
2264 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07002265
Jesse Barnes0a073b82013-04-17 15:54:58 -07002266 if (IS_VALLEYVIEW(dev))
2267 *val = vlv_gpu_freq(dev_priv->mem_freq,
2268 dev_priv->rps.min_delay);
2269 else
2270 *val = dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002271 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002272
Kees Cook647416f2013-03-10 14:10:06 -07002273 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07002274}
2275
Kees Cook647416f2013-03-10 14:10:06 -07002276static int
2277i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07002278{
Kees Cook647416f2013-03-10 14:10:06 -07002279 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07002280 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002281 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002282
2283 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2284 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07002285
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002286 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2287
Kees Cook647416f2013-03-10 14:10:06 -07002288 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07002289
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002290 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002291 if (ret)
2292 return ret;
2293
Jesse Barnes1523c312012-05-25 12:34:54 -07002294 /*
2295 * Turbo will still be enabled, but won't go below the set value.
2296 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07002297 if (IS_VALLEYVIEW(dev)) {
2298 val = vlv_freq_opcode(dev_priv->mem_freq, val);
2299 dev_priv->rps.min_delay = val;
2300 valleyview_set_rps(dev, val);
2301 } else {
2302 do_div(val, GT_FREQUENCY_MULTIPLIER);
2303 dev_priv->rps.min_delay = val;
2304 gen6_set_rps(dev, val);
2305 }
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002306 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002307
Kees Cook647416f2013-03-10 14:10:06 -07002308 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07002309}
2310
Kees Cook647416f2013-03-10 14:10:06 -07002311DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
2312 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002313 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07002314
Kees Cook647416f2013-03-10 14:10:06 -07002315static int
2316i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002317{
Kees Cook647416f2013-03-10 14:10:06 -07002318 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002319 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002320 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07002321 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002322
Daniel Vetter004777c2012-08-09 15:07:01 +02002323 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2324 return -ENODEV;
2325
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002326 ret = mutex_lock_interruptible(&dev->struct_mutex);
2327 if (ret)
2328 return ret;
2329
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002330 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2331 mutex_unlock(&dev_priv->dev->struct_mutex);
2332
Kees Cook647416f2013-03-10 14:10:06 -07002333 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002334
Kees Cook647416f2013-03-10 14:10:06 -07002335 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002336}
2337
Kees Cook647416f2013-03-10 14:10:06 -07002338static int
2339i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002340{
Kees Cook647416f2013-03-10 14:10:06 -07002341 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002342 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002343 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002344
Daniel Vetter004777c2012-08-09 15:07:01 +02002345 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2346 return -ENODEV;
2347
Kees Cook647416f2013-03-10 14:10:06 -07002348 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002349 return -EINVAL;
2350
Kees Cook647416f2013-03-10 14:10:06 -07002351 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002352
2353 /* Update the cache sharing policy here as well */
2354 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2355 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2356 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2357 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2358
Kees Cook647416f2013-03-10 14:10:06 -07002359 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002360}
2361
Kees Cook647416f2013-03-10 14:10:06 -07002362DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
2363 i915_cache_sharing_get, i915_cache_sharing_set,
2364 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002365
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002366/* As the drm_debugfs_init() routines are called before dev->dev_private is
2367 * allocated we need to hook into the minor for release. */
2368static int
2369drm_add_fake_info_node(struct drm_minor *minor,
2370 struct dentry *ent,
2371 const void *key)
2372{
2373 struct drm_info_node *node;
2374
Daniel Vetterb14c5672013-09-19 12:18:32 +02002375 node = kmalloc(sizeof(*node), GFP_KERNEL);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002376 if (node == NULL) {
2377 debugfs_remove(ent);
2378 return -ENOMEM;
2379 }
2380
2381 node->minor = minor;
2382 node->dent = ent;
2383 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002384
2385 mutex_lock(&minor->debugfs_lock);
2386 list_add(&node->list, &minor->debugfs_list);
2387 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002388
2389 return 0;
2390}
2391
Ben Widawsky6d794d42011-04-25 11:25:56 -07002392static int i915_forcewake_open(struct inode *inode, struct file *file)
2393{
2394 struct drm_device *dev = inode->i_private;
2395 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002396
Daniel Vetter075edca2012-01-24 09:44:28 +01002397 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002398 return 0;
2399
Ben Widawsky6d794d42011-04-25 11:25:56 -07002400 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002401
2402 return 0;
2403}
2404
Ben Widawskyc43b5632012-04-16 14:07:40 -07002405static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002406{
2407 struct drm_device *dev = inode->i_private;
2408 struct drm_i915_private *dev_priv = dev->dev_private;
2409
Daniel Vetter075edca2012-01-24 09:44:28 +01002410 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002411 return 0;
2412
Ben Widawsky6d794d42011-04-25 11:25:56 -07002413 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002414
2415 return 0;
2416}
2417
2418static const struct file_operations i915_forcewake_fops = {
2419 .owner = THIS_MODULE,
2420 .open = i915_forcewake_open,
2421 .release = i915_forcewake_release,
2422};
2423
2424static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2425{
2426 struct drm_device *dev = minor->dev;
2427 struct dentry *ent;
2428
2429 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002430 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002431 root, dev,
2432 &i915_forcewake_fops);
2433 if (IS_ERR(ent))
2434 return PTR_ERR(ent);
2435
Ben Widawsky8eb57292011-05-11 15:10:58 -07002436 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002437}
2438
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002439static int i915_debugfs_create(struct dentry *root,
2440 struct drm_minor *minor,
2441 const char *name,
2442 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002443{
2444 struct drm_device *dev = minor->dev;
2445 struct dentry *ent;
2446
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002447 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002448 S_IRUGO | S_IWUSR,
2449 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002450 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002451 if (IS_ERR(ent))
2452 return PTR_ERR(ent);
2453
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002454 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002455}
2456
Ben Gamari27c202a2009-07-01 22:26:52 -04002457static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002458 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002459 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002460 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002461 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002462 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002463 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b8882013-08-07 18:30:54 +01002464 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002465 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002466 {"i915_gem_request", i915_gem_request_info, 0},
2467 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002468 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002469 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002470 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2471 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2472 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07002473 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002474 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2475 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2476 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2477 {"i915_inttoext_table", i915_inttoext_table, 0},
2478 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002479 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002480 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002481 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002482 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03002483 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002484 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002485 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002486 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002487 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002488 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002489 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002490 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002491 {"i915_dpio", i915_dpio_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07002492 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002493 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01002494 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03002495 {"i915_pc8_status", i915_pc8_status, 0},
Shuang He8bf1e9f2013-10-15 18:55:27 +01002496 {"i915_pipe_A_crc", i915_pipe_crc, 0, (void *)PIPE_A},
2497 {"i915_pipe_B_crc", i915_pipe_crc, 0, (void *)PIPE_B},
2498 {"i915_pipe_C_crc", i915_pipe_crc, 0, (void *)PIPE_C},
Ben Gamari20172632009-02-17 20:08:50 -05002499};
Ben Gamari27c202a2009-07-01 22:26:52 -04002500#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002501
Ville Syrjälä2b4bd0e2013-08-07 15:11:52 +03002502static struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02002503 const char *name;
2504 const struct file_operations *fops;
2505} i915_debugfs_files[] = {
2506 {"i915_wedged", &i915_wedged_fops},
2507 {"i915_max_freq", &i915_max_freq_fops},
2508 {"i915_min_freq", &i915_min_freq_fops},
2509 {"i915_cache_sharing", &i915_cache_sharing_fops},
2510 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01002511 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
2512 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02002513 {"i915_gem_drop_caches", &i915_drop_caches_fops},
2514 {"i915_error_state", &i915_error_state_fops},
2515 {"i915_next_seqno", &i915_next_seqno_fops},
Daniel Vetter926321d2013-10-16 13:30:34 +02002516 {"i915_pipe_crc_ctl", &i915_pipe_crc_ctl_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02002517};
2518
Ben Gamari27c202a2009-07-01 22:26:52 -04002519int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002520{
Daniel Vetter34b96742013-07-04 20:49:44 +02002521 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002522
Ben Widawsky6d794d42011-04-25 11:25:56 -07002523 ret = i915_forcewake_create(minor->debugfs_root, minor);
2524 if (ret)
2525 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002526
Daniel Vetter34b96742013-07-04 20:49:44 +02002527 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
2528 ret = i915_debugfs_create(minor->debugfs_root, minor,
2529 i915_debugfs_files[i].name,
2530 i915_debugfs_files[i].fops);
2531 if (ret)
2532 return ret;
2533 }
Mika Kuoppala40633212012-12-04 15:12:00 +02002534
Ben Gamari27c202a2009-07-01 22:26:52 -04002535 return drm_debugfs_create_files(i915_debugfs_list,
2536 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002537 minor->debugfs_root, minor);
2538}
2539
Ben Gamari27c202a2009-07-01 22:26:52 -04002540void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002541{
Daniel Vetter34b96742013-07-04 20:49:44 +02002542 int i;
2543
Ben Gamari27c202a2009-07-01 22:26:52 -04002544 drm_debugfs_remove_files(i915_debugfs_list,
2545 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002546 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2547 1, minor);
Daniel Vetter34b96742013-07-04 20:49:44 +02002548 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
2549 struct drm_info_list *info_list =
2550 (struct drm_info_list *) i915_debugfs_files[i].fops;
2551
2552 drm_debugfs_remove_files(info_list, 1, minor);
2553 }
Ben Gamari20172632009-02-17 20:08:50 -05002554}
2555
2556#endif /* CONFIG_DEBUG_FS */