blob: a8b81407338a467fec2fcd1b604f2fabce922a69 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b8882013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Chris Wilson05394f32010-11-08 19:18:58 +000099 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +0000100 return "P";
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800101 else if (i915_gem_obj_is_pinned(obj))
Chris Wilsona6172a82009-02-11 14:26:38 +0000102 return "p";
103 else
104 return " ";
105}
106
Chris Wilson05394f32010-11-08 19:18:58 +0000107static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000108{
Akshay Joshi0206e352011-08-16 15:34:10 -0400109 switch (obj->tiling_mode) {
110 default:
111 case I915_TILING_NONE: return " ";
112 case I915_TILING_X: return "X";
113 case I915_TILING_Y: return "Y";
114 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000115}
116
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700117static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
118{
119 return obj->has_global_gtt_mapping ? "g" : " ";
120}
121
Chris Wilson37811fc2010-08-25 22:45:57 +0100122static void
123describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
124{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700125 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800126 int pin_count = 0;
127
Ville Syrjäläfb1ae912013-08-22 19:21:30 +0300128 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %u %u %u%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100129 &obj->base,
130 get_pin_flag(obj),
131 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700132 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800133 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100134 obj->base.read_domains,
135 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100136 obj->last_read_seqno,
137 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000138 obj->last_fenced_seqno,
Mika Kuoppala84734a02013-07-12 16:50:57 +0300139 i915_cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100140 obj->dirty ? " dirty" : "",
141 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
142 if (obj->base.name)
143 seq_printf(m, " (name: %d)", obj->base.name);
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800144 list_for_each_entry(vma, &obj->vma_list, vma_link)
145 if (vma->pin_count > 0)
146 pin_count++;
147 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100148 if (obj->pin_display)
149 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 if (obj->fence_reg != I915_FENCE_REG_NONE)
151 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700152 list_for_each_entry(vma, &obj->vma_list, vma_link) {
153 if (!i915_is_ggtt(vma->vm))
154 seq_puts(m, " (pp");
155 else
156 seq_puts(m, " (g");
157 seq_printf(m, "gtt offset: %08lx, size: %08lx)",
158 vma->node.start, vma->node.size);
159 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000160 if (obj->stolen)
161 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000162 if (obj->pin_mappable || obj->fault_mappable) {
163 char s[3], *t = s;
164 if (obj->pin_mappable)
165 *t++ = 'p';
166 if (obj->fault_mappable)
167 *t++ = 'f';
168 *t = '\0';
169 seq_printf(m, " (%s mappable)", s);
170 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100171 if (obj->ring != NULL)
172 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100173}
174
Oscar Mateo273497e2014-05-22 14:13:37 +0100175static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700176{
177 seq_putc(m, ctx->is_initialized ? 'I' : 'i');
178 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
179 seq_putc(m, ' ');
180}
181
Ben Gamari433e12f2009-02-17 20:08:51 -0500182static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500183{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100184 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500185 uintptr_t list = (uintptr_t) node->info_ent->data;
186 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500187 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700188 struct drm_i915_private *dev_priv = dev->dev_private;
189 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700190 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100191 size_t total_obj_size, total_gtt_size;
192 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100193
194 ret = mutex_lock_interruptible(&dev->struct_mutex);
195 if (ret)
196 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500197
Ben Widawskyca191b12013-07-31 17:00:14 -0700198 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500199 switch (list) {
200 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100201 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700202 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500203 break;
204 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100205 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700206 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500207 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500208 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100209 mutex_unlock(&dev->struct_mutex);
210 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500211 }
212
Chris Wilson8f2480f2010-09-26 11:44:19 +0100213 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700214 list_for_each_entry(vma, head, mm_list) {
215 seq_printf(m, " ");
216 describe_obj(m, vma->obj);
217 seq_printf(m, "\n");
218 total_obj_size += vma->obj->base.size;
219 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100220 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500221 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100222 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700223
Chris Wilson8f2480f2010-09-26 11:44:19 +0100224 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
225 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500226 return 0;
227}
228
Chris Wilson6d2b8882013-08-07 18:30:54 +0100229static int obj_rank_by_stolen(void *priv,
230 struct list_head *A, struct list_head *B)
231{
232 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200233 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100234 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100236
237 return a->stolen->start - b->stolen->start;
238}
239
240static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
241{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100242 struct drm_info_node *node = m->private;
Chris Wilson6d2b8882013-08-07 18:30:54 +0100243 struct drm_device *dev = node->minor->dev;
244 struct drm_i915_private *dev_priv = dev->dev_private;
245 struct drm_i915_gem_object *obj;
246 size_t total_obj_size, total_gtt_size;
247 LIST_HEAD(stolen);
248 int count, ret;
249
250 ret = mutex_lock_interruptible(&dev->struct_mutex);
251 if (ret)
252 return ret;
253
254 total_obj_size = total_gtt_size = count = 0;
255 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
256 if (obj->stolen == NULL)
257 continue;
258
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200259 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100260
261 total_obj_size += obj->base.size;
262 total_gtt_size += i915_gem_obj_ggtt_size(obj);
263 count++;
264 }
265 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
266 if (obj->stolen == NULL)
267 continue;
268
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200269 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100270
271 total_obj_size += obj->base.size;
272 count++;
273 }
274 list_sort(NULL, &stolen, obj_rank_by_stolen);
275 seq_puts(m, "Stolen:\n");
276 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200277 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100278 seq_puts(m, " ");
279 describe_obj(m, obj);
280 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200281 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100282 }
283 mutex_unlock(&dev->struct_mutex);
284
285 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
286 count, total_obj_size, total_gtt_size);
287 return 0;
288}
289
Chris Wilson6299f992010-11-24 12:23:44 +0000290#define count_objects(list, member) do { \
291 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700292 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000293 ++count; \
294 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700295 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000296 ++mappable_count; \
297 } \
298 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400299} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000300
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100301struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000302 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000304 size_t total, unbound;
305 size_t global, shared;
306 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100307};
308
309static int per_file_stats(int id, void *ptr, void *data)
310{
311 struct drm_i915_gem_object *obj = ptr;
312 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000313 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100314
315 stats->count++;
316 stats->total += obj->base.size;
317
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000318 if (obj->base.name || obj->base.dma_buf)
319 stats->shared += obj->base.size;
320
Chris Wilson6313c202014-03-19 13:45:45 +0000321 if (USES_FULL_PPGTT(obj->base.dev)) {
322 list_for_each_entry(vma, &obj->vma_list, vma_link) {
323 struct i915_hw_ppgtt *ppgtt;
324
325 if (!drm_mm_node_allocated(&vma->node))
326 continue;
327
328 if (i915_is_ggtt(vma->vm)) {
329 stats->global += obj->base.size;
330 continue;
331 }
332
333 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
334 if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv)
335 continue;
336
337 if (obj->ring) /* XXX per-vma statistic */
338 stats->active += obj->base.size;
339 else
340 stats->inactive += obj->base.size;
341
342 return 0;
343 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100344 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000345 if (i915_gem_obj_ggtt_bound(obj)) {
346 stats->global += obj->base.size;
347 if (obj->ring)
348 stats->active += obj->base.size;
349 else
350 stats->inactive += obj->base.size;
351 return 0;
352 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100353 }
354
Chris Wilson6313c202014-03-19 13:45:45 +0000355 if (!list_empty(&obj->global_list))
356 stats->unbound += obj->base.size;
357
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100358 return 0;
359}
360
Ben Widawskyca191b12013-07-31 17:00:14 -0700361#define count_vmas(list, member) do { \
362 list_for_each_entry(vma, list, member) { \
363 size += i915_gem_obj_ggtt_size(vma->obj); \
364 ++count; \
365 if (vma->obj->map_and_fenceable) { \
366 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
367 ++mappable_count; \
368 } \
369 } \
370} while (0)
371
372static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100373{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100374 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100375 struct drm_device *dev = node->minor->dev;
376 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200377 u32 count, mappable_count, purgeable_count;
378 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000379 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700380 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100381 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700382 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100383 int ret;
384
385 ret = mutex_lock_interruptible(&dev->struct_mutex);
386 if (ret)
387 return ret;
388
Chris Wilson6299f992010-11-24 12:23:44 +0000389 seq_printf(m, "%u objects, %zu bytes\n",
390 dev_priv->mm.object_count,
391 dev_priv->mm.object_memory);
392
393 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700394 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000395 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
396 count, mappable_count, size, mappable_size);
397
398 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700399 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000400 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
401 count, mappable_count, size, mappable_size);
402
403 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700404 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000405 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
406 count, mappable_count, size, mappable_size);
407
Chris Wilsonb7abb712012-08-20 11:33:30 +0200408 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700409 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200410 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200411 if (obj->madv == I915_MADV_DONTNEED)
412 purgeable_size += obj->base.size, ++purgeable_count;
413 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200414 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
415
Chris Wilson6299f992010-11-24 12:23:44 +0000416 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700417 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000418 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700419 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000420 ++count;
421 }
422 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700423 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000424 ++mappable_count;
425 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200426 if (obj->madv == I915_MADV_DONTNEED) {
427 purgeable_size += obj->base.size;
428 ++purgeable_count;
429 }
Chris Wilson6299f992010-11-24 12:23:44 +0000430 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200431 seq_printf(m, "%u purgeable objects, %zu bytes\n",
432 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000433 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
434 mappable_count, mappable_size);
435 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
436 count, size);
437
Ben Widawsky93d18792013-01-17 12:45:17 -0800438 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700439 dev_priv->gtt.base.total,
440 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100441
Damien Lespiau267f0c92013-06-24 22:59:48 +0100442 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100443 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
444 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900445 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100446
447 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000448 stats.file_priv = file->driver_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100449 idr_for_each(&file->object_idr, per_file_stats, &stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900450 /*
451 * Although we have a valid reference on file->pid, that does
452 * not guarantee that the task_struct who called get_pid() is
453 * still alive (e.g. get_pid(current) => fork() => exit()).
454 * Therefore, we need to protect this ->comm access using RCU.
455 */
456 rcu_read_lock();
457 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000458 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n",
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900459 task ? task->comm : "<unknown>",
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100460 stats.count,
461 stats.total,
462 stats.active,
463 stats.inactive,
Chris Wilson6313c202014-03-19 13:45:45 +0000464 stats.global,
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000465 stats.shared,
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100466 stats.unbound);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900467 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100468 }
469
Chris Wilson73aa8082010-09-30 11:46:12 +0100470 mutex_unlock(&dev->struct_mutex);
471
472 return 0;
473}
474
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100475static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000476{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100477 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000478 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100479 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000480 struct drm_i915_private *dev_priv = dev->dev_private;
481 struct drm_i915_gem_object *obj;
482 size_t total_obj_size, total_gtt_size;
483 int count, ret;
484
485 ret = mutex_lock_interruptible(&dev->struct_mutex);
486 if (ret)
487 return ret;
488
489 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700490 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800491 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100492 continue;
493
Damien Lespiau267f0c92013-06-24 22:59:48 +0100494 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000495 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100496 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000497 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700498 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000499 count++;
500 }
501
502 mutex_unlock(&dev->struct_mutex);
503
504 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
505 count, total_obj_size, total_gtt_size);
506
507 return 0;
508}
509
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100510static int i915_gem_pageflip_info(struct seq_file *m, void *data)
511{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100512 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100513 struct drm_device *dev = node->minor->dev;
514 unsigned long flags;
515 struct intel_crtc *crtc;
516
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100517 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800518 const char pipe = pipe_name(crtc->pipe);
519 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100520 struct intel_unpin_work *work;
521
522 spin_lock_irqsave(&dev->event_lock, flags);
523 work = crtc->unpin_work;
524 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800525 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100526 pipe, plane);
527 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000528 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800529 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100530 pipe, plane);
531 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800532 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100533 pipe, plane);
534 }
535 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100536 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100537 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100538 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000539 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100540
541 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000542 struct drm_i915_gem_object *obj = work->old_fb_obj;
543 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700544 seq_printf(m, "Old framebuffer gtt_offset 0x%08lx\n",
545 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100546 }
547 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000548 struct drm_i915_gem_object *obj = work->pending_flip_obj;
549 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700550 seq_printf(m, "New framebuffer gtt_offset 0x%08lx\n",
551 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100552 }
553 }
554 spin_unlock_irqrestore(&dev->event_lock, flags);
555 }
556
557 return 0;
558}
559
Ben Gamari20172632009-02-17 20:08:50 -0500560static int i915_gem_request_info(struct seq_file *m, void *data)
561{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100562 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500563 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300564 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100565 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500566 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100567 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100568
569 ret = mutex_lock_interruptible(&dev->struct_mutex);
570 if (ret)
571 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500572
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100573 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100574 for_each_ring(ring, dev_priv, i) {
575 if (list_empty(&ring->request_list))
576 continue;
577
578 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100579 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100580 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100581 list) {
582 seq_printf(m, " %d @ %d\n",
583 gem_request->seqno,
584 (int) (jiffies - gem_request->emitted_jiffies));
585 }
586 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500587 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100588 mutex_unlock(&dev->struct_mutex);
589
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100590 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100591 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100592
Ben Gamari20172632009-02-17 20:08:50 -0500593 return 0;
594}
595
Chris Wilsonb2223492010-10-27 15:27:33 +0100596static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100597 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100598{
599 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200600 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100601 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100602 }
603}
604
Ben Gamari20172632009-02-17 20:08:50 -0500605static int i915_gem_seqno_info(struct seq_file *m, void *data)
606{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100607 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500608 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300609 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100610 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000611 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100612
613 ret = mutex_lock_interruptible(&dev->struct_mutex);
614 if (ret)
615 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200616 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500617
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100618 for_each_ring(ring, dev_priv, i)
619 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100620
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200621 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100622 mutex_unlock(&dev->struct_mutex);
623
Ben Gamari20172632009-02-17 20:08:50 -0500624 return 0;
625}
626
627
628static int i915_interrupt_info(struct seq_file *m, void *data)
629{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100630 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500631 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300632 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100633 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800634 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100635
636 ret = mutex_lock_interruptible(&dev->struct_mutex);
637 if (ret)
638 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200639 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500640
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300641 if (IS_CHERRYVIEW(dev)) {
642 int i;
643 seq_printf(m, "Master Interrupt Control:\t%08x\n",
644 I915_READ(GEN8_MASTER_IRQ));
645
646 seq_printf(m, "Display IER:\t%08x\n",
647 I915_READ(VLV_IER));
648 seq_printf(m, "Display IIR:\t%08x\n",
649 I915_READ(VLV_IIR));
650 seq_printf(m, "Display IIR_RW:\t%08x\n",
651 I915_READ(VLV_IIR_RW));
652 seq_printf(m, "Display IMR:\t%08x\n",
653 I915_READ(VLV_IMR));
654 for_each_pipe(pipe)
655 seq_printf(m, "Pipe %c stat:\t%08x\n",
656 pipe_name(pipe),
657 I915_READ(PIPESTAT(pipe)));
658
659 seq_printf(m, "Port hotplug:\t%08x\n",
660 I915_READ(PORT_HOTPLUG_EN));
661 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
662 I915_READ(VLV_DPFLIPSTAT));
663 seq_printf(m, "DPINVGTT:\t%08x\n",
664 I915_READ(DPINVGTT));
665
666 for (i = 0; i < 4; i++) {
667 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
668 i, I915_READ(GEN8_GT_IMR(i)));
669 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
670 i, I915_READ(GEN8_GT_IIR(i)));
671 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
672 i, I915_READ(GEN8_GT_IER(i)));
673 }
674
675 seq_printf(m, "PCU interrupt mask:\t%08x\n",
676 I915_READ(GEN8_PCU_IMR));
677 seq_printf(m, "PCU interrupt identity:\t%08x\n",
678 I915_READ(GEN8_PCU_IIR));
679 seq_printf(m, "PCU interrupt enable:\t%08x\n",
680 I915_READ(GEN8_PCU_IER));
681 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700682 seq_printf(m, "Master Interrupt Control:\t%08x\n",
683 I915_READ(GEN8_MASTER_IRQ));
684
685 for (i = 0; i < 4; i++) {
686 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
687 i, I915_READ(GEN8_GT_IMR(i)));
688 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
689 i, I915_READ(GEN8_GT_IIR(i)));
690 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
691 i, I915_READ(GEN8_GT_IER(i)));
692 }
693
Damien Lespiau07d27e22014-03-03 17:31:46 +0000694 for_each_pipe(pipe) {
Ben Widawskya123f152013-11-02 21:07:10 -0700695 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000696 pipe_name(pipe),
697 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700698 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000699 pipe_name(pipe),
700 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700701 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000702 pipe_name(pipe),
703 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700704 }
705
706 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
707 I915_READ(GEN8_DE_PORT_IMR));
708 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
709 I915_READ(GEN8_DE_PORT_IIR));
710 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
711 I915_READ(GEN8_DE_PORT_IER));
712
713 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
714 I915_READ(GEN8_DE_MISC_IMR));
715 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
716 I915_READ(GEN8_DE_MISC_IIR));
717 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
718 I915_READ(GEN8_DE_MISC_IER));
719
720 seq_printf(m, "PCU interrupt mask:\t%08x\n",
721 I915_READ(GEN8_PCU_IMR));
722 seq_printf(m, "PCU interrupt identity:\t%08x\n",
723 I915_READ(GEN8_PCU_IIR));
724 seq_printf(m, "PCU interrupt enable:\t%08x\n",
725 I915_READ(GEN8_PCU_IER));
726 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700727 seq_printf(m, "Display IER:\t%08x\n",
728 I915_READ(VLV_IER));
729 seq_printf(m, "Display IIR:\t%08x\n",
730 I915_READ(VLV_IIR));
731 seq_printf(m, "Display IIR_RW:\t%08x\n",
732 I915_READ(VLV_IIR_RW));
733 seq_printf(m, "Display IMR:\t%08x\n",
734 I915_READ(VLV_IMR));
735 for_each_pipe(pipe)
736 seq_printf(m, "Pipe %c stat:\t%08x\n",
737 pipe_name(pipe),
738 I915_READ(PIPESTAT(pipe)));
739
740 seq_printf(m, "Master IER:\t%08x\n",
741 I915_READ(VLV_MASTER_IER));
742
743 seq_printf(m, "Render IER:\t%08x\n",
744 I915_READ(GTIER));
745 seq_printf(m, "Render IIR:\t%08x\n",
746 I915_READ(GTIIR));
747 seq_printf(m, "Render IMR:\t%08x\n",
748 I915_READ(GTIMR));
749
750 seq_printf(m, "PM IER:\t\t%08x\n",
751 I915_READ(GEN6_PMIER));
752 seq_printf(m, "PM IIR:\t\t%08x\n",
753 I915_READ(GEN6_PMIIR));
754 seq_printf(m, "PM IMR:\t\t%08x\n",
755 I915_READ(GEN6_PMIMR));
756
757 seq_printf(m, "Port hotplug:\t%08x\n",
758 I915_READ(PORT_HOTPLUG_EN));
759 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
760 I915_READ(VLV_DPFLIPSTAT));
761 seq_printf(m, "DPINVGTT:\t%08x\n",
762 I915_READ(DPINVGTT));
763
764 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800765 seq_printf(m, "Interrupt enable: %08x\n",
766 I915_READ(IER));
767 seq_printf(m, "Interrupt identity: %08x\n",
768 I915_READ(IIR));
769 seq_printf(m, "Interrupt mask: %08x\n",
770 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800771 for_each_pipe(pipe)
772 seq_printf(m, "Pipe %c stat: %08x\n",
773 pipe_name(pipe),
774 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800775 } else {
776 seq_printf(m, "North Display Interrupt enable: %08x\n",
777 I915_READ(DEIER));
778 seq_printf(m, "North Display Interrupt identity: %08x\n",
779 I915_READ(DEIIR));
780 seq_printf(m, "North Display Interrupt mask: %08x\n",
781 I915_READ(DEIMR));
782 seq_printf(m, "South Display Interrupt enable: %08x\n",
783 I915_READ(SDEIER));
784 seq_printf(m, "South Display Interrupt identity: %08x\n",
785 I915_READ(SDEIIR));
786 seq_printf(m, "South Display Interrupt mask: %08x\n",
787 I915_READ(SDEIMR));
788 seq_printf(m, "Graphics Interrupt enable: %08x\n",
789 I915_READ(GTIER));
790 seq_printf(m, "Graphics Interrupt identity: %08x\n",
791 I915_READ(GTIIR));
792 seq_printf(m, "Graphics Interrupt mask: %08x\n",
793 I915_READ(GTIMR));
794 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100795 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700796 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100797 seq_printf(m,
798 "Graphics Interrupt mask (%s): %08x\n",
799 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000800 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100801 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000802 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200803 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100804 mutex_unlock(&dev->struct_mutex);
805
Ben Gamari20172632009-02-17 20:08:50 -0500806 return 0;
807}
808
Chris Wilsona6172a82009-02-11 14:26:38 +0000809static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
810{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100811 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000812 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300813 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100814 int i, ret;
815
816 ret = mutex_lock_interruptible(&dev->struct_mutex);
817 if (ret)
818 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000819
820 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
821 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
822 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000823 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000824
Chris Wilson6c085a72012-08-20 11:40:46 +0200825 seq_printf(m, "Fence %d, pin count = %d, object = ",
826 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100827 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100828 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100829 else
Chris Wilson05394f32010-11-08 19:18:58 +0000830 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100831 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000832 }
833
Chris Wilson05394f32010-11-08 19:18:58 +0000834 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000835 return 0;
836}
837
Ben Gamari20172632009-02-17 20:08:50 -0500838static int i915_hws_info(struct seq_file *m, void *data)
839{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100840 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500841 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300842 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100843 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100844 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100845 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500846
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000847 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100848 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500849 if (hws == NULL)
850 return 0;
851
852 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
853 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
854 i * 4,
855 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
856 }
857 return 0;
858}
859
Daniel Vetterd5442302012-04-27 15:17:40 +0200860static ssize_t
861i915_error_state_write(struct file *filp,
862 const char __user *ubuf,
863 size_t cnt,
864 loff_t *ppos)
865{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300866 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200867 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200868 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200869
870 DRM_DEBUG_DRIVER("Resetting error state\n");
871
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200872 ret = mutex_lock_interruptible(&dev->struct_mutex);
873 if (ret)
874 return ret;
875
Daniel Vetterd5442302012-04-27 15:17:40 +0200876 i915_destroy_error_state(dev);
877 mutex_unlock(&dev->struct_mutex);
878
879 return cnt;
880}
881
882static int i915_error_state_open(struct inode *inode, struct file *file)
883{
884 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200885 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200886
887 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
888 if (!error_priv)
889 return -ENOMEM;
890
891 error_priv->dev = dev;
892
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300893 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200894
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300895 file->private_data = error_priv;
896
897 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200898}
899
900static int i915_error_state_release(struct inode *inode, struct file *file)
901{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300902 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200903
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300904 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200905 kfree(error_priv);
906
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300907 return 0;
908}
909
910static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
911 size_t count, loff_t *pos)
912{
913 struct i915_error_state_file_priv *error_priv = file->private_data;
914 struct drm_i915_error_state_buf error_str;
915 loff_t tmp_pos = 0;
916 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300917 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300918
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300919 ret = i915_error_state_buf_init(&error_str, count, *pos);
920 if (ret)
921 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300922
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300923 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300924 if (ret)
925 goto out;
926
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300927 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
928 error_str.buf,
929 error_str.bytes);
930
931 if (ret_count < 0)
932 ret = ret_count;
933 else
934 *pos = error_str.start + ret_count;
935out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300936 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300937 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200938}
939
940static const struct file_operations i915_error_state_fops = {
941 .owner = THIS_MODULE,
942 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300943 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200944 .write = i915_error_state_write,
945 .llseek = default_llseek,
946 .release = i915_error_state_release,
947};
948
Kees Cook647416f2013-03-10 14:10:06 -0700949static int
950i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200951{
Kees Cook647416f2013-03-10 14:10:06 -0700952 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300953 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200954 int ret;
955
956 ret = mutex_lock_interruptible(&dev->struct_mutex);
957 if (ret)
958 return ret;
959
Kees Cook647416f2013-03-10 14:10:06 -0700960 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200961 mutex_unlock(&dev->struct_mutex);
962
Kees Cook647416f2013-03-10 14:10:06 -0700963 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200964}
965
Kees Cook647416f2013-03-10 14:10:06 -0700966static int
967i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200968{
Kees Cook647416f2013-03-10 14:10:06 -0700969 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200970 int ret;
971
Mika Kuoppala40633212012-12-04 15:12:00 +0200972 ret = mutex_lock_interruptible(&dev->struct_mutex);
973 if (ret)
974 return ret;
975
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200976 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200977 mutex_unlock(&dev->struct_mutex);
978
Kees Cook647416f2013-03-10 14:10:06 -0700979 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200980}
981
Kees Cook647416f2013-03-10 14:10:06 -0700982DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
983 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +0300984 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +0200985
Jesse Barnesf97108d2010-01-29 11:27:07 -0800986static int i915_rstdby_delays(struct seq_file *m, void *unused)
987{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100988 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800989 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300990 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700991 u16 crstanddelay;
992 int ret;
993
994 ret = mutex_lock_interruptible(&dev->struct_mutex);
995 if (ret)
996 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200997 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -0700998
999 crstanddelay = I915_READ16(CRSTANDVID);
1000
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001001 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001002 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001003
1004 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
1005
1006 return 0;
1007}
1008
Deepak Sadb4bd12014-03-31 11:30:02 +05301009static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001010{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001011 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001012 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001013 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001014 int ret = 0;
1015
1016 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001017
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001018 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1019
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001020 if (IS_GEN5(dev)) {
1021 u16 rgvswctl = I915_READ16(MEMSWCTL);
1022 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1023
1024 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1025 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1026 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1027 MEMSTAT_VID_SHIFT);
1028 seq_printf(m, "Current P-state: %d\n",
1029 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001030 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1031 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001032 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1033 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1034 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001035 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001036 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001037 u32 rpupei, rpcurup, rpprevup;
1038 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001039 int max_freq;
1040
1041 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001042 ret = mutex_lock_interruptible(&dev->struct_mutex);
1043 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001044 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001045
Deepak Sc8d9a592013-11-23 14:55:42 +05301046 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001047
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001048 reqf = I915_READ(GEN6_RPNSWREQ);
1049 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001050 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001051 reqf >>= 24;
1052 else
1053 reqf >>= 25;
1054 reqf *= GT_FREQUENCY_MULTIPLIER;
1055
Chris Wilson0d8f9492014-03-27 09:06:14 +00001056 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1057 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1058 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1059
Jesse Barnesccab5c82011-01-18 15:49:25 -08001060 rpstat = I915_READ(GEN6_RPSTAT1);
1061 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1062 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1063 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1064 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1065 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1066 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001067 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001068 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1069 else
1070 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1071 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001072
Deepak Sc8d9a592013-11-23 14:55:42 +05301073 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001074 mutex_unlock(&dev->struct_mutex);
1075
Chris Wilson0d8f9492014-03-27 09:06:14 +00001076 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
1077 I915_READ(GEN6_PMIER),
1078 I915_READ(GEN6_PMIMR),
1079 I915_READ(GEN6_PMISR),
1080 I915_READ(GEN6_PMIIR),
1081 I915_READ(GEN6_PMINTRMSK));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001082 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001083 seq_printf(m, "Render p-state ratio: %d\n",
1084 (gt_perf_status & 0xff00) >> 8);
1085 seq_printf(m, "Render p-state VID: %d\n",
1086 gt_perf_status & 0xff);
1087 seq_printf(m, "Render p-state limit: %d\n",
1088 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001089 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1090 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1091 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1092 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001093 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001094 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001095 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1096 GEN6_CURICONT_MASK);
1097 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1098 GEN6_CURBSYTAVG_MASK);
1099 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1100 GEN6_CURBSYTAVG_MASK);
1101 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1102 GEN6_CURIAVG_MASK);
1103 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1104 GEN6_CURBSYTAVG_MASK);
1105 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1106 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001107
1108 max_freq = (rp_state_cap & 0xff0000) >> 16;
1109 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001110 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001111
1112 max_freq = (rp_state_cap & 0xff00) >> 8;
1113 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001114 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001115
1116 max_freq = rp_state_cap & 0xff;
1117 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001118 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001119
1120 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ben Widawskyb39fb292014-03-19 18:31:11 -07001121 dev_priv->rps.max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001122 } else if (IS_VALLEYVIEW(dev)) {
1123 u32 freq_sts, val;
1124
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001125 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001126 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001127 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1128 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1129
Chon Ming Leec5bd2bf2013-11-07 15:23:27 +08001130 val = valleyview_rps_max_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001131 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001132 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001133
Chon Ming Leec5bd2bf2013-11-07 15:23:27 +08001134 val = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001135 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001136 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001137
1138 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001139 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001140 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001141 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001142 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001144
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001145out:
1146 intel_runtime_pm_put(dev_priv);
1147 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001148}
1149
1150static int i915_delayfreq_table(struct seq_file *m, void *unused)
1151{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001152 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001153 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001154 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001155 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001156 int ret, i;
1157
1158 ret = mutex_lock_interruptible(&dev->struct_mutex);
1159 if (ret)
1160 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001161 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001162
1163 for (i = 0; i < 16; i++) {
1164 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001165 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1166 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001167 }
1168
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001169 intel_runtime_pm_put(dev_priv);
1170
Ben Widawsky616fdb52011-10-05 11:44:54 -07001171 mutex_unlock(&dev->struct_mutex);
1172
Jesse Barnesf97108d2010-01-29 11:27:07 -08001173 return 0;
1174}
1175
1176static inline int MAP_TO_MV(int map)
1177{
1178 return 1250 - (map * 25);
1179}
1180
1181static int i915_inttoext_table(struct seq_file *m, void *unused)
1182{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001183 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001184 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001185 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001186 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001187 int ret, i;
1188
1189 ret = mutex_lock_interruptible(&dev->struct_mutex);
1190 if (ret)
1191 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001192 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001193
1194 for (i = 1; i <= 32; i++) {
1195 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1196 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1197 }
1198
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001199 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001200 mutex_unlock(&dev->struct_mutex);
1201
Jesse Barnesf97108d2010-01-29 11:27:07 -08001202 return 0;
1203}
1204
Ben Widawsky4d855292011-12-12 19:34:16 -08001205static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001206{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001207 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001208 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001209 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001210 u32 rgvmodectl, rstdbyctl;
1211 u16 crstandvid;
1212 int ret;
1213
1214 ret = mutex_lock_interruptible(&dev->struct_mutex);
1215 if (ret)
1216 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001217 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001218
1219 rgvmodectl = I915_READ(MEMMODECTL);
1220 rstdbyctl = I915_READ(RSTDBYCTL);
1221 crstandvid = I915_READ16(CRSTANDVID);
1222
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001223 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001224 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001225
1226 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1227 "yes" : "no");
1228 seq_printf(m, "Boost freq: %d\n",
1229 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1230 MEMMODE_BOOST_FREQ_SHIFT);
1231 seq_printf(m, "HW control enabled: %s\n",
1232 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1233 seq_printf(m, "SW control enabled: %s\n",
1234 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1235 seq_printf(m, "Gated voltage change: %s\n",
1236 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1237 seq_printf(m, "Starting frequency: P%d\n",
1238 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001239 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001240 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001241 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1242 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1243 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1244 seq_printf(m, "Render standby enabled: %s\n",
1245 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001246 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001247 switch (rstdbyctl & RSX_STATUS_MASK) {
1248 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001249 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001250 break;
1251 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001252 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001253 break;
1254 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001255 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001256 break;
1257 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001258 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001259 break;
1260 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001261 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001262 break;
1263 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001264 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001265 break;
1266 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001267 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001268 break;
1269 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001270
1271 return 0;
1272}
1273
Deepak S669ab5a2014-01-10 15:18:26 +05301274static int vlv_drpc_info(struct seq_file *m)
1275{
1276
Damien Lespiau9f25d002014-05-13 15:30:28 +01001277 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301278 struct drm_device *dev = node->minor->dev;
1279 struct drm_i915_private *dev_priv = dev->dev_private;
1280 u32 rpmodectl1, rcctl1;
1281 unsigned fw_rendercount = 0, fw_mediacount = 0;
1282
Imre Deakd46c0512014-04-14 20:24:27 +03001283 intel_runtime_pm_get(dev_priv);
1284
Deepak S669ab5a2014-01-10 15:18:26 +05301285 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1286 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1287
Imre Deakd46c0512014-04-14 20:24:27 +03001288 intel_runtime_pm_put(dev_priv);
1289
Deepak S669ab5a2014-01-10 15:18:26 +05301290 seq_printf(m, "Video Turbo Mode: %s\n",
1291 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1292 seq_printf(m, "Turbo enabled: %s\n",
1293 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1294 seq_printf(m, "HW control enabled: %s\n",
1295 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1296 seq_printf(m, "SW control enabled: %s\n",
1297 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1298 GEN6_RP_MEDIA_SW_MODE));
1299 seq_printf(m, "RC6 Enabled: %s\n",
1300 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1301 GEN6_RC_CTL_EI_MODE(1))));
1302 seq_printf(m, "Render Power Well: %s\n",
1303 (I915_READ(VLV_GTLC_PW_STATUS) &
1304 VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
1305 seq_printf(m, "Media Power Well: %s\n",
1306 (I915_READ(VLV_GTLC_PW_STATUS) &
1307 VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
1308
Imre Deak9cc19be2014-04-14 20:24:24 +03001309 seq_printf(m, "Render RC6 residency since boot: %u\n",
1310 I915_READ(VLV_GT_RENDER_RC6));
1311 seq_printf(m, "Media RC6 residency since boot: %u\n",
1312 I915_READ(VLV_GT_MEDIA_RC6));
1313
Deepak S669ab5a2014-01-10 15:18:26 +05301314 spin_lock_irq(&dev_priv->uncore.lock);
1315 fw_rendercount = dev_priv->uncore.fw_rendercount;
1316 fw_mediacount = dev_priv->uncore.fw_mediacount;
1317 spin_unlock_irq(&dev_priv->uncore.lock);
1318
1319 seq_printf(m, "Forcewake Render Count = %u\n", fw_rendercount);
1320 seq_printf(m, "Forcewake Media Count = %u\n", fw_mediacount);
1321
1322
1323 return 0;
1324}
1325
1326
Ben Widawsky4d855292011-12-12 19:34:16 -08001327static int gen6_drpc_info(struct seq_file *m)
1328{
1329
Damien Lespiau9f25d002014-05-13 15:30:28 +01001330 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001331 struct drm_device *dev = node->minor->dev;
1332 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001333 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001334 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001335 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001336
1337 ret = mutex_lock_interruptible(&dev->struct_mutex);
1338 if (ret)
1339 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001340 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001341
Chris Wilson907b28c2013-07-19 20:36:52 +01001342 spin_lock_irq(&dev_priv->uncore.lock);
1343 forcewake_count = dev_priv->uncore.forcewake_count;
1344 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001345
1346 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001347 seq_puts(m, "RC information inaccurate because somebody "
1348 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001349 } else {
1350 /* NB: we cannot use forcewake, else we read the wrong values */
1351 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1352 udelay(10);
1353 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1354 }
1355
1356 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001357 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001358
1359 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1360 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1361 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001362 mutex_lock(&dev_priv->rps.hw_lock);
1363 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1364 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001365
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001366 intel_runtime_pm_put(dev_priv);
1367
Ben Widawsky4d855292011-12-12 19:34:16 -08001368 seq_printf(m, "Video Turbo Mode: %s\n",
1369 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1370 seq_printf(m, "HW control enabled: %s\n",
1371 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1372 seq_printf(m, "SW control enabled: %s\n",
1373 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1374 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001375 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001376 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1377 seq_printf(m, "RC6 Enabled: %s\n",
1378 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1379 seq_printf(m, "Deep RC6 Enabled: %s\n",
1380 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1381 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1382 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001383 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001384 switch (gt_core_status & GEN6_RCn_MASK) {
1385 case GEN6_RC0:
1386 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001387 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001388 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001389 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001390 break;
1391 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001392 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001393 break;
1394 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001395 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001396 break;
1397 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001398 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001399 break;
1400 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001401 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001402 break;
1403 }
1404
1405 seq_printf(m, "Core Power Down: %s\n",
1406 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001407
1408 /* Not exactly sure what this is */
1409 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1410 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1411 seq_printf(m, "RC6 residency since boot: %u\n",
1412 I915_READ(GEN6_GT_GFX_RC6));
1413 seq_printf(m, "RC6+ residency since boot: %u\n",
1414 I915_READ(GEN6_GT_GFX_RC6p));
1415 seq_printf(m, "RC6++ residency since boot: %u\n",
1416 I915_READ(GEN6_GT_GFX_RC6pp));
1417
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001418 seq_printf(m, "RC6 voltage: %dmV\n",
1419 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1420 seq_printf(m, "RC6+ voltage: %dmV\n",
1421 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1422 seq_printf(m, "RC6++ voltage: %dmV\n",
1423 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001424 return 0;
1425}
1426
1427static int i915_drpc_info(struct seq_file *m, void *unused)
1428{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001429 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001430 struct drm_device *dev = node->minor->dev;
1431
Deepak S669ab5a2014-01-10 15:18:26 +05301432 if (IS_VALLEYVIEW(dev))
1433 return vlv_drpc_info(m);
1434 else if (IS_GEN6(dev) || IS_GEN7(dev))
Ben Widawsky4d855292011-12-12 19:34:16 -08001435 return gen6_drpc_info(m);
1436 else
1437 return ironlake_drpc_info(m);
1438}
1439
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001440static int i915_fbc_status(struct seq_file *m, void *unused)
1441{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001442 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001443 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001444 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001445
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001446 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001448 return 0;
1449 }
1450
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001451 intel_runtime_pm_get(dev_priv);
1452
Adam Jacksonee5382a2010-04-23 11:17:39 -04001453 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001454 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001455 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001457 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001458 case FBC_OK:
1459 seq_puts(m, "FBC actived, but currently disabled in hardware");
1460 break;
1461 case FBC_UNSUPPORTED:
1462 seq_puts(m, "unsupported by this chipset");
1463 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001464 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001465 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001466 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001467 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001468 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001469 break;
1470 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001471 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001472 break;
1473 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001474 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001475 break;
1476 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001477 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001478 break;
1479 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001480 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001481 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001482 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001483 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001484 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001485 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001486 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001487 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001488 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001489 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001490 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001491 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001492 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001493 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001494 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001495 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001496
1497 intel_runtime_pm_put(dev_priv);
1498
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001499 return 0;
1500}
1501
Paulo Zanoni92d44622013-05-31 16:33:24 -03001502static int i915_ips_status(struct seq_file *m, void *unused)
1503{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001504 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001505 struct drm_device *dev = node->minor->dev;
1506 struct drm_i915_private *dev_priv = dev->dev_private;
1507
Damien Lespiauf5adf942013-06-24 18:29:34 +01001508 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001509 seq_puts(m, "not supported\n");
1510 return 0;
1511 }
1512
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001513 intel_runtime_pm_get(dev_priv);
1514
Jesse Barnese59150d2014-01-07 13:30:45 -08001515 if (IS_BROADWELL(dev) || I915_READ(IPS_CTL) & IPS_ENABLE)
Paulo Zanoni92d44622013-05-31 16:33:24 -03001516 seq_puts(m, "enabled\n");
1517 else
1518 seq_puts(m, "disabled\n");
1519
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001520 intel_runtime_pm_put(dev_priv);
1521
Paulo Zanoni92d44622013-05-31 16:33:24 -03001522 return 0;
1523}
1524
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001525static int i915_sr_status(struct seq_file *m, void *unused)
1526{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001527 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001528 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001529 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001530 bool sr_enabled = false;
1531
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001532 intel_runtime_pm_get(dev_priv);
1533
Yuanhan Liu13982612010-12-15 15:42:31 +08001534 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001535 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001536 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001537 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1538 else if (IS_I915GM(dev))
1539 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1540 else if (IS_PINEVIEW(dev))
1541 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1542
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001543 intel_runtime_pm_put(dev_priv);
1544
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001545 seq_printf(m, "self-refresh: %s\n",
1546 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001547
1548 return 0;
1549}
1550
Jesse Barnes7648fa92010-05-20 14:28:11 -07001551static int i915_emon_status(struct seq_file *m, void *unused)
1552{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001553 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001554 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001555 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001556 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001557 int ret;
1558
Chris Wilson582be6b2012-04-30 19:35:02 +01001559 if (!IS_GEN5(dev))
1560 return -ENODEV;
1561
Chris Wilsonde227ef2010-07-03 07:58:38 +01001562 ret = mutex_lock_interruptible(&dev->struct_mutex);
1563 if (ret)
1564 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001565
1566 temp = i915_mch_val(dev_priv);
1567 chipset = i915_chipset_val(dev_priv);
1568 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001569 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001570
1571 seq_printf(m, "GMCH temp: %ld\n", temp);
1572 seq_printf(m, "Chipset power: %ld\n", chipset);
1573 seq_printf(m, "GFX power: %ld\n", gfx);
1574 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1575
1576 return 0;
1577}
1578
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001579static int i915_ring_freq_table(struct seq_file *m, void *unused)
1580{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001581 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001582 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001583 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001584 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001585 int gpu_freq, ia_freq;
1586
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001587 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001588 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001589 return 0;
1590 }
1591
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001592 intel_runtime_pm_get(dev_priv);
1593
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001594 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1595
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001596 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001597 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001598 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001599
Damien Lespiau267f0c92013-06-24 22:59:48 +01001600 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001601
Ben Widawskyb39fb292014-03-19 18:31:11 -07001602 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1603 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001604 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001605 ia_freq = gpu_freq;
1606 sandybridge_pcode_read(dev_priv,
1607 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1608 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001609 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1610 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1611 ((ia_freq >> 0) & 0xff) * 100,
1612 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001613 }
1614
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001615 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001616
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001617out:
1618 intel_runtime_pm_put(dev_priv);
1619 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001620}
1621
Jesse Barnes7648fa92010-05-20 14:28:11 -07001622static int i915_gfxec(struct seq_file *m, void *unused)
1623{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001624 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001625 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001626 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001627 int ret;
1628
1629 ret = mutex_lock_interruptible(&dev->struct_mutex);
1630 if (ret)
1631 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001632 intel_runtime_pm_get(dev_priv);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001633
1634 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001635 intel_runtime_pm_put(dev_priv);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001636
Ben Widawsky616fdb52011-10-05 11:44:54 -07001637 mutex_unlock(&dev->struct_mutex);
1638
Jesse Barnes7648fa92010-05-20 14:28:11 -07001639 return 0;
1640}
1641
Chris Wilson44834a62010-08-19 16:09:23 +01001642static int i915_opregion(struct seq_file *m, void *unused)
1643{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001644 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001645 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001646 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001647 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001648 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001649 int ret;
1650
Daniel Vetter0d38f002012-04-21 22:49:10 +02001651 if (data == NULL)
1652 return -ENOMEM;
1653
Chris Wilson44834a62010-08-19 16:09:23 +01001654 ret = mutex_lock_interruptible(&dev->struct_mutex);
1655 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001656 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001657
Daniel Vetter0d38f002012-04-21 22:49:10 +02001658 if (opregion->header) {
1659 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1660 seq_write(m, data, OPREGION_SIZE);
1661 }
Chris Wilson44834a62010-08-19 16:09:23 +01001662
1663 mutex_unlock(&dev->struct_mutex);
1664
Daniel Vetter0d38f002012-04-21 22:49:10 +02001665out:
1666 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001667 return 0;
1668}
1669
Chris Wilson37811fc2010-08-25 22:45:57 +01001670static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1671{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001672 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001673 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001674 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001675 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001676
Daniel Vetter4520f532013-10-09 09:18:51 +02001677#ifdef CONFIG_DRM_I915_FBDEV
1678 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001679
1680 ifbdev = dev_priv->fbdev;
1681 fb = to_intel_framebuffer(ifbdev->helper.fb);
1682
Daniel Vetter623f9782012-12-11 16:21:38 +01001683 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001684 fb->base.width,
1685 fb->base.height,
1686 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001687 fb->base.bits_per_pixel,
1688 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001689 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001690 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001691#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001692
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001693 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001694 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001695 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001696 continue;
1697
Daniel Vetter623f9782012-12-11 16:21:38 +01001698 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001699 fb->base.width,
1700 fb->base.height,
1701 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001702 fb->base.bits_per_pixel,
1703 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001704 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001705 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001706 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001707 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001708
1709 return 0;
1710}
1711
Ben Widawskye76d3632011-03-19 18:14:29 -07001712static int i915_context_status(struct seq_file *m, void *unused)
1713{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001714 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001715 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001716 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001717 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001718 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001719 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001720
Daniel Vetterf3d28872014-05-29 23:23:08 +02001721 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001722 if (ret)
1723 return ret;
1724
Daniel Vetter3e373942012-11-02 19:55:04 +01001725 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001726 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001727 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001728 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001729 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001730
Daniel Vetter3e373942012-11-02 19:55:04 +01001731 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001732 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001733 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001734 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001735 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001736
Ben Widawskya33afea2013-09-17 21:12:45 -07001737 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilsonb77f6992014-04-30 08:30:00 +01001738 if (ctx->obj == NULL)
1739 continue;
1740
Ben Widawskya33afea2013-09-17 21:12:45 -07001741 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001742 describe_ctx(m, ctx);
Ben Widawskya33afea2013-09-17 21:12:45 -07001743 for_each_ring(ring, dev_priv, i)
1744 if (ring->default_context == ctx)
1745 seq_printf(m, "(default context %s) ", ring->name);
1746
1747 describe_obj(m, ctx->obj);
1748 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001749 }
1750
Daniel Vetterf3d28872014-05-29 23:23:08 +02001751 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001752
1753 return 0;
1754}
1755
Ben Widawsky6d794d42011-04-25 11:25:56 -07001756static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1757{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001758 struct drm_info_node *node = m->private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001759 struct drm_device *dev = node->minor->dev;
1760 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301761 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001762
Chris Wilson907b28c2013-07-19 20:36:52 +01001763 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301764 if (IS_VALLEYVIEW(dev)) {
1765 fw_rendercount = dev_priv->uncore.fw_rendercount;
1766 fw_mediacount = dev_priv->uncore.fw_mediacount;
1767 } else
1768 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001769 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001770
Deepak S43709ba2013-11-23 14:55:44 +05301771 if (IS_VALLEYVIEW(dev)) {
1772 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1773 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1774 } else
1775 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001776
1777 return 0;
1778}
1779
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001780static const char *swizzle_string(unsigned swizzle)
1781{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001782 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001783 case I915_BIT_6_SWIZZLE_NONE:
1784 return "none";
1785 case I915_BIT_6_SWIZZLE_9:
1786 return "bit9";
1787 case I915_BIT_6_SWIZZLE_9_10:
1788 return "bit9/bit10";
1789 case I915_BIT_6_SWIZZLE_9_11:
1790 return "bit9/bit11";
1791 case I915_BIT_6_SWIZZLE_9_10_11:
1792 return "bit9/bit10/bit11";
1793 case I915_BIT_6_SWIZZLE_9_17:
1794 return "bit9/bit17";
1795 case I915_BIT_6_SWIZZLE_9_10_17:
1796 return "bit9/bit10/bit17";
1797 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001798 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001799 }
1800
1801 return "bug";
1802}
1803
1804static int i915_swizzle_info(struct seq_file *m, void *data)
1805{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001806 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001807 struct drm_device *dev = node->minor->dev;
1808 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001809 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001810
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001811 ret = mutex_lock_interruptible(&dev->struct_mutex);
1812 if (ret)
1813 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001814 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001815
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001816 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1817 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1818 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1819 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1820
1821 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1822 seq_printf(m, "DDC = 0x%08x\n",
1823 I915_READ(DCC));
1824 seq_printf(m, "C0DRB3 = 0x%04x\n",
1825 I915_READ16(C0DRB3));
1826 seq_printf(m, "C1DRB3 = 0x%04x\n",
1827 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001828 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001829 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1830 I915_READ(MAD_DIMM_C0));
1831 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1832 I915_READ(MAD_DIMM_C1));
1833 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1834 I915_READ(MAD_DIMM_C2));
1835 seq_printf(m, "TILECTL = 0x%08x\n",
1836 I915_READ(TILECTL));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001837 if (IS_GEN8(dev))
1838 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
1839 I915_READ(GAMTARBMODE));
1840 else
1841 seq_printf(m, "ARB_MODE = 0x%08x\n",
1842 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001843 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1844 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001845 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001846 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001847 mutex_unlock(&dev->struct_mutex);
1848
1849 return 0;
1850}
1851
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001852static int per_file_ctx(int id, void *ptr, void *data)
1853{
Oscar Mateo273497e2014-05-22 14:13:37 +01001854 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001855 struct seq_file *m = data;
1856 struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(ctx);
1857
Oscar Mateof83d6512014-05-22 14:13:38 +01001858 if (i915_gem_context_is_default(ctx))
1859 seq_puts(m, " default context:\n");
1860 else
1861 seq_printf(m, " context %d:\n", ctx->id);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001862 ppgtt->debug_dump(ppgtt, m);
1863
1864 return 0;
1865}
1866
Ben Widawsky77df6772013-11-02 21:07:30 -07001867static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001868{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001869 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001870 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07001871 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1872 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001873
Ben Widawsky77df6772013-11-02 21:07:30 -07001874 if (!ppgtt)
1875 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001876
Ben Widawsky77df6772013-11-02 21:07:30 -07001877 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08001878 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07001879 for_each_ring(ring, dev_priv, unused) {
1880 seq_printf(m, "%s\n", ring->name);
1881 for (i = 0; i < 4; i++) {
1882 u32 offset = 0x270 + i * 8;
1883 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
1884 pdp <<= 32;
1885 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03001886 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07001887 }
1888 }
1889}
1890
1891static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
1892{
1893 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001894 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001895 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07001896 int i;
1897
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001898 if (INTEL_INFO(dev)->gen == 6)
1899 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1900
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001901 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001902 seq_printf(m, "%s\n", ring->name);
1903 if (INTEL_INFO(dev)->gen == 7)
1904 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1905 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1906 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1907 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1908 }
1909 if (dev_priv->mm.aliasing_ppgtt) {
1910 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1911
Damien Lespiau267f0c92013-06-24 22:59:48 +01001912 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001913 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001914
Ben Widawsky87d60b62013-12-06 14:11:29 -08001915 ppgtt->debug_dump(ppgtt, m);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001916 } else
1917 return;
1918
1919 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
1920 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001921
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001922 seq_printf(m, "proc: %s\n",
1923 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001924 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001925 }
1926 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07001927}
1928
1929static int i915_ppgtt_info(struct seq_file *m, void *data)
1930{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001931 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001932 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001933 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001934
1935 int ret = mutex_lock_interruptible(&dev->struct_mutex);
1936 if (ret)
1937 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001938 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07001939
1940 if (INTEL_INFO(dev)->gen >= 8)
1941 gen8_ppgtt_info(m, dev);
1942 else if (INTEL_INFO(dev)->gen >= 6)
1943 gen6_ppgtt_info(m, dev);
1944
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001945 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001946 mutex_unlock(&dev->struct_mutex);
1947
1948 return 0;
1949}
1950
Ben Widawsky63573eb2013-07-04 11:02:07 -07001951static int i915_llc(struct seq_file *m, void *data)
1952{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001953 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07001954 struct drm_device *dev = node->minor->dev;
1955 struct drm_i915_private *dev_priv = dev->dev_private;
1956
1957 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1958 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1959 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1960
1961 return 0;
1962}
1963
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001964static int i915_edp_psr_status(struct seq_file *m, void *data)
1965{
1966 struct drm_info_node *node = m->private;
1967 struct drm_device *dev = node->minor->dev;
1968 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03001969 u32 psrperf = 0;
1970 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001971
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001972 intel_runtime_pm_get(dev_priv);
1973
Rodrigo Vivia031d702013-10-03 16:15:06 -03001974 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
1975 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001976 seq_printf(m, "Enabled: %s\n", yesno(dev_priv->psr.enabled));
1977 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001978
Rodrigo Vivia031d702013-10-03 16:15:06 -03001979 enabled = HAS_PSR(dev) &&
1980 I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001981 seq_printf(m, "HW Enabled & Active bit: %s\n", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001982
Rodrigo Vivia031d702013-10-03 16:15:06 -03001983 if (HAS_PSR(dev))
1984 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
1985 EDP_PSR_PERF_CNT_MASK;
1986 seq_printf(m, "Performance_Counter: %u\n", psrperf);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001987
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001988 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001989 return 0;
1990}
1991
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001992static int i915_sink_crc(struct seq_file *m, void *data)
1993{
1994 struct drm_info_node *node = m->private;
1995 struct drm_device *dev = node->minor->dev;
1996 struct intel_encoder *encoder;
1997 struct intel_connector *connector;
1998 struct intel_dp *intel_dp = NULL;
1999 int ret;
2000 u8 crc[6];
2001
2002 drm_modeset_lock_all(dev);
2003 list_for_each_entry(connector, &dev->mode_config.connector_list,
2004 base.head) {
2005
2006 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2007 continue;
2008
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002009 if (!connector->base.encoder)
2010 continue;
2011
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002012 encoder = to_intel_encoder(connector->base.encoder);
2013 if (encoder->type != INTEL_OUTPUT_EDP)
2014 continue;
2015
2016 intel_dp = enc_to_intel_dp(&encoder->base);
2017
2018 ret = intel_dp_sink_crc(intel_dp, crc);
2019 if (ret)
2020 goto out;
2021
2022 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2023 crc[0], crc[1], crc[2],
2024 crc[3], crc[4], crc[5]);
2025 goto out;
2026 }
2027 ret = -ENODEV;
2028out:
2029 drm_modeset_unlock_all(dev);
2030 return ret;
2031}
2032
Jesse Barnesec013e72013-08-20 10:29:23 +01002033static int i915_energy_uJ(struct seq_file *m, void *data)
2034{
2035 struct drm_info_node *node = m->private;
2036 struct drm_device *dev = node->minor->dev;
2037 struct drm_i915_private *dev_priv = dev->dev_private;
2038 u64 power;
2039 u32 units;
2040
2041 if (INTEL_INFO(dev)->gen < 6)
2042 return -ENODEV;
2043
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002044 intel_runtime_pm_get(dev_priv);
2045
Jesse Barnesec013e72013-08-20 10:29:23 +01002046 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2047 power = (power & 0x1f00) >> 8;
2048 units = 1000000 / (1 << power); /* convert to uJ */
2049 power = I915_READ(MCH_SECP_NRG_STTS);
2050 power *= units;
2051
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002052 intel_runtime_pm_put(dev_priv);
2053
Jesse Barnesec013e72013-08-20 10:29:23 +01002054 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002055
2056 return 0;
2057}
2058
2059static int i915_pc8_status(struct seq_file *m, void *unused)
2060{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002061 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002062 struct drm_device *dev = node->minor->dev;
2063 struct drm_i915_private *dev_priv = dev->dev_private;
2064
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002065 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002066 seq_puts(m, "not supported\n");
2067 return 0;
2068 }
2069
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002070 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002071 seq_printf(m, "IRQs disabled: %s\n",
Paulo Zanoni5d584b22014-03-07 20:08:15 -03002072 yesno(dev_priv->pm.irqs_disabled));
Paulo Zanoni371db662013-08-19 13:18:10 -03002073
Jesse Barnesec013e72013-08-20 10:29:23 +01002074 return 0;
2075}
2076
Imre Deak1da51582013-11-25 17:15:35 +02002077static const char *power_domain_str(enum intel_display_power_domain domain)
2078{
2079 switch (domain) {
2080 case POWER_DOMAIN_PIPE_A:
2081 return "PIPE_A";
2082 case POWER_DOMAIN_PIPE_B:
2083 return "PIPE_B";
2084 case POWER_DOMAIN_PIPE_C:
2085 return "PIPE_C";
2086 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2087 return "PIPE_A_PANEL_FITTER";
2088 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2089 return "PIPE_B_PANEL_FITTER";
2090 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2091 return "PIPE_C_PANEL_FITTER";
2092 case POWER_DOMAIN_TRANSCODER_A:
2093 return "TRANSCODER_A";
2094 case POWER_DOMAIN_TRANSCODER_B:
2095 return "TRANSCODER_B";
2096 case POWER_DOMAIN_TRANSCODER_C:
2097 return "TRANSCODER_C";
2098 case POWER_DOMAIN_TRANSCODER_EDP:
2099 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002100 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2101 return "PORT_DDI_A_2_LANES";
2102 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2103 return "PORT_DDI_A_4_LANES";
2104 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2105 return "PORT_DDI_B_2_LANES";
2106 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2107 return "PORT_DDI_B_4_LANES";
2108 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2109 return "PORT_DDI_C_2_LANES";
2110 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2111 return "PORT_DDI_C_4_LANES";
2112 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2113 return "PORT_DDI_D_2_LANES";
2114 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2115 return "PORT_DDI_D_4_LANES";
2116 case POWER_DOMAIN_PORT_DSI:
2117 return "PORT_DSI";
2118 case POWER_DOMAIN_PORT_CRT:
2119 return "PORT_CRT";
2120 case POWER_DOMAIN_PORT_OTHER:
2121 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002122 case POWER_DOMAIN_VGA:
2123 return "VGA";
2124 case POWER_DOMAIN_AUDIO:
2125 return "AUDIO";
2126 case POWER_DOMAIN_INIT:
2127 return "INIT";
2128 default:
2129 WARN_ON(1);
2130 return "?";
2131 }
2132}
2133
2134static int i915_power_domain_info(struct seq_file *m, void *unused)
2135{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002136 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002137 struct drm_device *dev = node->minor->dev;
2138 struct drm_i915_private *dev_priv = dev->dev_private;
2139 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2140 int i;
2141
2142 mutex_lock(&power_domains->lock);
2143
2144 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2145 for (i = 0; i < power_domains->power_well_count; i++) {
2146 struct i915_power_well *power_well;
2147 enum intel_display_power_domain power_domain;
2148
2149 power_well = &power_domains->power_wells[i];
2150 seq_printf(m, "%-25s %d\n", power_well->name,
2151 power_well->count);
2152
2153 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2154 power_domain++) {
2155 if (!(BIT(power_domain) & power_well->domains))
2156 continue;
2157
2158 seq_printf(m, " %-23s %d\n",
2159 power_domain_str(power_domain),
2160 power_domains->domain_use_count[power_domain]);
2161 }
2162 }
2163
2164 mutex_unlock(&power_domains->lock);
2165
2166 return 0;
2167}
2168
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002169static void intel_seq_print_mode(struct seq_file *m, int tabs,
2170 struct drm_display_mode *mode)
2171{
2172 int i;
2173
2174 for (i = 0; i < tabs; i++)
2175 seq_putc(m, '\t');
2176
2177 seq_printf(m, "id %d:\"%s\" freq %d clock %d hdisp %d hss %d hse %d htot %d vdisp %d vss %d vse %d vtot %d type 0x%x flags 0x%x\n",
2178 mode->base.id, mode->name,
2179 mode->vrefresh, mode->clock,
2180 mode->hdisplay, mode->hsync_start,
2181 mode->hsync_end, mode->htotal,
2182 mode->vdisplay, mode->vsync_start,
2183 mode->vsync_end, mode->vtotal,
2184 mode->type, mode->flags);
2185}
2186
2187static void intel_encoder_info(struct seq_file *m,
2188 struct intel_crtc *intel_crtc,
2189 struct intel_encoder *intel_encoder)
2190{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002191 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002192 struct drm_device *dev = node->minor->dev;
2193 struct drm_crtc *crtc = &intel_crtc->base;
2194 struct intel_connector *intel_connector;
2195 struct drm_encoder *encoder;
2196
2197 encoder = &intel_encoder->base;
2198 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a02014-06-03 14:56:21 +03002199 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002200 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2201 struct drm_connector *connector = &intel_connector->base;
2202 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2203 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002204 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002205 drm_get_connector_status_name(connector->status));
2206 if (connector->status == connector_status_connected) {
2207 struct drm_display_mode *mode = &crtc->mode;
2208 seq_printf(m, ", mode:\n");
2209 intel_seq_print_mode(m, 2, mode);
2210 } else {
2211 seq_putc(m, '\n');
2212 }
2213 }
2214}
2215
2216static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2217{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002218 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002219 struct drm_device *dev = node->minor->dev;
2220 struct drm_crtc *crtc = &intel_crtc->base;
2221 struct intel_encoder *intel_encoder;
2222
2223 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Matt Roperf4510a22014-04-01 15:22:40 -07002224 crtc->primary->fb->base.id, crtc->x, crtc->y,
2225 crtc->primary->fb->width, crtc->primary->fb->height);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002226 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2227 intel_encoder_info(m, intel_crtc, intel_encoder);
2228}
2229
2230static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2231{
2232 struct drm_display_mode *mode = panel->fixed_mode;
2233
2234 seq_printf(m, "\tfixed mode:\n");
2235 intel_seq_print_mode(m, 2, mode);
2236}
2237
2238static void intel_dp_info(struct seq_file *m,
2239 struct intel_connector *intel_connector)
2240{
2241 struct intel_encoder *intel_encoder = intel_connector->encoder;
2242 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2243
2244 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2245 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2246 "no");
2247 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2248 intel_panel_info(m, &intel_connector->panel);
2249}
2250
2251static void intel_hdmi_info(struct seq_file *m,
2252 struct intel_connector *intel_connector)
2253{
2254 struct intel_encoder *intel_encoder = intel_connector->encoder;
2255 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2256
2257 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2258 "no");
2259}
2260
2261static void intel_lvds_info(struct seq_file *m,
2262 struct intel_connector *intel_connector)
2263{
2264 intel_panel_info(m, &intel_connector->panel);
2265}
2266
2267static void intel_connector_info(struct seq_file *m,
2268 struct drm_connector *connector)
2269{
2270 struct intel_connector *intel_connector = to_intel_connector(connector);
2271 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002272 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002273
2274 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002275 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002276 drm_get_connector_status_name(connector->status));
2277 if (connector->status == connector_status_connected) {
2278 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2279 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2280 connector->display_info.width_mm,
2281 connector->display_info.height_mm);
2282 seq_printf(m, "\tsubpixel order: %s\n",
2283 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2284 seq_printf(m, "\tCEA rev: %d\n",
2285 connector->display_info.cea_rev);
2286 }
2287 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2288 intel_encoder->type == INTEL_OUTPUT_EDP)
2289 intel_dp_info(m, intel_connector);
2290 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2291 intel_hdmi_info(m, intel_connector);
2292 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2293 intel_lvds_info(m, intel_connector);
2294
Jesse Barnesf103fc72014-02-20 12:39:57 -08002295 seq_printf(m, "\tmodes:\n");
2296 list_for_each_entry(mode, &connector->modes, head)
2297 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002298}
2299
Chris Wilson065f2ec2014-03-12 09:13:13 +00002300static bool cursor_active(struct drm_device *dev, int pipe)
2301{
2302 struct drm_i915_private *dev_priv = dev->dev_private;
2303 u32 state;
2304
2305 if (IS_845G(dev) || IS_I865G(dev))
2306 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002307 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002308 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002309
2310 return state;
2311}
2312
2313static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2314{
2315 struct drm_i915_private *dev_priv = dev->dev_private;
2316 u32 pos;
2317
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002318 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002319
2320 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2321 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2322 *x = -*x;
2323
2324 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2325 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2326 *y = -*y;
2327
2328 return cursor_active(dev, pipe);
2329}
2330
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002331static int i915_display_info(struct seq_file *m, void *unused)
2332{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002333 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002334 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002335 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002336 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002337 struct drm_connector *connector;
2338
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002339 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002340 drm_modeset_lock_all(dev);
2341 seq_printf(m, "CRTC info\n");
2342 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002343 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002344 bool active;
2345 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002346
2347 seq_printf(m, "CRTC %d: pipe: %c, active: %s\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002348 crtc->base.base.id, pipe_name(crtc->pipe),
2349 yesno(crtc->active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002350 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002351 intel_crtc_info(m, crtc);
2352
Paulo Zanonia23dc652014-04-01 14:55:11 -03002353 active = cursor_position(dev, crtc->pipe, &x, &y);
2354 seq_printf(m, "\tcursor visible? %s, position (%d, %d), addr 0x%08x, active? %s\n",
Chris Wilson4b0e3332014-05-30 16:35:26 +03002355 yesno(crtc->cursor_base),
Paulo Zanonia23dc652014-04-01 14:55:11 -03002356 x, y, crtc->cursor_addr,
2357 yesno(active));
2358 }
Daniel Vettercace8412014-05-22 17:56:31 +02002359
2360 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2361 yesno(!crtc->cpu_fifo_underrun_disabled),
2362 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002363 }
2364
2365 seq_printf(m, "\n");
2366 seq_printf(m, "Connector info\n");
2367 seq_printf(m, "--------------\n");
2368 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2369 intel_connector_info(m, connector);
2370 }
2371 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002372 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002373
2374 return 0;
2375}
2376
Damien Lespiau07144422013-10-15 18:55:40 +01002377struct pipe_crc_info {
2378 const char *name;
2379 struct drm_device *dev;
2380 enum pipe pipe;
2381};
2382
2383static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002384{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002385 struct pipe_crc_info *info = inode->i_private;
2386 struct drm_i915_private *dev_priv = info->dev->dev_private;
2387 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2388
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002389 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2390 return -ENODEV;
2391
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002392 spin_lock_irq(&pipe_crc->lock);
2393
2394 if (pipe_crc->opened) {
2395 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002396 return -EBUSY; /* already open */
2397 }
2398
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002399 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002400 filep->private_data = inode->i_private;
2401
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002402 spin_unlock_irq(&pipe_crc->lock);
2403
Damien Lespiau07144422013-10-15 18:55:40 +01002404 return 0;
2405}
2406
2407static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2408{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002409 struct pipe_crc_info *info = inode->i_private;
2410 struct drm_i915_private *dev_priv = info->dev->dev_private;
2411 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2412
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002413 spin_lock_irq(&pipe_crc->lock);
2414 pipe_crc->opened = false;
2415 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002416
Damien Lespiau07144422013-10-15 18:55:40 +01002417 return 0;
2418}
2419
2420/* (6 fields, 8 chars each, space separated (5) + '\n') */
2421#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2422/* account for \'0' */
2423#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2424
2425static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2426{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002427 assert_spin_locked(&pipe_crc->lock);
2428 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2429 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002430}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002431
Damien Lespiau07144422013-10-15 18:55:40 +01002432static ssize_t
2433i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2434 loff_t *pos)
2435{
2436 struct pipe_crc_info *info = filep->private_data;
2437 struct drm_device *dev = info->dev;
2438 struct drm_i915_private *dev_priv = dev->dev_private;
2439 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2440 char buf[PIPE_CRC_BUFFER_LEN];
2441 int head, tail, n_entries, n;
2442 ssize_t bytes_read;
2443
2444 /*
2445 * Don't allow user space to provide buffers not big enough to hold
2446 * a line of data.
2447 */
2448 if (count < PIPE_CRC_LINE_LEN)
2449 return -EINVAL;
2450
2451 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2452 return 0;
2453
2454 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002455 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002456 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002457 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002458
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002459 if (filep->f_flags & O_NONBLOCK) {
2460 spin_unlock_irq(&pipe_crc->lock);
2461 return -EAGAIN;
2462 }
2463
2464 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2465 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2466 if (ret) {
2467 spin_unlock_irq(&pipe_crc->lock);
2468 return ret;
2469 }
Damien Lespiau07144422013-10-15 18:55:40 +01002470 }
2471
2472 /* We now have one or more entries to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002473 head = pipe_crc->head;
2474 tail = pipe_crc->tail;
Damien Lespiau07144422013-10-15 18:55:40 +01002475 n_entries = min((size_t)CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR),
2476 count / PIPE_CRC_LINE_LEN);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002477 spin_unlock_irq(&pipe_crc->lock);
2478
Damien Lespiau07144422013-10-15 18:55:40 +01002479 bytes_read = 0;
2480 n = 0;
2481 do {
2482 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
2483 int ret;
2484
2485 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2486 "%8u %8x %8x %8x %8x %8x\n",
2487 entry->frame, entry->crc[0],
2488 entry->crc[1], entry->crc[2],
2489 entry->crc[3], entry->crc[4]);
2490
2491 ret = copy_to_user(user_buf + n * PIPE_CRC_LINE_LEN,
2492 buf, PIPE_CRC_LINE_LEN);
2493 if (ret == PIPE_CRC_LINE_LEN)
2494 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002495
2496 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2497 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiau07144422013-10-15 18:55:40 +01002498 n++;
2499 } while (--n_entries);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002500
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002501 spin_lock_irq(&pipe_crc->lock);
2502 pipe_crc->tail = tail;
2503 spin_unlock_irq(&pipe_crc->lock);
2504
Damien Lespiau07144422013-10-15 18:55:40 +01002505 return bytes_read;
2506}
2507
2508static const struct file_operations i915_pipe_crc_fops = {
2509 .owner = THIS_MODULE,
2510 .open = i915_pipe_crc_open,
2511 .read = i915_pipe_crc_read,
2512 .release = i915_pipe_crc_release,
2513};
2514
2515static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2516 {
2517 .name = "i915_pipe_A_crc",
2518 .pipe = PIPE_A,
2519 },
2520 {
2521 .name = "i915_pipe_B_crc",
2522 .pipe = PIPE_B,
2523 },
2524 {
2525 .name = "i915_pipe_C_crc",
2526 .pipe = PIPE_C,
2527 },
2528};
2529
2530static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2531 enum pipe pipe)
2532{
2533 struct drm_device *dev = minor->dev;
2534 struct dentry *ent;
2535 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2536
2537 info->dev = dev;
2538 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2539 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08002540 if (!ent)
2541 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01002542
2543 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002544}
2545
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002546static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002547 "none",
2548 "plane1",
2549 "plane2",
2550 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002551 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002552 "TV",
2553 "DP-B",
2554 "DP-C",
2555 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002556 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002557};
2558
2559static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2560{
2561 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2562 return pipe_crc_sources[source];
2563}
2564
Damien Lespiaubd9db022013-10-15 18:55:36 +01002565static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002566{
2567 struct drm_device *dev = m->private;
2568 struct drm_i915_private *dev_priv = dev->dev_private;
2569 int i;
2570
2571 for (i = 0; i < I915_MAX_PIPES; i++)
2572 seq_printf(m, "%c %s\n", pipe_name(i),
2573 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2574
2575 return 0;
2576}
2577
Damien Lespiaubd9db022013-10-15 18:55:36 +01002578static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02002579{
2580 struct drm_device *dev = inode->i_private;
2581
Damien Lespiaubd9db022013-10-15 18:55:36 +01002582 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02002583}
2584
Daniel Vetter46a19182013-11-01 10:50:20 +01002585static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02002586 uint32_t *val)
2587{
Daniel Vetter46a19182013-11-01 10:50:20 +01002588 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2589 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2590
2591 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02002592 case INTEL_PIPE_CRC_SOURCE_PIPE:
2593 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
2594 break;
2595 case INTEL_PIPE_CRC_SOURCE_NONE:
2596 *val = 0;
2597 break;
2598 default:
2599 return -EINVAL;
2600 }
2601
2602 return 0;
2603}
2604
Daniel Vetter46a19182013-11-01 10:50:20 +01002605static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
2606 enum intel_pipe_crc_source *source)
2607{
2608 struct intel_encoder *encoder;
2609 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01002610 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01002611 int ret = 0;
2612
2613 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2614
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002615 drm_modeset_lock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002616 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
2617 base.head) {
2618 if (!encoder->base.crtc)
2619 continue;
2620
2621 crtc = to_intel_crtc(encoder->base.crtc);
2622
2623 if (crtc->pipe != pipe)
2624 continue;
2625
2626 switch (encoder->type) {
2627 case INTEL_OUTPUT_TVOUT:
2628 *source = INTEL_PIPE_CRC_SOURCE_TV;
2629 break;
2630 case INTEL_OUTPUT_DISPLAYPORT:
2631 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01002632 dig_port = enc_to_dig_port(&encoder->base);
2633 switch (dig_port->port) {
2634 case PORT_B:
2635 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
2636 break;
2637 case PORT_C:
2638 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
2639 break;
2640 case PORT_D:
2641 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
2642 break;
2643 default:
2644 WARN(1, "nonexisting DP port %c\n",
2645 port_name(dig_port->port));
2646 break;
2647 }
Daniel Vetter46a19182013-11-01 10:50:20 +01002648 break;
2649 }
2650 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002651 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002652
2653 return ret;
2654}
2655
2656static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
2657 enum pipe pipe,
2658 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02002659 uint32_t *val)
2660{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002661 struct drm_i915_private *dev_priv = dev->dev_private;
2662 bool need_stable_symbols = false;
2663
Daniel Vetter46a19182013-11-01 10:50:20 +01002664 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2665 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2666 if (ret)
2667 return ret;
2668 }
2669
2670 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02002671 case INTEL_PIPE_CRC_SOURCE_PIPE:
2672 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
2673 break;
2674 case INTEL_PIPE_CRC_SOURCE_DP_B:
2675 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002676 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002677 break;
2678 case INTEL_PIPE_CRC_SOURCE_DP_C:
2679 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002680 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002681 break;
2682 case INTEL_PIPE_CRC_SOURCE_NONE:
2683 *val = 0;
2684 break;
2685 default:
2686 return -EINVAL;
2687 }
2688
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002689 /*
2690 * When the pipe CRC tap point is after the transcoders we need
2691 * to tweak symbol-level features to produce a deterministic series of
2692 * symbols for a given frame. We need to reset those features only once
2693 * a frame (instead of every nth symbol):
2694 * - DC-balance: used to ensure a better clock recovery from the data
2695 * link (SDVO)
2696 * - DisplayPort scrambling: used for EMI reduction
2697 */
2698 if (need_stable_symbols) {
2699 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2700
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002701 tmp |= DC_BALANCE_RESET_VLV;
2702 if (pipe == PIPE_A)
2703 tmp |= PIPE_A_SCRAMBLE_RESET;
2704 else
2705 tmp |= PIPE_B_SCRAMBLE_RESET;
2706
2707 I915_WRITE(PORT_DFT2_G4X, tmp);
2708 }
2709
Daniel Vetter7ac01292013-10-18 16:37:06 +02002710 return 0;
2711}
2712
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002713static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01002714 enum pipe pipe,
2715 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002716 uint32_t *val)
2717{
Daniel Vetter84093602013-11-01 10:50:21 +01002718 struct drm_i915_private *dev_priv = dev->dev_private;
2719 bool need_stable_symbols = false;
2720
Daniel Vetter46a19182013-11-01 10:50:20 +01002721 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2722 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2723 if (ret)
2724 return ret;
2725 }
2726
2727 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002728 case INTEL_PIPE_CRC_SOURCE_PIPE:
2729 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
2730 break;
2731 case INTEL_PIPE_CRC_SOURCE_TV:
2732 if (!SUPPORTS_TV(dev))
2733 return -EINVAL;
2734 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
2735 break;
2736 case INTEL_PIPE_CRC_SOURCE_DP_B:
2737 if (!IS_G4X(dev))
2738 return -EINVAL;
2739 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002740 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002741 break;
2742 case INTEL_PIPE_CRC_SOURCE_DP_C:
2743 if (!IS_G4X(dev))
2744 return -EINVAL;
2745 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002746 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002747 break;
2748 case INTEL_PIPE_CRC_SOURCE_DP_D:
2749 if (!IS_G4X(dev))
2750 return -EINVAL;
2751 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002752 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002753 break;
2754 case INTEL_PIPE_CRC_SOURCE_NONE:
2755 *val = 0;
2756 break;
2757 default:
2758 return -EINVAL;
2759 }
2760
Daniel Vetter84093602013-11-01 10:50:21 +01002761 /*
2762 * When the pipe CRC tap point is after the transcoders we need
2763 * to tweak symbol-level features to produce a deterministic series of
2764 * symbols for a given frame. We need to reset those features only once
2765 * a frame (instead of every nth symbol):
2766 * - DC-balance: used to ensure a better clock recovery from the data
2767 * link (SDVO)
2768 * - DisplayPort scrambling: used for EMI reduction
2769 */
2770 if (need_stable_symbols) {
2771 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2772
2773 WARN_ON(!IS_G4X(dev));
2774
2775 I915_WRITE(PORT_DFT_I9XX,
2776 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
2777
2778 if (pipe == PIPE_A)
2779 tmp |= PIPE_A_SCRAMBLE_RESET;
2780 else
2781 tmp |= PIPE_B_SCRAMBLE_RESET;
2782
2783 I915_WRITE(PORT_DFT2_G4X, tmp);
2784 }
2785
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002786 return 0;
2787}
2788
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002789static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
2790 enum pipe pipe)
2791{
2792 struct drm_i915_private *dev_priv = dev->dev_private;
2793 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2794
2795 if (pipe == PIPE_A)
2796 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2797 else
2798 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2799 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
2800 tmp &= ~DC_BALANCE_RESET_VLV;
2801 I915_WRITE(PORT_DFT2_G4X, tmp);
2802
2803}
2804
Daniel Vetter84093602013-11-01 10:50:21 +01002805static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
2806 enum pipe pipe)
2807{
2808 struct drm_i915_private *dev_priv = dev->dev_private;
2809 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2810
2811 if (pipe == PIPE_A)
2812 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2813 else
2814 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2815 I915_WRITE(PORT_DFT2_G4X, tmp);
2816
2817 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
2818 I915_WRITE(PORT_DFT_I9XX,
2819 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
2820 }
2821}
2822
Daniel Vetter46a19182013-11-01 10:50:20 +01002823static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002824 uint32_t *val)
2825{
Daniel Vetter46a19182013-11-01 10:50:20 +01002826 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2827 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2828
2829 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002830 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2831 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
2832 break;
2833 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2834 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
2835 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002836 case INTEL_PIPE_CRC_SOURCE_PIPE:
2837 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
2838 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002839 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002840 *val = 0;
2841 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002842 default:
2843 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002844 }
2845
2846 return 0;
2847}
2848
Daniel Vetter46a19182013-11-01 10:50:20 +01002849static int ivb_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002850 uint32_t *val)
2851{
Daniel Vetter46a19182013-11-01 10:50:20 +01002852 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2853 *source = INTEL_PIPE_CRC_SOURCE_PF;
2854
2855 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002856 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2857 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
2858 break;
2859 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2860 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
2861 break;
2862 case INTEL_PIPE_CRC_SOURCE_PF:
2863 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
2864 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002865 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002866 *val = 0;
2867 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002868 default:
2869 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002870 }
2871
2872 return 0;
2873}
2874
Daniel Vetter926321d2013-10-16 13:30:34 +02002875static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
2876 enum intel_pipe_crc_source source)
2877{
2878 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01002879 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Borislav Petkov432f3342013-11-21 16:49:46 +01002880 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002881 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02002882
Damien Lespiaucc3da172013-10-15 18:55:31 +01002883 if (pipe_crc->source == source)
2884 return 0;
2885
Damien Lespiauae676fc2013-10-15 18:55:32 +01002886 /* forbid changing the source without going back to 'none' */
2887 if (pipe_crc->source && source)
2888 return -EINVAL;
2889
Daniel Vetter52f843f2013-10-21 17:26:38 +02002890 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002891 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02002892 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01002893 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02002894 else if (IS_VALLEYVIEW(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002895 ret = vlv_pipe_crc_ctl_reg(dev,pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002896 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002897 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002898 else
Daniel Vetter46a19182013-11-01 10:50:20 +01002899 ret = ivb_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002900
2901 if (ret != 0)
2902 return ret;
2903
Damien Lespiau4b584362013-10-15 18:55:33 +01002904 /* none -> real source transition */
2905 if (source) {
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01002906 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
2907 pipe_name(pipe), pipe_crc_source_name(source));
2908
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002909 pipe_crc->entries = kzalloc(sizeof(*pipe_crc->entries) *
2910 INTEL_PIPE_CRC_ENTRIES_NR,
2911 GFP_KERNEL);
2912 if (!pipe_crc->entries)
2913 return -ENOMEM;
2914
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002915 spin_lock_irq(&pipe_crc->lock);
2916 pipe_crc->head = 0;
2917 pipe_crc->tail = 0;
2918 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01002919 }
2920
Damien Lespiaucc3da172013-10-15 18:55:31 +01002921 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02002922
Daniel Vetter926321d2013-10-16 13:30:34 +02002923 I915_WRITE(PIPE_CRC_CTL(pipe), val);
2924 POSTING_READ(PIPE_CRC_CTL(pipe));
2925
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002926 /* real source -> none transition */
2927 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002928 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02002929 struct intel_crtc *crtc =
2930 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002931
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01002932 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
2933 pipe_name(pipe));
2934
Daniel Vettera33d7102014-06-06 08:22:08 +02002935 drm_modeset_lock(&crtc->base.mutex, NULL);
2936 if (crtc->active)
2937 intel_wait_for_vblank(dev, pipe);
2938 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02002939
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002940 spin_lock_irq(&pipe_crc->lock);
2941 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002942 pipe_crc->entries = NULL;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002943 spin_unlock_irq(&pipe_crc->lock);
2944
2945 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01002946
2947 if (IS_G4X(dev))
2948 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002949 else if (IS_VALLEYVIEW(dev))
2950 vlv_undo_pipe_scramble_reset(dev, pipe);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002951 }
2952
Daniel Vetter926321d2013-10-16 13:30:34 +02002953 return 0;
2954}
2955
2956/*
2957 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01002958 * command: wsp* object wsp+ name wsp+ source wsp*
2959 * object: 'pipe'
2960 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02002961 * source: (none | plane1 | plane2 | pf)
2962 * wsp: (#0x20 | #0x9 | #0xA)+
2963 *
2964 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01002965 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
2966 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02002967 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01002968static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02002969{
2970 int n_words = 0;
2971
2972 while (*buf) {
2973 char *end;
2974
2975 /* skip leading white space */
2976 buf = skip_spaces(buf);
2977 if (!*buf)
2978 break; /* end of buffer */
2979
2980 /* find end of word */
2981 for (end = buf; *end && !isspace(*end); end++)
2982 ;
2983
2984 if (n_words == max_words) {
2985 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
2986 max_words);
2987 return -EINVAL; /* ran out of words[] before bytes */
2988 }
2989
2990 if (*end)
2991 *end++ = '\0';
2992 words[n_words++] = buf;
2993 buf = end;
2994 }
2995
2996 return n_words;
2997}
2998
Damien Lespiaub94dec82013-10-15 18:55:35 +01002999enum intel_pipe_crc_object {
3000 PIPE_CRC_OBJECT_PIPE,
3001};
3002
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003003static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003004 "pipe",
3005};
3006
3007static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003008display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003009{
3010 int i;
3011
3012 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3013 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003014 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003015 return 0;
3016 }
3017
3018 return -EINVAL;
3019}
3020
Damien Lespiaubd9db022013-10-15 18:55:36 +01003021static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003022{
3023 const char name = buf[0];
3024
3025 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3026 return -EINVAL;
3027
3028 *pipe = name - 'A';
3029
3030 return 0;
3031}
3032
3033static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003034display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003035{
3036 int i;
3037
3038 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3039 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003040 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003041 return 0;
3042 }
3043
3044 return -EINVAL;
3045}
3046
Damien Lespiaubd9db022013-10-15 18:55:36 +01003047static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003048{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003049#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003050 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003051 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003052 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003053 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003054 enum intel_pipe_crc_source source;
3055
Damien Lespiaubd9db022013-10-15 18:55:36 +01003056 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003057 if (n_words != N_WORDS) {
3058 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3059 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003060 return -EINVAL;
3061 }
3062
Damien Lespiaubd9db022013-10-15 18:55:36 +01003063 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003064 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003065 return -EINVAL;
3066 }
3067
Damien Lespiaubd9db022013-10-15 18:55:36 +01003068 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003069 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3070 return -EINVAL;
3071 }
3072
Damien Lespiaubd9db022013-10-15 18:55:36 +01003073 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003074 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003075 return -EINVAL;
3076 }
3077
3078 return pipe_crc_set_source(dev, pipe, source);
3079}
3080
Damien Lespiaubd9db022013-10-15 18:55:36 +01003081static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3082 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003083{
3084 struct seq_file *m = file->private_data;
3085 struct drm_device *dev = m->private;
3086 char *tmpbuf;
3087 int ret;
3088
3089 if (len == 0)
3090 return 0;
3091
3092 if (len > PAGE_SIZE - 1) {
3093 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3094 PAGE_SIZE);
3095 return -E2BIG;
3096 }
3097
3098 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3099 if (!tmpbuf)
3100 return -ENOMEM;
3101
3102 if (copy_from_user(tmpbuf, ubuf, len)) {
3103 ret = -EFAULT;
3104 goto out;
3105 }
3106 tmpbuf[len] = '\0';
3107
Damien Lespiaubd9db022013-10-15 18:55:36 +01003108 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003109
3110out:
3111 kfree(tmpbuf);
3112 if (ret < 0)
3113 return ret;
3114
3115 *offp += len;
3116 return len;
3117}
3118
Damien Lespiaubd9db022013-10-15 18:55:36 +01003119static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003120 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003121 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003122 .read = seq_read,
3123 .llseek = seq_lseek,
3124 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003125 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003126};
3127
Ville Syrjälä369a1342014-01-22 14:36:08 +02003128static void wm_latency_show(struct seq_file *m, const uint16_t wm[5])
3129{
3130 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003131 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003132 int level;
3133
3134 drm_modeset_lock_all(dev);
3135
3136 for (level = 0; level < num_levels; level++) {
3137 unsigned int latency = wm[level];
3138
3139 /* WM1+ latency values in 0.5us units */
3140 if (level > 0)
3141 latency *= 5;
3142
3143 seq_printf(m, "WM%d %u (%u.%u usec)\n",
3144 level, wm[level],
3145 latency / 10, latency % 10);
3146 }
3147
3148 drm_modeset_unlock_all(dev);
3149}
3150
3151static int pri_wm_latency_show(struct seq_file *m, void *data)
3152{
3153 struct drm_device *dev = m->private;
3154
3155 wm_latency_show(m, to_i915(dev)->wm.pri_latency);
3156
3157 return 0;
3158}
3159
3160static int spr_wm_latency_show(struct seq_file *m, void *data)
3161{
3162 struct drm_device *dev = m->private;
3163
3164 wm_latency_show(m, to_i915(dev)->wm.spr_latency);
3165
3166 return 0;
3167}
3168
3169static int cur_wm_latency_show(struct seq_file *m, void *data)
3170{
3171 struct drm_device *dev = m->private;
3172
3173 wm_latency_show(m, to_i915(dev)->wm.cur_latency);
3174
3175 return 0;
3176}
3177
3178static int pri_wm_latency_open(struct inode *inode, struct file *file)
3179{
3180 struct drm_device *dev = inode->i_private;
3181
3182 if (!HAS_PCH_SPLIT(dev))
3183 return -ENODEV;
3184
3185 return single_open(file, pri_wm_latency_show, dev);
3186}
3187
3188static int spr_wm_latency_open(struct inode *inode, struct file *file)
3189{
3190 struct drm_device *dev = inode->i_private;
3191
3192 if (!HAS_PCH_SPLIT(dev))
3193 return -ENODEV;
3194
3195 return single_open(file, spr_wm_latency_show, dev);
3196}
3197
3198static int cur_wm_latency_open(struct inode *inode, struct file *file)
3199{
3200 struct drm_device *dev = inode->i_private;
3201
3202 if (!HAS_PCH_SPLIT(dev))
3203 return -ENODEV;
3204
3205 return single_open(file, cur_wm_latency_show, dev);
3206}
3207
3208static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
3209 size_t len, loff_t *offp, uint16_t wm[5])
3210{
3211 struct seq_file *m = file->private_data;
3212 struct drm_device *dev = m->private;
3213 uint16_t new[5] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003214 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003215 int level;
3216 int ret;
3217 char tmp[32];
3218
3219 if (len >= sizeof(tmp))
3220 return -EINVAL;
3221
3222 if (copy_from_user(tmp, ubuf, len))
3223 return -EFAULT;
3224
3225 tmp[len] = '\0';
3226
3227 ret = sscanf(tmp, "%hu %hu %hu %hu %hu", &new[0], &new[1], &new[2], &new[3], &new[4]);
3228 if (ret != num_levels)
3229 return -EINVAL;
3230
3231 drm_modeset_lock_all(dev);
3232
3233 for (level = 0; level < num_levels; level++)
3234 wm[level] = new[level];
3235
3236 drm_modeset_unlock_all(dev);
3237
3238 return len;
3239}
3240
3241
3242static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3243 size_t len, loff_t *offp)
3244{
3245 struct seq_file *m = file->private_data;
3246 struct drm_device *dev = m->private;
3247
3248 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.pri_latency);
3249}
3250
3251static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3252 size_t len, loff_t *offp)
3253{
3254 struct seq_file *m = file->private_data;
3255 struct drm_device *dev = m->private;
3256
3257 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.spr_latency);
3258}
3259
3260static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3261 size_t len, loff_t *offp)
3262{
3263 struct seq_file *m = file->private_data;
3264 struct drm_device *dev = m->private;
3265
3266 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.cur_latency);
3267}
3268
3269static const struct file_operations i915_pri_wm_latency_fops = {
3270 .owner = THIS_MODULE,
3271 .open = pri_wm_latency_open,
3272 .read = seq_read,
3273 .llseek = seq_lseek,
3274 .release = single_release,
3275 .write = pri_wm_latency_write
3276};
3277
3278static const struct file_operations i915_spr_wm_latency_fops = {
3279 .owner = THIS_MODULE,
3280 .open = spr_wm_latency_open,
3281 .read = seq_read,
3282 .llseek = seq_lseek,
3283 .release = single_release,
3284 .write = spr_wm_latency_write
3285};
3286
3287static const struct file_operations i915_cur_wm_latency_fops = {
3288 .owner = THIS_MODULE,
3289 .open = cur_wm_latency_open,
3290 .read = seq_read,
3291 .llseek = seq_lseek,
3292 .release = single_release,
3293 .write = cur_wm_latency_write
3294};
3295
Kees Cook647416f2013-03-10 14:10:06 -07003296static int
3297i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003298{
Kees Cook647416f2013-03-10 14:10:06 -07003299 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003300 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003301
Kees Cook647416f2013-03-10 14:10:06 -07003302 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003303
Kees Cook647416f2013-03-10 14:10:06 -07003304 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003305}
3306
Kees Cook647416f2013-03-10 14:10:06 -07003307static int
3308i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003309{
Kees Cook647416f2013-03-10 14:10:06 -07003310 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003311 struct drm_i915_private *dev_priv = dev->dev_private;
3312
3313 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003314
Mika Kuoppala58174462014-02-25 17:11:26 +02003315 i915_handle_error(dev, val,
3316 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003317
3318 intel_runtime_pm_put(dev_priv);
3319
Kees Cook647416f2013-03-10 14:10:06 -07003320 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003321}
3322
Kees Cook647416f2013-03-10 14:10:06 -07003323DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3324 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003325 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003326
Kees Cook647416f2013-03-10 14:10:06 -07003327static int
3328i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003329{
Kees Cook647416f2013-03-10 14:10:06 -07003330 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003331 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003332
Kees Cook647416f2013-03-10 14:10:06 -07003333 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003334
Kees Cook647416f2013-03-10 14:10:06 -07003335 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003336}
3337
Kees Cook647416f2013-03-10 14:10:06 -07003338static int
3339i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003340{
Kees Cook647416f2013-03-10 14:10:06 -07003341 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003342 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003343 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003344
Kees Cook647416f2013-03-10 14:10:06 -07003345 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003346
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003347 ret = mutex_lock_interruptible(&dev->struct_mutex);
3348 if (ret)
3349 return ret;
3350
Daniel Vetter99584db2012-11-14 17:14:04 +01003351 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003352 mutex_unlock(&dev->struct_mutex);
3353
Kees Cook647416f2013-03-10 14:10:06 -07003354 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003355}
3356
Kees Cook647416f2013-03-10 14:10:06 -07003357DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
3358 i915_ring_stop_get, i915_ring_stop_set,
3359 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02003360
Chris Wilson094f9a52013-09-25 17:34:55 +01003361static int
3362i915_ring_missed_irq_get(void *data, u64 *val)
3363{
3364 struct drm_device *dev = data;
3365 struct drm_i915_private *dev_priv = dev->dev_private;
3366
3367 *val = dev_priv->gpu_error.missed_irq_rings;
3368 return 0;
3369}
3370
3371static int
3372i915_ring_missed_irq_set(void *data, u64 val)
3373{
3374 struct drm_device *dev = data;
3375 struct drm_i915_private *dev_priv = dev->dev_private;
3376 int ret;
3377
3378 /* Lock against concurrent debugfs callers */
3379 ret = mutex_lock_interruptible(&dev->struct_mutex);
3380 if (ret)
3381 return ret;
3382 dev_priv->gpu_error.missed_irq_rings = val;
3383 mutex_unlock(&dev->struct_mutex);
3384
3385 return 0;
3386}
3387
3388DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3389 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3390 "0x%08llx\n");
3391
3392static int
3393i915_ring_test_irq_get(void *data, u64 *val)
3394{
3395 struct drm_device *dev = data;
3396 struct drm_i915_private *dev_priv = dev->dev_private;
3397
3398 *val = dev_priv->gpu_error.test_irq_rings;
3399
3400 return 0;
3401}
3402
3403static int
3404i915_ring_test_irq_set(void *data, u64 val)
3405{
3406 struct drm_device *dev = data;
3407 struct drm_i915_private *dev_priv = dev->dev_private;
3408 int ret;
3409
3410 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
3411
3412 /* Lock against concurrent debugfs callers */
3413 ret = mutex_lock_interruptible(&dev->struct_mutex);
3414 if (ret)
3415 return ret;
3416
3417 dev_priv->gpu_error.test_irq_rings = val;
3418 mutex_unlock(&dev->struct_mutex);
3419
3420 return 0;
3421}
3422
3423DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
3424 i915_ring_test_irq_get, i915_ring_test_irq_set,
3425 "0x%08llx\n");
3426
Chris Wilsondd624af2013-01-15 12:39:35 +00003427#define DROP_UNBOUND 0x1
3428#define DROP_BOUND 0x2
3429#define DROP_RETIRE 0x4
3430#define DROP_ACTIVE 0x8
3431#define DROP_ALL (DROP_UNBOUND | \
3432 DROP_BOUND | \
3433 DROP_RETIRE | \
3434 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07003435static int
3436i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003437{
Kees Cook647416f2013-03-10 14:10:06 -07003438 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00003439
Kees Cook647416f2013-03-10 14:10:06 -07003440 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00003441}
3442
Kees Cook647416f2013-03-10 14:10:06 -07003443static int
3444i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003445{
Kees Cook647416f2013-03-10 14:10:06 -07003446 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00003447 struct drm_i915_private *dev_priv = dev->dev_private;
3448 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07003449 struct i915_address_space *vm;
3450 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07003451 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003452
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08003453 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00003454
3455 /* No need to check and wait for gpu resets, only libdrm auto-restarts
3456 * on ioctls on -EAGAIN. */
3457 ret = mutex_lock_interruptible(&dev->struct_mutex);
3458 if (ret)
3459 return ret;
3460
3461 if (val & DROP_ACTIVE) {
3462 ret = i915_gpu_idle(dev);
3463 if (ret)
3464 goto unlock;
3465 }
3466
3467 if (val & (DROP_RETIRE | DROP_ACTIVE))
3468 i915_gem_retire_requests(dev);
3469
3470 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07003471 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
3472 list_for_each_entry_safe(vma, x, &vm->inactive_list,
3473 mm_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -08003474 if (vma->pin_count)
Ben Widawskyca191b12013-07-31 17:00:14 -07003475 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07003476
Ben Widawskyca191b12013-07-31 17:00:14 -07003477 ret = i915_vma_unbind(vma);
3478 if (ret)
3479 goto unlock;
3480 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07003481 }
Chris Wilsondd624af2013-01-15 12:39:35 +00003482 }
3483
3484 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07003485 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
3486 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00003487 if (obj->pages_pin_count == 0) {
3488 ret = i915_gem_object_put_pages(obj);
3489 if (ret)
3490 goto unlock;
3491 }
3492 }
3493
3494unlock:
3495 mutex_unlock(&dev->struct_mutex);
3496
Kees Cook647416f2013-03-10 14:10:06 -07003497 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003498}
3499
Kees Cook647416f2013-03-10 14:10:06 -07003500DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
3501 i915_drop_caches_get, i915_drop_caches_set,
3502 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00003503
Kees Cook647416f2013-03-10 14:10:06 -07003504static int
3505i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003506{
Kees Cook647416f2013-03-10 14:10:06 -07003507 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003508 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003509 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003510
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003511 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003512 return -ENODEV;
3513
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003514 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3515
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003516 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003517 if (ret)
3518 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07003519
Jesse Barnes0a073b82013-04-17 15:54:58 -07003520 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003521 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003522 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003523 *val = dev_priv->rps.max_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003524 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003525
Kees Cook647416f2013-03-10 14:10:06 -07003526 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003527}
3528
Kees Cook647416f2013-03-10 14:10:06 -07003529static int
3530i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003531{
Kees Cook647416f2013-03-10 14:10:06 -07003532 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07003533 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003534 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003535 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003536
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003537 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003538 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07003539
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003540 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3541
Kees Cook647416f2013-03-10 14:10:06 -07003542 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07003543
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003544 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003545 if (ret)
3546 return ret;
3547
Jesse Barnes358733e2011-07-27 11:53:01 -07003548 /*
3549 * Turbo will still be enabled, but won't go above the set value.
3550 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003551 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003552 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003553
3554 hw_max = valleyview_rps_max_freq(dev_priv);
3555 hw_min = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003556 } else {
3557 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003558
3559 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003560 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003561 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003562 }
3563
Ben Widawskyb39fb292014-03-19 18:31:11 -07003564 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003565 mutex_unlock(&dev_priv->rps.hw_lock);
3566 return -EINVAL;
3567 }
3568
Ben Widawskyb39fb292014-03-19 18:31:11 -07003569 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003570
3571 if (IS_VALLEYVIEW(dev))
3572 valleyview_set_rps(dev, val);
3573 else
3574 gen6_set_rps(dev, val);
3575
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003576 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003577
Kees Cook647416f2013-03-10 14:10:06 -07003578 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003579}
3580
Kees Cook647416f2013-03-10 14:10:06 -07003581DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
3582 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003583 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07003584
Kees Cook647416f2013-03-10 14:10:06 -07003585static int
3586i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003587{
Kees Cook647416f2013-03-10 14:10:06 -07003588 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003589 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003590 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003591
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003592 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003593 return -ENODEV;
3594
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003595 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3596
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003597 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003598 if (ret)
3599 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07003600
Jesse Barnes0a073b82013-04-17 15:54:58 -07003601 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003602 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003603 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003604 *val = dev_priv->rps.min_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003605 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003606
Kees Cook647416f2013-03-10 14:10:06 -07003607 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003608}
3609
Kees Cook647416f2013-03-10 14:10:06 -07003610static int
3611i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003612{
Kees Cook647416f2013-03-10 14:10:06 -07003613 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07003614 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003615 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003616 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003617
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003618 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003619 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07003620
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003621 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3622
Kees Cook647416f2013-03-10 14:10:06 -07003623 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07003624
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003625 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003626 if (ret)
3627 return ret;
3628
Jesse Barnes1523c312012-05-25 12:34:54 -07003629 /*
3630 * Turbo will still be enabled, but won't go below the set value.
3631 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003632 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003633 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003634
3635 hw_max = valleyview_rps_max_freq(dev_priv);
3636 hw_min = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003637 } else {
3638 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003639
3640 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003641 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003642 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003643 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003644
Ben Widawskyb39fb292014-03-19 18:31:11 -07003645 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003646 mutex_unlock(&dev_priv->rps.hw_lock);
3647 return -EINVAL;
3648 }
3649
Ben Widawskyb39fb292014-03-19 18:31:11 -07003650 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003651
3652 if (IS_VALLEYVIEW(dev))
3653 valleyview_set_rps(dev, val);
3654 else
3655 gen6_set_rps(dev, val);
3656
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003657 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003658
Kees Cook647416f2013-03-10 14:10:06 -07003659 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003660}
3661
Kees Cook647416f2013-03-10 14:10:06 -07003662DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
3663 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003664 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07003665
Kees Cook647416f2013-03-10 14:10:06 -07003666static int
3667i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003668{
Kees Cook647416f2013-03-10 14:10:06 -07003669 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003670 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003671 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07003672 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003673
Daniel Vetter004777c2012-08-09 15:07:01 +02003674 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3675 return -ENODEV;
3676
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003677 ret = mutex_lock_interruptible(&dev->struct_mutex);
3678 if (ret)
3679 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003680 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003681
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003682 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003683
3684 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003685 mutex_unlock(&dev_priv->dev->struct_mutex);
3686
Kees Cook647416f2013-03-10 14:10:06 -07003687 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003688
Kees Cook647416f2013-03-10 14:10:06 -07003689 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003690}
3691
Kees Cook647416f2013-03-10 14:10:06 -07003692static int
3693i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003694{
Kees Cook647416f2013-03-10 14:10:06 -07003695 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003696 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003697 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003698
Daniel Vetter004777c2012-08-09 15:07:01 +02003699 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3700 return -ENODEV;
3701
Kees Cook647416f2013-03-10 14:10:06 -07003702 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003703 return -EINVAL;
3704
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003705 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003706 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003707
3708 /* Update the cache sharing policy here as well */
3709 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
3710 snpcr &= ~GEN6_MBC_SNPCR_MASK;
3711 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
3712 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
3713
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003714 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003715 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003716}
3717
Kees Cook647416f2013-03-10 14:10:06 -07003718DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
3719 i915_cache_sharing_get, i915_cache_sharing_set,
3720 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003721
Ben Widawsky6d794d42011-04-25 11:25:56 -07003722static int i915_forcewake_open(struct inode *inode, struct file *file)
3723{
3724 struct drm_device *dev = inode->i_private;
3725 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003726
Daniel Vetter075edca2012-01-24 09:44:28 +01003727 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003728 return 0;
3729
Deepak Sc8d9a592013-11-23 14:55:42 +05303730 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003731
3732 return 0;
3733}
3734
Ben Widawskyc43b5632012-04-16 14:07:40 -07003735static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003736{
3737 struct drm_device *dev = inode->i_private;
3738 struct drm_i915_private *dev_priv = dev->dev_private;
3739
Daniel Vetter075edca2012-01-24 09:44:28 +01003740 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003741 return 0;
3742
Deepak Sc8d9a592013-11-23 14:55:42 +05303743 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003744
3745 return 0;
3746}
3747
3748static const struct file_operations i915_forcewake_fops = {
3749 .owner = THIS_MODULE,
3750 .open = i915_forcewake_open,
3751 .release = i915_forcewake_release,
3752};
3753
3754static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
3755{
3756 struct drm_device *dev = minor->dev;
3757 struct dentry *ent;
3758
3759 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07003760 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07003761 root, dev,
3762 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003763 if (!ent)
3764 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003765
Ben Widawsky8eb57292011-05-11 15:10:58 -07003766 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003767}
3768
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003769static int i915_debugfs_create(struct dentry *root,
3770 struct drm_minor *minor,
3771 const char *name,
3772 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07003773{
3774 struct drm_device *dev = minor->dev;
3775 struct dentry *ent;
3776
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003777 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07003778 S_IRUGO | S_IWUSR,
3779 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003780 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003781 if (!ent)
3782 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07003783
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003784 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003785}
3786
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003787static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00003788 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01003789 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00003790 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01003791 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003792 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003793 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b8882013-08-07 18:30:54 +01003794 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01003795 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003796 {"i915_gem_request", i915_gem_request_info, 0},
3797 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00003798 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003799 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003800 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
3801 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
3802 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07003803 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003804 {"i915_rstdby_delays", i915_rstdby_delays, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05303805 {"i915_frequency_info", i915_frequency_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003806 {"i915_delayfreq_table", i915_delayfreq_table, 0},
3807 {"i915_inttoext_table", i915_inttoext_table, 0},
3808 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003809 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07003810 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003811 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08003812 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03003813 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08003814 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01003815 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01003816 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07003817 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07003818 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01003819 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01003820 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07003821 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03003822 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003823 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01003824 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03003825 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02003826 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003827 {"i915_display_info", i915_display_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003828};
Ben Gamari27c202a2009-07-01 22:26:52 -04003829#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05003830
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003831static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02003832 const char *name;
3833 const struct file_operations *fops;
3834} i915_debugfs_files[] = {
3835 {"i915_wedged", &i915_wedged_fops},
3836 {"i915_max_freq", &i915_max_freq_fops},
3837 {"i915_min_freq", &i915_min_freq_fops},
3838 {"i915_cache_sharing", &i915_cache_sharing_fops},
3839 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01003840 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
3841 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003842 {"i915_gem_drop_caches", &i915_drop_caches_fops},
3843 {"i915_error_state", &i915_error_state_fops},
3844 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01003845 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02003846 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
3847 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
3848 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003849};
3850
Damien Lespiau07144422013-10-15 18:55:40 +01003851void intel_display_crc_init(struct drm_device *dev)
3852{
3853 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01003854 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01003855
Daniel Vetterb3783602013-11-14 11:30:42 +01003856 for_each_pipe(pipe) {
3857 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01003858
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003859 pipe_crc->opened = false;
3860 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003861 init_waitqueue_head(&pipe_crc->wq);
3862 }
3863}
3864
Ben Gamari27c202a2009-07-01 22:26:52 -04003865int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003866{
Daniel Vetter34b96742013-07-04 20:49:44 +02003867 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003868
Ben Widawsky6d794d42011-04-25 11:25:56 -07003869 ret = i915_forcewake_create(minor->debugfs_root, minor);
3870 if (ret)
3871 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003872
Damien Lespiau07144422013-10-15 18:55:40 +01003873 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
3874 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
3875 if (ret)
3876 return ret;
3877 }
3878
Daniel Vetter34b96742013-07-04 20:49:44 +02003879 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3880 ret = i915_debugfs_create(minor->debugfs_root, minor,
3881 i915_debugfs_files[i].name,
3882 i915_debugfs_files[i].fops);
3883 if (ret)
3884 return ret;
3885 }
Mika Kuoppala40633212012-12-04 15:12:00 +02003886
Ben Gamari27c202a2009-07-01 22:26:52 -04003887 return drm_debugfs_create_files(i915_debugfs_list,
3888 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05003889 minor->debugfs_root, minor);
3890}
3891
Ben Gamari27c202a2009-07-01 22:26:52 -04003892void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003893{
Daniel Vetter34b96742013-07-04 20:49:44 +02003894 int i;
3895
Ben Gamari27c202a2009-07-01 22:26:52 -04003896 drm_debugfs_remove_files(i915_debugfs_list,
3897 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003898
Ben Widawsky6d794d42011-04-25 11:25:56 -07003899 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
3900 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003901
Daniel Vettere309a992013-10-16 22:55:51 +02003902 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01003903 struct drm_info_list *info_list =
3904 (struct drm_info_list *)&i915_pipe_crc_data[i];
3905
3906 drm_debugfs_remove_files(info_list, 1, minor);
3907 }
3908
Daniel Vetter34b96742013-07-04 20:49:44 +02003909 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3910 struct drm_info_list *info_list =
3911 (struct drm_info_list *) i915_debugfs_files[i].fops;
3912
3913 drm_debugfs_remove_files(info_list, 1, minor);
3914 }
Ben Gamari20172632009-02-17 20:08:50 -05003915}