blob: 6a98b647e99ea117100e629f673b45843ba4632c [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 Wilson6d2b88852013-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
Damien Lespiau497666d2013-10-15 18:55:39 +010056/* As the drm_debugfs_init() routines are called before dev->dev_private is
57 * allocated we need to hook into the minor for release. */
58static int
59drm_add_fake_info_node(struct drm_minor *minor,
60 struct dentry *ent,
61 const void *key)
62{
63 struct drm_info_node *node;
64
65 node = kmalloc(sizeof(*node), GFP_KERNEL);
66 if (node == NULL) {
67 debugfs_remove(ent);
68 return -ENOMEM;
69 }
70
71 node->minor = minor;
72 node->dent = ent;
73 node->info_ent = (void *) key;
74
75 mutex_lock(&minor->debugfs_lock);
76 list_add(&node->list, &minor->debugfs_list);
77 mutex_unlock(&minor->debugfs_lock);
78
79 return 0;
80}
81
Chris Wilson70d39fe2010-08-25 16:03:34 +010082static int i915_capabilities(struct seq_file *m, void *data)
83{
84 struct drm_info_node *node = (struct drm_info_node *) m->private;
85 struct drm_device *dev = node->minor->dev;
86 const struct intel_device_info *info = INTEL_INFO(dev);
87
88 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030089 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010090#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
91#define SEP_SEMICOLON ;
92 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
93#undef PRINT_FLAG
94#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010095
96 return 0;
97}
Ben Gamari433e12f2009-02-17 20:08:51 -050098
Chris Wilson05394f32010-11-08 19:18:58 +000099static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000100{
Chris Wilson05394f32010-11-08 19:18:58 +0000101 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +0000102 return "P";
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800103 else if (i915_gem_obj_is_pinned(obj))
Chris Wilsona6172a82009-02-11 14:26:38 +0000104 return "p";
105 else
106 return " ";
107}
108
Chris Wilson05394f32010-11-08 19:18:58 +0000109static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000110{
Akshay Joshi0206e352011-08-16 15:34:10 -0400111 switch (obj->tiling_mode) {
112 default:
113 case I915_TILING_NONE: return " ";
114 case I915_TILING_X: return "X";
115 case I915_TILING_Y: return "Y";
116 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000117}
118
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700119static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
120{
121 return obj->has_global_gtt_mapping ? "g" : " ";
122}
123
Chris Wilson37811fc2010-08-25 22:45:57 +0100124static void
125describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
126{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700127 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800128 int pin_count = 0;
129
Ville Syrjäläfb1ae912013-08-22 19:21:30 +0300130 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %u %u %u%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100131 &obj->base,
132 get_pin_flag(obj),
133 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700134 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800135 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100136 obj->base.read_domains,
137 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100138 obj->last_read_seqno,
139 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000140 obj->last_fenced_seqno,
Mika Kuoppala84734a02013-07-12 16:50:57 +0300141 i915_cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100142 obj->dirty ? " dirty" : "",
143 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
144 if (obj->base.name)
145 seq_printf(m, " (name: %d)", obj->base.name);
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800146 list_for_each_entry(vma, &obj->vma_list, vma_link)
147 if (vma->pin_count > 0)
148 pin_count++;
149 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100150 if (obj->pin_display)
151 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100152 if (obj->fence_reg != I915_FENCE_REG_NONE)
153 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700154 list_for_each_entry(vma, &obj->vma_list, vma_link) {
155 if (!i915_is_ggtt(vma->vm))
156 seq_puts(m, " (pp");
157 else
158 seq_puts(m, " (g");
159 seq_printf(m, "gtt offset: %08lx, size: %08lx)",
160 vma->node.start, vma->node.size);
161 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000162 if (obj->stolen)
163 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000164 if (obj->pin_mappable || obj->fault_mappable) {
165 char s[3], *t = s;
166 if (obj->pin_mappable)
167 *t++ = 'p';
168 if (obj->fault_mappable)
169 *t++ = 'f';
170 *t = '\0';
171 seq_printf(m, " (%s mappable)", s);
172 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100173 if (obj->ring != NULL)
174 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100175}
176
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700177static void describe_ctx(struct seq_file *m, struct i915_hw_context *ctx)
178{
179 seq_putc(m, ctx->is_initialized ? 'I' : 'i');
180 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
181 seq_putc(m, ' ');
182}
183
Ben Gamari433e12f2009-02-17 20:08:51 -0500184static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500185{
186 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500187 uintptr_t list = (uintptr_t) node->info_ent->data;
188 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500189 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700190 struct drm_i915_private *dev_priv = dev->dev_private;
191 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700192 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100193 size_t total_obj_size, total_gtt_size;
194 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100195
196 ret = mutex_lock_interruptible(&dev->struct_mutex);
197 if (ret)
198 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500199
Ben Widawskyca191b12013-07-31 17:00:14 -0700200 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500201 switch (list) {
202 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100203 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700204 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500205 break;
206 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100207 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700208 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500210 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100211 mutex_unlock(&dev->struct_mutex);
212 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500213 }
214
Chris Wilson8f2480f2010-09-26 11:44:19 +0100215 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700216 list_for_each_entry(vma, head, mm_list) {
217 seq_printf(m, " ");
218 describe_obj(m, vma->obj);
219 seq_printf(m, "\n");
220 total_obj_size += vma->obj->base.size;
221 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100222 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500223 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100224 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700225
Chris Wilson8f2480f2010-09-26 11:44:19 +0100226 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
227 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500228 return 0;
229}
230
Chris Wilson6d2b88852013-08-07 18:30:54 +0100231static int obj_rank_by_stolen(void *priv,
232 struct list_head *A, struct list_head *B)
233{
234 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100236 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200237 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100238
239 return a->stolen->start - b->stolen->start;
240}
241
242static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
243{
244 struct drm_info_node *node = (struct drm_info_node *) m->private;
245 struct drm_device *dev = node->minor->dev;
246 struct drm_i915_private *dev_priv = dev->dev_private;
247 struct drm_i915_gem_object *obj;
248 size_t total_obj_size, total_gtt_size;
249 LIST_HEAD(stolen);
250 int count, ret;
251
252 ret = mutex_lock_interruptible(&dev->struct_mutex);
253 if (ret)
254 return ret;
255
256 total_obj_size = total_gtt_size = count = 0;
257 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
258 if (obj->stolen == NULL)
259 continue;
260
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200261 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262
263 total_obj_size += obj->base.size;
264 total_gtt_size += i915_gem_obj_ggtt_size(obj);
265 count++;
266 }
267 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
268 if (obj->stolen == NULL)
269 continue;
270
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200271 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100272
273 total_obj_size += obj->base.size;
274 count++;
275 }
276 list_sort(NULL, &stolen, obj_rank_by_stolen);
277 seq_puts(m, "Stolen:\n");
278 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200279 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 seq_puts(m, " ");
281 describe_obj(m, obj);
282 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284 }
285 mutex_unlock(&dev->struct_mutex);
286
287 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
288 count, total_obj_size, total_gtt_size);
289 return 0;
290}
291
Chris Wilson6299f992010-11-24 12:23:44 +0000292#define count_objects(list, member) do { \
293 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700294 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000295 ++count; \
296 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700297 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000298 ++mappable_count; \
299 } \
300 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400301} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000302
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303struct file_stats {
304 int count;
305 size_t total, active, inactive, unbound;
306};
307
308static int per_file_stats(int id, void *ptr, void *data)
309{
310 struct drm_i915_gem_object *obj = ptr;
311 struct file_stats *stats = data;
312
313 stats->count++;
314 stats->total += obj->base.size;
315
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700316 if (i915_gem_obj_ggtt_bound(obj)) {
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100317 if (!list_empty(&obj->ring_list))
318 stats->active += obj->base.size;
319 else
320 stats->inactive += obj->base.size;
321 } else {
322 if (!list_empty(&obj->global_list))
323 stats->unbound += obj->base.size;
324 }
325
326 return 0;
327}
328
Ben Widawskyca191b12013-07-31 17:00:14 -0700329#define count_vmas(list, member) do { \
330 list_for_each_entry(vma, list, member) { \
331 size += i915_gem_obj_ggtt_size(vma->obj); \
332 ++count; \
333 if (vma->obj->map_and_fenceable) { \
334 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
335 ++mappable_count; \
336 } \
337 } \
338} while (0)
339
340static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100341{
342 struct drm_info_node *node = (struct drm_info_node *) m->private;
343 struct drm_device *dev = node->minor->dev;
344 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200345 u32 count, mappable_count, purgeable_count;
346 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000347 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700348 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100349 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700350 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100351 int ret;
352
353 ret = mutex_lock_interruptible(&dev->struct_mutex);
354 if (ret)
355 return ret;
356
Chris Wilson6299f992010-11-24 12:23:44 +0000357 seq_printf(m, "%u objects, %zu bytes\n",
358 dev_priv->mm.object_count,
359 dev_priv->mm.object_memory);
360
361 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700362 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000363 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
364 count, mappable_count, size, mappable_size);
365
366 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700367 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000368 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
369 count, mappable_count, size, mappable_size);
370
371 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700372 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000373 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
374 count, mappable_count, size, mappable_size);
375
Chris Wilsonb7abb712012-08-20 11:33:30 +0200376 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700377 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200378 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200379 if (obj->madv == I915_MADV_DONTNEED)
380 purgeable_size += obj->base.size, ++purgeable_count;
381 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200382 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
383
Chris Wilson6299f992010-11-24 12:23:44 +0000384 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700385 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000386 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700387 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000388 ++count;
389 }
390 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700391 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000392 ++mappable_count;
393 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200394 if (obj->madv == I915_MADV_DONTNEED) {
395 purgeable_size += obj->base.size;
396 ++purgeable_count;
397 }
Chris Wilson6299f992010-11-24 12:23:44 +0000398 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200399 seq_printf(m, "%u purgeable objects, %zu bytes\n",
400 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000401 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
402 mappable_count, mappable_size);
403 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
404 count, size);
405
Ben Widawsky93d18792013-01-17 12:45:17 -0800406 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700407 dev_priv->gtt.base.total,
408 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100409
Damien Lespiau267f0c92013-06-24 22:59:48 +0100410 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100411 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
412 struct file_stats stats;
413
414 memset(&stats, 0, sizeof(stats));
415 idr_for_each(&file->object_idr, per_file_stats, &stats);
416 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu unbound)\n",
417 get_pid_task(file->pid, PIDTYPE_PID)->comm,
418 stats.count,
419 stats.total,
420 stats.active,
421 stats.inactive,
422 stats.unbound);
423 }
424
Chris Wilson73aa8082010-09-30 11:46:12 +0100425 mutex_unlock(&dev->struct_mutex);
426
427 return 0;
428}
429
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100430static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000431{
432 struct drm_info_node *node = (struct drm_info_node *) m->private;
433 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100434 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000435 struct drm_i915_private *dev_priv = dev->dev_private;
436 struct drm_i915_gem_object *obj;
437 size_t total_obj_size, total_gtt_size;
438 int count, ret;
439
440 ret = mutex_lock_interruptible(&dev->struct_mutex);
441 if (ret)
442 return ret;
443
444 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700445 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800446 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100447 continue;
448
Damien Lespiau267f0c92013-06-24 22:59:48 +0100449 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000450 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100451 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000452 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700453 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000454 count++;
455 }
456
457 mutex_unlock(&dev->struct_mutex);
458
459 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
460 count, total_obj_size, total_gtt_size);
461
462 return 0;
463}
464
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100465static int i915_gem_pageflip_info(struct seq_file *m, void *data)
466{
467 struct drm_info_node *node = (struct drm_info_node *) m->private;
468 struct drm_device *dev = node->minor->dev;
469 unsigned long flags;
470 struct intel_crtc *crtc;
471
472 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800473 const char pipe = pipe_name(crtc->pipe);
474 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100475 struct intel_unpin_work *work;
476
477 spin_lock_irqsave(&dev->event_lock, flags);
478 work = crtc->unpin_work;
479 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800480 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100481 pipe, plane);
482 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000483 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800484 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100485 pipe, plane);
486 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800487 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100488 pipe, plane);
489 }
490 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100491 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100492 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100493 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000494 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100495
496 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000497 struct drm_i915_gem_object *obj = work->old_fb_obj;
498 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700499 seq_printf(m, "Old framebuffer gtt_offset 0x%08lx\n",
500 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100501 }
502 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000503 struct drm_i915_gem_object *obj = work->pending_flip_obj;
504 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700505 seq_printf(m, "New framebuffer gtt_offset 0x%08lx\n",
506 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100507 }
508 }
509 spin_unlock_irqrestore(&dev->event_lock, flags);
510 }
511
512 return 0;
513}
514
Ben Gamari20172632009-02-17 20:08:50 -0500515static int i915_gem_request_info(struct seq_file *m, void *data)
516{
517 struct drm_info_node *node = (struct drm_info_node *) m->private;
518 struct drm_device *dev = node->minor->dev;
519 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100520 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500521 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100522 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100523
524 ret = mutex_lock_interruptible(&dev->struct_mutex);
525 if (ret)
526 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500527
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100528 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100529 for_each_ring(ring, dev_priv, i) {
530 if (list_empty(&ring->request_list))
531 continue;
532
533 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100534 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100535 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100536 list) {
537 seq_printf(m, " %d @ %d\n",
538 gem_request->seqno,
539 (int) (jiffies - gem_request->emitted_jiffies));
540 }
541 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500542 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100543 mutex_unlock(&dev->struct_mutex);
544
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100545 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100546 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100547
Ben Gamari20172632009-02-17 20:08:50 -0500548 return 0;
549}
550
Chris Wilsonb2223492010-10-27 15:27:33 +0100551static void i915_ring_seqno_info(struct seq_file *m,
552 struct intel_ring_buffer *ring)
553{
554 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200555 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100556 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100557 }
558}
559
Ben Gamari20172632009-02-17 20:08:50 -0500560static int i915_gem_seqno_info(struct seq_file *m, void *data)
561{
562 struct drm_info_node *node = (struct drm_info_node *) m->private;
563 struct drm_device *dev = node->minor->dev;
564 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100565 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000566 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100567
568 ret = mutex_lock_interruptible(&dev->struct_mutex);
569 if (ret)
570 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500571
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100572 for_each_ring(ring, dev_priv, i)
573 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100574
575 mutex_unlock(&dev->struct_mutex);
576
Ben Gamari20172632009-02-17 20:08:50 -0500577 return 0;
578}
579
580
581static int i915_interrupt_info(struct seq_file *m, void *data)
582{
583 struct drm_info_node *node = (struct drm_info_node *) m->private;
584 struct drm_device *dev = node->minor->dev;
585 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100586 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800587 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100588
589 ret = mutex_lock_interruptible(&dev->struct_mutex);
590 if (ret)
591 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500592
Ben Widawskya123f152013-11-02 21:07:10 -0700593 if (INTEL_INFO(dev)->gen >= 8) {
594 int i;
595 seq_printf(m, "Master Interrupt Control:\t%08x\n",
596 I915_READ(GEN8_MASTER_IRQ));
597
598 for (i = 0; i < 4; i++) {
599 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
600 i, I915_READ(GEN8_GT_IMR(i)));
601 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
602 i, I915_READ(GEN8_GT_IIR(i)));
603 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
604 i, I915_READ(GEN8_GT_IER(i)));
605 }
606
607 for_each_pipe(i) {
608 seq_printf(m, "Pipe %c IMR:\t%08x\n",
609 pipe_name(i),
610 I915_READ(GEN8_DE_PIPE_IMR(i)));
611 seq_printf(m, "Pipe %c IIR:\t%08x\n",
612 pipe_name(i),
613 I915_READ(GEN8_DE_PIPE_IIR(i)));
614 seq_printf(m, "Pipe %c IER:\t%08x\n",
615 pipe_name(i),
616 I915_READ(GEN8_DE_PIPE_IER(i)));
617 }
618
619 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
620 I915_READ(GEN8_DE_PORT_IMR));
621 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
622 I915_READ(GEN8_DE_PORT_IIR));
623 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
624 I915_READ(GEN8_DE_PORT_IER));
625
626 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
627 I915_READ(GEN8_DE_MISC_IMR));
628 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
629 I915_READ(GEN8_DE_MISC_IIR));
630 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
631 I915_READ(GEN8_DE_MISC_IER));
632
633 seq_printf(m, "PCU interrupt mask:\t%08x\n",
634 I915_READ(GEN8_PCU_IMR));
635 seq_printf(m, "PCU interrupt identity:\t%08x\n",
636 I915_READ(GEN8_PCU_IIR));
637 seq_printf(m, "PCU interrupt enable:\t%08x\n",
638 I915_READ(GEN8_PCU_IER));
639 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700640 seq_printf(m, "Display IER:\t%08x\n",
641 I915_READ(VLV_IER));
642 seq_printf(m, "Display IIR:\t%08x\n",
643 I915_READ(VLV_IIR));
644 seq_printf(m, "Display IIR_RW:\t%08x\n",
645 I915_READ(VLV_IIR_RW));
646 seq_printf(m, "Display IMR:\t%08x\n",
647 I915_READ(VLV_IMR));
648 for_each_pipe(pipe)
649 seq_printf(m, "Pipe %c stat:\t%08x\n",
650 pipe_name(pipe),
651 I915_READ(PIPESTAT(pipe)));
652
653 seq_printf(m, "Master IER:\t%08x\n",
654 I915_READ(VLV_MASTER_IER));
655
656 seq_printf(m, "Render IER:\t%08x\n",
657 I915_READ(GTIER));
658 seq_printf(m, "Render IIR:\t%08x\n",
659 I915_READ(GTIIR));
660 seq_printf(m, "Render IMR:\t%08x\n",
661 I915_READ(GTIMR));
662
663 seq_printf(m, "PM IER:\t\t%08x\n",
664 I915_READ(GEN6_PMIER));
665 seq_printf(m, "PM IIR:\t\t%08x\n",
666 I915_READ(GEN6_PMIIR));
667 seq_printf(m, "PM IMR:\t\t%08x\n",
668 I915_READ(GEN6_PMIMR));
669
670 seq_printf(m, "Port hotplug:\t%08x\n",
671 I915_READ(PORT_HOTPLUG_EN));
672 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
673 I915_READ(VLV_DPFLIPSTAT));
674 seq_printf(m, "DPINVGTT:\t%08x\n",
675 I915_READ(DPINVGTT));
676
677 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800678 seq_printf(m, "Interrupt enable: %08x\n",
679 I915_READ(IER));
680 seq_printf(m, "Interrupt identity: %08x\n",
681 I915_READ(IIR));
682 seq_printf(m, "Interrupt mask: %08x\n",
683 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800684 for_each_pipe(pipe)
685 seq_printf(m, "Pipe %c stat: %08x\n",
686 pipe_name(pipe),
687 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800688 } else {
689 seq_printf(m, "North Display Interrupt enable: %08x\n",
690 I915_READ(DEIER));
691 seq_printf(m, "North Display Interrupt identity: %08x\n",
692 I915_READ(DEIIR));
693 seq_printf(m, "North Display Interrupt mask: %08x\n",
694 I915_READ(DEIMR));
695 seq_printf(m, "South Display Interrupt enable: %08x\n",
696 I915_READ(SDEIER));
697 seq_printf(m, "South Display Interrupt identity: %08x\n",
698 I915_READ(SDEIIR));
699 seq_printf(m, "South Display Interrupt mask: %08x\n",
700 I915_READ(SDEIMR));
701 seq_printf(m, "Graphics Interrupt enable: %08x\n",
702 I915_READ(GTIER));
703 seq_printf(m, "Graphics Interrupt identity: %08x\n",
704 I915_READ(GTIIR));
705 seq_printf(m, "Graphics Interrupt mask: %08x\n",
706 I915_READ(GTIMR));
707 }
Ben Gamari20172632009-02-17 20:08:50 -0500708 seq_printf(m, "Interrupts received: %d\n",
709 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100710 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700711 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100712 seq_printf(m,
713 "Graphics Interrupt mask (%s): %08x\n",
714 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000715 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100716 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000717 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100718 mutex_unlock(&dev->struct_mutex);
719
Ben Gamari20172632009-02-17 20:08:50 -0500720 return 0;
721}
722
Chris Wilsona6172a82009-02-11 14:26:38 +0000723static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
724{
725 struct drm_info_node *node = (struct drm_info_node *) m->private;
726 struct drm_device *dev = node->minor->dev;
727 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100728 int i, ret;
729
730 ret = mutex_lock_interruptible(&dev->struct_mutex);
731 if (ret)
732 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000733
734 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
735 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
736 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000737 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000738
Chris Wilson6c085a72012-08-20 11:40:46 +0200739 seq_printf(m, "Fence %d, pin count = %d, object = ",
740 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100741 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100742 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100743 else
Chris Wilson05394f32010-11-08 19:18:58 +0000744 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100745 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000746 }
747
Chris Wilson05394f32010-11-08 19:18:58 +0000748 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000749 return 0;
750}
751
Ben Gamari20172632009-02-17 20:08:50 -0500752static int i915_hws_info(struct seq_file *m, void *data)
753{
754 struct drm_info_node *node = (struct drm_info_node *) m->private;
755 struct drm_device *dev = node->minor->dev;
756 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100757 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100758 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100759 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500760
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000761 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100762 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500763 if (hws == NULL)
764 return 0;
765
766 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
767 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
768 i * 4,
769 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
770 }
771 return 0;
772}
773
Daniel Vetterd5442302012-04-27 15:17:40 +0200774static ssize_t
775i915_error_state_write(struct file *filp,
776 const char __user *ubuf,
777 size_t cnt,
778 loff_t *ppos)
779{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300780 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200781 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200782 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200783
784 DRM_DEBUG_DRIVER("Resetting error state\n");
785
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200786 ret = mutex_lock_interruptible(&dev->struct_mutex);
787 if (ret)
788 return ret;
789
Daniel Vetterd5442302012-04-27 15:17:40 +0200790 i915_destroy_error_state(dev);
791 mutex_unlock(&dev->struct_mutex);
792
793 return cnt;
794}
795
796static int i915_error_state_open(struct inode *inode, struct file *file)
797{
798 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200799 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200800
801 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
802 if (!error_priv)
803 return -ENOMEM;
804
805 error_priv->dev = dev;
806
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300807 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200808
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300809 file->private_data = error_priv;
810
811 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200812}
813
814static int i915_error_state_release(struct inode *inode, struct file *file)
815{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300816 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200817
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300818 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200819 kfree(error_priv);
820
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300821 return 0;
822}
823
824static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
825 size_t count, loff_t *pos)
826{
827 struct i915_error_state_file_priv *error_priv = file->private_data;
828 struct drm_i915_error_state_buf error_str;
829 loff_t tmp_pos = 0;
830 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300831 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300832
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300833 ret = i915_error_state_buf_init(&error_str, count, *pos);
834 if (ret)
835 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300836
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300837 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300838 if (ret)
839 goto out;
840
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300841 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
842 error_str.buf,
843 error_str.bytes);
844
845 if (ret_count < 0)
846 ret = ret_count;
847 else
848 *pos = error_str.start + ret_count;
849out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300850 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300851 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200852}
853
854static const struct file_operations i915_error_state_fops = {
855 .owner = THIS_MODULE,
856 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300857 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200858 .write = i915_error_state_write,
859 .llseek = default_llseek,
860 .release = i915_error_state_release,
861};
862
Kees Cook647416f2013-03-10 14:10:06 -0700863static int
864i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200865{
Kees Cook647416f2013-03-10 14:10:06 -0700866 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200867 drm_i915_private_t *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200868 int ret;
869
870 ret = mutex_lock_interruptible(&dev->struct_mutex);
871 if (ret)
872 return ret;
873
Kees Cook647416f2013-03-10 14:10:06 -0700874 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200875 mutex_unlock(&dev->struct_mutex);
876
Kees Cook647416f2013-03-10 14:10:06 -0700877 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200878}
879
Kees Cook647416f2013-03-10 14:10:06 -0700880static int
881i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200882{
Kees Cook647416f2013-03-10 14:10:06 -0700883 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200884 int ret;
885
Mika Kuoppala40633212012-12-04 15:12:00 +0200886 ret = mutex_lock_interruptible(&dev->struct_mutex);
887 if (ret)
888 return ret;
889
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200890 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200891 mutex_unlock(&dev->struct_mutex);
892
Kees Cook647416f2013-03-10 14:10:06 -0700893 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200894}
895
Kees Cook647416f2013-03-10 14:10:06 -0700896DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
897 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +0300898 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +0200899
Jesse Barnesf97108d2010-01-29 11:27:07 -0800900static int i915_rstdby_delays(struct seq_file *m, void *unused)
901{
902 struct drm_info_node *node = (struct drm_info_node *) m->private;
903 struct drm_device *dev = node->minor->dev;
904 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700905 u16 crstanddelay;
906 int ret;
907
908 ret = mutex_lock_interruptible(&dev->struct_mutex);
909 if (ret)
910 return ret;
911
912 crstanddelay = I915_READ16(CRSTANDVID);
913
914 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800915
916 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
917
918 return 0;
919}
920
921static int i915_cur_delayinfo(struct seq_file *m, void *unused)
922{
923 struct drm_info_node *node = (struct drm_info_node *) m->private;
924 struct drm_device *dev = node->minor->dev;
925 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100926 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800927
Tom O'Rourke5c9669c2013-09-16 14:56:43 -0700928 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
929
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800930 if (IS_GEN5(dev)) {
931 u16 rgvswctl = I915_READ16(MEMSWCTL);
932 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
933
934 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
935 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
936 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
937 MEMSTAT_VID_SHIFT);
938 seq_printf(m, "Current P-state: %d\n",
939 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700940 } else if ((IS_GEN6(dev) || IS_GEN7(dev)) && !IS_VALLEYVIEW(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800941 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
942 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
943 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson8e8c06c2013-08-26 19:51:01 -0300944 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800945 u32 rpupei, rpcurup, rpprevup;
946 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800947 int max_freq;
948
949 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100950 ret = mutex_lock_interruptible(&dev->struct_mutex);
951 if (ret)
952 return ret;
953
Deepak Sc8d9a592013-11-23 14:55:42 +0530954 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800955
Chris Wilson8e8c06c2013-08-26 19:51:01 -0300956 reqf = I915_READ(GEN6_RPNSWREQ);
957 reqf &= ~GEN6_TURBO_DISABLE;
958 if (IS_HASWELL(dev))
959 reqf >>= 24;
960 else
961 reqf >>= 25;
962 reqf *= GT_FREQUENCY_MULTIPLIER;
963
Jesse Barnesccab5c82011-01-18 15:49:25 -0800964 rpstat = I915_READ(GEN6_RPSTAT1);
965 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
966 rpcurup = I915_READ(GEN6_RP_CUR_UP);
967 rpprevup = I915_READ(GEN6_RP_PREV_UP);
968 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
969 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
970 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800971 if (IS_HASWELL(dev))
972 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
973 else
974 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
975 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800976
Deepak Sc8d9a592013-11-23 14:55:42 +0530977 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100978 mutex_unlock(&dev->struct_mutex);
979
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800980 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800981 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800982 seq_printf(m, "Render p-state ratio: %d\n",
983 (gt_perf_status & 0xff00) >> 8);
984 seq_printf(m, "Render p-state VID: %d\n",
985 gt_perf_status & 0xff);
986 seq_printf(m, "Render p-state limit: %d\n",
987 rp_state_limits & 0xff);
Chris Wilson8e8c06c2013-08-26 19:51:01 -0300988 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800989 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800990 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
991 GEN6_CURICONT_MASK);
992 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
993 GEN6_CURBSYTAVG_MASK);
994 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
995 GEN6_CURBSYTAVG_MASK);
996 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
997 GEN6_CURIAVG_MASK);
998 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
999 GEN6_CURBSYTAVG_MASK);
1000 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1001 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001002
1003 max_freq = (rp_state_cap & 0xff0000) >> 16;
1004 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001005 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001006
1007 max_freq = (rp_state_cap & 0xff00) >> 8;
1008 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001009 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001010
1011 max_freq = rp_state_cap & 0xff;
1012 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001013 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001014
1015 seq_printf(m, "Max overclocked frequency: %dMHz\n",
1016 dev_priv->rps.hw_max * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001017 } else if (IS_VALLEYVIEW(dev)) {
1018 u32 freq_sts, val;
1019
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001020 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001021 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001022 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1023 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1024
Chon Ming Leec5bd2bf62013-11-07 15:23:27 +08001025 val = valleyview_rps_max_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001026 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001027 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001028
Chon Ming Leec5bd2bf62013-11-07 15:23:27 +08001029 val = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001030 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001031 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001032
1033 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001034 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001035 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001036 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001037 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001038 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001039
1040 return 0;
1041}
1042
1043static int i915_delayfreq_table(struct seq_file *m, void *unused)
1044{
1045 struct drm_info_node *node = (struct drm_info_node *) m->private;
1046 struct drm_device *dev = node->minor->dev;
1047 drm_i915_private_t *dev_priv = dev->dev_private;
1048 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001049 int ret, i;
1050
1051 ret = mutex_lock_interruptible(&dev->struct_mutex);
1052 if (ret)
1053 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001054
1055 for (i = 0; i < 16; i++) {
1056 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001057 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1058 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001059 }
1060
Ben Widawsky616fdb52011-10-05 11:44:54 -07001061 mutex_unlock(&dev->struct_mutex);
1062
Jesse Barnesf97108d2010-01-29 11:27:07 -08001063 return 0;
1064}
1065
1066static inline int MAP_TO_MV(int map)
1067{
1068 return 1250 - (map * 25);
1069}
1070
1071static int i915_inttoext_table(struct seq_file *m, void *unused)
1072{
1073 struct drm_info_node *node = (struct drm_info_node *) m->private;
1074 struct drm_device *dev = node->minor->dev;
1075 drm_i915_private_t *dev_priv = dev->dev_private;
1076 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001077 int ret, i;
1078
1079 ret = mutex_lock_interruptible(&dev->struct_mutex);
1080 if (ret)
1081 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001082
1083 for (i = 1; i <= 32; i++) {
1084 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1085 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1086 }
1087
Ben Widawsky616fdb52011-10-05 11:44:54 -07001088 mutex_unlock(&dev->struct_mutex);
1089
Jesse Barnesf97108d2010-01-29 11:27:07 -08001090 return 0;
1091}
1092
Ben Widawsky4d855292011-12-12 19:34:16 -08001093static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001094{
1095 struct drm_info_node *node = (struct drm_info_node *) m->private;
1096 struct drm_device *dev = node->minor->dev;
1097 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001098 u32 rgvmodectl, rstdbyctl;
1099 u16 crstandvid;
1100 int ret;
1101
1102 ret = mutex_lock_interruptible(&dev->struct_mutex);
1103 if (ret)
1104 return ret;
1105
1106 rgvmodectl = I915_READ(MEMMODECTL);
1107 rstdbyctl = I915_READ(RSTDBYCTL);
1108 crstandvid = I915_READ16(CRSTANDVID);
1109
1110 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001111
1112 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1113 "yes" : "no");
1114 seq_printf(m, "Boost freq: %d\n",
1115 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1116 MEMMODE_BOOST_FREQ_SHIFT);
1117 seq_printf(m, "HW control enabled: %s\n",
1118 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1119 seq_printf(m, "SW control enabled: %s\n",
1120 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1121 seq_printf(m, "Gated voltage change: %s\n",
1122 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1123 seq_printf(m, "Starting frequency: P%d\n",
1124 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001125 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001126 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001127 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1128 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1129 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1130 seq_printf(m, "Render standby enabled: %s\n",
1131 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001132 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001133 switch (rstdbyctl & RSX_STATUS_MASK) {
1134 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001135 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001136 break;
1137 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001138 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001139 break;
1140 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001141 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001142 break;
1143 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001144 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001145 break;
1146 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001147 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001148 break;
1149 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001150 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001151 break;
1152 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001153 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001154 break;
1155 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001156
1157 return 0;
1158}
1159
Ben Widawsky4d855292011-12-12 19:34:16 -08001160static int gen6_drpc_info(struct seq_file *m)
1161{
1162
1163 struct drm_info_node *node = (struct drm_info_node *) m->private;
1164 struct drm_device *dev = node->minor->dev;
1165 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001166 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001167 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001168 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001169
1170 ret = mutex_lock_interruptible(&dev->struct_mutex);
1171 if (ret)
1172 return ret;
1173
Chris Wilson907b28c2013-07-19 20:36:52 +01001174 spin_lock_irq(&dev_priv->uncore.lock);
1175 forcewake_count = dev_priv->uncore.forcewake_count;
1176 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001177
1178 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001179 seq_puts(m, "RC information inaccurate because somebody "
1180 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001181 } else {
1182 /* NB: we cannot use forcewake, else we read the wrong values */
1183 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1184 udelay(10);
1185 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1186 }
1187
1188 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001189 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001190
1191 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1192 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1193 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001194 mutex_lock(&dev_priv->rps.hw_lock);
1195 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1196 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001197
1198 seq_printf(m, "Video Turbo Mode: %s\n",
1199 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1200 seq_printf(m, "HW control enabled: %s\n",
1201 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1202 seq_printf(m, "SW control enabled: %s\n",
1203 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1204 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001205 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001206 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1207 seq_printf(m, "RC6 Enabled: %s\n",
1208 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1209 seq_printf(m, "Deep RC6 Enabled: %s\n",
1210 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1211 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1212 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001213 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001214 switch (gt_core_status & GEN6_RCn_MASK) {
1215 case GEN6_RC0:
1216 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001217 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001218 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001219 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001220 break;
1221 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001222 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001223 break;
1224 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001225 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001226 break;
1227 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001228 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001229 break;
1230 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001231 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001232 break;
1233 }
1234
1235 seq_printf(m, "Core Power Down: %s\n",
1236 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001237
1238 /* Not exactly sure what this is */
1239 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1240 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1241 seq_printf(m, "RC6 residency since boot: %u\n",
1242 I915_READ(GEN6_GT_GFX_RC6));
1243 seq_printf(m, "RC6+ residency since boot: %u\n",
1244 I915_READ(GEN6_GT_GFX_RC6p));
1245 seq_printf(m, "RC6++ residency since boot: %u\n",
1246 I915_READ(GEN6_GT_GFX_RC6pp));
1247
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001248 seq_printf(m, "RC6 voltage: %dmV\n",
1249 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1250 seq_printf(m, "RC6+ voltage: %dmV\n",
1251 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1252 seq_printf(m, "RC6++ voltage: %dmV\n",
1253 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001254 return 0;
1255}
1256
1257static int i915_drpc_info(struct seq_file *m, void *unused)
1258{
1259 struct drm_info_node *node = (struct drm_info_node *) m->private;
1260 struct drm_device *dev = node->minor->dev;
1261
1262 if (IS_GEN6(dev) || IS_GEN7(dev))
1263 return gen6_drpc_info(m);
1264 else
1265 return ironlake_drpc_info(m);
1266}
1267
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001268static int i915_fbc_status(struct seq_file *m, void *unused)
1269{
1270 struct drm_info_node *node = (struct drm_info_node *) m->private;
1271 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001272 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001273
Adam Jacksonee5382a2010-04-23 11:17:39 -04001274 if (!I915_HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001275 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001276 return 0;
1277 }
1278
Adam Jacksonee5382a2010-04-23 11:17:39 -04001279 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001280 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001281 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001282 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001283 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001284 case FBC_OK:
1285 seq_puts(m, "FBC actived, but currently disabled in hardware");
1286 break;
1287 case FBC_UNSUPPORTED:
1288 seq_puts(m, "unsupported by this chipset");
1289 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001290 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001291 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001292 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001293 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001294 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001295 break;
1296 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001297 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001298 break;
1299 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001300 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001301 break;
1302 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001303 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001304 break;
1305 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001306 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001307 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001308 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001309 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001310 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001311 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001312 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001313 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001314 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001315 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001316 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001317 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001318 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001319 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001320 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001321 }
1322 return 0;
1323}
1324
Paulo Zanoni92d44622013-05-31 16:33:24 -03001325static int i915_ips_status(struct seq_file *m, void *unused)
1326{
1327 struct drm_info_node *node = (struct drm_info_node *) m->private;
1328 struct drm_device *dev = node->minor->dev;
1329 struct drm_i915_private *dev_priv = dev->dev_private;
1330
Damien Lespiauf5adf942013-06-24 18:29:34 +01001331 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001332 seq_puts(m, "not supported\n");
1333 return 0;
1334 }
1335
1336 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1337 seq_puts(m, "enabled\n");
1338 else
1339 seq_puts(m, "disabled\n");
1340
1341 return 0;
1342}
1343
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001344static int i915_sr_status(struct seq_file *m, void *unused)
1345{
1346 struct drm_info_node *node = (struct drm_info_node *) m->private;
1347 struct drm_device *dev = node->minor->dev;
1348 drm_i915_private_t *dev_priv = dev->dev_private;
1349 bool sr_enabled = false;
1350
Yuanhan Liu13982612010-12-15 15:42:31 +08001351 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001352 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001353 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001354 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1355 else if (IS_I915GM(dev))
1356 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1357 else if (IS_PINEVIEW(dev))
1358 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1359
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001360 seq_printf(m, "self-refresh: %s\n",
1361 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001362
1363 return 0;
1364}
1365
Jesse Barnes7648fa92010-05-20 14:28:11 -07001366static int i915_emon_status(struct seq_file *m, void *unused)
1367{
1368 struct drm_info_node *node = (struct drm_info_node *) m->private;
1369 struct drm_device *dev = node->minor->dev;
1370 drm_i915_private_t *dev_priv = dev->dev_private;
1371 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001372 int ret;
1373
Chris Wilson582be6b2012-04-30 19:35:02 +01001374 if (!IS_GEN5(dev))
1375 return -ENODEV;
1376
Chris Wilsonde227ef2010-07-03 07:58:38 +01001377 ret = mutex_lock_interruptible(&dev->struct_mutex);
1378 if (ret)
1379 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001380
1381 temp = i915_mch_val(dev_priv);
1382 chipset = i915_chipset_val(dev_priv);
1383 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001384 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001385
1386 seq_printf(m, "GMCH temp: %ld\n", temp);
1387 seq_printf(m, "Chipset power: %ld\n", chipset);
1388 seq_printf(m, "GFX power: %ld\n", gfx);
1389 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1390
1391 return 0;
1392}
1393
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001394static int i915_ring_freq_table(struct seq_file *m, void *unused)
1395{
1396 struct drm_info_node *node = (struct drm_info_node *) m->private;
1397 struct drm_device *dev = node->minor->dev;
1398 drm_i915_private_t *dev_priv = dev->dev_private;
1399 int ret;
1400 int gpu_freq, ia_freq;
1401
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001402 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001403 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001404 return 0;
1405 }
1406
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001407 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1408
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001409 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001410 if (ret)
1411 return ret;
1412
Damien Lespiau267f0c92013-06-24 22:59:48 +01001413 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001414
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001415 for (gpu_freq = dev_priv->rps.min_delay;
1416 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001417 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001418 ia_freq = gpu_freq;
1419 sandybridge_pcode_read(dev_priv,
1420 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1421 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001422 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1423 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1424 ((ia_freq >> 0) & 0xff) * 100,
1425 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001426 }
1427
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001428 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001429
1430 return 0;
1431}
1432
Jesse Barnes7648fa92010-05-20 14:28:11 -07001433static int i915_gfxec(struct seq_file *m, void *unused)
1434{
1435 struct drm_info_node *node = (struct drm_info_node *) m->private;
1436 struct drm_device *dev = node->minor->dev;
1437 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001438 int ret;
1439
1440 ret = mutex_lock_interruptible(&dev->struct_mutex);
1441 if (ret)
1442 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001443
1444 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1445
Ben Widawsky616fdb52011-10-05 11:44:54 -07001446 mutex_unlock(&dev->struct_mutex);
1447
Jesse Barnes7648fa92010-05-20 14:28:11 -07001448 return 0;
1449}
1450
Chris Wilson44834a62010-08-19 16:09:23 +01001451static int i915_opregion(struct seq_file *m, void *unused)
1452{
1453 struct drm_info_node *node = (struct drm_info_node *) m->private;
1454 struct drm_device *dev = node->minor->dev;
1455 drm_i915_private_t *dev_priv = dev->dev_private;
1456 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001457 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001458 int ret;
1459
Daniel Vetter0d38f002012-04-21 22:49:10 +02001460 if (data == NULL)
1461 return -ENOMEM;
1462
Chris Wilson44834a62010-08-19 16:09:23 +01001463 ret = mutex_lock_interruptible(&dev->struct_mutex);
1464 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001465 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001466
Daniel Vetter0d38f002012-04-21 22:49:10 +02001467 if (opregion->header) {
1468 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1469 seq_write(m, data, OPREGION_SIZE);
1470 }
Chris Wilson44834a62010-08-19 16:09:23 +01001471
1472 mutex_unlock(&dev->struct_mutex);
1473
Daniel Vetter0d38f002012-04-21 22:49:10 +02001474out:
1475 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001476 return 0;
1477}
1478
Chris Wilson37811fc2010-08-25 22:45:57 +01001479static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1480{
1481 struct drm_info_node *node = (struct drm_info_node *) m->private;
1482 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001483 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001484 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001485
Daniel Vetter4520f532013-10-09 09:18:51 +02001486#ifdef CONFIG_DRM_I915_FBDEV
1487 struct drm_i915_private *dev_priv = dev->dev_private;
1488 int ret = mutex_lock_interruptible(&dev->mode_config.mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001489 if (ret)
1490 return ret;
1491
1492 ifbdev = dev_priv->fbdev;
1493 fb = to_intel_framebuffer(ifbdev->helper.fb);
1494
Daniel Vetter623f9782012-12-11 16:21:38 +01001495 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001496 fb->base.width,
1497 fb->base.height,
1498 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001499 fb->base.bits_per_pixel,
1500 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001501 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001502 seq_putc(m, '\n');
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001503 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter4520f532013-10-09 09:18:51 +02001504#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001505
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001506 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001507 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001508 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001509 continue;
1510
Daniel Vetter623f9782012-12-11 16:21:38 +01001511 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001512 fb->base.width,
1513 fb->base.height,
1514 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001515 fb->base.bits_per_pixel,
1516 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001517 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001518 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001519 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001520 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001521
1522 return 0;
1523}
1524
Ben Widawskye76d3632011-03-19 18:14:29 -07001525static int i915_context_status(struct seq_file *m, void *unused)
1526{
1527 struct drm_info_node *node = (struct drm_info_node *) m->private;
1528 struct drm_device *dev = node->minor->dev;
1529 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskya168c292013-02-14 15:05:12 -08001530 struct intel_ring_buffer *ring;
Ben Widawskya33afea2013-09-17 21:12:45 -07001531 struct i915_hw_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001532 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001533
1534 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1535 if (ret)
1536 return ret;
1537
Daniel Vetter3e373942012-11-02 19:55:04 +01001538 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001539 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001540 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001541 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001542 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001543
Daniel Vetter3e373942012-11-02 19:55:04 +01001544 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001546 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001547 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001548 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001549
Ben Widawskya33afea2013-09-17 21:12:45 -07001550 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1551 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001552 describe_ctx(m, ctx);
Ben Widawskya33afea2013-09-17 21:12:45 -07001553 for_each_ring(ring, dev_priv, i)
1554 if (ring->default_context == ctx)
1555 seq_printf(m, "(default context %s) ", ring->name);
1556
1557 describe_obj(m, ctx->obj);
1558 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001559 }
1560
Ben Widawskye76d3632011-03-19 18:14:29 -07001561 mutex_unlock(&dev->mode_config.mutex);
1562
1563 return 0;
1564}
1565
Ben Widawsky6d794d42011-04-25 11:25:56 -07001566static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1567{
1568 struct drm_info_node *node = (struct drm_info_node *) m->private;
1569 struct drm_device *dev = node->minor->dev;
1570 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301571 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001572
Chris Wilson907b28c2013-07-19 20:36:52 +01001573 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301574 if (IS_VALLEYVIEW(dev)) {
1575 fw_rendercount = dev_priv->uncore.fw_rendercount;
1576 fw_mediacount = dev_priv->uncore.fw_mediacount;
1577 } else
1578 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001579 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001580
Deepak S43709ba2013-11-23 14:55:44 +05301581 if (IS_VALLEYVIEW(dev)) {
1582 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1583 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1584 } else
1585 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001586
1587 return 0;
1588}
1589
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001590static const char *swizzle_string(unsigned swizzle)
1591{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001592 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001593 case I915_BIT_6_SWIZZLE_NONE:
1594 return "none";
1595 case I915_BIT_6_SWIZZLE_9:
1596 return "bit9";
1597 case I915_BIT_6_SWIZZLE_9_10:
1598 return "bit9/bit10";
1599 case I915_BIT_6_SWIZZLE_9_11:
1600 return "bit9/bit11";
1601 case I915_BIT_6_SWIZZLE_9_10_11:
1602 return "bit9/bit10/bit11";
1603 case I915_BIT_6_SWIZZLE_9_17:
1604 return "bit9/bit17";
1605 case I915_BIT_6_SWIZZLE_9_10_17:
1606 return "bit9/bit10/bit17";
1607 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001608 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001609 }
1610
1611 return "bug";
1612}
1613
1614static int i915_swizzle_info(struct seq_file *m, void *data)
1615{
1616 struct drm_info_node *node = (struct drm_info_node *) m->private;
1617 struct drm_device *dev = node->minor->dev;
1618 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001619 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001620
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001621 ret = mutex_lock_interruptible(&dev->struct_mutex);
1622 if (ret)
1623 return ret;
1624
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001625 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1626 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1627 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1628 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1629
1630 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1631 seq_printf(m, "DDC = 0x%08x\n",
1632 I915_READ(DCC));
1633 seq_printf(m, "C0DRB3 = 0x%04x\n",
1634 I915_READ16(C0DRB3));
1635 seq_printf(m, "C1DRB3 = 0x%04x\n",
1636 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001637 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001638 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1639 I915_READ(MAD_DIMM_C0));
1640 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1641 I915_READ(MAD_DIMM_C1));
1642 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1643 I915_READ(MAD_DIMM_C2));
1644 seq_printf(m, "TILECTL = 0x%08x\n",
1645 I915_READ(TILECTL));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001646 if (IS_GEN8(dev))
1647 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
1648 I915_READ(GAMTARBMODE));
1649 else
1650 seq_printf(m, "ARB_MODE = 0x%08x\n",
1651 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001652 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1653 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001654 }
1655 mutex_unlock(&dev->struct_mutex);
1656
1657 return 0;
1658}
1659
Ben Widawsky77df6772013-11-02 21:07:30 -07001660static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001661{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001662 struct drm_i915_private *dev_priv = dev->dev_private;
1663 struct intel_ring_buffer *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07001664 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1665 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001666
Ben Widawsky77df6772013-11-02 21:07:30 -07001667 if (!ppgtt)
1668 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001669
Ben Widawsky77df6772013-11-02 21:07:30 -07001670 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
1671 seq_printf(m, "Page tables: %d\n", ppgtt->num_pt_pages);
1672 for_each_ring(ring, dev_priv, unused) {
1673 seq_printf(m, "%s\n", ring->name);
1674 for (i = 0; i < 4; i++) {
1675 u32 offset = 0x270 + i * 8;
1676 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
1677 pdp <<= 32;
1678 pdp |= I915_READ(ring->mmio_base + offset);
1679 for (i = 0; i < 4; i++)
1680 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
1681 }
1682 }
1683}
1684
1685static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
1686{
1687 struct drm_i915_private *dev_priv = dev->dev_private;
1688 struct intel_ring_buffer *ring;
1689 int i;
1690
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001691 if (INTEL_INFO(dev)->gen == 6)
1692 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1693
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001694 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001695 seq_printf(m, "%s\n", ring->name);
1696 if (INTEL_INFO(dev)->gen == 7)
1697 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1698 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1699 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1700 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1701 }
1702 if (dev_priv->mm.aliasing_ppgtt) {
1703 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1704
Damien Lespiau267f0c92013-06-24 22:59:48 +01001705 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001706 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky87d60b62013-12-06 14:11:29 -08001707 ppgtt->debug_dump(ppgtt, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001708 }
1709 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07001710}
1711
1712static int i915_ppgtt_info(struct seq_file *m, void *data)
1713{
1714 struct drm_info_node *node = (struct drm_info_node *) m->private;
1715 struct drm_device *dev = node->minor->dev;
1716
1717 int ret = mutex_lock_interruptible(&dev->struct_mutex);
1718 if (ret)
1719 return ret;
1720
1721 if (INTEL_INFO(dev)->gen >= 8)
1722 gen8_ppgtt_info(m, dev);
1723 else if (INTEL_INFO(dev)->gen >= 6)
1724 gen6_ppgtt_info(m, dev);
1725
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001726 mutex_unlock(&dev->struct_mutex);
1727
1728 return 0;
1729}
1730
Jesse Barnes57f350b2012-03-28 13:39:25 -07001731static int i915_dpio_info(struct seq_file *m, void *data)
1732{
1733 struct drm_info_node *node = (struct drm_info_node *) m->private;
1734 struct drm_device *dev = node->minor->dev;
1735 struct drm_i915_private *dev_priv = dev->dev_private;
1736 int ret;
1737
1738
1739 if (!IS_VALLEYVIEW(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001740 seq_puts(m, "unsupported\n");
Jesse Barnes57f350b2012-03-28 13:39:25 -07001741 return 0;
1742 }
1743
Daniel Vetter09153002012-12-12 14:06:44 +01001744 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001745 if (ret)
1746 return ret;
1747
1748 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1749
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001750 seq_printf(m, "DPIO PLL DW3 CH0 : 0x%08x\n",
1751 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW3(0)));
1752 seq_printf(m, "DPIO PLL DW3 CH1: 0x%08x\n",
1753 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW3(1)));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001754
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001755 seq_printf(m, "DPIO PLL DW5 CH0: 0x%08x\n",
1756 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW5(0)));
1757 seq_printf(m, "DPIO PLL DW5 CH1: 0x%08x\n",
1758 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW5(1)));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001759
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001760 seq_printf(m, "DPIO PLL DW7 CH0: 0x%08x\n",
1761 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW7(0)));
1762 seq_printf(m, "DPIO PLL DW7 CH1: 0x%08x\n",
1763 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW7(1)));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001764
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001765 seq_printf(m, "DPIO PLL DW10 CH0: 0x%08x\n",
1766 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW10(0)));
1767 seq_printf(m, "DPIO PLL DW10 CH1: 0x%08x\n",
1768 vlv_dpio_read(dev_priv, PIPE_A, VLV_PLL_DW10(1)));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001769
1770 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001771 vlv_dpio_read(dev_priv, PIPE_A, VLV_CMN_DW0));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001772
Daniel Vetter09153002012-12-12 14:06:44 +01001773 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001774
1775 return 0;
1776}
1777
Ben Widawsky63573eb2013-07-04 11:02:07 -07001778static int i915_llc(struct seq_file *m, void *data)
1779{
1780 struct drm_info_node *node = (struct drm_info_node *) m->private;
1781 struct drm_device *dev = node->minor->dev;
1782 struct drm_i915_private *dev_priv = dev->dev_private;
1783
1784 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1785 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1786 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1787
1788 return 0;
1789}
1790
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001791static int i915_edp_psr_status(struct seq_file *m, void *data)
1792{
1793 struct drm_info_node *node = m->private;
1794 struct drm_device *dev = node->minor->dev;
1795 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03001796 u32 psrperf = 0;
1797 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001798
Rodrigo Vivia031d702013-10-03 16:15:06 -03001799 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
1800 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001801
Rodrigo Vivia031d702013-10-03 16:15:06 -03001802 enabled = HAS_PSR(dev) &&
1803 I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
1804 seq_printf(m, "Enabled: %s\n", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001805
Rodrigo Vivia031d702013-10-03 16:15:06 -03001806 if (HAS_PSR(dev))
1807 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
1808 EDP_PSR_PERF_CNT_MASK;
1809 seq_printf(m, "Performance_Counter: %u\n", psrperf);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001810
1811 return 0;
1812}
1813
Jesse Barnesec013e72013-08-20 10:29:23 +01001814static int i915_energy_uJ(struct seq_file *m, void *data)
1815{
1816 struct drm_info_node *node = m->private;
1817 struct drm_device *dev = node->minor->dev;
1818 struct drm_i915_private *dev_priv = dev->dev_private;
1819 u64 power;
1820 u32 units;
1821
1822 if (INTEL_INFO(dev)->gen < 6)
1823 return -ENODEV;
1824
1825 rdmsrl(MSR_RAPL_POWER_UNIT, power);
1826 power = (power & 0x1f00) >> 8;
1827 units = 1000000 / (1 << power); /* convert to uJ */
1828 power = I915_READ(MCH_SECP_NRG_STTS);
1829 power *= units;
1830
1831 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03001832
1833 return 0;
1834}
1835
1836static int i915_pc8_status(struct seq_file *m, void *unused)
1837{
1838 struct drm_info_node *node = (struct drm_info_node *) m->private;
1839 struct drm_device *dev = node->minor->dev;
1840 struct drm_i915_private *dev_priv = dev->dev_private;
1841
1842 if (!IS_HASWELL(dev)) {
1843 seq_puts(m, "not supported\n");
1844 return 0;
1845 }
1846
1847 mutex_lock(&dev_priv->pc8.lock);
1848 seq_printf(m, "Requirements met: %s\n",
1849 yesno(dev_priv->pc8.requirements_met));
1850 seq_printf(m, "GPU idle: %s\n", yesno(dev_priv->pc8.gpu_idle));
1851 seq_printf(m, "Disable count: %d\n", dev_priv->pc8.disable_count);
1852 seq_printf(m, "IRQs disabled: %s\n",
1853 yesno(dev_priv->pc8.irqs_disabled));
1854 seq_printf(m, "Enabled: %s\n", yesno(dev_priv->pc8.enabled));
1855 mutex_unlock(&dev_priv->pc8.lock);
1856
Jesse Barnesec013e72013-08-20 10:29:23 +01001857 return 0;
1858}
1859
Imre Deak1da51582013-11-25 17:15:35 +02001860static const char *power_domain_str(enum intel_display_power_domain domain)
1861{
1862 switch (domain) {
1863 case POWER_DOMAIN_PIPE_A:
1864 return "PIPE_A";
1865 case POWER_DOMAIN_PIPE_B:
1866 return "PIPE_B";
1867 case POWER_DOMAIN_PIPE_C:
1868 return "PIPE_C";
1869 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
1870 return "PIPE_A_PANEL_FITTER";
1871 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
1872 return "PIPE_B_PANEL_FITTER";
1873 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
1874 return "PIPE_C_PANEL_FITTER";
1875 case POWER_DOMAIN_TRANSCODER_A:
1876 return "TRANSCODER_A";
1877 case POWER_DOMAIN_TRANSCODER_B:
1878 return "TRANSCODER_B";
1879 case POWER_DOMAIN_TRANSCODER_C:
1880 return "TRANSCODER_C";
1881 case POWER_DOMAIN_TRANSCODER_EDP:
1882 return "TRANSCODER_EDP";
1883 case POWER_DOMAIN_VGA:
1884 return "VGA";
1885 case POWER_DOMAIN_AUDIO:
1886 return "AUDIO";
1887 case POWER_DOMAIN_INIT:
1888 return "INIT";
1889 default:
1890 WARN_ON(1);
1891 return "?";
1892 }
1893}
1894
1895static int i915_power_domain_info(struct seq_file *m, void *unused)
1896{
1897 struct drm_info_node *node = (struct drm_info_node *) m->private;
1898 struct drm_device *dev = node->minor->dev;
1899 struct drm_i915_private *dev_priv = dev->dev_private;
1900 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1901 int i;
1902
1903 mutex_lock(&power_domains->lock);
1904
1905 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
1906 for (i = 0; i < power_domains->power_well_count; i++) {
1907 struct i915_power_well *power_well;
1908 enum intel_display_power_domain power_domain;
1909
1910 power_well = &power_domains->power_wells[i];
1911 seq_printf(m, "%-25s %d\n", power_well->name,
1912 power_well->count);
1913
1914 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
1915 power_domain++) {
1916 if (!(BIT(power_domain) & power_well->domains))
1917 continue;
1918
1919 seq_printf(m, " %-23s %d\n",
1920 power_domain_str(power_domain),
1921 power_domains->domain_use_count[power_domain]);
1922 }
1923 }
1924
1925 mutex_unlock(&power_domains->lock);
1926
1927 return 0;
1928}
1929
Damien Lespiau07144422013-10-15 18:55:40 +01001930struct pipe_crc_info {
1931 const char *name;
1932 struct drm_device *dev;
1933 enum pipe pipe;
1934};
1935
1936static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001937{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01001938 struct pipe_crc_info *info = inode->i_private;
1939 struct drm_i915_private *dev_priv = info->dev->dev_private;
1940 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
1941
Daniel Vetter7eb1c492013-11-14 11:30:43 +01001942 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
1943 return -ENODEV;
1944
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001945 spin_lock_irq(&pipe_crc->lock);
1946
1947 if (pipe_crc->opened) {
1948 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01001949 return -EBUSY; /* already open */
1950 }
1951
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001952 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01001953 filep->private_data = inode->i_private;
1954
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001955 spin_unlock_irq(&pipe_crc->lock);
1956
Damien Lespiau07144422013-10-15 18:55:40 +01001957 return 0;
1958}
1959
1960static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
1961{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01001962 struct pipe_crc_info *info = inode->i_private;
1963 struct drm_i915_private *dev_priv = info->dev->dev_private;
1964 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
1965
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001966 spin_lock_irq(&pipe_crc->lock);
1967 pipe_crc->opened = false;
1968 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01001969
Damien Lespiau07144422013-10-15 18:55:40 +01001970 return 0;
1971}
1972
1973/* (6 fields, 8 chars each, space separated (5) + '\n') */
1974#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
1975/* account for \'0' */
1976#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
1977
1978static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
1979{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001980 assert_spin_locked(&pipe_crc->lock);
1981 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
1982 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01001983}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001984
Damien Lespiau07144422013-10-15 18:55:40 +01001985static ssize_t
1986i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
1987 loff_t *pos)
1988{
1989 struct pipe_crc_info *info = filep->private_data;
1990 struct drm_device *dev = info->dev;
1991 struct drm_i915_private *dev_priv = dev->dev_private;
1992 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
1993 char buf[PIPE_CRC_BUFFER_LEN];
1994 int head, tail, n_entries, n;
1995 ssize_t bytes_read;
1996
1997 /*
1998 * Don't allow user space to provide buffers not big enough to hold
1999 * a line of data.
2000 */
2001 if (count < PIPE_CRC_LINE_LEN)
2002 return -EINVAL;
2003
2004 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2005 return 0;
2006
2007 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002008 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002009 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002010 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002011
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002012 if (filep->f_flags & O_NONBLOCK) {
2013 spin_unlock_irq(&pipe_crc->lock);
2014 return -EAGAIN;
2015 }
2016
2017 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2018 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2019 if (ret) {
2020 spin_unlock_irq(&pipe_crc->lock);
2021 return ret;
2022 }
Damien Lespiau07144422013-10-15 18:55:40 +01002023 }
2024
2025 /* We now have one or more entries to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002026 head = pipe_crc->head;
2027 tail = pipe_crc->tail;
Damien Lespiau07144422013-10-15 18:55:40 +01002028 n_entries = min((size_t)CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR),
2029 count / PIPE_CRC_LINE_LEN);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002030 spin_unlock_irq(&pipe_crc->lock);
2031
Damien Lespiau07144422013-10-15 18:55:40 +01002032 bytes_read = 0;
2033 n = 0;
2034 do {
2035 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
2036 int ret;
2037
2038 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2039 "%8u %8x %8x %8x %8x %8x\n",
2040 entry->frame, entry->crc[0],
2041 entry->crc[1], entry->crc[2],
2042 entry->crc[3], entry->crc[4]);
2043
2044 ret = copy_to_user(user_buf + n * PIPE_CRC_LINE_LEN,
2045 buf, PIPE_CRC_LINE_LEN);
2046 if (ret == PIPE_CRC_LINE_LEN)
2047 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002048
2049 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2050 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiau07144422013-10-15 18:55:40 +01002051 n++;
2052 } while (--n_entries);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002053
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002054 spin_lock_irq(&pipe_crc->lock);
2055 pipe_crc->tail = tail;
2056 spin_unlock_irq(&pipe_crc->lock);
2057
Damien Lespiau07144422013-10-15 18:55:40 +01002058 return bytes_read;
2059}
2060
2061static const struct file_operations i915_pipe_crc_fops = {
2062 .owner = THIS_MODULE,
2063 .open = i915_pipe_crc_open,
2064 .read = i915_pipe_crc_read,
2065 .release = i915_pipe_crc_release,
2066};
2067
2068static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2069 {
2070 .name = "i915_pipe_A_crc",
2071 .pipe = PIPE_A,
2072 },
2073 {
2074 .name = "i915_pipe_B_crc",
2075 .pipe = PIPE_B,
2076 },
2077 {
2078 .name = "i915_pipe_C_crc",
2079 .pipe = PIPE_C,
2080 },
2081};
2082
2083static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2084 enum pipe pipe)
2085{
2086 struct drm_device *dev = minor->dev;
2087 struct dentry *ent;
2088 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2089
2090 info->dev = dev;
2091 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2092 &i915_pipe_crc_fops);
2093 if (IS_ERR(ent))
2094 return PTR_ERR(ent);
2095
2096 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002097}
2098
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002099static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002100 "none",
2101 "plane1",
2102 "plane2",
2103 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002104 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002105 "TV",
2106 "DP-B",
2107 "DP-C",
2108 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002109 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002110};
2111
2112static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2113{
2114 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2115 return pipe_crc_sources[source];
2116}
2117
Damien Lespiaubd9db022013-10-15 18:55:36 +01002118static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002119{
2120 struct drm_device *dev = m->private;
2121 struct drm_i915_private *dev_priv = dev->dev_private;
2122 int i;
2123
2124 for (i = 0; i < I915_MAX_PIPES; i++)
2125 seq_printf(m, "%c %s\n", pipe_name(i),
2126 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2127
2128 return 0;
2129}
2130
Damien Lespiaubd9db022013-10-15 18:55:36 +01002131static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02002132{
2133 struct drm_device *dev = inode->i_private;
2134
Damien Lespiaubd9db022013-10-15 18:55:36 +01002135 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02002136}
2137
Daniel Vetter46a19182013-11-01 10:50:20 +01002138static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02002139 uint32_t *val)
2140{
Daniel Vetter46a19182013-11-01 10:50:20 +01002141 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2142 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2143
2144 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02002145 case INTEL_PIPE_CRC_SOURCE_PIPE:
2146 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
2147 break;
2148 case INTEL_PIPE_CRC_SOURCE_NONE:
2149 *val = 0;
2150 break;
2151 default:
2152 return -EINVAL;
2153 }
2154
2155 return 0;
2156}
2157
Daniel Vetter46a19182013-11-01 10:50:20 +01002158static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
2159 enum intel_pipe_crc_source *source)
2160{
2161 struct intel_encoder *encoder;
2162 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01002163 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01002164 int ret = 0;
2165
2166 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2167
2168 mutex_lock(&dev->mode_config.mutex);
2169 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
2170 base.head) {
2171 if (!encoder->base.crtc)
2172 continue;
2173
2174 crtc = to_intel_crtc(encoder->base.crtc);
2175
2176 if (crtc->pipe != pipe)
2177 continue;
2178
2179 switch (encoder->type) {
2180 case INTEL_OUTPUT_TVOUT:
2181 *source = INTEL_PIPE_CRC_SOURCE_TV;
2182 break;
2183 case INTEL_OUTPUT_DISPLAYPORT:
2184 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01002185 dig_port = enc_to_dig_port(&encoder->base);
2186 switch (dig_port->port) {
2187 case PORT_B:
2188 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
2189 break;
2190 case PORT_C:
2191 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
2192 break;
2193 case PORT_D:
2194 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
2195 break;
2196 default:
2197 WARN(1, "nonexisting DP port %c\n",
2198 port_name(dig_port->port));
2199 break;
2200 }
Daniel Vetter46a19182013-11-01 10:50:20 +01002201 break;
2202 }
2203 }
2204 mutex_unlock(&dev->mode_config.mutex);
2205
2206 return ret;
2207}
2208
2209static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
2210 enum pipe pipe,
2211 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02002212 uint32_t *val)
2213{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002214 struct drm_i915_private *dev_priv = dev->dev_private;
2215 bool need_stable_symbols = false;
2216
Daniel Vetter46a19182013-11-01 10:50:20 +01002217 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2218 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2219 if (ret)
2220 return ret;
2221 }
2222
2223 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02002224 case INTEL_PIPE_CRC_SOURCE_PIPE:
2225 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
2226 break;
2227 case INTEL_PIPE_CRC_SOURCE_DP_B:
2228 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002229 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002230 break;
2231 case INTEL_PIPE_CRC_SOURCE_DP_C:
2232 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002233 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002234 break;
2235 case INTEL_PIPE_CRC_SOURCE_NONE:
2236 *val = 0;
2237 break;
2238 default:
2239 return -EINVAL;
2240 }
2241
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002242 /*
2243 * When the pipe CRC tap point is after the transcoders we need
2244 * to tweak symbol-level features to produce a deterministic series of
2245 * symbols for a given frame. We need to reset those features only once
2246 * a frame (instead of every nth symbol):
2247 * - DC-balance: used to ensure a better clock recovery from the data
2248 * link (SDVO)
2249 * - DisplayPort scrambling: used for EMI reduction
2250 */
2251 if (need_stable_symbols) {
2252 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2253
2254 WARN_ON(!IS_G4X(dev));
2255
2256 tmp |= DC_BALANCE_RESET_VLV;
2257 if (pipe == PIPE_A)
2258 tmp |= PIPE_A_SCRAMBLE_RESET;
2259 else
2260 tmp |= PIPE_B_SCRAMBLE_RESET;
2261
2262 I915_WRITE(PORT_DFT2_G4X, tmp);
2263 }
2264
Daniel Vetter7ac01292013-10-18 16:37:06 +02002265 return 0;
2266}
2267
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002268static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01002269 enum pipe pipe,
2270 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002271 uint32_t *val)
2272{
Daniel Vetter84093602013-11-01 10:50:21 +01002273 struct drm_i915_private *dev_priv = dev->dev_private;
2274 bool need_stable_symbols = false;
2275
Daniel Vetter46a19182013-11-01 10:50:20 +01002276 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2277 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2278 if (ret)
2279 return ret;
2280 }
2281
2282 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002283 case INTEL_PIPE_CRC_SOURCE_PIPE:
2284 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
2285 break;
2286 case INTEL_PIPE_CRC_SOURCE_TV:
2287 if (!SUPPORTS_TV(dev))
2288 return -EINVAL;
2289 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
2290 break;
2291 case INTEL_PIPE_CRC_SOURCE_DP_B:
2292 if (!IS_G4X(dev))
2293 return -EINVAL;
2294 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002295 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002296 break;
2297 case INTEL_PIPE_CRC_SOURCE_DP_C:
2298 if (!IS_G4X(dev))
2299 return -EINVAL;
2300 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002301 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002302 break;
2303 case INTEL_PIPE_CRC_SOURCE_DP_D:
2304 if (!IS_G4X(dev))
2305 return -EINVAL;
2306 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002307 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002308 break;
2309 case INTEL_PIPE_CRC_SOURCE_NONE:
2310 *val = 0;
2311 break;
2312 default:
2313 return -EINVAL;
2314 }
2315
Daniel Vetter84093602013-11-01 10:50:21 +01002316 /*
2317 * When the pipe CRC tap point is after the transcoders we need
2318 * to tweak symbol-level features to produce a deterministic series of
2319 * symbols for a given frame. We need to reset those features only once
2320 * a frame (instead of every nth symbol):
2321 * - DC-balance: used to ensure a better clock recovery from the data
2322 * link (SDVO)
2323 * - DisplayPort scrambling: used for EMI reduction
2324 */
2325 if (need_stable_symbols) {
2326 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2327
2328 WARN_ON(!IS_G4X(dev));
2329
2330 I915_WRITE(PORT_DFT_I9XX,
2331 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
2332
2333 if (pipe == PIPE_A)
2334 tmp |= PIPE_A_SCRAMBLE_RESET;
2335 else
2336 tmp |= PIPE_B_SCRAMBLE_RESET;
2337
2338 I915_WRITE(PORT_DFT2_G4X, tmp);
2339 }
2340
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002341 return 0;
2342}
2343
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002344static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
2345 enum pipe pipe)
2346{
2347 struct drm_i915_private *dev_priv = dev->dev_private;
2348 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2349
2350 if (pipe == PIPE_A)
2351 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2352 else
2353 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2354 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
2355 tmp &= ~DC_BALANCE_RESET_VLV;
2356 I915_WRITE(PORT_DFT2_G4X, tmp);
2357
2358}
2359
Daniel Vetter84093602013-11-01 10:50:21 +01002360static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
2361 enum pipe pipe)
2362{
2363 struct drm_i915_private *dev_priv = dev->dev_private;
2364 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2365
2366 if (pipe == PIPE_A)
2367 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2368 else
2369 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2370 I915_WRITE(PORT_DFT2_G4X, tmp);
2371
2372 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
2373 I915_WRITE(PORT_DFT_I9XX,
2374 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
2375 }
2376}
2377
Daniel Vetter46a19182013-11-01 10:50:20 +01002378static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002379 uint32_t *val)
2380{
Daniel Vetter46a19182013-11-01 10:50:20 +01002381 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2382 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2383
2384 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002385 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2386 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
2387 break;
2388 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2389 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
2390 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002391 case INTEL_PIPE_CRC_SOURCE_PIPE:
2392 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
2393 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002394 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002395 *val = 0;
2396 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002397 default:
2398 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002399 }
2400
2401 return 0;
2402}
2403
Daniel Vetter46a19182013-11-01 10:50:20 +01002404static int ivb_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002405 uint32_t *val)
2406{
Daniel Vetter46a19182013-11-01 10:50:20 +01002407 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2408 *source = INTEL_PIPE_CRC_SOURCE_PF;
2409
2410 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002411 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2412 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
2413 break;
2414 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2415 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
2416 break;
2417 case INTEL_PIPE_CRC_SOURCE_PF:
2418 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
2419 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002420 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002421 *val = 0;
2422 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002423 default:
2424 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002425 }
2426
2427 return 0;
2428}
2429
Daniel Vetter926321d2013-10-16 13:30:34 +02002430static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
2431 enum intel_pipe_crc_source source)
2432{
2433 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01002434 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Borislav Petkov432f3342013-11-21 16:49:46 +01002435 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002436 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02002437
Damien Lespiaucc3da172013-10-15 18:55:31 +01002438 if (pipe_crc->source == source)
2439 return 0;
2440
Damien Lespiauae676fc2013-10-15 18:55:32 +01002441 /* forbid changing the source without going back to 'none' */
2442 if (pipe_crc->source && source)
2443 return -EINVAL;
2444
Daniel Vetter52f843f2013-10-21 17:26:38 +02002445 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002446 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02002447 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01002448 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02002449 else if (IS_VALLEYVIEW(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002450 ret = vlv_pipe_crc_ctl_reg(dev,pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002451 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002452 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002453 else
Daniel Vetter46a19182013-11-01 10:50:20 +01002454 ret = ivb_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002455
2456 if (ret != 0)
2457 return ret;
2458
Damien Lespiau4b584362013-10-15 18:55:33 +01002459 /* none -> real source transition */
2460 if (source) {
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01002461 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
2462 pipe_name(pipe), pipe_crc_source_name(source));
2463
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002464 pipe_crc->entries = kzalloc(sizeof(*pipe_crc->entries) *
2465 INTEL_PIPE_CRC_ENTRIES_NR,
2466 GFP_KERNEL);
2467 if (!pipe_crc->entries)
2468 return -ENOMEM;
2469
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002470 spin_lock_irq(&pipe_crc->lock);
2471 pipe_crc->head = 0;
2472 pipe_crc->tail = 0;
2473 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01002474 }
2475
Damien Lespiaucc3da172013-10-15 18:55:31 +01002476 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02002477
Daniel Vetter926321d2013-10-16 13:30:34 +02002478 I915_WRITE(PIPE_CRC_CTL(pipe), val);
2479 POSTING_READ(PIPE_CRC_CTL(pipe));
2480
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002481 /* real source -> none transition */
2482 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002483 struct intel_pipe_crc_entry *entries;
2484
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01002485 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
2486 pipe_name(pipe));
2487
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02002488 intel_wait_for_vblank(dev, pipe);
2489
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002490 spin_lock_irq(&pipe_crc->lock);
2491 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002492 pipe_crc->entries = NULL;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002493 spin_unlock_irq(&pipe_crc->lock);
2494
2495 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01002496
2497 if (IS_G4X(dev))
2498 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002499 else if (IS_VALLEYVIEW(dev))
2500 vlv_undo_pipe_scramble_reset(dev, pipe);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002501 }
2502
Daniel Vetter926321d2013-10-16 13:30:34 +02002503 return 0;
2504}
2505
2506/*
2507 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01002508 * command: wsp* object wsp+ name wsp+ source wsp*
2509 * object: 'pipe'
2510 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02002511 * source: (none | plane1 | plane2 | pf)
2512 * wsp: (#0x20 | #0x9 | #0xA)+
2513 *
2514 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01002515 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
2516 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02002517 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01002518static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02002519{
2520 int n_words = 0;
2521
2522 while (*buf) {
2523 char *end;
2524
2525 /* skip leading white space */
2526 buf = skip_spaces(buf);
2527 if (!*buf)
2528 break; /* end of buffer */
2529
2530 /* find end of word */
2531 for (end = buf; *end && !isspace(*end); end++)
2532 ;
2533
2534 if (n_words == max_words) {
2535 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
2536 max_words);
2537 return -EINVAL; /* ran out of words[] before bytes */
2538 }
2539
2540 if (*end)
2541 *end++ = '\0';
2542 words[n_words++] = buf;
2543 buf = end;
2544 }
2545
2546 return n_words;
2547}
2548
Damien Lespiaub94dec82013-10-15 18:55:35 +01002549enum intel_pipe_crc_object {
2550 PIPE_CRC_OBJECT_PIPE,
2551};
2552
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002553static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01002554 "pipe",
2555};
2556
2557static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01002558display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01002559{
2560 int i;
2561
2562 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
2563 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01002564 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01002565 return 0;
2566 }
2567
2568 return -EINVAL;
2569}
2570
Damien Lespiaubd9db022013-10-15 18:55:36 +01002571static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02002572{
2573 const char name = buf[0];
2574
2575 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
2576 return -EINVAL;
2577
2578 *pipe = name - 'A';
2579
2580 return 0;
2581}
2582
2583static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01002584display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02002585{
2586 int i;
2587
2588 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
2589 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01002590 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02002591 return 0;
2592 }
2593
2594 return -EINVAL;
2595}
2596
Damien Lespiaubd9db022013-10-15 18:55:36 +01002597static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02002598{
Damien Lespiaub94dec82013-10-15 18:55:35 +01002599#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02002600 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01002601 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02002602 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01002603 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02002604 enum intel_pipe_crc_source source;
2605
Damien Lespiaubd9db022013-10-15 18:55:36 +01002606 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01002607 if (n_words != N_WORDS) {
2608 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
2609 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02002610 return -EINVAL;
2611 }
2612
Damien Lespiaubd9db022013-10-15 18:55:36 +01002613 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01002614 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02002615 return -EINVAL;
2616 }
2617
Damien Lespiaubd9db022013-10-15 18:55:36 +01002618 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01002619 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
2620 return -EINVAL;
2621 }
2622
Damien Lespiaubd9db022013-10-15 18:55:36 +01002623 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01002624 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02002625 return -EINVAL;
2626 }
2627
2628 return pipe_crc_set_source(dev, pipe, source);
2629}
2630
Damien Lespiaubd9db022013-10-15 18:55:36 +01002631static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
2632 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02002633{
2634 struct seq_file *m = file->private_data;
2635 struct drm_device *dev = m->private;
2636 char *tmpbuf;
2637 int ret;
2638
2639 if (len == 0)
2640 return 0;
2641
2642 if (len > PAGE_SIZE - 1) {
2643 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
2644 PAGE_SIZE);
2645 return -E2BIG;
2646 }
2647
2648 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
2649 if (!tmpbuf)
2650 return -ENOMEM;
2651
2652 if (copy_from_user(tmpbuf, ubuf, len)) {
2653 ret = -EFAULT;
2654 goto out;
2655 }
2656 tmpbuf[len] = '\0';
2657
Damien Lespiaubd9db022013-10-15 18:55:36 +01002658 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02002659
2660out:
2661 kfree(tmpbuf);
2662 if (ret < 0)
2663 return ret;
2664
2665 *offp += len;
2666 return len;
2667}
2668
Damien Lespiaubd9db022013-10-15 18:55:36 +01002669static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002670 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01002671 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02002672 .read = seq_read,
2673 .llseek = seq_lseek,
2674 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01002675 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02002676};
2677
Kees Cook647416f2013-03-10 14:10:06 -07002678static int
2679i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002680{
Kees Cook647416f2013-03-10 14:10:06 -07002681 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002682 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002683
Kees Cook647416f2013-03-10 14:10:06 -07002684 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002685
Kees Cook647416f2013-03-10 14:10:06 -07002686 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002687}
2688
Kees Cook647416f2013-03-10 14:10:06 -07002689static int
2690i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002691{
Kees Cook647416f2013-03-10 14:10:06 -07002692 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002693
Kees Cook647416f2013-03-10 14:10:06 -07002694 DRM_INFO("Manually setting wedged to %llu\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00002695 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002696
Kees Cook647416f2013-03-10 14:10:06 -07002697 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002698}
2699
Kees Cook647416f2013-03-10 14:10:06 -07002700DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
2701 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002702 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002703
Kees Cook647416f2013-03-10 14:10:06 -07002704static int
2705i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002706{
Kees Cook647416f2013-03-10 14:10:06 -07002707 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002708 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002709
Kees Cook647416f2013-03-10 14:10:06 -07002710 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002711
Kees Cook647416f2013-03-10 14:10:06 -07002712 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002713}
2714
Kees Cook647416f2013-03-10 14:10:06 -07002715static int
2716i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002717{
Kees Cook647416f2013-03-10 14:10:06 -07002718 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002719 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002720 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002721
Kees Cook647416f2013-03-10 14:10:06 -07002722 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002723
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002724 ret = mutex_lock_interruptible(&dev->struct_mutex);
2725 if (ret)
2726 return ret;
2727
Daniel Vetter99584db2012-11-14 17:14:04 +01002728 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002729 mutex_unlock(&dev->struct_mutex);
2730
Kees Cook647416f2013-03-10 14:10:06 -07002731 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002732}
2733
Kees Cook647416f2013-03-10 14:10:06 -07002734DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
2735 i915_ring_stop_get, i915_ring_stop_set,
2736 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02002737
Chris Wilson094f9a52013-09-25 17:34:55 +01002738static int
2739i915_ring_missed_irq_get(void *data, u64 *val)
2740{
2741 struct drm_device *dev = data;
2742 struct drm_i915_private *dev_priv = dev->dev_private;
2743
2744 *val = dev_priv->gpu_error.missed_irq_rings;
2745 return 0;
2746}
2747
2748static int
2749i915_ring_missed_irq_set(void *data, u64 val)
2750{
2751 struct drm_device *dev = data;
2752 struct drm_i915_private *dev_priv = dev->dev_private;
2753 int ret;
2754
2755 /* Lock against concurrent debugfs callers */
2756 ret = mutex_lock_interruptible(&dev->struct_mutex);
2757 if (ret)
2758 return ret;
2759 dev_priv->gpu_error.missed_irq_rings = val;
2760 mutex_unlock(&dev->struct_mutex);
2761
2762 return 0;
2763}
2764
2765DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
2766 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
2767 "0x%08llx\n");
2768
2769static int
2770i915_ring_test_irq_get(void *data, u64 *val)
2771{
2772 struct drm_device *dev = data;
2773 struct drm_i915_private *dev_priv = dev->dev_private;
2774
2775 *val = dev_priv->gpu_error.test_irq_rings;
2776
2777 return 0;
2778}
2779
2780static int
2781i915_ring_test_irq_set(void *data, u64 val)
2782{
2783 struct drm_device *dev = data;
2784 struct drm_i915_private *dev_priv = dev->dev_private;
2785 int ret;
2786
2787 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
2788
2789 /* Lock against concurrent debugfs callers */
2790 ret = mutex_lock_interruptible(&dev->struct_mutex);
2791 if (ret)
2792 return ret;
2793
2794 dev_priv->gpu_error.test_irq_rings = val;
2795 mutex_unlock(&dev->struct_mutex);
2796
2797 return 0;
2798}
2799
2800DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
2801 i915_ring_test_irq_get, i915_ring_test_irq_set,
2802 "0x%08llx\n");
2803
Chris Wilsondd624af2013-01-15 12:39:35 +00002804#define DROP_UNBOUND 0x1
2805#define DROP_BOUND 0x2
2806#define DROP_RETIRE 0x4
2807#define DROP_ACTIVE 0x8
2808#define DROP_ALL (DROP_UNBOUND | \
2809 DROP_BOUND | \
2810 DROP_RETIRE | \
2811 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07002812static int
2813i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00002814{
Kees Cook647416f2013-03-10 14:10:06 -07002815 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00002816
Kees Cook647416f2013-03-10 14:10:06 -07002817 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00002818}
2819
Kees Cook647416f2013-03-10 14:10:06 -07002820static int
2821i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00002822{
Kees Cook647416f2013-03-10 14:10:06 -07002823 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00002824 struct drm_i915_private *dev_priv = dev->dev_private;
2825 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07002826 struct i915_address_space *vm;
2827 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07002828 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00002829
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08002830 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00002831
2832 /* No need to check and wait for gpu resets, only libdrm auto-restarts
2833 * on ioctls on -EAGAIN. */
2834 ret = mutex_lock_interruptible(&dev->struct_mutex);
2835 if (ret)
2836 return ret;
2837
2838 if (val & DROP_ACTIVE) {
2839 ret = i915_gpu_idle(dev);
2840 if (ret)
2841 goto unlock;
2842 }
2843
2844 if (val & (DROP_RETIRE | DROP_ACTIVE))
2845 i915_gem_retire_requests(dev);
2846
2847 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07002848 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
2849 list_for_each_entry_safe(vma, x, &vm->inactive_list,
2850 mm_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -08002851 if (vma->pin_count)
Ben Widawskyca191b12013-07-31 17:00:14 -07002852 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07002853
Ben Widawskyca191b12013-07-31 17:00:14 -07002854 ret = i915_vma_unbind(vma);
2855 if (ret)
2856 goto unlock;
2857 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07002858 }
Chris Wilsondd624af2013-01-15 12:39:35 +00002859 }
2860
2861 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07002862 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
2863 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00002864 if (obj->pages_pin_count == 0) {
2865 ret = i915_gem_object_put_pages(obj);
2866 if (ret)
2867 goto unlock;
2868 }
2869 }
2870
2871unlock:
2872 mutex_unlock(&dev->struct_mutex);
2873
Kees Cook647416f2013-03-10 14:10:06 -07002874 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00002875}
2876
Kees Cook647416f2013-03-10 14:10:06 -07002877DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
2878 i915_drop_caches_get, i915_drop_caches_set,
2879 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00002880
Kees Cook647416f2013-03-10 14:10:06 -07002881static int
2882i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07002883{
Kees Cook647416f2013-03-10 14:10:06 -07002884 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07002885 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002886 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002887
2888 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2889 return -ENODEV;
2890
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002891 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2892
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002893 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002894 if (ret)
2895 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07002896
Jesse Barnes0a073b82013-04-17 15:54:58 -07002897 if (IS_VALLEYVIEW(dev))
Ville Syrjälä2ec38152013-11-05 22:42:29 +02002898 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_delay);
Jesse Barnes0a073b82013-04-17 15:54:58 -07002899 else
2900 *val = dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002901 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07002902
Kees Cook647416f2013-03-10 14:10:06 -07002903 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07002904}
2905
Kees Cook647416f2013-03-10 14:10:06 -07002906static int
2907i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07002908{
Kees Cook647416f2013-03-10 14:10:06 -07002909 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07002910 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002911 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002912
2913 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2914 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07002915
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002916 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2917
Kees Cook647416f2013-03-10 14:10:06 -07002918 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07002919
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002920 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002921 if (ret)
2922 return ret;
2923
Jesse Barnes358733e2011-07-27 11:53:01 -07002924 /*
2925 * Turbo will still be enabled, but won't go above the set value.
2926 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07002927 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02002928 val = vlv_freq_opcode(dev_priv, val);
Jesse Barnes0a073b82013-04-17 15:54:58 -07002929 dev_priv->rps.max_delay = val;
Chris Wilson6917c7b2013-11-06 13:56:26 -02002930 valleyview_set_rps(dev, val);
Jesse Barnes0a073b82013-04-17 15:54:58 -07002931 } else {
2932 do_div(val, GT_FREQUENCY_MULTIPLIER);
2933 dev_priv->rps.max_delay = val;
2934 gen6_set_rps(dev, val);
2935 }
2936
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002937 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07002938
Kees Cook647416f2013-03-10 14:10:06 -07002939 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07002940}
2941
Kees Cook647416f2013-03-10 14:10:06 -07002942DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
2943 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002944 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07002945
Kees Cook647416f2013-03-10 14:10:06 -07002946static int
2947i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07002948{
Kees Cook647416f2013-03-10 14:10:06 -07002949 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07002950 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002951 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002952
2953 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2954 return -ENODEV;
2955
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002956 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2957
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002958 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002959 if (ret)
2960 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07002961
Jesse Barnes0a073b82013-04-17 15:54:58 -07002962 if (IS_VALLEYVIEW(dev))
Ville Syrjälä2ec38152013-11-05 22:42:29 +02002963 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_delay);
Jesse Barnes0a073b82013-04-17 15:54:58 -07002964 else
2965 *val = dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002966 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002967
Kees Cook647416f2013-03-10 14:10:06 -07002968 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07002969}
2970
Kees Cook647416f2013-03-10 14:10:06 -07002971static int
2972i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07002973{
Kees Cook647416f2013-03-10 14:10:06 -07002974 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07002975 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002976 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002977
2978 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2979 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07002980
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07002981 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
2982
Kees Cook647416f2013-03-10 14:10:06 -07002983 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07002984
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002985 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002986 if (ret)
2987 return ret;
2988
Jesse Barnes1523c312012-05-25 12:34:54 -07002989 /*
2990 * Turbo will still be enabled, but won't go below the set value.
2991 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07002992 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02002993 val = vlv_freq_opcode(dev_priv, val);
Jesse Barnes0a073b82013-04-17 15:54:58 -07002994 dev_priv->rps.min_delay = val;
2995 valleyview_set_rps(dev, val);
2996 } else {
2997 do_div(val, GT_FREQUENCY_MULTIPLIER);
2998 dev_priv->rps.min_delay = val;
2999 gen6_set_rps(dev, val);
3000 }
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003001 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003002
Kees Cook647416f2013-03-10 14:10:06 -07003003 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003004}
3005
Kees Cook647416f2013-03-10 14:10:06 -07003006DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
3007 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003008 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07003009
Kees Cook647416f2013-03-10 14:10:06 -07003010static int
3011i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003012{
Kees Cook647416f2013-03-10 14:10:06 -07003013 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003014 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003015 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07003016 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003017
Daniel Vetter004777c2012-08-09 15:07:01 +02003018 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3019 return -ENODEV;
3020
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003021 ret = mutex_lock_interruptible(&dev->struct_mutex);
3022 if (ret)
3023 return ret;
3024
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003025 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
3026 mutex_unlock(&dev_priv->dev->struct_mutex);
3027
Kees Cook647416f2013-03-10 14:10:06 -07003028 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003029
Kees Cook647416f2013-03-10 14:10:06 -07003030 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003031}
3032
Kees Cook647416f2013-03-10 14:10:06 -07003033static int
3034i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003035{
Kees Cook647416f2013-03-10 14:10:06 -07003036 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003037 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003038 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003039
Daniel Vetter004777c2012-08-09 15:07:01 +02003040 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3041 return -ENODEV;
3042
Kees Cook647416f2013-03-10 14:10:06 -07003043 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003044 return -EINVAL;
3045
Kees Cook647416f2013-03-10 14:10:06 -07003046 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003047
3048 /* Update the cache sharing policy here as well */
3049 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
3050 snpcr &= ~GEN6_MBC_SNPCR_MASK;
3051 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
3052 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
3053
Kees Cook647416f2013-03-10 14:10:06 -07003054 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003055}
3056
Kees Cook647416f2013-03-10 14:10:06 -07003057DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
3058 i915_cache_sharing_get, i915_cache_sharing_set,
3059 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003060
Ben Widawsky6d794d42011-04-25 11:25:56 -07003061static int i915_forcewake_open(struct inode *inode, struct file *file)
3062{
3063 struct drm_device *dev = inode->i_private;
3064 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003065
Daniel Vetter075edca2012-01-24 09:44:28 +01003066 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003067 return 0;
3068
Deepak Sc8d9a592013-11-23 14:55:42 +05303069 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003070
3071 return 0;
3072}
3073
Ben Widawskyc43b5632012-04-16 14:07:40 -07003074static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003075{
3076 struct drm_device *dev = inode->i_private;
3077 struct drm_i915_private *dev_priv = dev->dev_private;
3078
Daniel Vetter075edca2012-01-24 09:44:28 +01003079 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003080 return 0;
3081
Deepak Sc8d9a592013-11-23 14:55:42 +05303082 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003083
3084 return 0;
3085}
3086
3087static const struct file_operations i915_forcewake_fops = {
3088 .owner = THIS_MODULE,
3089 .open = i915_forcewake_open,
3090 .release = i915_forcewake_release,
3091};
3092
3093static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
3094{
3095 struct drm_device *dev = minor->dev;
3096 struct dentry *ent;
3097
3098 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07003099 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07003100 root, dev,
3101 &i915_forcewake_fops);
3102 if (IS_ERR(ent))
3103 return PTR_ERR(ent);
3104
Ben Widawsky8eb57292011-05-11 15:10:58 -07003105 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003106}
3107
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003108static int i915_debugfs_create(struct dentry *root,
3109 struct drm_minor *minor,
3110 const char *name,
3111 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07003112{
3113 struct drm_device *dev = minor->dev;
3114 struct dentry *ent;
3115
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003116 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07003117 S_IRUGO | S_IWUSR,
3118 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003119 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07003120 if (IS_ERR(ent))
3121 return PTR_ERR(ent);
3122
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003123 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003124}
3125
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003126static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00003127 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01003128 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00003129 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01003130 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003131 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003132 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01003133 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01003134 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003135 {"i915_gem_request", i915_gem_request_info, 0},
3136 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00003137 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003138 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003139 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
3140 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
3141 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07003142 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003143 {"i915_rstdby_delays", i915_rstdby_delays, 0},
3144 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
3145 {"i915_delayfreq_table", i915_delayfreq_table, 0},
3146 {"i915_inttoext_table", i915_inttoext_table, 0},
3147 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003148 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07003149 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003150 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08003151 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03003152 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08003153 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01003154 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01003155 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07003156 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07003157 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01003158 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01003159 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07003160 {"i915_dpio", i915_dpio_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07003161 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03003162 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01003163 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03003164 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02003165 {"i915_power_domain_info", i915_power_domain_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003166};
Ben Gamari27c202a2009-07-01 22:26:52 -04003167#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05003168
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003169static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02003170 const char *name;
3171 const struct file_operations *fops;
3172} i915_debugfs_files[] = {
3173 {"i915_wedged", &i915_wedged_fops},
3174 {"i915_max_freq", &i915_max_freq_fops},
3175 {"i915_min_freq", &i915_min_freq_fops},
3176 {"i915_cache_sharing", &i915_cache_sharing_fops},
3177 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01003178 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
3179 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003180 {"i915_gem_drop_caches", &i915_drop_caches_fops},
3181 {"i915_error_state", &i915_error_state_fops},
3182 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01003183 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003184};
3185
Damien Lespiau07144422013-10-15 18:55:40 +01003186void intel_display_crc_init(struct drm_device *dev)
3187{
3188 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01003189 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01003190
Daniel Vetterb3783602013-11-14 11:30:42 +01003191 for_each_pipe(pipe) {
3192 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01003193
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003194 pipe_crc->opened = false;
3195 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003196 init_waitqueue_head(&pipe_crc->wq);
3197 }
3198}
3199
Ben Gamari27c202a2009-07-01 22:26:52 -04003200int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003201{
Daniel Vetter34b96742013-07-04 20:49:44 +02003202 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003203
Ben Widawsky6d794d42011-04-25 11:25:56 -07003204 ret = i915_forcewake_create(minor->debugfs_root, minor);
3205 if (ret)
3206 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003207
Damien Lespiau07144422013-10-15 18:55:40 +01003208 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
3209 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
3210 if (ret)
3211 return ret;
3212 }
3213
Daniel Vetter34b96742013-07-04 20:49:44 +02003214 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3215 ret = i915_debugfs_create(minor->debugfs_root, minor,
3216 i915_debugfs_files[i].name,
3217 i915_debugfs_files[i].fops);
3218 if (ret)
3219 return ret;
3220 }
Mika Kuoppala40633212012-12-04 15:12:00 +02003221
Ben Gamari27c202a2009-07-01 22:26:52 -04003222 return drm_debugfs_create_files(i915_debugfs_list,
3223 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05003224 minor->debugfs_root, minor);
3225}
3226
Ben Gamari27c202a2009-07-01 22:26:52 -04003227void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003228{
Daniel Vetter34b96742013-07-04 20:49:44 +02003229 int i;
3230
Ben Gamari27c202a2009-07-01 22:26:52 -04003231 drm_debugfs_remove_files(i915_debugfs_list,
3232 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003233
Ben Widawsky6d794d42011-04-25 11:25:56 -07003234 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
3235 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003236
Daniel Vettere309a992013-10-16 22:55:51 +02003237 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01003238 struct drm_info_list *info_list =
3239 (struct drm_info_list *)&i915_pipe_crc_data[i];
3240
3241 drm_debugfs_remove_files(info_list, 1, minor);
3242 }
3243
Daniel Vetter34b96742013-07-04 20:49:44 +02003244 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3245 struct drm_info_list *info_list =
3246 (struct drm_info_list *) i915_debugfs_files[i].fops;
3247
3248 drm_debugfs_remove_files(info_list, 1, minor);
3249 }
Ben Gamari20172632009-02-17 20:08:50 -05003250}
3251
3252#endif /* CONFIG_DEBUG_FS */