blob: 2e312e0f267024a08cade0e8ebeb2e5310761d52 [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 Wilson8baa1f02016-10-12 12:48:27 +0100110 return obj->fault_mappable ? '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 Wilson27c01aa2016-08-04 07:52:30 +0100189
Chris Wilsond72d9082016-08-04 07:52:31 +0100190 engine = i915_gem_active_get_engine(&obj->last_write,
David Weinehall36cdd012016-08-22 13:59:31 +0300191 &dev_priv->drm.struct_mutex);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100192 if (engine)
193 seq_printf(m, " (%s)", engine->name);
194
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100195 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
196 if (frontbuffer_bits)
197 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100198}
199
Chris Wilson6d2b88852013-08-07 18:30:54 +0100200static int obj_rank_by_stolen(void *priv,
201 struct list_head *A, struct list_head *B)
202{
203 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200204 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100205 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200206 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100207
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200208 if (a->stolen->start < b->stolen->start)
209 return -1;
210 if (a->stolen->start > b->stolen->start)
211 return 1;
212 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100213}
214
215static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
216{
David Weinehall36cdd012016-08-22 13:59:31 +0300217 struct drm_i915_private *dev_priv = node_to_i915(m->private);
218 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100219 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300220 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100221 LIST_HEAD(stolen);
222 int count, ret;
223
224 ret = mutex_lock_interruptible(&dev->struct_mutex);
225 if (ret)
226 return ret;
227
228 total_obj_size = total_gtt_size = count = 0;
229 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
230 if (obj->stolen == NULL)
231 continue;
232
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200233 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100234
235 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100236 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100237 count++;
238 }
239 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
240 if (obj->stolen == NULL)
241 continue;
242
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200243 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100244
245 total_obj_size += obj->base.size;
246 count++;
247 }
248 list_sort(NULL, &stolen, obj_rank_by_stolen);
249 seq_puts(m, "Stolen:\n");
250 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200251 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252 seq_puts(m, " ");
253 describe_obj(m, obj);
254 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200255 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100256 }
257 mutex_unlock(&dev->struct_mutex);
258
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300259 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100260 count, total_obj_size, total_gtt_size);
261 return 0;
262}
263
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100264struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000265 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300266 unsigned long count;
267 u64 total, unbound;
268 u64 global, shared;
269 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100270};
271
272static int per_file_stats(int id, void *ptr, void *data)
273{
274 struct drm_i915_gem_object *obj = ptr;
275 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000276 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100277
278 stats->count++;
279 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100280 if (!obj->bind_count)
281 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000282 if (obj->base.name || obj->base.dma_buf)
283 stats->shared += obj->base.size;
284
Chris Wilson894eeec2016-08-04 07:52:20 +0100285 list_for_each_entry(vma, &obj->vma_list, obj_link) {
286 if (!drm_mm_node_allocated(&vma->node))
287 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000288
Chris Wilson3272db52016-08-04 16:32:32 +0100289 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100290 stats->global += vma->node.size;
291 } else {
292 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000293
Chris Wilson2bfa9962016-08-04 07:52:25 +0100294 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000295 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000296 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100297
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100298 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100299 stats->active += vma->node.size;
300 else
301 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100302 }
303
304 return 0;
305}
306
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100307#define print_file_stats(m, name, stats) do { \
308 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300309 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 +0100310 name, \
311 stats.count, \
312 stats.total, \
313 stats.active, \
314 stats.inactive, \
315 stats.global, \
316 stats.shared, \
317 stats.unbound); \
318} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800319
320static void print_batch_pool_stats(struct seq_file *m,
321 struct drm_i915_private *dev_priv)
322{
323 struct drm_i915_gem_object *obj;
324 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000325 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000326 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800327
328 memset(&stats, 0, sizeof(stats));
329
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000330 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000331 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100332 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000333 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100334 batch_pool_link)
335 per_file_stats(0, obj, &stats);
336 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100337 }
Brad Volkin493018d2014-12-11 12:13:08 -0800338
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100339 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800340}
341
Chris Wilson15da9562016-05-24 14:53:43 +0100342static int per_file_ctx_stats(int id, void *ptr, void *data)
343{
344 struct i915_gem_context *ctx = ptr;
345 int n;
346
347 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
348 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100349 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100350 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100351 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100352 }
353
354 return 0;
355}
356
357static void print_context_stats(struct seq_file *m,
358 struct drm_i915_private *dev_priv)
359{
David Weinehall36cdd012016-08-22 13:59:31 +0300360 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100361 struct file_stats stats;
362 struct drm_file *file;
363
364 memset(&stats, 0, sizeof(stats));
365
David Weinehall36cdd012016-08-22 13:59:31 +0300366 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100367 if (dev_priv->kernel_context)
368 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
369
David Weinehall36cdd012016-08-22 13:59:31 +0300370 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100371 struct drm_i915_file_private *fpriv = file->driver_priv;
372 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
373 }
David Weinehall36cdd012016-08-22 13:59:31 +0300374 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100375
376 print_file_stats(m, "[k]contexts", stats);
377}
378
David Weinehall36cdd012016-08-22 13:59:31 +0300379static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100380{
David Weinehall36cdd012016-08-22 13:59:31 +0300381 struct drm_i915_private *dev_priv = node_to_i915(m->private);
382 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300383 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100384 u32 count, mapped_count, purgeable_count, dpy_count;
385 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000386 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100387 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100388 int ret;
389
390 ret = mutex_lock_interruptible(&dev->struct_mutex);
391 if (ret)
392 return ret;
393
Chris Wilson6299f992010-11-24 12:23:44 +0000394 seq_printf(m, "%u objects, %zu bytes\n",
395 dev_priv->mm.object_count,
396 dev_priv->mm.object_memory);
397
Chris Wilson1544c422016-08-15 13:18:16 +0100398 size = count = 0;
399 mapped_size = mapped_count = 0;
400 purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700401 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100402 size += obj->base.size;
403 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200404
Chris Wilsonb7abb712012-08-20 11:33:30 +0200405 if (obj->madv == I915_MADV_DONTNEED) {
406 purgeable_size += obj->base.size;
407 ++purgeable_count;
408 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100409
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100410 if (obj->mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100411 mapped_count++;
412 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100413 }
Chris Wilson6299f992010-11-24 12:23:44 +0000414 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100415 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
416
417 size = count = dpy_size = dpy_count = 0;
418 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
419 size += obj->base.size;
420 ++count;
421
422 if (obj->pin_display) {
423 dpy_size += obj->base.size;
424 ++dpy_count;
425 }
426
427 if (obj->madv == I915_MADV_DONTNEED) {
428 purgeable_size += obj->base.size;
429 ++purgeable_count;
430 }
431
432 if (obj->mapping) {
433 mapped_count++;
434 mapped_size += obj->base.size;
435 }
436 }
437 seq_printf(m, "%u bound objects, %llu bytes\n",
438 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300439 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200440 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100441 seq_printf(m, "%u mapped objects, %llu bytes\n",
442 mapped_count, mapped_size);
443 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
444 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000445
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300446 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300447 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100448
Damien Lespiau267f0c92013-06-24 22:59:48 +0100449 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800450 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200451 mutex_unlock(&dev->struct_mutex);
452
453 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100454 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100455 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
456 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100457 struct drm_i915_file_private *file_priv = file->driver_priv;
458 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900459 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100460
461 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000462 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100463 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100464 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100465 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900466 /*
467 * Although we have a valid reference on file->pid, that does
468 * not guarantee that the task_struct who called get_pid() is
469 * still alive (e.g. get_pid(current) => fork() => exit()).
470 * Therefore, we need to protect this ->comm access using RCU.
471 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100472 mutex_lock(&dev->struct_mutex);
473 request = list_first_entry_or_null(&file_priv->mm.request_list,
474 struct drm_i915_gem_request,
475 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900476 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100477 task = pid_task(request && request->ctx->pid ?
478 request->ctx->pid : file->pid,
479 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800480 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900481 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100482 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100483 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200484 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100485
486 return 0;
487}
488
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100489static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000490{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100491 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300492 struct drm_i915_private *dev_priv = node_to_i915(node);
493 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100494 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000495 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300496 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000497 int count, ret;
498
499 ret = mutex_lock_interruptible(&dev->struct_mutex);
500 if (ret)
501 return ret;
502
503 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700504 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6da84822016-08-15 10:48:44 +0100505 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100506 continue;
507
Damien Lespiau267f0c92013-06-24 22:59:48 +0100508 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000509 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100510 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000511 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100512 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000513 count++;
514 }
515
516 mutex_unlock(&dev->struct_mutex);
517
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300518 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000519 count, total_obj_size, total_gtt_size);
520
521 return 0;
522}
523
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100524static int i915_gem_pageflip_info(struct seq_file *m, void *data)
525{
David Weinehall36cdd012016-08-22 13:59:31 +0300526 struct drm_i915_private *dev_priv = node_to_i915(m->private);
527 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100528 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200529 int ret;
530
531 ret = mutex_lock_interruptible(&dev->struct_mutex);
532 if (ret)
533 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100534
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100535 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800536 const char pipe = pipe_name(crtc->pipe);
537 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200538 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100539
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200540 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200541 work = crtc->flip_work;
542 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800543 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100544 pipe, plane);
545 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200546 u32 pending;
547 u32 addr;
548
549 pending = atomic_read(&work->pending);
550 if (pending) {
551 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
552 pipe, plane);
553 } else {
554 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
555 pipe, plane);
556 }
557 if (work->flip_queued_req) {
558 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
559
560 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
561 engine->name,
562 i915_gem_request_get_seqno(work->flip_queued_req),
563 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100564 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100565 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200566 } else
567 seq_printf(m, "Flip not associated with any ring\n");
568 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
569 work->flip_queued_vblank,
570 work->flip_ready_vblank,
571 intel_crtc_get_vblank_counter(crtc));
572 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
573
David Weinehall36cdd012016-08-22 13:59:31 +0300574 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200575 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
576 else
577 addr = I915_READ(DSPADDR(crtc->plane));
578 seq_printf(m, "Current scanout address 0x%08x\n", addr);
579
580 if (work->pending_flip_obj) {
581 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
582 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100583 }
584 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200585 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100586 }
587
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200588 mutex_unlock(&dev->struct_mutex);
589
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100590 return 0;
591}
592
Brad Volkin493018d2014-12-11 12:13:08 -0800593static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
594{
David Weinehall36cdd012016-08-22 13:59:31 +0300595 struct drm_i915_private *dev_priv = node_to_i915(m->private);
596 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800597 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000598 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100599 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000600 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800601
602 ret = mutex_lock_interruptible(&dev->struct_mutex);
603 if (ret)
604 return ret;
605
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000606 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000607 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100608 int count;
609
610 count = 0;
611 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000612 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100613 batch_pool_link)
614 count++;
615 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000616 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100617
618 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000619 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100620 batch_pool_link) {
621 seq_puts(m, " ");
622 describe_obj(m, obj);
623 seq_putc(m, '\n');
624 }
625
626 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100627 }
Brad Volkin493018d2014-12-11 12:13:08 -0800628 }
629
Chris Wilson8d9d5742015-04-07 16:20:38 +0100630 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800631
632 mutex_unlock(&dev->struct_mutex);
633
634 return 0;
635}
636
Chris Wilson1b365952016-10-04 21:11:31 +0100637static void print_request(struct seq_file *m,
638 struct drm_i915_gem_request *rq,
639 const char *prefix)
640{
641 struct pid *pid = rq->ctx->pid;
642 struct task_struct *task;
643
644 rcu_read_lock();
645 task = pid ? pid_task(pid, PIDTYPE_PID) : NULL;
646 seq_printf(m, "%s%x [%x:%x] @ %d: %s [%d]\n", prefix,
647 rq->fence.seqno, rq->ctx->hw_id, rq->fence.seqno,
648 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
649 task ? task->comm : "<unknown>",
650 task ? task->pid : -1);
651 rcu_read_unlock();
652}
653
Ben Gamari20172632009-02-17 20:08:50 -0500654static int i915_gem_request_info(struct seq_file *m, void *data)
655{
David Weinehall36cdd012016-08-22 13:59:31 +0300656 struct drm_i915_private *dev_priv = node_to_i915(m->private);
657 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000658 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200659 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000660 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100661
662 ret = mutex_lock_interruptible(&dev->struct_mutex);
663 if (ret)
664 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500665
Chris Wilson2d1070b2015-04-01 10:36:56 +0100666 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000667 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100668 int count;
669
670 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100671 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100672 count++;
673 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100674 continue;
675
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000676 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson1b365952016-10-04 21:11:31 +0100677 list_for_each_entry(req, &engine->request_list, link)
678 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100679
680 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500681 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100682 mutex_unlock(&dev->struct_mutex);
683
Chris Wilson2d1070b2015-04-01 10:36:56 +0100684 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100685 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100686
Ben Gamari20172632009-02-17 20:08:50 -0500687 return 0;
688}
689
Chris Wilsonb2223492010-10-27 15:27:33 +0100690static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000691 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100692{
Chris Wilson688e6c72016-07-01 17:23:15 +0100693 struct intel_breadcrumbs *b = &engine->breadcrumbs;
694 struct rb_node *rb;
695
Chris Wilson12471ba2016-04-09 10:57:55 +0100696 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100697 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100698
699 spin_lock(&b->lock);
700 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
701 struct intel_wait *w = container_of(rb, typeof(*w), node);
702
703 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
704 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
705 }
706 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100707}
708
Ben Gamari20172632009-02-17 20:08:50 -0500709static int i915_gem_seqno_info(struct seq_file *m, void *data)
710{
David Weinehall36cdd012016-08-22 13:59:31 +0300711 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000712 struct intel_engine_cs *engine;
Ben Gamari20172632009-02-17 20:08:50 -0500713
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000714 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000715 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100716
Ben Gamari20172632009-02-17 20:08:50 -0500717 return 0;
718}
719
720
721static int i915_interrupt_info(struct seq_file *m, void *data)
722{
David Weinehall36cdd012016-08-22 13:59:31 +0300723 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000724 struct intel_engine_cs *engine;
Chris Wilson4bb05042016-09-03 07:53:43 +0100725 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100726
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200727 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500728
David Weinehall36cdd012016-08-22 13:59:31 +0300729 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300730 seq_printf(m, "Master Interrupt Control:\t%08x\n",
731 I915_READ(GEN8_MASTER_IRQ));
732
733 seq_printf(m, "Display IER:\t%08x\n",
734 I915_READ(VLV_IER));
735 seq_printf(m, "Display IIR:\t%08x\n",
736 I915_READ(VLV_IIR));
737 seq_printf(m, "Display IIR_RW:\t%08x\n",
738 I915_READ(VLV_IIR_RW));
739 seq_printf(m, "Display IMR:\t%08x\n",
740 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100741 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300742 seq_printf(m, "Pipe %c stat:\t%08x\n",
743 pipe_name(pipe),
744 I915_READ(PIPESTAT(pipe)));
745
746 seq_printf(m, "Port hotplug:\t%08x\n",
747 I915_READ(PORT_HOTPLUG_EN));
748 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
749 I915_READ(VLV_DPFLIPSTAT));
750 seq_printf(m, "DPINVGTT:\t%08x\n",
751 I915_READ(DPINVGTT));
752
753 for (i = 0; i < 4; i++) {
754 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
755 i, I915_READ(GEN8_GT_IMR(i)));
756 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
757 i, I915_READ(GEN8_GT_IIR(i)));
758 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
759 i, I915_READ(GEN8_GT_IER(i)));
760 }
761
762 seq_printf(m, "PCU interrupt mask:\t%08x\n",
763 I915_READ(GEN8_PCU_IMR));
764 seq_printf(m, "PCU interrupt identity:\t%08x\n",
765 I915_READ(GEN8_PCU_IIR));
766 seq_printf(m, "PCU interrupt enable:\t%08x\n",
767 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300768 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700769 seq_printf(m, "Master Interrupt Control:\t%08x\n",
770 I915_READ(GEN8_MASTER_IRQ));
771
772 for (i = 0; i < 4; i++) {
773 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
774 i, I915_READ(GEN8_GT_IMR(i)));
775 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
776 i, I915_READ(GEN8_GT_IIR(i)));
777 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
778 i, I915_READ(GEN8_GT_IER(i)));
779 }
780
Damien Lespiau055e3932014-08-18 13:49:10 +0100781 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200782 enum intel_display_power_domain power_domain;
783
784 power_domain = POWER_DOMAIN_PIPE(pipe);
785 if (!intel_display_power_get_if_enabled(dev_priv,
786 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300787 seq_printf(m, "Pipe %c power disabled\n",
788 pipe_name(pipe));
789 continue;
790 }
Ben Widawskya123f152013-11-02 21:07:10 -0700791 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000792 pipe_name(pipe),
793 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700794 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000795 pipe_name(pipe),
796 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700797 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000798 pipe_name(pipe),
799 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200800
801 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700802 }
803
804 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
805 I915_READ(GEN8_DE_PORT_IMR));
806 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
807 I915_READ(GEN8_DE_PORT_IIR));
808 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
809 I915_READ(GEN8_DE_PORT_IER));
810
811 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
812 I915_READ(GEN8_DE_MISC_IMR));
813 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
814 I915_READ(GEN8_DE_MISC_IIR));
815 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
816 I915_READ(GEN8_DE_MISC_IER));
817
818 seq_printf(m, "PCU interrupt mask:\t%08x\n",
819 I915_READ(GEN8_PCU_IMR));
820 seq_printf(m, "PCU interrupt identity:\t%08x\n",
821 I915_READ(GEN8_PCU_IIR));
822 seq_printf(m, "PCU interrupt enable:\t%08x\n",
823 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300824 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700825 seq_printf(m, "Display IER:\t%08x\n",
826 I915_READ(VLV_IER));
827 seq_printf(m, "Display IIR:\t%08x\n",
828 I915_READ(VLV_IIR));
829 seq_printf(m, "Display IIR_RW:\t%08x\n",
830 I915_READ(VLV_IIR_RW));
831 seq_printf(m, "Display IMR:\t%08x\n",
832 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100833 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700834 seq_printf(m, "Pipe %c stat:\t%08x\n",
835 pipe_name(pipe),
836 I915_READ(PIPESTAT(pipe)));
837
838 seq_printf(m, "Master IER:\t%08x\n",
839 I915_READ(VLV_MASTER_IER));
840
841 seq_printf(m, "Render IER:\t%08x\n",
842 I915_READ(GTIER));
843 seq_printf(m, "Render IIR:\t%08x\n",
844 I915_READ(GTIIR));
845 seq_printf(m, "Render IMR:\t%08x\n",
846 I915_READ(GTIMR));
847
848 seq_printf(m, "PM IER:\t\t%08x\n",
849 I915_READ(GEN6_PMIER));
850 seq_printf(m, "PM IIR:\t\t%08x\n",
851 I915_READ(GEN6_PMIIR));
852 seq_printf(m, "PM IMR:\t\t%08x\n",
853 I915_READ(GEN6_PMIMR));
854
855 seq_printf(m, "Port hotplug:\t%08x\n",
856 I915_READ(PORT_HOTPLUG_EN));
857 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
858 I915_READ(VLV_DPFLIPSTAT));
859 seq_printf(m, "DPINVGTT:\t%08x\n",
860 I915_READ(DPINVGTT));
861
David Weinehall36cdd012016-08-22 13:59:31 +0300862 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800863 seq_printf(m, "Interrupt enable: %08x\n",
864 I915_READ(IER));
865 seq_printf(m, "Interrupt identity: %08x\n",
866 I915_READ(IIR));
867 seq_printf(m, "Interrupt mask: %08x\n",
868 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100869 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800870 seq_printf(m, "Pipe %c stat: %08x\n",
871 pipe_name(pipe),
872 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800873 } else {
874 seq_printf(m, "North Display Interrupt enable: %08x\n",
875 I915_READ(DEIER));
876 seq_printf(m, "North Display Interrupt identity: %08x\n",
877 I915_READ(DEIIR));
878 seq_printf(m, "North Display Interrupt mask: %08x\n",
879 I915_READ(DEIMR));
880 seq_printf(m, "South Display Interrupt enable: %08x\n",
881 I915_READ(SDEIER));
882 seq_printf(m, "South Display Interrupt identity: %08x\n",
883 I915_READ(SDEIIR));
884 seq_printf(m, "South Display Interrupt mask: %08x\n",
885 I915_READ(SDEIMR));
886 seq_printf(m, "Graphics Interrupt enable: %08x\n",
887 I915_READ(GTIER));
888 seq_printf(m, "Graphics Interrupt identity: %08x\n",
889 I915_READ(GTIIR));
890 seq_printf(m, "Graphics Interrupt mask: %08x\n",
891 I915_READ(GTIMR));
892 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000893 for_each_engine(engine, dev_priv) {
David Weinehall36cdd012016-08-22 13:59:31 +0300894 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100895 seq_printf(m,
896 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000897 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000898 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000899 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000900 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200901 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100902
Ben Gamari20172632009-02-17 20:08:50 -0500903 return 0;
904}
905
Chris Wilsona6172a82009-02-11 14:26:38 +0000906static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
907{
David Weinehall36cdd012016-08-22 13:59:31 +0300908 struct drm_i915_private *dev_priv = node_to_i915(m->private);
909 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100910 int i, ret;
911
912 ret = mutex_lock_interruptible(&dev->struct_mutex);
913 if (ret)
914 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000915
Chris Wilsona6172a82009-02-11 14:26:38 +0000916 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
917 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100918 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000919
Chris Wilson6c085a72012-08-20 11:40:46 +0200920 seq_printf(m, "Fence %d, pin count = %d, object = ",
921 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100922 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100923 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100924 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100925 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100926 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000927 }
928
Chris Wilson05394f32010-11-08 19:18:58 +0000929 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000930 return 0;
931}
932
Ben Gamari20172632009-02-17 20:08:50 -0500933static int i915_hws_info(struct seq_file *m, void *data)
934{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100935 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300936 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000937 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100938 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100939 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500940
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +0000941 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000942 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500943 if (hws == NULL)
944 return 0;
945
946 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
947 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
948 i * 4,
949 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
950 }
951 return 0;
952}
953
Chris Wilson98a2f412016-10-12 10:05:18 +0100954#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
955
Daniel Vetterd5442302012-04-27 15:17:40 +0200956static ssize_t
957i915_error_state_write(struct file *filp,
958 const char __user *ubuf,
959 size_t cnt,
960 loff_t *ppos)
961{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300962 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200963
964 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100965 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200966
967 return cnt;
968}
969
970static int i915_error_state_open(struct inode *inode, struct file *file)
971{
David Weinehall36cdd012016-08-22 13:59:31 +0300972 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200973 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200974
975 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
976 if (!error_priv)
977 return -ENOMEM;
978
David Weinehall36cdd012016-08-22 13:59:31 +0300979 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200980
David Weinehall36cdd012016-08-22 13:59:31 +0300981 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200982
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300983 file->private_data = error_priv;
984
985 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200986}
987
988static int i915_error_state_release(struct inode *inode, struct file *file)
989{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300990 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200991
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300992 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200993 kfree(error_priv);
994
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300995 return 0;
996}
997
998static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
999 size_t count, loff_t *pos)
1000{
1001 struct i915_error_state_file_priv *error_priv = file->private_data;
1002 struct drm_i915_error_state_buf error_str;
1003 loff_t tmp_pos = 0;
1004 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001005 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001006
David Weinehall36cdd012016-08-22 13:59:31 +03001007 ret = i915_error_state_buf_init(&error_str,
1008 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001009 if (ret)
1010 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001011
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001012 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001013 if (ret)
1014 goto out;
1015
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001016 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1017 error_str.buf,
1018 error_str.bytes);
1019
1020 if (ret_count < 0)
1021 ret = ret_count;
1022 else
1023 *pos = error_str.start + ret_count;
1024out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001025 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001026 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001027}
1028
1029static const struct file_operations i915_error_state_fops = {
1030 .owner = THIS_MODULE,
1031 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001032 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001033 .write = i915_error_state_write,
1034 .llseek = default_llseek,
1035 .release = i915_error_state_release,
1036};
1037
Chris Wilson98a2f412016-10-12 10:05:18 +01001038#endif
1039
Kees Cook647416f2013-03-10 14:10:06 -07001040static int
1041i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001042{
David Weinehall36cdd012016-08-22 13:59:31 +03001043 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001044 int ret;
1045
David Weinehall36cdd012016-08-22 13:59:31 +03001046 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001047 if (ret)
1048 return ret;
1049
Kees Cook647416f2013-03-10 14:10:06 -07001050 *val = dev_priv->next_seqno;
David Weinehall36cdd012016-08-22 13:59:31 +03001051 mutex_unlock(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001052
Kees Cook647416f2013-03-10 14:10:06 -07001053 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001054}
1055
Kees Cook647416f2013-03-10 14:10:06 -07001056static int
1057i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001058{
David Weinehall36cdd012016-08-22 13:59:31 +03001059 struct drm_i915_private *dev_priv = data;
1060 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001061 int ret;
1062
Mika Kuoppala40633212012-12-04 15:12:00 +02001063 ret = mutex_lock_interruptible(&dev->struct_mutex);
1064 if (ret)
1065 return ret;
1066
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001067 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001068 mutex_unlock(&dev->struct_mutex);
1069
Kees Cook647416f2013-03-10 14:10:06 -07001070 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001071}
1072
Kees Cook647416f2013-03-10 14:10:06 -07001073DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1074 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001075 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001076
Deepak Sadb4bd12014-03-31 11:30:02 +05301077static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001078{
David Weinehall36cdd012016-08-22 13:59:31 +03001079 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1080 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001081 int ret = 0;
1082
1083 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001084
David Weinehall36cdd012016-08-22 13:59:31 +03001085 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001086 u16 rgvswctl = I915_READ16(MEMSWCTL);
1087 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1088
1089 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1090 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1091 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1092 MEMSTAT_VID_SHIFT);
1093 seq_printf(m, "Current P-state: %d\n",
1094 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001095 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001096 u32 freq_sts;
1097
1098 mutex_lock(&dev_priv->rps.hw_lock);
1099 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1100 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1101 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1102
1103 seq_printf(m, "actual GPU freq: %d MHz\n",
1104 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1105
1106 seq_printf(m, "current GPU freq: %d MHz\n",
1107 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1108
1109 seq_printf(m, "max GPU freq: %d MHz\n",
1110 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1111
1112 seq_printf(m, "min GPU freq: %d MHz\n",
1113 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1114
1115 seq_printf(m, "idle GPU freq: %d MHz\n",
1116 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1117
1118 seq_printf(m,
1119 "efficient (RPe) frequency: %d MHz\n",
1120 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1121 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001122 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001123 u32 rp_state_limits;
1124 u32 gt_perf_status;
1125 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001126 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001127 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001128 u32 rpupei, rpcurup, rpprevup;
1129 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001130 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001131 int max_freq;
1132
Bob Paauwe35040562015-06-25 14:54:07 -07001133 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001134 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001135 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1136 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1137 } else {
1138 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1139 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1140 }
1141
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001142 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001143 ret = mutex_lock_interruptible(&dev->struct_mutex);
1144 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001145 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001146
Mika Kuoppala59bad942015-01-16 11:34:40 +02001147 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001148
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001149 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001150 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301151 reqf >>= 23;
1152 else {
1153 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001154 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301155 reqf >>= 24;
1156 else
1157 reqf >>= 25;
1158 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001159 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001160
Chris Wilson0d8f9492014-03-27 09:06:14 +00001161 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1162 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1163 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1164
Jesse Barnesccab5c82011-01-18 15:49:25 -08001165 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301166 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1167 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1168 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1169 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1170 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1171 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001172 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301173 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001174 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001175 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1176 else
1177 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001178 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001179
Mika Kuoppala59bad942015-01-16 11:34:40 +02001180 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001181 mutex_unlock(&dev->struct_mutex);
1182
David Weinehall36cdd012016-08-22 13:59:31 +03001183 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001184 pm_ier = I915_READ(GEN6_PMIER);
1185 pm_imr = I915_READ(GEN6_PMIMR);
1186 pm_isr = I915_READ(GEN6_PMISR);
1187 pm_iir = I915_READ(GEN6_PMIIR);
1188 pm_mask = I915_READ(GEN6_PMINTRMSK);
1189 } else {
1190 pm_ier = I915_READ(GEN8_GT_IER(2));
1191 pm_imr = I915_READ(GEN8_GT_IMR(2));
1192 pm_isr = I915_READ(GEN8_GT_ISR(2));
1193 pm_iir = I915_READ(GEN8_GT_IIR(2));
1194 pm_mask = I915_READ(GEN6_PMINTRMSK);
1195 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001196 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 -03001197 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301198 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001199 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001200 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001201 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001202 seq_printf(m, "Render p-state VID: %d\n",
1203 gt_perf_status & 0xff);
1204 seq_printf(m, "Render p-state limit: %d\n",
1205 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001206 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1207 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1208 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1209 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001210 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001211 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301212 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1213 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1214 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1215 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1216 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1217 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001218 seq_printf(m, "Up threshold: %d%%\n",
1219 dev_priv->rps.up_threshold);
1220
Akash Goeld6cda9c2016-04-23 00:05:46 +05301221 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1222 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1223 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1224 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1225 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1226 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001227 seq_printf(m, "Down threshold: %d%%\n",
1228 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001229
David Weinehall36cdd012016-08-22 13:59:31 +03001230 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001231 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001232 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001233 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001234 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001235 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001236
1237 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001238 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001239 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001240 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001241 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001242
David Weinehall36cdd012016-08-22 13:59:31 +03001243 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001244 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001245 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001246 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001247 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001248 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001249 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001250 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001251
Chris Wilsond86ed342015-04-27 13:41:19 +01001252 seq_printf(m, "Current freq: %d MHz\n",
1253 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1254 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001255 seq_printf(m, "Idle freq: %d MHz\n",
1256 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001257 seq_printf(m, "Min freq: %d MHz\n",
1258 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001259 seq_printf(m, "Boost freq: %d MHz\n",
1260 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001261 seq_printf(m, "Max freq: %d MHz\n",
1262 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1263 seq_printf(m,
1264 "efficient (RPe) frequency: %d MHz\n",
1265 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001266 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001267 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001268 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001269
Mika Kahola1170f282015-09-25 14:00:32 +03001270 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1271 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1272 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1273
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001274out:
1275 intel_runtime_pm_put(dev_priv);
1276 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001277}
1278
Ben Widawskyd6369512016-09-20 16:54:32 +03001279static void i915_instdone_info(struct drm_i915_private *dev_priv,
1280 struct seq_file *m,
1281 struct intel_instdone *instdone)
1282{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001283 int slice;
1284 int subslice;
1285
Ben Widawskyd6369512016-09-20 16:54:32 +03001286 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1287 instdone->instdone);
1288
1289 if (INTEL_GEN(dev_priv) <= 3)
1290 return;
1291
1292 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1293 instdone->slice_common);
1294
1295 if (INTEL_GEN(dev_priv) <= 6)
1296 return;
1297
Ben Widawskyf9e61372016-09-20 16:54:33 +03001298 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1299 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1300 slice, subslice, instdone->sampler[slice][subslice]);
1301
1302 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1303 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1304 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001305}
1306
Chris Wilsonf6544492015-01-26 18:03:04 +02001307static int i915_hangcheck_info(struct seq_file *m, void *unused)
1308{
David Weinehall36cdd012016-08-22 13:59:31 +03001309 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001310 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001311 u64 acthd[I915_NUM_ENGINES];
1312 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001313 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001314 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001315
Chris Wilson8af29b02016-09-09 14:11:47 +01001316 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1317 seq_printf(m, "Wedged\n");
1318 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1319 seq_printf(m, "Reset in progress\n");
1320 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1321 seq_printf(m, "Waiter holding struct mutex\n");
1322 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1323 seq_printf(m, "struct_mutex blocked for reset\n");
1324
Chris Wilsonf6544492015-01-26 18:03:04 +02001325 if (!i915.enable_hangcheck) {
1326 seq_printf(m, "Hangcheck disabled\n");
1327 return 0;
1328 }
1329
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001330 intel_runtime_pm_get(dev_priv);
1331
Dave Gordonc3232b12016-03-23 18:19:53 +00001332 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001333 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001334 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001335 }
1336
Chris Wilson0e704472016-10-12 10:05:17 +01001337 intel_engine_get_instdone(&dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001338
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001339 intel_runtime_pm_put(dev_priv);
1340
Chris Wilsonf6544492015-01-26 18:03:04 +02001341 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1342 seq_printf(m, "Hangcheck active, fires in %dms\n",
1343 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1344 jiffies));
1345 } else
1346 seq_printf(m, "Hangcheck inactive\n");
1347
Dave Gordonc3232b12016-03-23 18:19:53 +00001348 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001349 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1350 struct rb_node *rb;
1351
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001352 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001353 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1354 engine->hangcheck.seqno,
1355 seqno[id],
1356 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001357 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1358 yesno(intel_engine_has_waiter(engine)),
1359 yesno(test_bit(engine->id,
1360 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilson33f53712016-10-04 21:11:32 +01001361 spin_lock(&b->lock);
1362 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1363 struct intel_wait *w = container_of(rb, typeof(*w), node);
1364
1365 seq_printf(m, "\t%s [%d] waiting for %x\n",
1366 w->tsk->comm, w->tsk->pid, w->seqno);
1367 }
1368 spin_unlock(&b->lock);
1369
Chris Wilsonf6544492015-01-26 18:03:04 +02001370 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001371 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001372 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001373 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1374 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001375
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001376 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001377 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001378
Ben Widawskyd6369512016-09-20 16:54:32 +03001379 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001380
Ben Widawskyd6369512016-09-20 16:54:32 +03001381 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001382
Ben Widawskyd6369512016-09-20 16:54:32 +03001383 i915_instdone_info(dev_priv, m,
1384 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001385 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001386 }
1387
1388 return 0;
1389}
1390
Ben Widawsky4d855292011-12-12 19:34:16 -08001391static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001392{
David Weinehall36cdd012016-08-22 13:59:31 +03001393 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1394 struct drm_device *dev = &dev_priv->drm;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001395 u32 rgvmodectl, rstdbyctl;
1396 u16 crstandvid;
1397 int ret;
1398
1399 ret = mutex_lock_interruptible(&dev->struct_mutex);
1400 if (ret)
1401 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001402 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001403
1404 rgvmodectl = I915_READ(MEMMODECTL);
1405 rstdbyctl = I915_READ(RSTDBYCTL);
1406 crstandvid = I915_READ16(CRSTANDVID);
1407
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001408 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001409 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001410
Jani Nikula742f4912015-09-03 11:16:09 +03001411 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001412 seq_printf(m, "Boost freq: %d\n",
1413 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1414 MEMMODE_BOOST_FREQ_SHIFT);
1415 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001416 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001417 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001418 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001419 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001420 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001421 seq_printf(m, "Starting frequency: P%d\n",
1422 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001423 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001424 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001425 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1426 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1427 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1428 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001429 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001430 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001431 switch (rstdbyctl & RSX_STATUS_MASK) {
1432 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001433 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001434 break;
1435 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001436 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001437 break;
1438 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001439 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001440 break;
1441 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001442 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001443 break;
1444 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001445 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001446 break;
1447 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001448 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001449 break;
1450 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001451 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001452 break;
1453 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001454
1455 return 0;
1456}
1457
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001458static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001459{
David Weinehall36cdd012016-08-22 13:59:31 +03001460 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001461 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001462
1463 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001464 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001465 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001466 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001467 fw_domain->wake_count);
1468 }
1469 spin_unlock_irq(&dev_priv->uncore.lock);
1470
1471 return 0;
1472}
1473
Deepak S669ab5a2014-01-10 15:18:26 +05301474static int vlv_drpc_info(struct seq_file *m)
1475{
David Weinehall36cdd012016-08-22 13:59:31 +03001476 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001477 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301478
Imre Deakd46c0512014-04-14 20:24:27 +03001479 intel_runtime_pm_get(dev_priv);
1480
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001481 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301482 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1483 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1484
Imre Deakd46c0512014-04-14 20:24:27 +03001485 intel_runtime_pm_put(dev_priv);
1486
Deepak S669ab5a2014-01-10 15:18:26 +05301487 seq_printf(m, "Video Turbo Mode: %s\n",
1488 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1489 seq_printf(m, "Turbo enabled: %s\n",
1490 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1491 seq_printf(m, "HW control enabled: %s\n",
1492 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1493 seq_printf(m, "SW control enabled: %s\n",
1494 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1495 GEN6_RP_MEDIA_SW_MODE));
1496 seq_printf(m, "RC6 Enabled: %s\n",
1497 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1498 GEN6_RC_CTL_EI_MODE(1))));
1499 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001500 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301501 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001502 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301503
Imre Deak9cc19be2014-04-14 20:24:24 +03001504 seq_printf(m, "Render RC6 residency since boot: %u\n",
1505 I915_READ(VLV_GT_RENDER_RC6));
1506 seq_printf(m, "Media RC6 residency since boot: %u\n",
1507 I915_READ(VLV_GT_MEDIA_RC6));
1508
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001509 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301510}
1511
Ben Widawsky4d855292011-12-12 19:34:16 -08001512static int gen6_drpc_info(struct seq_file *m)
1513{
David Weinehall36cdd012016-08-22 13:59:31 +03001514 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1515 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001516 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301517 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001518 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001519 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001520
1521 ret = mutex_lock_interruptible(&dev->struct_mutex);
1522 if (ret)
1523 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001524 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001525
Chris Wilson907b28c2013-07-19 20:36:52 +01001526 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001527 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001528 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001529
1530 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001531 seq_puts(m, "RC information inaccurate because somebody "
1532 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001533 } else {
1534 /* NB: we cannot use forcewake, else we read the wrong values */
1535 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1536 udelay(10);
1537 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1538 }
1539
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001540 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001541 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001542
1543 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1544 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001545 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301546 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1547 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1548 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001549 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001550 mutex_lock(&dev_priv->rps.hw_lock);
1551 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1552 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001553
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001554 intel_runtime_pm_put(dev_priv);
1555
Ben Widawsky4d855292011-12-12 19:34:16 -08001556 seq_printf(m, "Video Turbo Mode: %s\n",
1557 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1558 seq_printf(m, "HW control enabled: %s\n",
1559 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1560 seq_printf(m, "SW control enabled: %s\n",
1561 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1562 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001563 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001564 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1565 seq_printf(m, "RC6 Enabled: %s\n",
1566 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001567 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301568 seq_printf(m, "Render Well Gating Enabled: %s\n",
1569 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1570 seq_printf(m, "Media Well Gating Enabled: %s\n",
1571 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1572 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001573 seq_printf(m, "Deep RC6 Enabled: %s\n",
1574 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1575 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1576 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001577 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001578 switch (gt_core_status & GEN6_RCn_MASK) {
1579 case GEN6_RC0:
1580 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001581 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001582 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001583 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001584 break;
1585 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001586 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 break;
1588 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001589 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001590 break;
1591 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001592 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 break;
1594 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001596 break;
1597 }
1598
1599 seq_printf(m, "Core Power Down: %s\n",
1600 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001601 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301602 seq_printf(m, "Render Power Well: %s\n",
1603 (gen9_powergate_status &
1604 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1605 seq_printf(m, "Media Power Well: %s\n",
1606 (gen9_powergate_status &
1607 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1608 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001609
1610 /* Not exactly sure what this is */
1611 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1612 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1613 seq_printf(m, "RC6 residency since boot: %u\n",
1614 I915_READ(GEN6_GT_GFX_RC6));
1615 seq_printf(m, "RC6+ residency since boot: %u\n",
1616 I915_READ(GEN6_GT_GFX_RC6p));
1617 seq_printf(m, "RC6++ residency since boot: %u\n",
1618 I915_READ(GEN6_GT_GFX_RC6pp));
1619
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001620 seq_printf(m, "RC6 voltage: %dmV\n",
1621 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1622 seq_printf(m, "RC6+ voltage: %dmV\n",
1623 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1624 seq_printf(m, "RC6++ voltage: %dmV\n",
1625 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301626 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001627}
1628
1629static int i915_drpc_info(struct seq_file *m, void *unused)
1630{
David Weinehall36cdd012016-08-22 13:59:31 +03001631 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001632
David Weinehall36cdd012016-08-22 13:59:31 +03001633 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301634 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001635 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001636 return gen6_drpc_info(m);
1637 else
1638 return ironlake_drpc_info(m);
1639}
1640
Daniel Vetter9a851782015-06-18 10:30:22 +02001641static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1642{
David Weinehall36cdd012016-08-22 13:59:31 +03001643 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001644
1645 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1646 dev_priv->fb_tracking.busy_bits);
1647
1648 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1649 dev_priv->fb_tracking.flip_bits);
1650
1651 return 0;
1652}
1653
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001654static int i915_fbc_status(struct seq_file *m, void *unused)
1655{
David Weinehall36cdd012016-08-22 13:59:31 +03001656 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001657
David Weinehall36cdd012016-08-22 13:59:31 +03001658 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001659 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001660 return 0;
1661 }
1662
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001663 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001664 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001665
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001666 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001667 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001668 else
1669 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001670 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001671
Nagaraju, Vathsalabc4ec7c2016-09-22 14:19:53 +05301672 if (intel_fbc_is_active(dev_priv) &&
1673 INTEL_GEN(dev_priv) >= 7)
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001674 seq_printf(m, "Compressing: %s\n",
1675 yesno(I915_READ(FBC_STATUS2) &
1676 FBC_COMPRESSION_MASK));
1677
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001678 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001679 intel_runtime_pm_put(dev_priv);
1680
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001681 return 0;
1682}
1683
Rodrigo Vivida46f932014-08-01 02:04:45 -07001684static int i915_fbc_fc_get(void *data, u64 *val)
1685{
David Weinehall36cdd012016-08-22 13:59:31 +03001686 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001687
David Weinehall36cdd012016-08-22 13:59:31 +03001688 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001689 return -ENODEV;
1690
Rodrigo Vivida46f932014-08-01 02:04:45 -07001691 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001692
1693 return 0;
1694}
1695
1696static int i915_fbc_fc_set(void *data, u64 val)
1697{
David Weinehall36cdd012016-08-22 13:59:31 +03001698 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001699 u32 reg;
1700
David Weinehall36cdd012016-08-22 13:59:31 +03001701 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001702 return -ENODEV;
1703
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001704 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001705
1706 reg = I915_READ(ILK_DPFC_CONTROL);
1707 dev_priv->fbc.false_color = val;
1708
1709 I915_WRITE(ILK_DPFC_CONTROL, val ?
1710 (reg | FBC_CTL_FALSE_COLOR) :
1711 (reg & ~FBC_CTL_FALSE_COLOR));
1712
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001713 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001714 return 0;
1715}
1716
1717DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1718 i915_fbc_fc_get, i915_fbc_fc_set,
1719 "%llu\n");
1720
Paulo Zanoni92d44622013-05-31 16:33:24 -03001721static int i915_ips_status(struct seq_file *m, void *unused)
1722{
David Weinehall36cdd012016-08-22 13:59:31 +03001723 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001724
David Weinehall36cdd012016-08-22 13:59:31 +03001725 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001726 seq_puts(m, "not supported\n");
1727 return 0;
1728 }
1729
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001730 intel_runtime_pm_get(dev_priv);
1731
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001732 seq_printf(m, "Enabled by kernel parameter: %s\n",
1733 yesno(i915.enable_ips));
1734
David Weinehall36cdd012016-08-22 13:59:31 +03001735 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001736 seq_puts(m, "Currently: unknown\n");
1737 } else {
1738 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1739 seq_puts(m, "Currently: enabled\n");
1740 else
1741 seq_puts(m, "Currently: disabled\n");
1742 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001743
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001744 intel_runtime_pm_put(dev_priv);
1745
Paulo Zanoni92d44622013-05-31 16:33:24 -03001746 return 0;
1747}
1748
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001749static int i915_sr_status(struct seq_file *m, void *unused)
1750{
David Weinehall36cdd012016-08-22 13:59:31 +03001751 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001752 bool sr_enabled = false;
1753
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001754 intel_runtime_pm_get(dev_priv);
1755
David Weinehall36cdd012016-08-22 13:59:31 +03001756 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001757 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001758 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1759 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001760 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001761 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001762 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001763 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001764 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001765 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001766 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001767
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001768 intel_runtime_pm_put(dev_priv);
1769
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001770 seq_printf(m, "self-refresh: %s\n",
1771 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001772
1773 return 0;
1774}
1775
Jesse Barnes7648fa92010-05-20 14:28:11 -07001776static int i915_emon_status(struct seq_file *m, void *unused)
1777{
David Weinehall36cdd012016-08-22 13:59:31 +03001778 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1779 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001780 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001781 int ret;
1782
David Weinehall36cdd012016-08-22 13:59:31 +03001783 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001784 return -ENODEV;
1785
Chris Wilsonde227ef2010-07-03 07:58:38 +01001786 ret = mutex_lock_interruptible(&dev->struct_mutex);
1787 if (ret)
1788 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001789
1790 temp = i915_mch_val(dev_priv);
1791 chipset = i915_chipset_val(dev_priv);
1792 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001793 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001794
1795 seq_printf(m, "GMCH temp: %ld\n", temp);
1796 seq_printf(m, "Chipset power: %ld\n", chipset);
1797 seq_printf(m, "GFX power: %ld\n", gfx);
1798 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1799
1800 return 0;
1801}
1802
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001803static int i915_ring_freq_table(struct seq_file *m, void *unused)
1804{
David Weinehall36cdd012016-08-22 13:59:31 +03001805 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001806 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001807 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301808 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001809
Carlos Santa26310342016-08-17 12:30:41 -07001810 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001811 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001812 return 0;
1813 }
1814
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001815 intel_runtime_pm_get(dev_priv);
1816
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001817 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001818 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001819 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001820
David Weinehall36cdd012016-08-22 13:59:31 +03001821 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301822 /* Convert GT frequency to 50 HZ units */
1823 min_gpu_freq =
1824 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1825 max_gpu_freq =
1826 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1827 } else {
1828 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1829 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1830 }
1831
Damien Lespiau267f0c92013-06-24 22:59:48 +01001832 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001833
Akash Goelf936ec32015-06-29 14:50:22 +05301834 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001835 ia_freq = gpu_freq;
1836 sandybridge_pcode_read(dev_priv,
1837 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1838 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001839 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301840 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001841 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001842 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001843 ((ia_freq >> 0) & 0xff) * 100,
1844 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001845 }
1846
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001847 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001848
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001849out:
1850 intel_runtime_pm_put(dev_priv);
1851 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001852}
1853
Chris Wilson44834a62010-08-19 16:09:23 +01001854static int i915_opregion(struct seq_file *m, void *unused)
1855{
David Weinehall36cdd012016-08-22 13:59:31 +03001856 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1857 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001858 struct intel_opregion *opregion = &dev_priv->opregion;
1859 int ret;
1860
1861 ret = mutex_lock_interruptible(&dev->struct_mutex);
1862 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001863 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001864
Jani Nikula2455a8e2015-12-14 12:50:53 +02001865 if (opregion->header)
1866 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001867
1868 mutex_unlock(&dev->struct_mutex);
1869
Daniel Vetter0d38f002012-04-21 22:49:10 +02001870out:
Chris Wilson44834a62010-08-19 16:09:23 +01001871 return 0;
1872}
1873
Jani Nikulaada8f952015-12-15 13:17:12 +02001874static int i915_vbt(struct seq_file *m, void *unused)
1875{
David Weinehall36cdd012016-08-22 13:59:31 +03001876 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001877
1878 if (opregion->vbt)
1879 seq_write(m, opregion->vbt, opregion->vbt_size);
1880
1881 return 0;
1882}
1883
Chris Wilson37811fc2010-08-25 22:45:57 +01001884static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1885{
David Weinehall36cdd012016-08-22 13:59:31 +03001886 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1887 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301888 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001889 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001890 int ret;
1891
1892 ret = mutex_lock_interruptible(&dev->struct_mutex);
1893 if (ret)
1894 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001895
Daniel Vetter06957262015-08-10 13:34:08 +02001896#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001897 if (dev_priv->fbdev) {
1898 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001899
Chris Wilson25bcce92016-07-02 15:36:00 +01001900 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1901 fbdev_fb->base.width,
1902 fbdev_fb->base.height,
1903 fbdev_fb->base.depth,
1904 fbdev_fb->base.bits_per_pixel,
1905 fbdev_fb->base.modifier[0],
1906 drm_framebuffer_read_refcount(&fbdev_fb->base));
1907 describe_obj(m, fbdev_fb->obj);
1908 seq_putc(m, '\n');
1909 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001910#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001911
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001912 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001913 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301914 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1915 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001916 continue;
1917
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001918 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 +01001919 fb->base.width,
1920 fb->base.height,
1921 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001922 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001923 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001924 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001925 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001926 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001927 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001928 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001929 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001930
1931 return 0;
1932}
1933
Chris Wilson7e37f882016-08-02 22:50:21 +01001934static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001935{
1936 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001937 ring->space, ring->head, ring->tail,
1938 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001939}
1940
Ben Widawskye76d3632011-03-19 18:14:29 -07001941static int i915_context_status(struct seq_file *m, void *unused)
1942{
David Weinehall36cdd012016-08-22 13:59:31 +03001943 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1944 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001945 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001946 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00001947 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001948
Daniel Vetterf3d28872014-05-29 23:23:08 +02001949 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001950 if (ret)
1951 return ret;
1952
Ben Widawskya33afea2013-09-17 21:12:45 -07001953 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001954 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001955 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001956 struct task_struct *task;
1957
Chris Wilsonc84455b2016-08-15 10:49:08 +01001958 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001959 if (task) {
1960 seq_printf(m, "(%s [%d]) ",
1961 task->comm, task->pid);
1962 put_task_struct(task);
1963 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001964 } else if (IS_ERR(ctx->file_priv)) {
1965 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001966 } else {
1967 seq_puts(m, "(kernel) ");
1968 }
1969
Chris Wilsonbca44d82016-05-24 14:53:41 +01001970 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1971 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001972
Chris Wilsonbca44d82016-05-24 14:53:41 +01001973 for_each_engine(engine, dev_priv) {
1974 struct intel_context *ce = &ctx->engine[engine->id];
1975
1976 seq_printf(m, "%s: ", engine->name);
1977 seq_putc(m, ce->initialised ? 'I' : 'i');
1978 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001979 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001980 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001981 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001982 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001983 }
1984
Ben Widawskya33afea2013-09-17 21:12:45 -07001985 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001986 }
1987
Daniel Vetterf3d28872014-05-29 23:23:08 +02001988 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001989
1990 return 0;
1991}
1992
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001993static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001994 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001995 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001996{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001997 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001998 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001999 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002000
Chris Wilson7069b142016-04-28 09:56:52 +01002001 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2002
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002003 if (!vma) {
2004 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002005 return;
2006 }
2007
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002008 if (vma->flags & I915_VMA_GLOBAL_BIND)
2009 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002010 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002011
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002012 if (i915_gem_object_get_pages(vma->obj)) {
2013 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002014 return;
2015 }
2016
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002017 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2018 if (page) {
2019 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002020
2021 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002022 seq_printf(m,
2023 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2024 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002025 reg_state[j], reg_state[j + 1],
2026 reg_state[j + 2], reg_state[j + 3]);
2027 }
2028 kunmap_atomic(reg_state);
2029 }
2030
2031 seq_putc(m, '\n');
2032}
2033
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002034static int i915_dump_lrc(struct seq_file *m, void *unused)
2035{
David Weinehall36cdd012016-08-22 13:59:31 +03002036 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2037 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002038 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002039 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002040 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002041
2042 if (!i915.enable_execlists) {
2043 seq_printf(m, "Logical Ring Contexts are disabled\n");
2044 return 0;
2045 }
2046
2047 ret = mutex_lock_interruptible(&dev->struct_mutex);
2048 if (ret)
2049 return ret;
2050
Dave Gordone28e4042016-01-19 19:02:55 +00002051 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002052 for_each_engine(engine, dev_priv)
2053 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002054
2055 mutex_unlock(&dev->struct_mutex);
2056
2057 return 0;
2058}
2059
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002060static const char *swizzle_string(unsigned swizzle)
2061{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002062 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002063 case I915_BIT_6_SWIZZLE_NONE:
2064 return "none";
2065 case I915_BIT_6_SWIZZLE_9:
2066 return "bit9";
2067 case I915_BIT_6_SWIZZLE_9_10:
2068 return "bit9/bit10";
2069 case I915_BIT_6_SWIZZLE_9_11:
2070 return "bit9/bit11";
2071 case I915_BIT_6_SWIZZLE_9_10_11:
2072 return "bit9/bit10/bit11";
2073 case I915_BIT_6_SWIZZLE_9_17:
2074 return "bit9/bit17";
2075 case I915_BIT_6_SWIZZLE_9_10_17:
2076 return "bit9/bit10/bit17";
2077 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002078 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002079 }
2080
2081 return "bug";
2082}
2083
2084static int i915_swizzle_info(struct seq_file *m, void *data)
2085{
David Weinehall36cdd012016-08-22 13:59:31 +03002086 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2087 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002088 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002089
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002090 ret = mutex_lock_interruptible(&dev->struct_mutex);
2091 if (ret)
2092 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002093 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002094
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002095 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2096 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2097 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2098 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2099
David Weinehall36cdd012016-08-22 13:59:31 +03002100 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002101 seq_printf(m, "DDC = 0x%08x\n",
2102 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002103 seq_printf(m, "DDC2 = 0x%08x\n",
2104 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002105 seq_printf(m, "C0DRB3 = 0x%04x\n",
2106 I915_READ16(C0DRB3));
2107 seq_printf(m, "C1DRB3 = 0x%04x\n",
2108 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002109 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002110 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2111 I915_READ(MAD_DIMM_C0));
2112 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2113 I915_READ(MAD_DIMM_C1));
2114 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2115 I915_READ(MAD_DIMM_C2));
2116 seq_printf(m, "TILECTL = 0x%08x\n",
2117 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002118 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002119 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2120 I915_READ(GAMTARBMODE));
2121 else
2122 seq_printf(m, "ARB_MODE = 0x%08x\n",
2123 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002124 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2125 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002126 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002127
2128 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2129 seq_puts(m, "L-shaped memory detected\n");
2130
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002131 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002132 mutex_unlock(&dev->struct_mutex);
2133
2134 return 0;
2135}
2136
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002137static int per_file_ctx(int id, void *ptr, void *data)
2138{
Chris Wilsone2efd132016-05-24 14:53:34 +01002139 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002140 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002141 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2142
2143 if (!ppgtt) {
2144 seq_printf(m, " no ppgtt for context %d\n",
2145 ctx->user_handle);
2146 return 0;
2147 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002148
Oscar Mateof83d6512014-05-22 14:13:38 +01002149 if (i915_gem_context_is_default(ctx))
2150 seq_puts(m, " default context:\n");
2151 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002152 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002153 ppgtt->debug_dump(ppgtt, m);
2154
2155 return 0;
2156}
2157
David Weinehall36cdd012016-08-22 13:59:31 +03002158static void gen8_ppgtt_info(struct seq_file *m,
2159 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002160{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002161 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002162 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002163 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002164
Ben Widawsky77df6772013-11-02 21:07:30 -07002165 if (!ppgtt)
2166 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002167
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002168 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002169 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002170 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002171 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002172 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002173 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002174 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002175 }
2176 }
2177}
2178
David Weinehall36cdd012016-08-22 13:59:31 +03002179static void gen6_ppgtt_info(struct seq_file *m,
2180 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002181{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002182 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002183
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002184 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002185 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2186
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002187 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002188 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002189 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002190 seq_printf(m, "GFX_MODE: 0x%08x\n",
2191 I915_READ(RING_MODE_GEN7(engine)));
2192 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2193 I915_READ(RING_PP_DIR_BASE(engine)));
2194 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2195 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2196 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2197 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002198 }
2199 if (dev_priv->mm.aliasing_ppgtt) {
2200 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2201
Damien Lespiau267f0c92013-06-24 22:59:48 +01002202 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002203 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002204
Ben Widawsky87d60b62013-12-06 14:11:29 -08002205 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002206 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002207
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002208 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002209}
2210
2211static int i915_ppgtt_info(struct seq_file *m, void *data)
2212{
David Weinehall36cdd012016-08-22 13:59:31 +03002213 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2214 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002215 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002216 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002217
Chris Wilson637ee292016-08-22 14:28:20 +01002218 mutex_lock(&dev->filelist_mutex);
2219 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002220 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002221 goto out_unlock;
2222
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002223 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002224
David Weinehall36cdd012016-08-22 13:59:31 +03002225 if (INTEL_GEN(dev_priv) >= 8)
2226 gen8_ppgtt_info(m, dev_priv);
2227 else if (INTEL_GEN(dev_priv) >= 6)
2228 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002229
Michel Thierryea91e402015-07-29 17:23:57 +01002230 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2231 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002232 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002233
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002234 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002235 if (!task) {
2236 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002237 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002238 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002239 seq_printf(m, "\nproc: %s\n", task->comm);
2240 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002241 idr_for_each(&file_priv->context_idr, per_file_ctx,
2242 (void *)(unsigned long)m);
2243 }
2244
Chris Wilson637ee292016-08-22 14:28:20 +01002245out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002246 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002247 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002248out_unlock:
2249 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002250 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002251}
2252
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002253static int count_irq_waiters(struct drm_i915_private *i915)
2254{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002255 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002256 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002257
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002258 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002259 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002260
2261 return count;
2262}
2263
Chris Wilson7466c292016-08-15 09:49:33 +01002264static const char *rps_power_to_str(unsigned int power)
2265{
2266 static const char * const strings[] = {
2267 [LOW_POWER] = "low power",
2268 [BETWEEN] = "mixed",
2269 [HIGH_POWER] = "high power",
2270 };
2271
2272 if (power >= ARRAY_SIZE(strings) || !strings[power])
2273 return "unknown";
2274
2275 return strings[power];
2276}
2277
Chris Wilson1854d5c2015-04-07 16:20:32 +01002278static int i915_rps_boost_info(struct seq_file *m, void *data)
2279{
David Weinehall36cdd012016-08-22 13:59:31 +03002280 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2281 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002282 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002283
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002284 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002285 seq_printf(m, "GPU busy? %s [%x]\n",
2286 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002287 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002288 seq_printf(m, "Frequency requested %d\n",
2289 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2290 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002291 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2292 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2293 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2294 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002295 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2296 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2297 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2298 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002299
2300 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002301 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002302 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2303 struct drm_i915_file_private *file_priv = file->driver_priv;
2304 struct task_struct *task;
2305
2306 rcu_read_lock();
2307 task = pid_task(file->pid, PIDTYPE_PID);
2308 seq_printf(m, "%s [%d]: %d boosts%s\n",
2309 task ? task->comm : "<unknown>",
2310 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002311 file_priv->rps.boosts,
2312 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002313 rcu_read_unlock();
2314 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002315 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002316 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002317 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002318
Chris Wilson7466c292016-08-15 09:49:33 +01002319 if (INTEL_GEN(dev_priv) >= 6 &&
2320 dev_priv->rps.enabled &&
2321 dev_priv->gt.active_engines) {
2322 u32 rpup, rpupei;
2323 u32 rpdown, rpdownei;
2324
2325 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2326 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2327 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2328 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2329 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2330 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2331
2332 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2333 rps_power_to_str(dev_priv->rps.power));
2334 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2335 100 * rpup / rpupei,
2336 dev_priv->rps.up_threshold);
2337 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2338 100 * rpdown / rpdownei,
2339 dev_priv->rps.down_threshold);
2340 } else {
2341 seq_puts(m, "\nRPS Autotuning inactive\n");
2342 }
2343
Chris Wilson8d3afd72015-05-21 21:01:47 +01002344 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002345}
2346
Ben Widawsky63573eb2013-07-04 11:02:07 -07002347static int i915_llc(struct seq_file *m, void *data)
2348{
David Weinehall36cdd012016-08-22 13:59:31 +03002349 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002350 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002351
David Weinehall36cdd012016-08-22 13:59:31 +03002352 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002353 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2354 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002355
2356 return 0;
2357}
2358
Alex Daifdf5d352015-08-12 15:43:37 +01002359static int i915_guc_load_status_info(struct seq_file *m, void *data)
2360{
David Weinehall36cdd012016-08-22 13:59:31 +03002361 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002362 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2363 u32 tmp, i;
2364
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002365 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002366 return 0;
2367
2368 seq_printf(m, "GuC firmware status:\n");
2369 seq_printf(m, "\tpath: %s\n",
2370 guc_fw->guc_fw_path);
2371 seq_printf(m, "\tfetch: %s\n",
2372 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2373 seq_printf(m, "\tload: %s\n",
2374 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2375 seq_printf(m, "\tversion wanted: %d.%d\n",
2376 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2377 seq_printf(m, "\tversion found: %d.%d\n",
2378 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002379 seq_printf(m, "\theader: offset is %d; size = %d\n",
2380 guc_fw->header_offset, guc_fw->header_size);
2381 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2382 guc_fw->ucode_offset, guc_fw->ucode_size);
2383 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2384 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002385
2386 tmp = I915_READ(GUC_STATUS);
2387
2388 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2389 seq_printf(m, "\tBootrom status = 0x%x\n",
2390 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2391 seq_printf(m, "\tuKernel status = 0x%x\n",
2392 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2393 seq_printf(m, "\tMIA Core status = 0x%x\n",
2394 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2395 seq_puts(m, "\nScratch registers:\n");
2396 for (i = 0; i < 16; i++)
2397 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2398
2399 return 0;
2400}
2401
Dave Gordon8b417c22015-08-12 15:43:44 +01002402static void i915_guc_client_info(struct seq_file *m,
2403 struct drm_i915_private *dev_priv,
2404 struct i915_guc_client *client)
2405{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002406 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002407 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002408 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002409
2410 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2411 client->priority, client->ctx_index, client->proc_desc_offset);
2412 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2413 client->doorbell_id, client->doorbell_offset, client->cookie);
2414 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2415 client->wq_size, client->wq_offset, client->wq_tail);
2416
Dave Gordon551aaec2016-05-13 15:36:33 +01002417 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002418 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2419 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2420
Dave Gordonc18468c2016-08-09 15:19:22 +01002421 for_each_engine_id(engine, dev_priv, id) {
2422 u64 submissions = client->submissions[id];
2423 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002424 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002425 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002426 }
2427 seq_printf(m, "\tTotal: %llu\n", tot);
2428}
2429
2430static int i915_guc_info(struct seq_file *m, void *data)
2431{
David Weinehall36cdd012016-08-22 13:59:31 +03002432 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2433 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002434 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002435 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002436 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002437 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002438 u64 total = 0;
2439
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002440 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002441 return 0;
2442
Alex Dai5a843302015-12-02 16:56:29 -08002443 if (mutex_lock_interruptible(&dev->struct_mutex))
2444 return 0;
2445
Dave Gordon8b417c22015-08-12 15:43:44 +01002446 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002447 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002448 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002449 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002450
2451 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002452
Dave Gordon9636f6d2016-06-13 17:57:28 +01002453 seq_printf(m, "Doorbell map:\n");
2454 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2455 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2456
Dave Gordon8b417c22015-08-12 15:43:44 +01002457 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2458 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2459 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2460 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2461 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2462
2463 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonc18468c2016-08-09 15:19:22 +01002464 for_each_engine_id(engine, dev_priv, id) {
2465 u64 submissions = guc.submissions[id];
2466 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002467 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002468 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002469 }
2470 seq_printf(m, "\t%s: %llu\n", "Total", total);
2471
2472 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2473 i915_guc_client_info(m, dev_priv, &client);
2474
2475 /* Add more as required ... */
2476
2477 return 0;
2478}
2479
Alex Dai4c7e77f2015-08-12 15:43:40 +01002480static int i915_guc_log_dump(struct seq_file *m, void *data)
2481{
David Weinehall36cdd012016-08-22 13:59:31 +03002482 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002483 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002484 int i = 0, pg;
2485
Chris Wilson8b797af2016-08-15 10:48:51 +01002486 if (!dev_priv->guc.log_vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002487 return 0;
2488
Chris Wilson8b797af2016-08-15 10:48:51 +01002489 obj = dev_priv->guc.log_vma->obj;
2490 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2491 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002492
2493 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2494 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2495 *(log + i), *(log + i + 1),
2496 *(log + i + 2), *(log + i + 3));
2497
2498 kunmap_atomic(log);
2499 }
2500
2501 seq_putc(m, '\n');
2502
2503 return 0;
2504}
2505
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002506static int i915_edp_psr_status(struct seq_file *m, void *data)
2507{
David Weinehall36cdd012016-08-22 13:59:31 +03002508 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002509 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002510 u32 stat[3];
2511 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002512 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002513
David Weinehall36cdd012016-08-22 13:59:31 +03002514 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002515 seq_puts(m, "PSR not supported\n");
2516 return 0;
2517 }
2518
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002519 intel_runtime_pm_get(dev_priv);
2520
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002521 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002522 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2523 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002524 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002525 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002526 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2527 dev_priv->psr.busy_frontbuffer_bits);
2528 seq_printf(m, "Re-enable work scheduled: %s\n",
2529 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002530
David Weinehall36cdd012016-08-22 13:59:31 +03002531 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002532 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002533 else {
2534 for_each_pipe(dev_priv, pipe) {
2535 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2536 VLV_EDP_PSR_CURR_STATE_MASK;
2537 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2538 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2539 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002540 }
2541 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002542
2543 seq_printf(m, "Main link in standby mode: %s\n",
2544 yesno(dev_priv->psr.link_standby));
2545
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002546 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002547
David Weinehall36cdd012016-08-22 13:59:31 +03002548 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002549 for_each_pipe(dev_priv, pipe) {
2550 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2551 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2552 seq_printf(m, " pipe %c", pipe_name(pipe));
2553 }
2554 seq_puts(m, "\n");
2555
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002556 /*
2557 * VLV/CHV PSR has no kind of performance counter
2558 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2559 */
David Weinehall36cdd012016-08-22 13:59:31 +03002560 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002561 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002562 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002563
2564 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2565 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002566 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002567
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002568 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002569 return 0;
2570}
2571
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002572static int i915_sink_crc(struct seq_file *m, void *data)
2573{
David Weinehall36cdd012016-08-22 13:59:31 +03002574 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2575 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002576 struct intel_connector *connector;
2577 struct intel_dp *intel_dp = NULL;
2578 int ret;
2579 u8 crc[6];
2580
2581 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002582 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002583 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002584
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002585 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002586 continue;
2587
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002588 crtc = connector->base.state->crtc;
2589 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002590 continue;
2591
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002592 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002593 continue;
2594
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002595 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002596
2597 ret = intel_dp_sink_crc(intel_dp, crc);
2598 if (ret)
2599 goto out;
2600
2601 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2602 crc[0], crc[1], crc[2],
2603 crc[3], crc[4], crc[5]);
2604 goto out;
2605 }
2606 ret = -ENODEV;
2607out:
2608 drm_modeset_unlock_all(dev);
2609 return ret;
2610}
2611
Jesse Barnesec013e72013-08-20 10:29:23 +01002612static int i915_energy_uJ(struct seq_file *m, void *data)
2613{
David Weinehall36cdd012016-08-22 13:59:31 +03002614 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002615 u64 power;
2616 u32 units;
2617
David Weinehall36cdd012016-08-22 13:59:31 +03002618 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002619 return -ENODEV;
2620
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002621 intel_runtime_pm_get(dev_priv);
2622
Jesse Barnesec013e72013-08-20 10:29:23 +01002623 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2624 power = (power & 0x1f00) >> 8;
2625 units = 1000000 / (1 << power); /* convert to uJ */
2626 power = I915_READ(MCH_SECP_NRG_STTS);
2627 power *= units;
2628
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002629 intel_runtime_pm_put(dev_priv);
2630
Jesse Barnesec013e72013-08-20 10:29:23 +01002631 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002632
2633 return 0;
2634}
2635
Damien Lespiau6455c872015-06-04 18:23:57 +01002636static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002637{
David Weinehall36cdd012016-08-22 13:59:31 +03002638 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002639 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002640
Chris Wilsona156e642016-04-03 14:14:21 +01002641 if (!HAS_RUNTIME_PM(dev_priv))
2642 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002643
Chris Wilson67d97da2016-07-04 08:08:31 +01002644 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002645 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002646 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002647#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002648 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002649 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002650#else
2651 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2652#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002653 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002654 pci_power_name(pdev->current_state),
2655 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002656
Jesse Barnesec013e72013-08-20 10:29:23 +01002657 return 0;
2658}
2659
Imre Deak1da51582013-11-25 17:15:35 +02002660static int i915_power_domain_info(struct seq_file *m, void *unused)
2661{
David Weinehall36cdd012016-08-22 13:59:31 +03002662 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002663 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2664 int i;
2665
2666 mutex_lock(&power_domains->lock);
2667
2668 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2669 for (i = 0; i < power_domains->power_well_count; i++) {
2670 struct i915_power_well *power_well;
2671 enum intel_display_power_domain power_domain;
2672
2673 power_well = &power_domains->power_wells[i];
2674 seq_printf(m, "%-25s %d\n", power_well->name,
2675 power_well->count);
2676
2677 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2678 power_domain++) {
2679 if (!(BIT(power_domain) & power_well->domains))
2680 continue;
2681
2682 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002683 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002684 power_domains->domain_use_count[power_domain]);
2685 }
2686 }
2687
2688 mutex_unlock(&power_domains->lock);
2689
2690 return 0;
2691}
2692
Damien Lespiaub7cec662015-10-27 14:47:01 +02002693static int i915_dmc_info(struct seq_file *m, void *unused)
2694{
David Weinehall36cdd012016-08-22 13:59:31 +03002695 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002696 struct intel_csr *csr;
2697
David Weinehall36cdd012016-08-22 13:59:31 +03002698 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002699 seq_puts(m, "not supported\n");
2700 return 0;
2701 }
2702
2703 csr = &dev_priv->csr;
2704
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002705 intel_runtime_pm_get(dev_priv);
2706
Damien Lespiaub7cec662015-10-27 14:47:01 +02002707 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2708 seq_printf(m, "path: %s\n", csr->fw_path);
2709
2710 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002711 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002712
2713 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2714 CSR_VERSION_MINOR(csr->version));
2715
David Weinehall36cdd012016-08-22 13:59:31 +03002716 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002717 seq_printf(m, "DC3 -> DC5 count: %d\n",
2718 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2719 seq_printf(m, "DC5 -> DC6 count: %d\n",
2720 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002721 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002722 seq_printf(m, "DC3 -> DC5 count: %d\n",
2723 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002724 }
2725
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002726out:
2727 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2728 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2729 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2730
Damien Lespiau83372062015-10-30 17:53:32 +02002731 intel_runtime_pm_put(dev_priv);
2732
Damien Lespiaub7cec662015-10-27 14:47:01 +02002733 return 0;
2734}
2735
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002736static void intel_seq_print_mode(struct seq_file *m, int tabs,
2737 struct drm_display_mode *mode)
2738{
2739 int i;
2740
2741 for (i = 0; i < tabs; i++)
2742 seq_putc(m, '\t');
2743
2744 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",
2745 mode->base.id, mode->name,
2746 mode->vrefresh, mode->clock,
2747 mode->hdisplay, mode->hsync_start,
2748 mode->hsync_end, mode->htotal,
2749 mode->vdisplay, mode->vsync_start,
2750 mode->vsync_end, mode->vtotal,
2751 mode->type, mode->flags);
2752}
2753
2754static void intel_encoder_info(struct seq_file *m,
2755 struct intel_crtc *intel_crtc,
2756 struct intel_encoder *intel_encoder)
2757{
David Weinehall36cdd012016-08-22 13:59:31 +03002758 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2759 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002760 struct drm_crtc *crtc = &intel_crtc->base;
2761 struct intel_connector *intel_connector;
2762 struct drm_encoder *encoder;
2763
2764 encoder = &intel_encoder->base;
2765 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002766 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002767 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2768 struct drm_connector *connector = &intel_connector->base;
2769 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2770 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002771 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002772 drm_get_connector_status_name(connector->status));
2773 if (connector->status == connector_status_connected) {
2774 struct drm_display_mode *mode = &crtc->mode;
2775 seq_printf(m, ", mode:\n");
2776 intel_seq_print_mode(m, 2, mode);
2777 } else {
2778 seq_putc(m, '\n');
2779 }
2780 }
2781}
2782
2783static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2784{
David Weinehall36cdd012016-08-22 13:59:31 +03002785 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2786 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002787 struct drm_crtc *crtc = &intel_crtc->base;
2788 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002789 struct drm_plane_state *plane_state = crtc->primary->state;
2790 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002791
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002792 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002793 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002794 fb->base.id, plane_state->src_x >> 16,
2795 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002796 else
2797 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002798 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2799 intel_encoder_info(m, intel_crtc, intel_encoder);
2800}
2801
2802static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2803{
2804 struct drm_display_mode *mode = panel->fixed_mode;
2805
2806 seq_printf(m, "\tfixed mode:\n");
2807 intel_seq_print_mode(m, 2, mode);
2808}
2809
2810static void intel_dp_info(struct seq_file *m,
2811 struct intel_connector *intel_connector)
2812{
2813 struct intel_encoder *intel_encoder = intel_connector->encoder;
2814 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2815
2816 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002817 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002818 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002819 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002820
2821 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2822 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002823}
2824
2825static void intel_hdmi_info(struct seq_file *m,
2826 struct intel_connector *intel_connector)
2827{
2828 struct intel_encoder *intel_encoder = intel_connector->encoder;
2829 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2830
Jani Nikula742f4912015-09-03 11:16:09 +03002831 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002832}
2833
2834static void intel_lvds_info(struct seq_file *m,
2835 struct intel_connector *intel_connector)
2836{
2837 intel_panel_info(m, &intel_connector->panel);
2838}
2839
2840static void intel_connector_info(struct seq_file *m,
2841 struct drm_connector *connector)
2842{
2843 struct intel_connector *intel_connector = to_intel_connector(connector);
2844 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002845 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002846
2847 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002848 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002849 drm_get_connector_status_name(connector->status));
2850 if (connector->status == connector_status_connected) {
2851 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2852 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2853 connector->display_info.width_mm,
2854 connector->display_info.height_mm);
2855 seq_printf(m, "\tsubpixel order: %s\n",
2856 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2857 seq_printf(m, "\tCEA rev: %d\n",
2858 connector->display_info.cea_rev);
2859 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002860
2861 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2862 return;
2863
2864 switch (connector->connector_type) {
2865 case DRM_MODE_CONNECTOR_DisplayPort:
2866 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002867 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002868 break;
2869 case DRM_MODE_CONNECTOR_LVDS:
2870 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002871 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002872 break;
2873 case DRM_MODE_CONNECTOR_HDMIA:
2874 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2875 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2876 intel_hdmi_info(m, intel_connector);
2877 break;
2878 default:
2879 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002880 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002881
Jesse Barnesf103fc72014-02-20 12:39:57 -08002882 seq_printf(m, "\tmodes:\n");
2883 list_for_each_entry(mode, &connector->modes, head)
2884 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002885}
2886
David Weinehall36cdd012016-08-22 13:59:31 +03002887static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002888{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002889 u32 state;
2890
David Weinehall36cdd012016-08-22 13:59:31 +03002891 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002892 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002893 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002894 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002895
2896 return state;
2897}
2898
David Weinehall36cdd012016-08-22 13:59:31 +03002899static bool cursor_position(struct drm_i915_private *dev_priv,
2900 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002901{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002902 u32 pos;
2903
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002904 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002905
2906 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2907 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2908 *x = -*x;
2909
2910 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2911 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2912 *y = -*y;
2913
David Weinehall36cdd012016-08-22 13:59:31 +03002914 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002915}
2916
Robert Fekete3abc4e02015-10-27 16:58:32 +01002917static const char *plane_type(enum drm_plane_type type)
2918{
2919 switch (type) {
2920 case DRM_PLANE_TYPE_OVERLAY:
2921 return "OVL";
2922 case DRM_PLANE_TYPE_PRIMARY:
2923 return "PRI";
2924 case DRM_PLANE_TYPE_CURSOR:
2925 return "CUR";
2926 /*
2927 * Deliberately omitting default: to generate compiler warnings
2928 * when a new drm_plane_type gets added.
2929 */
2930 }
2931
2932 return "unknown";
2933}
2934
2935static const char *plane_rotation(unsigned int rotation)
2936{
2937 static char buf[48];
2938 /*
2939 * According to doc only one DRM_ROTATE_ is allowed but this
2940 * will print them all to visualize if the values are misused
2941 */
2942 snprintf(buf, sizeof(buf),
2943 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03002944 (rotation & DRM_ROTATE_0) ? "0 " : "",
2945 (rotation & DRM_ROTATE_90) ? "90 " : "",
2946 (rotation & DRM_ROTATE_180) ? "180 " : "",
2947 (rotation & DRM_ROTATE_270) ? "270 " : "",
2948 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
2949 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01002950 rotation);
2951
2952 return buf;
2953}
2954
2955static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2956{
David Weinehall36cdd012016-08-22 13:59:31 +03002957 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2958 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01002959 struct intel_plane *intel_plane;
2960
2961 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
2962 struct drm_plane_state *state;
2963 struct drm_plane *plane = &intel_plane->base;
Eric Engestromd3828142016-08-15 16:29:55 +01002964 char *format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01002965
2966 if (!plane->state) {
2967 seq_puts(m, "plane->state is NULL!\n");
2968 continue;
2969 }
2970
2971 state = plane->state;
2972
Eric Engestrom90844f02016-08-15 01:02:38 +01002973 if (state->fb) {
2974 format_name = drm_get_format_name(state->fb->pixel_format);
2975 } else {
2976 format_name = kstrdup("N/A", GFP_KERNEL);
2977 }
2978
Robert Fekete3abc4e02015-10-27 16:58:32 +01002979 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",
2980 plane->base.id,
2981 plane_type(intel_plane->base.type),
2982 state->crtc_x, state->crtc_y,
2983 state->crtc_w, state->crtc_h,
2984 (state->src_x >> 16),
2985 ((state->src_x & 0xffff) * 15625) >> 10,
2986 (state->src_y >> 16),
2987 ((state->src_y & 0xffff) * 15625) >> 10,
2988 (state->src_w >> 16),
2989 ((state->src_w & 0xffff) * 15625) >> 10,
2990 (state->src_h >> 16),
2991 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestrom90844f02016-08-15 01:02:38 +01002992 format_name,
Robert Fekete3abc4e02015-10-27 16:58:32 +01002993 plane_rotation(state->rotation));
Eric Engestrom90844f02016-08-15 01:02:38 +01002994
2995 kfree(format_name);
Robert Fekete3abc4e02015-10-27 16:58:32 +01002996 }
2997}
2998
2999static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3000{
3001 struct intel_crtc_state *pipe_config;
3002 int num_scalers = intel_crtc->num_scalers;
3003 int i;
3004
3005 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3006
3007 /* Not all platformas have a scaler */
3008 if (num_scalers) {
3009 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3010 num_scalers,
3011 pipe_config->scaler_state.scaler_users,
3012 pipe_config->scaler_state.scaler_id);
3013
3014 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3015 struct intel_scaler *sc =
3016 &pipe_config->scaler_state.scalers[i];
3017
3018 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3019 i, yesno(sc->in_use), sc->mode);
3020 }
3021 seq_puts(m, "\n");
3022 } else {
3023 seq_puts(m, "\tNo scalers available on this platform\n");
3024 }
3025}
3026
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003027static int i915_display_info(struct seq_file *m, void *unused)
3028{
David Weinehall36cdd012016-08-22 13:59:31 +03003029 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3030 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003031 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003032 struct drm_connector *connector;
3033
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003034 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003035 drm_modeset_lock_all(dev);
3036 seq_printf(m, "CRTC info\n");
3037 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003038 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003039 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003040 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003041 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003042
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003043 pipe_config = to_intel_crtc_state(crtc->base.state);
3044
Robert Fekete3abc4e02015-10-27 16:58:32 +01003045 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003046 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003047 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003048 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3049 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3050
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003051 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003052 intel_crtc_info(m, crtc);
3053
David Weinehall36cdd012016-08-22 13:59:31 +03003054 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003055 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 +03003056 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003057 x, y, crtc->base.cursor->state->crtc_w,
3058 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003059 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003060 intel_scaler_info(m, crtc);
3061 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003062 }
Daniel Vettercace8412014-05-22 17:56:31 +02003063
3064 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3065 yesno(!crtc->cpu_fifo_underrun_disabled),
3066 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003067 }
3068
3069 seq_printf(m, "\n");
3070 seq_printf(m, "Connector info\n");
3071 seq_printf(m, "--------------\n");
3072 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3073 intel_connector_info(m, connector);
3074 }
3075 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003076 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003077
3078 return 0;
3079}
3080
Chris Wilson1b365952016-10-04 21:11:31 +01003081static int i915_engine_info(struct seq_file *m, void *unused)
3082{
3083 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3084 struct intel_engine_cs *engine;
3085
3086 for_each_engine(engine, dev_priv) {
3087 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3088 struct drm_i915_gem_request *rq;
3089 struct rb_node *rb;
3090 u64 addr;
3091
3092 seq_printf(m, "%s\n", engine->name);
3093 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3094 intel_engine_get_seqno(engine),
3095 engine->last_submitted_seqno,
3096 engine->hangcheck.seqno,
3097 engine->hangcheck.score);
3098
3099 rcu_read_lock();
3100
3101 seq_printf(m, "\tRequests:\n");
3102
3103 rq = list_first_entry(&engine->request_list,
3104 struct drm_i915_gem_request, link);
3105 if (&rq->link != &engine->request_list)
3106 print_request(m, rq, "\t\tfirst ");
3107
3108 rq = list_last_entry(&engine->request_list,
3109 struct drm_i915_gem_request, link);
3110 if (&rq->link != &engine->request_list)
3111 print_request(m, rq, "\t\tlast ");
3112
3113 rq = i915_gem_find_active_request(engine);
3114 if (rq) {
3115 print_request(m, rq, "\t\tactive ");
3116 seq_printf(m,
3117 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3118 rq->head, rq->postfix, rq->tail,
3119 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3120 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3121 }
3122
3123 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3124 I915_READ(RING_START(engine->mmio_base)),
3125 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3126 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3127 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3128 rq ? rq->ring->head : 0);
3129 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3130 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3131 rq ? rq->ring->tail : 0);
3132 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3133 I915_READ(RING_CTL(engine->mmio_base)),
3134 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3135
3136 rcu_read_unlock();
3137
3138 addr = intel_engine_get_active_head(engine);
3139 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3140 upper_32_bits(addr), lower_32_bits(addr));
3141 addr = intel_engine_get_last_batch_head(engine);
3142 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3143 upper_32_bits(addr), lower_32_bits(addr));
3144
3145 if (i915.enable_execlists) {
3146 u32 ptr, read, write;
3147
3148 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3149 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3150 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3151
3152 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3153 read = GEN8_CSB_READ_PTR(ptr);
3154 write = GEN8_CSB_WRITE_PTR(ptr);
3155 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3156 read, write);
3157 if (read >= GEN8_CSB_ENTRIES)
3158 read = 0;
3159 if (write >= GEN8_CSB_ENTRIES)
3160 write = 0;
3161 if (read > write)
3162 write += GEN8_CSB_ENTRIES;
3163 while (read < write) {
3164 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3165
3166 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3167 idx,
3168 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3169 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3170 }
3171
3172 rcu_read_lock();
3173 rq = READ_ONCE(engine->execlist_port[0].request);
3174 if (rq)
3175 print_request(m, rq, "\t\tELSP[0] ");
3176 else
3177 seq_printf(m, "\t\tELSP[0] idle\n");
3178 rq = READ_ONCE(engine->execlist_port[1].request);
3179 if (rq)
3180 print_request(m, rq, "\t\tELSP[1] ");
3181 else
3182 seq_printf(m, "\t\tELSP[1] idle\n");
3183 rcu_read_unlock();
3184 } else if (INTEL_GEN(dev_priv) > 6) {
3185 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3186 I915_READ(RING_PP_DIR_BASE(engine)));
3187 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3188 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3189 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3190 I915_READ(RING_PP_DIR_DCLV(engine)));
3191 }
3192
3193 spin_lock(&b->lock);
3194 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3195 struct intel_wait *w = container_of(rb, typeof(*w), node);
3196
3197 seq_printf(m, "\t%s [%d] waiting for %x\n",
3198 w->tsk->comm, w->tsk->pid, w->seqno);
3199 }
3200 spin_unlock(&b->lock);
3201
3202 seq_puts(m, "\n");
3203 }
3204
3205 return 0;
3206}
3207
Ben Widawskye04934c2014-06-30 09:53:42 -07003208static int i915_semaphore_status(struct seq_file *m, void *unused)
3209{
David Weinehall36cdd012016-08-22 13:59:31 +03003210 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3211 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003212 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003213 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003214 enum intel_engine_id id;
3215 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003216
Chris Wilson39df9192016-07-20 13:31:57 +01003217 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003218 seq_puts(m, "Semaphores are disabled\n");
3219 return 0;
3220 }
3221
3222 ret = mutex_lock_interruptible(&dev->struct_mutex);
3223 if (ret)
3224 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003225 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003226
David Weinehall36cdd012016-08-22 13:59:31 +03003227 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003228 struct page *page;
3229 uint64_t *seqno;
3230
Chris Wilson51d545d2016-08-15 10:49:02 +01003231 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003232
3233 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003234 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003235 uint64_t offset;
3236
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003237 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003238
3239 seq_puts(m, " Last signal:");
3240 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003241 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003242 seq_printf(m, "0x%08llx (0x%02llx) ",
3243 seqno[offset], offset * 8);
3244 }
3245 seq_putc(m, '\n');
3246
3247 seq_puts(m, " Last wait: ");
3248 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003249 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003250 seq_printf(m, "0x%08llx (0x%02llx) ",
3251 seqno[offset], offset * 8);
3252 }
3253 seq_putc(m, '\n');
3254
3255 }
3256 kunmap_atomic(seqno);
3257 } else {
3258 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003259 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003260 for (j = 0; j < num_rings; j++)
3261 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003262 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003263 seq_putc(m, '\n');
3264 }
3265
3266 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003267 for_each_engine(engine, dev_priv) {
3268 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003269 seq_printf(m, " 0x%08x ",
3270 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003271 seq_putc(m, '\n');
3272 }
3273 seq_putc(m, '\n');
3274
Paulo Zanoni03872062014-07-09 14:31:57 -03003275 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003276 mutex_unlock(&dev->struct_mutex);
3277 return 0;
3278}
3279
Daniel Vetter728e29d2014-06-25 22:01:53 +03003280static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3281{
David Weinehall36cdd012016-08-22 13:59:31 +03003282 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3283 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003284 int i;
3285
3286 drm_modeset_lock_all(dev);
3287 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3288 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3289
3290 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003291 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3292 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003293 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003294 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3295 seq_printf(m, " dpll_md: 0x%08x\n",
3296 pll->config.hw_state.dpll_md);
3297 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3298 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3299 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003300 }
3301 drm_modeset_unlock_all(dev);
3302
3303 return 0;
3304}
3305
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003306static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003307{
3308 int i;
3309 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003310 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003311 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3312 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003313 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003314 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003315
Arun Siluvery888b5992014-08-26 14:44:51 +01003316 ret = mutex_lock_interruptible(&dev->struct_mutex);
3317 if (ret)
3318 return ret;
3319
3320 intel_runtime_pm_get(dev_priv);
3321
Arun Siluvery33136b02016-01-21 21:43:47 +00003322 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003323 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003324 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003325 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003326 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003327 i915_reg_t addr;
3328 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003329 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003330
Arun Siluvery33136b02016-01-21 21:43:47 +00003331 addr = workarounds->reg[i].addr;
3332 mask = workarounds->reg[i].mask;
3333 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003334 read = I915_READ(addr);
3335 ok = (value & mask) == (read & mask);
3336 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 +02003337 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003338 }
3339
3340 intel_runtime_pm_put(dev_priv);
3341 mutex_unlock(&dev->struct_mutex);
3342
3343 return 0;
3344}
3345
Damien Lespiauc5511e42014-11-04 17:06:51 +00003346static int i915_ddb_info(struct seq_file *m, void *unused)
3347{
David Weinehall36cdd012016-08-22 13:59:31 +03003348 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3349 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003350 struct skl_ddb_allocation *ddb;
3351 struct skl_ddb_entry *entry;
3352 enum pipe pipe;
3353 int plane;
3354
David Weinehall36cdd012016-08-22 13:59:31 +03003355 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003356 return 0;
3357
Damien Lespiauc5511e42014-11-04 17:06:51 +00003358 drm_modeset_lock_all(dev);
3359
3360 ddb = &dev_priv->wm.skl_hw.ddb;
3361
3362 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3363
3364 for_each_pipe(dev_priv, pipe) {
3365 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3366
Damien Lespiaudd740782015-02-28 14:54:08 +00003367 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003368 entry = &ddb->plane[pipe][plane];
3369 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3370 entry->start, entry->end,
3371 skl_ddb_entry_size(entry));
3372 }
3373
Matt Roper4969d332015-09-24 15:53:10 -07003374 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003375 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3376 entry->end, skl_ddb_entry_size(entry));
3377 }
3378
3379 drm_modeset_unlock_all(dev);
3380
3381 return 0;
3382}
3383
Vandana Kannana54746e2015-03-03 20:53:10 +05303384static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003385 struct drm_device *dev,
3386 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303387{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003388 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303389 struct i915_drrs *drrs = &dev_priv->drrs;
3390 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003391 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303392
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003393 drm_for_each_connector(connector, dev) {
3394 if (connector->state->crtc != &intel_crtc->base)
3395 continue;
3396
3397 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303398 }
3399
3400 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3401 seq_puts(m, "\tVBT: DRRS_type: Static");
3402 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3403 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3404 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3405 seq_puts(m, "\tVBT: DRRS_type: None");
3406 else
3407 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3408
3409 seq_puts(m, "\n\n");
3410
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003411 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303412 struct intel_panel *panel;
3413
3414 mutex_lock(&drrs->mutex);
3415 /* DRRS Supported */
3416 seq_puts(m, "\tDRRS Supported: Yes\n");
3417
3418 /* disable_drrs() will make drrs->dp NULL */
3419 if (!drrs->dp) {
3420 seq_puts(m, "Idleness DRRS: Disabled");
3421 mutex_unlock(&drrs->mutex);
3422 return;
3423 }
3424
3425 panel = &drrs->dp->attached_connector->panel;
3426 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3427 drrs->busy_frontbuffer_bits);
3428
3429 seq_puts(m, "\n\t\t");
3430 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3431 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3432 vrefresh = panel->fixed_mode->vrefresh;
3433 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3434 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3435 vrefresh = panel->downclock_mode->vrefresh;
3436 } else {
3437 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3438 drrs->refresh_rate_type);
3439 mutex_unlock(&drrs->mutex);
3440 return;
3441 }
3442 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3443
3444 seq_puts(m, "\n\t\t");
3445 mutex_unlock(&drrs->mutex);
3446 } else {
3447 /* DRRS not supported. Print the VBT parameter*/
3448 seq_puts(m, "\tDRRS Supported : No");
3449 }
3450 seq_puts(m, "\n");
3451}
3452
3453static int i915_drrs_status(struct seq_file *m, void *unused)
3454{
David Weinehall36cdd012016-08-22 13:59:31 +03003455 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3456 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303457 struct intel_crtc *intel_crtc;
3458 int active_crtc_cnt = 0;
3459
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003460 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303461 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003462 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303463 active_crtc_cnt++;
3464 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3465
3466 drrs_status_per_crtc(m, dev, intel_crtc);
3467 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303468 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003469 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303470
3471 if (!active_crtc_cnt)
3472 seq_puts(m, "No active crtc found\n");
3473
3474 return 0;
3475}
3476
Damien Lespiau07144422013-10-15 18:55:40 +01003477struct pipe_crc_info {
3478 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003479 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003480 enum pipe pipe;
3481};
3482
Dave Airlie11bed952014-05-12 15:22:27 +10003483static int i915_dp_mst_info(struct seq_file *m, void *unused)
3484{
David Weinehall36cdd012016-08-22 13:59:31 +03003485 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3486 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003487 struct intel_encoder *intel_encoder;
3488 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003489 struct drm_connector *connector;
3490
Dave Airlie11bed952014-05-12 15:22:27 +10003491 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003492 drm_for_each_connector(connector, dev) {
3493 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003494 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003495
3496 intel_encoder = intel_attached_encoder(connector);
3497 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3498 continue;
3499
3500 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003501 if (!intel_dig_port->dp.can_mst)
3502 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003503
Jim Bride40ae80c2016-04-14 10:18:37 -07003504 seq_printf(m, "MST Source Port %c\n",
3505 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003506 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3507 }
3508 drm_modeset_unlock_all(dev);
3509 return 0;
3510}
3511
Damien Lespiau07144422013-10-15 18:55:40 +01003512static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003513{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003514 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003515 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003516 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3517
David Weinehall36cdd012016-08-22 13:59:31 +03003518 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003519 return -ENODEV;
3520
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003521 spin_lock_irq(&pipe_crc->lock);
3522
3523 if (pipe_crc->opened) {
3524 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003525 return -EBUSY; /* already open */
3526 }
3527
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003528 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003529 filep->private_data = inode->i_private;
3530
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003531 spin_unlock_irq(&pipe_crc->lock);
3532
Damien Lespiau07144422013-10-15 18:55:40 +01003533 return 0;
3534}
3535
3536static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3537{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003538 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003539 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003540 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3541
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003542 spin_lock_irq(&pipe_crc->lock);
3543 pipe_crc->opened = false;
3544 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003545
Damien Lespiau07144422013-10-15 18:55:40 +01003546 return 0;
3547}
3548
3549/* (6 fields, 8 chars each, space separated (5) + '\n') */
3550#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3551/* account for \'0' */
3552#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3553
3554static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3555{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003556 assert_spin_locked(&pipe_crc->lock);
3557 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3558 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003559}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003560
Damien Lespiau07144422013-10-15 18:55:40 +01003561static ssize_t
3562i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3563 loff_t *pos)
3564{
3565 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003566 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003567 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3568 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003569 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003570 ssize_t bytes_read;
3571
3572 /*
3573 * Don't allow user space to provide buffers not big enough to hold
3574 * a line of data.
3575 */
3576 if (count < PIPE_CRC_LINE_LEN)
3577 return -EINVAL;
3578
3579 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3580 return 0;
3581
3582 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003583 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003584 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003585 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003586
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003587 if (filep->f_flags & O_NONBLOCK) {
3588 spin_unlock_irq(&pipe_crc->lock);
3589 return -EAGAIN;
3590 }
3591
3592 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3593 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3594 if (ret) {
3595 spin_unlock_irq(&pipe_crc->lock);
3596 return ret;
3597 }
Damien Lespiau07144422013-10-15 18:55:40 +01003598 }
3599
3600 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003601 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003602
Damien Lespiau07144422013-10-15 18:55:40 +01003603 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003604 while (n_entries > 0) {
3605 struct intel_pipe_crc_entry *entry =
3606 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003607
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003608 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3609 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3610 break;
3611
3612 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3613 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3614
Damien Lespiau07144422013-10-15 18:55:40 +01003615 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3616 "%8u %8x %8x %8x %8x %8x\n",
3617 entry->frame, entry->crc[0],
3618 entry->crc[1], entry->crc[2],
3619 entry->crc[3], entry->crc[4]);
3620
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003621 spin_unlock_irq(&pipe_crc->lock);
3622
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003623 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003624 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003625
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003626 user_buf += PIPE_CRC_LINE_LEN;
3627 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003628
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003629 spin_lock_irq(&pipe_crc->lock);
3630 }
3631
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003632 spin_unlock_irq(&pipe_crc->lock);
3633
Damien Lespiau07144422013-10-15 18:55:40 +01003634 return bytes_read;
3635}
3636
3637static const struct file_operations i915_pipe_crc_fops = {
3638 .owner = THIS_MODULE,
3639 .open = i915_pipe_crc_open,
3640 .read = i915_pipe_crc_read,
3641 .release = i915_pipe_crc_release,
3642};
3643
3644static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3645 {
3646 .name = "i915_pipe_A_crc",
3647 .pipe = PIPE_A,
3648 },
3649 {
3650 .name = "i915_pipe_B_crc",
3651 .pipe = PIPE_B,
3652 },
3653 {
3654 .name = "i915_pipe_C_crc",
3655 .pipe = PIPE_C,
3656 },
3657};
3658
3659static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3660 enum pipe pipe)
3661{
David Weinehall36cdd012016-08-22 13:59:31 +03003662 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003663 struct dentry *ent;
3664 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3665
David Weinehall36cdd012016-08-22 13:59:31 +03003666 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003667 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3668 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003669 if (!ent)
3670 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003671
3672 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003673}
3674
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003675static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003676 "none",
3677 "plane1",
3678 "plane2",
3679 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003680 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003681 "TV",
3682 "DP-B",
3683 "DP-C",
3684 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003685 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003686};
3687
3688static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3689{
3690 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3691 return pipe_crc_sources[source];
3692}
3693
Damien Lespiaubd9db022013-10-15 18:55:36 +01003694static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003695{
David Weinehall36cdd012016-08-22 13:59:31 +03003696 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003697 int i;
3698
3699 for (i = 0; i < I915_MAX_PIPES; i++)
3700 seq_printf(m, "%c %s\n", pipe_name(i),
3701 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3702
3703 return 0;
3704}
3705
Damien Lespiaubd9db022013-10-15 18:55:36 +01003706static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003707{
David Weinehall36cdd012016-08-22 13:59:31 +03003708 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003709}
3710
Daniel Vetter46a19182013-11-01 10:50:20 +01003711static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003712 uint32_t *val)
3713{
Daniel Vetter46a19182013-11-01 10:50:20 +01003714 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3715 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3716
3717 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003718 case INTEL_PIPE_CRC_SOURCE_PIPE:
3719 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3720 break;
3721 case INTEL_PIPE_CRC_SOURCE_NONE:
3722 *val = 0;
3723 break;
3724 default:
3725 return -EINVAL;
3726 }
3727
3728 return 0;
3729}
3730
David Weinehall36cdd012016-08-22 13:59:31 +03003731static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3732 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003733 enum intel_pipe_crc_source *source)
3734{
David Weinehall36cdd012016-08-22 13:59:31 +03003735 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003736 struct intel_encoder *encoder;
3737 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003738 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003739 int ret = 0;
3740
3741 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3742
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003743 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003744 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003745 if (!encoder->base.crtc)
3746 continue;
3747
3748 crtc = to_intel_crtc(encoder->base.crtc);
3749
3750 if (crtc->pipe != pipe)
3751 continue;
3752
3753 switch (encoder->type) {
3754 case INTEL_OUTPUT_TVOUT:
3755 *source = INTEL_PIPE_CRC_SOURCE_TV;
3756 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003757 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003758 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003759 dig_port = enc_to_dig_port(&encoder->base);
3760 switch (dig_port->port) {
3761 case PORT_B:
3762 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3763 break;
3764 case PORT_C:
3765 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3766 break;
3767 case PORT_D:
3768 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3769 break;
3770 default:
3771 WARN(1, "nonexisting DP port %c\n",
3772 port_name(dig_port->port));
3773 break;
3774 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003775 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003776 default:
3777 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003778 }
3779 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003780 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003781
3782 return ret;
3783}
3784
David Weinehall36cdd012016-08-22 13:59:31 +03003785static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003786 enum pipe pipe,
3787 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003788 uint32_t *val)
3789{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003790 bool need_stable_symbols = false;
3791
Daniel Vetter46a19182013-11-01 10:50:20 +01003792 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003793 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003794 if (ret)
3795 return ret;
3796 }
3797
3798 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003799 case INTEL_PIPE_CRC_SOURCE_PIPE:
3800 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3801 break;
3802 case INTEL_PIPE_CRC_SOURCE_DP_B:
3803 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003804 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003805 break;
3806 case INTEL_PIPE_CRC_SOURCE_DP_C:
3807 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003808 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003809 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003810 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003811 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003812 return -EINVAL;
3813 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3814 need_stable_symbols = true;
3815 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003816 case INTEL_PIPE_CRC_SOURCE_NONE:
3817 *val = 0;
3818 break;
3819 default:
3820 return -EINVAL;
3821 }
3822
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003823 /*
3824 * When the pipe CRC tap point is after the transcoders we need
3825 * to tweak symbol-level features to produce a deterministic series of
3826 * symbols for a given frame. We need to reset those features only once
3827 * a frame (instead of every nth symbol):
3828 * - DC-balance: used to ensure a better clock recovery from the data
3829 * link (SDVO)
3830 * - DisplayPort scrambling: used for EMI reduction
3831 */
3832 if (need_stable_symbols) {
3833 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3834
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003835 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003836 switch (pipe) {
3837 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003838 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003839 break;
3840 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003841 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003842 break;
3843 case PIPE_C:
3844 tmp |= PIPE_C_SCRAMBLE_RESET;
3845 break;
3846 default:
3847 return -EINVAL;
3848 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003849 I915_WRITE(PORT_DFT2_G4X, tmp);
3850 }
3851
Daniel Vetter7ac01292013-10-18 16:37:06 +02003852 return 0;
3853}
3854
David Weinehall36cdd012016-08-22 13:59:31 +03003855static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003856 enum pipe pipe,
3857 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003858 uint32_t *val)
3859{
Daniel Vetter84093602013-11-01 10:50:21 +01003860 bool need_stable_symbols = false;
3861
Daniel Vetter46a19182013-11-01 10:50:20 +01003862 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003863 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003864 if (ret)
3865 return ret;
3866 }
3867
3868 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003869 case INTEL_PIPE_CRC_SOURCE_PIPE:
3870 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3871 break;
3872 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003873 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003874 return -EINVAL;
3875 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3876 break;
3877 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003878 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003879 return -EINVAL;
3880 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003881 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003882 break;
3883 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003884 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003885 return -EINVAL;
3886 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003887 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003888 break;
3889 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003890 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003891 return -EINVAL;
3892 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003893 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003894 break;
3895 case INTEL_PIPE_CRC_SOURCE_NONE:
3896 *val = 0;
3897 break;
3898 default:
3899 return -EINVAL;
3900 }
3901
Daniel Vetter84093602013-11-01 10:50:21 +01003902 /*
3903 * When the pipe CRC tap point is after the transcoders we need
3904 * to tweak symbol-level features to produce a deterministic series of
3905 * symbols for a given frame. We need to reset those features only once
3906 * a frame (instead of every nth symbol):
3907 * - DC-balance: used to ensure a better clock recovery from the data
3908 * link (SDVO)
3909 * - DisplayPort scrambling: used for EMI reduction
3910 */
3911 if (need_stable_symbols) {
3912 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3913
David Weinehall36cdd012016-08-22 13:59:31 +03003914 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003915
3916 I915_WRITE(PORT_DFT_I9XX,
3917 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3918
3919 if (pipe == PIPE_A)
3920 tmp |= PIPE_A_SCRAMBLE_RESET;
3921 else
3922 tmp |= PIPE_B_SCRAMBLE_RESET;
3923
3924 I915_WRITE(PORT_DFT2_G4X, tmp);
3925 }
3926
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003927 return 0;
3928}
3929
David Weinehall36cdd012016-08-22 13:59:31 +03003930static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003931 enum pipe pipe)
3932{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003933 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3934
Ville Syrjäläeb736672014-12-09 21:28:28 +02003935 switch (pipe) {
3936 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003937 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003938 break;
3939 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003940 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003941 break;
3942 case PIPE_C:
3943 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3944 break;
3945 default:
3946 return;
3947 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003948 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3949 tmp &= ~DC_BALANCE_RESET_VLV;
3950 I915_WRITE(PORT_DFT2_G4X, tmp);
3951
3952}
3953
David Weinehall36cdd012016-08-22 13:59:31 +03003954static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01003955 enum pipe pipe)
3956{
Daniel Vetter84093602013-11-01 10:50:21 +01003957 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3958
3959 if (pipe == PIPE_A)
3960 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3961 else
3962 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3963 I915_WRITE(PORT_DFT2_G4X, tmp);
3964
3965 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3966 I915_WRITE(PORT_DFT_I9XX,
3967 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3968 }
3969}
3970
Daniel Vetter46a19182013-11-01 10:50:20 +01003971static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003972 uint32_t *val)
3973{
Daniel Vetter46a19182013-11-01 10:50:20 +01003974 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3975 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3976
3977 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003978 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3979 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3980 break;
3981 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3982 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3983 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003984 case INTEL_PIPE_CRC_SOURCE_PIPE:
3985 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3986 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003987 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003988 *val = 0;
3989 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003990 default:
3991 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003992 }
3993
3994 return 0;
3995}
3996
David Weinehall36cdd012016-08-22 13:59:31 +03003997static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
3998 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003999{
David Weinehall36cdd012016-08-22 13:59:31 +03004000 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004001 struct intel_crtc *crtc =
4002 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004003 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004004 struct drm_atomic_state *state;
4005 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004006
4007 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004008 state = drm_atomic_state_alloc(dev);
4009 if (!state) {
4010 ret = -ENOMEM;
4011 goto out;
4012 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004013
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004014 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4015 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4016 if (IS_ERR(pipe_config)) {
4017 ret = PTR_ERR(pipe_config);
4018 goto out;
4019 }
4020
4021 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004022 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004023 pipe_config->pch_pfit.enabled != enable)
4024 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004025
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004026 ret = drm_atomic_commit(state);
4027out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004028 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004029 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4030 if (ret)
4031 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004032}
4033
David Weinehall36cdd012016-08-22 13:59:31 +03004034static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004035 enum pipe pipe,
4036 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004037 uint32_t *val)
4038{
Daniel Vetter46a19182013-11-01 10:50:20 +01004039 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4040 *source = INTEL_PIPE_CRC_SOURCE_PF;
4041
4042 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004043 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4044 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4045 break;
4046 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4047 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4048 break;
4049 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004050 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4051 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004052
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004053 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4054 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004055 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004056 *val = 0;
4057 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004058 default:
4059 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004060 }
4061
4062 return 0;
4063}
4064
David Weinehall36cdd012016-08-22 13:59:31 +03004065static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4066 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004067 enum intel_pipe_crc_source source)
4068{
David Weinehall36cdd012016-08-22 13:59:31 +03004069 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004070 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03004071 struct intel_crtc *crtc =
4072 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02004073 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004074 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004075 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004076
Damien Lespiaucc3da172013-10-15 18:55:31 +01004077 if (pipe_crc->source == source)
4078 return 0;
4079
Damien Lespiauae676fc2013-10-15 18:55:32 +01004080 /* forbid changing the source without going back to 'none' */
4081 if (pipe_crc->source && source)
4082 return -EINVAL;
4083
Imre Deake1296492016-02-12 18:55:17 +02004084 power_domain = POWER_DOMAIN_PIPE(pipe);
4085 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004086 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4087 return -EIO;
4088 }
4089
David Weinehall36cdd012016-08-22 13:59:31 +03004090 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004091 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004092 else if (INTEL_GEN(dev_priv) < 5)
4093 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4094 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4095 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4096 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004097 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004098 else
David Weinehall36cdd012016-08-22 13:59:31 +03004099 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004100
4101 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004102 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004103
Damien Lespiau4b584362013-10-15 18:55:33 +01004104 /* none -> real source transition */
4105 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004106 struct intel_pipe_crc_entry *entries;
4107
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004108 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4109 pipe_name(pipe), pipe_crc_source_name(source));
4110
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004111 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4112 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004113 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004114 if (!entries) {
4115 ret = -ENOMEM;
4116 goto out;
4117 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004118
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004119 /*
4120 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4121 * enabled and disabled dynamically based on package C states,
4122 * user space can't make reliable use of the CRCs, so let's just
4123 * completely disable it.
4124 */
4125 hsw_disable_ips(crtc);
4126
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004127 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004128 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004129 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004130 pipe_crc->head = 0;
4131 pipe_crc->tail = 0;
4132 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004133 }
4134
Damien Lespiaucc3da172013-10-15 18:55:31 +01004135 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004136
Daniel Vetter926321d2013-10-16 13:30:34 +02004137 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4138 POSTING_READ(PIPE_CRC_CTL(pipe));
4139
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004140 /* real source -> none transition */
4141 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004142 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004143 struct intel_crtc *crtc =
4144 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004145
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004146 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4147 pipe_name(pipe));
4148
Daniel Vettera33d7102014-06-06 08:22:08 +02004149 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004150 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004151 intel_wait_for_vblank(dev, pipe);
4152 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004153
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004154 spin_lock_irq(&pipe_crc->lock);
4155 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004156 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004157 pipe_crc->head = 0;
4158 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004159 spin_unlock_irq(&pipe_crc->lock);
4160
4161 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004162
David Weinehall36cdd012016-08-22 13:59:31 +03004163 if (IS_G4X(dev_priv))
4164 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4165 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4166 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4167 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4168 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004169
4170 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004171 }
4172
Imre Deake1296492016-02-12 18:55:17 +02004173 ret = 0;
4174
4175out:
4176 intel_display_power_put(dev_priv, power_domain);
4177
4178 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004179}
4180
4181/*
4182 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004183 * command: wsp* object wsp+ name wsp+ source wsp*
4184 * object: 'pipe'
4185 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004186 * source: (none | plane1 | plane2 | pf)
4187 * wsp: (#0x20 | #0x9 | #0xA)+
4188 *
4189 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004190 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4191 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004192 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004193static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004194{
4195 int n_words = 0;
4196
4197 while (*buf) {
4198 char *end;
4199
4200 /* skip leading white space */
4201 buf = skip_spaces(buf);
4202 if (!*buf)
4203 break; /* end of buffer */
4204
4205 /* find end of word */
4206 for (end = buf; *end && !isspace(*end); end++)
4207 ;
4208
4209 if (n_words == max_words) {
4210 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4211 max_words);
4212 return -EINVAL; /* ran out of words[] before bytes */
4213 }
4214
4215 if (*end)
4216 *end++ = '\0';
4217 words[n_words++] = buf;
4218 buf = end;
4219 }
4220
4221 return n_words;
4222}
4223
Damien Lespiaub94dec82013-10-15 18:55:35 +01004224enum intel_pipe_crc_object {
4225 PIPE_CRC_OBJECT_PIPE,
4226};
4227
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004228static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004229 "pipe",
4230};
4231
4232static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004233display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004234{
4235 int i;
4236
4237 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4238 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004239 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004240 return 0;
4241 }
4242
4243 return -EINVAL;
4244}
4245
Damien Lespiaubd9db022013-10-15 18:55:36 +01004246static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004247{
4248 const char name = buf[0];
4249
4250 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4251 return -EINVAL;
4252
4253 *pipe = name - 'A';
4254
4255 return 0;
4256}
4257
4258static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004259display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004260{
4261 int i;
4262
4263 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4264 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004265 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004266 return 0;
4267 }
4268
4269 return -EINVAL;
4270}
4271
David Weinehall36cdd012016-08-22 13:59:31 +03004272static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4273 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004274{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004275#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004276 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004277 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004278 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004279 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004280 enum intel_pipe_crc_source source;
4281
Damien Lespiaubd9db022013-10-15 18:55:36 +01004282 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004283 if (n_words != N_WORDS) {
4284 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4285 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004286 return -EINVAL;
4287 }
4288
Damien Lespiaubd9db022013-10-15 18:55:36 +01004289 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004290 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004291 return -EINVAL;
4292 }
4293
Damien Lespiaubd9db022013-10-15 18:55:36 +01004294 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004295 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4296 return -EINVAL;
4297 }
4298
Damien Lespiaubd9db022013-10-15 18:55:36 +01004299 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004300 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004301 return -EINVAL;
4302 }
4303
David Weinehall36cdd012016-08-22 13:59:31 +03004304 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004305}
4306
Damien Lespiaubd9db022013-10-15 18:55:36 +01004307static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4308 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004309{
4310 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004311 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004312 char *tmpbuf;
4313 int ret;
4314
4315 if (len == 0)
4316 return 0;
4317
4318 if (len > PAGE_SIZE - 1) {
4319 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4320 PAGE_SIZE);
4321 return -E2BIG;
4322 }
4323
4324 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4325 if (!tmpbuf)
4326 return -ENOMEM;
4327
4328 if (copy_from_user(tmpbuf, ubuf, len)) {
4329 ret = -EFAULT;
4330 goto out;
4331 }
4332 tmpbuf[len] = '\0';
4333
David Weinehall36cdd012016-08-22 13:59:31 +03004334 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004335
4336out:
4337 kfree(tmpbuf);
4338 if (ret < 0)
4339 return ret;
4340
4341 *offp += len;
4342 return len;
4343}
4344
Damien Lespiaubd9db022013-10-15 18:55:36 +01004345static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004346 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004347 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004348 .read = seq_read,
4349 .llseek = seq_lseek,
4350 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004351 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004352};
4353
Todd Previteeb3394fa2015-04-18 00:04:19 -07004354static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004355 const char __user *ubuf,
4356 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004357{
4358 char *input_buffer;
4359 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004360 struct drm_device *dev;
4361 struct drm_connector *connector;
4362 struct list_head *connector_list;
4363 struct intel_dp *intel_dp;
4364 int val = 0;
4365
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304366 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004367
Todd Previteeb3394fa2015-04-18 00:04:19 -07004368 connector_list = &dev->mode_config.connector_list;
4369
4370 if (len == 0)
4371 return 0;
4372
4373 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4374 if (!input_buffer)
4375 return -ENOMEM;
4376
4377 if (copy_from_user(input_buffer, ubuf, len)) {
4378 status = -EFAULT;
4379 goto out;
4380 }
4381
4382 input_buffer[len] = '\0';
4383 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4384
4385 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004386 if (connector->connector_type !=
4387 DRM_MODE_CONNECTOR_DisplayPort)
4388 continue;
4389
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304390 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004391 connector->encoder != NULL) {
4392 intel_dp = enc_to_intel_dp(connector->encoder);
4393 status = kstrtoint(input_buffer, 10, &val);
4394 if (status < 0)
4395 goto out;
4396 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4397 /* To prevent erroneous activation of the compliance
4398 * testing code, only accept an actual value of 1 here
4399 */
4400 if (val == 1)
4401 intel_dp->compliance_test_active = 1;
4402 else
4403 intel_dp->compliance_test_active = 0;
4404 }
4405 }
4406out:
4407 kfree(input_buffer);
4408 if (status < 0)
4409 return status;
4410
4411 *offp += len;
4412 return len;
4413}
4414
4415static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4416{
4417 struct drm_device *dev = m->private;
4418 struct drm_connector *connector;
4419 struct list_head *connector_list = &dev->mode_config.connector_list;
4420 struct intel_dp *intel_dp;
4421
Todd Previteeb3394fa2015-04-18 00:04:19 -07004422 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004423 if (connector->connector_type !=
4424 DRM_MODE_CONNECTOR_DisplayPort)
4425 continue;
4426
4427 if (connector->status == connector_status_connected &&
4428 connector->encoder != NULL) {
4429 intel_dp = enc_to_intel_dp(connector->encoder);
4430 if (intel_dp->compliance_test_active)
4431 seq_puts(m, "1");
4432 else
4433 seq_puts(m, "0");
4434 } else
4435 seq_puts(m, "0");
4436 }
4437
4438 return 0;
4439}
4440
4441static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004442 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004443{
David Weinehall36cdd012016-08-22 13:59:31 +03004444 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004445
David Weinehall36cdd012016-08-22 13:59:31 +03004446 return single_open(file, i915_displayport_test_active_show,
4447 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004448}
4449
4450static const struct file_operations i915_displayport_test_active_fops = {
4451 .owner = THIS_MODULE,
4452 .open = i915_displayport_test_active_open,
4453 .read = seq_read,
4454 .llseek = seq_lseek,
4455 .release = single_release,
4456 .write = i915_displayport_test_active_write
4457};
4458
4459static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4460{
4461 struct drm_device *dev = m->private;
4462 struct drm_connector *connector;
4463 struct list_head *connector_list = &dev->mode_config.connector_list;
4464 struct intel_dp *intel_dp;
4465
Todd Previteeb3394fa2015-04-18 00:04:19 -07004466 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004467 if (connector->connector_type !=
4468 DRM_MODE_CONNECTOR_DisplayPort)
4469 continue;
4470
4471 if (connector->status == connector_status_connected &&
4472 connector->encoder != NULL) {
4473 intel_dp = enc_to_intel_dp(connector->encoder);
4474 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4475 } else
4476 seq_puts(m, "0");
4477 }
4478
4479 return 0;
4480}
4481static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004482 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004483{
David Weinehall36cdd012016-08-22 13:59:31 +03004484 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004485
David Weinehall36cdd012016-08-22 13:59:31 +03004486 return single_open(file, i915_displayport_test_data_show,
4487 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004488}
4489
4490static const struct file_operations i915_displayport_test_data_fops = {
4491 .owner = THIS_MODULE,
4492 .open = i915_displayport_test_data_open,
4493 .read = seq_read,
4494 .llseek = seq_lseek,
4495 .release = single_release
4496};
4497
4498static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4499{
4500 struct drm_device *dev = m->private;
4501 struct drm_connector *connector;
4502 struct list_head *connector_list = &dev->mode_config.connector_list;
4503 struct intel_dp *intel_dp;
4504
Todd Previteeb3394fa2015-04-18 00:04:19 -07004505 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004506 if (connector->connector_type !=
4507 DRM_MODE_CONNECTOR_DisplayPort)
4508 continue;
4509
4510 if (connector->status == connector_status_connected &&
4511 connector->encoder != NULL) {
4512 intel_dp = enc_to_intel_dp(connector->encoder);
4513 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4514 } else
4515 seq_puts(m, "0");
4516 }
4517
4518 return 0;
4519}
4520
4521static int i915_displayport_test_type_open(struct inode *inode,
4522 struct file *file)
4523{
David Weinehall36cdd012016-08-22 13:59:31 +03004524 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004525
David Weinehall36cdd012016-08-22 13:59:31 +03004526 return single_open(file, i915_displayport_test_type_show,
4527 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004528}
4529
4530static const struct file_operations i915_displayport_test_type_fops = {
4531 .owner = THIS_MODULE,
4532 .open = i915_displayport_test_type_open,
4533 .read = seq_read,
4534 .llseek = seq_lseek,
4535 .release = single_release
4536};
4537
Damien Lespiau97e94b22014-11-04 17:06:50 +00004538static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004539{
David Weinehall36cdd012016-08-22 13:59:31 +03004540 struct drm_i915_private *dev_priv = m->private;
4541 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004542 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004543 int num_levels;
4544
David Weinehall36cdd012016-08-22 13:59:31 +03004545 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004546 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004547 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004548 num_levels = 1;
4549 else
4550 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004551
4552 drm_modeset_lock_all(dev);
4553
4554 for (level = 0; level < num_levels; level++) {
4555 unsigned int latency = wm[level];
4556
Damien Lespiau97e94b22014-11-04 17:06:50 +00004557 /*
4558 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004559 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004560 */
David Weinehall36cdd012016-08-22 13:59:31 +03004561 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4562 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004563 latency *= 10;
4564 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004565 latency *= 5;
4566
4567 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004568 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004569 }
4570
4571 drm_modeset_unlock_all(dev);
4572}
4573
4574static int pri_wm_latency_show(struct seq_file *m, void *data)
4575{
David Weinehall36cdd012016-08-22 13:59:31 +03004576 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004577 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004578
David Weinehall36cdd012016-08-22 13:59:31 +03004579 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004580 latencies = dev_priv->wm.skl_latency;
4581 else
David Weinehall36cdd012016-08-22 13:59:31 +03004582 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004583
4584 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004585
4586 return 0;
4587}
4588
4589static int spr_wm_latency_show(struct seq_file *m, void *data)
4590{
David Weinehall36cdd012016-08-22 13:59:31 +03004591 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004592 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004593
David Weinehall36cdd012016-08-22 13:59:31 +03004594 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004595 latencies = dev_priv->wm.skl_latency;
4596 else
David Weinehall36cdd012016-08-22 13:59:31 +03004597 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004598
4599 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004600
4601 return 0;
4602}
4603
4604static int cur_wm_latency_show(struct seq_file *m, void *data)
4605{
David Weinehall36cdd012016-08-22 13:59:31 +03004606 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004607 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004608
David Weinehall36cdd012016-08-22 13:59:31 +03004609 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004610 latencies = dev_priv->wm.skl_latency;
4611 else
David Weinehall36cdd012016-08-22 13:59:31 +03004612 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004613
4614 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004615
4616 return 0;
4617}
4618
4619static int pri_wm_latency_open(struct inode *inode, struct file *file)
4620{
David Weinehall36cdd012016-08-22 13:59:31 +03004621 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004622
David Weinehall36cdd012016-08-22 13:59:31 +03004623 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004624 return -ENODEV;
4625
David Weinehall36cdd012016-08-22 13:59:31 +03004626 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004627}
4628
4629static int spr_wm_latency_open(struct inode *inode, struct file *file)
4630{
David Weinehall36cdd012016-08-22 13:59:31 +03004631 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004632
David Weinehall36cdd012016-08-22 13:59:31 +03004633 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004634 return -ENODEV;
4635
David Weinehall36cdd012016-08-22 13:59:31 +03004636 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004637}
4638
4639static int cur_wm_latency_open(struct inode *inode, struct file *file)
4640{
David Weinehall36cdd012016-08-22 13:59:31 +03004641 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004642
David Weinehall36cdd012016-08-22 13:59:31 +03004643 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004644 return -ENODEV;
4645
David Weinehall36cdd012016-08-22 13:59:31 +03004646 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004647}
4648
4649static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004650 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004651{
4652 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004653 struct drm_i915_private *dev_priv = m->private;
4654 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004655 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004656 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004657 int level;
4658 int ret;
4659 char tmp[32];
4660
David Weinehall36cdd012016-08-22 13:59:31 +03004661 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004662 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004663 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004664 num_levels = 1;
4665 else
4666 num_levels = ilk_wm_max_level(dev) + 1;
4667
Ville Syrjälä369a1342014-01-22 14:36:08 +02004668 if (len >= sizeof(tmp))
4669 return -EINVAL;
4670
4671 if (copy_from_user(tmp, ubuf, len))
4672 return -EFAULT;
4673
4674 tmp[len] = '\0';
4675
Damien Lespiau97e94b22014-11-04 17:06:50 +00004676 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4677 &new[0], &new[1], &new[2], &new[3],
4678 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004679 if (ret != num_levels)
4680 return -EINVAL;
4681
4682 drm_modeset_lock_all(dev);
4683
4684 for (level = 0; level < num_levels; level++)
4685 wm[level] = new[level];
4686
4687 drm_modeset_unlock_all(dev);
4688
4689 return len;
4690}
4691
4692
4693static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4694 size_t len, loff_t *offp)
4695{
4696 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004697 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004698 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004699
David Weinehall36cdd012016-08-22 13:59:31 +03004700 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004701 latencies = dev_priv->wm.skl_latency;
4702 else
David Weinehall36cdd012016-08-22 13:59:31 +03004703 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004704
4705 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004706}
4707
4708static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4709 size_t len, loff_t *offp)
4710{
4711 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004712 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004713 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004714
David Weinehall36cdd012016-08-22 13:59:31 +03004715 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004716 latencies = dev_priv->wm.skl_latency;
4717 else
David Weinehall36cdd012016-08-22 13:59:31 +03004718 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004719
4720 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004721}
4722
4723static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4724 size_t len, loff_t *offp)
4725{
4726 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004727 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004728 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004729
David Weinehall36cdd012016-08-22 13:59:31 +03004730 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004731 latencies = dev_priv->wm.skl_latency;
4732 else
David Weinehall36cdd012016-08-22 13:59:31 +03004733 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004734
4735 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004736}
4737
4738static const struct file_operations i915_pri_wm_latency_fops = {
4739 .owner = THIS_MODULE,
4740 .open = pri_wm_latency_open,
4741 .read = seq_read,
4742 .llseek = seq_lseek,
4743 .release = single_release,
4744 .write = pri_wm_latency_write
4745};
4746
4747static const struct file_operations i915_spr_wm_latency_fops = {
4748 .owner = THIS_MODULE,
4749 .open = spr_wm_latency_open,
4750 .read = seq_read,
4751 .llseek = seq_lseek,
4752 .release = single_release,
4753 .write = spr_wm_latency_write
4754};
4755
4756static const struct file_operations i915_cur_wm_latency_fops = {
4757 .owner = THIS_MODULE,
4758 .open = cur_wm_latency_open,
4759 .read = seq_read,
4760 .llseek = seq_lseek,
4761 .release = single_release,
4762 .write = cur_wm_latency_write
4763};
4764
Kees Cook647416f2013-03-10 14:10:06 -07004765static int
4766i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004767{
David Weinehall36cdd012016-08-22 13:59:31 +03004768 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004769
Chris Wilsond98c52c2016-04-13 17:35:05 +01004770 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004771
Kees Cook647416f2013-03-10 14:10:06 -07004772 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004773}
4774
Kees Cook647416f2013-03-10 14:10:06 -07004775static int
4776i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004777{
David Weinehall36cdd012016-08-22 13:59:31 +03004778 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004779
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004780 /*
4781 * There is no safeguard against this debugfs entry colliding
4782 * with the hangcheck calling same i915_handle_error() in
4783 * parallel, causing an explosion. For now we assume that the
4784 * test harness is responsible enough not to inject gpu hangs
4785 * while it is writing to 'i915_wedged'
4786 */
4787
Chris Wilsond98c52c2016-04-13 17:35:05 +01004788 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004789 return -EAGAIN;
4790
Imre Deakd46c0512014-04-14 20:24:27 +03004791 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004792
Chris Wilsonc0336662016-05-06 15:40:21 +01004793 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004794 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004795
4796 intel_runtime_pm_put(dev_priv);
4797
Kees Cook647416f2013-03-10 14:10:06 -07004798 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004799}
4800
Kees Cook647416f2013-03-10 14:10:06 -07004801DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4802 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004803 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004804
Kees Cook647416f2013-03-10 14:10:06 -07004805static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004806i915_ring_missed_irq_get(void *data, u64 *val)
4807{
David Weinehall36cdd012016-08-22 13:59:31 +03004808 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004809
4810 *val = dev_priv->gpu_error.missed_irq_rings;
4811 return 0;
4812}
4813
4814static int
4815i915_ring_missed_irq_set(void *data, u64 val)
4816{
David Weinehall36cdd012016-08-22 13:59:31 +03004817 struct drm_i915_private *dev_priv = data;
4818 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004819 int ret;
4820
4821 /* Lock against concurrent debugfs callers */
4822 ret = mutex_lock_interruptible(&dev->struct_mutex);
4823 if (ret)
4824 return ret;
4825 dev_priv->gpu_error.missed_irq_rings = val;
4826 mutex_unlock(&dev->struct_mutex);
4827
4828 return 0;
4829}
4830
4831DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4832 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4833 "0x%08llx\n");
4834
4835static int
4836i915_ring_test_irq_get(void *data, u64 *val)
4837{
David Weinehall36cdd012016-08-22 13:59:31 +03004838 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004839
4840 *val = dev_priv->gpu_error.test_irq_rings;
4841
4842 return 0;
4843}
4844
4845static int
4846i915_ring_test_irq_set(void *data, u64 val)
4847{
David Weinehall36cdd012016-08-22 13:59:31 +03004848 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004849
Chris Wilson3a122c22016-06-17 14:35:05 +01004850 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004851 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004852 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004853
4854 return 0;
4855}
4856
4857DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4858 i915_ring_test_irq_get, i915_ring_test_irq_set,
4859 "0x%08llx\n");
4860
Chris Wilsondd624af2013-01-15 12:39:35 +00004861#define DROP_UNBOUND 0x1
4862#define DROP_BOUND 0x2
4863#define DROP_RETIRE 0x4
4864#define DROP_ACTIVE 0x8
4865#define DROP_ALL (DROP_UNBOUND | \
4866 DROP_BOUND | \
4867 DROP_RETIRE | \
4868 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004869static int
4870i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004871{
Kees Cook647416f2013-03-10 14:10:06 -07004872 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004873
Kees Cook647416f2013-03-10 14:10:06 -07004874 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004875}
4876
Kees Cook647416f2013-03-10 14:10:06 -07004877static int
4878i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004879{
David Weinehall36cdd012016-08-22 13:59:31 +03004880 struct drm_i915_private *dev_priv = data;
4881 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004882 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004883
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004884 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004885
4886 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4887 * on ioctls on -EAGAIN. */
4888 ret = mutex_lock_interruptible(&dev->struct_mutex);
4889 if (ret)
4890 return ret;
4891
4892 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004893 ret = i915_gem_wait_for_idle(dev_priv,
4894 I915_WAIT_INTERRUPTIBLE |
4895 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004896 if (ret)
4897 goto unlock;
4898 }
4899
4900 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004901 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004902
Chris Wilson21ab4e72014-09-09 11:16:08 +01004903 if (val & DROP_BOUND)
4904 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004905
Chris Wilson21ab4e72014-09-09 11:16:08 +01004906 if (val & DROP_UNBOUND)
4907 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004908
4909unlock:
4910 mutex_unlock(&dev->struct_mutex);
4911
Kees Cook647416f2013-03-10 14:10:06 -07004912 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004913}
4914
Kees Cook647416f2013-03-10 14:10:06 -07004915DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4916 i915_drop_caches_get, i915_drop_caches_set,
4917 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004918
Kees Cook647416f2013-03-10 14:10:06 -07004919static int
4920i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004921{
David Weinehall36cdd012016-08-22 13:59:31 +03004922 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004923
David Weinehall36cdd012016-08-22 13:59:31 +03004924 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004925 return -ENODEV;
4926
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004927 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004928 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004929}
4930
Kees Cook647416f2013-03-10 14:10:06 -07004931static int
4932i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004933{
David Weinehall36cdd012016-08-22 13:59:31 +03004934 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304935 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004936 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004937
David Weinehall36cdd012016-08-22 13:59:31 +03004938 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004939 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004940
Kees Cook647416f2013-03-10 14:10:06 -07004941 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004942
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004943 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004944 if (ret)
4945 return ret;
4946
Jesse Barnes358733e2011-07-27 11:53:01 -07004947 /*
4948 * Turbo will still be enabled, but won't go above the set value.
4949 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304950 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004951
Akash Goelbc4d91f2015-02-26 16:09:47 +05304952 hw_max = dev_priv->rps.max_freq;
4953 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004954
Ben Widawskyb39fb292014-03-19 18:31:11 -07004955 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004956 mutex_unlock(&dev_priv->rps.hw_lock);
4957 return -EINVAL;
4958 }
4959
Ben Widawskyb39fb292014-03-19 18:31:11 -07004960 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004961
Chris Wilsondc979972016-05-10 14:10:04 +01004962 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004963
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004964 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004965
Kees Cook647416f2013-03-10 14:10:06 -07004966 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004967}
4968
Kees Cook647416f2013-03-10 14:10:06 -07004969DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4970 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004971 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004972
Kees Cook647416f2013-03-10 14:10:06 -07004973static int
4974i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004975{
David Weinehall36cdd012016-08-22 13:59:31 +03004976 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004977
Chris Wilson62e1baa2016-07-13 09:10:36 +01004978 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004979 return -ENODEV;
4980
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004981 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004982 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004983}
4984
Kees Cook647416f2013-03-10 14:10:06 -07004985static int
4986i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004987{
David Weinehall36cdd012016-08-22 13:59:31 +03004988 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304989 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004990 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004991
Chris Wilson62e1baa2016-07-13 09:10:36 +01004992 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004993 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004994
Kees Cook647416f2013-03-10 14:10:06 -07004995 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004996
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004997 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004998 if (ret)
4999 return ret;
5000
Jesse Barnes1523c312012-05-25 12:34:54 -07005001 /*
5002 * Turbo will still be enabled, but won't go below the set value.
5003 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305004 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005005
Akash Goelbc4d91f2015-02-26 16:09:47 +05305006 hw_max = dev_priv->rps.max_freq;
5007 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005008
David Weinehall36cdd012016-08-22 13:59:31 +03005009 if (val < hw_min ||
5010 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005011 mutex_unlock(&dev_priv->rps.hw_lock);
5012 return -EINVAL;
5013 }
5014
Ben Widawskyb39fb292014-03-19 18:31:11 -07005015 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005016
Chris Wilsondc979972016-05-10 14:10:04 +01005017 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005018
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005019 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005020
Kees Cook647416f2013-03-10 14:10:06 -07005021 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005022}
5023
Kees Cook647416f2013-03-10 14:10:06 -07005024DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5025 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005026 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005027
Kees Cook647416f2013-03-10 14:10:06 -07005028static int
5029i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005030{
David Weinehall36cdd012016-08-22 13:59:31 +03005031 struct drm_i915_private *dev_priv = data;
5032 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005033 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005034 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005035
David Weinehall36cdd012016-08-22 13:59:31 +03005036 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005037 return -ENODEV;
5038
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005039 ret = mutex_lock_interruptible(&dev->struct_mutex);
5040 if (ret)
5041 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005042 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005043
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005044 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005045
5046 intel_runtime_pm_put(dev_priv);
David Weinehall36cdd012016-08-22 13:59:31 +03005047 mutex_unlock(&dev->struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005048
Kees Cook647416f2013-03-10 14:10:06 -07005049 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005050
Kees Cook647416f2013-03-10 14:10:06 -07005051 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005052}
5053
Kees Cook647416f2013-03-10 14:10:06 -07005054static int
5055i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005056{
David Weinehall36cdd012016-08-22 13:59:31 +03005057 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005058 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005059
David Weinehall36cdd012016-08-22 13:59:31 +03005060 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005061 return -ENODEV;
5062
Kees Cook647416f2013-03-10 14:10:06 -07005063 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005064 return -EINVAL;
5065
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005066 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005067 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005068
5069 /* Update the cache sharing policy here as well */
5070 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5071 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5072 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5073 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5074
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005075 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005076 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005077}
5078
Kees Cook647416f2013-03-10 14:10:06 -07005079DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5080 i915_cache_sharing_get, i915_cache_sharing_set,
5081 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005082
David Weinehall36cdd012016-08-22 13:59:31 +03005083static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005084 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005085{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005086 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005087 int ss;
5088 u32 sig1[ss_max], sig2[ss_max];
5089
5090 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5091 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5092 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5093 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5094
5095 for (ss = 0; ss < ss_max; ss++) {
5096 unsigned int eu_cnt;
5097
5098 if (sig1[ss] & CHV_SS_PG_ENABLE)
5099 /* skip disabled subslice */
5100 continue;
5101
Imre Deakf08a0c92016-08-31 19:13:04 +03005102 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005103 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005104 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5105 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5106 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5107 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005108 sseu->eu_total += eu_cnt;
5109 sseu->eu_per_subslice = max_t(unsigned int,
5110 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005111 }
Jeff McGee5d395252015-04-03 18:13:17 -07005112}
5113
David Weinehall36cdd012016-08-22 13:59:31 +03005114static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005115 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005116{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005117 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005118 int s, ss;
5119 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5120
Jeff McGee1c046bc2015-04-03 18:13:18 -07005121 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005122 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005123 s_max = 1;
5124 ss_max = 3;
5125 }
5126
5127 for (s = 0; s < s_max; s++) {
5128 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5129 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5130 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5131 }
5132
Jeff McGee5d395252015-04-03 18:13:17 -07005133 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5134 GEN9_PGCTL_SSA_EU19_ACK |
5135 GEN9_PGCTL_SSA_EU210_ACK |
5136 GEN9_PGCTL_SSA_EU311_ACK;
5137 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5138 GEN9_PGCTL_SSB_EU19_ACK |
5139 GEN9_PGCTL_SSB_EU210_ACK |
5140 GEN9_PGCTL_SSB_EU311_ACK;
5141
5142 for (s = 0; s < s_max; s++) {
5143 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5144 /* skip disabled slice */
5145 continue;
5146
Imre Deakf08a0c92016-08-31 19:13:04 +03005147 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005148
David Weinehall36cdd012016-08-22 13:59:31 +03005149 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005150 sseu->subslice_mask =
5151 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005152
Jeff McGee5d395252015-04-03 18:13:17 -07005153 for (ss = 0; ss < ss_max; ss++) {
5154 unsigned int eu_cnt;
5155
Imre Deak57ec1712016-08-31 19:13:05 +03005156 if (IS_BROXTON(dev_priv)) {
5157 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5158 /* skip disabled subslice */
5159 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005160
Imre Deak57ec1712016-08-31 19:13:05 +03005161 sseu->subslice_mask |= BIT(ss);
5162 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005163
Jeff McGee5d395252015-04-03 18:13:17 -07005164 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5165 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005166 sseu->eu_total += eu_cnt;
5167 sseu->eu_per_subslice = max_t(unsigned int,
5168 sseu->eu_per_subslice,
5169 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005170 }
5171 }
5172}
5173
David Weinehall36cdd012016-08-22 13:59:31 +03005174static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005175 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005176{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005177 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005178 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005179
Imre Deakf08a0c92016-08-31 19:13:04 +03005180 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005181
Imre Deakf08a0c92016-08-31 19:13:04 +03005182 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005183 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005184 sseu->eu_per_subslice =
5185 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005186 sseu->eu_total = sseu->eu_per_subslice *
5187 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005188
5189 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005190 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005191 u8 subslice_7eu =
5192 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005193
Imre Deak915490d2016-08-31 19:13:01 +03005194 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005195 }
5196 }
5197}
5198
Imre Deak615d8902016-08-31 19:13:03 +03005199static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5200 const struct sseu_dev_info *sseu)
5201{
5202 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5203 const char *type = is_available_info ? "Available" : "Enabled";
5204
Imre Deakc67ba532016-08-31 19:13:06 +03005205 seq_printf(m, " %s Slice Mask: %04x\n", type,
5206 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005207 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005208 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005209 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005210 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005211 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5212 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005213 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005214 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005215 seq_printf(m, " %s EU Total: %u\n", type,
5216 sseu->eu_total);
5217 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5218 sseu->eu_per_subslice);
5219
5220 if (!is_available_info)
5221 return;
5222
5223 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5224 if (HAS_POOLED_EU(dev_priv))
5225 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5226
5227 seq_printf(m, " Has Slice Power Gating: %s\n",
5228 yesno(sseu->has_slice_pg));
5229 seq_printf(m, " Has Subslice Power Gating: %s\n",
5230 yesno(sseu->has_subslice_pg));
5231 seq_printf(m, " Has EU Power Gating: %s\n",
5232 yesno(sseu->has_eu_pg));
5233}
5234
Jeff McGee38732182015-02-13 10:27:54 -06005235static int i915_sseu_status(struct seq_file *m, void *unused)
5236{
David Weinehall36cdd012016-08-22 13:59:31 +03005237 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005238 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005239
David Weinehall36cdd012016-08-22 13:59:31 +03005240 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005241 return -ENODEV;
5242
5243 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005244 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005245
Jeff McGee7f992ab2015-02-13 10:27:55 -06005246 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005247 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005248
5249 intel_runtime_pm_get(dev_priv);
5250
David Weinehall36cdd012016-08-22 13:59:31 +03005251 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005252 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005253 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005254 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005255 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005256 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005257 }
David Weinehall238010e2016-08-01 17:33:27 +03005258
5259 intel_runtime_pm_put(dev_priv);
5260
Imre Deak615d8902016-08-31 19:13:03 +03005261 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005262
Jeff McGee38732182015-02-13 10:27:54 -06005263 return 0;
5264}
5265
Ben Widawsky6d794d42011-04-25 11:25:56 -07005266static int i915_forcewake_open(struct inode *inode, struct file *file)
5267{
David Weinehall36cdd012016-08-22 13:59:31 +03005268 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005269
David Weinehall36cdd012016-08-22 13:59:31 +03005270 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005271 return 0;
5272
Chris Wilson6daccb02015-01-16 11:34:35 +02005273 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005274 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005275
5276 return 0;
5277}
5278
Ben Widawskyc43b5632012-04-16 14:07:40 -07005279static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005280{
David Weinehall36cdd012016-08-22 13:59:31 +03005281 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005282
David Weinehall36cdd012016-08-22 13:59:31 +03005283 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005284 return 0;
5285
Mika Kuoppala59bad942015-01-16 11:34:40 +02005286 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005287 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005288
5289 return 0;
5290}
5291
5292static const struct file_operations i915_forcewake_fops = {
5293 .owner = THIS_MODULE,
5294 .open = i915_forcewake_open,
5295 .release = i915_forcewake_release,
5296};
5297
5298static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5299{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005300 struct dentry *ent;
5301
5302 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005303 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005304 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005305 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005306 if (!ent)
5307 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005308
Ben Widawsky8eb57292011-05-11 15:10:58 -07005309 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005310}
5311
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005312static int i915_debugfs_create(struct dentry *root,
5313 struct drm_minor *minor,
5314 const char *name,
5315 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005316{
Jesse Barnes358733e2011-07-27 11:53:01 -07005317 struct dentry *ent;
5318
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005319 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005320 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005321 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005322 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005323 if (!ent)
5324 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005325
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005326 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005327}
5328
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005329static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005330 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005331 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005332 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005333 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005334 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005335 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005336 {"i915_gem_request", i915_gem_request_info, 0},
5337 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005338 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005339 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005340 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5341 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5342 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005343 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005344 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005345 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005346 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005347 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305348 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005349 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005350 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005351 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005352 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005353 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005354 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005355 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005356 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005357 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005358 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005359 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005360 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005361 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005362 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005363 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005364 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005365 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005366 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005367 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005368 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005369 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005370 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005371 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005372 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005373 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005374 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005375 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005376 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005377 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005378 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005379 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305380 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005381 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005382};
Ben Gamari27c202a2009-07-01 22:26:52 -04005383#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005384
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005385static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005386 const char *name;
5387 const struct file_operations *fops;
5388} i915_debugfs_files[] = {
5389 {"i915_wedged", &i915_wedged_fops},
5390 {"i915_max_freq", &i915_max_freq_fops},
5391 {"i915_min_freq", &i915_min_freq_fops},
5392 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005393 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5394 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005395 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005396#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005397 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005398#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005399 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005400 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005401 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5402 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5403 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005404 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005405 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5406 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5407 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005408};
5409
David Weinehall36cdd012016-08-22 13:59:31 +03005410void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005411{
Daniel Vetterb3783602013-11-14 11:30:42 +01005412 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005413
Damien Lespiau055e3932014-08-18 13:49:10 +01005414 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005415 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005416
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005417 pipe_crc->opened = false;
5418 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005419 init_waitqueue_head(&pipe_crc->wq);
5420 }
5421}
5422
Chris Wilson1dac8912016-06-24 14:00:17 +01005423int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005424{
Chris Wilson91c8a322016-07-05 10:40:23 +01005425 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005426 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005427
Ben Widawsky6d794d42011-04-25 11:25:56 -07005428 ret = i915_forcewake_create(minor->debugfs_root, minor);
5429 if (ret)
5430 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005431
Damien Lespiau07144422013-10-15 18:55:40 +01005432 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5433 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5434 if (ret)
5435 return ret;
5436 }
5437
Daniel Vetter34b96742013-07-04 20:49:44 +02005438 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5439 ret = i915_debugfs_create(minor->debugfs_root, minor,
5440 i915_debugfs_files[i].name,
5441 i915_debugfs_files[i].fops);
5442 if (ret)
5443 return ret;
5444 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005445
Ben Gamari27c202a2009-07-01 22:26:52 -04005446 return drm_debugfs_create_files(i915_debugfs_list,
5447 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005448 minor->debugfs_root, minor);
5449}
5450
Chris Wilson1dac8912016-06-24 14:00:17 +01005451void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005452{
Chris Wilson91c8a322016-07-05 10:40:23 +01005453 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005454 int i;
5455
Ben Gamari27c202a2009-07-01 22:26:52 -04005456 drm_debugfs_remove_files(i915_debugfs_list,
5457 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005458
David Weinehall36cdd012016-08-22 13:59:31 +03005459 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005460 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005461
Daniel Vettere309a992013-10-16 22:55:51 +02005462 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005463 struct drm_info_list *info_list =
5464 (struct drm_info_list *)&i915_pipe_crc_data[i];
5465
5466 drm_debugfs_remove_files(info_list, 1, minor);
5467 }
5468
Daniel Vetter34b96742013-07-04 20:49:44 +02005469 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5470 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005471 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005472
5473 drm_debugfs_remove_files(info_list, 1, minor);
5474 }
Ben Gamari20172632009-02-17 20:08:50 -05005475}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005476
5477struct dpcd_block {
5478 /* DPCD dump start address. */
5479 unsigned int offset;
5480 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5481 unsigned int end;
5482 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5483 size_t size;
5484 /* Only valid for eDP. */
5485 bool edp;
5486};
5487
5488static const struct dpcd_block i915_dpcd_debug[] = {
5489 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5490 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5491 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5492 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5493 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5494 { .offset = DP_SET_POWER },
5495 { .offset = DP_EDP_DPCD_REV },
5496 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5497 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5498 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5499};
5500
5501static int i915_dpcd_show(struct seq_file *m, void *data)
5502{
5503 struct drm_connector *connector = m->private;
5504 struct intel_dp *intel_dp =
5505 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5506 uint8_t buf[16];
5507 ssize_t err;
5508 int i;
5509
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005510 if (connector->status != connector_status_connected)
5511 return -ENODEV;
5512
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005513 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5514 const struct dpcd_block *b = &i915_dpcd_debug[i];
5515 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5516
5517 if (b->edp &&
5518 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5519 continue;
5520
5521 /* low tech for now */
5522 if (WARN_ON(size > sizeof(buf)))
5523 continue;
5524
5525 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5526 if (err <= 0) {
5527 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5528 size, b->offset, err);
5529 continue;
5530 }
5531
5532 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005533 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005534
5535 return 0;
5536}
5537
5538static int i915_dpcd_open(struct inode *inode, struct file *file)
5539{
5540 return single_open(file, i915_dpcd_show, inode->i_private);
5541}
5542
5543static const struct file_operations i915_dpcd_fops = {
5544 .owner = THIS_MODULE,
5545 .open = i915_dpcd_open,
5546 .read = seq_read,
5547 .llseek = seq_lseek,
5548 .release = single_release,
5549};
5550
David Weinehallecbd6782016-08-23 12:23:56 +03005551static int i915_panel_show(struct seq_file *m, void *data)
5552{
5553 struct drm_connector *connector = m->private;
5554 struct intel_dp *intel_dp =
5555 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5556
5557 if (connector->status != connector_status_connected)
5558 return -ENODEV;
5559
5560 seq_printf(m, "Panel power up delay: %d\n",
5561 intel_dp->panel_power_up_delay);
5562 seq_printf(m, "Panel power down delay: %d\n",
5563 intel_dp->panel_power_down_delay);
5564 seq_printf(m, "Backlight on delay: %d\n",
5565 intel_dp->backlight_on_delay);
5566 seq_printf(m, "Backlight off delay: %d\n",
5567 intel_dp->backlight_off_delay);
5568
5569 return 0;
5570}
5571
5572static int i915_panel_open(struct inode *inode, struct file *file)
5573{
5574 return single_open(file, i915_panel_show, inode->i_private);
5575}
5576
5577static const struct file_operations i915_panel_fops = {
5578 .owner = THIS_MODULE,
5579 .open = i915_panel_open,
5580 .read = seq_read,
5581 .llseek = seq_lseek,
5582 .release = single_release,
5583};
5584
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005585/**
5586 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5587 * @connector: pointer to a registered drm_connector
5588 *
5589 * Cleanup will be done by drm_connector_unregister() through a call to
5590 * drm_debugfs_connector_remove().
5591 *
5592 * Returns 0 on success, negative error codes on error.
5593 */
5594int i915_debugfs_connector_add(struct drm_connector *connector)
5595{
5596 struct dentry *root = connector->debugfs_entry;
5597
5598 /* The connector must have been registered beforehands. */
5599 if (!root)
5600 return -ENODEV;
5601
5602 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5603 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005604 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5605 connector, &i915_dpcd_fops);
5606
5607 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5608 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5609 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005610
5611 return 0;
5612}