blob: d42db6bc34e07b1af72c3ccdec2832215bb5e518 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
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);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200173 if (obj->frontbuffer_bits)
174 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100175}
176
Oscar Mateo273497e2014-05-22 14:13:37 +0100177static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700178{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100179 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700180 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
181 seq_putc(m, ' ');
182}
183
Ben Gamari433e12f2009-02-17 20:08:51 -0500184static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500185{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100186 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500187 uintptr_t list = (uintptr_t) node->info_ent->data;
188 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500189 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700190 struct drm_i915_private *dev_priv = dev->dev_private;
191 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700192 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100193 size_t total_obj_size, total_gtt_size;
194 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100195
196 ret = mutex_lock_interruptible(&dev->struct_mutex);
197 if (ret)
198 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500199
Ben Widawskyca191b12013-07-31 17:00:14 -0700200 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500201 switch (list) {
202 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100203 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700204 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500205 break;
206 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100207 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700208 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500210 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100211 mutex_unlock(&dev->struct_mutex);
212 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500213 }
214
Chris Wilson8f2480f2010-09-26 11:44:19 +0100215 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700216 list_for_each_entry(vma, head, mm_list) {
217 seq_printf(m, " ");
218 describe_obj(m, vma->obj);
219 seq_printf(m, "\n");
220 total_obj_size += vma->obj->base.size;
221 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100222 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500223 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100224 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700225
Chris Wilson8f2480f2010-09-26 11:44:19 +0100226 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
227 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500228 return 0;
229}
230
Chris Wilson6d2b88852013-08-07 18:30:54 +0100231static int obj_rank_by_stolen(void *priv,
232 struct list_head *A, struct list_head *B)
233{
234 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100236 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200237 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100238
239 return a->stolen->start - b->stolen->start;
240}
241
242static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
243{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100244 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245 struct drm_device *dev = node->minor->dev;
246 struct drm_i915_private *dev_priv = dev->dev_private;
247 struct drm_i915_gem_object *obj;
248 size_t total_obj_size, total_gtt_size;
249 LIST_HEAD(stolen);
250 int count, ret;
251
252 ret = mutex_lock_interruptible(&dev->struct_mutex);
253 if (ret)
254 return ret;
255
256 total_obj_size = total_gtt_size = count = 0;
257 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
258 if (obj->stolen == NULL)
259 continue;
260
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200261 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262
263 total_obj_size += obj->base.size;
264 total_gtt_size += i915_gem_obj_ggtt_size(obj);
265 count++;
266 }
267 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
268 if (obj->stolen == NULL)
269 continue;
270
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200271 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100272
273 total_obj_size += obj->base.size;
274 count++;
275 }
276 list_sort(NULL, &stolen, obj_rank_by_stolen);
277 seq_puts(m, "Stolen:\n");
278 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200279 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 seq_puts(m, " ");
281 describe_obj(m, obj);
282 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284 }
285 mutex_unlock(&dev->struct_mutex);
286
287 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
288 count, total_obj_size, total_gtt_size);
289 return 0;
290}
291
Chris Wilson6299f992010-11-24 12:23:44 +0000292#define count_objects(list, member) do { \
293 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700294 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000295 ++count; \
296 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700297 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000298 ++mappable_count; \
299 } \
300 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400301} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000302
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000304 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100305 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000306 size_t total, unbound;
307 size_t global, shared;
308 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100309};
310
311static int per_file_stats(int id, void *ptr, void *data)
312{
313 struct drm_i915_gem_object *obj = ptr;
314 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000315 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100316
317 stats->count++;
318 stats->total += obj->base.size;
319
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000320 if (obj->base.name || obj->base.dma_buf)
321 stats->shared += obj->base.size;
322
Chris Wilson6313c202014-03-19 13:45:45 +0000323 if (USES_FULL_PPGTT(obj->base.dev)) {
324 list_for_each_entry(vma, &obj->vma_list, vma_link) {
325 struct i915_hw_ppgtt *ppgtt;
326
327 if (!drm_mm_node_allocated(&vma->node))
328 continue;
329
330 if (i915_is_ggtt(vma->vm)) {
331 stats->global += obj->base.size;
332 continue;
333 }
334
335 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200336 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000337 continue;
338
339 if (obj->ring) /* XXX per-vma statistic */
340 stats->active += obj->base.size;
341 else
342 stats->inactive += obj->base.size;
343
344 return 0;
345 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100346 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000347 if (i915_gem_obj_ggtt_bound(obj)) {
348 stats->global += obj->base.size;
349 if (obj->ring)
350 stats->active += obj->base.size;
351 else
352 stats->inactive += obj->base.size;
353 return 0;
354 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100355 }
356
Chris Wilson6313c202014-03-19 13:45:45 +0000357 if (!list_empty(&obj->global_list))
358 stats->unbound += obj->base.size;
359
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100360 return 0;
361}
362
Ben Widawskyca191b12013-07-31 17:00:14 -0700363#define count_vmas(list, member) do { \
364 list_for_each_entry(vma, list, member) { \
365 size += i915_gem_obj_ggtt_size(vma->obj); \
366 ++count; \
367 if (vma->obj->map_and_fenceable) { \
368 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
369 ++mappable_count; \
370 } \
371 } \
372} while (0)
373
374static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100375{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100376 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100377 struct drm_device *dev = node->minor->dev;
378 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200379 u32 count, mappable_count, purgeable_count;
380 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000381 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700382 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100383 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700384 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100385 int ret;
386
387 ret = mutex_lock_interruptible(&dev->struct_mutex);
388 if (ret)
389 return ret;
390
Chris Wilson6299f992010-11-24 12:23:44 +0000391 seq_printf(m, "%u objects, %zu bytes\n",
392 dev_priv->mm.object_count,
393 dev_priv->mm.object_memory);
394
395 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700396 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000397 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
398 count, mappable_count, size, mappable_size);
399
400 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700401 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000402 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
403 count, mappable_count, size, mappable_size);
404
405 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700406 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000407 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
408 count, mappable_count, size, mappable_size);
409
Chris Wilsonb7abb712012-08-20 11:33:30 +0200410 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700411 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200412 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200413 if (obj->madv == I915_MADV_DONTNEED)
414 purgeable_size += obj->base.size, ++purgeable_count;
415 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200416 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
417
Chris Wilson6299f992010-11-24 12:23:44 +0000418 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700419 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000420 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700421 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000422 ++count;
423 }
424 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700425 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000426 ++mappable_count;
427 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200428 if (obj->madv == I915_MADV_DONTNEED) {
429 purgeable_size += obj->base.size;
430 ++purgeable_count;
431 }
Chris Wilson6299f992010-11-24 12:23:44 +0000432 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200433 seq_printf(m, "%u purgeable objects, %zu bytes\n",
434 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000435 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
436 mappable_count, mappable_size);
437 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
438 count, size);
439
Ben Widawsky93d18792013-01-17 12:45:17 -0800440 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700441 dev_priv->gtt.base.total,
442 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100443
Damien Lespiau267f0c92013-06-24 22:59:48 +0100444 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100445 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
446 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900447 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100448
449 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000450 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100451 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100452 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100453 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900454 /*
455 * Although we have a valid reference on file->pid, that does
456 * not guarantee that the task_struct who called get_pid() is
457 * still alive (e.g. get_pid(current) => fork() => exit()).
458 * Therefore, we need to protect this ->comm access using RCU.
459 */
460 rcu_read_lock();
461 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000462 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 +0900463 task ? task->comm : "<unknown>",
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100464 stats.count,
465 stats.total,
466 stats.active,
467 stats.inactive,
Chris Wilson6313c202014-03-19 13:45:45 +0000468 stats.global,
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000469 stats.shared,
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100470 stats.unbound);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900471 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100472 }
473
Chris Wilson73aa8082010-09-30 11:46:12 +0100474 mutex_unlock(&dev->struct_mutex);
475
476 return 0;
477}
478
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100479static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000480{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100481 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000482 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100483 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000484 struct drm_i915_private *dev_priv = dev->dev_private;
485 struct drm_i915_gem_object *obj;
486 size_t total_obj_size, total_gtt_size;
487 int count, ret;
488
489 ret = mutex_lock_interruptible(&dev->struct_mutex);
490 if (ret)
491 return ret;
492
493 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700494 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800495 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100496 continue;
497
Damien Lespiau267f0c92013-06-24 22:59:48 +0100498 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000499 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100500 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000501 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700502 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000503 count++;
504 }
505
506 mutex_unlock(&dev->struct_mutex);
507
508 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
509 count, total_obj_size, total_gtt_size);
510
511 return 0;
512}
513
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100514static int i915_gem_pageflip_info(struct seq_file *m, void *data)
515{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100516 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100517 struct drm_device *dev = node->minor->dev;
518 unsigned long flags;
519 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200520 int ret;
521
522 ret = mutex_lock_interruptible(&dev->struct_mutex);
523 if (ret)
524 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100525
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100526 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800527 const char pipe = pipe_name(crtc->pipe);
528 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100529 struct intel_unpin_work *work;
530
531 spin_lock_irqsave(&dev->event_lock, flags);
532 work = crtc->unpin_work;
533 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800534 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100535 pipe, plane);
536 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000537 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800538 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100539 pipe, plane);
540 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800541 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542 pipe, plane);
543 }
544 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100545 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100546 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100547 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000548 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100549
550 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000551 struct drm_i915_gem_object *obj = work->old_fb_obj;
552 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700553 seq_printf(m, "Old framebuffer gtt_offset 0x%08lx\n",
554 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100555 }
556 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000557 struct drm_i915_gem_object *obj = work->pending_flip_obj;
558 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700559 seq_printf(m, "New framebuffer gtt_offset 0x%08lx\n",
560 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100561 }
562 }
563 spin_unlock_irqrestore(&dev->event_lock, flags);
564 }
565
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200566 mutex_unlock(&dev->struct_mutex);
567
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100568 return 0;
569}
570
Ben Gamari20172632009-02-17 20:08:50 -0500571static int i915_gem_request_info(struct seq_file *m, void *data)
572{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100573 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500574 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300575 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100576 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500577 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100578 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100579
580 ret = mutex_lock_interruptible(&dev->struct_mutex);
581 if (ret)
582 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500583
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100584 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100585 for_each_ring(ring, dev_priv, i) {
586 if (list_empty(&ring->request_list))
587 continue;
588
589 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100590 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100591 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100592 list) {
593 seq_printf(m, " %d @ %d\n",
594 gem_request->seqno,
595 (int) (jiffies - gem_request->emitted_jiffies));
596 }
597 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500598 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100599 mutex_unlock(&dev->struct_mutex);
600
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100601 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100602 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100603
Ben Gamari20172632009-02-17 20:08:50 -0500604 return 0;
605}
606
Chris Wilsonb2223492010-10-27 15:27:33 +0100607static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100608 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100609{
610 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200611 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100612 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100613 }
614}
615
Ben Gamari20172632009-02-17 20:08:50 -0500616static int i915_gem_seqno_info(struct seq_file *m, void *data)
617{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100618 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500619 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300620 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100621 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000622 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100623
624 ret = mutex_lock_interruptible(&dev->struct_mutex);
625 if (ret)
626 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200627 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500628
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100629 for_each_ring(ring, dev_priv, i)
630 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100631
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200632 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100633 mutex_unlock(&dev->struct_mutex);
634
Ben Gamari20172632009-02-17 20:08:50 -0500635 return 0;
636}
637
638
639static int i915_interrupt_info(struct seq_file *m, void *data)
640{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100641 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500642 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300643 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100644 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800645 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100646
647 ret = mutex_lock_interruptible(&dev->struct_mutex);
648 if (ret)
649 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200650 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500651
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300652 if (IS_CHERRYVIEW(dev)) {
653 int i;
654 seq_printf(m, "Master Interrupt Control:\t%08x\n",
655 I915_READ(GEN8_MASTER_IRQ));
656
657 seq_printf(m, "Display IER:\t%08x\n",
658 I915_READ(VLV_IER));
659 seq_printf(m, "Display IIR:\t%08x\n",
660 I915_READ(VLV_IIR));
661 seq_printf(m, "Display IIR_RW:\t%08x\n",
662 I915_READ(VLV_IIR_RW));
663 seq_printf(m, "Display IMR:\t%08x\n",
664 I915_READ(VLV_IMR));
665 for_each_pipe(pipe)
666 seq_printf(m, "Pipe %c stat:\t%08x\n",
667 pipe_name(pipe),
668 I915_READ(PIPESTAT(pipe)));
669
670 seq_printf(m, "Port hotplug:\t%08x\n",
671 I915_READ(PORT_HOTPLUG_EN));
672 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
673 I915_READ(VLV_DPFLIPSTAT));
674 seq_printf(m, "DPINVGTT:\t%08x\n",
675 I915_READ(DPINVGTT));
676
677 for (i = 0; i < 4; i++) {
678 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
679 i, I915_READ(GEN8_GT_IMR(i)));
680 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
681 i, I915_READ(GEN8_GT_IIR(i)));
682 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
683 i, I915_READ(GEN8_GT_IER(i)));
684 }
685
686 seq_printf(m, "PCU interrupt mask:\t%08x\n",
687 I915_READ(GEN8_PCU_IMR));
688 seq_printf(m, "PCU interrupt identity:\t%08x\n",
689 I915_READ(GEN8_PCU_IIR));
690 seq_printf(m, "PCU interrupt enable:\t%08x\n",
691 I915_READ(GEN8_PCU_IER));
692 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700693 seq_printf(m, "Master Interrupt Control:\t%08x\n",
694 I915_READ(GEN8_MASTER_IRQ));
695
696 for (i = 0; i < 4; i++) {
697 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
698 i, I915_READ(GEN8_GT_IMR(i)));
699 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
700 i, I915_READ(GEN8_GT_IIR(i)));
701 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
702 i, I915_READ(GEN8_GT_IER(i)));
703 }
704
Damien Lespiau07d27e22014-03-03 17:31:46 +0000705 for_each_pipe(pipe) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300706 if (!intel_display_power_enabled(dev_priv,
707 POWER_DOMAIN_PIPE(pipe))) {
708 seq_printf(m, "Pipe %c power disabled\n",
709 pipe_name(pipe));
710 continue;
711 }
Ben Widawskya123f152013-11-02 21:07:10 -0700712 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000713 pipe_name(pipe),
714 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700715 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000716 pipe_name(pipe),
717 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700718 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000719 pipe_name(pipe),
720 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700721 }
722
723 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
724 I915_READ(GEN8_DE_PORT_IMR));
725 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
726 I915_READ(GEN8_DE_PORT_IIR));
727 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
728 I915_READ(GEN8_DE_PORT_IER));
729
730 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
731 I915_READ(GEN8_DE_MISC_IMR));
732 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
733 I915_READ(GEN8_DE_MISC_IIR));
734 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
735 I915_READ(GEN8_DE_MISC_IER));
736
737 seq_printf(m, "PCU interrupt mask:\t%08x\n",
738 I915_READ(GEN8_PCU_IMR));
739 seq_printf(m, "PCU interrupt identity:\t%08x\n",
740 I915_READ(GEN8_PCU_IIR));
741 seq_printf(m, "PCU interrupt enable:\t%08x\n",
742 I915_READ(GEN8_PCU_IER));
743 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700744 seq_printf(m, "Display IER:\t%08x\n",
745 I915_READ(VLV_IER));
746 seq_printf(m, "Display IIR:\t%08x\n",
747 I915_READ(VLV_IIR));
748 seq_printf(m, "Display IIR_RW:\t%08x\n",
749 I915_READ(VLV_IIR_RW));
750 seq_printf(m, "Display IMR:\t%08x\n",
751 I915_READ(VLV_IMR));
752 for_each_pipe(pipe)
753 seq_printf(m, "Pipe %c stat:\t%08x\n",
754 pipe_name(pipe),
755 I915_READ(PIPESTAT(pipe)));
756
757 seq_printf(m, "Master IER:\t%08x\n",
758 I915_READ(VLV_MASTER_IER));
759
760 seq_printf(m, "Render IER:\t%08x\n",
761 I915_READ(GTIER));
762 seq_printf(m, "Render IIR:\t%08x\n",
763 I915_READ(GTIIR));
764 seq_printf(m, "Render IMR:\t%08x\n",
765 I915_READ(GTIMR));
766
767 seq_printf(m, "PM IER:\t\t%08x\n",
768 I915_READ(GEN6_PMIER));
769 seq_printf(m, "PM IIR:\t\t%08x\n",
770 I915_READ(GEN6_PMIIR));
771 seq_printf(m, "PM IMR:\t\t%08x\n",
772 I915_READ(GEN6_PMIMR));
773
774 seq_printf(m, "Port hotplug:\t%08x\n",
775 I915_READ(PORT_HOTPLUG_EN));
776 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
777 I915_READ(VLV_DPFLIPSTAT));
778 seq_printf(m, "DPINVGTT:\t%08x\n",
779 I915_READ(DPINVGTT));
780
781 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800782 seq_printf(m, "Interrupt enable: %08x\n",
783 I915_READ(IER));
784 seq_printf(m, "Interrupt identity: %08x\n",
785 I915_READ(IIR));
786 seq_printf(m, "Interrupt mask: %08x\n",
787 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800788 for_each_pipe(pipe)
789 seq_printf(m, "Pipe %c stat: %08x\n",
790 pipe_name(pipe),
791 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800792 } else {
793 seq_printf(m, "North Display Interrupt enable: %08x\n",
794 I915_READ(DEIER));
795 seq_printf(m, "North Display Interrupt identity: %08x\n",
796 I915_READ(DEIIR));
797 seq_printf(m, "North Display Interrupt mask: %08x\n",
798 I915_READ(DEIMR));
799 seq_printf(m, "South Display Interrupt enable: %08x\n",
800 I915_READ(SDEIER));
801 seq_printf(m, "South Display Interrupt identity: %08x\n",
802 I915_READ(SDEIIR));
803 seq_printf(m, "South Display Interrupt mask: %08x\n",
804 I915_READ(SDEIMR));
805 seq_printf(m, "Graphics Interrupt enable: %08x\n",
806 I915_READ(GTIER));
807 seq_printf(m, "Graphics Interrupt identity: %08x\n",
808 I915_READ(GTIIR));
809 seq_printf(m, "Graphics Interrupt mask: %08x\n",
810 I915_READ(GTIMR));
811 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100812 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700813 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100814 seq_printf(m,
815 "Graphics Interrupt mask (%s): %08x\n",
816 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000817 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100818 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000819 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200820 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100821 mutex_unlock(&dev->struct_mutex);
822
Ben Gamari20172632009-02-17 20:08:50 -0500823 return 0;
824}
825
Chris Wilsona6172a82009-02-11 14:26:38 +0000826static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
827{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100828 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000829 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300830 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100831 int i, ret;
832
833 ret = mutex_lock_interruptible(&dev->struct_mutex);
834 if (ret)
835 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000836
837 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
838 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
839 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000840 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000841
Chris Wilson6c085a72012-08-20 11:40:46 +0200842 seq_printf(m, "Fence %d, pin count = %d, object = ",
843 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100844 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100845 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100846 else
Chris Wilson05394f32010-11-08 19:18:58 +0000847 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100848 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000849 }
850
Chris Wilson05394f32010-11-08 19:18:58 +0000851 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000852 return 0;
853}
854
Ben Gamari20172632009-02-17 20:08:50 -0500855static int i915_hws_info(struct seq_file *m, void *data)
856{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100857 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500858 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300859 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100860 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100861 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100862 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500863
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000864 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100865 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500866 if (hws == NULL)
867 return 0;
868
869 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
870 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
871 i * 4,
872 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
873 }
874 return 0;
875}
876
Daniel Vetterd5442302012-04-27 15:17:40 +0200877static ssize_t
878i915_error_state_write(struct file *filp,
879 const char __user *ubuf,
880 size_t cnt,
881 loff_t *ppos)
882{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300883 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200884 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200885 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200886
887 DRM_DEBUG_DRIVER("Resetting error state\n");
888
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200889 ret = mutex_lock_interruptible(&dev->struct_mutex);
890 if (ret)
891 return ret;
892
Daniel Vetterd5442302012-04-27 15:17:40 +0200893 i915_destroy_error_state(dev);
894 mutex_unlock(&dev->struct_mutex);
895
896 return cnt;
897}
898
899static int i915_error_state_open(struct inode *inode, struct file *file)
900{
901 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200902 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200903
904 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
905 if (!error_priv)
906 return -ENOMEM;
907
908 error_priv->dev = dev;
909
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300910 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200911
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300912 file->private_data = error_priv;
913
914 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200915}
916
917static int i915_error_state_release(struct inode *inode, struct file *file)
918{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300919 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200920
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300921 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200922 kfree(error_priv);
923
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300924 return 0;
925}
926
927static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
928 size_t count, loff_t *pos)
929{
930 struct i915_error_state_file_priv *error_priv = file->private_data;
931 struct drm_i915_error_state_buf error_str;
932 loff_t tmp_pos = 0;
933 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300934 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300935
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300936 ret = i915_error_state_buf_init(&error_str, count, *pos);
937 if (ret)
938 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300939
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300940 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300941 if (ret)
942 goto out;
943
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300944 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
945 error_str.buf,
946 error_str.bytes);
947
948 if (ret_count < 0)
949 ret = ret_count;
950 else
951 *pos = error_str.start + ret_count;
952out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300953 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300954 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200955}
956
957static const struct file_operations i915_error_state_fops = {
958 .owner = THIS_MODULE,
959 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300960 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200961 .write = i915_error_state_write,
962 .llseek = default_llseek,
963 .release = i915_error_state_release,
964};
965
Kees Cook647416f2013-03-10 14:10:06 -0700966static int
967i915_next_seqno_get(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;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300970 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200971 int ret;
972
973 ret = mutex_lock_interruptible(&dev->struct_mutex);
974 if (ret)
975 return ret;
976
Kees Cook647416f2013-03-10 14:10:06 -0700977 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200978 mutex_unlock(&dev->struct_mutex);
979
Kees Cook647416f2013-03-10 14:10:06 -0700980 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200981}
982
Kees Cook647416f2013-03-10 14:10:06 -0700983static int
984i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200985{
Kees Cook647416f2013-03-10 14:10:06 -0700986 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200987 int ret;
988
Mika Kuoppala40633212012-12-04 15:12:00 +0200989 ret = mutex_lock_interruptible(&dev->struct_mutex);
990 if (ret)
991 return ret;
992
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200993 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200994 mutex_unlock(&dev->struct_mutex);
995
Kees Cook647416f2013-03-10 14:10:06 -0700996 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200997}
998
Kees Cook647416f2013-03-10 14:10:06 -0700999DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1000 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001001 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001002
Deepak Sadb4bd12014-03-31 11:30:02 +05301003static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001004{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001005 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001006 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001007 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001008 int ret = 0;
1009
1010 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001011
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001012 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1013
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001014 if (IS_GEN5(dev)) {
1015 u16 rgvswctl = I915_READ16(MEMSWCTL);
1016 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1017
1018 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1019 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1020 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1021 MEMSTAT_VID_SHIFT);
1022 seq_printf(m, "Current P-state: %d\n",
1023 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001024 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1025 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001026 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1027 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1028 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001029 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001030 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001031 u32 rpupei, rpcurup, rpprevup;
1032 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001033 int max_freq;
1034
1035 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001036 ret = mutex_lock_interruptible(&dev->struct_mutex);
1037 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001038 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001039
Deepak Sc8d9a592013-11-23 14:55:42 +05301040 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001041
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001042 reqf = I915_READ(GEN6_RPNSWREQ);
1043 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001044 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001045 reqf >>= 24;
1046 else
1047 reqf >>= 25;
1048 reqf *= GT_FREQUENCY_MULTIPLIER;
1049
Chris Wilson0d8f9492014-03-27 09:06:14 +00001050 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1051 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1052 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1053
Jesse Barnesccab5c82011-01-18 15:49:25 -08001054 rpstat = I915_READ(GEN6_RPSTAT1);
1055 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1056 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1057 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1058 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1059 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1060 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001061 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001062 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1063 else
1064 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1065 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001066
Deepak Sc8d9a592013-11-23 14:55:42 +05301067 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001068 mutex_unlock(&dev->struct_mutex);
1069
Chris Wilson0d8f9492014-03-27 09:06:14 +00001070 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
1071 I915_READ(GEN6_PMIER),
1072 I915_READ(GEN6_PMIMR),
1073 I915_READ(GEN6_PMISR),
1074 I915_READ(GEN6_PMIIR),
1075 I915_READ(GEN6_PMINTRMSK));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001076 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001077 seq_printf(m, "Render p-state ratio: %d\n",
1078 (gt_perf_status & 0xff00) >> 8);
1079 seq_printf(m, "Render p-state VID: %d\n",
1080 gt_perf_status & 0xff);
1081 seq_printf(m, "Render p-state limit: %d\n",
1082 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001083 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1084 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1085 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1086 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001087 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001088 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001089 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1090 GEN6_CURICONT_MASK);
1091 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1092 GEN6_CURBSYTAVG_MASK);
1093 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1094 GEN6_CURBSYTAVG_MASK);
1095 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1096 GEN6_CURIAVG_MASK);
1097 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1098 GEN6_CURBSYTAVG_MASK);
1099 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1100 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001101
1102 max_freq = (rp_state_cap & 0xff0000) >> 16;
1103 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001104 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001105
1106 max_freq = (rp_state_cap & 0xff00) >> 8;
1107 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001108 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001109
1110 max_freq = rp_state_cap & 0xff;
1111 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001112 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001113
1114 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ben Widawskyb39fb292014-03-19 18:31:11 -07001115 dev_priv->rps.max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001116 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001117 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001118
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001119 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001120 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001121 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1122 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1123
Jesse Barnes0a073b82013-04-17 15:54:58 -07001124 seq_printf(m, "max GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301125 vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001126
Jesse Barnes0a073b82013-04-17 15:54:58 -07001127 seq_printf(m, "min GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301128 vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001129
1130 seq_printf(m, "efficient (RPe) frequency: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301131 vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001132
1133 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001134 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001135 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001136 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001137 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001138 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001139
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001140out:
1141 intel_runtime_pm_put(dev_priv);
1142 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001143}
1144
Ben Widawsky4d855292011-12-12 19:34:16 -08001145static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001146{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001147 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001148 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001149 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001150 u32 rgvmodectl, rstdbyctl;
1151 u16 crstandvid;
1152 int ret;
1153
1154 ret = mutex_lock_interruptible(&dev->struct_mutex);
1155 if (ret)
1156 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001157 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001158
1159 rgvmodectl = I915_READ(MEMMODECTL);
1160 rstdbyctl = I915_READ(RSTDBYCTL);
1161 crstandvid = I915_READ16(CRSTANDVID);
1162
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001163 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001164 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001165
1166 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1167 "yes" : "no");
1168 seq_printf(m, "Boost freq: %d\n",
1169 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1170 MEMMODE_BOOST_FREQ_SHIFT);
1171 seq_printf(m, "HW control enabled: %s\n",
1172 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1173 seq_printf(m, "SW control enabled: %s\n",
1174 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1175 seq_printf(m, "Gated voltage change: %s\n",
1176 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1177 seq_printf(m, "Starting frequency: P%d\n",
1178 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001179 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001180 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001181 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1182 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1183 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1184 seq_printf(m, "Render standby enabled: %s\n",
1185 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001186 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001187 switch (rstdbyctl & RSX_STATUS_MASK) {
1188 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001189 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001190 break;
1191 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001192 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001193 break;
1194 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001195 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001196 break;
1197 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001198 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001199 break;
1200 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001201 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001202 break;
1203 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001204 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001205 break;
1206 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001207 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001208 break;
1209 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001210
1211 return 0;
1212}
1213
Deepak S669ab5a2014-01-10 15:18:26 +05301214static int vlv_drpc_info(struct seq_file *m)
1215{
1216
Damien Lespiau9f25d002014-05-13 15:30:28 +01001217 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301218 struct drm_device *dev = node->minor->dev;
1219 struct drm_i915_private *dev_priv = dev->dev_private;
1220 u32 rpmodectl1, rcctl1;
1221 unsigned fw_rendercount = 0, fw_mediacount = 0;
1222
Imre Deakd46c0512014-04-14 20:24:27 +03001223 intel_runtime_pm_get(dev_priv);
1224
Deepak S669ab5a2014-01-10 15:18:26 +05301225 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1226 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1227
Imre Deakd46c0512014-04-14 20:24:27 +03001228 intel_runtime_pm_put(dev_priv);
1229
Deepak S669ab5a2014-01-10 15:18:26 +05301230 seq_printf(m, "Video Turbo Mode: %s\n",
1231 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1232 seq_printf(m, "Turbo enabled: %s\n",
1233 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1234 seq_printf(m, "HW control enabled: %s\n",
1235 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1236 seq_printf(m, "SW control enabled: %s\n",
1237 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1238 GEN6_RP_MEDIA_SW_MODE));
1239 seq_printf(m, "RC6 Enabled: %s\n",
1240 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1241 GEN6_RC_CTL_EI_MODE(1))));
1242 seq_printf(m, "Render Power Well: %s\n",
1243 (I915_READ(VLV_GTLC_PW_STATUS) &
1244 VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
1245 seq_printf(m, "Media Power Well: %s\n",
1246 (I915_READ(VLV_GTLC_PW_STATUS) &
1247 VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
1248
Imre Deak9cc19be2014-04-14 20:24:24 +03001249 seq_printf(m, "Render RC6 residency since boot: %u\n",
1250 I915_READ(VLV_GT_RENDER_RC6));
1251 seq_printf(m, "Media RC6 residency since boot: %u\n",
1252 I915_READ(VLV_GT_MEDIA_RC6));
1253
Deepak S669ab5a2014-01-10 15:18:26 +05301254 spin_lock_irq(&dev_priv->uncore.lock);
1255 fw_rendercount = dev_priv->uncore.fw_rendercount;
1256 fw_mediacount = dev_priv->uncore.fw_mediacount;
1257 spin_unlock_irq(&dev_priv->uncore.lock);
1258
1259 seq_printf(m, "Forcewake Render Count = %u\n", fw_rendercount);
1260 seq_printf(m, "Forcewake Media Count = %u\n", fw_mediacount);
1261
1262
1263 return 0;
1264}
1265
1266
Ben Widawsky4d855292011-12-12 19:34:16 -08001267static int gen6_drpc_info(struct seq_file *m)
1268{
1269
Damien Lespiau9f25d002014-05-13 15:30:28 +01001270 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001271 struct drm_device *dev = node->minor->dev;
1272 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001273 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001274 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001275 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001276
1277 ret = mutex_lock_interruptible(&dev->struct_mutex);
1278 if (ret)
1279 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001280 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001281
Chris Wilson907b28c2013-07-19 20:36:52 +01001282 spin_lock_irq(&dev_priv->uncore.lock);
1283 forcewake_count = dev_priv->uncore.forcewake_count;
1284 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001285
1286 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001287 seq_puts(m, "RC information inaccurate because somebody "
1288 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001289 } else {
1290 /* NB: we cannot use forcewake, else we read the wrong values */
1291 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1292 udelay(10);
1293 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1294 }
1295
1296 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001297 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001298
1299 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1300 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1301 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001302 mutex_lock(&dev_priv->rps.hw_lock);
1303 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1304 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001305
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001306 intel_runtime_pm_put(dev_priv);
1307
Ben Widawsky4d855292011-12-12 19:34:16 -08001308 seq_printf(m, "Video Turbo Mode: %s\n",
1309 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1310 seq_printf(m, "HW control enabled: %s\n",
1311 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1312 seq_printf(m, "SW control enabled: %s\n",
1313 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1314 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001315 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001316 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1317 seq_printf(m, "RC6 Enabled: %s\n",
1318 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1319 seq_printf(m, "Deep RC6 Enabled: %s\n",
1320 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1321 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1322 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001323 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001324 switch (gt_core_status & GEN6_RCn_MASK) {
1325 case GEN6_RC0:
1326 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001327 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001328 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001329 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001330 break;
1331 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001332 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001333 break;
1334 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001335 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001336 break;
1337 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001338 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001339 break;
1340 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001341 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001342 break;
1343 }
1344
1345 seq_printf(m, "Core Power Down: %s\n",
1346 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001347
1348 /* Not exactly sure what this is */
1349 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1350 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1351 seq_printf(m, "RC6 residency since boot: %u\n",
1352 I915_READ(GEN6_GT_GFX_RC6));
1353 seq_printf(m, "RC6+ residency since boot: %u\n",
1354 I915_READ(GEN6_GT_GFX_RC6p));
1355 seq_printf(m, "RC6++ residency since boot: %u\n",
1356 I915_READ(GEN6_GT_GFX_RC6pp));
1357
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001358 seq_printf(m, "RC6 voltage: %dmV\n",
1359 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1360 seq_printf(m, "RC6+ voltage: %dmV\n",
1361 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1362 seq_printf(m, "RC6++ voltage: %dmV\n",
1363 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001364 return 0;
1365}
1366
1367static int i915_drpc_info(struct seq_file *m, void *unused)
1368{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001369 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001370 struct drm_device *dev = node->minor->dev;
1371
Deepak S669ab5a2014-01-10 15:18:26 +05301372 if (IS_VALLEYVIEW(dev))
1373 return vlv_drpc_info(m);
1374 else if (IS_GEN6(dev) || IS_GEN7(dev))
Ben Widawsky4d855292011-12-12 19:34:16 -08001375 return gen6_drpc_info(m);
1376 else
1377 return ironlake_drpc_info(m);
1378}
1379
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001380static int i915_fbc_status(struct seq_file *m, void *unused)
1381{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001382 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001383 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001384 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001385
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001386 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001387 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001388 return 0;
1389 }
1390
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001391 intel_runtime_pm_get(dev_priv);
1392
Adam Jacksonee5382a2010-04-23 11:17:39 -04001393 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001394 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001395 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001396 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001397 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001398 case FBC_OK:
1399 seq_puts(m, "FBC actived, but currently disabled in hardware");
1400 break;
1401 case FBC_UNSUPPORTED:
1402 seq_puts(m, "unsupported by this chipset");
1403 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001404 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001405 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001406 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001407 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001408 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001409 break;
1410 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001411 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001412 break;
1413 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001414 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001415 break;
1416 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001417 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001418 break;
1419 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001420 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001421 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001422 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001423 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001424 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001425 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001426 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001427 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001428 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001429 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001430 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001431 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001432 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001433 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001434 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001435 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001436
1437 intel_runtime_pm_put(dev_priv);
1438
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001439 return 0;
1440}
1441
Rodrigo Vivida46f932014-08-01 02:04:45 -07001442static int i915_fbc_fc_get(void *data, u64 *val)
1443{
1444 struct drm_device *dev = data;
1445 struct drm_i915_private *dev_priv = dev->dev_private;
1446
1447 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1448 return -ENODEV;
1449
1450 drm_modeset_lock_all(dev);
1451 *val = dev_priv->fbc.false_color;
1452 drm_modeset_unlock_all(dev);
1453
1454 return 0;
1455}
1456
1457static int i915_fbc_fc_set(void *data, u64 val)
1458{
1459 struct drm_device *dev = data;
1460 struct drm_i915_private *dev_priv = dev->dev_private;
1461 u32 reg;
1462
1463 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1464 return -ENODEV;
1465
1466 drm_modeset_lock_all(dev);
1467
1468 reg = I915_READ(ILK_DPFC_CONTROL);
1469 dev_priv->fbc.false_color = val;
1470
1471 I915_WRITE(ILK_DPFC_CONTROL, val ?
1472 (reg | FBC_CTL_FALSE_COLOR) :
1473 (reg & ~FBC_CTL_FALSE_COLOR));
1474
1475 drm_modeset_unlock_all(dev);
1476 return 0;
1477}
1478
1479DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1480 i915_fbc_fc_get, i915_fbc_fc_set,
1481 "%llu\n");
1482
Paulo Zanoni92d44622013-05-31 16:33:24 -03001483static int i915_ips_status(struct seq_file *m, void *unused)
1484{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001485 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001486 struct drm_device *dev = node->minor->dev;
1487 struct drm_i915_private *dev_priv = dev->dev_private;
1488
Damien Lespiauf5adf942013-06-24 18:29:34 +01001489 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001490 seq_puts(m, "not supported\n");
1491 return 0;
1492 }
1493
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001494 intel_runtime_pm_get(dev_priv);
1495
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001496 seq_printf(m, "Enabled by kernel parameter: %s\n",
1497 yesno(i915.enable_ips));
1498
1499 if (INTEL_INFO(dev)->gen >= 8) {
1500 seq_puts(m, "Currently: unknown\n");
1501 } else {
1502 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1503 seq_puts(m, "Currently: enabled\n");
1504 else
1505 seq_puts(m, "Currently: disabled\n");
1506 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001507
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001508 intel_runtime_pm_put(dev_priv);
1509
Paulo Zanoni92d44622013-05-31 16:33:24 -03001510 return 0;
1511}
1512
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001513static int i915_sr_status(struct seq_file *m, void *unused)
1514{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001515 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001516 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001517 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001518 bool sr_enabled = false;
1519
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001520 intel_runtime_pm_get(dev_priv);
1521
Yuanhan Liu13982612010-12-15 15:42:31 +08001522 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001523 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001524 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001525 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1526 else if (IS_I915GM(dev))
1527 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1528 else if (IS_PINEVIEW(dev))
1529 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1530
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001531 intel_runtime_pm_put(dev_priv);
1532
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001533 seq_printf(m, "self-refresh: %s\n",
1534 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001535
1536 return 0;
1537}
1538
Jesse Barnes7648fa92010-05-20 14:28:11 -07001539static int i915_emon_status(struct seq_file *m, void *unused)
1540{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001541 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001542 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001543 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001544 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001545 int ret;
1546
Chris Wilson582be6b2012-04-30 19:35:02 +01001547 if (!IS_GEN5(dev))
1548 return -ENODEV;
1549
Chris Wilsonde227ef2010-07-03 07:58:38 +01001550 ret = mutex_lock_interruptible(&dev->struct_mutex);
1551 if (ret)
1552 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001553
1554 temp = i915_mch_val(dev_priv);
1555 chipset = i915_chipset_val(dev_priv);
1556 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001557 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001558
1559 seq_printf(m, "GMCH temp: %ld\n", temp);
1560 seq_printf(m, "Chipset power: %ld\n", chipset);
1561 seq_printf(m, "GFX power: %ld\n", gfx);
1562 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1563
1564 return 0;
1565}
1566
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001567static int i915_ring_freq_table(struct seq_file *m, void *unused)
1568{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001569 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001570 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001571 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001572 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001573 int gpu_freq, ia_freq;
1574
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001575 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001576 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001577 return 0;
1578 }
1579
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001580 intel_runtime_pm_get(dev_priv);
1581
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001582 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1583
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001584 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001585 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001586 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001587
Damien Lespiau267f0c92013-06-24 22:59:48 +01001588 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001589
Ben Widawskyb39fb292014-03-19 18:31:11 -07001590 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1591 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001592 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001593 ia_freq = gpu_freq;
1594 sandybridge_pcode_read(dev_priv,
1595 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1596 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001597 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1598 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1599 ((ia_freq >> 0) & 0xff) * 100,
1600 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001601 }
1602
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001603 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001604
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001605out:
1606 intel_runtime_pm_put(dev_priv);
1607 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001608}
1609
Chris Wilson44834a62010-08-19 16:09:23 +01001610static int i915_opregion(struct seq_file *m, void *unused)
1611{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001612 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001613 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001614 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001615 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001616 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001617 int ret;
1618
Daniel Vetter0d38f002012-04-21 22:49:10 +02001619 if (data == NULL)
1620 return -ENOMEM;
1621
Chris Wilson44834a62010-08-19 16:09:23 +01001622 ret = mutex_lock_interruptible(&dev->struct_mutex);
1623 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001624 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001625
Daniel Vetter0d38f002012-04-21 22:49:10 +02001626 if (opregion->header) {
1627 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1628 seq_write(m, data, OPREGION_SIZE);
1629 }
Chris Wilson44834a62010-08-19 16:09:23 +01001630
1631 mutex_unlock(&dev->struct_mutex);
1632
Daniel Vetter0d38f002012-04-21 22:49:10 +02001633out:
1634 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001635 return 0;
1636}
1637
Chris Wilson37811fc2010-08-25 22:45:57 +01001638static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1639{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001640 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001641 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001642 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001643 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001644
Daniel Vetter4520f532013-10-09 09:18:51 +02001645#ifdef CONFIG_DRM_I915_FBDEV
1646 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001647
1648 ifbdev = dev_priv->fbdev;
1649 fb = to_intel_framebuffer(ifbdev->helper.fb);
1650
Daniel Vetter623f9782012-12-11 16:21:38 +01001651 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001652 fb->base.width,
1653 fb->base.height,
1654 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001655 fb->base.bits_per_pixel,
1656 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001657 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001658 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001659#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001660
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001661 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001662 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001663 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001664 continue;
1665
Daniel Vetter623f9782012-12-11 16:21:38 +01001666 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001667 fb->base.width,
1668 fb->base.height,
1669 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001670 fb->base.bits_per_pixel,
1671 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001672 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001673 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001674 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001675 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001676
1677 return 0;
1678}
1679
Ben Widawskye76d3632011-03-19 18:14:29 -07001680static int i915_context_status(struct seq_file *m, void *unused)
1681{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001682 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001683 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001684 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001685 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001686 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001687 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001688
Daniel Vetterf3d28872014-05-29 23:23:08 +02001689 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001690 if (ret)
1691 return ret;
1692
Daniel Vetter3e373942012-11-02 19:55:04 +01001693 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001694 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001695 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001696 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001697 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001698
Daniel Vetter3e373942012-11-02 19:55:04 +01001699 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001700 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001701 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001702 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001703 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001704
Ben Widawskya33afea2013-09-17 21:12:45 -07001705 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoea0c76f2014-07-03 16:27:59 +01001706 if (ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001707 continue;
1708
Ben Widawskya33afea2013-09-17 21:12:45 -07001709 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001710 describe_ctx(m, ctx);
Ben Widawskya33afea2013-09-17 21:12:45 -07001711 for_each_ring(ring, dev_priv, i)
1712 if (ring->default_context == ctx)
1713 seq_printf(m, "(default context %s) ", ring->name);
1714
Oscar Mateoea0c76f2014-07-03 16:27:59 +01001715 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
Ben Widawskya33afea2013-09-17 21:12:45 -07001716 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001717 }
1718
Daniel Vetterf3d28872014-05-29 23:23:08 +02001719 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001720
1721 return 0;
1722}
1723
Ben Widawsky6d794d42011-04-25 11:25:56 -07001724static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1725{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001726 struct drm_info_node *node = m->private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001727 struct drm_device *dev = node->minor->dev;
1728 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301729 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001730
Chris Wilson907b28c2013-07-19 20:36:52 +01001731 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301732 if (IS_VALLEYVIEW(dev)) {
1733 fw_rendercount = dev_priv->uncore.fw_rendercount;
1734 fw_mediacount = dev_priv->uncore.fw_mediacount;
1735 } else
1736 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001737 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001738
Deepak S43709ba2013-11-23 14:55:44 +05301739 if (IS_VALLEYVIEW(dev)) {
1740 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1741 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1742 } else
1743 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001744
1745 return 0;
1746}
1747
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001748static const char *swizzle_string(unsigned swizzle)
1749{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001750 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001751 case I915_BIT_6_SWIZZLE_NONE:
1752 return "none";
1753 case I915_BIT_6_SWIZZLE_9:
1754 return "bit9";
1755 case I915_BIT_6_SWIZZLE_9_10:
1756 return "bit9/bit10";
1757 case I915_BIT_6_SWIZZLE_9_11:
1758 return "bit9/bit11";
1759 case I915_BIT_6_SWIZZLE_9_10_11:
1760 return "bit9/bit10/bit11";
1761 case I915_BIT_6_SWIZZLE_9_17:
1762 return "bit9/bit17";
1763 case I915_BIT_6_SWIZZLE_9_10_17:
1764 return "bit9/bit10/bit17";
1765 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001766 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001767 }
1768
1769 return "bug";
1770}
1771
1772static int i915_swizzle_info(struct seq_file *m, void *data)
1773{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001774 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001775 struct drm_device *dev = node->minor->dev;
1776 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001777 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001778
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001779 ret = mutex_lock_interruptible(&dev->struct_mutex);
1780 if (ret)
1781 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001782 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001783
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001784 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1785 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1786 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1787 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1788
1789 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1790 seq_printf(m, "DDC = 0x%08x\n",
1791 I915_READ(DCC));
1792 seq_printf(m, "C0DRB3 = 0x%04x\n",
1793 I915_READ16(C0DRB3));
1794 seq_printf(m, "C1DRB3 = 0x%04x\n",
1795 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001796 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001797 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1798 I915_READ(MAD_DIMM_C0));
1799 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1800 I915_READ(MAD_DIMM_C1));
1801 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1802 I915_READ(MAD_DIMM_C2));
1803 seq_printf(m, "TILECTL = 0x%08x\n",
1804 I915_READ(TILECTL));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001805 if (IS_GEN8(dev))
1806 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
1807 I915_READ(GAMTARBMODE));
1808 else
1809 seq_printf(m, "ARB_MODE = 0x%08x\n",
1810 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001811 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1812 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001813 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001814 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001815 mutex_unlock(&dev->struct_mutex);
1816
1817 return 0;
1818}
1819
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001820static int per_file_ctx(int id, void *ptr, void *data)
1821{
Oscar Mateo273497e2014-05-22 14:13:37 +01001822 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001823 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02001824 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
1825
1826 if (!ppgtt) {
1827 seq_printf(m, " no ppgtt for context %d\n",
1828 ctx->user_handle);
1829 return 0;
1830 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001831
Oscar Mateof83d6512014-05-22 14:13:38 +01001832 if (i915_gem_context_is_default(ctx))
1833 seq_puts(m, " default context:\n");
1834 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01001835 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001836 ppgtt->debug_dump(ppgtt, m);
1837
1838 return 0;
1839}
1840
Ben Widawsky77df6772013-11-02 21:07:30 -07001841static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001842{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001843 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001844 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07001845 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1846 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001847
Ben Widawsky77df6772013-11-02 21:07:30 -07001848 if (!ppgtt)
1849 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001850
Ben Widawsky77df6772013-11-02 21:07:30 -07001851 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08001852 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07001853 for_each_ring(ring, dev_priv, unused) {
1854 seq_printf(m, "%s\n", ring->name);
1855 for (i = 0; i < 4; i++) {
1856 u32 offset = 0x270 + i * 8;
1857 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
1858 pdp <<= 32;
1859 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03001860 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07001861 }
1862 }
1863}
1864
1865static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
1866{
1867 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001868 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001869 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07001870 int i;
1871
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001872 if (INTEL_INFO(dev)->gen == 6)
1873 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1874
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001875 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001876 seq_printf(m, "%s\n", ring->name);
1877 if (INTEL_INFO(dev)->gen == 7)
1878 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1879 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1880 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1881 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1882 }
1883 if (dev_priv->mm.aliasing_ppgtt) {
1884 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1885
Damien Lespiau267f0c92013-06-24 22:59:48 +01001886 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001887 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001888
Ben Widawsky87d60b62013-12-06 14:11:29 -08001889 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02001890 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001891
1892 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
1893 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001894
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001895 seq_printf(m, "proc: %s\n",
1896 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001897 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001898 }
1899 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07001900}
1901
1902static int i915_ppgtt_info(struct seq_file *m, void *data)
1903{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001904 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001905 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001906 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001907
1908 int ret = mutex_lock_interruptible(&dev->struct_mutex);
1909 if (ret)
1910 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001911 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07001912
1913 if (INTEL_INFO(dev)->gen >= 8)
1914 gen8_ppgtt_info(m, dev);
1915 else if (INTEL_INFO(dev)->gen >= 6)
1916 gen6_ppgtt_info(m, dev);
1917
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001918 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001919 mutex_unlock(&dev->struct_mutex);
1920
1921 return 0;
1922}
1923
Ben Widawsky63573eb2013-07-04 11:02:07 -07001924static int i915_llc(struct seq_file *m, void *data)
1925{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001926 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07001927 struct drm_device *dev = node->minor->dev;
1928 struct drm_i915_private *dev_priv = dev->dev_private;
1929
1930 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1931 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1932 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1933
1934 return 0;
1935}
1936
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001937static int i915_edp_psr_status(struct seq_file *m, void *data)
1938{
1939 struct drm_info_node *node = m->private;
1940 struct drm_device *dev = node->minor->dev;
1941 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03001942 u32 psrperf = 0;
1943 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001944
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001945 intel_runtime_pm_get(dev_priv);
1946
Daniel Vetterfa128fa2014-07-11 10:30:17 -07001947 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03001948 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
1949 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07001950 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001951 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07001952 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
1953 dev_priv->psr.busy_frontbuffer_bits);
1954 seq_printf(m, "Re-enable work scheduled: %s\n",
1955 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001956
Rodrigo Vivia031d702013-10-03 16:15:06 -03001957 enabled = HAS_PSR(dev) &&
1958 I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001959 seq_printf(m, "HW Enabled & Active bit: %s\n", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001960
Rodrigo Vivia031d702013-10-03 16:15:06 -03001961 if (HAS_PSR(dev))
1962 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
1963 EDP_PSR_PERF_CNT_MASK;
1964 seq_printf(m, "Performance_Counter: %u\n", psrperf);
Daniel Vetterfa128fa2014-07-11 10:30:17 -07001965 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001966
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001967 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001968 return 0;
1969}
1970
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001971static int i915_sink_crc(struct seq_file *m, void *data)
1972{
1973 struct drm_info_node *node = m->private;
1974 struct drm_device *dev = node->minor->dev;
1975 struct intel_encoder *encoder;
1976 struct intel_connector *connector;
1977 struct intel_dp *intel_dp = NULL;
1978 int ret;
1979 u8 crc[6];
1980
1981 drm_modeset_lock_all(dev);
1982 list_for_each_entry(connector, &dev->mode_config.connector_list,
1983 base.head) {
1984
1985 if (connector->base.dpms != DRM_MODE_DPMS_ON)
1986 continue;
1987
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02001988 if (!connector->base.encoder)
1989 continue;
1990
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001991 encoder = to_intel_encoder(connector->base.encoder);
1992 if (encoder->type != INTEL_OUTPUT_EDP)
1993 continue;
1994
1995 intel_dp = enc_to_intel_dp(&encoder->base);
1996
1997 ret = intel_dp_sink_crc(intel_dp, crc);
1998 if (ret)
1999 goto out;
2000
2001 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2002 crc[0], crc[1], crc[2],
2003 crc[3], crc[4], crc[5]);
2004 goto out;
2005 }
2006 ret = -ENODEV;
2007out:
2008 drm_modeset_unlock_all(dev);
2009 return ret;
2010}
2011
Jesse Barnesec013e72013-08-20 10:29:23 +01002012static int i915_energy_uJ(struct seq_file *m, void *data)
2013{
2014 struct drm_info_node *node = m->private;
2015 struct drm_device *dev = node->minor->dev;
2016 struct drm_i915_private *dev_priv = dev->dev_private;
2017 u64 power;
2018 u32 units;
2019
2020 if (INTEL_INFO(dev)->gen < 6)
2021 return -ENODEV;
2022
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002023 intel_runtime_pm_get(dev_priv);
2024
Jesse Barnesec013e72013-08-20 10:29:23 +01002025 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2026 power = (power & 0x1f00) >> 8;
2027 units = 1000000 / (1 << power); /* convert to uJ */
2028 power = I915_READ(MCH_SECP_NRG_STTS);
2029 power *= units;
2030
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002031 intel_runtime_pm_put(dev_priv);
2032
Jesse Barnesec013e72013-08-20 10:29:23 +01002033 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002034
2035 return 0;
2036}
2037
2038static int i915_pc8_status(struct seq_file *m, void *unused)
2039{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002040 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002041 struct drm_device *dev = node->minor->dev;
2042 struct drm_i915_private *dev_priv = dev->dev_private;
2043
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002044 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002045 seq_puts(m, "not supported\n");
2046 return 0;
2047 }
2048
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002049 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002050 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002051 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002052
Jesse Barnesec013e72013-08-20 10:29:23 +01002053 return 0;
2054}
2055
Imre Deak1da51582013-11-25 17:15:35 +02002056static const char *power_domain_str(enum intel_display_power_domain domain)
2057{
2058 switch (domain) {
2059 case POWER_DOMAIN_PIPE_A:
2060 return "PIPE_A";
2061 case POWER_DOMAIN_PIPE_B:
2062 return "PIPE_B";
2063 case POWER_DOMAIN_PIPE_C:
2064 return "PIPE_C";
2065 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2066 return "PIPE_A_PANEL_FITTER";
2067 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2068 return "PIPE_B_PANEL_FITTER";
2069 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2070 return "PIPE_C_PANEL_FITTER";
2071 case POWER_DOMAIN_TRANSCODER_A:
2072 return "TRANSCODER_A";
2073 case POWER_DOMAIN_TRANSCODER_B:
2074 return "TRANSCODER_B";
2075 case POWER_DOMAIN_TRANSCODER_C:
2076 return "TRANSCODER_C";
2077 case POWER_DOMAIN_TRANSCODER_EDP:
2078 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002079 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2080 return "PORT_DDI_A_2_LANES";
2081 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2082 return "PORT_DDI_A_4_LANES";
2083 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2084 return "PORT_DDI_B_2_LANES";
2085 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2086 return "PORT_DDI_B_4_LANES";
2087 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2088 return "PORT_DDI_C_2_LANES";
2089 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2090 return "PORT_DDI_C_4_LANES";
2091 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2092 return "PORT_DDI_D_2_LANES";
2093 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2094 return "PORT_DDI_D_4_LANES";
2095 case POWER_DOMAIN_PORT_DSI:
2096 return "PORT_DSI";
2097 case POWER_DOMAIN_PORT_CRT:
2098 return "PORT_CRT";
2099 case POWER_DOMAIN_PORT_OTHER:
2100 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002101 case POWER_DOMAIN_VGA:
2102 return "VGA";
2103 case POWER_DOMAIN_AUDIO:
2104 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002105 case POWER_DOMAIN_PLLS:
2106 return "PLLS";
Imre Deak1da51582013-11-25 17:15:35 +02002107 case POWER_DOMAIN_INIT:
2108 return "INIT";
2109 default:
2110 WARN_ON(1);
2111 return "?";
2112 }
2113}
2114
2115static int i915_power_domain_info(struct seq_file *m, void *unused)
2116{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002117 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002118 struct drm_device *dev = node->minor->dev;
2119 struct drm_i915_private *dev_priv = dev->dev_private;
2120 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2121 int i;
2122
2123 mutex_lock(&power_domains->lock);
2124
2125 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2126 for (i = 0; i < power_domains->power_well_count; i++) {
2127 struct i915_power_well *power_well;
2128 enum intel_display_power_domain power_domain;
2129
2130 power_well = &power_domains->power_wells[i];
2131 seq_printf(m, "%-25s %d\n", power_well->name,
2132 power_well->count);
2133
2134 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2135 power_domain++) {
2136 if (!(BIT(power_domain) & power_well->domains))
2137 continue;
2138
2139 seq_printf(m, " %-23s %d\n",
2140 power_domain_str(power_domain),
2141 power_domains->domain_use_count[power_domain]);
2142 }
2143 }
2144
2145 mutex_unlock(&power_domains->lock);
2146
2147 return 0;
2148}
2149
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002150static void intel_seq_print_mode(struct seq_file *m, int tabs,
2151 struct drm_display_mode *mode)
2152{
2153 int i;
2154
2155 for (i = 0; i < tabs; i++)
2156 seq_putc(m, '\t');
2157
2158 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",
2159 mode->base.id, mode->name,
2160 mode->vrefresh, mode->clock,
2161 mode->hdisplay, mode->hsync_start,
2162 mode->hsync_end, mode->htotal,
2163 mode->vdisplay, mode->vsync_start,
2164 mode->vsync_end, mode->vtotal,
2165 mode->type, mode->flags);
2166}
2167
2168static void intel_encoder_info(struct seq_file *m,
2169 struct intel_crtc *intel_crtc,
2170 struct intel_encoder *intel_encoder)
2171{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002172 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002173 struct drm_device *dev = node->minor->dev;
2174 struct drm_crtc *crtc = &intel_crtc->base;
2175 struct intel_connector *intel_connector;
2176 struct drm_encoder *encoder;
2177
2178 encoder = &intel_encoder->base;
2179 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002180 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002181 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2182 struct drm_connector *connector = &intel_connector->base;
2183 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2184 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002185 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002186 drm_get_connector_status_name(connector->status));
2187 if (connector->status == connector_status_connected) {
2188 struct drm_display_mode *mode = &crtc->mode;
2189 seq_printf(m, ", mode:\n");
2190 intel_seq_print_mode(m, 2, mode);
2191 } else {
2192 seq_putc(m, '\n');
2193 }
2194 }
2195}
2196
2197static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2198{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002199 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002200 struct drm_device *dev = node->minor->dev;
2201 struct drm_crtc *crtc = &intel_crtc->base;
2202 struct intel_encoder *intel_encoder;
2203
Matt Roper5aa8a932014-06-16 10:12:55 -07002204 if (crtc->primary->fb)
2205 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2206 crtc->primary->fb->base.id, crtc->x, crtc->y,
2207 crtc->primary->fb->width, crtc->primary->fb->height);
2208 else
2209 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002210 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2211 intel_encoder_info(m, intel_crtc, intel_encoder);
2212}
2213
2214static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2215{
2216 struct drm_display_mode *mode = panel->fixed_mode;
2217
2218 seq_printf(m, "\tfixed mode:\n");
2219 intel_seq_print_mode(m, 2, mode);
2220}
2221
2222static void intel_dp_info(struct seq_file *m,
2223 struct intel_connector *intel_connector)
2224{
2225 struct intel_encoder *intel_encoder = intel_connector->encoder;
2226 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2227
2228 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2229 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2230 "no");
2231 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2232 intel_panel_info(m, &intel_connector->panel);
2233}
2234
2235static void intel_hdmi_info(struct seq_file *m,
2236 struct intel_connector *intel_connector)
2237{
2238 struct intel_encoder *intel_encoder = intel_connector->encoder;
2239 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2240
2241 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2242 "no");
2243}
2244
2245static void intel_lvds_info(struct seq_file *m,
2246 struct intel_connector *intel_connector)
2247{
2248 intel_panel_info(m, &intel_connector->panel);
2249}
2250
2251static void intel_connector_info(struct seq_file *m,
2252 struct drm_connector *connector)
2253{
2254 struct intel_connector *intel_connector = to_intel_connector(connector);
2255 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002256 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002257
2258 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002259 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002260 drm_get_connector_status_name(connector->status));
2261 if (connector->status == connector_status_connected) {
2262 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2263 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2264 connector->display_info.width_mm,
2265 connector->display_info.height_mm);
2266 seq_printf(m, "\tsubpixel order: %s\n",
2267 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2268 seq_printf(m, "\tCEA rev: %d\n",
2269 connector->display_info.cea_rev);
2270 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002271 if (intel_encoder) {
2272 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2273 intel_encoder->type == INTEL_OUTPUT_EDP)
2274 intel_dp_info(m, intel_connector);
2275 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2276 intel_hdmi_info(m, intel_connector);
2277 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2278 intel_lvds_info(m, intel_connector);
2279 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002280
Jesse Barnesf103fc72014-02-20 12:39:57 -08002281 seq_printf(m, "\tmodes:\n");
2282 list_for_each_entry(mode, &connector->modes, head)
2283 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002284}
2285
Chris Wilson065f2ec2014-03-12 09:13:13 +00002286static bool cursor_active(struct drm_device *dev, int pipe)
2287{
2288 struct drm_i915_private *dev_priv = dev->dev_private;
2289 u32 state;
2290
2291 if (IS_845G(dev) || IS_I865G(dev))
2292 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002293 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002294 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002295
2296 return state;
2297}
2298
2299static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2300{
2301 struct drm_i915_private *dev_priv = dev->dev_private;
2302 u32 pos;
2303
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002304 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002305
2306 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2307 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2308 *x = -*x;
2309
2310 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2311 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2312 *y = -*y;
2313
2314 return cursor_active(dev, pipe);
2315}
2316
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002317static int i915_display_info(struct seq_file *m, void *unused)
2318{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002319 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002320 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002321 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002322 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002323 struct drm_connector *connector;
2324
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002325 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002326 drm_modeset_lock_all(dev);
2327 seq_printf(m, "CRTC info\n");
2328 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002329 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002330 bool active;
2331 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002332
Chris Wilson57127ef2014-07-04 08:20:11 +01002333 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002334 crtc->base.base.id, pipe_name(crtc->pipe),
Chris Wilson57127ef2014-07-04 08:20:11 +01002335 yesno(crtc->active), crtc->config.pipe_src_w, crtc->config.pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002336 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002337 intel_crtc_info(m, crtc);
2338
Paulo Zanonia23dc652014-04-01 14:55:11 -03002339 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002340 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x, active? %s\n",
Chris Wilson4b0e3332014-05-30 16:35:26 +03002341 yesno(crtc->cursor_base),
Chris Wilson57127ef2014-07-04 08:20:11 +01002342 x, y, crtc->cursor_width, crtc->cursor_height,
2343 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002344 }
Daniel Vettercace8412014-05-22 17:56:31 +02002345
2346 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2347 yesno(!crtc->cpu_fifo_underrun_disabled),
2348 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002349 }
2350
2351 seq_printf(m, "\n");
2352 seq_printf(m, "Connector info\n");
2353 seq_printf(m, "--------------\n");
2354 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2355 intel_connector_info(m, connector);
2356 }
2357 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002358 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002359
2360 return 0;
2361}
2362
Ben Widawskye04934c2014-06-30 09:53:42 -07002363static int i915_semaphore_status(struct seq_file *m, void *unused)
2364{
2365 struct drm_info_node *node = (struct drm_info_node *) m->private;
2366 struct drm_device *dev = node->minor->dev;
2367 struct drm_i915_private *dev_priv = dev->dev_private;
2368 struct intel_engine_cs *ring;
2369 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2370 int i, j, ret;
2371
2372 if (!i915_semaphore_is_enabled(dev)) {
2373 seq_puts(m, "Semaphores are disabled\n");
2374 return 0;
2375 }
2376
2377 ret = mutex_lock_interruptible(&dev->struct_mutex);
2378 if (ret)
2379 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002380 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002381
2382 if (IS_BROADWELL(dev)) {
2383 struct page *page;
2384 uint64_t *seqno;
2385
2386 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2387
2388 seqno = (uint64_t *)kmap_atomic(page);
2389 for_each_ring(ring, dev_priv, i) {
2390 uint64_t offset;
2391
2392 seq_printf(m, "%s\n", ring->name);
2393
2394 seq_puts(m, " Last signal:");
2395 for (j = 0; j < num_rings; j++) {
2396 offset = i * I915_NUM_RINGS + j;
2397 seq_printf(m, "0x%08llx (0x%02llx) ",
2398 seqno[offset], offset * 8);
2399 }
2400 seq_putc(m, '\n');
2401
2402 seq_puts(m, " Last wait: ");
2403 for (j = 0; j < num_rings; j++) {
2404 offset = i + (j * I915_NUM_RINGS);
2405 seq_printf(m, "0x%08llx (0x%02llx) ",
2406 seqno[offset], offset * 8);
2407 }
2408 seq_putc(m, '\n');
2409
2410 }
2411 kunmap_atomic(seqno);
2412 } else {
2413 seq_puts(m, " Last signal:");
2414 for_each_ring(ring, dev_priv, i)
2415 for (j = 0; j < num_rings; j++)
2416 seq_printf(m, "0x%08x\n",
2417 I915_READ(ring->semaphore.mbox.signal[j]));
2418 seq_putc(m, '\n');
2419 }
2420
2421 seq_puts(m, "\nSync seqno:\n");
2422 for_each_ring(ring, dev_priv, i) {
2423 for (j = 0; j < num_rings; j++) {
2424 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2425 }
2426 seq_putc(m, '\n');
2427 }
2428 seq_putc(m, '\n');
2429
Paulo Zanoni03872062014-07-09 14:31:57 -03002430 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002431 mutex_unlock(&dev->struct_mutex);
2432 return 0;
2433}
2434
Daniel Vetter728e29d2014-06-25 22:01:53 +03002435static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2436{
2437 struct drm_info_node *node = (struct drm_info_node *) m->private;
2438 struct drm_device *dev = node->minor->dev;
2439 struct drm_i915_private *dev_priv = dev->dev_private;
2440 int i;
2441
2442 drm_modeset_lock_all(dev);
2443 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2444 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2445
2446 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
2447 seq_printf(m, " refcount: %i, active: %i, on: %s\n", pll->refcount,
2448 pll->active, yesno(pll->on));
2449 seq_printf(m, " tracked hardware state:\n");
2450 seq_printf(m, " dpll: 0x%08x\n", pll->hw_state.dpll);
2451 seq_printf(m, " dpll_md: 0x%08x\n", pll->hw_state.dpll_md);
2452 seq_printf(m, " fp0: 0x%08x\n", pll->hw_state.fp0);
2453 seq_printf(m, " fp1: 0x%08x\n", pll->hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03002454 seq_printf(m, " wrpll: 0x%08x\n", pll->hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002455 }
2456 drm_modeset_unlock_all(dev);
2457
2458 return 0;
2459}
2460
Damien Lespiau07144422013-10-15 18:55:40 +01002461struct pipe_crc_info {
2462 const char *name;
2463 struct drm_device *dev;
2464 enum pipe pipe;
2465};
2466
Dave Airlie11bed952014-05-12 15:22:27 +10002467static int i915_dp_mst_info(struct seq_file *m, void *unused)
2468{
2469 struct drm_info_node *node = (struct drm_info_node *) m->private;
2470 struct drm_device *dev = node->minor->dev;
2471 struct drm_encoder *encoder;
2472 struct intel_encoder *intel_encoder;
2473 struct intel_digital_port *intel_dig_port;
2474 drm_modeset_lock_all(dev);
2475 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2476 intel_encoder = to_intel_encoder(encoder);
2477 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2478 continue;
2479 intel_dig_port = enc_to_dig_port(encoder);
2480 if (!intel_dig_port->dp.can_mst)
2481 continue;
2482
2483 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
2484 }
2485 drm_modeset_unlock_all(dev);
2486 return 0;
2487}
2488
Damien Lespiau07144422013-10-15 18:55:40 +01002489static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002490{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002491 struct pipe_crc_info *info = inode->i_private;
2492 struct drm_i915_private *dev_priv = info->dev->dev_private;
2493 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2494
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002495 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2496 return -ENODEV;
2497
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002498 spin_lock_irq(&pipe_crc->lock);
2499
2500 if (pipe_crc->opened) {
2501 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002502 return -EBUSY; /* already open */
2503 }
2504
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002505 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002506 filep->private_data = inode->i_private;
2507
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002508 spin_unlock_irq(&pipe_crc->lock);
2509
Damien Lespiau07144422013-10-15 18:55:40 +01002510 return 0;
2511}
2512
2513static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2514{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002515 struct pipe_crc_info *info = inode->i_private;
2516 struct drm_i915_private *dev_priv = info->dev->dev_private;
2517 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2518
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002519 spin_lock_irq(&pipe_crc->lock);
2520 pipe_crc->opened = false;
2521 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002522
Damien Lespiau07144422013-10-15 18:55:40 +01002523 return 0;
2524}
2525
2526/* (6 fields, 8 chars each, space separated (5) + '\n') */
2527#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2528/* account for \'0' */
2529#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2530
2531static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2532{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002533 assert_spin_locked(&pipe_crc->lock);
2534 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2535 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002536}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002537
Damien Lespiau07144422013-10-15 18:55:40 +01002538static ssize_t
2539i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2540 loff_t *pos)
2541{
2542 struct pipe_crc_info *info = filep->private_data;
2543 struct drm_device *dev = info->dev;
2544 struct drm_i915_private *dev_priv = dev->dev_private;
2545 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2546 char buf[PIPE_CRC_BUFFER_LEN];
2547 int head, tail, n_entries, n;
2548 ssize_t bytes_read;
2549
2550 /*
2551 * Don't allow user space to provide buffers not big enough to hold
2552 * a line of data.
2553 */
2554 if (count < PIPE_CRC_LINE_LEN)
2555 return -EINVAL;
2556
2557 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2558 return 0;
2559
2560 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002561 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002562 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002563 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002564
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002565 if (filep->f_flags & O_NONBLOCK) {
2566 spin_unlock_irq(&pipe_crc->lock);
2567 return -EAGAIN;
2568 }
2569
2570 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2571 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2572 if (ret) {
2573 spin_unlock_irq(&pipe_crc->lock);
2574 return ret;
2575 }
Damien Lespiau07144422013-10-15 18:55:40 +01002576 }
2577
2578 /* We now have one or more entries to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002579 head = pipe_crc->head;
2580 tail = pipe_crc->tail;
Damien Lespiau07144422013-10-15 18:55:40 +01002581 n_entries = min((size_t)CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR),
2582 count / PIPE_CRC_LINE_LEN);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002583 spin_unlock_irq(&pipe_crc->lock);
2584
Damien Lespiau07144422013-10-15 18:55:40 +01002585 bytes_read = 0;
2586 n = 0;
2587 do {
2588 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
2589 int ret;
2590
2591 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2592 "%8u %8x %8x %8x %8x %8x\n",
2593 entry->frame, entry->crc[0],
2594 entry->crc[1], entry->crc[2],
2595 entry->crc[3], entry->crc[4]);
2596
2597 ret = copy_to_user(user_buf + n * PIPE_CRC_LINE_LEN,
2598 buf, PIPE_CRC_LINE_LEN);
2599 if (ret == PIPE_CRC_LINE_LEN)
2600 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002601
2602 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2603 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiau07144422013-10-15 18:55:40 +01002604 n++;
2605 } while (--n_entries);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002606
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002607 spin_lock_irq(&pipe_crc->lock);
2608 pipe_crc->tail = tail;
2609 spin_unlock_irq(&pipe_crc->lock);
2610
Damien Lespiau07144422013-10-15 18:55:40 +01002611 return bytes_read;
2612}
2613
2614static const struct file_operations i915_pipe_crc_fops = {
2615 .owner = THIS_MODULE,
2616 .open = i915_pipe_crc_open,
2617 .read = i915_pipe_crc_read,
2618 .release = i915_pipe_crc_release,
2619};
2620
2621static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2622 {
2623 .name = "i915_pipe_A_crc",
2624 .pipe = PIPE_A,
2625 },
2626 {
2627 .name = "i915_pipe_B_crc",
2628 .pipe = PIPE_B,
2629 },
2630 {
2631 .name = "i915_pipe_C_crc",
2632 .pipe = PIPE_C,
2633 },
2634};
2635
2636static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2637 enum pipe pipe)
2638{
2639 struct drm_device *dev = minor->dev;
2640 struct dentry *ent;
2641 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2642
2643 info->dev = dev;
2644 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2645 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08002646 if (!ent)
2647 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01002648
2649 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002650}
2651
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002652static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002653 "none",
2654 "plane1",
2655 "plane2",
2656 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002657 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002658 "TV",
2659 "DP-B",
2660 "DP-C",
2661 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002662 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002663};
2664
2665static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2666{
2667 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2668 return pipe_crc_sources[source];
2669}
2670
Damien Lespiaubd9db022013-10-15 18:55:36 +01002671static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002672{
2673 struct drm_device *dev = m->private;
2674 struct drm_i915_private *dev_priv = dev->dev_private;
2675 int i;
2676
2677 for (i = 0; i < I915_MAX_PIPES; i++)
2678 seq_printf(m, "%c %s\n", pipe_name(i),
2679 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2680
2681 return 0;
2682}
2683
Damien Lespiaubd9db022013-10-15 18:55:36 +01002684static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02002685{
2686 struct drm_device *dev = inode->i_private;
2687
Damien Lespiaubd9db022013-10-15 18:55:36 +01002688 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02002689}
2690
Daniel Vetter46a19182013-11-01 10:50:20 +01002691static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02002692 uint32_t *val)
2693{
Daniel Vetter46a19182013-11-01 10:50:20 +01002694 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2695 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2696
2697 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02002698 case INTEL_PIPE_CRC_SOURCE_PIPE:
2699 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
2700 break;
2701 case INTEL_PIPE_CRC_SOURCE_NONE:
2702 *val = 0;
2703 break;
2704 default:
2705 return -EINVAL;
2706 }
2707
2708 return 0;
2709}
2710
Daniel Vetter46a19182013-11-01 10:50:20 +01002711static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
2712 enum intel_pipe_crc_source *source)
2713{
2714 struct intel_encoder *encoder;
2715 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01002716 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01002717 int ret = 0;
2718
2719 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2720
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002721 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01002722 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01002723 if (!encoder->base.crtc)
2724 continue;
2725
2726 crtc = to_intel_crtc(encoder->base.crtc);
2727
2728 if (crtc->pipe != pipe)
2729 continue;
2730
2731 switch (encoder->type) {
2732 case INTEL_OUTPUT_TVOUT:
2733 *source = INTEL_PIPE_CRC_SOURCE_TV;
2734 break;
2735 case INTEL_OUTPUT_DISPLAYPORT:
2736 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01002737 dig_port = enc_to_dig_port(&encoder->base);
2738 switch (dig_port->port) {
2739 case PORT_B:
2740 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
2741 break;
2742 case PORT_C:
2743 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
2744 break;
2745 case PORT_D:
2746 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
2747 break;
2748 default:
2749 WARN(1, "nonexisting DP port %c\n",
2750 port_name(dig_port->port));
2751 break;
2752 }
Daniel Vetter46a19182013-11-01 10:50:20 +01002753 break;
2754 }
2755 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002756 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002757
2758 return ret;
2759}
2760
2761static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
2762 enum pipe pipe,
2763 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02002764 uint32_t *val)
2765{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002766 struct drm_i915_private *dev_priv = dev->dev_private;
2767 bool need_stable_symbols = false;
2768
Daniel Vetter46a19182013-11-01 10:50:20 +01002769 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2770 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2771 if (ret)
2772 return ret;
2773 }
2774
2775 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02002776 case INTEL_PIPE_CRC_SOURCE_PIPE:
2777 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
2778 break;
2779 case INTEL_PIPE_CRC_SOURCE_DP_B:
2780 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002781 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002782 break;
2783 case INTEL_PIPE_CRC_SOURCE_DP_C:
2784 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002785 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002786 break;
2787 case INTEL_PIPE_CRC_SOURCE_NONE:
2788 *val = 0;
2789 break;
2790 default:
2791 return -EINVAL;
2792 }
2793
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002794 /*
2795 * When the pipe CRC tap point is after the transcoders we need
2796 * to tweak symbol-level features to produce a deterministic series of
2797 * symbols for a given frame. We need to reset those features only once
2798 * a frame (instead of every nth symbol):
2799 * - DC-balance: used to ensure a better clock recovery from the data
2800 * link (SDVO)
2801 * - DisplayPort scrambling: used for EMI reduction
2802 */
2803 if (need_stable_symbols) {
2804 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2805
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002806 tmp |= DC_BALANCE_RESET_VLV;
2807 if (pipe == PIPE_A)
2808 tmp |= PIPE_A_SCRAMBLE_RESET;
2809 else
2810 tmp |= PIPE_B_SCRAMBLE_RESET;
2811
2812 I915_WRITE(PORT_DFT2_G4X, tmp);
2813 }
2814
Daniel Vetter7ac01292013-10-18 16:37:06 +02002815 return 0;
2816}
2817
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002818static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01002819 enum pipe pipe,
2820 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002821 uint32_t *val)
2822{
Daniel Vetter84093602013-11-01 10:50:21 +01002823 struct drm_i915_private *dev_priv = dev->dev_private;
2824 bool need_stable_symbols = false;
2825
Daniel Vetter46a19182013-11-01 10:50:20 +01002826 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2827 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2828 if (ret)
2829 return ret;
2830 }
2831
2832 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002833 case INTEL_PIPE_CRC_SOURCE_PIPE:
2834 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
2835 break;
2836 case INTEL_PIPE_CRC_SOURCE_TV:
2837 if (!SUPPORTS_TV(dev))
2838 return -EINVAL;
2839 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
2840 break;
2841 case INTEL_PIPE_CRC_SOURCE_DP_B:
2842 if (!IS_G4X(dev))
2843 return -EINVAL;
2844 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002845 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002846 break;
2847 case INTEL_PIPE_CRC_SOURCE_DP_C:
2848 if (!IS_G4X(dev))
2849 return -EINVAL;
2850 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002851 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002852 break;
2853 case INTEL_PIPE_CRC_SOURCE_DP_D:
2854 if (!IS_G4X(dev))
2855 return -EINVAL;
2856 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002857 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002858 break;
2859 case INTEL_PIPE_CRC_SOURCE_NONE:
2860 *val = 0;
2861 break;
2862 default:
2863 return -EINVAL;
2864 }
2865
Daniel Vetter84093602013-11-01 10:50:21 +01002866 /*
2867 * When the pipe CRC tap point is after the transcoders we need
2868 * to tweak symbol-level features to produce a deterministic series of
2869 * symbols for a given frame. We need to reset those features only once
2870 * a frame (instead of every nth symbol):
2871 * - DC-balance: used to ensure a better clock recovery from the data
2872 * link (SDVO)
2873 * - DisplayPort scrambling: used for EMI reduction
2874 */
2875 if (need_stable_symbols) {
2876 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2877
2878 WARN_ON(!IS_G4X(dev));
2879
2880 I915_WRITE(PORT_DFT_I9XX,
2881 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
2882
2883 if (pipe == PIPE_A)
2884 tmp |= PIPE_A_SCRAMBLE_RESET;
2885 else
2886 tmp |= PIPE_B_SCRAMBLE_RESET;
2887
2888 I915_WRITE(PORT_DFT2_G4X, tmp);
2889 }
2890
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002891 return 0;
2892}
2893
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002894static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
2895 enum pipe pipe)
2896{
2897 struct drm_i915_private *dev_priv = dev->dev_private;
2898 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2899
2900 if (pipe == PIPE_A)
2901 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2902 else
2903 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2904 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
2905 tmp &= ~DC_BALANCE_RESET_VLV;
2906 I915_WRITE(PORT_DFT2_G4X, tmp);
2907
2908}
2909
Daniel Vetter84093602013-11-01 10:50:21 +01002910static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
2911 enum pipe pipe)
2912{
2913 struct drm_i915_private *dev_priv = dev->dev_private;
2914 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2915
2916 if (pipe == PIPE_A)
2917 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2918 else
2919 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2920 I915_WRITE(PORT_DFT2_G4X, tmp);
2921
2922 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
2923 I915_WRITE(PORT_DFT_I9XX,
2924 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
2925 }
2926}
2927
Daniel Vetter46a19182013-11-01 10:50:20 +01002928static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002929 uint32_t *val)
2930{
Daniel Vetter46a19182013-11-01 10:50:20 +01002931 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2932 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2933
2934 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002935 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2936 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
2937 break;
2938 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2939 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
2940 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002941 case INTEL_PIPE_CRC_SOURCE_PIPE:
2942 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
2943 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002944 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002945 *val = 0;
2946 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002947 default:
2948 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002949 }
2950
2951 return 0;
2952}
2953
Daniel Vetterfabf6e52014-05-29 14:10:22 +02002954static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
2955{
2956 struct drm_i915_private *dev_priv = dev->dev_private;
2957 struct intel_crtc *crtc =
2958 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
2959
2960 drm_modeset_lock_all(dev);
2961 /*
2962 * If we use the eDP transcoder we need to make sure that we don't
2963 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
2964 * relevant on hsw with pipe A when using the always-on power well
2965 * routing.
2966 */
2967 if (crtc->config.cpu_transcoder == TRANSCODER_EDP &&
2968 !crtc->config.pch_pfit.enabled) {
2969 crtc->config.pch_pfit.force_thru = true;
2970
2971 intel_display_power_get(dev_priv,
2972 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
2973
2974 dev_priv->display.crtc_disable(&crtc->base);
2975 dev_priv->display.crtc_enable(&crtc->base);
2976 }
2977 drm_modeset_unlock_all(dev);
2978}
2979
2980static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
2981{
2982 struct drm_i915_private *dev_priv = dev->dev_private;
2983 struct intel_crtc *crtc =
2984 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
2985
2986 drm_modeset_lock_all(dev);
2987 /*
2988 * If we use the eDP transcoder we need to make sure that we don't
2989 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
2990 * relevant on hsw with pipe A when using the always-on power well
2991 * routing.
2992 */
2993 if (crtc->config.pch_pfit.force_thru) {
2994 crtc->config.pch_pfit.force_thru = false;
2995
2996 dev_priv->display.crtc_disable(&crtc->base);
2997 dev_priv->display.crtc_enable(&crtc->base);
2998
2999 intel_display_power_put(dev_priv,
3000 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3001 }
3002 drm_modeset_unlock_all(dev);
3003}
3004
3005static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3006 enum pipe pipe,
3007 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003008 uint32_t *val)
3009{
Daniel Vetter46a19182013-11-01 10:50:20 +01003010 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3011 *source = INTEL_PIPE_CRC_SOURCE_PF;
3012
3013 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003014 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3015 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3016 break;
3017 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3018 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3019 break;
3020 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003021 if (IS_HASWELL(dev) && pipe == PIPE_A)
3022 hsw_trans_edp_pipe_A_crc_wa(dev);
3023
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003024 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3025 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003026 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003027 *val = 0;
3028 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003029 default:
3030 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003031 }
3032
3033 return 0;
3034}
3035
Daniel Vetter926321d2013-10-16 13:30:34 +02003036static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3037 enum intel_pipe_crc_source source)
3038{
3039 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003040 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Borislav Petkov432f3342013-11-21 16:49:46 +01003041 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003042 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003043
Damien Lespiaucc3da172013-10-15 18:55:31 +01003044 if (pipe_crc->source == source)
3045 return 0;
3046
Damien Lespiauae676fc2013-10-15 18:55:32 +01003047 /* forbid changing the source without going back to 'none' */
3048 if (pipe_crc->source && source)
3049 return -EINVAL;
3050
Daniel Vetter52f843f2013-10-21 17:26:38 +02003051 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003052 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003053 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003054 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003055 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003056 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003057 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003058 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003059 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003060 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003061
3062 if (ret != 0)
3063 return ret;
3064
Damien Lespiau4b584362013-10-15 18:55:33 +01003065 /* none -> real source transition */
3066 if (source) {
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003067 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3068 pipe_name(pipe), pipe_crc_source_name(source));
3069
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003070 pipe_crc->entries = kzalloc(sizeof(*pipe_crc->entries) *
3071 INTEL_PIPE_CRC_ENTRIES_NR,
3072 GFP_KERNEL);
3073 if (!pipe_crc->entries)
3074 return -ENOMEM;
3075
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003076 spin_lock_irq(&pipe_crc->lock);
3077 pipe_crc->head = 0;
3078 pipe_crc->tail = 0;
3079 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003080 }
3081
Damien Lespiaucc3da172013-10-15 18:55:31 +01003082 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003083
Daniel Vetter926321d2013-10-16 13:30:34 +02003084 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3085 POSTING_READ(PIPE_CRC_CTL(pipe));
3086
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003087 /* real source -> none transition */
3088 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003089 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003090 struct intel_crtc *crtc =
3091 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003092
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003093 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3094 pipe_name(pipe));
3095
Daniel Vettera33d7102014-06-06 08:22:08 +02003096 drm_modeset_lock(&crtc->base.mutex, NULL);
3097 if (crtc->active)
3098 intel_wait_for_vblank(dev, pipe);
3099 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003100
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003101 spin_lock_irq(&pipe_crc->lock);
3102 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003103 pipe_crc->entries = NULL;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003104 spin_unlock_irq(&pipe_crc->lock);
3105
3106 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003107
3108 if (IS_G4X(dev))
3109 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003110 else if (IS_VALLEYVIEW(dev))
3111 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003112 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3113 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003114 }
3115
Daniel Vetter926321d2013-10-16 13:30:34 +02003116 return 0;
3117}
3118
3119/*
3120 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003121 * command: wsp* object wsp+ name wsp+ source wsp*
3122 * object: 'pipe'
3123 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003124 * source: (none | plane1 | plane2 | pf)
3125 * wsp: (#0x20 | #0x9 | #0xA)+
3126 *
3127 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003128 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3129 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003130 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003131static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003132{
3133 int n_words = 0;
3134
3135 while (*buf) {
3136 char *end;
3137
3138 /* skip leading white space */
3139 buf = skip_spaces(buf);
3140 if (!*buf)
3141 break; /* end of buffer */
3142
3143 /* find end of word */
3144 for (end = buf; *end && !isspace(*end); end++)
3145 ;
3146
3147 if (n_words == max_words) {
3148 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3149 max_words);
3150 return -EINVAL; /* ran out of words[] before bytes */
3151 }
3152
3153 if (*end)
3154 *end++ = '\0';
3155 words[n_words++] = buf;
3156 buf = end;
3157 }
3158
3159 return n_words;
3160}
3161
Damien Lespiaub94dec82013-10-15 18:55:35 +01003162enum intel_pipe_crc_object {
3163 PIPE_CRC_OBJECT_PIPE,
3164};
3165
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003166static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003167 "pipe",
3168};
3169
3170static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003171display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003172{
3173 int i;
3174
3175 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3176 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003177 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003178 return 0;
3179 }
3180
3181 return -EINVAL;
3182}
3183
Damien Lespiaubd9db022013-10-15 18:55:36 +01003184static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003185{
3186 const char name = buf[0];
3187
3188 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3189 return -EINVAL;
3190
3191 *pipe = name - 'A';
3192
3193 return 0;
3194}
3195
3196static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003197display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003198{
3199 int i;
3200
3201 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3202 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003203 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003204 return 0;
3205 }
3206
3207 return -EINVAL;
3208}
3209
Damien Lespiaubd9db022013-10-15 18:55:36 +01003210static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003211{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003212#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003213 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003214 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003215 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003216 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003217 enum intel_pipe_crc_source source;
3218
Damien Lespiaubd9db022013-10-15 18:55:36 +01003219 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003220 if (n_words != N_WORDS) {
3221 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3222 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003223 return -EINVAL;
3224 }
3225
Damien Lespiaubd9db022013-10-15 18:55:36 +01003226 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003227 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003228 return -EINVAL;
3229 }
3230
Damien Lespiaubd9db022013-10-15 18:55:36 +01003231 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003232 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3233 return -EINVAL;
3234 }
3235
Damien Lespiaubd9db022013-10-15 18:55:36 +01003236 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003237 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003238 return -EINVAL;
3239 }
3240
3241 return pipe_crc_set_source(dev, pipe, source);
3242}
3243
Damien Lespiaubd9db022013-10-15 18:55:36 +01003244static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3245 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003246{
3247 struct seq_file *m = file->private_data;
3248 struct drm_device *dev = m->private;
3249 char *tmpbuf;
3250 int ret;
3251
3252 if (len == 0)
3253 return 0;
3254
3255 if (len > PAGE_SIZE - 1) {
3256 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3257 PAGE_SIZE);
3258 return -E2BIG;
3259 }
3260
3261 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3262 if (!tmpbuf)
3263 return -ENOMEM;
3264
3265 if (copy_from_user(tmpbuf, ubuf, len)) {
3266 ret = -EFAULT;
3267 goto out;
3268 }
3269 tmpbuf[len] = '\0';
3270
Damien Lespiaubd9db022013-10-15 18:55:36 +01003271 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003272
3273out:
3274 kfree(tmpbuf);
3275 if (ret < 0)
3276 return ret;
3277
3278 *offp += len;
3279 return len;
3280}
3281
Damien Lespiaubd9db022013-10-15 18:55:36 +01003282static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003283 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003284 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003285 .read = seq_read,
3286 .llseek = seq_lseek,
3287 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003288 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003289};
3290
Ville Syrjälä369a1342014-01-22 14:36:08 +02003291static void wm_latency_show(struct seq_file *m, const uint16_t wm[5])
3292{
3293 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003294 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003295 int level;
3296
3297 drm_modeset_lock_all(dev);
3298
3299 for (level = 0; level < num_levels; level++) {
3300 unsigned int latency = wm[level];
3301
3302 /* WM1+ latency values in 0.5us units */
3303 if (level > 0)
3304 latency *= 5;
3305
3306 seq_printf(m, "WM%d %u (%u.%u usec)\n",
3307 level, wm[level],
3308 latency / 10, latency % 10);
3309 }
3310
3311 drm_modeset_unlock_all(dev);
3312}
3313
3314static int pri_wm_latency_show(struct seq_file *m, void *data)
3315{
3316 struct drm_device *dev = m->private;
3317
3318 wm_latency_show(m, to_i915(dev)->wm.pri_latency);
3319
3320 return 0;
3321}
3322
3323static int spr_wm_latency_show(struct seq_file *m, void *data)
3324{
3325 struct drm_device *dev = m->private;
3326
3327 wm_latency_show(m, to_i915(dev)->wm.spr_latency);
3328
3329 return 0;
3330}
3331
3332static int cur_wm_latency_show(struct seq_file *m, void *data)
3333{
3334 struct drm_device *dev = m->private;
3335
3336 wm_latency_show(m, to_i915(dev)->wm.cur_latency);
3337
3338 return 0;
3339}
3340
3341static int pri_wm_latency_open(struct inode *inode, struct file *file)
3342{
3343 struct drm_device *dev = inode->i_private;
3344
Sonika Jindal9ad02572014-07-21 15:23:39 +05303345 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003346 return -ENODEV;
3347
3348 return single_open(file, pri_wm_latency_show, dev);
3349}
3350
3351static int spr_wm_latency_open(struct inode *inode, struct file *file)
3352{
3353 struct drm_device *dev = inode->i_private;
3354
Sonika Jindal9ad02572014-07-21 15:23:39 +05303355 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003356 return -ENODEV;
3357
3358 return single_open(file, spr_wm_latency_show, dev);
3359}
3360
3361static int cur_wm_latency_open(struct inode *inode, struct file *file)
3362{
3363 struct drm_device *dev = inode->i_private;
3364
Sonika Jindal9ad02572014-07-21 15:23:39 +05303365 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003366 return -ENODEV;
3367
3368 return single_open(file, cur_wm_latency_show, dev);
3369}
3370
3371static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
3372 size_t len, loff_t *offp, uint16_t wm[5])
3373{
3374 struct seq_file *m = file->private_data;
3375 struct drm_device *dev = m->private;
3376 uint16_t new[5] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003377 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003378 int level;
3379 int ret;
3380 char tmp[32];
3381
3382 if (len >= sizeof(tmp))
3383 return -EINVAL;
3384
3385 if (copy_from_user(tmp, ubuf, len))
3386 return -EFAULT;
3387
3388 tmp[len] = '\0';
3389
3390 ret = sscanf(tmp, "%hu %hu %hu %hu %hu", &new[0], &new[1], &new[2], &new[3], &new[4]);
3391 if (ret != num_levels)
3392 return -EINVAL;
3393
3394 drm_modeset_lock_all(dev);
3395
3396 for (level = 0; level < num_levels; level++)
3397 wm[level] = new[level];
3398
3399 drm_modeset_unlock_all(dev);
3400
3401 return len;
3402}
3403
3404
3405static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3406 size_t len, loff_t *offp)
3407{
3408 struct seq_file *m = file->private_data;
3409 struct drm_device *dev = m->private;
3410
3411 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.pri_latency);
3412}
3413
3414static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3415 size_t len, loff_t *offp)
3416{
3417 struct seq_file *m = file->private_data;
3418 struct drm_device *dev = m->private;
3419
3420 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.spr_latency);
3421}
3422
3423static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3424 size_t len, loff_t *offp)
3425{
3426 struct seq_file *m = file->private_data;
3427 struct drm_device *dev = m->private;
3428
3429 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.cur_latency);
3430}
3431
3432static const struct file_operations i915_pri_wm_latency_fops = {
3433 .owner = THIS_MODULE,
3434 .open = pri_wm_latency_open,
3435 .read = seq_read,
3436 .llseek = seq_lseek,
3437 .release = single_release,
3438 .write = pri_wm_latency_write
3439};
3440
3441static const struct file_operations i915_spr_wm_latency_fops = {
3442 .owner = THIS_MODULE,
3443 .open = spr_wm_latency_open,
3444 .read = seq_read,
3445 .llseek = seq_lseek,
3446 .release = single_release,
3447 .write = spr_wm_latency_write
3448};
3449
3450static const struct file_operations i915_cur_wm_latency_fops = {
3451 .owner = THIS_MODULE,
3452 .open = cur_wm_latency_open,
3453 .read = seq_read,
3454 .llseek = seq_lseek,
3455 .release = single_release,
3456 .write = cur_wm_latency_write
3457};
3458
Kees Cook647416f2013-03-10 14:10:06 -07003459static int
3460i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003461{
Kees Cook647416f2013-03-10 14:10:06 -07003462 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003463 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003464
Kees Cook647416f2013-03-10 14:10:06 -07003465 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003466
Kees Cook647416f2013-03-10 14:10:06 -07003467 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003468}
3469
Kees Cook647416f2013-03-10 14:10:06 -07003470static int
3471i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003472{
Kees Cook647416f2013-03-10 14:10:06 -07003473 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003474 struct drm_i915_private *dev_priv = dev->dev_private;
3475
3476 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003477
Mika Kuoppala58174462014-02-25 17:11:26 +02003478 i915_handle_error(dev, val,
3479 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003480
3481 intel_runtime_pm_put(dev_priv);
3482
Kees Cook647416f2013-03-10 14:10:06 -07003483 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003484}
3485
Kees Cook647416f2013-03-10 14:10:06 -07003486DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3487 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003488 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003489
Kees Cook647416f2013-03-10 14:10:06 -07003490static int
3491i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003492{
Kees Cook647416f2013-03-10 14:10:06 -07003493 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003494 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003495
Kees Cook647416f2013-03-10 14:10:06 -07003496 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003497
Kees Cook647416f2013-03-10 14:10:06 -07003498 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003499}
3500
Kees Cook647416f2013-03-10 14:10:06 -07003501static int
3502i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003503{
Kees Cook647416f2013-03-10 14:10:06 -07003504 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003505 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003506 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003507
Kees Cook647416f2013-03-10 14:10:06 -07003508 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003509
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003510 ret = mutex_lock_interruptible(&dev->struct_mutex);
3511 if (ret)
3512 return ret;
3513
Daniel Vetter99584db2012-11-14 17:14:04 +01003514 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003515 mutex_unlock(&dev->struct_mutex);
3516
Kees Cook647416f2013-03-10 14:10:06 -07003517 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003518}
3519
Kees Cook647416f2013-03-10 14:10:06 -07003520DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
3521 i915_ring_stop_get, i915_ring_stop_set,
3522 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02003523
Chris Wilson094f9a52013-09-25 17:34:55 +01003524static int
3525i915_ring_missed_irq_get(void *data, u64 *val)
3526{
3527 struct drm_device *dev = data;
3528 struct drm_i915_private *dev_priv = dev->dev_private;
3529
3530 *val = dev_priv->gpu_error.missed_irq_rings;
3531 return 0;
3532}
3533
3534static int
3535i915_ring_missed_irq_set(void *data, u64 val)
3536{
3537 struct drm_device *dev = data;
3538 struct drm_i915_private *dev_priv = dev->dev_private;
3539 int ret;
3540
3541 /* Lock against concurrent debugfs callers */
3542 ret = mutex_lock_interruptible(&dev->struct_mutex);
3543 if (ret)
3544 return ret;
3545 dev_priv->gpu_error.missed_irq_rings = val;
3546 mutex_unlock(&dev->struct_mutex);
3547
3548 return 0;
3549}
3550
3551DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3552 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3553 "0x%08llx\n");
3554
3555static int
3556i915_ring_test_irq_get(void *data, u64 *val)
3557{
3558 struct drm_device *dev = data;
3559 struct drm_i915_private *dev_priv = dev->dev_private;
3560
3561 *val = dev_priv->gpu_error.test_irq_rings;
3562
3563 return 0;
3564}
3565
3566static int
3567i915_ring_test_irq_set(void *data, u64 val)
3568{
3569 struct drm_device *dev = data;
3570 struct drm_i915_private *dev_priv = dev->dev_private;
3571 int ret;
3572
3573 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
3574
3575 /* Lock against concurrent debugfs callers */
3576 ret = mutex_lock_interruptible(&dev->struct_mutex);
3577 if (ret)
3578 return ret;
3579
3580 dev_priv->gpu_error.test_irq_rings = val;
3581 mutex_unlock(&dev->struct_mutex);
3582
3583 return 0;
3584}
3585
3586DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
3587 i915_ring_test_irq_get, i915_ring_test_irq_set,
3588 "0x%08llx\n");
3589
Chris Wilsondd624af2013-01-15 12:39:35 +00003590#define DROP_UNBOUND 0x1
3591#define DROP_BOUND 0x2
3592#define DROP_RETIRE 0x4
3593#define DROP_ACTIVE 0x8
3594#define DROP_ALL (DROP_UNBOUND | \
3595 DROP_BOUND | \
3596 DROP_RETIRE | \
3597 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07003598static int
3599i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003600{
Kees Cook647416f2013-03-10 14:10:06 -07003601 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00003602
Kees Cook647416f2013-03-10 14:10:06 -07003603 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00003604}
3605
Kees Cook647416f2013-03-10 14:10:06 -07003606static int
3607i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003608{
Kees Cook647416f2013-03-10 14:10:06 -07003609 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00003610 struct drm_i915_private *dev_priv = dev->dev_private;
3611 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07003612 struct i915_address_space *vm;
3613 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07003614 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003615
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08003616 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00003617
3618 /* No need to check and wait for gpu resets, only libdrm auto-restarts
3619 * on ioctls on -EAGAIN. */
3620 ret = mutex_lock_interruptible(&dev->struct_mutex);
3621 if (ret)
3622 return ret;
3623
3624 if (val & DROP_ACTIVE) {
3625 ret = i915_gpu_idle(dev);
3626 if (ret)
3627 goto unlock;
3628 }
3629
3630 if (val & (DROP_RETIRE | DROP_ACTIVE))
3631 i915_gem_retire_requests(dev);
3632
3633 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07003634 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
3635 list_for_each_entry_safe(vma, x, &vm->inactive_list,
3636 mm_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -08003637 if (vma->pin_count)
Ben Widawskyca191b12013-07-31 17:00:14 -07003638 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07003639
Ben Widawskyca191b12013-07-31 17:00:14 -07003640 ret = i915_vma_unbind(vma);
3641 if (ret)
3642 goto unlock;
3643 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07003644 }
Chris Wilsondd624af2013-01-15 12:39:35 +00003645 }
3646
3647 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07003648 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
3649 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00003650 if (obj->pages_pin_count == 0) {
3651 ret = i915_gem_object_put_pages(obj);
3652 if (ret)
3653 goto unlock;
3654 }
3655 }
3656
3657unlock:
3658 mutex_unlock(&dev->struct_mutex);
3659
Kees Cook647416f2013-03-10 14:10:06 -07003660 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003661}
3662
Kees Cook647416f2013-03-10 14:10:06 -07003663DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
3664 i915_drop_caches_get, i915_drop_caches_set,
3665 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00003666
Kees Cook647416f2013-03-10 14:10:06 -07003667static int
3668i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003669{
Kees Cook647416f2013-03-10 14:10:06 -07003670 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003671 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003672 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003673
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003674 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003675 return -ENODEV;
3676
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003677 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3678
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003679 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003680 if (ret)
3681 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07003682
Jesse Barnes0a073b82013-04-17 15:54:58 -07003683 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003684 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003685 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003686 *val = dev_priv->rps.max_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003687 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003688
Kees Cook647416f2013-03-10 14:10:06 -07003689 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003690}
3691
Kees Cook647416f2013-03-10 14:10:06 -07003692static int
3693i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003694{
Kees Cook647416f2013-03-10 14:10:06 -07003695 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07003696 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003697 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003698 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003699
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003700 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003701 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07003702
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003703 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3704
Kees Cook647416f2013-03-10 14:10:06 -07003705 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07003706
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003707 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003708 if (ret)
3709 return ret;
3710
Jesse Barnes358733e2011-07-27 11:53:01 -07003711 /*
3712 * Turbo will still be enabled, but won't go above the set value.
3713 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003714 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003715 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003716
Ville Syrjälä03af2042014-06-28 02:03:53 +03003717 hw_max = dev_priv->rps.max_freq;
3718 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003719 } else {
3720 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003721
3722 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003723 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003724 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003725 }
3726
Ben Widawskyb39fb292014-03-19 18:31:11 -07003727 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003728 mutex_unlock(&dev_priv->rps.hw_lock);
3729 return -EINVAL;
3730 }
3731
Ben Widawskyb39fb292014-03-19 18:31:11 -07003732 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003733
3734 if (IS_VALLEYVIEW(dev))
3735 valleyview_set_rps(dev, val);
3736 else
3737 gen6_set_rps(dev, val);
3738
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003739 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003740
Kees Cook647416f2013-03-10 14:10:06 -07003741 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003742}
3743
Kees Cook647416f2013-03-10 14:10:06 -07003744DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
3745 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003746 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07003747
Kees Cook647416f2013-03-10 14:10:06 -07003748static int
3749i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003750{
Kees Cook647416f2013-03-10 14:10:06 -07003751 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003752 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003753 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003754
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003755 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003756 return -ENODEV;
3757
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003758 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3759
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003760 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003761 if (ret)
3762 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07003763
Jesse Barnes0a073b82013-04-17 15:54:58 -07003764 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003765 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003766 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003767 *val = dev_priv->rps.min_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003768 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003769
Kees Cook647416f2013-03-10 14:10:06 -07003770 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003771}
3772
Kees Cook647416f2013-03-10 14:10:06 -07003773static int
3774i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003775{
Kees Cook647416f2013-03-10 14:10:06 -07003776 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07003777 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003778 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003779 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003780
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003781 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003782 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07003783
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003784 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3785
Kees Cook647416f2013-03-10 14:10:06 -07003786 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07003787
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003788 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003789 if (ret)
3790 return ret;
3791
Jesse Barnes1523c312012-05-25 12:34:54 -07003792 /*
3793 * Turbo will still be enabled, but won't go below the set value.
3794 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003795 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003796 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003797
Ville Syrjälä03af2042014-06-28 02:03:53 +03003798 hw_max = dev_priv->rps.max_freq;
3799 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003800 } else {
3801 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003802
3803 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003804 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003805 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003806 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003807
Ben Widawskyb39fb292014-03-19 18:31:11 -07003808 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003809 mutex_unlock(&dev_priv->rps.hw_lock);
3810 return -EINVAL;
3811 }
3812
Ben Widawskyb39fb292014-03-19 18:31:11 -07003813 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003814
3815 if (IS_VALLEYVIEW(dev))
3816 valleyview_set_rps(dev, val);
3817 else
3818 gen6_set_rps(dev, val);
3819
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003820 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003821
Kees Cook647416f2013-03-10 14:10:06 -07003822 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003823}
3824
Kees Cook647416f2013-03-10 14:10:06 -07003825DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
3826 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003827 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07003828
Kees Cook647416f2013-03-10 14:10:06 -07003829static int
3830i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003831{
Kees Cook647416f2013-03-10 14:10:06 -07003832 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003833 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003834 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07003835 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003836
Daniel Vetter004777c2012-08-09 15:07:01 +02003837 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3838 return -ENODEV;
3839
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003840 ret = mutex_lock_interruptible(&dev->struct_mutex);
3841 if (ret)
3842 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003843 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003844
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003845 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003846
3847 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003848 mutex_unlock(&dev_priv->dev->struct_mutex);
3849
Kees Cook647416f2013-03-10 14:10:06 -07003850 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003851
Kees Cook647416f2013-03-10 14:10:06 -07003852 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003853}
3854
Kees Cook647416f2013-03-10 14:10:06 -07003855static int
3856i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003857{
Kees Cook647416f2013-03-10 14:10:06 -07003858 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003859 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003860 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003861
Daniel Vetter004777c2012-08-09 15:07:01 +02003862 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3863 return -ENODEV;
3864
Kees Cook647416f2013-03-10 14:10:06 -07003865 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003866 return -EINVAL;
3867
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003868 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003869 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003870
3871 /* Update the cache sharing policy here as well */
3872 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
3873 snpcr &= ~GEN6_MBC_SNPCR_MASK;
3874 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
3875 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
3876
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003877 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003878 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003879}
3880
Kees Cook647416f2013-03-10 14:10:06 -07003881DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
3882 i915_cache_sharing_get, i915_cache_sharing_set,
3883 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003884
Ben Widawsky6d794d42011-04-25 11:25:56 -07003885static int i915_forcewake_open(struct inode *inode, struct file *file)
3886{
3887 struct drm_device *dev = inode->i_private;
3888 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003889
Daniel Vetter075edca2012-01-24 09:44:28 +01003890 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003891 return 0;
3892
Deepak Sc8d9a592013-11-23 14:55:42 +05303893 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003894
3895 return 0;
3896}
3897
Ben Widawskyc43b5632012-04-16 14:07:40 -07003898static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003899{
3900 struct drm_device *dev = inode->i_private;
3901 struct drm_i915_private *dev_priv = dev->dev_private;
3902
Daniel Vetter075edca2012-01-24 09:44:28 +01003903 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003904 return 0;
3905
Deepak Sc8d9a592013-11-23 14:55:42 +05303906 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003907
3908 return 0;
3909}
3910
3911static const struct file_operations i915_forcewake_fops = {
3912 .owner = THIS_MODULE,
3913 .open = i915_forcewake_open,
3914 .release = i915_forcewake_release,
3915};
3916
3917static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
3918{
3919 struct drm_device *dev = minor->dev;
3920 struct dentry *ent;
3921
3922 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07003923 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07003924 root, dev,
3925 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003926 if (!ent)
3927 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003928
Ben Widawsky8eb57292011-05-11 15:10:58 -07003929 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003930}
3931
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003932static int i915_debugfs_create(struct dentry *root,
3933 struct drm_minor *minor,
3934 const char *name,
3935 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07003936{
3937 struct drm_device *dev = minor->dev;
3938 struct dentry *ent;
3939
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003940 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07003941 S_IRUGO | S_IWUSR,
3942 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003943 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003944 if (!ent)
3945 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07003946
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003947 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003948}
3949
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003950static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00003951 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01003952 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00003953 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01003954 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003955 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003956 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01003957 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01003958 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003959 {"i915_gem_request", i915_gem_request_info, 0},
3960 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00003961 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003962 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003963 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
3964 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
3965 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07003966 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Deepak Sadb4bd12014-03-31 11:30:02 +05303967 {"i915_frequency_info", i915_frequency_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003968 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003969 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07003970 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08003971 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03003972 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08003973 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01003974 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01003975 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07003976 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07003977 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01003978 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01003979 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07003980 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03003981 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003982 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01003983 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03003984 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02003985 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003986 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07003987 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03003988 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10003989 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003990};
Ben Gamari27c202a2009-07-01 22:26:52 -04003991#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05003992
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003993static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02003994 const char *name;
3995 const struct file_operations *fops;
3996} i915_debugfs_files[] = {
3997 {"i915_wedged", &i915_wedged_fops},
3998 {"i915_max_freq", &i915_max_freq_fops},
3999 {"i915_min_freq", &i915_min_freq_fops},
4000 {"i915_cache_sharing", &i915_cache_sharing_fops},
4001 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004002 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4003 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004004 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4005 {"i915_error_state", &i915_error_state_fops},
4006 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004007 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004008 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4009 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4010 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004011 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004012};
4013
Damien Lespiau07144422013-10-15 18:55:40 +01004014void intel_display_crc_init(struct drm_device *dev)
4015{
4016 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004017 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004018
Daniel Vetterb3783602013-11-14 11:30:42 +01004019 for_each_pipe(pipe) {
4020 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004021
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004022 pipe_crc->opened = false;
4023 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004024 init_waitqueue_head(&pipe_crc->wq);
4025 }
4026}
4027
Ben Gamari27c202a2009-07-01 22:26:52 -04004028int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004029{
Daniel Vetter34b96742013-07-04 20:49:44 +02004030 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004031
Ben Widawsky6d794d42011-04-25 11:25:56 -07004032 ret = i915_forcewake_create(minor->debugfs_root, minor);
4033 if (ret)
4034 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004035
Damien Lespiau07144422013-10-15 18:55:40 +01004036 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4037 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4038 if (ret)
4039 return ret;
4040 }
4041
Daniel Vetter34b96742013-07-04 20:49:44 +02004042 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4043 ret = i915_debugfs_create(minor->debugfs_root, minor,
4044 i915_debugfs_files[i].name,
4045 i915_debugfs_files[i].fops);
4046 if (ret)
4047 return ret;
4048 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004049
Ben Gamari27c202a2009-07-01 22:26:52 -04004050 return drm_debugfs_create_files(i915_debugfs_list,
4051 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004052 minor->debugfs_root, minor);
4053}
4054
Ben Gamari27c202a2009-07-01 22:26:52 -04004055void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004056{
Daniel Vetter34b96742013-07-04 20:49:44 +02004057 int i;
4058
Ben Gamari27c202a2009-07-01 22:26:52 -04004059 drm_debugfs_remove_files(i915_debugfs_list,
4060 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004061
Ben Widawsky6d794d42011-04-25 11:25:56 -07004062 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4063 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004064
Daniel Vettere309a992013-10-16 22:55:51 +02004065 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004066 struct drm_info_list *info_list =
4067 (struct drm_info_list *)&i915_pipe_crc_data[i];
4068
4069 drm_debugfs_remove_files(info_list, 1, minor);
4070 }
4071
Daniel Vetter34b96742013-07-04 20:49:44 +02004072 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4073 struct drm_info_list *info_list =
4074 (struct drm_info_list *) i915_debugfs_files[i].fops;
4075
4076 drm_debugfs_remove_files(info_list, 1, minor);
4077 }
Ben Gamari20172632009-02-17 20:08:50 -05004078}