blob: 358663e833d6e7f30f9b6af115d74c83a006097f [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
David Weinehall36cdd012016-08-22 13:59:31 +030043static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
44{
45 return to_i915(node->minor->dev);
46}
47
Damien Lespiau497666d2013-10-15 18:55:39 +010048/* As the drm_debugfs_init() routines are called before dev->dev_private is
49 * allocated we need to hook into the minor for release. */
50static int
51drm_add_fake_info_node(struct drm_minor *minor,
52 struct dentry *ent,
53 const void *key)
54{
55 struct drm_info_node *node;
56
57 node = kmalloc(sizeof(*node), GFP_KERNEL);
58 if (node == NULL) {
59 debugfs_remove(ent);
60 return -ENOMEM;
61 }
62
63 node->minor = minor;
64 node->dent = ent;
David Weinehall36cdd012016-08-22 13:59:31 +030065 node->info_ent = (void *)key;
Damien Lespiau497666d2013-10-15 18:55:39 +010066
67 mutex_lock(&minor->debugfs_lock);
68 list_add(&node->list, &minor->debugfs_list);
69 mutex_unlock(&minor->debugfs_lock);
70
71 return 0;
72}
73
Chris Wilson70d39fe2010-08-25 16:03:34 +010074static int i915_capabilities(struct seq_file *m, void *data)
75{
David Weinehall36cdd012016-08-22 13:59:31 +030076 struct drm_i915_private *dev_priv = node_to_i915(m->private);
77 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010078
David Weinehall36cdd012016-08-22 13:59:31 +030079 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
80 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010081#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030082 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010083#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010084
85 return 0;
86}
Ben Gamari433e12f2009-02-17 20:08:51 -050087
Imre Deaka7363de2016-05-12 16:18:52 +030088static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000089{
Chris Wilson573adb32016-08-04 16:32:39 +010090 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000091}
92
Imre Deaka7363de2016-05-12 16:18:52 +030093static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010094{
95 return obj->pin_display ? 'p' : ' ';
96}
97
Imre Deaka7363de2016-05-12 16:18:52 +030098static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000099{
Chris Wilson3e510a82016-08-05 10:14:23 +0100100 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -0400101 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100102 case I915_TILING_NONE: return ' ';
103 case I915_TILING_X: return 'X';
104 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400105 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000106}
107
Imre Deaka7363de2016-05-12 16:18:52 +0300108static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700109{
Chris Wilson058d88c2016-08-15 10:49:06 +0100110 return i915_gem_object_to_ggtt(obj, NULL) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100111}
112
Imre Deaka7363de2016-05-12 16:18:52 +0300113static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100114{
115 return obj->mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700116}
117
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100118static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
119{
120 u64 size = 0;
121 struct i915_vma *vma;
122
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000123 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100124 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100125 size += vma->node.size;
126 }
127
128 return size;
129}
130
Chris Wilson37811fc2010-08-25 22:45:57 +0100131static void
132describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
133{
Chris Wilsonb4716182015-04-27 13:41:17 +0100134 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000135 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700136 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100137 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800138 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000139 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800140
Chris Wilson188c1ab2016-04-03 14:14:20 +0100141 lockdep_assert_held(&obj->base.dev->struct_mutex);
142
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100143 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100144 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100145 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 get_pin_flag(obj),
147 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700148 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100149 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800150 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100151 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100152 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000153 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100154 seq_printf(m, "%x ",
Chris Wilsond72d9082016-08-04 07:52:31 +0100155 i915_gem_active_get_seqno(&obj->last_read[id],
156 &obj->base.dev->struct_mutex));
Chris Wilson49ef5292016-08-18 17:17:00 +0100157 seq_printf(m, "] %x %s%s%s",
Chris Wilsond72d9082016-08-04 07:52:31 +0100158 i915_gem_active_get_seqno(&obj->last_write,
159 &obj->base.dev->struct_mutex),
David Weinehall36cdd012016-08-22 13:59:31 +0300160 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100161 obj->dirty ? " dirty" : "",
162 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
163 if (obj->base.name)
164 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000165 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100166 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800167 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300168 }
169 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100170 if (obj->pin_display)
171 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000172 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100173 if (!drm_mm_node_allocated(&vma->node))
174 continue;
175
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100176 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100177 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100178 vma->node.start, vma->node.size);
Chris Wilson3272db52016-08-04 16:32:32 +0100179 if (i915_vma_is_ggtt(vma))
Chris Wilson596c5922016-02-26 11:03:20 +0000180 seq_printf(m, ", type: %u", vma->ggtt_view.type);
Chris Wilson49ef5292016-08-18 17:17:00 +0100181 if (vma->fence)
182 seq_printf(m, " , fence: %d%s",
183 vma->fence->id,
184 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000185 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700186 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000187 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100188 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100189 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000190 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100191 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000192 *t++ = 'p';
193 if (obj->fault_mappable)
194 *t++ = 'f';
195 *t = '\0';
196 seq_printf(m, " (%s mappable)", s);
197 }
Chris Wilson27c01aa2016-08-04 07:52:30 +0100198
Chris Wilsond72d9082016-08-04 07:52:31 +0100199 engine = i915_gem_active_get_engine(&obj->last_write,
David Weinehall36cdd012016-08-22 13:59:31 +0300200 &dev_priv->drm.struct_mutex);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100201 if (engine)
202 seq_printf(m, " (%s)", engine->name);
203
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100204 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
205 if (frontbuffer_bits)
206 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100207}
208
Chris Wilson6d2b88852013-08-07 18:30:54 +0100209static int obj_rank_by_stolen(void *priv,
210 struct list_head *A, struct list_head *B)
211{
212 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200213 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100214 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200215 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100216
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200217 if (a->stolen->start < b->stolen->start)
218 return -1;
219 if (a->stolen->start > b->stolen->start)
220 return 1;
221 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100222}
223
224static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
225{
David Weinehall36cdd012016-08-22 13:59:31 +0300226 struct drm_i915_private *dev_priv = node_to_i915(m->private);
227 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100228 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300229 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100230 LIST_HEAD(stolen);
231 int count, ret;
232
233 ret = mutex_lock_interruptible(&dev->struct_mutex);
234 if (ret)
235 return ret;
236
237 total_obj_size = total_gtt_size = count = 0;
238 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
239 if (obj->stolen == NULL)
240 continue;
241
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200242 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100243
244 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100245 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100246 count++;
247 }
248 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
249 if (obj->stolen == NULL)
250 continue;
251
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200252 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100253
254 total_obj_size += obj->base.size;
255 count++;
256 }
257 list_sort(NULL, &stolen, obj_rank_by_stolen);
258 seq_puts(m, "Stolen:\n");
259 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200260 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261 seq_puts(m, " ");
262 describe_obj(m, obj);
263 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200264 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100265 }
266 mutex_unlock(&dev->struct_mutex);
267
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300268 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100269 count, total_obj_size, total_gtt_size);
270 return 0;
271}
272
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100273struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000274 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300275 unsigned long count;
276 u64 total, unbound;
277 u64 global, shared;
278 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100279};
280
281static int per_file_stats(int id, void *ptr, void *data)
282{
283 struct drm_i915_gem_object *obj = ptr;
284 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000285 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100286
287 stats->count++;
288 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100289 if (!obj->bind_count)
290 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000291 if (obj->base.name || obj->base.dma_buf)
292 stats->shared += obj->base.size;
293
Chris Wilson894eeec2016-08-04 07:52:20 +0100294 list_for_each_entry(vma, &obj->vma_list, obj_link) {
295 if (!drm_mm_node_allocated(&vma->node))
296 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000297
Chris Wilson3272db52016-08-04 16:32:32 +0100298 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100299 stats->global += vma->node.size;
300 } else {
301 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000302
Chris Wilson2bfa9962016-08-04 07:52:25 +0100303 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000304 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000305 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100306
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100307 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100308 stats->active += vma->node.size;
309 else
310 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100311 }
312
313 return 0;
314}
315
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100316#define print_file_stats(m, name, stats) do { \
317 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300318 seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100319 name, \
320 stats.count, \
321 stats.total, \
322 stats.active, \
323 stats.inactive, \
324 stats.global, \
325 stats.shared, \
326 stats.unbound); \
327} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800328
329static void print_batch_pool_stats(struct seq_file *m,
330 struct drm_i915_private *dev_priv)
331{
332 struct drm_i915_gem_object *obj;
333 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000334 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000335 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800336
337 memset(&stats, 0, sizeof(stats));
338
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000339 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000340 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100341 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000342 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100343 batch_pool_link)
344 per_file_stats(0, obj, &stats);
345 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100346 }
Brad Volkin493018d2014-12-11 12:13:08 -0800347
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100348 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800349}
350
Chris Wilson15da9562016-05-24 14:53:43 +0100351static int per_file_ctx_stats(int id, void *ptr, void *data)
352{
353 struct i915_gem_context *ctx = ptr;
354 int n;
355
356 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
357 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100358 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100359 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100360 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100361 }
362
363 return 0;
364}
365
366static void print_context_stats(struct seq_file *m,
367 struct drm_i915_private *dev_priv)
368{
David Weinehall36cdd012016-08-22 13:59:31 +0300369 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100370 struct file_stats stats;
371 struct drm_file *file;
372
373 memset(&stats, 0, sizeof(stats));
374
David Weinehall36cdd012016-08-22 13:59:31 +0300375 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100376 if (dev_priv->kernel_context)
377 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
378
David Weinehall36cdd012016-08-22 13:59:31 +0300379 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100380 struct drm_i915_file_private *fpriv = file->driver_priv;
381 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
382 }
David Weinehall36cdd012016-08-22 13:59:31 +0300383 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100384
385 print_file_stats(m, "[k]contexts", stats);
386}
387
David Weinehall36cdd012016-08-22 13:59:31 +0300388static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100389{
David Weinehall36cdd012016-08-22 13:59:31 +0300390 struct drm_i915_private *dev_priv = node_to_i915(m->private);
391 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300392 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100393 u32 count, mapped_count, purgeable_count, dpy_count;
394 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000395 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100396 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100397 int ret;
398
399 ret = mutex_lock_interruptible(&dev->struct_mutex);
400 if (ret)
401 return ret;
402
Chris Wilson6299f992010-11-24 12:23:44 +0000403 seq_printf(m, "%u objects, %zu bytes\n",
404 dev_priv->mm.object_count,
405 dev_priv->mm.object_memory);
406
Chris Wilson1544c422016-08-15 13:18:16 +0100407 size = count = 0;
408 mapped_size = mapped_count = 0;
409 purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700410 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100411 size += obj->base.size;
412 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200413
Chris Wilsonb7abb712012-08-20 11:33:30 +0200414 if (obj->madv == I915_MADV_DONTNEED) {
415 purgeable_size += obj->base.size;
416 ++purgeable_count;
417 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100418
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100419 if (obj->mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100420 mapped_count++;
421 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100422 }
Chris Wilson6299f992010-11-24 12:23:44 +0000423 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100424 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
425
426 size = count = dpy_size = dpy_count = 0;
427 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
428 size += obj->base.size;
429 ++count;
430
431 if (obj->pin_display) {
432 dpy_size += obj->base.size;
433 ++dpy_count;
434 }
435
436 if (obj->madv == I915_MADV_DONTNEED) {
437 purgeable_size += obj->base.size;
438 ++purgeable_count;
439 }
440
441 if (obj->mapping) {
442 mapped_count++;
443 mapped_size += obj->base.size;
444 }
445 }
446 seq_printf(m, "%u bound objects, %llu bytes\n",
447 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300448 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200449 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100450 seq_printf(m, "%u mapped objects, %llu bytes\n",
451 mapped_count, mapped_size);
452 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
453 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000454
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300455 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300456 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100457
Damien Lespiau267f0c92013-06-24 22:59:48 +0100458 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800459 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200460 mutex_unlock(&dev->struct_mutex);
461
462 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100463 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100464 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
465 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100466 struct drm_i915_file_private *file_priv = file->driver_priv;
467 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900468 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100469
470 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000471 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100472 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100473 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100474 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900475 /*
476 * Although we have a valid reference on file->pid, that does
477 * not guarantee that the task_struct who called get_pid() is
478 * still alive (e.g. get_pid(current) => fork() => exit()).
479 * Therefore, we need to protect this ->comm access using RCU.
480 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100481 mutex_lock(&dev->struct_mutex);
482 request = list_first_entry_or_null(&file_priv->mm.request_list,
483 struct drm_i915_gem_request,
484 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900485 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100486 task = pid_task(request && request->ctx->pid ?
487 request->ctx->pid : file->pid,
488 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800489 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900490 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100491 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100492 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200493 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100494
495 return 0;
496}
497
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100498static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000499{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100500 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300501 struct drm_i915_private *dev_priv = node_to_i915(node);
502 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100503 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000504 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300505 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000506 int count, ret;
507
508 ret = mutex_lock_interruptible(&dev->struct_mutex);
509 if (ret)
510 return ret;
511
512 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700513 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6da84822016-08-15 10:48:44 +0100514 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100515 continue;
516
Damien Lespiau267f0c92013-06-24 22:59:48 +0100517 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000518 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100519 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000520 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100521 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000522 count++;
523 }
524
525 mutex_unlock(&dev->struct_mutex);
526
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300527 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000528 count, total_obj_size, total_gtt_size);
529
530 return 0;
531}
532
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100533static int i915_gem_pageflip_info(struct seq_file *m, void *data)
534{
David Weinehall36cdd012016-08-22 13:59:31 +0300535 struct drm_i915_private *dev_priv = node_to_i915(m->private);
536 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100537 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200538 int ret;
539
540 ret = mutex_lock_interruptible(&dev->struct_mutex);
541 if (ret)
542 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100543
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100544 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800545 const char pipe = pipe_name(crtc->pipe);
546 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200547 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100548
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200549 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200550 work = crtc->flip_work;
551 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800552 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100553 pipe, plane);
554 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200555 u32 pending;
556 u32 addr;
557
558 pending = atomic_read(&work->pending);
559 if (pending) {
560 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
561 pipe, plane);
562 } else {
563 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
564 pipe, plane);
565 }
566 if (work->flip_queued_req) {
567 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
568
569 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
570 engine->name,
571 i915_gem_request_get_seqno(work->flip_queued_req),
572 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100573 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100574 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200575 } else
576 seq_printf(m, "Flip not associated with any ring\n");
577 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
578 work->flip_queued_vblank,
579 work->flip_ready_vblank,
580 intel_crtc_get_vblank_counter(crtc));
581 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
582
David Weinehall36cdd012016-08-22 13:59:31 +0300583 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200584 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
585 else
586 addr = I915_READ(DSPADDR(crtc->plane));
587 seq_printf(m, "Current scanout address 0x%08x\n", addr);
588
589 if (work->pending_flip_obj) {
590 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
591 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100592 }
593 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200594 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100595 }
596
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200597 mutex_unlock(&dev->struct_mutex);
598
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100599 return 0;
600}
601
Brad Volkin493018d2014-12-11 12:13:08 -0800602static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
603{
David Weinehall36cdd012016-08-22 13:59:31 +0300604 struct drm_i915_private *dev_priv = node_to_i915(m->private);
605 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800606 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000607 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100608 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000609 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800610
611 ret = mutex_lock_interruptible(&dev->struct_mutex);
612 if (ret)
613 return ret;
614
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000615 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000616 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100617 int count;
618
619 count = 0;
620 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000621 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100622 batch_pool_link)
623 count++;
624 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000625 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100626
627 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000628 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100629 batch_pool_link) {
630 seq_puts(m, " ");
631 describe_obj(m, obj);
632 seq_putc(m, '\n');
633 }
634
635 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100636 }
Brad Volkin493018d2014-12-11 12:13:08 -0800637 }
638
Chris Wilson8d9d5742015-04-07 16:20:38 +0100639 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800640
641 mutex_unlock(&dev->struct_mutex);
642
643 return 0;
644}
645
Chris Wilson1b365952016-10-04 21:11:31 +0100646static void print_request(struct seq_file *m,
647 struct drm_i915_gem_request *rq,
648 const char *prefix)
649{
650 struct pid *pid = rq->ctx->pid;
651 struct task_struct *task;
652
653 rcu_read_lock();
654 task = pid ? pid_task(pid, PIDTYPE_PID) : NULL;
655 seq_printf(m, "%s%x [%x:%x] @ %d: %s [%d]\n", prefix,
656 rq->fence.seqno, rq->ctx->hw_id, rq->fence.seqno,
657 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
658 task ? task->comm : "<unknown>",
659 task ? task->pid : -1);
660 rcu_read_unlock();
661}
662
Ben Gamari20172632009-02-17 20:08:50 -0500663static int i915_gem_request_info(struct seq_file *m, void *data)
664{
David Weinehall36cdd012016-08-22 13:59:31 +0300665 struct drm_i915_private *dev_priv = node_to_i915(m->private);
666 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000667 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200668 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000669 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100670
671 ret = mutex_lock_interruptible(&dev->struct_mutex);
672 if (ret)
673 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500674
Chris Wilson2d1070b2015-04-01 10:36:56 +0100675 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000676 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100677 int count;
678
679 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100680 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100681 count++;
682 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100683 continue;
684
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000685 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson1b365952016-10-04 21:11:31 +0100686 list_for_each_entry(req, &engine->request_list, link)
687 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100688
689 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500690 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100691 mutex_unlock(&dev->struct_mutex);
692
Chris Wilson2d1070b2015-04-01 10:36:56 +0100693 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100694 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100695
Ben Gamari20172632009-02-17 20:08:50 -0500696 return 0;
697}
698
Chris Wilsonb2223492010-10-27 15:27:33 +0100699static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000700 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100701{
Chris Wilson688e6c72016-07-01 17:23:15 +0100702 struct intel_breadcrumbs *b = &engine->breadcrumbs;
703 struct rb_node *rb;
704
Chris Wilson12471ba2016-04-09 10:57:55 +0100705 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100706 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100707
708 spin_lock(&b->lock);
709 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
710 struct intel_wait *w = container_of(rb, typeof(*w), node);
711
712 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
713 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
714 }
715 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100716}
717
Ben Gamari20172632009-02-17 20:08:50 -0500718static int i915_gem_seqno_info(struct seq_file *m, void *data)
719{
David Weinehall36cdd012016-08-22 13:59:31 +0300720 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000721 struct intel_engine_cs *engine;
Ben Gamari20172632009-02-17 20:08:50 -0500722
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000723 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000724 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100725
Ben Gamari20172632009-02-17 20:08:50 -0500726 return 0;
727}
728
729
730static int i915_interrupt_info(struct seq_file *m, void *data)
731{
David Weinehall36cdd012016-08-22 13:59:31 +0300732 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000733 struct intel_engine_cs *engine;
Chris Wilson4bb05042016-09-03 07:53:43 +0100734 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100735
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200736 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500737
David Weinehall36cdd012016-08-22 13:59:31 +0300738 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300739 seq_printf(m, "Master Interrupt Control:\t%08x\n",
740 I915_READ(GEN8_MASTER_IRQ));
741
742 seq_printf(m, "Display IER:\t%08x\n",
743 I915_READ(VLV_IER));
744 seq_printf(m, "Display IIR:\t%08x\n",
745 I915_READ(VLV_IIR));
746 seq_printf(m, "Display IIR_RW:\t%08x\n",
747 I915_READ(VLV_IIR_RW));
748 seq_printf(m, "Display IMR:\t%08x\n",
749 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100750 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300751 seq_printf(m, "Pipe %c stat:\t%08x\n",
752 pipe_name(pipe),
753 I915_READ(PIPESTAT(pipe)));
754
755 seq_printf(m, "Port hotplug:\t%08x\n",
756 I915_READ(PORT_HOTPLUG_EN));
757 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
758 I915_READ(VLV_DPFLIPSTAT));
759 seq_printf(m, "DPINVGTT:\t%08x\n",
760 I915_READ(DPINVGTT));
761
762 for (i = 0; i < 4; i++) {
763 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
764 i, I915_READ(GEN8_GT_IMR(i)));
765 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
766 i, I915_READ(GEN8_GT_IIR(i)));
767 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
768 i, I915_READ(GEN8_GT_IER(i)));
769 }
770
771 seq_printf(m, "PCU interrupt mask:\t%08x\n",
772 I915_READ(GEN8_PCU_IMR));
773 seq_printf(m, "PCU interrupt identity:\t%08x\n",
774 I915_READ(GEN8_PCU_IIR));
775 seq_printf(m, "PCU interrupt enable:\t%08x\n",
776 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300777 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700778 seq_printf(m, "Master Interrupt Control:\t%08x\n",
779 I915_READ(GEN8_MASTER_IRQ));
780
781 for (i = 0; i < 4; i++) {
782 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
783 i, I915_READ(GEN8_GT_IMR(i)));
784 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
785 i, I915_READ(GEN8_GT_IIR(i)));
786 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
787 i, I915_READ(GEN8_GT_IER(i)));
788 }
789
Damien Lespiau055e3932014-08-18 13:49:10 +0100790 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200791 enum intel_display_power_domain power_domain;
792
793 power_domain = POWER_DOMAIN_PIPE(pipe);
794 if (!intel_display_power_get_if_enabled(dev_priv,
795 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300796 seq_printf(m, "Pipe %c power disabled\n",
797 pipe_name(pipe));
798 continue;
799 }
Ben Widawskya123f152013-11-02 21:07:10 -0700800 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000801 pipe_name(pipe),
802 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700803 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000804 pipe_name(pipe),
805 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700806 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000807 pipe_name(pipe),
808 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200809
810 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700811 }
812
813 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
814 I915_READ(GEN8_DE_PORT_IMR));
815 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
816 I915_READ(GEN8_DE_PORT_IIR));
817 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
818 I915_READ(GEN8_DE_PORT_IER));
819
820 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
821 I915_READ(GEN8_DE_MISC_IMR));
822 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
823 I915_READ(GEN8_DE_MISC_IIR));
824 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
825 I915_READ(GEN8_DE_MISC_IER));
826
827 seq_printf(m, "PCU interrupt mask:\t%08x\n",
828 I915_READ(GEN8_PCU_IMR));
829 seq_printf(m, "PCU interrupt identity:\t%08x\n",
830 I915_READ(GEN8_PCU_IIR));
831 seq_printf(m, "PCU interrupt enable:\t%08x\n",
832 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300833 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700834 seq_printf(m, "Display IER:\t%08x\n",
835 I915_READ(VLV_IER));
836 seq_printf(m, "Display IIR:\t%08x\n",
837 I915_READ(VLV_IIR));
838 seq_printf(m, "Display IIR_RW:\t%08x\n",
839 I915_READ(VLV_IIR_RW));
840 seq_printf(m, "Display IMR:\t%08x\n",
841 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100842 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700843 seq_printf(m, "Pipe %c stat:\t%08x\n",
844 pipe_name(pipe),
845 I915_READ(PIPESTAT(pipe)));
846
847 seq_printf(m, "Master IER:\t%08x\n",
848 I915_READ(VLV_MASTER_IER));
849
850 seq_printf(m, "Render IER:\t%08x\n",
851 I915_READ(GTIER));
852 seq_printf(m, "Render IIR:\t%08x\n",
853 I915_READ(GTIIR));
854 seq_printf(m, "Render IMR:\t%08x\n",
855 I915_READ(GTIMR));
856
857 seq_printf(m, "PM IER:\t\t%08x\n",
858 I915_READ(GEN6_PMIER));
859 seq_printf(m, "PM IIR:\t\t%08x\n",
860 I915_READ(GEN6_PMIIR));
861 seq_printf(m, "PM IMR:\t\t%08x\n",
862 I915_READ(GEN6_PMIMR));
863
864 seq_printf(m, "Port hotplug:\t%08x\n",
865 I915_READ(PORT_HOTPLUG_EN));
866 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
867 I915_READ(VLV_DPFLIPSTAT));
868 seq_printf(m, "DPINVGTT:\t%08x\n",
869 I915_READ(DPINVGTT));
870
David Weinehall36cdd012016-08-22 13:59:31 +0300871 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800872 seq_printf(m, "Interrupt enable: %08x\n",
873 I915_READ(IER));
874 seq_printf(m, "Interrupt identity: %08x\n",
875 I915_READ(IIR));
876 seq_printf(m, "Interrupt mask: %08x\n",
877 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100878 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800879 seq_printf(m, "Pipe %c stat: %08x\n",
880 pipe_name(pipe),
881 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800882 } else {
883 seq_printf(m, "North Display Interrupt enable: %08x\n",
884 I915_READ(DEIER));
885 seq_printf(m, "North Display Interrupt identity: %08x\n",
886 I915_READ(DEIIR));
887 seq_printf(m, "North Display Interrupt mask: %08x\n",
888 I915_READ(DEIMR));
889 seq_printf(m, "South Display Interrupt enable: %08x\n",
890 I915_READ(SDEIER));
891 seq_printf(m, "South Display Interrupt identity: %08x\n",
892 I915_READ(SDEIIR));
893 seq_printf(m, "South Display Interrupt mask: %08x\n",
894 I915_READ(SDEIMR));
895 seq_printf(m, "Graphics Interrupt enable: %08x\n",
896 I915_READ(GTIER));
897 seq_printf(m, "Graphics Interrupt identity: %08x\n",
898 I915_READ(GTIIR));
899 seq_printf(m, "Graphics Interrupt mask: %08x\n",
900 I915_READ(GTIMR));
901 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000902 for_each_engine(engine, dev_priv) {
David Weinehall36cdd012016-08-22 13:59:31 +0300903 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100904 seq_printf(m,
905 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000906 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000907 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000908 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000909 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200910 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100911
Ben Gamari20172632009-02-17 20:08:50 -0500912 return 0;
913}
914
Chris Wilsona6172a82009-02-11 14:26:38 +0000915static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
916{
David Weinehall36cdd012016-08-22 13:59:31 +0300917 struct drm_i915_private *dev_priv = node_to_i915(m->private);
918 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100919 int i, ret;
920
921 ret = mutex_lock_interruptible(&dev->struct_mutex);
922 if (ret)
923 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000924
Chris Wilsona6172a82009-02-11 14:26:38 +0000925 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
926 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100927 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000928
Chris Wilson6c085a72012-08-20 11:40:46 +0200929 seq_printf(m, "Fence %d, pin count = %d, object = ",
930 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100931 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100932 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100933 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100934 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100935 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000936 }
937
Chris Wilson05394f32010-11-08 19:18:58 +0000938 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000939 return 0;
940}
941
Ben Gamari20172632009-02-17 20:08:50 -0500942static int i915_hws_info(struct seq_file *m, void *data)
943{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100944 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300945 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000946 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100947 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100948 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500949
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +0000950 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000951 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500952 if (hws == NULL)
953 return 0;
954
955 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
956 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
957 i * 4,
958 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
959 }
960 return 0;
961}
962
Chris Wilson98a2f412016-10-12 10:05:18 +0100963#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
964
Daniel Vetterd5442302012-04-27 15:17:40 +0200965static ssize_t
966i915_error_state_write(struct file *filp,
967 const char __user *ubuf,
968 size_t cnt,
969 loff_t *ppos)
970{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300971 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200972
973 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100974 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200975
976 return cnt;
977}
978
979static int i915_error_state_open(struct inode *inode, struct file *file)
980{
David Weinehall36cdd012016-08-22 13:59:31 +0300981 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200982 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200983
984 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
985 if (!error_priv)
986 return -ENOMEM;
987
David Weinehall36cdd012016-08-22 13:59:31 +0300988 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200989
David Weinehall36cdd012016-08-22 13:59:31 +0300990 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200991
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300992 file->private_data = error_priv;
993
994 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200995}
996
997static int i915_error_state_release(struct inode *inode, struct file *file)
998{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300999 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001000
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001001 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001002 kfree(error_priv);
1003
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001004 return 0;
1005}
1006
1007static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1008 size_t count, loff_t *pos)
1009{
1010 struct i915_error_state_file_priv *error_priv = file->private_data;
1011 struct drm_i915_error_state_buf error_str;
1012 loff_t tmp_pos = 0;
1013 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001014 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001015
David Weinehall36cdd012016-08-22 13:59:31 +03001016 ret = i915_error_state_buf_init(&error_str,
1017 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001018 if (ret)
1019 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001020
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001021 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001022 if (ret)
1023 goto out;
1024
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001025 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1026 error_str.buf,
1027 error_str.bytes);
1028
1029 if (ret_count < 0)
1030 ret = ret_count;
1031 else
1032 *pos = error_str.start + ret_count;
1033out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001034 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001035 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001036}
1037
1038static const struct file_operations i915_error_state_fops = {
1039 .owner = THIS_MODULE,
1040 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001041 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001042 .write = i915_error_state_write,
1043 .llseek = default_llseek,
1044 .release = i915_error_state_release,
1045};
1046
Chris Wilson98a2f412016-10-12 10:05:18 +01001047#endif
1048
Kees Cook647416f2013-03-10 14:10:06 -07001049static int
1050i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001051{
David Weinehall36cdd012016-08-22 13:59:31 +03001052 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001053 int ret;
1054
David Weinehall36cdd012016-08-22 13:59:31 +03001055 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001056 if (ret)
1057 return ret;
1058
Kees Cook647416f2013-03-10 14:10:06 -07001059 *val = dev_priv->next_seqno;
David Weinehall36cdd012016-08-22 13:59:31 +03001060 mutex_unlock(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001061
Kees Cook647416f2013-03-10 14:10:06 -07001062 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001063}
1064
Kees Cook647416f2013-03-10 14:10:06 -07001065static int
1066i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001067{
David Weinehall36cdd012016-08-22 13:59:31 +03001068 struct drm_i915_private *dev_priv = data;
1069 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001070 int ret;
1071
Mika Kuoppala40633212012-12-04 15:12:00 +02001072 ret = mutex_lock_interruptible(&dev->struct_mutex);
1073 if (ret)
1074 return ret;
1075
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001076 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001077 mutex_unlock(&dev->struct_mutex);
1078
Kees Cook647416f2013-03-10 14:10:06 -07001079 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001080}
1081
Kees Cook647416f2013-03-10 14:10:06 -07001082DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1083 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001084 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001085
Deepak Sadb4bd12014-03-31 11:30:02 +05301086static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001087{
David Weinehall36cdd012016-08-22 13:59:31 +03001088 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1089 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001090 int ret = 0;
1091
1092 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001093
David Weinehall36cdd012016-08-22 13:59:31 +03001094 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001095 u16 rgvswctl = I915_READ16(MEMSWCTL);
1096 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1097
1098 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1099 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1100 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1101 MEMSTAT_VID_SHIFT);
1102 seq_printf(m, "Current P-state: %d\n",
1103 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001104 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001105 u32 freq_sts;
1106
1107 mutex_lock(&dev_priv->rps.hw_lock);
1108 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1109 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1110 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1111
1112 seq_printf(m, "actual GPU freq: %d MHz\n",
1113 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1114
1115 seq_printf(m, "current GPU freq: %d MHz\n",
1116 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1117
1118 seq_printf(m, "max GPU freq: %d MHz\n",
1119 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1120
1121 seq_printf(m, "min GPU freq: %d MHz\n",
1122 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1123
1124 seq_printf(m, "idle GPU freq: %d MHz\n",
1125 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1126
1127 seq_printf(m,
1128 "efficient (RPe) frequency: %d MHz\n",
1129 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1130 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001131 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001132 u32 rp_state_limits;
1133 u32 gt_perf_status;
1134 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001135 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001136 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001137 u32 rpupei, rpcurup, rpprevup;
1138 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001139 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001140 int max_freq;
1141
Bob Paauwe35040562015-06-25 14:54:07 -07001142 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001143 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001144 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1145 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1146 } else {
1147 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1148 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1149 }
1150
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001151 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001152 ret = mutex_lock_interruptible(&dev->struct_mutex);
1153 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001154 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001155
Mika Kuoppala59bad942015-01-16 11:34:40 +02001156 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001157
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001158 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001159 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301160 reqf >>= 23;
1161 else {
1162 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001163 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301164 reqf >>= 24;
1165 else
1166 reqf >>= 25;
1167 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001168 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001169
Chris Wilson0d8f9492014-03-27 09:06:14 +00001170 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1171 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1172 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1173
Jesse Barnesccab5c82011-01-18 15:49:25 -08001174 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301175 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1176 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1177 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1178 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1179 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1180 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001181 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301182 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001183 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001184 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1185 else
1186 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001187 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001188
Mika Kuoppala59bad942015-01-16 11:34:40 +02001189 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001190 mutex_unlock(&dev->struct_mutex);
1191
David Weinehall36cdd012016-08-22 13:59:31 +03001192 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001193 pm_ier = I915_READ(GEN6_PMIER);
1194 pm_imr = I915_READ(GEN6_PMIMR);
1195 pm_isr = I915_READ(GEN6_PMISR);
1196 pm_iir = I915_READ(GEN6_PMIIR);
1197 pm_mask = I915_READ(GEN6_PMINTRMSK);
1198 } else {
1199 pm_ier = I915_READ(GEN8_GT_IER(2));
1200 pm_imr = I915_READ(GEN8_GT_IMR(2));
1201 pm_isr = I915_READ(GEN8_GT_ISR(2));
1202 pm_iir = I915_READ(GEN8_GT_IIR(2));
1203 pm_mask = I915_READ(GEN6_PMINTRMSK);
1204 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001205 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001206 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301207 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001208 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001209 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001210 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001211 seq_printf(m, "Render p-state VID: %d\n",
1212 gt_perf_status & 0xff);
1213 seq_printf(m, "Render p-state limit: %d\n",
1214 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001215 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1216 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1217 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1218 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001219 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001220 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301221 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1222 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1223 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1224 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1225 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1226 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001227 seq_printf(m, "Up threshold: %d%%\n",
1228 dev_priv->rps.up_threshold);
1229
Akash Goeld6cda9c2016-04-23 00:05:46 +05301230 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1231 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1232 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1233 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1234 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1235 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001236 seq_printf(m, "Down threshold: %d%%\n",
1237 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001238
David Weinehall36cdd012016-08-22 13:59:31 +03001239 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001240 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001241 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001242 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001243 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001244 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001245
1246 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001247 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001248 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001249 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001250 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001251
David Weinehall36cdd012016-08-22 13:59:31 +03001252 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001253 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001254 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001255 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001256 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001257 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001258 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001259 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001260
Chris Wilsond86ed342015-04-27 13:41:19 +01001261 seq_printf(m, "Current freq: %d MHz\n",
1262 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1263 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001264 seq_printf(m, "Idle freq: %d MHz\n",
1265 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001266 seq_printf(m, "Min freq: %d MHz\n",
1267 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001268 seq_printf(m, "Boost freq: %d MHz\n",
1269 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001270 seq_printf(m, "Max freq: %d MHz\n",
1271 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1272 seq_printf(m,
1273 "efficient (RPe) frequency: %d MHz\n",
1274 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001275 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001276 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001277 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001278
Mika Kahola1170f282015-09-25 14:00:32 +03001279 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1280 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1281 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1282
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001283out:
1284 intel_runtime_pm_put(dev_priv);
1285 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001286}
1287
Ben Widawskyd6369512016-09-20 16:54:32 +03001288static void i915_instdone_info(struct drm_i915_private *dev_priv,
1289 struct seq_file *m,
1290 struct intel_instdone *instdone)
1291{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001292 int slice;
1293 int subslice;
1294
Ben Widawskyd6369512016-09-20 16:54:32 +03001295 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1296 instdone->instdone);
1297
1298 if (INTEL_GEN(dev_priv) <= 3)
1299 return;
1300
1301 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1302 instdone->slice_common);
1303
1304 if (INTEL_GEN(dev_priv) <= 6)
1305 return;
1306
Ben Widawskyf9e61372016-09-20 16:54:33 +03001307 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1308 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1309 slice, subslice, instdone->sampler[slice][subslice]);
1310
1311 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1312 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1313 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001314}
1315
Chris Wilsonf6544492015-01-26 18:03:04 +02001316static int i915_hangcheck_info(struct seq_file *m, void *unused)
1317{
David Weinehall36cdd012016-08-22 13:59:31 +03001318 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001319 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001320 u64 acthd[I915_NUM_ENGINES];
1321 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001322 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001323 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001324
Chris Wilson8af29b02016-09-09 14:11:47 +01001325 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1326 seq_printf(m, "Wedged\n");
1327 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1328 seq_printf(m, "Reset in progress\n");
1329 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1330 seq_printf(m, "Waiter holding struct mutex\n");
1331 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1332 seq_printf(m, "struct_mutex blocked for reset\n");
1333
Chris Wilsonf6544492015-01-26 18:03:04 +02001334 if (!i915.enable_hangcheck) {
1335 seq_printf(m, "Hangcheck disabled\n");
1336 return 0;
1337 }
1338
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001339 intel_runtime_pm_get(dev_priv);
1340
Dave Gordonc3232b12016-03-23 18:19:53 +00001341 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001342 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001343 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001344 }
1345
Chris Wilson0e704472016-10-12 10:05:17 +01001346 intel_engine_get_instdone(&dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001347
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001348 intel_runtime_pm_put(dev_priv);
1349
Chris Wilsonf6544492015-01-26 18:03:04 +02001350 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1351 seq_printf(m, "Hangcheck active, fires in %dms\n",
1352 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1353 jiffies));
1354 } else
1355 seq_printf(m, "Hangcheck inactive\n");
1356
Dave Gordonc3232b12016-03-23 18:19:53 +00001357 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001358 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1359 struct rb_node *rb;
1360
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001361 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001362 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1363 engine->hangcheck.seqno,
1364 seqno[id],
1365 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001366 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1367 yesno(intel_engine_has_waiter(engine)),
1368 yesno(test_bit(engine->id,
1369 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilson33f53712016-10-04 21:11:32 +01001370 spin_lock(&b->lock);
1371 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1372 struct intel_wait *w = container_of(rb, typeof(*w), node);
1373
1374 seq_printf(m, "\t%s [%d] waiting for %x\n",
1375 w->tsk->comm, w->tsk->pid, w->seqno);
1376 }
1377 spin_unlock(&b->lock);
1378
Chris Wilsonf6544492015-01-26 18:03:04 +02001379 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001380 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001381 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001382 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1383 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001384
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001385 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001386 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001387
Ben Widawskyd6369512016-09-20 16:54:32 +03001388 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001389
Ben Widawskyd6369512016-09-20 16:54:32 +03001390 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001391
Ben Widawskyd6369512016-09-20 16:54:32 +03001392 i915_instdone_info(dev_priv, m,
1393 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001394 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001395 }
1396
1397 return 0;
1398}
1399
Ben Widawsky4d855292011-12-12 19:34:16 -08001400static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001401{
David Weinehall36cdd012016-08-22 13:59:31 +03001402 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1403 struct drm_device *dev = &dev_priv->drm;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001404 u32 rgvmodectl, rstdbyctl;
1405 u16 crstandvid;
1406 int ret;
1407
1408 ret = mutex_lock_interruptible(&dev->struct_mutex);
1409 if (ret)
1410 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001411 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001412
1413 rgvmodectl = I915_READ(MEMMODECTL);
1414 rstdbyctl = I915_READ(RSTDBYCTL);
1415 crstandvid = I915_READ16(CRSTANDVID);
1416
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001417 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001418 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001419
Jani Nikula742f4912015-09-03 11:16:09 +03001420 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001421 seq_printf(m, "Boost freq: %d\n",
1422 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1423 MEMMODE_BOOST_FREQ_SHIFT);
1424 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001425 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001427 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001428 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001429 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001430 seq_printf(m, "Starting frequency: P%d\n",
1431 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001432 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001433 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001434 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1435 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1436 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1437 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001438 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001439 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001440 switch (rstdbyctl & RSX_STATUS_MASK) {
1441 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001442 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001443 break;
1444 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001445 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001446 break;
1447 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001448 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001449 break;
1450 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001451 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001452 break;
1453 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001454 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001455 break;
1456 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001457 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001458 break;
1459 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001460 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001461 break;
1462 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001463
1464 return 0;
1465}
1466
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001467static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001468{
David Weinehall36cdd012016-08-22 13:59:31 +03001469 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001470 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001471
1472 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001473 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001474 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001475 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001476 fw_domain->wake_count);
1477 }
1478 spin_unlock_irq(&dev_priv->uncore.lock);
1479
1480 return 0;
1481}
1482
Deepak S669ab5a2014-01-10 15:18:26 +05301483static int vlv_drpc_info(struct seq_file *m)
1484{
David Weinehall36cdd012016-08-22 13:59:31 +03001485 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001486 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301487
Imre Deakd46c0512014-04-14 20:24:27 +03001488 intel_runtime_pm_get(dev_priv);
1489
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001490 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301491 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1492 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1493
Imre Deakd46c0512014-04-14 20:24:27 +03001494 intel_runtime_pm_put(dev_priv);
1495
Deepak S669ab5a2014-01-10 15:18:26 +05301496 seq_printf(m, "Video Turbo Mode: %s\n",
1497 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1498 seq_printf(m, "Turbo enabled: %s\n",
1499 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1500 seq_printf(m, "HW control enabled: %s\n",
1501 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1502 seq_printf(m, "SW control enabled: %s\n",
1503 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1504 GEN6_RP_MEDIA_SW_MODE));
1505 seq_printf(m, "RC6 Enabled: %s\n",
1506 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1507 GEN6_RC_CTL_EI_MODE(1))));
1508 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001509 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301510 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001511 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301512
Imre Deak9cc19be2014-04-14 20:24:24 +03001513 seq_printf(m, "Render RC6 residency since boot: %u\n",
1514 I915_READ(VLV_GT_RENDER_RC6));
1515 seq_printf(m, "Media RC6 residency since boot: %u\n",
1516 I915_READ(VLV_GT_MEDIA_RC6));
1517
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001518 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301519}
1520
Ben Widawsky4d855292011-12-12 19:34:16 -08001521static int gen6_drpc_info(struct seq_file *m)
1522{
David Weinehall36cdd012016-08-22 13:59:31 +03001523 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1524 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001525 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301526 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001527 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001528 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001529
1530 ret = mutex_lock_interruptible(&dev->struct_mutex);
1531 if (ret)
1532 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001533 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001534
Chris Wilson907b28c2013-07-19 20:36:52 +01001535 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001536 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001537 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001538
1539 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001540 seq_puts(m, "RC information inaccurate because somebody "
1541 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001542 } else {
1543 /* NB: we cannot use forcewake, else we read the wrong values */
1544 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1545 udelay(10);
1546 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1547 }
1548
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001549 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001550 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001551
1552 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1553 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001554 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301555 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1556 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1557 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001558 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001559 mutex_lock(&dev_priv->rps.hw_lock);
1560 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1561 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001562
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001563 intel_runtime_pm_put(dev_priv);
1564
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 seq_printf(m, "Video Turbo Mode: %s\n",
1566 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1567 seq_printf(m, "HW control enabled: %s\n",
1568 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1569 seq_printf(m, "SW control enabled: %s\n",
1570 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1571 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001572 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001573 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1574 seq_printf(m, "RC6 Enabled: %s\n",
1575 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001576 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301577 seq_printf(m, "Render Well Gating Enabled: %s\n",
1578 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1579 seq_printf(m, "Media Well Gating Enabled: %s\n",
1580 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1581 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001582 seq_printf(m, "Deep RC6 Enabled: %s\n",
1583 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1584 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1585 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001586 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 switch (gt_core_status & GEN6_RCn_MASK) {
1588 case GEN6_RC0:
1589 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001590 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001591 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001592 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 break;
1594 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001596 break;
1597 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001598 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001599 break;
1600 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001601 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001602 break;
1603 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001604 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001605 break;
1606 }
1607
1608 seq_printf(m, "Core Power Down: %s\n",
1609 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001610 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301611 seq_printf(m, "Render Power Well: %s\n",
1612 (gen9_powergate_status &
1613 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1614 seq_printf(m, "Media Power Well: %s\n",
1615 (gen9_powergate_status &
1616 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1617 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001618
1619 /* Not exactly sure what this is */
1620 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1621 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1622 seq_printf(m, "RC6 residency since boot: %u\n",
1623 I915_READ(GEN6_GT_GFX_RC6));
1624 seq_printf(m, "RC6+ residency since boot: %u\n",
1625 I915_READ(GEN6_GT_GFX_RC6p));
1626 seq_printf(m, "RC6++ residency since boot: %u\n",
1627 I915_READ(GEN6_GT_GFX_RC6pp));
1628
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001629 seq_printf(m, "RC6 voltage: %dmV\n",
1630 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1631 seq_printf(m, "RC6+ voltage: %dmV\n",
1632 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1633 seq_printf(m, "RC6++ voltage: %dmV\n",
1634 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301635 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001636}
1637
1638static int i915_drpc_info(struct seq_file *m, void *unused)
1639{
David Weinehall36cdd012016-08-22 13:59:31 +03001640 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001641
David Weinehall36cdd012016-08-22 13:59:31 +03001642 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301643 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001644 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001645 return gen6_drpc_info(m);
1646 else
1647 return ironlake_drpc_info(m);
1648}
1649
Daniel Vetter9a851782015-06-18 10:30:22 +02001650static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1651{
David Weinehall36cdd012016-08-22 13:59:31 +03001652 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001653
1654 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1655 dev_priv->fb_tracking.busy_bits);
1656
1657 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1658 dev_priv->fb_tracking.flip_bits);
1659
1660 return 0;
1661}
1662
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001663static int i915_fbc_status(struct seq_file *m, void *unused)
1664{
David Weinehall36cdd012016-08-22 13:59:31 +03001665 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001666
David Weinehall36cdd012016-08-22 13:59:31 +03001667 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001668 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001669 return 0;
1670 }
1671
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001672 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001673 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001674
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001675 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001676 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001677 else
1678 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001679 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001680
Nagaraju, Vathsalabc4ec7c2016-09-22 14:19:53 +05301681 if (intel_fbc_is_active(dev_priv) &&
1682 INTEL_GEN(dev_priv) >= 7)
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001683 seq_printf(m, "Compressing: %s\n",
1684 yesno(I915_READ(FBC_STATUS2) &
1685 FBC_COMPRESSION_MASK));
1686
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001687 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001688 intel_runtime_pm_put(dev_priv);
1689
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001690 return 0;
1691}
1692
Rodrigo Vivida46f932014-08-01 02:04:45 -07001693static int i915_fbc_fc_get(void *data, u64 *val)
1694{
David Weinehall36cdd012016-08-22 13:59:31 +03001695 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001696
David Weinehall36cdd012016-08-22 13:59:31 +03001697 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001698 return -ENODEV;
1699
Rodrigo Vivida46f932014-08-01 02:04:45 -07001700 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001701
1702 return 0;
1703}
1704
1705static int i915_fbc_fc_set(void *data, u64 val)
1706{
David Weinehall36cdd012016-08-22 13:59:31 +03001707 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001708 u32 reg;
1709
David Weinehall36cdd012016-08-22 13:59:31 +03001710 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001711 return -ENODEV;
1712
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001713 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001714
1715 reg = I915_READ(ILK_DPFC_CONTROL);
1716 dev_priv->fbc.false_color = val;
1717
1718 I915_WRITE(ILK_DPFC_CONTROL, val ?
1719 (reg | FBC_CTL_FALSE_COLOR) :
1720 (reg & ~FBC_CTL_FALSE_COLOR));
1721
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001722 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001723 return 0;
1724}
1725
1726DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1727 i915_fbc_fc_get, i915_fbc_fc_set,
1728 "%llu\n");
1729
Paulo Zanoni92d44622013-05-31 16:33:24 -03001730static int i915_ips_status(struct seq_file *m, void *unused)
1731{
David Weinehall36cdd012016-08-22 13:59:31 +03001732 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001733
David Weinehall36cdd012016-08-22 13:59:31 +03001734 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001735 seq_puts(m, "not supported\n");
1736 return 0;
1737 }
1738
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001739 intel_runtime_pm_get(dev_priv);
1740
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001741 seq_printf(m, "Enabled by kernel parameter: %s\n",
1742 yesno(i915.enable_ips));
1743
David Weinehall36cdd012016-08-22 13:59:31 +03001744 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001745 seq_puts(m, "Currently: unknown\n");
1746 } else {
1747 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1748 seq_puts(m, "Currently: enabled\n");
1749 else
1750 seq_puts(m, "Currently: disabled\n");
1751 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001752
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001753 intel_runtime_pm_put(dev_priv);
1754
Paulo Zanoni92d44622013-05-31 16:33:24 -03001755 return 0;
1756}
1757
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001758static int i915_sr_status(struct seq_file *m, void *unused)
1759{
David Weinehall36cdd012016-08-22 13:59:31 +03001760 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001761 bool sr_enabled = false;
1762
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001763 intel_runtime_pm_get(dev_priv);
1764
David Weinehall36cdd012016-08-22 13:59:31 +03001765 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001766 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001767 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1768 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001769 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001770 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001771 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001772 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001773 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001774 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001775 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001776
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001777 intel_runtime_pm_put(dev_priv);
1778
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001779 seq_printf(m, "self-refresh: %s\n",
1780 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001781
1782 return 0;
1783}
1784
Jesse Barnes7648fa92010-05-20 14:28:11 -07001785static int i915_emon_status(struct seq_file *m, void *unused)
1786{
David Weinehall36cdd012016-08-22 13:59:31 +03001787 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1788 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001789 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001790 int ret;
1791
David Weinehall36cdd012016-08-22 13:59:31 +03001792 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001793 return -ENODEV;
1794
Chris Wilsonde227ef2010-07-03 07:58:38 +01001795 ret = mutex_lock_interruptible(&dev->struct_mutex);
1796 if (ret)
1797 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001798
1799 temp = i915_mch_val(dev_priv);
1800 chipset = i915_chipset_val(dev_priv);
1801 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001802 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001803
1804 seq_printf(m, "GMCH temp: %ld\n", temp);
1805 seq_printf(m, "Chipset power: %ld\n", chipset);
1806 seq_printf(m, "GFX power: %ld\n", gfx);
1807 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1808
1809 return 0;
1810}
1811
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001812static int i915_ring_freq_table(struct seq_file *m, void *unused)
1813{
David Weinehall36cdd012016-08-22 13:59:31 +03001814 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001815 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001816 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301817 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001818
Carlos Santa26310342016-08-17 12:30:41 -07001819 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001820 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001821 return 0;
1822 }
1823
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001824 intel_runtime_pm_get(dev_priv);
1825
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001826 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001828 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001829
David Weinehall36cdd012016-08-22 13:59:31 +03001830 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301831 /* Convert GT frequency to 50 HZ units */
1832 min_gpu_freq =
1833 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1834 max_gpu_freq =
1835 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1836 } else {
1837 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1838 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1839 }
1840
Damien Lespiau267f0c92013-06-24 22:59:48 +01001841 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001842
Akash Goelf936ec32015-06-29 14:50:22 +05301843 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001844 ia_freq = gpu_freq;
1845 sandybridge_pcode_read(dev_priv,
1846 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1847 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001848 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301849 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001850 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001851 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001852 ((ia_freq >> 0) & 0xff) * 100,
1853 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001854 }
1855
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001856 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001857
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001858out:
1859 intel_runtime_pm_put(dev_priv);
1860 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001861}
1862
Chris Wilson44834a62010-08-19 16:09:23 +01001863static int i915_opregion(struct seq_file *m, void *unused)
1864{
David Weinehall36cdd012016-08-22 13:59:31 +03001865 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1866 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001867 struct intel_opregion *opregion = &dev_priv->opregion;
1868 int ret;
1869
1870 ret = mutex_lock_interruptible(&dev->struct_mutex);
1871 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001872 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001873
Jani Nikula2455a8e2015-12-14 12:50:53 +02001874 if (opregion->header)
1875 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001876
1877 mutex_unlock(&dev->struct_mutex);
1878
Daniel Vetter0d38f002012-04-21 22:49:10 +02001879out:
Chris Wilson44834a62010-08-19 16:09:23 +01001880 return 0;
1881}
1882
Jani Nikulaada8f952015-12-15 13:17:12 +02001883static int i915_vbt(struct seq_file *m, void *unused)
1884{
David Weinehall36cdd012016-08-22 13:59:31 +03001885 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001886
1887 if (opregion->vbt)
1888 seq_write(m, opregion->vbt, opregion->vbt_size);
1889
1890 return 0;
1891}
1892
Chris Wilson37811fc2010-08-25 22:45:57 +01001893static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1894{
David Weinehall36cdd012016-08-22 13:59:31 +03001895 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1896 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301897 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001898 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001899 int ret;
1900
1901 ret = mutex_lock_interruptible(&dev->struct_mutex);
1902 if (ret)
1903 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001904
Daniel Vetter06957262015-08-10 13:34:08 +02001905#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001906 if (dev_priv->fbdev) {
1907 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001908
Chris Wilson25bcce92016-07-02 15:36:00 +01001909 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1910 fbdev_fb->base.width,
1911 fbdev_fb->base.height,
1912 fbdev_fb->base.depth,
1913 fbdev_fb->base.bits_per_pixel,
1914 fbdev_fb->base.modifier[0],
1915 drm_framebuffer_read_refcount(&fbdev_fb->base));
1916 describe_obj(m, fbdev_fb->obj);
1917 seq_putc(m, '\n');
1918 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001919#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001920
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001921 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001922 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301923 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1924 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001925 continue;
1926
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001927 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001928 fb->base.width,
1929 fb->base.height,
1930 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001931 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001932 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001933 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001934 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001935 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001936 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001937 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001938 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001939
1940 return 0;
1941}
1942
Chris Wilson7e37f882016-08-02 22:50:21 +01001943static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001944{
1945 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001946 ring->space, ring->head, ring->tail,
1947 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001948}
1949
Ben Widawskye76d3632011-03-19 18:14:29 -07001950static int i915_context_status(struct seq_file *m, void *unused)
1951{
David Weinehall36cdd012016-08-22 13:59:31 +03001952 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1953 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001954 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001955 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00001956 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001957
Daniel Vetterf3d28872014-05-29 23:23:08 +02001958 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001959 if (ret)
1960 return ret;
1961
Ben Widawskya33afea2013-09-17 21:12:45 -07001962 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001963 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001964 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001965 struct task_struct *task;
1966
Chris Wilsonc84455b2016-08-15 10:49:08 +01001967 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001968 if (task) {
1969 seq_printf(m, "(%s [%d]) ",
1970 task->comm, task->pid);
1971 put_task_struct(task);
1972 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001973 } else if (IS_ERR(ctx->file_priv)) {
1974 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001975 } else {
1976 seq_puts(m, "(kernel) ");
1977 }
1978
Chris Wilsonbca44d82016-05-24 14:53:41 +01001979 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1980 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001981
Chris Wilsonbca44d82016-05-24 14:53:41 +01001982 for_each_engine(engine, dev_priv) {
1983 struct intel_context *ce = &ctx->engine[engine->id];
1984
1985 seq_printf(m, "%s: ", engine->name);
1986 seq_putc(m, ce->initialised ? 'I' : 'i');
1987 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001988 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001989 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001990 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001991 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001992 }
1993
Ben Widawskya33afea2013-09-17 21:12:45 -07001994 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001995 }
1996
Daniel Vetterf3d28872014-05-29 23:23:08 +02001997 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001998
1999 return 0;
2000}
2001
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002002static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002003 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002004 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002005{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002006 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002007 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002008 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002009
Chris Wilson7069b142016-04-28 09:56:52 +01002010 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2011
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002012 if (!vma) {
2013 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002014 return;
2015 }
2016
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002017 if (vma->flags & I915_VMA_GLOBAL_BIND)
2018 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002019 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002020
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002021 if (i915_gem_object_get_pages(vma->obj)) {
2022 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002023 return;
2024 }
2025
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002026 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2027 if (page) {
2028 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002029
2030 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002031 seq_printf(m,
2032 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2033 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002034 reg_state[j], reg_state[j + 1],
2035 reg_state[j + 2], reg_state[j + 3]);
2036 }
2037 kunmap_atomic(reg_state);
2038 }
2039
2040 seq_putc(m, '\n');
2041}
2042
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002043static int i915_dump_lrc(struct seq_file *m, void *unused)
2044{
David Weinehall36cdd012016-08-22 13:59:31 +03002045 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2046 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002047 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002048 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002049 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002050
2051 if (!i915.enable_execlists) {
2052 seq_printf(m, "Logical Ring Contexts are disabled\n");
2053 return 0;
2054 }
2055
2056 ret = mutex_lock_interruptible(&dev->struct_mutex);
2057 if (ret)
2058 return ret;
2059
Dave Gordone28e4042016-01-19 19:02:55 +00002060 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002061 for_each_engine(engine, dev_priv)
2062 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002063
2064 mutex_unlock(&dev->struct_mutex);
2065
2066 return 0;
2067}
2068
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002069static const char *swizzle_string(unsigned swizzle)
2070{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002071 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002072 case I915_BIT_6_SWIZZLE_NONE:
2073 return "none";
2074 case I915_BIT_6_SWIZZLE_9:
2075 return "bit9";
2076 case I915_BIT_6_SWIZZLE_9_10:
2077 return "bit9/bit10";
2078 case I915_BIT_6_SWIZZLE_9_11:
2079 return "bit9/bit11";
2080 case I915_BIT_6_SWIZZLE_9_10_11:
2081 return "bit9/bit10/bit11";
2082 case I915_BIT_6_SWIZZLE_9_17:
2083 return "bit9/bit17";
2084 case I915_BIT_6_SWIZZLE_9_10_17:
2085 return "bit9/bit10/bit17";
2086 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002087 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002088 }
2089
2090 return "bug";
2091}
2092
2093static int i915_swizzle_info(struct seq_file *m, void *data)
2094{
David Weinehall36cdd012016-08-22 13:59:31 +03002095 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2096 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002097 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002098
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002099 ret = mutex_lock_interruptible(&dev->struct_mutex);
2100 if (ret)
2101 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002102 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002103
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002104 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2105 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2106 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2107 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2108
David Weinehall36cdd012016-08-22 13:59:31 +03002109 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002110 seq_printf(m, "DDC = 0x%08x\n",
2111 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002112 seq_printf(m, "DDC2 = 0x%08x\n",
2113 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002114 seq_printf(m, "C0DRB3 = 0x%04x\n",
2115 I915_READ16(C0DRB3));
2116 seq_printf(m, "C1DRB3 = 0x%04x\n",
2117 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002118 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002119 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2120 I915_READ(MAD_DIMM_C0));
2121 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2122 I915_READ(MAD_DIMM_C1));
2123 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2124 I915_READ(MAD_DIMM_C2));
2125 seq_printf(m, "TILECTL = 0x%08x\n",
2126 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002127 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002128 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2129 I915_READ(GAMTARBMODE));
2130 else
2131 seq_printf(m, "ARB_MODE = 0x%08x\n",
2132 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002133 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2134 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002135 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002136
2137 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2138 seq_puts(m, "L-shaped memory detected\n");
2139
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002140 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002141 mutex_unlock(&dev->struct_mutex);
2142
2143 return 0;
2144}
2145
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002146static int per_file_ctx(int id, void *ptr, void *data)
2147{
Chris Wilsone2efd132016-05-24 14:53:34 +01002148 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002149 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002150 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2151
2152 if (!ppgtt) {
2153 seq_printf(m, " no ppgtt for context %d\n",
2154 ctx->user_handle);
2155 return 0;
2156 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002157
Oscar Mateof83d6512014-05-22 14:13:38 +01002158 if (i915_gem_context_is_default(ctx))
2159 seq_puts(m, " default context:\n");
2160 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002161 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002162 ppgtt->debug_dump(ppgtt, m);
2163
2164 return 0;
2165}
2166
David Weinehall36cdd012016-08-22 13:59:31 +03002167static void gen8_ppgtt_info(struct seq_file *m,
2168 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002169{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002170 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002171 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002172 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002173
Ben Widawsky77df6772013-11-02 21:07:30 -07002174 if (!ppgtt)
2175 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002176
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002177 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002178 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002179 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002180 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002181 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002182 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002183 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002184 }
2185 }
2186}
2187
David Weinehall36cdd012016-08-22 13:59:31 +03002188static void gen6_ppgtt_info(struct seq_file *m,
2189 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002190{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002191 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002192
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002193 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002194 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2195
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002196 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002197 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002198 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002199 seq_printf(m, "GFX_MODE: 0x%08x\n",
2200 I915_READ(RING_MODE_GEN7(engine)));
2201 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2202 I915_READ(RING_PP_DIR_BASE(engine)));
2203 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2204 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2205 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2206 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002207 }
2208 if (dev_priv->mm.aliasing_ppgtt) {
2209 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2210
Damien Lespiau267f0c92013-06-24 22:59:48 +01002211 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002212 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002213
Ben Widawsky87d60b62013-12-06 14:11:29 -08002214 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002215 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002216
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002217 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002218}
2219
2220static int i915_ppgtt_info(struct seq_file *m, void *data)
2221{
David Weinehall36cdd012016-08-22 13:59:31 +03002222 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2223 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002224 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002225 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002226
Chris Wilson637ee292016-08-22 14:28:20 +01002227 mutex_lock(&dev->filelist_mutex);
2228 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002229 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002230 goto out_unlock;
2231
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002232 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002233
David Weinehall36cdd012016-08-22 13:59:31 +03002234 if (INTEL_GEN(dev_priv) >= 8)
2235 gen8_ppgtt_info(m, dev_priv);
2236 else if (INTEL_GEN(dev_priv) >= 6)
2237 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002238
Michel Thierryea91e402015-07-29 17:23:57 +01002239 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2240 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002241 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002242
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002243 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002244 if (!task) {
2245 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002246 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002247 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002248 seq_printf(m, "\nproc: %s\n", task->comm);
2249 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002250 idr_for_each(&file_priv->context_idr, per_file_ctx,
2251 (void *)(unsigned long)m);
2252 }
2253
Chris Wilson637ee292016-08-22 14:28:20 +01002254out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002255 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002256 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002257out_unlock:
2258 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002259 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002260}
2261
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002262static int count_irq_waiters(struct drm_i915_private *i915)
2263{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002264 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002265 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002266
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002267 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002268 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002269
2270 return count;
2271}
2272
Chris Wilson7466c292016-08-15 09:49:33 +01002273static const char *rps_power_to_str(unsigned int power)
2274{
2275 static const char * const strings[] = {
2276 [LOW_POWER] = "low power",
2277 [BETWEEN] = "mixed",
2278 [HIGH_POWER] = "high power",
2279 };
2280
2281 if (power >= ARRAY_SIZE(strings) || !strings[power])
2282 return "unknown";
2283
2284 return strings[power];
2285}
2286
Chris Wilson1854d5c2015-04-07 16:20:32 +01002287static int i915_rps_boost_info(struct seq_file *m, void *data)
2288{
David Weinehall36cdd012016-08-22 13:59:31 +03002289 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2290 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002291 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002292
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002293 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002294 seq_printf(m, "GPU busy? %s [%x]\n",
2295 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002296 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002297 seq_printf(m, "Frequency requested %d\n",
2298 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2299 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002300 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2301 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2302 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2303 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002304 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2305 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2306 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2307 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002308
2309 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002310 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002311 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2312 struct drm_i915_file_private *file_priv = file->driver_priv;
2313 struct task_struct *task;
2314
2315 rcu_read_lock();
2316 task = pid_task(file->pid, PIDTYPE_PID);
2317 seq_printf(m, "%s [%d]: %d boosts%s\n",
2318 task ? task->comm : "<unknown>",
2319 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002320 file_priv->rps.boosts,
2321 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002322 rcu_read_unlock();
2323 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002324 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002325 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002326 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002327
Chris Wilson7466c292016-08-15 09:49:33 +01002328 if (INTEL_GEN(dev_priv) >= 6 &&
2329 dev_priv->rps.enabled &&
2330 dev_priv->gt.active_engines) {
2331 u32 rpup, rpupei;
2332 u32 rpdown, rpdownei;
2333
2334 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2335 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2336 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2337 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2338 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2339 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2340
2341 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2342 rps_power_to_str(dev_priv->rps.power));
2343 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2344 100 * rpup / rpupei,
2345 dev_priv->rps.up_threshold);
2346 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2347 100 * rpdown / rpdownei,
2348 dev_priv->rps.down_threshold);
2349 } else {
2350 seq_puts(m, "\nRPS Autotuning inactive\n");
2351 }
2352
Chris Wilson8d3afd72015-05-21 21:01:47 +01002353 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002354}
2355
Ben Widawsky63573eb2013-07-04 11:02:07 -07002356static int i915_llc(struct seq_file *m, void *data)
2357{
David Weinehall36cdd012016-08-22 13:59:31 +03002358 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002359 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002360
David Weinehall36cdd012016-08-22 13:59:31 +03002361 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002362 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2363 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002364
2365 return 0;
2366}
2367
Alex Daifdf5d352015-08-12 15:43:37 +01002368static int i915_guc_load_status_info(struct seq_file *m, void *data)
2369{
David Weinehall36cdd012016-08-22 13:59:31 +03002370 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002371 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2372 u32 tmp, i;
2373
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002374 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002375 return 0;
2376
2377 seq_printf(m, "GuC firmware status:\n");
2378 seq_printf(m, "\tpath: %s\n",
2379 guc_fw->guc_fw_path);
2380 seq_printf(m, "\tfetch: %s\n",
2381 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2382 seq_printf(m, "\tload: %s\n",
2383 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2384 seq_printf(m, "\tversion wanted: %d.%d\n",
2385 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2386 seq_printf(m, "\tversion found: %d.%d\n",
2387 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002388 seq_printf(m, "\theader: offset is %d; size = %d\n",
2389 guc_fw->header_offset, guc_fw->header_size);
2390 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2391 guc_fw->ucode_offset, guc_fw->ucode_size);
2392 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2393 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002394
2395 tmp = I915_READ(GUC_STATUS);
2396
2397 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2398 seq_printf(m, "\tBootrom status = 0x%x\n",
2399 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2400 seq_printf(m, "\tuKernel status = 0x%x\n",
2401 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2402 seq_printf(m, "\tMIA Core status = 0x%x\n",
2403 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2404 seq_puts(m, "\nScratch registers:\n");
2405 for (i = 0; i < 16; i++)
2406 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2407
2408 return 0;
2409}
2410
Dave Gordon8b417c22015-08-12 15:43:44 +01002411static void i915_guc_client_info(struct seq_file *m,
2412 struct drm_i915_private *dev_priv,
2413 struct i915_guc_client *client)
2414{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002415 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002416 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002417 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002418
2419 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2420 client->priority, client->ctx_index, client->proc_desc_offset);
2421 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2422 client->doorbell_id, client->doorbell_offset, client->cookie);
2423 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2424 client->wq_size, client->wq_offset, client->wq_tail);
2425
Dave Gordon551aaec2016-05-13 15:36:33 +01002426 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002427 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2428 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2429
Dave Gordonc18468c2016-08-09 15:19:22 +01002430 for_each_engine_id(engine, dev_priv, id) {
2431 u64 submissions = client->submissions[id];
2432 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002433 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002434 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002435 }
2436 seq_printf(m, "\tTotal: %llu\n", tot);
2437}
2438
2439static int i915_guc_info(struct seq_file *m, void *data)
2440{
David Weinehall36cdd012016-08-22 13:59:31 +03002441 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2442 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002443 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002444 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002445 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002446 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002447 u64 total = 0;
2448
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002449 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002450 return 0;
2451
Alex Dai5a843302015-12-02 16:56:29 -08002452 if (mutex_lock_interruptible(&dev->struct_mutex))
2453 return 0;
2454
Dave Gordon8b417c22015-08-12 15:43:44 +01002455 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002456 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002457 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002458 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002459
2460 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002461
Dave Gordon9636f6d2016-06-13 17:57:28 +01002462 seq_printf(m, "Doorbell map:\n");
2463 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2464 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2465
Dave Gordon8b417c22015-08-12 15:43:44 +01002466 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2467 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2468 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2469 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2470 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2471
2472 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonc18468c2016-08-09 15:19:22 +01002473 for_each_engine_id(engine, dev_priv, id) {
2474 u64 submissions = guc.submissions[id];
2475 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002476 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002477 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002478 }
2479 seq_printf(m, "\t%s: %llu\n", "Total", total);
2480
2481 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2482 i915_guc_client_info(m, dev_priv, &client);
2483
2484 /* Add more as required ... */
2485
2486 return 0;
2487}
2488
Alex Dai4c7e77f2015-08-12 15:43:40 +01002489static int i915_guc_log_dump(struct seq_file *m, void *data)
2490{
David Weinehall36cdd012016-08-22 13:59:31 +03002491 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002492 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002493 int i = 0, pg;
2494
Chris Wilson8b797af2016-08-15 10:48:51 +01002495 if (!dev_priv->guc.log_vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002496 return 0;
2497
Chris Wilson8b797af2016-08-15 10:48:51 +01002498 obj = dev_priv->guc.log_vma->obj;
2499 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2500 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002501
2502 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2503 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2504 *(log + i), *(log + i + 1),
2505 *(log + i + 2), *(log + i + 3));
2506
2507 kunmap_atomic(log);
2508 }
2509
2510 seq_putc(m, '\n');
2511
2512 return 0;
2513}
2514
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002515static int i915_edp_psr_status(struct seq_file *m, void *data)
2516{
David Weinehall36cdd012016-08-22 13:59:31 +03002517 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002518 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002519 u32 stat[3];
2520 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002521 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002522
David Weinehall36cdd012016-08-22 13:59:31 +03002523 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002524 seq_puts(m, "PSR not supported\n");
2525 return 0;
2526 }
2527
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002528 intel_runtime_pm_get(dev_priv);
2529
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002530 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002531 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2532 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002533 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002534 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002535 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2536 dev_priv->psr.busy_frontbuffer_bits);
2537 seq_printf(m, "Re-enable work scheduled: %s\n",
2538 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002539
David Weinehall36cdd012016-08-22 13:59:31 +03002540 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002541 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002542 else {
2543 for_each_pipe(dev_priv, pipe) {
2544 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2545 VLV_EDP_PSR_CURR_STATE_MASK;
2546 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2547 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2548 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002549 }
2550 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002551
2552 seq_printf(m, "Main link in standby mode: %s\n",
2553 yesno(dev_priv->psr.link_standby));
2554
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002555 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002556
David Weinehall36cdd012016-08-22 13:59:31 +03002557 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002558 for_each_pipe(dev_priv, pipe) {
2559 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2560 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2561 seq_printf(m, " pipe %c", pipe_name(pipe));
2562 }
2563 seq_puts(m, "\n");
2564
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002565 /*
2566 * VLV/CHV PSR has no kind of performance counter
2567 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2568 */
David Weinehall36cdd012016-08-22 13:59:31 +03002569 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002570 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002571 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002572
2573 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2574 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002575 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002576
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002577 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002578 return 0;
2579}
2580
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002581static int i915_sink_crc(struct seq_file *m, void *data)
2582{
David Weinehall36cdd012016-08-22 13:59:31 +03002583 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2584 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002585 struct intel_connector *connector;
2586 struct intel_dp *intel_dp = NULL;
2587 int ret;
2588 u8 crc[6];
2589
2590 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002591 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002592 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002593
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002594 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002595 continue;
2596
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002597 crtc = connector->base.state->crtc;
2598 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002599 continue;
2600
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002601 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002602 continue;
2603
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002604 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002605
2606 ret = intel_dp_sink_crc(intel_dp, crc);
2607 if (ret)
2608 goto out;
2609
2610 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2611 crc[0], crc[1], crc[2],
2612 crc[3], crc[4], crc[5]);
2613 goto out;
2614 }
2615 ret = -ENODEV;
2616out:
2617 drm_modeset_unlock_all(dev);
2618 return ret;
2619}
2620
Jesse Barnesec013e72013-08-20 10:29:23 +01002621static int i915_energy_uJ(struct seq_file *m, void *data)
2622{
David Weinehall36cdd012016-08-22 13:59:31 +03002623 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002624 u64 power;
2625 u32 units;
2626
David Weinehall36cdd012016-08-22 13:59:31 +03002627 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002628 return -ENODEV;
2629
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002630 intel_runtime_pm_get(dev_priv);
2631
Jesse Barnesec013e72013-08-20 10:29:23 +01002632 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2633 power = (power & 0x1f00) >> 8;
2634 units = 1000000 / (1 << power); /* convert to uJ */
2635 power = I915_READ(MCH_SECP_NRG_STTS);
2636 power *= units;
2637
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002638 intel_runtime_pm_put(dev_priv);
2639
Jesse Barnesec013e72013-08-20 10:29:23 +01002640 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002641
2642 return 0;
2643}
2644
Damien Lespiau6455c872015-06-04 18:23:57 +01002645static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002646{
David Weinehall36cdd012016-08-22 13:59:31 +03002647 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002648 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002649
Chris Wilsona156e642016-04-03 14:14:21 +01002650 if (!HAS_RUNTIME_PM(dev_priv))
2651 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002652
Chris Wilson67d97da2016-07-04 08:08:31 +01002653 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002654 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002655 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002656#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002657 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002658 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002659#else
2660 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2661#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002662 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002663 pci_power_name(pdev->current_state),
2664 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002665
Jesse Barnesec013e72013-08-20 10:29:23 +01002666 return 0;
2667}
2668
Imre Deak1da51582013-11-25 17:15:35 +02002669static int i915_power_domain_info(struct seq_file *m, void *unused)
2670{
David Weinehall36cdd012016-08-22 13:59:31 +03002671 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002672 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2673 int i;
2674
2675 mutex_lock(&power_domains->lock);
2676
2677 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2678 for (i = 0; i < power_domains->power_well_count; i++) {
2679 struct i915_power_well *power_well;
2680 enum intel_display_power_domain power_domain;
2681
2682 power_well = &power_domains->power_wells[i];
2683 seq_printf(m, "%-25s %d\n", power_well->name,
2684 power_well->count);
2685
2686 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2687 power_domain++) {
2688 if (!(BIT(power_domain) & power_well->domains))
2689 continue;
2690
2691 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002692 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002693 power_domains->domain_use_count[power_domain]);
2694 }
2695 }
2696
2697 mutex_unlock(&power_domains->lock);
2698
2699 return 0;
2700}
2701
Damien Lespiaub7cec662015-10-27 14:47:01 +02002702static int i915_dmc_info(struct seq_file *m, void *unused)
2703{
David Weinehall36cdd012016-08-22 13:59:31 +03002704 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002705 struct intel_csr *csr;
2706
David Weinehall36cdd012016-08-22 13:59:31 +03002707 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002708 seq_puts(m, "not supported\n");
2709 return 0;
2710 }
2711
2712 csr = &dev_priv->csr;
2713
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002714 intel_runtime_pm_get(dev_priv);
2715
Damien Lespiaub7cec662015-10-27 14:47:01 +02002716 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2717 seq_printf(m, "path: %s\n", csr->fw_path);
2718
2719 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002720 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002721
2722 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2723 CSR_VERSION_MINOR(csr->version));
2724
David Weinehall36cdd012016-08-22 13:59:31 +03002725 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002726 seq_printf(m, "DC3 -> DC5 count: %d\n",
2727 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2728 seq_printf(m, "DC5 -> DC6 count: %d\n",
2729 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002730 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002731 seq_printf(m, "DC3 -> DC5 count: %d\n",
2732 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002733 }
2734
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002735out:
2736 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2737 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2738 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2739
Damien Lespiau83372062015-10-30 17:53:32 +02002740 intel_runtime_pm_put(dev_priv);
2741
Damien Lespiaub7cec662015-10-27 14:47:01 +02002742 return 0;
2743}
2744
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002745static void intel_seq_print_mode(struct seq_file *m, int tabs,
2746 struct drm_display_mode *mode)
2747{
2748 int i;
2749
2750 for (i = 0; i < tabs; i++)
2751 seq_putc(m, '\t');
2752
2753 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",
2754 mode->base.id, mode->name,
2755 mode->vrefresh, mode->clock,
2756 mode->hdisplay, mode->hsync_start,
2757 mode->hsync_end, mode->htotal,
2758 mode->vdisplay, mode->vsync_start,
2759 mode->vsync_end, mode->vtotal,
2760 mode->type, mode->flags);
2761}
2762
2763static void intel_encoder_info(struct seq_file *m,
2764 struct intel_crtc *intel_crtc,
2765 struct intel_encoder *intel_encoder)
2766{
David Weinehall36cdd012016-08-22 13:59:31 +03002767 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2768 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002769 struct drm_crtc *crtc = &intel_crtc->base;
2770 struct intel_connector *intel_connector;
2771 struct drm_encoder *encoder;
2772
2773 encoder = &intel_encoder->base;
2774 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002775 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002776 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2777 struct drm_connector *connector = &intel_connector->base;
2778 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2779 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002780 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002781 drm_get_connector_status_name(connector->status));
2782 if (connector->status == connector_status_connected) {
2783 struct drm_display_mode *mode = &crtc->mode;
2784 seq_printf(m, ", mode:\n");
2785 intel_seq_print_mode(m, 2, mode);
2786 } else {
2787 seq_putc(m, '\n');
2788 }
2789 }
2790}
2791
2792static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2793{
David Weinehall36cdd012016-08-22 13:59:31 +03002794 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2795 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002796 struct drm_crtc *crtc = &intel_crtc->base;
2797 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002798 struct drm_plane_state *plane_state = crtc->primary->state;
2799 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002800
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002801 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002802 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002803 fb->base.id, plane_state->src_x >> 16,
2804 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002805 else
2806 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002807 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2808 intel_encoder_info(m, intel_crtc, intel_encoder);
2809}
2810
2811static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2812{
2813 struct drm_display_mode *mode = panel->fixed_mode;
2814
2815 seq_printf(m, "\tfixed mode:\n");
2816 intel_seq_print_mode(m, 2, mode);
2817}
2818
2819static void intel_dp_info(struct seq_file *m,
2820 struct intel_connector *intel_connector)
2821{
2822 struct intel_encoder *intel_encoder = intel_connector->encoder;
2823 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2824
2825 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002826 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002827 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002828 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002829
2830 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2831 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002832}
2833
2834static void intel_hdmi_info(struct seq_file *m,
2835 struct intel_connector *intel_connector)
2836{
2837 struct intel_encoder *intel_encoder = intel_connector->encoder;
2838 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2839
Jani Nikula742f4912015-09-03 11:16:09 +03002840 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002841}
2842
2843static void intel_lvds_info(struct seq_file *m,
2844 struct intel_connector *intel_connector)
2845{
2846 intel_panel_info(m, &intel_connector->panel);
2847}
2848
2849static void intel_connector_info(struct seq_file *m,
2850 struct drm_connector *connector)
2851{
2852 struct intel_connector *intel_connector = to_intel_connector(connector);
2853 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002854 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002855
2856 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002857 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002858 drm_get_connector_status_name(connector->status));
2859 if (connector->status == connector_status_connected) {
2860 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2861 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2862 connector->display_info.width_mm,
2863 connector->display_info.height_mm);
2864 seq_printf(m, "\tsubpixel order: %s\n",
2865 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2866 seq_printf(m, "\tCEA rev: %d\n",
2867 connector->display_info.cea_rev);
2868 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002869
2870 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2871 return;
2872
2873 switch (connector->connector_type) {
2874 case DRM_MODE_CONNECTOR_DisplayPort:
2875 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002876 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002877 break;
2878 case DRM_MODE_CONNECTOR_LVDS:
2879 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002880 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002881 break;
2882 case DRM_MODE_CONNECTOR_HDMIA:
2883 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2884 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2885 intel_hdmi_info(m, intel_connector);
2886 break;
2887 default:
2888 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002889 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002890
Jesse Barnesf103fc72014-02-20 12:39:57 -08002891 seq_printf(m, "\tmodes:\n");
2892 list_for_each_entry(mode, &connector->modes, head)
2893 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002894}
2895
David Weinehall36cdd012016-08-22 13:59:31 +03002896static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002897{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002898 u32 state;
2899
David Weinehall36cdd012016-08-22 13:59:31 +03002900 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002901 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002902 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002903 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002904
2905 return state;
2906}
2907
David Weinehall36cdd012016-08-22 13:59:31 +03002908static bool cursor_position(struct drm_i915_private *dev_priv,
2909 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002910{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002911 u32 pos;
2912
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002913 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002914
2915 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2916 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2917 *x = -*x;
2918
2919 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2920 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2921 *y = -*y;
2922
David Weinehall36cdd012016-08-22 13:59:31 +03002923 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002924}
2925
Robert Fekete3abc4e02015-10-27 16:58:32 +01002926static const char *plane_type(enum drm_plane_type type)
2927{
2928 switch (type) {
2929 case DRM_PLANE_TYPE_OVERLAY:
2930 return "OVL";
2931 case DRM_PLANE_TYPE_PRIMARY:
2932 return "PRI";
2933 case DRM_PLANE_TYPE_CURSOR:
2934 return "CUR";
2935 /*
2936 * Deliberately omitting default: to generate compiler warnings
2937 * when a new drm_plane_type gets added.
2938 */
2939 }
2940
2941 return "unknown";
2942}
2943
2944static const char *plane_rotation(unsigned int rotation)
2945{
2946 static char buf[48];
2947 /*
2948 * According to doc only one DRM_ROTATE_ is allowed but this
2949 * will print them all to visualize if the values are misused
2950 */
2951 snprintf(buf, sizeof(buf),
2952 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03002953 (rotation & DRM_ROTATE_0) ? "0 " : "",
2954 (rotation & DRM_ROTATE_90) ? "90 " : "",
2955 (rotation & DRM_ROTATE_180) ? "180 " : "",
2956 (rotation & DRM_ROTATE_270) ? "270 " : "",
2957 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
2958 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01002959 rotation);
2960
2961 return buf;
2962}
2963
2964static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2965{
David Weinehall36cdd012016-08-22 13:59:31 +03002966 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2967 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01002968 struct intel_plane *intel_plane;
2969
2970 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
2971 struct drm_plane_state *state;
2972 struct drm_plane *plane = &intel_plane->base;
Eric Engestromd3828142016-08-15 16:29:55 +01002973 char *format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01002974
2975 if (!plane->state) {
2976 seq_puts(m, "plane->state is NULL!\n");
2977 continue;
2978 }
2979
2980 state = plane->state;
2981
Eric Engestrom90844f02016-08-15 01:02:38 +01002982 if (state->fb) {
2983 format_name = drm_get_format_name(state->fb->pixel_format);
2984 } else {
2985 format_name = kstrdup("N/A", GFP_KERNEL);
2986 }
2987
Robert Fekete3abc4e02015-10-27 16:58:32 +01002988 seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
2989 plane->base.id,
2990 plane_type(intel_plane->base.type),
2991 state->crtc_x, state->crtc_y,
2992 state->crtc_w, state->crtc_h,
2993 (state->src_x >> 16),
2994 ((state->src_x & 0xffff) * 15625) >> 10,
2995 (state->src_y >> 16),
2996 ((state->src_y & 0xffff) * 15625) >> 10,
2997 (state->src_w >> 16),
2998 ((state->src_w & 0xffff) * 15625) >> 10,
2999 (state->src_h >> 16),
3000 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestrom90844f02016-08-15 01:02:38 +01003001 format_name,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003002 plane_rotation(state->rotation));
Eric Engestrom90844f02016-08-15 01:02:38 +01003003
3004 kfree(format_name);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003005 }
3006}
3007
3008static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3009{
3010 struct intel_crtc_state *pipe_config;
3011 int num_scalers = intel_crtc->num_scalers;
3012 int i;
3013
3014 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3015
3016 /* Not all platformas have a scaler */
3017 if (num_scalers) {
3018 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3019 num_scalers,
3020 pipe_config->scaler_state.scaler_users,
3021 pipe_config->scaler_state.scaler_id);
3022
3023 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3024 struct intel_scaler *sc =
3025 &pipe_config->scaler_state.scalers[i];
3026
3027 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3028 i, yesno(sc->in_use), sc->mode);
3029 }
3030 seq_puts(m, "\n");
3031 } else {
3032 seq_puts(m, "\tNo scalers available on this platform\n");
3033 }
3034}
3035
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003036static int i915_display_info(struct seq_file *m, void *unused)
3037{
David Weinehall36cdd012016-08-22 13:59:31 +03003038 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3039 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003040 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003041 struct drm_connector *connector;
3042
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003043 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003044 drm_modeset_lock_all(dev);
3045 seq_printf(m, "CRTC info\n");
3046 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003047 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003048 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003049 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003050 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003051
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003052 pipe_config = to_intel_crtc_state(crtc->base.state);
3053
Robert Fekete3abc4e02015-10-27 16:58:32 +01003054 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003055 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003056 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003057 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3058 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3059
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003060 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003061 intel_crtc_info(m, crtc);
3062
David Weinehall36cdd012016-08-22 13:59:31 +03003063 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003064 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 +03003065 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003066 x, y, crtc->base.cursor->state->crtc_w,
3067 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003068 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003069 intel_scaler_info(m, crtc);
3070 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003071 }
Daniel Vettercace8412014-05-22 17:56:31 +02003072
3073 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3074 yesno(!crtc->cpu_fifo_underrun_disabled),
3075 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003076 }
3077
3078 seq_printf(m, "\n");
3079 seq_printf(m, "Connector info\n");
3080 seq_printf(m, "--------------\n");
3081 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3082 intel_connector_info(m, connector);
3083 }
3084 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003085 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003086
3087 return 0;
3088}
3089
Chris Wilson1b365952016-10-04 21:11:31 +01003090static int i915_engine_info(struct seq_file *m, void *unused)
3091{
3092 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3093 struct intel_engine_cs *engine;
3094
3095 for_each_engine(engine, dev_priv) {
3096 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3097 struct drm_i915_gem_request *rq;
3098 struct rb_node *rb;
3099 u64 addr;
3100
3101 seq_printf(m, "%s\n", engine->name);
3102 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3103 intel_engine_get_seqno(engine),
3104 engine->last_submitted_seqno,
3105 engine->hangcheck.seqno,
3106 engine->hangcheck.score);
3107
3108 rcu_read_lock();
3109
3110 seq_printf(m, "\tRequests:\n");
3111
3112 rq = list_first_entry(&engine->request_list,
3113 struct drm_i915_gem_request, link);
3114 if (&rq->link != &engine->request_list)
3115 print_request(m, rq, "\t\tfirst ");
3116
3117 rq = list_last_entry(&engine->request_list,
3118 struct drm_i915_gem_request, link);
3119 if (&rq->link != &engine->request_list)
3120 print_request(m, rq, "\t\tlast ");
3121
3122 rq = i915_gem_find_active_request(engine);
3123 if (rq) {
3124 print_request(m, rq, "\t\tactive ");
3125 seq_printf(m,
3126 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3127 rq->head, rq->postfix, rq->tail,
3128 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3129 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3130 }
3131
3132 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3133 I915_READ(RING_START(engine->mmio_base)),
3134 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3135 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3136 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3137 rq ? rq->ring->head : 0);
3138 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3139 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3140 rq ? rq->ring->tail : 0);
3141 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3142 I915_READ(RING_CTL(engine->mmio_base)),
3143 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3144
3145 rcu_read_unlock();
3146
3147 addr = intel_engine_get_active_head(engine);
3148 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3149 upper_32_bits(addr), lower_32_bits(addr));
3150 addr = intel_engine_get_last_batch_head(engine);
3151 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3152 upper_32_bits(addr), lower_32_bits(addr));
3153
3154 if (i915.enable_execlists) {
3155 u32 ptr, read, write;
3156
3157 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3158 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3159 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3160
3161 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3162 read = GEN8_CSB_READ_PTR(ptr);
3163 write = GEN8_CSB_WRITE_PTR(ptr);
3164 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3165 read, write);
3166 if (read >= GEN8_CSB_ENTRIES)
3167 read = 0;
3168 if (write >= GEN8_CSB_ENTRIES)
3169 write = 0;
3170 if (read > write)
3171 write += GEN8_CSB_ENTRIES;
3172 while (read < write) {
3173 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3174
3175 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3176 idx,
3177 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3178 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3179 }
3180
3181 rcu_read_lock();
3182 rq = READ_ONCE(engine->execlist_port[0].request);
3183 if (rq)
3184 print_request(m, rq, "\t\tELSP[0] ");
3185 else
3186 seq_printf(m, "\t\tELSP[0] idle\n");
3187 rq = READ_ONCE(engine->execlist_port[1].request);
3188 if (rq)
3189 print_request(m, rq, "\t\tELSP[1] ");
3190 else
3191 seq_printf(m, "\t\tELSP[1] idle\n");
3192 rcu_read_unlock();
3193 } else if (INTEL_GEN(dev_priv) > 6) {
3194 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3195 I915_READ(RING_PP_DIR_BASE(engine)));
3196 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3197 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3198 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3199 I915_READ(RING_PP_DIR_DCLV(engine)));
3200 }
3201
3202 spin_lock(&b->lock);
3203 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3204 struct intel_wait *w = container_of(rb, typeof(*w), node);
3205
3206 seq_printf(m, "\t%s [%d] waiting for %x\n",
3207 w->tsk->comm, w->tsk->pid, w->seqno);
3208 }
3209 spin_unlock(&b->lock);
3210
3211 seq_puts(m, "\n");
3212 }
3213
3214 return 0;
3215}
3216
Ben Widawskye04934c2014-06-30 09:53:42 -07003217static int i915_semaphore_status(struct seq_file *m, void *unused)
3218{
David Weinehall36cdd012016-08-22 13:59:31 +03003219 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3220 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003221 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003222 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003223 enum intel_engine_id id;
3224 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003225
Chris Wilson39df9192016-07-20 13:31:57 +01003226 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003227 seq_puts(m, "Semaphores are disabled\n");
3228 return 0;
3229 }
3230
3231 ret = mutex_lock_interruptible(&dev->struct_mutex);
3232 if (ret)
3233 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003234 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003235
David Weinehall36cdd012016-08-22 13:59:31 +03003236 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003237 struct page *page;
3238 uint64_t *seqno;
3239
Chris Wilson51d545d2016-08-15 10:49:02 +01003240 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003241
3242 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003243 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003244 uint64_t offset;
3245
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003246 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003247
3248 seq_puts(m, " Last signal:");
3249 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003250 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003251 seq_printf(m, "0x%08llx (0x%02llx) ",
3252 seqno[offset], offset * 8);
3253 }
3254 seq_putc(m, '\n');
3255
3256 seq_puts(m, " Last wait: ");
3257 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003258 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003259 seq_printf(m, "0x%08llx (0x%02llx) ",
3260 seqno[offset], offset * 8);
3261 }
3262 seq_putc(m, '\n');
3263
3264 }
3265 kunmap_atomic(seqno);
3266 } else {
3267 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003268 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003269 for (j = 0; j < num_rings; j++)
3270 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003271 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003272 seq_putc(m, '\n');
3273 }
3274
3275 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003276 for_each_engine(engine, dev_priv) {
3277 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003278 seq_printf(m, " 0x%08x ",
3279 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003280 seq_putc(m, '\n');
3281 }
3282 seq_putc(m, '\n');
3283
Paulo Zanoni03872062014-07-09 14:31:57 -03003284 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003285 mutex_unlock(&dev->struct_mutex);
3286 return 0;
3287}
3288
Daniel Vetter728e29d2014-06-25 22:01:53 +03003289static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3290{
David Weinehall36cdd012016-08-22 13:59:31 +03003291 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3292 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003293 int i;
3294
3295 drm_modeset_lock_all(dev);
3296 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3297 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3298
3299 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003300 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3301 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003302 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003303 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3304 seq_printf(m, " dpll_md: 0x%08x\n",
3305 pll->config.hw_state.dpll_md);
3306 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3307 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3308 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003309 }
3310 drm_modeset_unlock_all(dev);
3311
3312 return 0;
3313}
3314
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003315static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003316{
3317 int i;
3318 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003319 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003320 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3321 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003322 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003323 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003324
Arun Siluvery888b5992014-08-26 14:44:51 +01003325 ret = mutex_lock_interruptible(&dev->struct_mutex);
3326 if (ret)
3327 return ret;
3328
3329 intel_runtime_pm_get(dev_priv);
3330
Arun Siluvery33136b02016-01-21 21:43:47 +00003331 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003332 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003333 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003334 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003335 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003336 i915_reg_t addr;
3337 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003338 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003339
Arun Siluvery33136b02016-01-21 21:43:47 +00003340 addr = workarounds->reg[i].addr;
3341 mask = workarounds->reg[i].mask;
3342 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003343 read = I915_READ(addr);
3344 ok = (value & mask) == (read & mask);
3345 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003346 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003347 }
3348
3349 intel_runtime_pm_put(dev_priv);
3350 mutex_unlock(&dev->struct_mutex);
3351
3352 return 0;
3353}
3354
Damien Lespiauc5511e42014-11-04 17:06:51 +00003355static int i915_ddb_info(struct seq_file *m, void *unused)
3356{
David Weinehall36cdd012016-08-22 13:59:31 +03003357 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3358 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003359 struct skl_ddb_allocation *ddb;
3360 struct skl_ddb_entry *entry;
3361 enum pipe pipe;
3362 int plane;
3363
David Weinehall36cdd012016-08-22 13:59:31 +03003364 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003365 return 0;
3366
Damien Lespiauc5511e42014-11-04 17:06:51 +00003367 drm_modeset_lock_all(dev);
3368
3369 ddb = &dev_priv->wm.skl_hw.ddb;
3370
3371 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3372
3373 for_each_pipe(dev_priv, pipe) {
3374 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3375
Damien Lespiaudd740782015-02-28 14:54:08 +00003376 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003377 entry = &ddb->plane[pipe][plane];
3378 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3379 entry->start, entry->end,
3380 skl_ddb_entry_size(entry));
3381 }
3382
Matt Roper4969d332015-09-24 15:53:10 -07003383 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003384 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3385 entry->end, skl_ddb_entry_size(entry));
3386 }
3387
3388 drm_modeset_unlock_all(dev);
3389
3390 return 0;
3391}
3392
Vandana Kannana54746e2015-03-03 20:53:10 +05303393static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003394 struct drm_device *dev,
3395 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303396{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003397 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303398 struct i915_drrs *drrs = &dev_priv->drrs;
3399 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003400 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303401
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003402 drm_for_each_connector(connector, dev) {
3403 if (connector->state->crtc != &intel_crtc->base)
3404 continue;
3405
3406 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303407 }
3408
3409 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3410 seq_puts(m, "\tVBT: DRRS_type: Static");
3411 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3412 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3413 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3414 seq_puts(m, "\tVBT: DRRS_type: None");
3415 else
3416 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3417
3418 seq_puts(m, "\n\n");
3419
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003420 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303421 struct intel_panel *panel;
3422
3423 mutex_lock(&drrs->mutex);
3424 /* DRRS Supported */
3425 seq_puts(m, "\tDRRS Supported: Yes\n");
3426
3427 /* disable_drrs() will make drrs->dp NULL */
3428 if (!drrs->dp) {
3429 seq_puts(m, "Idleness DRRS: Disabled");
3430 mutex_unlock(&drrs->mutex);
3431 return;
3432 }
3433
3434 panel = &drrs->dp->attached_connector->panel;
3435 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3436 drrs->busy_frontbuffer_bits);
3437
3438 seq_puts(m, "\n\t\t");
3439 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3440 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3441 vrefresh = panel->fixed_mode->vrefresh;
3442 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3443 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3444 vrefresh = panel->downclock_mode->vrefresh;
3445 } else {
3446 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3447 drrs->refresh_rate_type);
3448 mutex_unlock(&drrs->mutex);
3449 return;
3450 }
3451 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3452
3453 seq_puts(m, "\n\t\t");
3454 mutex_unlock(&drrs->mutex);
3455 } else {
3456 /* DRRS not supported. Print the VBT parameter*/
3457 seq_puts(m, "\tDRRS Supported : No");
3458 }
3459 seq_puts(m, "\n");
3460}
3461
3462static int i915_drrs_status(struct seq_file *m, void *unused)
3463{
David Weinehall36cdd012016-08-22 13:59:31 +03003464 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3465 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303466 struct intel_crtc *intel_crtc;
3467 int active_crtc_cnt = 0;
3468
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003469 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303470 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003471 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303472 active_crtc_cnt++;
3473 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3474
3475 drrs_status_per_crtc(m, dev, intel_crtc);
3476 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303477 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003478 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303479
3480 if (!active_crtc_cnt)
3481 seq_puts(m, "No active crtc found\n");
3482
3483 return 0;
3484}
3485
Damien Lespiau07144422013-10-15 18:55:40 +01003486struct pipe_crc_info {
3487 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003488 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003489 enum pipe pipe;
3490};
3491
Dave Airlie11bed952014-05-12 15:22:27 +10003492static int i915_dp_mst_info(struct seq_file *m, void *unused)
3493{
David Weinehall36cdd012016-08-22 13:59:31 +03003494 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3495 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003496 struct intel_encoder *intel_encoder;
3497 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003498 struct drm_connector *connector;
3499
Dave Airlie11bed952014-05-12 15:22:27 +10003500 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003501 drm_for_each_connector(connector, dev) {
3502 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003503 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003504
3505 intel_encoder = intel_attached_encoder(connector);
3506 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3507 continue;
3508
3509 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003510 if (!intel_dig_port->dp.can_mst)
3511 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003512
Jim Bride40ae80c2016-04-14 10:18:37 -07003513 seq_printf(m, "MST Source Port %c\n",
3514 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003515 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3516 }
3517 drm_modeset_unlock_all(dev);
3518 return 0;
3519}
3520
Damien Lespiau07144422013-10-15 18:55:40 +01003521static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003522{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003523 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003524 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003525 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3526
David Weinehall36cdd012016-08-22 13:59:31 +03003527 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003528 return -ENODEV;
3529
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003530 spin_lock_irq(&pipe_crc->lock);
3531
3532 if (pipe_crc->opened) {
3533 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003534 return -EBUSY; /* already open */
3535 }
3536
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003537 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003538 filep->private_data = inode->i_private;
3539
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003540 spin_unlock_irq(&pipe_crc->lock);
3541
Damien Lespiau07144422013-10-15 18:55:40 +01003542 return 0;
3543}
3544
3545static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3546{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003547 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003548 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003549 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3550
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003551 spin_lock_irq(&pipe_crc->lock);
3552 pipe_crc->opened = false;
3553 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003554
Damien Lespiau07144422013-10-15 18:55:40 +01003555 return 0;
3556}
3557
3558/* (6 fields, 8 chars each, space separated (5) + '\n') */
3559#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3560/* account for \'0' */
3561#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3562
3563static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3564{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003565 assert_spin_locked(&pipe_crc->lock);
3566 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3567 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003568}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003569
Damien Lespiau07144422013-10-15 18:55:40 +01003570static ssize_t
3571i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3572 loff_t *pos)
3573{
3574 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003575 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003576 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3577 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003578 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003579 ssize_t bytes_read;
3580
3581 /*
3582 * Don't allow user space to provide buffers not big enough to hold
3583 * a line of data.
3584 */
3585 if (count < PIPE_CRC_LINE_LEN)
3586 return -EINVAL;
3587
3588 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3589 return 0;
3590
3591 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003592 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003593 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003594 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003595
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003596 if (filep->f_flags & O_NONBLOCK) {
3597 spin_unlock_irq(&pipe_crc->lock);
3598 return -EAGAIN;
3599 }
3600
3601 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3602 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3603 if (ret) {
3604 spin_unlock_irq(&pipe_crc->lock);
3605 return ret;
3606 }
Damien Lespiau07144422013-10-15 18:55:40 +01003607 }
3608
3609 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003610 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003611
Damien Lespiau07144422013-10-15 18:55:40 +01003612 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003613 while (n_entries > 0) {
3614 struct intel_pipe_crc_entry *entry =
3615 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003616
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003617 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3618 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3619 break;
3620
3621 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3622 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3623
Damien Lespiau07144422013-10-15 18:55:40 +01003624 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3625 "%8u %8x %8x %8x %8x %8x\n",
3626 entry->frame, entry->crc[0],
3627 entry->crc[1], entry->crc[2],
3628 entry->crc[3], entry->crc[4]);
3629
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003630 spin_unlock_irq(&pipe_crc->lock);
3631
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003632 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003633 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003634
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003635 user_buf += PIPE_CRC_LINE_LEN;
3636 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003637
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003638 spin_lock_irq(&pipe_crc->lock);
3639 }
3640
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003641 spin_unlock_irq(&pipe_crc->lock);
3642
Damien Lespiau07144422013-10-15 18:55:40 +01003643 return bytes_read;
3644}
3645
3646static const struct file_operations i915_pipe_crc_fops = {
3647 .owner = THIS_MODULE,
3648 .open = i915_pipe_crc_open,
3649 .read = i915_pipe_crc_read,
3650 .release = i915_pipe_crc_release,
3651};
3652
3653static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3654 {
3655 .name = "i915_pipe_A_crc",
3656 .pipe = PIPE_A,
3657 },
3658 {
3659 .name = "i915_pipe_B_crc",
3660 .pipe = PIPE_B,
3661 },
3662 {
3663 .name = "i915_pipe_C_crc",
3664 .pipe = PIPE_C,
3665 },
3666};
3667
3668static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3669 enum pipe pipe)
3670{
David Weinehall36cdd012016-08-22 13:59:31 +03003671 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003672 struct dentry *ent;
3673 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3674
David Weinehall36cdd012016-08-22 13:59:31 +03003675 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003676 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3677 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003678 if (!ent)
3679 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003680
3681 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003682}
3683
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003684static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003685 "none",
3686 "plane1",
3687 "plane2",
3688 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003689 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003690 "TV",
3691 "DP-B",
3692 "DP-C",
3693 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003694 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003695};
3696
3697static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3698{
3699 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3700 return pipe_crc_sources[source];
3701}
3702
Damien Lespiaubd9db022013-10-15 18:55:36 +01003703static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003704{
David Weinehall36cdd012016-08-22 13:59:31 +03003705 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003706 int i;
3707
3708 for (i = 0; i < I915_MAX_PIPES; i++)
3709 seq_printf(m, "%c %s\n", pipe_name(i),
3710 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3711
3712 return 0;
3713}
3714
Damien Lespiaubd9db022013-10-15 18:55:36 +01003715static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003716{
David Weinehall36cdd012016-08-22 13:59:31 +03003717 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003718}
3719
Daniel Vetter46a19182013-11-01 10:50:20 +01003720static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003721 uint32_t *val)
3722{
Daniel Vetter46a19182013-11-01 10:50:20 +01003723 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3724 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3725
3726 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003727 case INTEL_PIPE_CRC_SOURCE_PIPE:
3728 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3729 break;
3730 case INTEL_PIPE_CRC_SOURCE_NONE:
3731 *val = 0;
3732 break;
3733 default:
3734 return -EINVAL;
3735 }
3736
3737 return 0;
3738}
3739
David Weinehall36cdd012016-08-22 13:59:31 +03003740static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3741 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003742 enum intel_pipe_crc_source *source)
3743{
David Weinehall36cdd012016-08-22 13:59:31 +03003744 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003745 struct intel_encoder *encoder;
3746 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003747 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003748 int ret = 0;
3749
3750 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3751
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003752 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003753 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003754 if (!encoder->base.crtc)
3755 continue;
3756
3757 crtc = to_intel_crtc(encoder->base.crtc);
3758
3759 if (crtc->pipe != pipe)
3760 continue;
3761
3762 switch (encoder->type) {
3763 case INTEL_OUTPUT_TVOUT:
3764 *source = INTEL_PIPE_CRC_SOURCE_TV;
3765 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003766 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003767 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003768 dig_port = enc_to_dig_port(&encoder->base);
3769 switch (dig_port->port) {
3770 case PORT_B:
3771 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3772 break;
3773 case PORT_C:
3774 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3775 break;
3776 case PORT_D:
3777 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3778 break;
3779 default:
3780 WARN(1, "nonexisting DP port %c\n",
3781 port_name(dig_port->port));
3782 break;
3783 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003784 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003785 default:
3786 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003787 }
3788 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003789 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003790
3791 return ret;
3792}
3793
David Weinehall36cdd012016-08-22 13:59:31 +03003794static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003795 enum pipe pipe,
3796 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003797 uint32_t *val)
3798{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003799 bool need_stable_symbols = false;
3800
Daniel Vetter46a19182013-11-01 10:50:20 +01003801 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003802 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003803 if (ret)
3804 return ret;
3805 }
3806
3807 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003808 case INTEL_PIPE_CRC_SOURCE_PIPE:
3809 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3810 break;
3811 case INTEL_PIPE_CRC_SOURCE_DP_B:
3812 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003813 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003814 break;
3815 case INTEL_PIPE_CRC_SOURCE_DP_C:
3816 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003817 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003818 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003819 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003820 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003821 return -EINVAL;
3822 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3823 need_stable_symbols = true;
3824 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003825 case INTEL_PIPE_CRC_SOURCE_NONE:
3826 *val = 0;
3827 break;
3828 default:
3829 return -EINVAL;
3830 }
3831
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003832 /*
3833 * When the pipe CRC tap point is after the transcoders we need
3834 * to tweak symbol-level features to produce a deterministic series of
3835 * symbols for a given frame. We need to reset those features only once
3836 * a frame (instead of every nth symbol):
3837 * - DC-balance: used to ensure a better clock recovery from the data
3838 * link (SDVO)
3839 * - DisplayPort scrambling: used for EMI reduction
3840 */
3841 if (need_stable_symbols) {
3842 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3843
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003844 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003845 switch (pipe) {
3846 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003847 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003848 break;
3849 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003850 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003851 break;
3852 case PIPE_C:
3853 tmp |= PIPE_C_SCRAMBLE_RESET;
3854 break;
3855 default:
3856 return -EINVAL;
3857 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003858 I915_WRITE(PORT_DFT2_G4X, tmp);
3859 }
3860
Daniel Vetter7ac01292013-10-18 16:37:06 +02003861 return 0;
3862}
3863
David Weinehall36cdd012016-08-22 13:59:31 +03003864static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003865 enum pipe pipe,
3866 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003867 uint32_t *val)
3868{
Daniel Vetter84093602013-11-01 10:50:21 +01003869 bool need_stable_symbols = false;
3870
Daniel Vetter46a19182013-11-01 10:50:20 +01003871 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003872 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003873 if (ret)
3874 return ret;
3875 }
3876
3877 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003878 case INTEL_PIPE_CRC_SOURCE_PIPE:
3879 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3880 break;
3881 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003882 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003883 return -EINVAL;
3884 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3885 break;
3886 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003887 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003888 return -EINVAL;
3889 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003890 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003891 break;
3892 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003893 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003894 return -EINVAL;
3895 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003896 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003897 break;
3898 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003899 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003900 return -EINVAL;
3901 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003902 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003903 break;
3904 case INTEL_PIPE_CRC_SOURCE_NONE:
3905 *val = 0;
3906 break;
3907 default:
3908 return -EINVAL;
3909 }
3910
Daniel Vetter84093602013-11-01 10:50:21 +01003911 /*
3912 * When the pipe CRC tap point is after the transcoders we need
3913 * to tweak symbol-level features to produce a deterministic series of
3914 * symbols for a given frame. We need to reset those features only once
3915 * a frame (instead of every nth symbol):
3916 * - DC-balance: used to ensure a better clock recovery from the data
3917 * link (SDVO)
3918 * - DisplayPort scrambling: used for EMI reduction
3919 */
3920 if (need_stable_symbols) {
3921 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3922
David Weinehall36cdd012016-08-22 13:59:31 +03003923 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003924
3925 I915_WRITE(PORT_DFT_I9XX,
3926 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3927
3928 if (pipe == PIPE_A)
3929 tmp |= PIPE_A_SCRAMBLE_RESET;
3930 else
3931 tmp |= PIPE_B_SCRAMBLE_RESET;
3932
3933 I915_WRITE(PORT_DFT2_G4X, tmp);
3934 }
3935
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003936 return 0;
3937}
3938
David Weinehall36cdd012016-08-22 13:59:31 +03003939static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003940 enum pipe pipe)
3941{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003942 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3943
Ville Syrjäläeb736672014-12-09 21:28:28 +02003944 switch (pipe) {
3945 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003946 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003947 break;
3948 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003949 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003950 break;
3951 case PIPE_C:
3952 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3953 break;
3954 default:
3955 return;
3956 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003957 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3958 tmp &= ~DC_BALANCE_RESET_VLV;
3959 I915_WRITE(PORT_DFT2_G4X, tmp);
3960
3961}
3962
David Weinehall36cdd012016-08-22 13:59:31 +03003963static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01003964 enum pipe pipe)
3965{
Daniel Vetter84093602013-11-01 10:50:21 +01003966 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3967
3968 if (pipe == PIPE_A)
3969 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3970 else
3971 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3972 I915_WRITE(PORT_DFT2_G4X, tmp);
3973
3974 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3975 I915_WRITE(PORT_DFT_I9XX,
3976 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3977 }
3978}
3979
Daniel Vetter46a19182013-11-01 10:50:20 +01003980static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003981 uint32_t *val)
3982{
Daniel Vetter46a19182013-11-01 10:50:20 +01003983 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3984 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3985
3986 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003987 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3988 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3989 break;
3990 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3991 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3992 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003993 case INTEL_PIPE_CRC_SOURCE_PIPE:
3994 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3995 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003996 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003997 *val = 0;
3998 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003999 default:
4000 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004001 }
4002
4003 return 0;
4004}
4005
David Weinehall36cdd012016-08-22 13:59:31 +03004006static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4007 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004008{
David Weinehall36cdd012016-08-22 13:59:31 +03004009 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004010 struct intel_crtc *crtc =
4011 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004012 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004013 struct drm_atomic_state *state;
4014 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004015
4016 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004017 state = drm_atomic_state_alloc(dev);
4018 if (!state) {
4019 ret = -ENOMEM;
4020 goto out;
4021 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004022
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004023 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4024 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4025 if (IS_ERR(pipe_config)) {
4026 ret = PTR_ERR(pipe_config);
4027 goto out;
4028 }
4029
4030 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004031 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004032 pipe_config->pch_pfit.enabled != enable)
4033 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004034
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004035 ret = drm_atomic_commit(state);
4036out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004037 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004038 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4039 if (ret)
4040 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004041}
4042
David Weinehall36cdd012016-08-22 13:59:31 +03004043static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004044 enum pipe pipe,
4045 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004046 uint32_t *val)
4047{
Daniel Vetter46a19182013-11-01 10:50:20 +01004048 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4049 *source = INTEL_PIPE_CRC_SOURCE_PF;
4050
4051 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004052 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4053 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4054 break;
4055 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4056 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4057 break;
4058 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004059 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4060 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004061
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004062 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4063 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004064 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004065 *val = 0;
4066 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004067 default:
4068 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004069 }
4070
4071 return 0;
4072}
4073
David Weinehall36cdd012016-08-22 13:59:31 +03004074static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4075 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004076 enum intel_pipe_crc_source source)
4077{
David Weinehall36cdd012016-08-22 13:59:31 +03004078 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004079 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03004080 struct intel_crtc *crtc =
4081 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02004082 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004083 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004084 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004085
Damien Lespiaucc3da172013-10-15 18:55:31 +01004086 if (pipe_crc->source == source)
4087 return 0;
4088
Damien Lespiauae676fc2013-10-15 18:55:32 +01004089 /* forbid changing the source without going back to 'none' */
4090 if (pipe_crc->source && source)
4091 return -EINVAL;
4092
Imre Deake1296492016-02-12 18:55:17 +02004093 power_domain = POWER_DOMAIN_PIPE(pipe);
4094 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004095 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4096 return -EIO;
4097 }
4098
David Weinehall36cdd012016-08-22 13:59:31 +03004099 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004100 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004101 else if (INTEL_GEN(dev_priv) < 5)
4102 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4103 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4104 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4105 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004106 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004107 else
David Weinehall36cdd012016-08-22 13:59:31 +03004108 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004109
4110 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004111 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004112
Damien Lespiau4b584362013-10-15 18:55:33 +01004113 /* none -> real source transition */
4114 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004115 struct intel_pipe_crc_entry *entries;
4116
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004117 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4118 pipe_name(pipe), pipe_crc_source_name(source));
4119
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004120 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4121 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004122 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004123 if (!entries) {
4124 ret = -ENOMEM;
4125 goto out;
4126 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004127
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004128 /*
4129 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4130 * enabled and disabled dynamically based on package C states,
4131 * user space can't make reliable use of the CRCs, so let's just
4132 * completely disable it.
4133 */
4134 hsw_disable_ips(crtc);
4135
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004136 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004137 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004138 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004139 pipe_crc->head = 0;
4140 pipe_crc->tail = 0;
4141 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004142 }
4143
Damien Lespiaucc3da172013-10-15 18:55:31 +01004144 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004145
Daniel Vetter926321d2013-10-16 13:30:34 +02004146 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4147 POSTING_READ(PIPE_CRC_CTL(pipe));
4148
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004149 /* real source -> none transition */
4150 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004151 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004152 struct intel_crtc *crtc =
4153 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004154
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004155 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4156 pipe_name(pipe));
4157
Daniel Vettera33d7102014-06-06 08:22:08 +02004158 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004159 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004160 intel_wait_for_vblank(dev, pipe);
4161 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004162
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004163 spin_lock_irq(&pipe_crc->lock);
4164 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004165 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004166 pipe_crc->head = 0;
4167 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004168 spin_unlock_irq(&pipe_crc->lock);
4169
4170 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004171
David Weinehall36cdd012016-08-22 13:59:31 +03004172 if (IS_G4X(dev_priv))
4173 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4174 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4175 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4176 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4177 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004178
4179 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004180 }
4181
Imre Deake1296492016-02-12 18:55:17 +02004182 ret = 0;
4183
4184out:
4185 intel_display_power_put(dev_priv, power_domain);
4186
4187 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004188}
4189
4190/*
4191 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004192 * command: wsp* object wsp+ name wsp+ source wsp*
4193 * object: 'pipe'
4194 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004195 * source: (none | plane1 | plane2 | pf)
4196 * wsp: (#0x20 | #0x9 | #0xA)+
4197 *
4198 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004199 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4200 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004201 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004202static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004203{
4204 int n_words = 0;
4205
4206 while (*buf) {
4207 char *end;
4208
4209 /* skip leading white space */
4210 buf = skip_spaces(buf);
4211 if (!*buf)
4212 break; /* end of buffer */
4213
4214 /* find end of word */
4215 for (end = buf; *end && !isspace(*end); end++)
4216 ;
4217
4218 if (n_words == max_words) {
4219 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4220 max_words);
4221 return -EINVAL; /* ran out of words[] before bytes */
4222 }
4223
4224 if (*end)
4225 *end++ = '\0';
4226 words[n_words++] = buf;
4227 buf = end;
4228 }
4229
4230 return n_words;
4231}
4232
Damien Lespiaub94dec82013-10-15 18:55:35 +01004233enum intel_pipe_crc_object {
4234 PIPE_CRC_OBJECT_PIPE,
4235};
4236
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004237static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004238 "pipe",
4239};
4240
4241static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004242display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004243{
4244 int i;
4245
4246 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4247 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004248 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004249 return 0;
4250 }
4251
4252 return -EINVAL;
4253}
4254
Damien Lespiaubd9db022013-10-15 18:55:36 +01004255static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004256{
4257 const char name = buf[0];
4258
4259 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4260 return -EINVAL;
4261
4262 *pipe = name - 'A';
4263
4264 return 0;
4265}
4266
4267static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004268display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004269{
4270 int i;
4271
4272 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4273 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004274 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004275 return 0;
4276 }
4277
4278 return -EINVAL;
4279}
4280
David Weinehall36cdd012016-08-22 13:59:31 +03004281static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4282 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004283{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004284#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004285 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004286 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004287 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004288 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004289 enum intel_pipe_crc_source source;
4290
Damien Lespiaubd9db022013-10-15 18:55:36 +01004291 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004292 if (n_words != N_WORDS) {
4293 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4294 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004295 return -EINVAL;
4296 }
4297
Damien Lespiaubd9db022013-10-15 18:55:36 +01004298 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004299 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004300 return -EINVAL;
4301 }
4302
Damien Lespiaubd9db022013-10-15 18:55:36 +01004303 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004304 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4305 return -EINVAL;
4306 }
4307
Damien Lespiaubd9db022013-10-15 18:55:36 +01004308 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004309 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004310 return -EINVAL;
4311 }
4312
David Weinehall36cdd012016-08-22 13:59:31 +03004313 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004314}
4315
Damien Lespiaubd9db022013-10-15 18:55:36 +01004316static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4317 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004318{
4319 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004320 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004321 char *tmpbuf;
4322 int ret;
4323
4324 if (len == 0)
4325 return 0;
4326
4327 if (len > PAGE_SIZE - 1) {
4328 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4329 PAGE_SIZE);
4330 return -E2BIG;
4331 }
4332
4333 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4334 if (!tmpbuf)
4335 return -ENOMEM;
4336
4337 if (copy_from_user(tmpbuf, ubuf, len)) {
4338 ret = -EFAULT;
4339 goto out;
4340 }
4341 tmpbuf[len] = '\0';
4342
David Weinehall36cdd012016-08-22 13:59:31 +03004343 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004344
4345out:
4346 kfree(tmpbuf);
4347 if (ret < 0)
4348 return ret;
4349
4350 *offp += len;
4351 return len;
4352}
4353
Damien Lespiaubd9db022013-10-15 18:55:36 +01004354static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004355 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004356 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004357 .read = seq_read,
4358 .llseek = seq_lseek,
4359 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004360 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004361};
4362
Todd Previteeb3394fa2015-04-18 00:04:19 -07004363static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004364 const char __user *ubuf,
4365 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004366{
4367 char *input_buffer;
4368 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004369 struct drm_device *dev;
4370 struct drm_connector *connector;
4371 struct list_head *connector_list;
4372 struct intel_dp *intel_dp;
4373 int val = 0;
4374
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304375 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004376
Todd Previteeb3394fa2015-04-18 00:04:19 -07004377 connector_list = &dev->mode_config.connector_list;
4378
4379 if (len == 0)
4380 return 0;
4381
4382 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4383 if (!input_buffer)
4384 return -ENOMEM;
4385
4386 if (copy_from_user(input_buffer, ubuf, len)) {
4387 status = -EFAULT;
4388 goto out;
4389 }
4390
4391 input_buffer[len] = '\0';
4392 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4393
4394 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004395 if (connector->connector_type !=
4396 DRM_MODE_CONNECTOR_DisplayPort)
4397 continue;
4398
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304399 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004400 connector->encoder != NULL) {
4401 intel_dp = enc_to_intel_dp(connector->encoder);
4402 status = kstrtoint(input_buffer, 10, &val);
4403 if (status < 0)
4404 goto out;
4405 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4406 /* To prevent erroneous activation of the compliance
4407 * testing code, only accept an actual value of 1 here
4408 */
4409 if (val == 1)
4410 intel_dp->compliance_test_active = 1;
4411 else
4412 intel_dp->compliance_test_active = 0;
4413 }
4414 }
4415out:
4416 kfree(input_buffer);
4417 if (status < 0)
4418 return status;
4419
4420 *offp += len;
4421 return len;
4422}
4423
4424static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4425{
4426 struct drm_device *dev = m->private;
4427 struct drm_connector *connector;
4428 struct list_head *connector_list = &dev->mode_config.connector_list;
4429 struct intel_dp *intel_dp;
4430
Todd Previteeb3394fa2015-04-18 00:04:19 -07004431 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004432 if (connector->connector_type !=
4433 DRM_MODE_CONNECTOR_DisplayPort)
4434 continue;
4435
4436 if (connector->status == connector_status_connected &&
4437 connector->encoder != NULL) {
4438 intel_dp = enc_to_intel_dp(connector->encoder);
4439 if (intel_dp->compliance_test_active)
4440 seq_puts(m, "1");
4441 else
4442 seq_puts(m, "0");
4443 } else
4444 seq_puts(m, "0");
4445 }
4446
4447 return 0;
4448}
4449
4450static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004451 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004452{
David Weinehall36cdd012016-08-22 13:59:31 +03004453 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004454
David Weinehall36cdd012016-08-22 13:59:31 +03004455 return single_open(file, i915_displayport_test_active_show,
4456 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004457}
4458
4459static const struct file_operations i915_displayport_test_active_fops = {
4460 .owner = THIS_MODULE,
4461 .open = i915_displayport_test_active_open,
4462 .read = seq_read,
4463 .llseek = seq_lseek,
4464 .release = single_release,
4465 .write = i915_displayport_test_active_write
4466};
4467
4468static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4469{
4470 struct drm_device *dev = m->private;
4471 struct drm_connector *connector;
4472 struct list_head *connector_list = &dev->mode_config.connector_list;
4473 struct intel_dp *intel_dp;
4474
Todd Previteeb3394fa2015-04-18 00:04:19 -07004475 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004476 if (connector->connector_type !=
4477 DRM_MODE_CONNECTOR_DisplayPort)
4478 continue;
4479
4480 if (connector->status == connector_status_connected &&
4481 connector->encoder != NULL) {
4482 intel_dp = enc_to_intel_dp(connector->encoder);
4483 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4484 } else
4485 seq_puts(m, "0");
4486 }
4487
4488 return 0;
4489}
4490static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004491 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004492{
David Weinehall36cdd012016-08-22 13:59:31 +03004493 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004494
David Weinehall36cdd012016-08-22 13:59:31 +03004495 return single_open(file, i915_displayport_test_data_show,
4496 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004497}
4498
4499static const struct file_operations i915_displayport_test_data_fops = {
4500 .owner = THIS_MODULE,
4501 .open = i915_displayport_test_data_open,
4502 .read = seq_read,
4503 .llseek = seq_lseek,
4504 .release = single_release
4505};
4506
4507static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4508{
4509 struct drm_device *dev = m->private;
4510 struct drm_connector *connector;
4511 struct list_head *connector_list = &dev->mode_config.connector_list;
4512 struct intel_dp *intel_dp;
4513
Todd Previteeb3394fa2015-04-18 00:04:19 -07004514 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004515 if (connector->connector_type !=
4516 DRM_MODE_CONNECTOR_DisplayPort)
4517 continue;
4518
4519 if (connector->status == connector_status_connected &&
4520 connector->encoder != NULL) {
4521 intel_dp = enc_to_intel_dp(connector->encoder);
4522 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4523 } else
4524 seq_puts(m, "0");
4525 }
4526
4527 return 0;
4528}
4529
4530static int i915_displayport_test_type_open(struct inode *inode,
4531 struct file *file)
4532{
David Weinehall36cdd012016-08-22 13:59:31 +03004533 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004534
David Weinehall36cdd012016-08-22 13:59:31 +03004535 return single_open(file, i915_displayport_test_type_show,
4536 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004537}
4538
4539static const struct file_operations i915_displayport_test_type_fops = {
4540 .owner = THIS_MODULE,
4541 .open = i915_displayport_test_type_open,
4542 .read = seq_read,
4543 .llseek = seq_lseek,
4544 .release = single_release
4545};
4546
Damien Lespiau97e94b22014-11-04 17:06:50 +00004547static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004548{
David Weinehall36cdd012016-08-22 13:59:31 +03004549 struct drm_i915_private *dev_priv = m->private;
4550 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004551 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004552 int num_levels;
4553
David Weinehall36cdd012016-08-22 13:59:31 +03004554 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004555 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004556 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004557 num_levels = 1;
4558 else
4559 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004560
4561 drm_modeset_lock_all(dev);
4562
4563 for (level = 0; level < num_levels; level++) {
4564 unsigned int latency = wm[level];
4565
Damien Lespiau97e94b22014-11-04 17:06:50 +00004566 /*
4567 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004568 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004569 */
David Weinehall36cdd012016-08-22 13:59:31 +03004570 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4571 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004572 latency *= 10;
4573 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004574 latency *= 5;
4575
4576 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004577 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004578 }
4579
4580 drm_modeset_unlock_all(dev);
4581}
4582
4583static int pri_wm_latency_show(struct seq_file *m, void *data)
4584{
David Weinehall36cdd012016-08-22 13:59:31 +03004585 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004586 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004587
David Weinehall36cdd012016-08-22 13:59:31 +03004588 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004589 latencies = dev_priv->wm.skl_latency;
4590 else
David Weinehall36cdd012016-08-22 13:59:31 +03004591 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004592
4593 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004594
4595 return 0;
4596}
4597
4598static int spr_wm_latency_show(struct seq_file *m, void *data)
4599{
David Weinehall36cdd012016-08-22 13:59:31 +03004600 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004601 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004602
David Weinehall36cdd012016-08-22 13:59:31 +03004603 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004604 latencies = dev_priv->wm.skl_latency;
4605 else
David Weinehall36cdd012016-08-22 13:59:31 +03004606 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004607
4608 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004609
4610 return 0;
4611}
4612
4613static int cur_wm_latency_show(struct seq_file *m, void *data)
4614{
David Weinehall36cdd012016-08-22 13:59:31 +03004615 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004616 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004617
David Weinehall36cdd012016-08-22 13:59:31 +03004618 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004619 latencies = dev_priv->wm.skl_latency;
4620 else
David Weinehall36cdd012016-08-22 13:59:31 +03004621 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004622
4623 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004624
4625 return 0;
4626}
4627
4628static int pri_wm_latency_open(struct inode *inode, struct file *file)
4629{
David Weinehall36cdd012016-08-22 13:59:31 +03004630 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004631
David Weinehall36cdd012016-08-22 13:59:31 +03004632 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004633 return -ENODEV;
4634
David Weinehall36cdd012016-08-22 13:59:31 +03004635 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004636}
4637
4638static int spr_wm_latency_open(struct inode *inode, struct file *file)
4639{
David Weinehall36cdd012016-08-22 13:59:31 +03004640 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004641
David Weinehall36cdd012016-08-22 13:59:31 +03004642 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004643 return -ENODEV;
4644
David Weinehall36cdd012016-08-22 13:59:31 +03004645 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004646}
4647
4648static int cur_wm_latency_open(struct inode *inode, struct file *file)
4649{
David Weinehall36cdd012016-08-22 13:59:31 +03004650 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004651
David Weinehall36cdd012016-08-22 13:59:31 +03004652 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004653 return -ENODEV;
4654
David Weinehall36cdd012016-08-22 13:59:31 +03004655 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004656}
4657
4658static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004659 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004660{
4661 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004662 struct drm_i915_private *dev_priv = m->private;
4663 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004664 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004665 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004666 int level;
4667 int ret;
4668 char tmp[32];
4669
David Weinehall36cdd012016-08-22 13:59:31 +03004670 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004671 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004672 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004673 num_levels = 1;
4674 else
4675 num_levels = ilk_wm_max_level(dev) + 1;
4676
Ville Syrjälä369a1342014-01-22 14:36:08 +02004677 if (len >= sizeof(tmp))
4678 return -EINVAL;
4679
4680 if (copy_from_user(tmp, ubuf, len))
4681 return -EFAULT;
4682
4683 tmp[len] = '\0';
4684
Damien Lespiau97e94b22014-11-04 17:06:50 +00004685 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4686 &new[0], &new[1], &new[2], &new[3],
4687 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004688 if (ret != num_levels)
4689 return -EINVAL;
4690
4691 drm_modeset_lock_all(dev);
4692
4693 for (level = 0; level < num_levels; level++)
4694 wm[level] = new[level];
4695
4696 drm_modeset_unlock_all(dev);
4697
4698 return len;
4699}
4700
4701
4702static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4703 size_t len, loff_t *offp)
4704{
4705 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004706 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004707 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004708
David Weinehall36cdd012016-08-22 13:59:31 +03004709 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004710 latencies = dev_priv->wm.skl_latency;
4711 else
David Weinehall36cdd012016-08-22 13:59:31 +03004712 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004713
4714 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004715}
4716
4717static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4718 size_t len, loff_t *offp)
4719{
4720 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004721 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004722 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004723
David Weinehall36cdd012016-08-22 13:59:31 +03004724 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004725 latencies = dev_priv->wm.skl_latency;
4726 else
David Weinehall36cdd012016-08-22 13:59:31 +03004727 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004728
4729 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004730}
4731
4732static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4733 size_t len, loff_t *offp)
4734{
4735 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004736 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004737 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004738
David Weinehall36cdd012016-08-22 13:59:31 +03004739 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004740 latencies = dev_priv->wm.skl_latency;
4741 else
David Weinehall36cdd012016-08-22 13:59:31 +03004742 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004743
4744 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004745}
4746
4747static const struct file_operations i915_pri_wm_latency_fops = {
4748 .owner = THIS_MODULE,
4749 .open = pri_wm_latency_open,
4750 .read = seq_read,
4751 .llseek = seq_lseek,
4752 .release = single_release,
4753 .write = pri_wm_latency_write
4754};
4755
4756static const struct file_operations i915_spr_wm_latency_fops = {
4757 .owner = THIS_MODULE,
4758 .open = spr_wm_latency_open,
4759 .read = seq_read,
4760 .llseek = seq_lseek,
4761 .release = single_release,
4762 .write = spr_wm_latency_write
4763};
4764
4765static const struct file_operations i915_cur_wm_latency_fops = {
4766 .owner = THIS_MODULE,
4767 .open = cur_wm_latency_open,
4768 .read = seq_read,
4769 .llseek = seq_lseek,
4770 .release = single_release,
4771 .write = cur_wm_latency_write
4772};
4773
Kees Cook647416f2013-03-10 14:10:06 -07004774static int
4775i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004776{
David Weinehall36cdd012016-08-22 13:59:31 +03004777 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004778
Chris Wilsond98c52c2016-04-13 17:35:05 +01004779 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004780
Kees Cook647416f2013-03-10 14:10:06 -07004781 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004782}
4783
Kees Cook647416f2013-03-10 14:10:06 -07004784static int
4785i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004786{
David Weinehall36cdd012016-08-22 13:59:31 +03004787 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004788
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004789 /*
4790 * There is no safeguard against this debugfs entry colliding
4791 * with the hangcheck calling same i915_handle_error() in
4792 * parallel, causing an explosion. For now we assume that the
4793 * test harness is responsible enough not to inject gpu hangs
4794 * while it is writing to 'i915_wedged'
4795 */
4796
Chris Wilsond98c52c2016-04-13 17:35:05 +01004797 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004798 return -EAGAIN;
4799
Imre Deakd46c0512014-04-14 20:24:27 +03004800 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004801
Chris Wilsonc0336662016-05-06 15:40:21 +01004802 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004803 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004804
4805 intel_runtime_pm_put(dev_priv);
4806
Kees Cook647416f2013-03-10 14:10:06 -07004807 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004808}
4809
Kees Cook647416f2013-03-10 14:10:06 -07004810DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4811 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004812 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004813
Kees Cook647416f2013-03-10 14:10:06 -07004814static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004815i915_ring_missed_irq_get(void *data, u64 *val)
4816{
David Weinehall36cdd012016-08-22 13:59:31 +03004817 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004818
4819 *val = dev_priv->gpu_error.missed_irq_rings;
4820 return 0;
4821}
4822
4823static int
4824i915_ring_missed_irq_set(void *data, u64 val)
4825{
David Weinehall36cdd012016-08-22 13:59:31 +03004826 struct drm_i915_private *dev_priv = data;
4827 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004828 int ret;
4829
4830 /* Lock against concurrent debugfs callers */
4831 ret = mutex_lock_interruptible(&dev->struct_mutex);
4832 if (ret)
4833 return ret;
4834 dev_priv->gpu_error.missed_irq_rings = val;
4835 mutex_unlock(&dev->struct_mutex);
4836
4837 return 0;
4838}
4839
4840DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4841 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4842 "0x%08llx\n");
4843
4844static int
4845i915_ring_test_irq_get(void *data, u64 *val)
4846{
David Weinehall36cdd012016-08-22 13:59:31 +03004847 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004848
4849 *val = dev_priv->gpu_error.test_irq_rings;
4850
4851 return 0;
4852}
4853
4854static int
4855i915_ring_test_irq_set(void *data, u64 val)
4856{
David Weinehall36cdd012016-08-22 13:59:31 +03004857 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004858
Chris Wilson3a122c22016-06-17 14:35:05 +01004859 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004860 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004861 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004862
4863 return 0;
4864}
4865
4866DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4867 i915_ring_test_irq_get, i915_ring_test_irq_set,
4868 "0x%08llx\n");
4869
Chris Wilsondd624af2013-01-15 12:39:35 +00004870#define DROP_UNBOUND 0x1
4871#define DROP_BOUND 0x2
4872#define DROP_RETIRE 0x4
4873#define DROP_ACTIVE 0x8
4874#define DROP_ALL (DROP_UNBOUND | \
4875 DROP_BOUND | \
4876 DROP_RETIRE | \
4877 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004878static int
4879i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004880{
Kees Cook647416f2013-03-10 14:10:06 -07004881 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004882
Kees Cook647416f2013-03-10 14:10:06 -07004883 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004884}
4885
Kees Cook647416f2013-03-10 14:10:06 -07004886static int
4887i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004888{
David Weinehall36cdd012016-08-22 13:59:31 +03004889 struct drm_i915_private *dev_priv = data;
4890 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004891 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004892
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004893 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004894
4895 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4896 * on ioctls on -EAGAIN. */
4897 ret = mutex_lock_interruptible(&dev->struct_mutex);
4898 if (ret)
4899 return ret;
4900
4901 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004902 ret = i915_gem_wait_for_idle(dev_priv,
4903 I915_WAIT_INTERRUPTIBLE |
4904 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004905 if (ret)
4906 goto unlock;
4907 }
4908
4909 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004910 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004911
Chris Wilson21ab4e72014-09-09 11:16:08 +01004912 if (val & DROP_BOUND)
4913 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004914
Chris Wilson21ab4e72014-09-09 11:16:08 +01004915 if (val & DROP_UNBOUND)
4916 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004917
4918unlock:
4919 mutex_unlock(&dev->struct_mutex);
4920
Kees Cook647416f2013-03-10 14:10:06 -07004921 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004922}
4923
Kees Cook647416f2013-03-10 14:10:06 -07004924DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4925 i915_drop_caches_get, i915_drop_caches_set,
4926 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004927
Kees Cook647416f2013-03-10 14:10:06 -07004928static int
4929i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004930{
David Weinehall36cdd012016-08-22 13:59:31 +03004931 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004932
David Weinehall36cdd012016-08-22 13:59:31 +03004933 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004934 return -ENODEV;
4935
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004936 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004937 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004938}
4939
Kees Cook647416f2013-03-10 14:10:06 -07004940static int
4941i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004942{
David Weinehall36cdd012016-08-22 13:59:31 +03004943 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304944 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004945 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004946
David Weinehall36cdd012016-08-22 13:59:31 +03004947 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004948 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004949
Kees Cook647416f2013-03-10 14:10:06 -07004950 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004951
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004952 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004953 if (ret)
4954 return ret;
4955
Jesse Barnes358733e2011-07-27 11:53:01 -07004956 /*
4957 * Turbo will still be enabled, but won't go above the set value.
4958 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304959 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004960
Akash Goelbc4d91f2015-02-26 16:09:47 +05304961 hw_max = dev_priv->rps.max_freq;
4962 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004963
Ben Widawskyb39fb292014-03-19 18:31:11 -07004964 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004965 mutex_unlock(&dev_priv->rps.hw_lock);
4966 return -EINVAL;
4967 }
4968
Ben Widawskyb39fb292014-03-19 18:31:11 -07004969 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004970
Chris Wilsondc979972016-05-10 14:10:04 +01004971 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004972
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004973 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004974
Kees Cook647416f2013-03-10 14:10:06 -07004975 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004976}
4977
Kees Cook647416f2013-03-10 14:10:06 -07004978DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4979 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004980 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004981
Kees Cook647416f2013-03-10 14:10:06 -07004982static int
4983i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004984{
David Weinehall36cdd012016-08-22 13:59:31 +03004985 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004986
Chris Wilson62e1baa2016-07-13 09:10:36 +01004987 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004988 return -ENODEV;
4989
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004990 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004991 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004992}
4993
Kees Cook647416f2013-03-10 14:10:06 -07004994static int
4995i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004996{
David Weinehall36cdd012016-08-22 13:59:31 +03004997 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304998 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004999 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005000
Chris Wilson62e1baa2016-07-13 09:10:36 +01005001 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005002 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005003
Kees Cook647416f2013-03-10 14:10:06 -07005004 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005005
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005006 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005007 if (ret)
5008 return ret;
5009
Jesse Barnes1523c312012-05-25 12:34:54 -07005010 /*
5011 * Turbo will still be enabled, but won't go below the set value.
5012 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305013 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005014
Akash Goelbc4d91f2015-02-26 16:09:47 +05305015 hw_max = dev_priv->rps.max_freq;
5016 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005017
David Weinehall36cdd012016-08-22 13:59:31 +03005018 if (val < hw_min ||
5019 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005020 mutex_unlock(&dev_priv->rps.hw_lock);
5021 return -EINVAL;
5022 }
5023
Ben Widawskyb39fb292014-03-19 18:31:11 -07005024 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005025
Chris Wilsondc979972016-05-10 14:10:04 +01005026 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005027
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005028 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005029
Kees Cook647416f2013-03-10 14:10:06 -07005030 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005031}
5032
Kees Cook647416f2013-03-10 14:10:06 -07005033DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5034 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005035 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005036
Kees Cook647416f2013-03-10 14:10:06 -07005037static int
5038i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005039{
David Weinehall36cdd012016-08-22 13:59:31 +03005040 struct drm_i915_private *dev_priv = data;
5041 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005042 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005043 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005044
David Weinehall36cdd012016-08-22 13:59:31 +03005045 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005046 return -ENODEV;
5047
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005048 ret = mutex_lock_interruptible(&dev->struct_mutex);
5049 if (ret)
5050 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005051 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005052
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005053 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005054
5055 intel_runtime_pm_put(dev_priv);
David Weinehall36cdd012016-08-22 13:59:31 +03005056 mutex_unlock(&dev->struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005057
Kees Cook647416f2013-03-10 14:10:06 -07005058 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005059
Kees Cook647416f2013-03-10 14:10:06 -07005060 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005061}
5062
Kees Cook647416f2013-03-10 14:10:06 -07005063static int
5064i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005065{
David Weinehall36cdd012016-08-22 13:59:31 +03005066 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005067 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005068
David Weinehall36cdd012016-08-22 13:59:31 +03005069 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005070 return -ENODEV;
5071
Kees Cook647416f2013-03-10 14:10:06 -07005072 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005073 return -EINVAL;
5074
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005075 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005076 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005077
5078 /* Update the cache sharing policy here as well */
5079 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5080 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5081 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5082 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5083
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005084 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005085 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005086}
5087
Kees Cook647416f2013-03-10 14:10:06 -07005088DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5089 i915_cache_sharing_get, i915_cache_sharing_set,
5090 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005091
David Weinehall36cdd012016-08-22 13:59:31 +03005092static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005093 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005094{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005095 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005096 int ss;
5097 u32 sig1[ss_max], sig2[ss_max];
5098
5099 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5100 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5101 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5102 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5103
5104 for (ss = 0; ss < ss_max; ss++) {
5105 unsigned int eu_cnt;
5106
5107 if (sig1[ss] & CHV_SS_PG_ENABLE)
5108 /* skip disabled subslice */
5109 continue;
5110
Imre Deakf08a0c92016-08-31 19:13:04 +03005111 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005112 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005113 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5114 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5115 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5116 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005117 sseu->eu_total += eu_cnt;
5118 sseu->eu_per_subslice = max_t(unsigned int,
5119 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005120 }
Jeff McGee5d395252015-04-03 18:13:17 -07005121}
5122
David Weinehall36cdd012016-08-22 13:59:31 +03005123static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005124 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005125{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005126 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005127 int s, ss;
5128 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5129
Jeff McGee1c046bc2015-04-03 18:13:18 -07005130 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005131 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005132 s_max = 1;
5133 ss_max = 3;
5134 }
5135
5136 for (s = 0; s < s_max; s++) {
5137 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5138 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5139 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5140 }
5141
Jeff McGee5d395252015-04-03 18:13:17 -07005142 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5143 GEN9_PGCTL_SSA_EU19_ACK |
5144 GEN9_PGCTL_SSA_EU210_ACK |
5145 GEN9_PGCTL_SSA_EU311_ACK;
5146 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5147 GEN9_PGCTL_SSB_EU19_ACK |
5148 GEN9_PGCTL_SSB_EU210_ACK |
5149 GEN9_PGCTL_SSB_EU311_ACK;
5150
5151 for (s = 0; s < s_max; s++) {
5152 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5153 /* skip disabled slice */
5154 continue;
5155
Imre Deakf08a0c92016-08-31 19:13:04 +03005156 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005157
David Weinehall36cdd012016-08-22 13:59:31 +03005158 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005159 sseu->subslice_mask =
5160 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005161
Jeff McGee5d395252015-04-03 18:13:17 -07005162 for (ss = 0; ss < ss_max; ss++) {
5163 unsigned int eu_cnt;
5164
Imre Deak57ec1712016-08-31 19:13:05 +03005165 if (IS_BROXTON(dev_priv)) {
5166 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5167 /* skip disabled subslice */
5168 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005169
Imre Deak57ec1712016-08-31 19:13:05 +03005170 sseu->subslice_mask |= BIT(ss);
5171 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005172
Jeff McGee5d395252015-04-03 18:13:17 -07005173 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5174 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005175 sseu->eu_total += eu_cnt;
5176 sseu->eu_per_subslice = max_t(unsigned int,
5177 sseu->eu_per_subslice,
5178 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005179 }
5180 }
5181}
5182
David Weinehall36cdd012016-08-22 13:59:31 +03005183static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005184 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005185{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005186 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005187 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005188
Imre Deakf08a0c92016-08-31 19:13:04 +03005189 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005190
Imre Deakf08a0c92016-08-31 19:13:04 +03005191 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005192 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005193 sseu->eu_per_subslice =
5194 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005195 sseu->eu_total = sseu->eu_per_subslice *
5196 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005197
5198 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005199 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005200 u8 subslice_7eu =
5201 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005202
Imre Deak915490d2016-08-31 19:13:01 +03005203 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005204 }
5205 }
5206}
5207
Imre Deak615d8902016-08-31 19:13:03 +03005208static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5209 const struct sseu_dev_info *sseu)
5210{
5211 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5212 const char *type = is_available_info ? "Available" : "Enabled";
5213
Imre Deakc67ba532016-08-31 19:13:06 +03005214 seq_printf(m, " %s Slice Mask: %04x\n", type,
5215 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005216 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005217 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005218 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005219 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005220 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5221 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005222 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005223 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005224 seq_printf(m, " %s EU Total: %u\n", type,
5225 sseu->eu_total);
5226 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5227 sseu->eu_per_subslice);
5228
5229 if (!is_available_info)
5230 return;
5231
5232 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5233 if (HAS_POOLED_EU(dev_priv))
5234 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5235
5236 seq_printf(m, " Has Slice Power Gating: %s\n",
5237 yesno(sseu->has_slice_pg));
5238 seq_printf(m, " Has Subslice Power Gating: %s\n",
5239 yesno(sseu->has_subslice_pg));
5240 seq_printf(m, " Has EU Power Gating: %s\n",
5241 yesno(sseu->has_eu_pg));
5242}
5243
Jeff McGee38732182015-02-13 10:27:54 -06005244static int i915_sseu_status(struct seq_file *m, void *unused)
5245{
David Weinehall36cdd012016-08-22 13:59:31 +03005246 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005247 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005248
David Weinehall36cdd012016-08-22 13:59:31 +03005249 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005250 return -ENODEV;
5251
5252 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005253 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005254
Jeff McGee7f992ab2015-02-13 10:27:55 -06005255 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005256 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005257
5258 intel_runtime_pm_get(dev_priv);
5259
David Weinehall36cdd012016-08-22 13:59:31 +03005260 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005261 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005262 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005263 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005264 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005265 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005266 }
David Weinehall238010e2016-08-01 17:33:27 +03005267
5268 intel_runtime_pm_put(dev_priv);
5269
Imre Deak615d8902016-08-31 19:13:03 +03005270 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005271
Jeff McGee38732182015-02-13 10:27:54 -06005272 return 0;
5273}
5274
Ben Widawsky6d794d42011-04-25 11:25:56 -07005275static int i915_forcewake_open(struct inode *inode, struct file *file)
5276{
David Weinehall36cdd012016-08-22 13:59:31 +03005277 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005278
David Weinehall36cdd012016-08-22 13:59:31 +03005279 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005280 return 0;
5281
Chris Wilson6daccb02015-01-16 11:34:35 +02005282 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005283 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005284
5285 return 0;
5286}
5287
Ben Widawskyc43b5632012-04-16 14:07:40 -07005288static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005289{
David Weinehall36cdd012016-08-22 13:59:31 +03005290 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005291
David Weinehall36cdd012016-08-22 13:59:31 +03005292 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005293 return 0;
5294
Mika Kuoppala59bad942015-01-16 11:34:40 +02005295 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005296 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005297
5298 return 0;
5299}
5300
5301static const struct file_operations i915_forcewake_fops = {
5302 .owner = THIS_MODULE,
5303 .open = i915_forcewake_open,
5304 .release = i915_forcewake_release,
5305};
5306
5307static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5308{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005309 struct dentry *ent;
5310
5311 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005312 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005313 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005314 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005315 if (!ent)
5316 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005317
Ben Widawsky8eb57292011-05-11 15:10:58 -07005318 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005319}
5320
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005321static int i915_debugfs_create(struct dentry *root,
5322 struct drm_minor *minor,
5323 const char *name,
5324 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005325{
Jesse Barnes358733e2011-07-27 11:53:01 -07005326 struct dentry *ent;
5327
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005328 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005329 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005330 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005331 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005332 if (!ent)
5333 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005334
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005335 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005336}
5337
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005338static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005339 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005340 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005341 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005342 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005343 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005344 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005345 {"i915_gem_request", i915_gem_request_info, 0},
5346 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005347 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005348 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005349 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5350 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5351 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005352 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005353 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005354 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005355 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005356 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305357 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005358 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005359 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005360 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005361 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005362 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005363 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005364 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005365 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005366 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005367 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005368 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005369 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005370 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005371 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005372 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005373 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005374 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005375 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005376 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005377 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005378 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005379 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005380 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005381 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005382 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005383 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005384 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005385 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005386 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005387 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005388 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305389 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005390 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005391};
Ben Gamari27c202a2009-07-01 22:26:52 -04005392#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005393
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005394static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005395 const char *name;
5396 const struct file_operations *fops;
5397} i915_debugfs_files[] = {
5398 {"i915_wedged", &i915_wedged_fops},
5399 {"i915_max_freq", &i915_max_freq_fops},
5400 {"i915_min_freq", &i915_min_freq_fops},
5401 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005402 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5403 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005404 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005405#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005406 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005407#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005408 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005409 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005410 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5411 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5412 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005413 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005414 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5415 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5416 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005417};
5418
David Weinehall36cdd012016-08-22 13:59:31 +03005419void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005420{
Daniel Vetterb3783602013-11-14 11:30:42 +01005421 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005422
Damien Lespiau055e3932014-08-18 13:49:10 +01005423 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005424 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005425
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005426 pipe_crc->opened = false;
5427 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005428 init_waitqueue_head(&pipe_crc->wq);
5429 }
5430}
5431
Chris Wilson1dac8912016-06-24 14:00:17 +01005432int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005433{
Chris Wilson91c8a322016-07-05 10:40:23 +01005434 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005435 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005436
Ben Widawsky6d794d42011-04-25 11:25:56 -07005437 ret = i915_forcewake_create(minor->debugfs_root, minor);
5438 if (ret)
5439 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005440
Damien Lespiau07144422013-10-15 18:55:40 +01005441 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5442 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5443 if (ret)
5444 return ret;
5445 }
5446
Daniel Vetter34b96742013-07-04 20:49:44 +02005447 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5448 ret = i915_debugfs_create(minor->debugfs_root, minor,
5449 i915_debugfs_files[i].name,
5450 i915_debugfs_files[i].fops);
5451 if (ret)
5452 return ret;
5453 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005454
Ben Gamari27c202a2009-07-01 22:26:52 -04005455 return drm_debugfs_create_files(i915_debugfs_list,
5456 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005457 minor->debugfs_root, minor);
5458}
5459
Chris Wilson1dac8912016-06-24 14:00:17 +01005460void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005461{
Chris Wilson91c8a322016-07-05 10:40:23 +01005462 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005463 int i;
5464
Ben Gamari27c202a2009-07-01 22:26:52 -04005465 drm_debugfs_remove_files(i915_debugfs_list,
5466 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005467
David Weinehall36cdd012016-08-22 13:59:31 +03005468 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005469 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005470
Daniel Vettere309a992013-10-16 22:55:51 +02005471 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005472 struct drm_info_list *info_list =
5473 (struct drm_info_list *)&i915_pipe_crc_data[i];
5474
5475 drm_debugfs_remove_files(info_list, 1, minor);
5476 }
5477
Daniel Vetter34b96742013-07-04 20:49:44 +02005478 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5479 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005480 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005481
5482 drm_debugfs_remove_files(info_list, 1, minor);
5483 }
Ben Gamari20172632009-02-17 20:08:50 -05005484}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005485
5486struct dpcd_block {
5487 /* DPCD dump start address. */
5488 unsigned int offset;
5489 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5490 unsigned int end;
5491 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5492 size_t size;
5493 /* Only valid for eDP. */
5494 bool edp;
5495};
5496
5497static const struct dpcd_block i915_dpcd_debug[] = {
5498 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5499 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5500 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5501 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5502 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5503 { .offset = DP_SET_POWER },
5504 { .offset = DP_EDP_DPCD_REV },
5505 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5506 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5507 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5508};
5509
5510static int i915_dpcd_show(struct seq_file *m, void *data)
5511{
5512 struct drm_connector *connector = m->private;
5513 struct intel_dp *intel_dp =
5514 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5515 uint8_t buf[16];
5516 ssize_t err;
5517 int i;
5518
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005519 if (connector->status != connector_status_connected)
5520 return -ENODEV;
5521
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005522 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5523 const struct dpcd_block *b = &i915_dpcd_debug[i];
5524 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5525
5526 if (b->edp &&
5527 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5528 continue;
5529
5530 /* low tech for now */
5531 if (WARN_ON(size > sizeof(buf)))
5532 continue;
5533
5534 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5535 if (err <= 0) {
5536 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5537 size, b->offset, err);
5538 continue;
5539 }
5540
5541 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005542 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005543
5544 return 0;
5545}
5546
5547static int i915_dpcd_open(struct inode *inode, struct file *file)
5548{
5549 return single_open(file, i915_dpcd_show, inode->i_private);
5550}
5551
5552static const struct file_operations i915_dpcd_fops = {
5553 .owner = THIS_MODULE,
5554 .open = i915_dpcd_open,
5555 .read = seq_read,
5556 .llseek = seq_lseek,
5557 .release = single_release,
5558};
5559
David Weinehallecbd6782016-08-23 12:23:56 +03005560static int i915_panel_show(struct seq_file *m, void *data)
5561{
5562 struct drm_connector *connector = m->private;
5563 struct intel_dp *intel_dp =
5564 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5565
5566 if (connector->status != connector_status_connected)
5567 return -ENODEV;
5568
5569 seq_printf(m, "Panel power up delay: %d\n",
5570 intel_dp->panel_power_up_delay);
5571 seq_printf(m, "Panel power down delay: %d\n",
5572 intel_dp->panel_power_down_delay);
5573 seq_printf(m, "Backlight on delay: %d\n",
5574 intel_dp->backlight_on_delay);
5575 seq_printf(m, "Backlight off delay: %d\n",
5576 intel_dp->backlight_off_delay);
5577
5578 return 0;
5579}
5580
5581static int i915_panel_open(struct inode *inode, struct file *file)
5582{
5583 return single_open(file, i915_panel_show, inode->i_private);
5584}
5585
5586static const struct file_operations i915_panel_fops = {
5587 .owner = THIS_MODULE,
5588 .open = i915_panel_open,
5589 .read = seq_read,
5590 .llseek = seq_lseek,
5591 .release = single_release,
5592};
5593
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005594/**
5595 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5596 * @connector: pointer to a registered drm_connector
5597 *
5598 * Cleanup will be done by drm_connector_unregister() through a call to
5599 * drm_debugfs_connector_remove().
5600 *
5601 * Returns 0 on success, negative error codes on error.
5602 */
5603int i915_debugfs_connector_add(struct drm_connector *connector)
5604{
5605 struct dentry *root = connector->debugfs_entry;
5606
5607 /* The connector must have been registered beforehands. */
5608 if (!root)
5609 return -ENODEV;
5610
5611 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5612 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005613 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5614 connector, &i915_dpcd_fops);
5615
5616 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5617 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5618 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005619
5620 return 0;
5621}