blob: 9f5a39209f5222f1d105cb1de77f5f4c961856c5 [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 Wilson275f0392016-10-24 13:42:14 +0100110 return !list_empty(&obj->userfault_link) ? '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);
Akash Goel3b3f1652016-10-13 22:44:48 +0530153 for_each_engine(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;
Akash Goel3b3f1652016-10-13 22:44:48 +0530326 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000327 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800328
329 memset(&stats, 0, sizeof(stats));
330
Akash Goel3b3f1652016-10-13 22:44:48 +0530331 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000332 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100333 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000334 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100335 batch_pool_link)
336 per_file_stats(0, obj, &stats);
337 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100338 }
Brad Volkin493018d2014-12-11 12:13:08 -0800339
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100340 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800341}
342
Chris Wilson15da9562016-05-24 14:53:43 +0100343static int per_file_ctx_stats(int id, void *ptr, void *data)
344{
345 struct i915_gem_context *ctx = ptr;
346 int n;
347
348 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
349 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100350 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100351 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100352 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100353 }
354
355 return 0;
356}
357
358static void print_context_stats(struct seq_file *m,
359 struct drm_i915_private *dev_priv)
360{
David Weinehall36cdd012016-08-22 13:59:31 +0300361 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100362 struct file_stats stats;
363 struct drm_file *file;
364
365 memset(&stats, 0, sizeof(stats));
366
David Weinehall36cdd012016-08-22 13:59:31 +0300367 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100368 if (dev_priv->kernel_context)
369 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
370
David Weinehall36cdd012016-08-22 13:59:31 +0300371 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100372 struct drm_i915_file_private *fpriv = file->driver_priv;
373 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
374 }
David Weinehall36cdd012016-08-22 13:59:31 +0300375 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100376
377 print_file_stats(m, "[k]contexts", stats);
378}
379
David Weinehall36cdd012016-08-22 13:59:31 +0300380static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100381{
David Weinehall36cdd012016-08-22 13:59:31 +0300382 struct drm_i915_private *dev_priv = node_to_i915(m->private);
383 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300384 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100385 u32 count, mapped_count, purgeable_count, dpy_count;
386 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000387 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100388 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100389 int ret;
390
391 ret = mutex_lock_interruptible(&dev->struct_mutex);
392 if (ret)
393 return ret;
394
Chris Wilson3ef7f222016-10-18 13:02:48 +0100395 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000396 dev_priv->mm.object_count,
397 dev_priv->mm.object_memory);
398
Chris Wilson1544c422016-08-15 13:18:16 +0100399 size = count = 0;
400 mapped_size = mapped_count = 0;
401 purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700402 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100403 size += obj->base.size;
404 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200405
Chris Wilsonb7abb712012-08-20 11:33:30 +0200406 if (obj->madv == I915_MADV_DONTNEED) {
407 purgeable_size += obj->base.size;
408 ++purgeable_count;
409 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100410
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100411 if (obj->mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100412 mapped_count++;
413 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100414 }
Chris Wilson6299f992010-11-24 12:23:44 +0000415 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100416 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
417
418 size = count = dpy_size = dpy_count = 0;
419 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
420 size += obj->base.size;
421 ++count;
422
423 if (obj->pin_display) {
424 dpy_size += obj->base.size;
425 ++dpy_count;
426 }
427
428 if (obj->madv == I915_MADV_DONTNEED) {
429 purgeable_size += obj->base.size;
430 ++purgeable_count;
431 }
432
433 if (obj->mapping) {
434 mapped_count++;
435 mapped_size += obj->base.size;
436 }
437 }
438 seq_printf(m, "%u bound objects, %llu bytes\n",
439 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300440 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200441 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100442 seq_printf(m, "%u mapped objects, %llu bytes\n",
443 mapped_count, mapped_size);
444 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
445 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000446
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300447 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300448 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100449
Damien Lespiau267f0c92013-06-24 22:59:48 +0100450 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800451 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200452 mutex_unlock(&dev->struct_mutex);
453
454 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100455 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100456 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
457 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100458 struct drm_i915_file_private *file_priv = file->driver_priv;
459 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900460 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100461
462 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000463 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100464 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100465 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100466 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900467 /*
468 * Although we have a valid reference on file->pid, that does
469 * not guarantee that the task_struct who called get_pid() is
470 * still alive (e.g. get_pid(current) => fork() => exit()).
471 * Therefore, we need to protect this ->comm access using RCU.
472 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100473 mutex_lock(&dev->struct_mutex);
474 request = list_first_entry_or_null(&file_priv->mm.request_list,
475 struct drm_i915_gem_request,
476 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900477 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100478 task = pid_task(request && request->ctx->pid ?
479 request->ctx->pid : file->pid,
480 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800481 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900482 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100483 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100484 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200485 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100486
487 return 0;
488}
489
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100490static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000491{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100492 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300493 struct drm_i915_private *dev_priv = node_to_i915(node);
494 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100495 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000496 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300497 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000498 int count, ret;
499
500 ret = mutex_lock_interruptible(&dev->struct_mutex);
501 if (ret)
502 return ret;
503
504 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700505 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6da84822016-08-15 10:48:44 +0100506 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100507 continue;
508
Damien Lespiau267f0c92013-06-24 22:59:48 +0100509 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000510 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100511 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000512 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100513 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000514 count++;
515 }
516
517 mutex_unlock(&dev->struct_mutex);
518
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300519 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000520 count, total_obj_size, total_gtt_size);
521
522 return 0;
523}
524
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100525static int i915_gem_pageflip_info(struct seq_file *m, void *data)
526{
David Weinehall36cdd012016-08-22 13:59:31 +0300527 struct drm_i915_private *dev_priv = node_to_i915(m->private);
528 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100529 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200530 int ret;
531
532 ret = mutex_lock_interruptible(&dev->struct_mutex);
533 if (ret)
534 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100535
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100536 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800537 const char pipe = pipe_name(crtc->pipe);
538 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200539 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100540
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200541 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200542 work = crtc->flip_work;
543 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800544 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100545 pipe, plane);
546 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200547 u32 pending;
548 u32 addr;
549
550 pending = atomic_read(&work->pending);
551 if (pending) {
552 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
553 pipe, plane);
554 } else {
555 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
556 pipe, plane);
557 }
558 if (work->flip_queued_req) {
559 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
560
561 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
562 engine->name,
563 i915_gem_request_get_seqno(work->flip_queued_req),
564 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100565 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100566 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200567 } else
568 seq_printf(m, "Flip not associated with any ring\n");
569 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
570 work->flip_queued_vblank,
571 work->flip_ready_vblank,
572 intel_crtc_get_vblank_counter(crtc));
573 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
574
David Weinehall36cdd012016-08-22 13:59:31 +0300575 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200576 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
577 else
578 addr = I915_READ(DSPADDR(crtc->plane));
579 seq_printf(m, "Current scanout address 0x%08x\n", addr);
580
581 if (work->pending_flip_obj) {
582 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
583 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100584 }
585 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200586 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100587 }
588
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200589 mutex_unlock(&dev->struct_mutex);
590
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100591 return 0;
592}
593
Brad Volkin493018d2014-12-11 12:13:08 -0800594static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
595{
David Weinehall36cdd012016-08-22 13:59:31 +0300596 struct drm_i915_private *dev_priv = node_to_i915(m->private);
597 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800598 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000599 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530600 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100601 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000602 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800603
604 ret = mutex_lock_interruptible(&dev->struct_mutex);
605 if (ret)
606 return ret;
607
Akash Goel3b3f1652016-10-13 22:44:48 +0530608 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000609 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100610 int count;
611
612 count = 0;
613 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000614 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100615 batch_pool_link)
616 count++;
617 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000618 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100619
620 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000621 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100622 batch_pool_link) {
623 seq_puts(m, " ");
624 describe_obj(m, obj);
625 seq_putc(m, '\n');
626 }
627
628 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100629 }
Brad Volkin493018d2014-12-11 12:13:08 -0800630 }
631
Chris Wilson8d9d5742015-04-07 16:20:38 +0100632 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800633
634 mutex_unlock(&dev->struct_mutex);
635
636 return 0;
637}
638
Chris Wilson1b365952016-10-04 21:11:31 +0100639static void print_request(struct seq_file *m,
640 struct drm_i915_gem_request *rq,
641 const char *prefix)
642{
643 struct pid *pid = rq->ctx->pid;
644 struct task_struct *task;
645
646 rcu_read_lock();
647 task = pid ? pid_task(pid, PIDTYPE_PID) : NULL;
648 seq_printf(m, "%s%x [%x:%x] @ %d: %s [%d]\n", prefix,
649 rq->fence.seqno, rq->ctx->hw_id, rq->fence.seqno,
650 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
651 task ? task->comm : "<unknown>",
652 task ? task->pid : -1);
653 rcu_read_unlock();
654}
655
Ben Gamari20172632009-02-17 20:08:50 -0500656static int i915_gem_request_info(struct seq_file *m, void *data)
657{
David Weinehall36cdd012016-08-22 13:59:31 +0300658 struct drm_i915_private *dev_priv = node_to_i915(m->private);
659 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200660 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530661 struct intel_engine_cs *engine;
662 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000663 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100664
665 ret = mutex_lock_interruptible(&dev->struct_mutex);
666 if (ret)
667 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500668
Chris Wilson2d1070b2015-04-01 10:36:56 +0100669 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530670 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100671 int count;
672
673 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100674 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100675 count++;
676 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100677 continue;
678
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000679 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson1b365952016-10-04 21:11:31 +0100680 list_for_each_entry(req, &engine->request_list, link)
681 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100682
683 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500684 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100685 mutex_unlock(&dev->struct_mutex);
686
Chris Wilson2d1070b2015-04-01 10:36:56 +0100687 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100688 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100689
Ben Gamari20172632009-02-17 20:08:50 -0500690 return 0;
691}
692
Chris Wilsonb2223492010-10-27 15:27:33 +0100693static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000694 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100695{
Chris Wilson688e6c72016-07-01 17:23:15 +0100696 struct intel_breadcrumbs *b = &engine->breadcrumbs;
697 struct rb_node *rb;
698
Chris Wilson12471ba2016-04-09 10:57:55 +0100699 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100700 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100701
702 spin_lock(&b->lock);
703 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
704 struct intel_wait *w = container_of(rb, typeof(*w), node);
705
706 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
707 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
708 }
709 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100710}
711
Ben Gamari20172632009-02-17 20:08:50 -0500712static int i915_gem_seqno_info(struct seq_file *m, void *data)
713{
David Weinehall36cdd012016-08-22 13:59:31 +0300714 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000715 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530716 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500717
Akash Goel3b3f1652016-10-13 22:44:48 +0530718 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000719 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100720
Ben Gamari20172632009-02-17 20:08:50 -0500721 return 0;
722}
723
724
725static int i915_interrupt_info(struct seq_file *m, void *data)
726{
David Weinehall36cdd012016-08-22 13:59:31 +0300727 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000728 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530729 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100730 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100731
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200732 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500733
David Weinehall36cdd012016-08-22 13:59:31 +0300734 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300735 seq_printf(m, "Master Interrupt Control:\t%08x\n",
736 I915_READ(GEN8_MASTER_IRQ));
737
738 seq_printf(m, "Display IER:\t%08x\n",
739 I915_READ(VLV_IER));
740 seq_printf(m, "Display IIR:\t%08x\n",
741 I915_READ(VLV_IIR));
742 seq_printf(m, "Display IIR_RW:\t%08x\n",
743 I915_READ(VLV_IIR_RW));
744 seq_printf(m, "Display IMR:\t%08x\n",
745 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100746 for_each_pipe(dev_priv, pipe) {
747 enum intel_display_power_domain power_domain;
748
749 power_domain = POWER_DOMAIN_PIPE(pipe);
750 if (!intel_display_power_get_if_enabled(dev_priv,
751 power_domain)) {
752 seq_printf(m, "Pipe %c power disabled\n",
753 pipe_name(pipe));
754 continue;
755 }
756
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300757 seq_printf(m, "Pipe %c stat:\t%08x\n",
758 pipe_name(pipe),
759 I915_READ(PIPESTAT(pipe)));
760
Chris Wilson9c870d02016-10-24 13:42:15 +0100761 intel_display_power_put(dev_priv, power_domain);
762 }
763
764 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300765 seq_printf(m, "Port hotplug:\t%08x\n",
766 I915_READ(PORT_HOTPLUG_EN));
767 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
768 I915_READ(VLV_DPFLIPSTAT));
769 seq_printf(m, "DPINVGTT:\t%08x\n",
770 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100771 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300772
773 for (i = 0; i < 4; i++) {
774 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
775 i, I915_READ(GEN8_GT_IMR(i)));
776 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
777 i, I915_READ(GEN8_GT_IIR(i)));
778 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
779 i, I915_READ(GEN8_GT_IER(i)));
780 }
781
782 seq_printf(m, "PCU interrupt mask:\t%08x\n",
783 I915_READ(GEN8_PCU_IMR));
784 seq_printf(m, "PCU interrupt identity:\t%08x\n",
785 I915_READ(GEN8_PCU_IIR));
786 seq_printf(m, "PCU interrupt enable:\t%08x\n",
787 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300788 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700789 seq_printf(m, "Master Interrupt Control:\t%08x\n",
790 I915_READ(GEN8_MASTER_IRQ));
791
792 for (i = 0; i < 4; i++) {
793 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
794 i, I915_READ(GEN8_GT_IMR(i)));
795 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
796 i, I915_READ(GEN8_GT_IIR(i)));
797 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
798 i, I915_READ(GEN8_GT_IER(i)));
799 }
800
Damien Lespiau055e3932014-08-18 13:49:10 +0100801 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200802 enum intel_display_power_domain power_domain;
803
804 power_domain = POWER_DOMAIN_PIPE(pipe);
805 if (!intel_display_power_get_if_enabled(dev_priv,
806 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300807 seq_printf(m, "Pipe %c power disabled\n",
808 pipe_name(pipe));
809 continue;
810 }
Ben Widawskya123f152013-11-02 21:07:10 -0700811 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000812 pipe_name(pipe),
813 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700814 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000815 pipe_name(pipe),
816 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700817 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000818 pipe_name(pipe),
819 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200820
821 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700822 }
823
824 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
825 I915_READ(GEN8_DE_PORT_IMR));
826 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
827 I915_READ(GEN8_DE_PORT_IIR));
828 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
829 I915_READ(GEN8_DE_PORT_IER));
830
831 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
832 I915_READ(GEN8_DE_MISC_IMR));
833 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
834 I915_READ(GEN8_DE_MISC_IIR));
835 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
836 I915_READ(GEN8_DE_MISC_IER));
837
838 seq_printf(m, "PCU interrupt mask:\t%08x\n",
839 I915_READ(GEN8_PCU_IMR));
840 seq_printf(m, "PCU interrupt identity:\t%08x\n",
841 I915_READ(GEN8_PCU_IIR));
842 seq_printf(m, "PCU interrupt enable:\t%08x\n",
843 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300844 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700845 seq_printf(m, "Display IER:\t%08x\n",
846 I915_READ(VLV_IER));
847 seq_printf(m, "Display IIR:\t%08x\n",
848 I915_READ(VLV_IIR));
849 seq_printf(m, "Display IIR_RW:\t%08x\n",
850 I915_READ(VLV_IIR_RW));
851 seq_printf(m, "Display IMR:\t%08x\n",
852 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100853 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700854 seq_printf(m, "Pipe %c stat:\t%08x\n",
855 pipe_name(pipe),
856 I915_READ(PIPESTAT(pipe)));
857
858 seq_printf(m, "Master IER:\t%08x\n",
859 I915_READ(VLV_MASTER_IER));
860
861 seq_printf(m, "Render IER:\t%08x\n",
862 I915_READ(GTIER));
863 seq_printf(m, "Render IIR:\t%08x\n",
864 I915_READ(GTIIR));
865 seq_printf(m, "Render IMR:\t%08x\n",
866 I915_READ(GTIMR));
867
868 seq_printf(m, "PM IER:\t\t%08x\n",
869 I915_READ(GEN6_PMIER));
870 seq_printf(m, "PM IIR:\t\t%08x\n",
871 I915_READ(GEN6_PMIIR));
872 seq_printf(m, "PM IMR:\t\t%08x\n",
873 I915_READ(GEN6_PMIMR));
874
875 seq_printf(m, "Port hotplug:\t%08x\n",
876 I915_READ(PORT_HOTPLUG_EN));
877 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
878 I915_READ(VLV_DPFLIPSTAT));
879 seq_printf(m, "DPINVGTT:\t%08x\n",
880 I915_READ(DPINVGTT));
881
David Weinehall36cdd012016-08-22 13:59:31 +0300882 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800883 seq_printf(m, "Interrupt enable: %08x\n",
884 I915_READ(IER));
885 seq_printf(m, "Interrupt identity: %08x\n",
886 I915_READ(IIR));
887 seq_printf(m, "Interrupt mask: %08x\n",
888 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100889 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800890 seq_printf(m, "Pipe %c stat: %08x\n",
891 pipe_name(pipe),
892 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800893 } else {
894 seq_printf(m, "North Display Interrupt enable: %08x\n",
895 I915_READ(DEIER));
896 seq_printf(m, "North Display Interrupt identity: %08x\n",
897 I915_READ(DEIIR));
898 seq_printf(m, "North Display Interrupt mask: %08x\n",
899 I915_READ(DEIMR));
900 seq_printf(m, "South Display Interrupt enable: %08x\n",
901 I915_READ(SDEIER));
902 seq_printf(m, "South Display Interrupt identity: %08x\n",
903 I915_READ(SDEIIR));
904 seq_printf(m, "South Display Interrupt mask: %08x\n",
905 I915_READ(SDEIMR));
906 seq_printf(m, "Graphics Interrupt enable: %08x\n",
907 I915_READ(GTIER));
908 seq_printf(m, "Graphics Interrupt identity: %08x\n",
909 I915_READ(GTIIR));
910 seq_printf(m, "Graphics Interrupt mask: %08x\n",
911 I915_READ(GTIMR));
912 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530913 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300914 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100915 seq_printf(m,
916 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000917 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000918 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000919 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000920 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200921 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100922
Ben Gamari20172632009-02-17 20:08:50 -0500923 return 0;
924}
925
Chris Wilsona6172a82009-02-11 14:26:38 +0000926static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
927{
David Weinehall36cdd012016-08-22 13:59:31 +0300928 struct drm_i915_private *dev_priv = node_to_i915(m->private);
929 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100930 int i, ret;
931
932 ret = mutex_lock_interruptible(&dev->struct_mutex);
933 if (ret)
934 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000935
Chris Wilsona6172a82009-02-11 14:26:38 +0000936 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
937 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100938 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000939
Chris Wilson6c085a72012-08-20 11:40:46 +0200940 seq_printf(m, "Fence %d, pin count = %d, object = ",
941 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100942 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100943 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100944 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100945 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100946 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000947 }
948
Chris Wilson05394f32010-11-08 19:18:58 +0000949 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000950 return 0;
951}
952
Ben Gamari20172632009-02-17 20:08:50 -0500953static int i915_hws_info(struct seq_file *m, void *data)
954{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100955 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300956 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000957 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100958 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100959 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500960
Akash Goel3b3f1652016-10-13 22:44:48 +0530961 engine = dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000962 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500963 if (hws == NULL)
964 return 0;
965
966 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
967 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
968 i * 4,
969 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
970 }
971 return 0;
972}
973
Chris Wilson98a2f412016-10-12 10:05:18 +0100974#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
975
Daniel Vetterd5442302012-04-27 15:17:40 +0200976static ssize_t
977i915_error_state_write(struct file *filp,
978 const char __user *ubuf,
979 size_t cnt,
980 loff_t *ppos)
981{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300982 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200983
984 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100985 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200986
987 return cnt;
988}
989
990static int i915_error_state_open(struct inode *inode, struct file *file)
991{
David Weinehall36cdd012016-08-22 13:59:31 +0300992 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200993 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200994
995 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
996 if (!error_priv)
997 return -ENOMEM;
998
David Weinehall36cdd012016-08-22 13:59:31 +0300999 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +02001000
David Weinehall36cdd012016-08-22 13:59:31 +03001001 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001002
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001003 file->private_data = error_priv;
1004
1005 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001006}
1007
1008static int i915_error_state_release(struct inode *inode, struct file *file)
1009{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001010 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001011
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001012 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001013 kfree(error_priv);
1014
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001015 return 0;
1016}
1017
1018static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1019 size_t count, loff_t *pos)
1020{
1021 struct i915_error_state_file_priv *error_priv = file->private_data;
1022 struct drm_i915_error_state_buf error_str;
1023 loff_t tmp_pos = 0;
1024 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001025 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001026
David Weinehall36cdd012016-08-22 13:59:31 +03001027 ret = i915_error_state_buf_init(&error_str,
1028 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001029 if (ret)
1030 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001031
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001032 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001033 if (ret)
1034 goto out;
1035
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001036 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1037 error_str.buf,
1038 error_str.bytes);
1039
1040 if (ret_count < 0)
1041 ret = ret_count;
1042 else
1043 *pos = error_str.start + ret_count;
1044out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001045 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001046 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001047}
1048
1049static const struct file_operations i915_error_state_fops = {
1050 .owner = THIS_MODULE,
1051 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001052 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001053 .write = i915_error_state_write,
1054 .llseek = default_llseek,
1055 .release = i915_error_state_release,
1056};
1057
Chris Wilson98a2f412016-10-12 10:05:18 +01001058#endif
1059
Kees Cook647416f2013-03-10 14:10:06 -07001060static int
1061i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001062{
David Weinehall36cdd012016-08-22 13:59:31 +03001063 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001064 int ret;
1065
David Weinehall36cdd012016-08-22 13:59:31 +03001066 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001067 if (ret)
1068 return ret;
1069
Kees Cook647416f2013-03-10 14:10:06 -07001070 *val = dev_priv->next_seqno;
David Weinehall36cdd012016-08-22 13:59:31 +03001071 mutex_unlock(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001072
Kees Cook647416f2013-03-10 14:10:06 -07001073 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001074}
1075
Kees Cook647416f2013-03-10 14:10:06 -07001076static int
1077i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001078{
David Weinehall36cdd012016-08-22 13:59:31 +03001079 struct drm_i915_private *dev_priv = data;
1080 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001081 int ret;
1082
Mika Kuoppala40633212012-12-04 15:12:00 +02001083 ret = mutex_lock_interruptible(&dev->struct_mutex);
1084 if (ret)
1085 return ret;
1086
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001087 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001088 mutex_unlock(&dev->struct_mutex);
1089
Kees Cook647416f2013-03-10 14:10:06 -07001090 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001091}
1092
Kees Cook647416f2013-03-10 14:10:06 -07001093DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1094 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001095 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001096
Deepak Sadb4bd12014-03-31 11:30:02 +05301097static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001098{
David Weinehall36cdd012016-08-22 13:59:31 +03001099 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1100 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001101 int ret = 0;
1102
1103 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001104
David Weinehall36cdd012016-08-22 13:59:31 +03001105 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001106 u16 rgvswctl = I915_READ16(MEMSWCTL);
1107 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1108
1109 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1110 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1111 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1112 MEMSTAT_VID_SHIFT);
1113 seq_printf(m, "Current P-state: %d\n",
1114 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001115 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001116 u32 freq_sts;
1117
1118 mutex_lock(&dev_priv->rps.hw_lock);
1119 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1120 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1121 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1122
1123 seq_printf(m, "actual GPU freq: %d MHz\n",
1124 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1125
1126 seq_printf(m, "current GPU freq: %d MHz\n",
1127 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1128
1129 seq_printf(m, "max GPU freq: %d MHz\n",
1130 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1131
1132 seq_printf(m, "min GPU freq: %d MHz\n",
1133 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1134
1135 seq_printf(m, "idle GPU freq: %d MHz\n",
1136 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1137
1138 seq_printf(m,
1139 "efficient (RPe) frequency: %d MHz\n",
1140 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1141 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001142 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001143 u32 rp_state_limits;
1144 u32 gt_perf_status;
1145 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001146 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001147 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001148 u32 rpupei, rpcurup, rpprevup;
1149 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001150 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001151 int max_freq;
1152
Bob Paauwe35040562015-06-25 14:54:07 -07001153 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001154 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001155 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1156 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1157 } else {
1158 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1159 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1160 }
1161
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001162 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001163 ret = mutex_lock_interruptible(&dev->struct_mutex);
1164 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001165 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001166
Mika Kuoppala59bad942015-01-16 11:34:40 +02001167 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001168
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001169 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001170 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301171 reqf >>= 23;
1172 else {
1173 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001174 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301175 reqf >>= 24;
1176 else
1177 reqf >>= 25;
1178 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001179 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001180
Chris Wilson0d8f9492014-03-27 09:06:14 +00001181 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1182 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1183 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1184
Jesse Barnesccab5c82011-01-18 15:49:25 -08001185 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301186 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1187 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1188 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1189 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1190 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1191 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001192 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301193 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001194 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001195 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1196 else
1197 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001198 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001199
Mika Kuoppala59bad942015-01-16 11:34:40 +02001200 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001201 mutex_unlock(&dev->struct_mutex);
1202
David Weinehall36cdd012016-08-22 13:59:31 +03001203 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001204 pm_ier = I915_READ(GEN6_PMIER);
1205 pm_imr = I915_READ(GEN6_PMIMR);
1206 pm_isr = I915_READ(GEN6_PMISR);
1207 pm_iir = I915_READ(GEN6_PMIIR);
1208 pm_mask = I915_READ(GEN6_PMINTRMSK);
1209 } else {
1210 pm_ier = I915_READ(GEN8_GT_IER(2));
1211 pm_imr = I915_READ(GEN8_GT_IMR(2));
1212 pm_isr = I915_READ(GEN8_GT_ISR(2));
1213 pm_iir = I915_READ(GEN8_GT_IIR(2));
1214 pm_mask = I915_READ(GEN6_PMINTRMSK);
1215 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001216 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 -03001217 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301218 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001219 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001220 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001221 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001222 seq_printf(m, "Render p-state VID: %d\n",
1223 gt_perf_status & 0xff);
1224 seq_printf(m, "Render p-state limit: %d\n",
1225 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001226 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1227 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1228 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1229 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001230 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001231 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301232 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1233 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1234 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1235 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1236 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1237 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001238 seq_printf(m, "Up threshold: %d%%\n",
1239 dev_priv->rps.up_threshold);
1240
Akash Goeld6cda9c2016-04-23 00:05:46 +05301241 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1242 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1243 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1244 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1245 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1246 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001247 seq_printf(m, "Down threshold: %d%%\n",
1248 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001249
David Weinehall36cdd012016-08-22 13:59:31 +03001250 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001251 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001252 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001253 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001254 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001255 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001256
1257 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001258 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001259 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001261 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001262
David Weinehall36cdd012016-08-22 13:59:31 +03001263 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001264 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001265 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001266 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001267 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001268 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001269 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001270 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001271
Chris Wilsond86ed342015-04-27 13:41:19 +01001272 seq_printf(m, "Current freq: %d MHz\n",
1273 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1274 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001275 seq_printf(m, "Idle freq: %d MHz\n",
1276 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001277 seq_printf(m, "Min freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001279 seq_printf(m, "Boost freq: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001281 seq_printf(m, "Max freq: %d MHz\n",
1282 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1283 seq_printf(m,
1284 "efficient (RPe) frequency: %d MHz\n",
1285 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001286 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001287 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001288 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001289
Mika Kahola1170f282015-09-25 14:00:32 +03001290 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1291 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1292 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1293
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001294out:
1295 intel_runtime_pm_put(dev_priv);
1296 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001297}
1298
Ben Widawskyd6369512016-09-20 16:54:32 +03001299static void i915_instdone_info(struct drm_i915_private *dev_priv,
1300 struct seq_file *m,
1301 struct intel_instdone *instdone)
1302{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001303 int slice;
1304 int subslice;
1305
Ben Widawskyd6369512016-09-20 16:54:32 +03001306 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1307 instdone->instdone);
1308
1309 if (INTEL_GEN(dev_priv) <= 3)
1310 return;
1311
1312 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1313 instdone->slice_common);
1314
1315 if (INTEL_GEN(dev_priv) <= 6)
1316 return;
1317
Ben Widawskyf9e61372016-09-20 16:54:33 +03001318 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1319 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1320 slice, subslice, instdone->sampler[slice][subslice]);
1321
1322 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1323 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1324 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001325}
1326
Chris Wilsonf6544492015-01-26 18:03:04 +02001327static int i915_hangcheck_info(struct seq_file *m, void *unused)
1328{
David Weinehall36cdd012016-08-22 13:59:31 +03001329 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001330 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001331 u64 acthd[I915_NUM_ENGINES];
1332 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001333 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001334 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001335
Chris Wilson8af29b02016-09-09 14:11:47 +01001336 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1337 seq_printf(m, "Wedged\n");
1338 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1339 seq_printf(m, "Reset in progress\n");
1340 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1341 seq_printf(m, "Waiter holding struct mutex\n");
1342 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1343 seq_printf(m, "struct_mutex blocked for reset\n");
1344
Chris Wilsonf6544492015-01-26 18:03:04 +02001345 if (!i915.enable_hangcheck) {
1346 seq_printf(m, "Hangcheck disabled\n");
1347 return 0;
1348 }
1349
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001350 intel_runtime_pm_get(dev_priv);
1351
Akash Goel3b3f1652016-10-13 22:44:48 +05301352 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001353 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001354 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001355 }
1356
Akash Goel3b3f1652016-10-13 22:44:48 +05301357 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001358
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001359 intel_runtime_pm_put(dev_priv);
1360
Chris Wilsonf6544492015-01-26 18:03:04 +02001361 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1362 seq_printf(m, "Hangcheck active, fires in %dms\n",
1363 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1364 jiffies));
1365 } else
1366 seq_printf(m, "Hangcheck inactive\n");
1367
Akash Goel3b3f1652016-10-13 22:44:48 +05301368 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001369 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1370 struct rb_node *rb;
1371
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001372 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001373 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1374 engine->hangcheck.seqno,
1375 seqno[id],
1376 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001377 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1378 yesno(intel_engine_has_waiter(engine)),
1379 yesno(test_bit(engine->id,
1380 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilson33f53712016-10-04 21:11:32 +01001381 spin_lock(&b->lock);
1382 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1383 struct intel_wait *w = container_of(rb, typeof(*w), node);
1384
1385 seq_printf(m, "\t%s [%d] waiting for %x\n",
1386 w->tsk->comm, w->tsk->pid, w->seqno);
1387 }
1388 spin_unlock(&b->lock);
1389
Chris Wilsonf6544492015-01-26 18:03:04 +02001390 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001391 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001392 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001393 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1394 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001395
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001396 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001397 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001398
Ben Widawskyd6369512016-09-20 16:54:32 +03001399 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001400
Ben Widawskyd6369512016-09-20 16:54:32 +03001401 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001402
Ben Widawskyd6369512016-09-20 16:54:32 +03001403 i915_instdone_info(dev_priv, m,
1404 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001405 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001406 }
1407
1408 return 0;
1409}
1410
Ben Widawsky4d855292011-12-12 19:34:16 -08001411static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001412{
David Weinehall36cdd012016-08-22 13:59:31 +03001413 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001414 u32 rgvmodectl, rstdbyctl;
1415 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001416
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001417 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001418
1419 rgvmodectl = I915_READ(MEMMODECTL);
1420 rstdbyctl = I915_READ(RSTDBYCTL);
1421 crstandvid = I915_READ16(CRSTANDVID);
1422
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001423 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001424
Jani Nikula742f4912015-09-03 11:16:09 +03001425 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426 seq_printf(m, "Boost freq: %d\n",
1427 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1428 MEMMODE_BOOST_FREQ_SHIFT);
1429 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001430 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001431 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001432 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001433 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001434 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001435 seq_printf(m, "Starting frequency: P%d\n",
1436 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001437 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001438 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001439 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1440 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1441 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1442 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001443 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 switch (rstdbyctl & RSX_STATUS_MASK) {
1446 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 break;
1449 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001457 break;
1458 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001459 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001460 break;
1461 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001462 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001463 break;
1464 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001465 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001466 break;
1467 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001468
1469 return 0;
1470}
1471
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001472static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001473{
David Weinehall36cdd012016-08-22 13:59:31 +03001474 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001475 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001476
1477 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001478 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001479 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001480 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001481 fw_domain->wake_count);
1482 }
1483 spin_unlock_irq(&dev_priv->uncore.lock);
1484
1485 return 0;
1486}
1487
Deepak S669ab5a2014-01-10 15:18:26 +05301488static int vlv_drpc_info(struct seq_file *m)
1489{
David Weinehall36cdd012016-08-22 13:59:31 +03001490 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001491 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301492
Imre Deakd46c0512014-04-14 20:24:27 +03001493 intel_runtime_pm_get(dev_priv);
1494
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001495 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301496 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1497 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1498
Imre Deakd46c0512014-04-14 20:24:27 +03001499 intel_runtime_pm_put(dev_priv);
1500
Deepak S669ab5a2014-01-10 15:18:26 +05301501 seq_printf(m, "Video Turbo Mode: %s\n",
1502 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1503 seq_printf(m, "Turbo enabled: %s\n",
1504 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1505 seq_printf(m, "HW control enabled: %s\n",
1506 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1507 seq_printf(m, "SW control enabled: %s\n",
1508 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1509 GEN6_RP_MEDIA_SW_MODE));
1510 seq_printf(m, "RC6 Enabled: %s\n",
1511 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1512 GEN6_RC_CTL_EI_MODE(1))));
1513 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001514 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301515 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001516 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301517
Imre Deak9cc19be2014-04-14 20:24:24 +03001518 seq_printf(m, "Render RC6 residency since boot: %u\n",
1519 I915_READ(VLV_GT_RENDER_RC6));
1520 seq_printf(m, "Media RC6 residency since boot: %u\n",
1521 I915_READ(VLV_GT_MEDIA_RC6));
1522
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001523 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301524}
1525
Ben Widawsky4d855292011-12-12 19:34:16 -08001526static int gen6_drpc_info(struct seq_file *m)
1527{
David Weinehall36cdd012016-08-22 13:59:31 +03001528 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1529 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001530 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301531 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001532 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001533 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001534
1535 ret = mutex_lock_interruptible(&dev->struct_mutex);
1536 if (ret)
1537 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001538 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001539
Chris Wilson907b28c2013-07-19 20:36:52 +01001540 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001541 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001542 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001543
1544 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "RC information inaccurate because somebody "
1546 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 } else {
1548 /* NB: we cannot use forcewake, else we read the wrong values */
1549 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1550 udelay(10);
1551 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1552 }
1553
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001554 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001555 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001556
1557 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1558 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001559 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301560 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1561 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1562 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001564 mutex_lock(&dev_priv->rps.hw_lock);
1565 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1566 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001567
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001568 intel_runtime_pm_put(dev_priv);
1569
Ben Widawsky4d855292011-12-12 19:34:16 -08001570 seq_printf(m, "Video Turbo Mode: %s\n",
1571 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1572 seq_printf(m, "HW control enabled: %s\n",
1573 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1574 seq_printf(m, "SW control enabled: %s\n",
1575 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1576 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001577 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001578 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1579 seq_printf(m, "RC6 Enabled: %s\n",
1580 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001581 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301582 seq_printf(m, "Render Well Gating Enabled: %s\n",
1583 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1584 seq_printf(m, "Media Well Gating Enabled: %s\n",
1585 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1586 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 seq_printf(m, "Deep RC6 Enabled: %s\n",
1588 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1589 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1590 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001591 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001592 switch (gt_core_status & GEN6_RCn_MASK) {
1593 case GEN6_RC0:
1594 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001596 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001597 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001598 break;
1599 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001600 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001601 break;
1602 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001603 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001604 break;
1605 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001606 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001607 break;
1608 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001609 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001610 break;
1611 }
1612
1613 seq_printf(m, "Core Power Down: %s\n",
1614 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001615 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301616 seq_printf(m, "Render Power Well: %s\n",
1617 (gen9_powergate_status &
1618 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1619 seq_printf(m, "Media Power Well: %s\n",
1620 (gen9_powergate_status &
1621 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1622 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001623
1624 /* Not exactly sure what this is */
1625 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1626 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1627 seq_printf(m, "RC6 residency since boot: %u\n",
1628 I915_READ(GEN6_GT_GFX_RC6));
1629 seq_printf(m, "RC6+ residency since boot: %u\n",
1630 I915_READ(GEN6_GT_GFX_RC6p));
1631 seq_printf(m, "RC6++ residency since boot: %u\n",
1632 I915_READ(GEN6_GT_GFX_RC6pp));
1633
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001634 seq_printf(m, "RC6 voltage: %dmV\n",
1635 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1636 seq_printf(m, "RC6+ voltage: %dmV\n",
1637 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1638 seq_printf(m, "RC6++ voltage: %dmV\n",
1639 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301640 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001641}
1642
1643static int i915_drpc_info(struct seq_file *m, void *unused)
1644{
David Weinehall36cdd012016-08-22 13:59:31 +03001645 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001646
David Weinehall36cdd012016-08-22 13:59:31 +03001647 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301648 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001649 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001650 return gen6_drpc_info(m);
1651 else
1652 return ironlake_drpc_info(m);
1653}
1654
Daniel Vetter9a851782015-06-18 10:30:22 +02001655static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1656{
David Weinehall36cdd012016-08-22 13:59:31 +03001657 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001658
1659 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1660 dev_priv->fb_tracking.busy_bits);
1661
1662 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1663 dev_priv->fb_tracking.flip_bits);
1664
1665 return 0;
1666}
1667
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001668static int i915_fbc_status(struct seq_file *m, void *unused)
1669{
David Weinehall36cdd012016-08-22 13:59:31 +03001670 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001671
David Weinehall36cdd012016-08-22 13:59:31 +03001672 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001673 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001674 return 0;
1675 }
1676
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001677 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001678 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001679
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001680 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001681 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001682 else
1683 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001684 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001685
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001686 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1687 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1688 BDW_FBC_COMPRESSION_MASK :
1689 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001690 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001691 yesno(I915_READ(FBC_STATUS2) & mask));
1692 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001693
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001694 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001695 intel_runtime_pm_put(dev_priv);
1696
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001697 return 0;
1698}
1699
Rodrigo Vivida46f932014-08-01 02:04:45 -07001700static int i915_fbc_fc_get(void *data, u64 *val)
1701{
David Weinehall36cdd012016-08-22 13:59:31 +03001702 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001703
David Weinehall36cdd012016-08-22 13:59:31 +03001704 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001705 return -ENODEV;
1706
Rodrigo Vivida46f932014-08-01 02:04:45 -07001707 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001708
1709 return 0;
1710}
1711
1712static int i915_fbc_fc_set(void *data, u64 val)
1713{
David Weinehall36cdd012016-08-22 13:59:31 +03001714 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001715 u32 reg;
1716
David Weinehall36cdd012016-08-22 13:59:31 +03001717 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001718 return -ENODEV;
1719
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001720 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001721
1722 reg = I915_READ(ILK_DPFC_CONTROL);
1723 dev_priv->fbc.false_color = val;
1724
1725 I915_WRITE(ILK_DPFC_CONTROL, val ?
1726 (reg | FBC_CTL_FALSE_COLOR) :
1727 (reg & ~FBC_CTL_FALSE_COLOR));
1728
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001729 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001730 return 0;
1731}
1732
1733DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1734 i915_fbc_fc_get, i915_fbc_fc_set,
1735 "%llu\n");
1736
Paulo Zanoni92d44622013-05-31 16:33:24 -03001737static int i915_ips_status(struct seq_file *m, void *unused)
1738{
David Weinehall36cdd012016-08-22 13:59:31 +03001739 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001740
David Weinehall36cdd012016-08-22 13:59:31 +03001741 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001742 seq_puts(m, "not supported\n");
1743 return 0;
1744 }
1745
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001746 intel_runtime_pm_get(dev_priv);
1747
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001748 seq_printf(m, "Enabled by kernel parameter: %s\n",
1749 yesno(i915.enable_ips));
1750
David Weinehall36cdd012016-08-22 13:59:31 +03001751 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001752 seq_puts(m, "Currently: unknown\n");
1753 } else {
1754 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1755 seq_puts(m, "Currently: enabled\n");
1756 else
1757 seq_puts(m, "Currently: disabled\n");
1758 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001759
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001760 intel_runtime_pm_put(dev_priv);
1761
Paulo Zanoni92d44622013-05-31 16:33:24 -03001762 return 0;
1763}
1764
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001765static int i915_sr_status(struct seq_file *m, void *unused)
1766{
David Weinehall36cdd012016-08-22 13:59:31 +03001767 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001768 bool sr_enabled = false;
1769
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001770 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001771 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001772
David Weinehall36cdd012016-08-22 13:59:31 +03001773 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001774 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001775 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1776 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001777 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001778 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001779 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001780 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001781 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001782 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001783 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001784
Chris Wilson9c870d02016-10-24 13:42:15 +01001785 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001786 intel_runtime_pm_put(dev_priv);
1787
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001788 seq_printf(m, "self-refresh: %s\n",
1789 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001790
1791 return 0;
1792}
1793
Jesse Barnes7648fa92010-05-20 14:28:11 -07001794static int i915_emon_status(struct seq_file *m, void *unused)
1795{
David Weinehall36cdd012016-08-22 13:59:31 +03001796 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1797 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001798 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001799 int ret;
1800
David Weinehall36cdd012016-08-22 13:59:31 +03001801 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001802 return -ENODEV;
1803
Chris Wilsonde227ef2010-07-03 07:58:38 +01001804 ret = mutex_lock_interruptible(&dev->struct_mutex);
1805 if (ret)
1806 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001807
1808 temp = i915_mch_val(dev_priv);
1809 chipset = i915_chipset_val(dev_priv);
1810 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001811 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001812
1813 seq_printf(m, "GMCH temp: %ld\n", temp);
1814 seq_printf(m, "Chipset power: %ld\n", chipset);
1815 seq_printf(m, "GFX power: %ld\n", gfx);
1816 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1817
1818 return 0;
1819}
1820
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001821static int i915_ring_freq_table(struct seq_file *m, void *unused)
1822{
David Weinehall36cdd012016-08-22 13:59:31 +03001823 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001824 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001825 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301826 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827
Carlos Santa26310342016-08-17 12:30:41 -07001828 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001829 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001830 return 0;
1831 }
1832
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001833 intel_runtime_pm_get(dev_priv);
1834
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001835 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001836 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001837 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001838
David Weinehall36cdd012016-08-22 13:59:31 +03001839 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301840 /* Convert GT frequency to 50 HZ units */
1841 min_gpu_freq =
1842 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1843 max_gpu_freq =
1844 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1845 } else {
1846 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1847 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1848 }
1849
Damien Lespiau267f0c92013-06-24 22:59:48 +01001850 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001851
Akash Goelf936ec32015-06-29 14:50:22 +05301852 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001853 ia_freq = gpu_freq;
1854 sandybridge_pcode_read(dev_priv,
1855 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1856 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001857 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301858 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001859 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001860 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001861 ((ia_freq >> 0) & 0xff) * 100,
1862 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001863 }
1864
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001865 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001866
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001867out:
1868 intel_runtime_pm_put(dev_priv);
1869 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001870}
1871
Chris Wilson44834a62010-08-19 16:09:23 +01001872static int i915_opregion(struct seq_file *m, void *unused)
1873{
David Weinehall36cdd012016-08-22 13:59:31 +03001874 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1875 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001876 struct intel_opregion *opregion = &dev_priv->opregion;
1877 int ret;
1878
1879 ret = mutex_lock_interruptible(&dev->struct_mutex);
1880 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001881 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001882
Jani Nikula2455a8e2015-12-14 12:50:53 +02001883 if (opregion->header)
1884 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001885
1886 mutex_unlock(&dev->struct_mutex);
1887
Daniel Vetter0d38f002012-04-21 22:49:10 +02001888out:
Chris Wilson44834a62010-08-19 16:09:23 +01001889 return 0;
1890}
1891
Jani Nikulaada8f952015-12-15 13:17:12 +02001892static int i915_vbt(struct seq_file *m, void *unused)
1893{
David Weinehall36cdd012016-08-22 13:59:31 +03001894 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001895
1896 if (opregion->vbt)
1897 seq_write(m, opregion->vbt, opregion->vbt_size);
1898
1899 return 0;
1900}
1901
Chris Wilson37811fc2010-08-25 22:45:57 +01001902static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1903{
David Weinehall36cdd012016-08-22 13:59:31 +03001904 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1905 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301906 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001907 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001908 int ret;
1909
1910 ret = mutex_lock_interruptible(&dev->struct_mutex);
1911 if (ret)
1912 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001913
Daniel Vetter06957262015-08-10 13:34:08 +02001914#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001915 if (dev_priv->fbdev) {
1916 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001917
Chris Wilson25bcce92016-07-02 15:36:00 +01001918 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1919 fbdev_fb->base.width,
1920 fbdev_fb->base.height,
1921 fbdev_fb->base.depth,
1922 fbdev_fb->base.bits_per_pixel,
1923 fbdev_fb->base.modifier[0],
1924 drm_framebuffer_read_refcount(&fbdev_fb->base));
1925 describe_obj(m, fbdev_fb->obj);
1926 seq_putc(m, '\n');
1927 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001928#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001929
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001930 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001931 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301932 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1933 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001934 continue;
1935
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001936 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 +01001937 fb->base.width,
1938 fb->base.height,
1939 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001940 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001941 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001942 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001943 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001944 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001945 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001946 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001947 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001948
1949 return 0;
1950}
1951
Chris Wilson7e37f882016-08-02 22:50:21 +01001952static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001953{
1954 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001955 ring->space, ring->head, ring->tail,
1956 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001957}
1958
Ben Widawskye76d3632011-03-19 18:14:29 -07001959static int i915_context_status(struct seq_file *m, void *unused)
1960{
David Weinehall36cdd012016-08-22 13:59:31 +03001961 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1962 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001963 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001964 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301965 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001966 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001967
Daniel Vetterf3d28872014-05-29 23:23:08 +02001968 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001969 if (ret)
1970 return ret;
1971
Ben Widawskya33afea2013-09-17 21:12:45 -07001972 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001973 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001974 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001975 struct task_struct *task;
1976
Chris Wilsonc84455b2016-08-15 10:49:08 +01001977 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001978 if (task) {
1979 seq_printf(m, "(%s [%d]) ",
1980 task->comm, task->pid);
1981 put_task_struct(task);
1982 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001983 } else if (IS_ERR(ctx->file_priv)) {
1984 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001985 } else {
1986 seq_puts(m, "(kernel) ");
1987 }
1988
Chris Wilsonbca44d82016-05-24 14:53:41 +01001989 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1990 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001991
Akash Goel3b3f1652016-10-13 22:44:48 +05301992 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001993 struct intel_context *ce = &ctx->engine[engine->id];
1994
1995 seq_printf(m, "%s: ", engine->name);
1996 seq_putc(m, ce->initialised ? 'I' : 'i');
1997 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001998 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001999 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01002000 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002001 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002002 }
2003
Ben Widawskya33afea2013-09-17 21:12:45 -07002004 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002005 }
2006
Daniel Vetterf3d28872014-05-29 23:23:08 +02002007 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002008
2009 return 0;
2010}
2011
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002012static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002013 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002014 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002015{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002016 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002017 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002018 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002019
Chris Wilson7069b142016-04-28 09:56:52 +01002020 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2021
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002022 if (!vma) {
2023 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002024 return;
2025 }
2026
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002027 if (vma->flags & I915_VMA_GLOBAL_BIND)
2028 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002029 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002030
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002031 if (i915_gem_object_get_pages(vma->obj)) {
2032 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002033 return;
2034 }
2035
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002036 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2037 if (page) {
2038 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002039
2040 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002041 seq_printf(m,
2042 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2043 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002044 reg_state[j], reg_state[j + 1],
2045 reg_state[j + 2], reg_state[j + 3]);
2046 }
2047 kunmap_atomic(reg_state);
2048 }
2049
2050 seq_putc(m, '\n');
2051}
2052
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002053static int i915_dump_lrc(struct seq_file *m, void *unused)
2054{
David Weinehall36cdd012016-08-22 13:59:31 +03002055 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2056 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002057 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002058 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302059 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002060 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002061
2062 if (!i915.enable_execlists) {
2063 seq_printf(m, "Logical Ring Contexts are disabled\n");
2064 return 0;
2065 }
2066
2067 ret = mutex_lock_interruptible(&dev->struct_mutex);
2068 if (ret)
2069 return ret;
2070
Dave Gordone28e4042016-01-19 19:02:55 +00002071 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302072 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002073 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002074
2075 mutex_unlock(&dev->struct_mutex);
2076
2077 return 0;
2078}
2079
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002080static const char *swizzle_string(unsigned swizzle)
2081{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002082 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002083 case I915_BIT_6_SWIZZLE_NONE:
2084 return "none";
2085 case I915_BIT_6_SWIZZLE_9:
2086 return "bit9";
2087 case I915_BIT_6_SWIZZLE_9_10:
2088 return "bit9/bit10";
2089 case I915_BIT_6_SWIZZLE_9_11:
2090 return "bit9/bit11";
2091 case I915_BIT_6_SWIZZLE_9_10_11:
2092 return "bit9/bit10/bit11";
2093 case I915_BIT_6_SWIZZLE_9_17:
2094 return "bit9/bit17";
2095 case I915_BIT_6_SWIZZLE_9_10_17:
2096 return "bit9/bit10/bit17";
2097 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002098 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002099 }
2100
2101 return "bug";
2102}
2103
2104static int i915_swizzle_info(struct seq_file *m, void *data)
2105{
David Weinehall36cdd012016-08-22 13:59:31 +03002106 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002107
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002108 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002109
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002110 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2111 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2112 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2113 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2114
David Weinehall36cdd012016-08-22 13:59:31 +03002115 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002116 seq_printf(m, "DDC = 0x%08x\n",
2117 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002118 seq_printf(m, "DDC2 = 0x%08x\n",
2119 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002120 seq_printf(m, "C0DRB3 = 0x%04x\n",
2121 I915_READ16(C0DRB3));
2122 seq_printf(m, "C1DRB3 = 0x%04x\n",
2123 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002124 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002125 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2126 I915_READ(MAD_DIMM_C0));
2127 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2128 I915_READ(MAD_DIMM_C1));
2129 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2130 I915_READ(MAD_DIMM_C2));
2131 seq_printf(m, "TILECTL = 0x%08x\n",
2132 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002133 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002134 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2135 I915_READ(GAMTARBMODE));
2136 else
2137 seq_printf(m, "ARB_MODE = 0x%08x\n",
2138 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002139 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2140 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002141 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002142
2143 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2144 seq_puts(m, "L-shaped memory detected\n");
2145
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002146 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002147
2148 return 0;
2149}
2150
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002151static int per_file_ctx(int id, void *ptr, void *data)
2152{
Chris Wilsone2efd132016-05-24 14:53:34 +01002153 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002154 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002155 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2156
2157 if (!ppgtt) {
2158 seq_printf(m, " no ppgtt for context %d\n",
2159 ctx->user_handle);
2160 return 0;
2161 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002162
Oscar Mateof83d6512014-05-22 14:13:38 +01002163 if (i915_gem_context_is_default(ctx))
2164 seq_puts(m, " default context:\n");
2165 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002166 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002167 ppgtt->debug_dump(ppgtt, m);
2168
2169 return 0;
2170}
2171
David Weinehall36cdd012016-08-22 13:59:31 +03002172static void gen8_ppgtt_info(struct seq_file *m,
2173 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002174{
Ben Widawsky77df6772013-11-02 21:07:30 -07002175 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302176 struct intel_engine_cs *engine;
2177 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002178 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002179
Ben Widawsky77df6772013-11-02 21:07:30 -07002180 if (!ppgtt)
2181 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002182
Akash Goel3b3f1652016-10-13 22:44:48 +05302183 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002184 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002185 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002186 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002187 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002188 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002189 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002190 }
2191 }
2192}
2193
David Weinehall36cdd012016-08-22 13:59:31 +03002194static void gen6_ppgtt_info(struct seq_file *m,
2195 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002196{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002197 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302198 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002199
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002200 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002201 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2202
Akash Goel3b3f1652016-10-13 22:44:48 +05302203 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002204 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002205 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002206 seq_printf(m, "GFX_MODE: 0x%08x\n",
2207 I915_READ(RING_MODE_GEN7(engine)));
2208 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2209 I915_READ(RING_PP_DIR_BASE(engine)));
2210 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2211 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2212 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2213 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002214 }
2215 if (dev_priv->mm.aliasing_ppgtt) {
2216 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2217
Damien Lespiau267f0c92013-06-24 22:59:48 +01002218 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002219 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002220
Ben Widawsky87d60b62013-12-06 14:11:29 -08002221 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002222 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002223
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002224 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002225}
2226
2227static int i915_ppgtt_info(struct seq_file *m, void *data)
2228{
David Weinehall36cdd012016-08-22 13:59:31 +03002229 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2230 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002231 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002232 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002233
Chris Wilson637ee292016-08-22 14:28:20 +01002234 mutex_lock(&dev->filelist_mutex);
2235 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002236 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002237 goto out_unlock;
2238
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002239 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002240
David Weinehall36cdd012016-08-22 13:59:31 +03002241 if (INTEL_GEN(dev_priv) >= 8)
2242 gen8_ppgtt_info(m, dev_priv);
2243 else if (INTEL_GEN(dev_priv) >= 6)
2244 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002245
Michel Thierryea91e402015-07-29 17:23:57 +01002246 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2247 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002248 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002249
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002250 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002251 if (!task) {
2252 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002253 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002254 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002255 seq_printf(m, "\nproc: %s\n", task->comm);
2256 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002257 idr_for_each(&file_priv->context_idr, per_file_ctx,
2258 (void *)(unsigned long)m);
2259 }
2260
Chris Wilson637ee292016-08-22 14:28:20 +01002261out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002262 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002263 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002264out_unlock:
2265 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002266 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002267}
2268
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002269static int count_irq_waiters(struct drm_i915_private *i915)
2270{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002271 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302272 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002273 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002274
Akash Goel3b3f1652016-10-13 22:44:48 +05302275 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002276 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002277
2278 return count;
2279}
2280
Chris Wilson7466c292016-08-15 09:49:33 +01002281static const char *rps_power_to_str(unsigned int power)
2282{
2283 static const char * const strings[] = {
2284 [LOW_POWER] = "low power",
2285 [BETWEEN] = "mixed",
2286 [HIGH_POWER] = "high power",
2287 };
2288
2289 if (power >= ARRAY_SIZE(strings) || !strings[power])
2290 return "unknown";
2291
2292 return strings[power];
2293}
2294
Chris Wilson1854d5c2015-04-07 16:20:32 +01002295static int i915_rps_boost_info(struct seq_file *m, void *data)
2296{
David Weinehall36cdd012016-08-22 13:59:31 +03002297 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2298 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002299 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002300
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002301 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002302 seq_printf(m, "GPU busy? %s [%x]\n",
2303 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002304 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002305 seq_printf(m, "Frequency requested %d\n",
2306 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2307 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002308 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2309 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2310 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2311 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002312 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2313 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2314 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2315 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002316
2317 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002318 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002319 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2320 struct drm_i915_file_private *file_priv = file->driver_priv;
2321 struct task_struct *task;
2322
2323 rcu_read_lock();
2324 task = pid_task(file->pid, PIDTYPE_PID);
2325 seq_printf(m, "%s [%d]: %d boosts%s\n",
2326 task ? task->comm : "<unknown>",
2327 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002328 file_priv->rps.boosts,
2329 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002330 rcu_read_unlock();
2331 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002332 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002333 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002334 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002335
Chris Wilson7466c292016-08-15 09:49:33 +01002336 if (INTEL_GEN(dev_priv) >= 6 &&
2337 dev_priv->rps.enabled &&
2338 dev_priv->gt.active_engines) {
2339 u32 rpup, rpupei;
2340 u32 rpdown, rpdownei;
2341
2342 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2343 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2344 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2345 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2346 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2347 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2348
2349 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2350 rps_power_to_str(dev_priv->rps.power));
2351 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2352 100 * rpup / rpupei,
2353 dev_priv->rps.up_threshold);
2354 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2355 100 * rpdown / rpdownei,
2356 dev_priv->rps.down_threshold);
2357 } else {
2358 seq_puts(m, "\nRPS Autotuning inactive\n");
2359 }
2360
Chris Wilson8d3afd72015-05-21 21:01:47 +01002361 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002362}
2363
Ben Widawsky63573eb2013-07-04 11:02:07 -07002364static int i915_llc(struct seq_file *m, void *data)
2365{
David Weinehall36cdd012016-08-22 13:59:31 +03002366 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002367 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002368
David Weinehall36cdd012016-08-22 13:59:31 +03002369 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002370 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2371 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002372
2373 return 0;
2374}
2375
Alex Daifdf5d352015-08-12 15:43:37 +01002376static int i915_guc_load_status_info(struct seq_file *m, void *data)
2377{
David Weinehall36cdd012016-08-22 13:59:31 +03002378 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002379 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2380 u32 tmp, i;
2381
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002382 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002383 return 0;
2384
2385 seq_printf(m, "GuC firmware status:\n");
2386 seq_printf(m, "\tpath: %s\n",
2387 guc_fw->guc_fw_path);
2388 seq_printf(m, "\tfetch: %s\n",
2389 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2390 seq_printf(m, "\tload: %s\n",
2391 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2392 seq_printf(m, "\tversion wanted: %d.%d\n",
2393 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2394 seq_printf(m, "\tversion found: %d.%d\n",
2395 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002396 seq_printf(m, "\theader: offset is %d; size = %d\n",
2397 guc_fw->header_offset, guc_fw->header_size);
2398 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2399 guc_fw->ucode_offset, guc_fw->ucode_size);
2400 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2401 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002402
2403 tmp = I915_READ(GUC_STATUS);
2404
2405 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2406 seq_printf(m, "\tBootrom status = 0x%x\n",
2407 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2408 seq_printf(m, "\tuKernel status = 0x%x\n",
2409 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2410 seq_printf(m, "\tMIA Core status = 0x%x\n",
2411 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2412 seq_puts(m, "\nScratch registers:\n");
2413 for (i = 0; i < 16; i++)
2414 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2415
2416 return 0;
2417}
2418
Akash Goel5aa1ee42016-10-12 21:54:36 +05302419static void i915_guc_log_info(struct seq_file *m,
2420 struct drm_i915_private *dev_priv)
2421{
2422 struct intel_guc *guc = &dev_priv->guc;
2423
2424 seq_puts(m, "\nGuC logging stats:\n");
2425
2426 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2427 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2428 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2429
2430 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2431 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2432 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2433
2434 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2435 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2436 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2437
2438 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2439 guc->log.flush_interrupt_count);
2440
2441 seq_printf(m, "\tCapture miss count: %u\n",
2442 guc->log.capture_miss_count);
2443}
2444
Dave Gordon8b417c22015-08-12 15:43:44 +01002445static void i915_guc_client_info(struct seq_file *m,
2446 struct drm_i915_private *dev_priv,
2447 struct i915_guc_client *client)
2448{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002449 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002450 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002451 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002452
2453 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2454 client->priority, client->ctx_index, client->proc_desc_offset);
2455 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2456 client->doorbell_id, client->doorbell_offset, client->cookie);
2457 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2458 client->wq_size, client->wq_offset, client->wq_tail);
2459
Dave Gordon551aaec2016-05-13 15:36:33 +01002460 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002461 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2462 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2463
Akash Goel3b3f1652016-10-13 22:44:48 +05302464 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002465 u64 submissions = client->submissions[id];
2466 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002467 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002468 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002469 }
2470 seq_printf(m, "\tTotal: %llu\n", tot);
2471}
2472
2473static int i915_guc_info(struct seq_file *m, void *data)
2474{
David Weinehall36cdd012016-08-22 13:59:31 +03002475 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2476 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002477 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002478 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002479 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002480 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002481 u64 total = 0;
2482
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002483 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002484 return 0;
2485
Alex Dai5a843302015-12-02 16:56:29 -08002486 if (mutex_lock_interruptible(&dev->struct_mutex))
2487 return 0;
2488
Dave Gordon8b417c22015-08-12 15:43:44 +01002489 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002490 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002491 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002492 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002493
2494 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002495
Dave Gordon9636f6d2016-06-13 17:57:28 +01002496 seq_printf(m, "Doorbell map:\n");
2497 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2498 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2499
Dave Gordon8b417c22015-08-12 15:43:44 +01002500 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2501 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2502 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2503 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2504 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2505
2506 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302507 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002508 u64 submissions = guc.submissions[id];
2509 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002510 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002511 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002512 }
2513 seq_printf(m, "\t%s: %llu\n", "Total", total);
2514
2515 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2516 i915_guc_client_info(m, dev_priv, &client);
2517
Akash Goel5aa1ee42016-10-12 21:54:36 +05302518 i915_guc_log_info(m, dev_priv);
2519
Dave Gordon8b417c22015-08-12 15:43:44 +01002520 /* Add more as required ... */
2521
2522 return 0;
2523}
2524
Alex Dai4c7e77f2015-08-12 15:43:40 +01002525static int i915_guc_log_dump(struct seq_file *m, void *data)
2526{
David Weinehall36cdd012016-08-22 13:59:31 +03002527 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002528 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002529 int i = 0, pg;
2530
Akash Goeld6b40b42016-10-12 21:54:29 +05302531 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002532 return 0;
2533
Akash Goeld6b40b42016-10-12 21:54:29 +05302534 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002535 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2536 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002537
2538 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2539 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2540 *(log + i), *(log + i + 1),
2541 *(log + i + 2), *(log + i + 3));
2542
2543 kunmap_atomic(log);
2544 }
2545
2546 seq_putc(m, '\n');
2547
2548 return 0;
2549}
2550
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302551static int i915_guc_log_control_get(void *data, u64 *val)
2552{
2553 struct drm_device *dev = data;
2554 struct drm_i915_private *dev_priv = to_i915(dev);
2555
2556 if (!dev_priv->guc.log.vma)
2557 return -EINVAL;
2558
2559 *val = i915.guc_log_level;
2560
2561 return 0;
2562}
2563
2564static int i915_guc_log_control_set(void *data, u64 val)
2565{
2566 struct drm_device *dev = data;
2567 struct drm_i915_private *dev_priv = to_i915(dev);
2568 int ret;
2569
2570 if (!dev_priv->guc.log.vma)
2571 return -EINVAL;
2572
2573 ret = mutex_lock_interruptible(&dev->struct_mutex);
2574 if (ret)
2575 return ret;
2576
2577 intel_runtime_pm_get(dev_priv);
2578 ret = i915_guc_log_control(dev_priv, val);
2579 intel_runtime_pm_put(dev_priv);
2580
2581 mutex_unlock(&dev->struct_mutex);
2582 return ret;
2583}
2584
2585DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2586 i915_guc_log_control_get, i915_guc_log_control_set,
2587 "%lld\n");
2588
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002589static int i915_edp_psr_status(struct seq_file *m, void *data)
2590{
David Weinehall36cdd012016-08-22 13:59:31 +03002591 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002592 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002593 u32 stat[3];
2594 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002595 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002596
David Weinehall36cdd012016-08-22 13:59:31 +03002597 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002598 seq_puts(m, "PSR not supported\n");
2599 return 0;
2600 }
2601
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002602 intel_runtime_pm_get(dev_priv);
2603
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002604 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002605 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2606 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002607 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002608 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002609 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2610 dev_priv->psr.busy_frontbuffer_bits);
2611 seq_printf(m, "Re-enable work scheduled: %s\n",
2612 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002613
David Weinehall36cdd012016-08-22 13:59:31 +03002614 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002615 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002616 else {
2617 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002618 enum transcoder cpu_transcoder =
2619 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2620 enum intel_display_power_domain power_domain;
2621
2622 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2623 if (!intel_display_power_get_if_enabled(dev_priv,
2624 power_domain))
2625 continue;
2626
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002627 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2628 VLV_EDP_PSR_CURR_STATE_MASK;
2629 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2630 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2631 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002632
2633 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002634 }
2635 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002636
2637 seq_printf(m, "Main link in standby mode: %s\n",
2638 yesno(dev_priv->psr.link_standby));
2639
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002640 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002641
David Weinehall36cdd012016-08-22 13:59:31 +03002642 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002643 for_each_pipe(dev_priv, pipe) {
2644 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2645 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2646 seq_printf(m, " pipe %c", pipe_name(pipe));
2647 }
2648 seq_puts(m, "\n");
2649
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002650 /*
2651 * VLV/CHV PSR has no kind of performance counter
2652 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2653 */
David Weinehall36cdd012016-08-22 13:59:31 +03002654 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002655 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002656 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002657
2658 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2659 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002660 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002661
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002662 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002663 return 0;
2664}
2665
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002666static int i915_sink_crc(struct seq_file *m, void *data)
2667{
David Weinehall36cdd012016-08-22 13:59:31 +03002668 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2669 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002670 struct intel_connector *connector;
2671 struct intel_dp *intel_dp = NULL;
2672 int ret;
2673 u8 crc[6];
2674
2675 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002676 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002677 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002678
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002679 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002680 continue;
2681
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002682 crtc = connector->base.state->crtc;
2683 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002684 continue;
2685
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002686 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002687 continue;
2688
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002689 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002690
2691 ret = intel_dp_sink_crc(intel_dp, crc);
2692 if (ret)
2693 goto out;
2694
2695 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2696 crc[0], crc[1], crc[2],
2697 crc[3], crc[4], crc[5]);
2698 goto out;
2699 }
2700 ret = -ENODEV;
2701out:
2702 drm_modeset_unlock_all(dev);
2703 return ret;
2704}
2705
Jesse Barnesec013e72013-08-20 10:29:23 +01002706static int i915_energy_uJ(struct seq_file *m, void *data)
2707{
David Weinehall36cdd012016-08-22 13:59:31 +03002708 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002709 u64 power;
2710 u32 units;
2711
David Weinehall36cdd012016-08-22 13:59:31 +03002712 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002713 return -ENODEV;
2714
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002715 intel_runtime_pm_get(dev_priv);
2716
Jesse Barnesec013e72013-08-20 10:29:23 +01002717 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2718 power = (power & 0x1f00) >> 8;
2719 units = 1000000 / (1 << power); /* convert to uJ */
2720 power = I915_READ(MCH_SECP_NRG_STTS);
2721 power *= units;
2722
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002723 intel_runtime_pm_put(dev_priv);
2724
Jesse Barnesec013e72013-08-20 10:29:23 +01002725 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002726
2727 return 0;
2728}
2729
Damien Lespiau6455c872015-06-04 18:23:57 +01002730static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002731{
David Weinehall36cdd012016-08-22 13:59:31 +03002732 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002733 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002734
Chris Wilsona156e642016-04-03 14:14:21 +01002735 if (!HAS_RUNTIME_PM(dev_priv))
2736 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002737
Chris Wilson67d97da2016-07-04 08:08:31 +01002738 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002739 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002740 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002741#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002742 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002743 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002744#else
2745 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2746#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002747 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002748 pci_power_name(pdev->current_state),
2749 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002750
Jesse Barnesec013e72013-08-20 10:29:23 +01002751 return 0;
2752}
2753
Imre Deak1da51582013-11-25 17:15:35 +02002754static int i915_power_domain_info(struct seq_file *m, void *unused)
2755{
David Weinehall36cdd012016-08-22 13:59:31 +03002756 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002757 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2758 int i;
2759
2760 mutex_lock(&power_domains->lock);
2761
2762 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2763 for (i = 0; i < power_domains->power_well_count; i++) {
2764 struct i915_power_well *power_well;
2765 enum intel_display_power_domain power_domain;
2766
2767 power_well = &power_domains->power_wells[i];
2768 seq_printf(m, "%-25s %d\n", power_well->name,
2769 power_well->count);
2770
2771 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2772 power_domain++) {
2773 if (!(BIT(power_domain) & power_well->domains))
2774 continue;
2775
2776 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002777 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002778 power_domains->domain_use_count[power_domain]);
2779 }
2780 }
2781
2782 mutex_unlock(&power_domains->lock);
2783
2784 return 0;
2785}
2786
Damien Lespiaub7cec662015-10-27 14:47:01 +02002787static int i915_dmc_info(struct seq_file *m, void *unused)
2788{
David Weinehall36cdd012016-08-22 13:59:31 +03002789 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002790 struct intel_csr *csr;
2791
David Weinehall36cdd012016-08-22 13:59:31 +03002792 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002793 seq_puts(m, "not supported\n");
2794 return 0;
2795 }
2796
2797 csr = &dev_priv->csr;
2798
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002799 intel_runtime_pm_get(dev_priv);
2800
Damien Lespiaub7cec662015-10-27 14:47:01 +02002801 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2802 seq_printf(m, "path: %s\n", csr->fw_path);
2803
2804 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002805 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002806
2807 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2808 CSR_VERSION_MINOR(csr->version));
2809
David Weinehall36cdd012016-08-22 13:59:31 +03002810 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002811 seq_printf(m, "DC3 -> DC5 count: %d\n",
2812 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2813 seq_printf(m, "DC5 -> DC6 count: %d\n",
2814 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002815 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002816 seq_printf(m, "DC3 -> DC5 count: %d\n",
2817 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002818 }
2819
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002820out:
2821 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2822 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2823 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2824
Damien Lespiau83372062015-10-30 17:53:32 +02002825 intel_runtime_pm_put(dev_priv);
2826
Damien Lespiaub7cec662015-10-27 14:47:01 +02002827 return 0;
2828}
2829
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002830static void intel_seq_print_mode(struct seq_file *m, int tabs,
2831 struct drm_display_mode *mode)
2832{
2833 int i;
2834
2835 for (i = 0; i < tabs; i++)
2836 seq_putc(m, '\t');
2837
2838 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",
2839 mode->base.id, mode->name,
2840 mode->vrefresh, mode->clock,
2841 mode->hdisplay, mode->hsync_start,
2842 mode->hsync_end, mode->htotal,
2843 mode->vdisplay, mode->vsync_start,
2844 mode->vsync_end, mode->vtotal,
2845 mode->type, mode->flags);
2846}
2847
2848static void intel_encoder_info(struct seq_file *m,
2849 struct intel_crtc *intel_crtc,
2850 struct intel_encoder *intel_encoder)
2851{
David Weinehall36cdd012016-08-22 13:59:31 +03002852 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2853 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002854 struct drm_crtc *crtc = &intel_crtc->base;
2855 struct intel_connector *intel_connector;
2856 struct drm_encoder *encoder;
2857
2858 encoder = &intel_encoder->base;
2859 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002860 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002861 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2862 struct drm_connector *connector = &intel_connector->base;
2863 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2864 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002865 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002866 drm_get_connector_status_name(connector->status));
2867 if (connector->status == connector_status_connected) {
2868 struct drm_display_mode *mode = &crtc->mode;
2869 seq_printf(m, ", mode:\n");
2870 intel_seq_print_mode(m, 2, mode);
2871 } else {
2872 seq_putc(m, '\n');
2873 }
2874 }
2875}
2876
2877static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2878{
David Weinehall36cdd012016-08-22 13:59:31 +03002879 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2880 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002881 struct drm_crtc *crtc = &intel_crtc->base;
2882 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002883 struct drm_plane_state *plane_state = crtc->primary->state;
2884 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002885
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002886 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002887 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002888 fb->base.id, plane_state->src_x >> 16,
2889 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002890 else
2891 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002892 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2893 intel_encoder_info(m, intel_crtc, intel_encoder);
2894}
2895
2896static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2897{
2898 struct drm_display_mode *mode = panel->fixed_mode;
2899
2900 seq_printf(m, "\tfixed mode:\n");
2901 intel_seq_print_mode(m, 2, mode);
2902}
2903
2904static void intel_dp_info(struct seq_file *m,
2905 struct intel_connector *intel_connector)
2906{
2907 struct intel_encoder *intel_encoder = intel_connector->encoder;
2908 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2909
2910 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002911 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002912 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002913 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002914
2915 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2916 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002917}
2918
2919static void intel_hdmi_info(struct seq_file *m,
2920 struct intel_connector *intel_connector)
2921{
2922 struct intel_encoder *intel_encoder = intel_connector->encoder;
2923 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2924
Jani Nikula742f4912015-09-03 11:16:09 +03002925 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002926}
2927
2928static void intel_lvds_info(struct seq_file *m,
2929 struct intel_connector *intel_connector)
2930{
2931 intel_panel_info(m, &intel_connector->panel);
2932}
2933
2934static void intel_connector_info(struct seq_file *m,
2935 struct drm_connector *connector)
2936{
2937 struct intel_connector *intel_connector = to_intel_connector(connector);
2938 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002939 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002940
2941 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002942 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002943 drm_get_connector_status_name(connector->status));
2944 if (connector->status == connector_status_connected) {
2945 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2946 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2947 connector->display_info.width_mm,
2948 connector->display_info.height_mm);
2949 seq_printf(m, "\tsubpixel order: %s\n",
2950 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2951 seq_printf(m, "\tCEA rev: %d\n",
2952 connector->display_info.cea_rev);
2953 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002954
2955 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2956 return;
2957
2958 switch (connector->connector_type) {
2959 case DRM_MODE_CONNECTOR_DisplayPort:
2960 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002961 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002962 break;
2963 case DRM_MODE_CONNECTOR_LVDS:
2964 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002965 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002966 break;
2967 case DRM_MODE_CONNECTOR_HDMIA:
2968 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2969 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2970 intel_hdmi_info(m, intel_connector);
2971 break;
2972 default:
2973 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002974 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002975
Jesse Barnesf103fc72014-02-20 12:39:57 -08002976 seq_printf(m, "\tmodes:\n");
2977 list_for_each_entry(mode, &connector->modes, head)
2978 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002979}
2980
David Weinehall36cdd012016-08-22 13:59:31 +03002981static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002982{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002983 u32 state;
2984
David Weinehall36cdd012016-08-22 13:59:31 +03002985 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002986 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002987 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002988 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002989
2990 return state;
2991}
2992
David Weinehall36cdd012016-08-22 13:59:31 +03002993static bool cursor_position(struct drm_i915_private *dev_priv,
2994 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002995{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002996 u32 pos;
2997
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002998 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002999
3000 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3001 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3002 *x = -*x;
3003
3004 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3005 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3006 *y = -*y;
3007
David Weinehall36cdd012016-08-22 13:59:31 +03003008 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003009}
3010
Robert Fekete3abc4e02015-10-27 16:58:32 +01003011static const char *plane_type(enum drm_plane_type type)
3012{
3013 switch (type) {
3014 case DRM_PLANE_TYPE_OVERLAY:
3015 return "OVL";
3016 case DRM_PLANE_TYPE_PRIMARY:
3017 return "PRI";
3018 case DRM_PLANE_TYPE_CURSOR:
3019 return "CUR";
3020 /*
3021 * Deliberately omitting default: to generate compiler warnings
3022 * when a new drm_plane_type gets added.
3023 */
3024 }
3025
3026 return "unknown";
3027}
3028
3029static const char *plane_rotation(unsigned int rotation)
3030{
3031 static char buf[48];
3032 /*
3033 * According to doc only one DRM_ROTATE_ is allowed but this
3034 * will print them all to visualize if the values are misused
3035 */
3036 snprintf(buf, sizeof(buf),
3037 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003038 (rotation & DRM_ROTATE_0) ? "0 " : "",
3039 (rotation & DRM_ROTATE_90) ? "90 " : "",
3040 (rotation & DRM_ROTATE_180) ? "180 " : "",
3041 (rotation & DRM_ROTATE_270) ? "270 " : "",
3042 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3043 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003044 rotation);
3045
3046 return buf;
3047}
3048
3049static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3050{
David Weinehall36cdd012016-08-22 13:59:31 +03003051 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3052 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003053 struct intel_plane *intel_plane;
3054
3055 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3056 struct drm_plane_state *state;
3057 struct drm_plane *plane = &intel_plane->base;
Eric Engestromd3828142016-08-15 16:29:55 +01003058 char *format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003059
3060 if (!plane->state) {
3061 seq_puts(m, "plane->state is NULL!\n");
3062 continue;
3063 }
3064
3065 state = plane->state;
3066
Eric Engestrom90844f02016-08-15 01:02:38 +01003067 if (state->fb) {
3068 format_name = drm_get_format_name(state->fb->pixel_format);
3069 } else {
3070 format_name = kstrdup("N/A", GFP_KERNEL);
3071 }
3072
Robert Fekete3abc4e02015-10-27 16:58:32 +01003073 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",
3074 plane->base.id,
3075 plane_type(intel_plane->base.type),
3076 state->crtc_x, state->crtc_y,
3077 state->crtc_w, state->crtc_h,
3078 (state->src_x >> 16),
3079 ((state->src_x & 0xffff) * 15625) >> 10,
3080 (state->src_y >> 16),
3081 ((state->src_y & 0xffff) * 15625) >> 10,
3082 (state->src_w >> 16),
3083 ((state->src_w & 0xffff) * 15625) >> 10,
3084 (state->src_h >> 16),
3085 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestrom90844f02016-08-15 01:02:38 +01003086 format_name,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003087 plane_rotation(state->rotation));
Eric Engestrom90844f02016-08-15 01:02:38 +01003088
3089 kfree(format_name);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003090 }
3091}
3092
3093static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3094{
3095 struct intel_crtc_state *pipe_config;
3096 int num_scalers = intel_crtc->num_scalers;
3097 int i;
3098
3099 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3100
3101 /* Not all platformas have a scaler */
3102 if (num_scalers) {
3103 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3104 num_scalers,
3105 pipe_config->scaler_state.scaler_users,
3106 pipe_config->scaler_state.scaler_id);
3107
3108 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3109 struct intel_scaler *sc =
3110 &pipe_config->scaler_state.scalers[i];
3111
3112 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3113 i, yesno(sc->in_use), sc->mode);
3114 }
3115 seq_puts(m, "\n");
3116 } else {
3117 seq_puts(m, "\tNo scalers available on this platform\n");
3118 }
3119}
3120
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003121static int i915_display_info(struct seq_file *m, void *unused)
3122{
David Weinehall36cdd012016-08-22 13:59:31 +03003123 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3124 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003125 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003126 struct drm_connector *connector;
3127
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003128 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003129 drm_modeset_lock_all(dev);
3130 seq_printf(m, "CRTC info\n");
3131 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003132 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003133 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003134 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003135 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003136
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003137 pipe_config = to_intel_crtc_state(crtc->base.state);
3138
Robert Fekete3abc4e02015-10-27 16:58:32 +01003139 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003140 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003141 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003142 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3143 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3144
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003145 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003146 intel_crtc_info(m, crtc);
3147
David Weinehall36cdd012016-08-22 13:59:31 +03003148 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003149 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 +03003150 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003151 x, y, crtc->base.cursor->state->crtc_w,
3152 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003153 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003154 intel_scaler_info(m, crtc);
3155 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003156 }
Daniel Vettercace8412014-05-22 17:56:31 +02003157
3158 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3159 yesno(!crtc->cpu_fifo_underrun_disabled),
3160 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003161 }
3162
3163 seq_printf(m, "\n");
3164 seq_printf(m, "Connector info\n");
3165 seq_printf(m, "--------------\n");
3166 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3167 intel_connector_info(m, connector);
3168 }
3169 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003170 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003171
3172 return 0;
3173}
3174
Chris Wilson1b365952016-10-04 21:11:31 +01003175static int i915_engine_info(struct seq_file *m, void *unused)
3176{
3177 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3178 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303179 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003180
Chris Wilson9c870d02016-10-24 13:42:15 +01003181 intel_runtime_pm_get(dev_priv);
3182
Akash Goel3b3f1652016-10-13 22:44:48 +05303183 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003184 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3185 struct drm_i915_gem_request *rq;
3186 struct rb_node *rb;
3187 u64 addr;
3188
3189 seq_printf(m, "%s\n", engine->name);
3190 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3191 intel_engine_get_seqno(engine),
3192 engine->last_submitted_seqno,
3193 engine->hangcheck.seqno,
3194 engine->hangcheck.score);
3195
3196 rcu_read_lock();
3197
3198 seq_printf(m, "\tRequests:\n");
3199
3200 rq = list_first_entry(&engine->request_list,
3201 struct drm_i915_gem_request, link);
3202 if (&rq->link != &engine->request_list)
3203 print_request(m, rq, "\t\tfirst ");
3204
3205 rq = list_last_entry(&engine->request_list,
3206 struct drm_i915_gem_request, link);
3207 if (&rq->link != &engine->request_list)
3208 print_request(m, rq, "\t\tlast ");
3209
3210 rq = i915_gem_find_active_request(engine);
3211 if (rq) {
3212 print_request(m, rq, "\t\tactive ");
3213 seq_printf(m,
3214 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3215 rq->head, rq->postfix, rq->tail,
3216 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3217 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3218 }
3219
3220 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3221 I915_READ(RING_START(engine->mmio_base)),
3222 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3223 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3224 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3225 rq ? rq->ring->head : 0);
3226 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3227 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3228 rq ? rq->ring->tail : 0);
3229 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3230 I915_READ(RING_CTL(engine->mmio_base)),
3231 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3232
3233 rcu_read_unlock();
3234
3235 addr = intel_engine_get_active_head(engine);
3236 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3237 upper_32_bits(addr), lower_32_bits(addr));
3238 addr = intel_engine_get_last_batch_head(engine);
3239 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3240 upper_32_bits(addr), lower_32_bits(addr));
3241
3242 if (i915.enable_execlists) {
3243 u32 ptr, read, write;
3244
3245 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3246 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3247 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3248
3249 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3250 read = GEN8_CSB_READ_PTR(ptr);
3251 write = GEN8_CSB_WRITE_PTR(ptr);
3252 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3253 read, write);
3254 if (read >= GEN8_CSB_ENTRIES)
3255 read = 0;
3256 if (write >= GEN8_CSB_ENTRIES)
3257 write = 0;
3258 if (read > write)
3259 write += GEN8_CSB_ENTRIES;
3260 while (read < write) {
3261 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3262
3263 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3264 idx,
3265 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3266 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3267 }
3268
3269 rcu_read_lock();
3270 rq = READ_ONCE(engine->execlist_port[0].request);
3271 if (rq)
3272 print_request(m, rq, "\t\tELSP[0] ");
3273 else
3274 seq_printf(m, "\t\tELSP[0] idle\n");
3275 rq = READ_ONCE(engine->execlist_port[1].request);
3276 if (rq)
3277 print_request(m, rq, "\t\tELSP[1] ");
3278 else
3279 seq_printf(m, "\t\tELSP[1] idle\n");
3280 rcu_read_unlock();
3281 } else if (INTEL_GEN(dev_priv) > 6) {
3282 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3283 I915_READ(RING_PP_DIR_BASE(engine)));
3284 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3285 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3286 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3287 I915_READ(RING_PP_DIR_DCLV(engine)));
3288 }
3289
3290 spin_lock(&b->lock);
3291 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3292 struct intel_wait *w = container_of(rb, typeof(*w), node);
3293
3294 seq_printf(m, "\t%s [%d] waiting for %x\n",
3295 w->tsk->comm, w->tsk->pid, w->seqno);
3296 }
3297 spin_unlock(&b->lock);
3298
3299 seq_puts(m, "\n");
3300 }
3301
Chris Wilson9c870d02016-10-24 13:42:15 +01003302 intel_runtime_pm_put(dev_priv);
3303
Chris Wilson1b365952016-10-04 21:11:31 +01003304 return 0;
3305}
3306
Ben Widawskye04934c2014-06-30 09:53:42 -07003307static int i915_semaphore_status(struct seq_file *m, void *unused)
3308{
David Weinehall36cdd012016-08-22 13:59:31 +03003309 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3310 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003311 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003312 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003313 enum intel_engine_id id;
3314 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003315
Chris Wilson39df9192016-07-20 13:31:57 +01003316 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003317 seq_puts(m, "Semaphores are disabled\n");
3318 return 0;
3319 }
3320
3321 ret = mutex_lock_interruptible(&dev->struct_mutex);
3322 if (ret)
3323 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003324 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003325
David Weinehall36cdd012016-08-22 13:59:31 +03003326 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003327 struct page *page;
3328 uint64_t *seqno;
3329
Chris Wilson51d545d2016-08-15 10:49:02 +01003330 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003331
3332 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303333 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003334 uint64_t offset;
3335
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003336 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003337
3338 seq_puts(m, " Last signal:");
3339 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003340 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003341 seq_printf(m, "0x%08llx (0x%02llx) ",
3342 seqno[offset], offset * 8);
3343 }
3344 seq_putc(m, '\n');
3345
3346 seq_puts(m, " Last wait: ");
3347 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003348 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003349 seq_printf(m, "0x%08llx (0x%02llx) ",
3350 seqno[offset], offset * 8);
3351 }
3352 seq_putc(m, '\n');
3353
3354 }
3355 kunmap_atomic(seqno);
3356 } else {
3357 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303358 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003359 for (j = 0; j < num_rings; j++)
3360 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003361 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003362 seq_putc(m, '\n');
3363 }
3364
3365 seq_puts(m, "\nSync seqno:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05303366 for_each_engine(engine, dev_priv, id) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003367 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003368 seq_printf(m, " 0x%08x ",
3369 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003370 seq_putc(m, '\n');
3371 }
3372 seq_putc(m, '\n');
3373
Paulo Zanoni03872062014-07-09 14:31:57 -03003374 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003375 mutex_unlock(&dev->struct_mutex);
3376 return 0;
3377}
3378
Daniel Vetter728e29d2014-06-25 22:01:53 +03003379static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3380{
David Weinehall36cdd012016-08-22 13:59:31 +03003381 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3382 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003383 int i;
3384
3385 drm_modeset_lock_all(dev);
3386 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3387 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3388
3389 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003390 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3391 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003392 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003393 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3394 seq_printf(m, " dpll_md: 0x%08x\n",
3395 pll->config.hw_state.dpll_md);
3396 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3397 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3398 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003399 }
3400 drm_modeset_unlock_all(dev);
3401
3402 return 0;
3403}
3404
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003405static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003406{
3407 int i;
3408 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003409 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003410 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3411 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003412 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003413 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003414
Arun Siluvery888b5992014-08-26 14:44:51 +01003415 ret = mutex_lock_interruptible(&dev->struct_mutex);
3416 if (ret)
3417 return ret;
3418
3419 intel_runtime_pm_get(dev_priv);
3420
Arun Siluvery33136b02016-01-21 21:43:47 +00003421 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303422 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003423 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003424 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003425 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003426 i915_reg_t addr;
3427 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003428 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003429
Arun Siluvery33136b02016-01-21 21:43:47 +00003430 addr = workarounds->reg[i].addr;
3431 mask = workarounds->reg[i].mask;
3432 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003433 read = I915_READ(addr);
3434 ok = (value & mask) == (read & mask);
3435 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 +02003436 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003437 }
3438
3439 intel_runtime_pm_put(dev_priv);
3440 mutex_unlock(&dev->struct_mutex);
3441
3442 return 0;
3443}
3444
Damien Lespiauc5511e42014-11-04 17:06:51 +00003445static int i915_ddb_info(struct seq_file *m, void *unused)
3446{
David Weinehall36cdd012016-08-22 13:59:31 +03003447 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3448 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003449 struct skl_ddb_allocation *ddb;
3450 struct skl_ddb_entry *entry;
3451 enum pipe pipe;
3452 int plane;
3453
David Weinehall36cdd012016-08-22 13:59:31 +03003454 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003455 return 0;
3456
Damien Lespiauc5511e42014-11-04 17:06:51 +00003457 drm_modeset_lock_all(dev);
3458
3459 ddb = &dev_priv->wm.skl_hw.ddb;
3460
3461 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3462
3463 for_each_pipe(dev_priv, pipe) {
3464 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3465
Matt Roper8b364b42016-10-26 15:51:28 -07003466 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003467 entry = &ddb->plane[pipe][plane];
3468 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3469 entry->start, entry->end,
3470 skl_ddb_entry_size(entry));
3471 }
3472
Matt Roper4969d332015-09-24 15:53:10 -07003473 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003474 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3475 entry->end, skl_ddb_entry_size(entry));
3476 }
3477
3478 drm_modeset_unlock_all(dev);
3479
3480 return 0;
3481}
3482
Vandana Kannana54746e2015-03-03 20:53:10 +05303483static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003484 struct drm_device *dev,
3485 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303486{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003487 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303488 struct i915_drrs *drrs = &dev_priv->drrs;
3489 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003490 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303491
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003492 drm_for_each_connector(connector, dev) {
3493 if (connector->state->crtc != &intel_crtc->base)
3494 continue;
3495
3496 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303497 }
3498
3499 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3500 seq_puts(m, "\tVBT: DRRS_type: Static");
3501 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3502 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3503 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3504 seq_puts(m, "\tVBT: DRRS_type: None");
3505 else
3506 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3507
3508 seq_puts(m, "\n\n");
3509
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003510 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303511 struct intel_panel *panel;
3512
3513 mutex_lock(&drrs->mutex);
3514 /* DRRS Supported */
3515 seq_puts(m, "\tDRRS Supported: Yes\n");
3516
3517 /* disable_drrs() will make drrs->dp NULL */
3518 if (!drrs->dp) {
3519 seq_puts(m, "Idleness DRRS: Disabled");
3520 mutex_unlock(&drrs->mutex);
3521 return;
3522 }
3523
3524 panel = &drrs->dp->attached_connector->panel;
3525 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3526 drrs->busy_frontbuffer_bits);
3527
3528 seq_puts(m, "\n\t\t");
3529 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3530 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3531 vrefresh = panel->fixed_mode->vrefresh;
3532 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3533 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3534 vrefresh = panel->downclock_mode->vrefresh;
3535 } else {
3536 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3537 drrs->refresh_rate_type);
3538 mutex_unlock(&drrs->mutex);
3539 return;
3540 }
3541 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3542
3543 seq_puts(m, "\n\t\t");
3544 mutex_unlock(&drrs->mutex);
3545 } else {
3546 /* DRRS not supported. Print the VBT parameter*/
3547 seq_puts(m, "\tDRRS Supported : No");
3548 }
3549 seq_puts(m, "\n");
3550}
3551
3552static int i915_drrs_status(struct seq_file *m, void *unused)
3553{
David Weinehall36cdd012016-08-22 13:59:31 +03003554 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3555 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303556 struct intel_crtc *intel_crtc;
3557 int active_crtc_cnt = 0;
3558
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003559 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303560 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003561 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303562 active_crtc_cnt++;
3563 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3564
3565 drrs_status_per_crtc(m, dev, intel_crtc);
3566 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303567 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003568 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303569
3570 if (!active_crtc_cnt)
3571 seq_puts(m, "No active crtc found\n");
3572
3573 return 0;
3574}
3575
Damien Lespiau07144422013-10-15 18:55:40 +01003576struct pipe_crc_info {
3577 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003578 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003579 enum pipe pipe;
3580};
3581
Dave Airlie11bed952014-05-12 15:22:27 +10003582static int i915_dp_mst_info(struct seq_file *m, void *unused)
3583{
David Weinehall36cdd012016-08-22 13:59:31 +03003584 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3585 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003586 struct intel_encoder *intel_encoder;
3587 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003588 struct drm_connector *connector;
3589
Dave Airlie11bed952014-05-12 15:22:27 +10003590 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003591 drm_for_each_connector(connector, dev) {
3592 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003593 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003594
3595 intel_encoder = intel_attached_encoder(connector);
3596 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3597 continue;
3598
3599 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003600 if (!intel_dig_port->dp.can_mst)
3601 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003602
Jim Bride40ae80c2016-04-14 10:18:37 -07003603 seq_printf(m, "MST Source Port %c\n",
3604 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003605 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3606 }
3607 drm_modeset_unlock_all(dev);
3608 return 0;
3609}
3610
Damien Lespiau07144422013-10-15 18:55:40 +01003611static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003612{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003613 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003614 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003615 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3616
David Weinehall36cdd012016-08-22 13:59:31 +03003617 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003618 return -ENODEV;
3619
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003620 spin_lock_irq(&pipe_crc->lock);
3621
3622 if (pipe_crc->opened) {
3623 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003624 return -EBUSY; /* already open */
3625 }
3626
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003627 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003628 filep->private_data = inode->i_private;
3629
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003630 spin_unlock_irq(&pipe_crc->lock);
3631
Damien Lespiau07144422013-10-15 18:55:40 +01003632 return 0;
3633}
3634
3635static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3636{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003637 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003638 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003639 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3640
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003641 spin_lock_irq(&pipe_crc->lock);
3642 pipe_crc->opened = false;
3643 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003644
Damien Lespiau07144422013-10-15 18:55:40 +01003645 return 0;
3646}
3647
3648/* (6 fields, 8 chars each, space separated (5) + '\n') */
3649#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3650/* account for \'0' */
3651#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3652
3653static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3654{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003655 assert_spin_locked(&pipe_crc->lock);
3656 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3657 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003658}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003659
Damien Lespiau07144422013-10-15 18:55:40 +01003660static ssize_t
3661i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3662 loff_t *pos)
3663{
3664 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003665 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003666 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3667 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003668 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003669 ssize_t bytes_read;
3670
3671 /*
3672 * Don't allow user space to provide buffers not big enough to hold
3673 * a line of data.
3674 */
3675 if (count < PIPE_CRC_LINE_LEN)
3676 return -EINVAL;
3677
3678 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3679 return 0;
3680
3681 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003682 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003683 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003684 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003685
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003686 if (filep->f_flags & O_NONBLOCK) {
3687 spin_unlock_irq(&pipe_crc->lock);
3688 return -EAGAIN;
3689 }
3690
3691 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3692 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3693 if (ret) {
3694 spin_unlock_irq(&pipe_crc->lock);
3695 return ret;
3696 }
Damien Lespiau07144422013-10-15 18:55:40 +01003697 }
3698
3699 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003700 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003701
Damien Lespiau07144422013-10-15 18:55:40 +01003702 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003703 while (n_entries > 0) {
3704 struct intel_pipe_crc_entry *entry =
3705 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003706
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003707 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3708 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3709 break;
3710
3711 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3712 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3713
Damien Lespiau07144422013-10-15 18:55:40 +01003714 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3715 "%8u %8x %8x %8x %8x %8x\n",
3716 entry->frame, entry->crc[0],
3717 entry->crc[1], entry->crc[2],
3718 entry->crc[3], entry->crc[4]);
3719
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003720 spin_unlock_irq(&pipe_crc->lock);
3721
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003722 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003723 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003724
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003725 user_buf += PIPE_CRC_LINE_LEN;
3726 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003727
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003728 spin_lock_irq(&pipe_crc->lock);
3729 }
3730
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003731 spin_unlock_irq(&pipe_crc->lock);
3732
Damien Lespiau07144422013-10-15 18:55:40 +01003733 return bytes_read;
3734}
3735
3736static const struct file_operations i915_pipe_crc_fops = {
3737 .owner = THIS_MODULE,
3738 .open = i915_pipe_crc_open,
3739 .read = i915_pipe_crc_read,
3740 .release = i915_pipe_crc_release,
3741};
3742
3743static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3744 {
3745 .name = "i915_pipe_A_crc",
3746 .pipe = PIPE_A,
3747 },
3748 {
3749 .name = "i915_pipe_B_crc",
3750 .pipe = PIPE_B,
3751 },
3752 {
3753 .name = "i915_pipe_C_crc",
3754 .pipe = PIPE_C,
3755 },
3756};
3757
3758static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3759 enum pipe pipe)
3760{
David Weinehall36cdd012016-08-22 13:59:31 +03003761 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003762 struct dentry *ent;
3763 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3764
David Weinehall36cdd012016-08-22 13:59:31 +03003765 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003766 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3767 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003768 if (!ent)
3769 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003770
3771 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003772}
3773
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003774static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003775 "none",
3776 "plane1",
3777 "plane2",
3778 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003779 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003780 "TV",
3781 "DP-B",
3782 "DP-C",
3783 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003784 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003785};
3786
3787static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3788{
3789 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3790 return pipe_crc_sources[source];
3791}
3792
Damien Lespiaubd9db022013-10-15 18:55:36 +01003793static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003794{
David Weinehall36cdd012016-08-22 13:59:31 +03003795 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003796 int i;
3797
3798 for (i = 0; i < I915_MAX_PIPES; i++)
3799 seq_printf(m, "%c %s\n", pipe_name(i),
3800 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3801
3802 return 0;
3803}
3804
Damien Lespiaubd9db022013-10-15 18:55:36 +01003805static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003806{
David Weinehall36cdd012016-08-22 13:59:31 +03003807 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003808}
3809
Daniel Vetter46a19182013-11-01 10:50:20 +01003810static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003811 uint32_t *val)
3812{
Daniel Vetter46a19182013-11-01 10:50:20 +01003813 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3814 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3815
3816 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003817 case INTEL_PIPE_CRC_SOURCE_PIPE:
3818 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3819 break;
3820 case INTEL_PIPE_CRC_SOURCE_NONE:
3821 *val = 0;
3822 break;
3823 default:
3824 return -EINVAL;
3825 }
3826
3827 return 0;
3828}
3829
David Weinehall36cdd012016-08-22 13:59:31 +03003830static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3831 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003832 enum intel_pipe_crc_source *source)
3833{
David Weinehall36cdd012016-08-22 13:59:31 +03003834 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003835 struct intel_encoder *encoder;
3836 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003837 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003838 int ret = 0;
3839
3840 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3841
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003842 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003843 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003844 if (!encoder->base.crtc)
3845 continue;
3846
3847 crtc = to_intel_crtc(encoder->base.crtc);
3848
3849 if (crtc->pipe != pipe)
3850 continue;
3851
3852 switch (encoder->type) {
3853 case INTEL_OUTPUT_TVOUT:
3854 *source = INTEL_PIPE_CRC_SOURCE_TV;
3855 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003856 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003857 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003858 dig_port = enc_to_dig_port(&encoder->base);
3859 switch (dig_port->port) {
3860 case PORT_B:
3861 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3862 break;
3863 case PORT_C:
3864 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3865 break;
3866 case PORT_D:
3867 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3868 break;
3869 default:
3870 WARN(1, "nonexisting DP port %c\n",
3871 port_name(dig_port->port));
3872 break;
3873 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003874 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003875 default:
3876 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003877 }
3878 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003879 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003880
3881 return ret;
3882}
3883
David Weinehall36cdd012016-08-22 13:59:31 +03003884static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003885 enum pipe pipe,
3886 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003887 uint32_t *val)
3888{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003889 bool need_stable_symbols = false;
3890
Daniel Vetter46a19182013-11-01 10:50:20 +01003891 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003892 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003893 if (ret)
3894 return ret;
3895 }
3896
3897 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003898 case INTEL_PIPE_CRC_SOURCE_PIPE:
3899 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3900 break;
3901 case INTEL_PIPE_CRC_SOURCE_DP_B:
3902 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003903 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003904 break;
3905 case INTEL_PIPE_CRC_SOURCE_DP_C:
3906 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003907 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003908 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003909 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003910 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003911 return -EINVAL;
3912 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3913 need_stable_symbols = true;
3914 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003915 case INTEL_PIPE_CRC_SOURCE_NONE:
3916 *val = 0;
3917 break;
3918 default:
3919 return -EINVAL;
3920 }
3921
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003922 /*
3923 * When the pipe CRC tap point is after the transcoders we need
3924 * to tweak symbol-level features to produce a deterministic series of
3925 * symbols for a given frame. We need to reset those features only once
3926 * a frame (instead of every nth symbol):
3927 * - DC-balance: used to ensure a better clock recovery from the data
3928 * link (SDVO)
3929 * - DisplayPort scrambling: used for EMI reduction
3930 */
3931 if (need_stable_symbols) {
3932 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3933
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003934 tmp |= DC_BALANCE_RESET_VLV;
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 -EINVAL;
3947 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003948 I915_WRITE(PORT_DFT2_G4X, tmp);
3949 }
3950
Daniel Vetter7ac01292013-10-18 16:37:06 +02003951 return 0;
3952}
3953
David Weinehall36cdd012016-08-22 13:59:31 +03003954static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003955 enum pipe pipe,
3956 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003957 uint32_t *val)
3958{
Daniel Vetter84093602013-11-01 10:50:21 +01003959 bool need_stable_symbols = false;
3960
Daniel Vetter46a19182013-11-01 10:50:20 +01003961 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003962 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003963 if (ret)
3964 return ret;
3965 }
3966
3967 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003968 case INTEL_PIPE_CRC_SOURCE_PIPE:
3969 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3970 break;
3971 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003972 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003973 return -EINVAL;
3974 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3975 break;
3976 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003977 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003978 return -EINVAL;
3979 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003980 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003981 break;
3982 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003983 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003984 return -EINVAL;
3985 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003986 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003987 break;
3988 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003989 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003990 return -EINVAL;
3991 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003992 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003993 break;
3994 case INTEL_PIPE_CRC_SOURCE_NONE:
3995 *val = 0;
3996 break;
3997 default:
3998 return -EINVAL;
3999 }
4000
Daniel Vetter84093602013-11-01 10:50:21 +01004001 /*
4002 * When the pipe CRC tap point is after the transcoders we need
4003 * to tweak symbol-level features to produce a deterministic series of
4004 * symbols for a given frame. We need to reset those features only once
4005 * a frame (instead of every nth symbol):
4006 * - DC-balance: used to ensure a better clock recovery from the data
4007 * link (SDVO)
4008 * - DisplayPort scrambling: used for EMI reduction
4009 */
4010 if (need_stable_symbols) {
4011 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4012
David Weinehall36cdd012016-08-22 13:59:31 +03004013 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01004014
4015 I915_WRITE(PORT_DFT_I9XX,
4016 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
4017
4018 if (pipe == PIPE_A)
4019 tmp |= PIPE_A_SCRAMBLE_RESET;
4020 else
4021 tmp |= PIPE_B_SCRAMBLE_RESET;
4022
4023 I915_WRITE(PORT_DFT2_G4X, tmp);
4024 }
4025
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004026 return 0;
4027}
4028
David Weinehall36cdd012016-08-22 13:59:31 +03004029static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004030 enum pipe pipe)
4031{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004032 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4033
Ville Syrjäläeb736672014-12-09 21:28:28 +02004034 switch (pipe) {
4035 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004036 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004037 break;
4038 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004039 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004040 break;
4041 case PIPE_C:
4042 tmp &= ~PIPE_C_SCRAMBLE_RESET;
4043 break;
4044 default:
4045 return;
4046 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004047 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
4048 tmp &= ~DC_BALANCE_RESET_VLV;
4049 I915_WRITE(PORT_DFT2_G4X, tmp);
4050
4051}
4052
David Weinehall36cdd012016-08-22 13:59:31 +03004053static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01004054 enum pipe pipe)
4055{
Daniel Vetter84093602013-11-01 10:50:21 +01004056 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4057
4058 if (pipe == PIPE_A)
4059 tmp &= ~PIPE_A_SCRAMBLE_RESET;
4060 else
4061 tmp &= ~PIPE_B_SCRAMBLE_RESET;
4062 I915_WRITE(PORT_DFT2_G4X, tmp);
4063
4064 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
4065 I915_WRITE(PORT_DFT_I9XX,
4066 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
4067 }
4068}
4069
Daniel Vetter46a19182013-11-01 10:50:20 +01004070static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004071 uint32_t *val)
4072{
Daniel Vetter46a19182013-11-01 10:50:20 +01004073 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4074 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4075
4076 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004077 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4078 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4079 break;
4080 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4081 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4082 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004083 case INTEL_PIPE_CRC_SOURCE_PIPE:
4084 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4085 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004086 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004087 *val = 0;
4088 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004089 default:
4090 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004091 }
4092
4093 return 0;
4094}
4095
David Weinehall36cdd012016-08-22 13:59:31 +03004096static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4097 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004098{
David Weinehall36cdd012016-08-22 13:59:31 +03004099 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004100 struct intel_crtc *crtc =
4101 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004102 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004103 struct drm_atomic_state *state;
4104 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004105
4106 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004107 state = drm_atomic_state_alloc(dev);
4108 if (!state) {
4109 ret = -ENOMEM;
4110 goto out;
4111 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004112
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004113 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4114 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4115 if (IS_ERR(pipe_config)) {
4116 ret = PTR_ERR(pipe_config);
4117 goto out;
4118 }
4119
4120 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004121 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004122 pipe_config->pch_pfit.enabled != enable)
4123 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004124
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004125 ret = drm_atomic_commit(state);
4126out:
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004127 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
Chris Wilson08536952016-10-14 13:18:18 +01004128 drm_modeset_unlock_all(dev);
4129 drm_atomic_state_put(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004130}
4131
David Weinehall36cdd012016-08-22 13:59:31 +03004132static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004133 enum pipe pipe,
4134 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004135 uint32_t *val)
4136{
Daniel Vetter46a19182013-11-01 10:50:20 +01004137 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4138 *source = INTEL_PIPE_CRC_SOURCE_PF;
4139
4140 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004141 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4142 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4143 break;
4144 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4145 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4146 break;
4147 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004148 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4149 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004150
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004151 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4152 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004153 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004154 *val = 0;
4155 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004156 default:
4157 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004158 }
4159
4160 return 0;
4161}
4162
David Weinehall36cdd012016-08-22 13:59:31 +03004163static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4164 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004165 enum intel_pipe_crc_source source)
4166{
David Weinehall36cdd012016-08-22 13:59:31 +03004167 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004168 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03004169 struct intel_crtc *crtc =
4170 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02004171 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004172 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004173 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004174
Damien Lespiaucc3da172013-10-15 18:55:31 +01004175 if (pipe_crc->source == source)
4176 return 0;
4177
Damien Lespiauae676fc2013-10-15 18:55:32 +01004178 /* forbid changing the source without going back to 'none' */
4179 if (pipe_crc->source && source)
4180 return -EINVAL;
4181
Imre Deake1296492016-02-12 18:55:17 +02004182 power_domain = POWER_DOMAIN_PIPE(pipe);
4183 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004184 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4185 return -EIO;
4186 }
4187
David Weinehall36cdd012016-08-22 13:59:31 +03004188 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004189 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004190 else if (INTEL_GEN(dev_priv) < 5)
4191 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4192 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4193 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4194 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004195 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004196 else
David Weinehall36cdd012016-08-22 13:59:31 +03004197 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004198
4199 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004200 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004201
Damien Lespiau4b584362013-10-15 18:55:33 +01004202 /* none -> real source transition */
4203 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004204 struct intel_pipe_crc_entry *entries;
4205
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004206 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4207 pipe_name(pipe), pipe_crc_source_name(source));
4208
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004209 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4210 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004211 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004212 if (!entries) {
4213 ret = -ENOMEM;
4214 goto out;
4215 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004216
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004217 /*
4218 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4219 * enabled and disabled dynamically based on package C states,
4220 * user space can't make reliable use of the CRCs, so let's just
4221 * completely disable it.
4222 */
4223 hsw_disable_ips(crtc);
4224
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004225 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004226 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004227 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004228 pipe_crc->head = 0;
4229 pipe_crc->tail = 0;
4230 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004231 }
4232
Damien Lespiaucc3da172013-10-15 18:55:31 +01004233 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004234
Daniel Vetter926321d2013-10-16 13:30:34 +02004235 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4236 POSTING_READ(PIPE_CRC_CTL(pipe));
4237
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004238 /* real source -> none transition */
4239 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004240 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004241 struct intel_crtc *crtc =
4242 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004243
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004244 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4245 pipe_name(pipe));
4246
Daniel Vettera33d7102014-06-06 08:22:08 +02004247 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004248 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004249 intel_wait_for_vblank(dev, pipe);
4250 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004251
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004252 spin_lock_irq(&pipe_crc->lock);
4253 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004254 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004255 pipe_crc->head = 0;
4256 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004257 spin_unlock_irq(&pipe_crc->lock);
4258
4259 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004260
David Weinehall36cdd012016-08-22 13:59:31 +03004261 if (IS_G4X(dev_priv))
4262 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4263 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4264 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4265 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4266 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004267
4268 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004269 }
4270
Imre Deake1296492016-02-12 18:55:17 +02004271 ret = 0;
4272
4273out:
4274 intel_display_power_put(dev_priv, power_domain);
4275
4276 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004277}
4278
4279/*
4280 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004281 * command: wsp* object wsp+ name wsp+ source wsp*
4282 * object: 'pipe'
4283 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004284 * source: (none | plane1 | plane2 | pf)
4285 * wsp: (#0x20 | #0x9 | #0xA)+
4286 *
4287 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004288 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4289 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004290 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004291static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004292{
4293 int n_words = 0;
4294
4295 while (*buf) {
4296 char *end;
4297
4298 /* skip leading white space */
4299 buf = skip_spaces(buf);
4300 if (!*buf)
4301 break; /* end of buffer */
4302
4303 /* find end of word */
4304 for (end = buf; *end && !isspace(*end); end++)
4305 ;
4306
4307 if (n_words == max_words) {
4308 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4309 max_words);
4310 return -EINVAL; /* ran out of words[] before bytes */
4311 }
4312
4313 if (*end)
4314 *end++ = '\0';
4315 words[n_words++] = buf;
4316 buf = end;
4317 }
4318
4319 return n_words;
4320}
4321
Damien Lespiaub94dec82013-10-15 18:55:35 +01004322enum intel_pipe_crc_object {
4323 PIPE_CRC_OBJECT_PIPE,
4324};
4325
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004326static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004327 "pipe",
4328};
4329
4330static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004331display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004332{
4333 int i;
4334
4335 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4336 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004337 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004338 return 0;
4339 }
4340
4341 return -EINVAL;
4342}
4343
Damien Lespiaubd9db022013-10-15 18:55:36 +01004344static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004345{
4346 const char name = buf[0];
4347
4348 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4349 return -EINVAL;
4350
4351 *pipe = name - 'A';
4352
4353 return 0;
4354}
4355
4356static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004357display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004358{
4359 int i;
4360
4361 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4362 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004363 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004364 return 0;
4365 }
4366
4367 return -EINVAL;
4368}
4369
David Weinehall36cdd012016-08-22 13:59:31 +03004370static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4371 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004372{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004373#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004374 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004375 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004376 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004377 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004378 enum intel_pipe_crc_source source;
4379
Damien Lespiaubd9db022013-10-15 18:55:36 +01004380 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004381 if (n_words != N_WORDS) {
4382 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4383 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004384 return -EINVAL;
4385 }
4386
Damien Lespiaubd9db022013-10-15 18:55:36 +01004387 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004388 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004389 return -EINVAL;
4390 }
4391
Damien Lespiaubd9db022013-10-15 18:55:36 +01004392 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004393 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4394 return -EINVAL;
4395 }
4396
Damien Lespiaubd9db022013-10-15 18:55:36 +01004397 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004398 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004399 return -EINVAL;
4400 }
4401
David Weinehall36cdd012016-08-22 13:59:31 +03004402 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004403}
4404
Damien Lespiaubd9db022013-10-15 18:55:36 +01004405static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4406 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004407{
4408 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004409 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004410 char *tmpbuf;
4411 int ret;
4412
4413 if (len == 0)
4414 return 0;
4415
4416 if (len > PAGE_SIZE - 1) {
4417 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4418 PAGE_SIZE);
4419 return -E2BIG;
4420 }
4421
4422 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4423 if (!tmpbuf)
4424 return -ENOMEM;
4425
4426 if (copy_from_user(tmpbuf, ubuf, len)) {
4427 ret = -EFAULT;
4428 goto out;
4429 }
4430 tmpbuf[len] = '\0';
4431
David Weinehall36cdd012016-08-22 13:59:31 +03004432 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004433
4434out:
4435 kfree(tmpbuf);
4436 if (ret < 0)
4437 return ret;
4438
4439 *offp += len;
4440 return len;
4441}
4442
Damien Lespiaubd9db022013-10-15 18:55:36 +01004443static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004444 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004445 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004446 .read = seq_read,
4447 .llseek = seq_lseek,
4448 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004449 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004450};
4451
Todd Previteeb3394fa2015-04-18 00:04:19 -07004452static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004453 const char __user *ubuf,
4454 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004455{
4456 char *input_buffer;
4457 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004458 struct drm_device *dev;
4459 struct drm_connector *connector;
4460 struct list_head *connector_list;
4461 struct intel_dp *intel_dp;
4462 int val = 0;
4463
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304464 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004465
Todd Previteeb3394fa2015-04-18 00:04:19 -07004466 connector_list = &dev->mode_config.connector_list;
4467
4468 if (len == 0)
4469 return 0;
4470
4471 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4472 if (!input_buffer)
4473 return -ENOMEM;
4474
4475 if (copy_from_user(input_buffer, ubuf, len)) {
4476 status = -EFAULT;
4477 goto out;
4478 }
4479
4480 input_buffer[len] = '\0';
4481 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4482
4483 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004484 if (connector->connector_type !=
4485 DRM_MODE_CONNECTOR_DisplayPort)
4486 continue;
4487
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304488 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004489 connector->encoder != NULL) {
4490 intel_dp = enc_to_intel_dp(connector->encoder);
4491 status = kstrtoint(input_buffer, 10, &val);
4492 if (status < 0)
4493 goto out;
4494 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4495 /* To prevent erroneous activation of the compliance
4496 * testing code, only accept an actual value of 1 here
4497 */
4498 if (val == 1)
4499 intel_dp->compliance_test_active = 1;
4500 else
4501 intel_dp->compliance_test_active = 0;
4502 }
4503 }
4504out:
4505 kfree(input_buffer);
4506 if (status < 0)
4507 return status;
4508
4509 *offp += len;
4510 return len;
4511}
4512
4513static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4514{
4515 struct drm_device *dev = m->private;
4516 struct drm_connector *connector;
4517 struct list_head *connector_list = &dev->mode_config.connector_list;
4518 struct intel_dp *intel_dp;
4519
Todd Previteeb3394fa2015-04-18 00:04:19 -07004520 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004521 if (connector->connector_type !=
4522 DRM_MODE_CONNECTOR_DisplayPort)
4523 continue;
4524
4525 if (connector->status == connector_status_connected &&
4526 connector->encoder != NULL) {
4527 intel_dp = enc_to_intel_dp(connector->encoder);
4528 if (intel_dp->compliance_test_active)
4529 seq_puts(m, "1");
4530 else
4531 seq_puts(m, "0");
4532 } else
4533 seq_puts(m, "0");
4534 }
4535
4536 return 0;
4537}
4538
4539static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004540 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004541{
David Weinehall36cdd012016-08-22 13:59:31 +03004542 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004543
David Weinehall36cdd012016-08-22 13:59:31 +03004544 return single_open(file, i915_displayport_test_active_show,
4545 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004546}
4547
4548static const struct file_operations i915_displayport_test_active_fops = {
4549 .owner = THIS_MODULE,
4550 .open = i915_displayport_test_active_open,
4551 .read = seq_read,
4552 .llseek = seq_lseek,
4553 .release = single_release,
4554 .write = i915_displayport_test_active_write
4555};
4556
4557static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4558{
4559 struct drm_device *dev = m->private;
4560 struct drm_connector *connector;
4561 struct list_head *connector_list = &dev->mode_config.connector_list;
4562 struct intel_dp *intel_dp;
4563
Todd Previteeb3394fa2015-04-18 00:04:19 -07004564 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004565 if (connector->connector_type !=
4566 DRM_MODE_CONNECTOR_DisplayPort)
4567 continue;
4568
4569 if (connector->status == connector_status_connected &&
4570 connector->encoder != NULL) {
4571 intel_dp = enc_to_intel_dp(connector->encoder);
4572 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4573 } else
4574 seq_puts(m, "0");
4575 }
4576
4577 return 0;
4578}
4579static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004580 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004581{
David Weinehall36cdd012016-08-22 13:59:31 +03004582 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004583
David Weinehall36cdd012016-08-22 13:59:31 +03004584 return single_open(file, i915_displayport_test_data_show,
4585 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004586}
4587
4588static const struct file_operations i915_displayport_test_data_fops = {
4589 .owner = THIS_MODULE,
4590 .open = i915_displayport_test_data_open,
4591 .read = seq_read,
4592 .llseek = seq_lseek,
4593 .release = single_release
4594};
4595
4596static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4597{
4598 struct drm_device *dev = m->private;
4599 struct drm_connector *connector;
4600 struct list_head *connector_list = &dev->mode_config.connector_list;
4601 struct intel_dp *intel_dp;
4602
Todd Previteeb3394fa2015-04-18 00:04:19 -07004603 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004604 if (connector->connector_type !=
4605 DRM_MODE_CONNECTOR_DisplayPort)
4606 continue;
4607
4608 if (connector->status == connector_status_connected &&
4609 connector->encoder != NULL) {
4610 intel_dp = enc_to_intel_dp(connector->encoder);
4611 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4612 } else
4613 seq_puts(m, "0");
4614 }
4615
4616 return 0;
4617}
4618
4619static int i915_displayport_test_type_open(struct inode *inode,
4620 struct file *file)
4621{
David Weinehall36cdd012016-08-22 13:59:31 +03004622 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004623
David Weinehall36cdd012016-08-22 13:59:31 +03004624 return single_open(file, i915_displayport_test_type_show,
4625 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004626}
4627
4628static const struct file_operations i915_displayport_test_type_fops = {
4629 .owner = THIS_MODULE,
4630 .open = i915_displayport_test_type_open,
4631 .read = seq_read,
4632 .llseek = seq_lseek,
4633 .release = single_release
4634};
4635
Damien Lespiau97e94b22014-11-04 17:06:50 +00004636static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004637{
David Weinehall36cdd012016-08-22 13:59:31 +03004638 struct drm_i915_private *dev_priv = m->private;
4639 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004640 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004641 int num_levels;
4642
David Weinehall36cdd012016-08-22 13:59:31 +03004643 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004644 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004645 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004646 num_levels = 1;
4647 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004648 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004649
4650 drm_modeset_lock_all(dev);
4651
4652 for (level = 0; level < num_levels; level++) {
4653 unsigned int latency = wm[level];
4654
Damien Lespiau97e94b22014-11-04 17:06:50 +00004655 /*
4656 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004657 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004658 */
David Weinehall36cdd012016-08-22 13:59:31 +03004659 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4660 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004661 latency *= 10;
4662 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004663 latency *= 5;
4664
4665 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004666 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004667 }
4668
4669 drm_modeset_unlock_all(dev);
4670}
4671
4672static int pri_wm_latency_show(struct seq_file *m, void *data)
4673{
David Weinehall36cdd012016-08-22 13:59:31 +03004674 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004675 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004676
David Weinehall36cdd012016-08-22 13:59:31 +03004677 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004678 latencies = dev_priv->wm.skl_latency;
4679 else
David Weinehall36cdd012016-08-22 13:59:31 +03004680 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004681
4682 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004683
4684 return 0;
4685}
4686
4687static int spr_wm_latency_show(struct seq_file *m, void *data)
4688{
David Weinehall36cdd012016-08-22 13:59:31 +03004689 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004690 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004691
David Weinehall36cdd012016-08-22 13:59:31 +03004692 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004693 latencies = dev_priv->wm.skl_latency;
4694 else
David Weinehall36cdd012016-08-22 13:59:31 +03004695 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004696
4697 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004698
4699 return 0;
4700}
4701
4702static int cur_wm_latency_show(struct seq_file *m, void *data)
4703{
David Weinehall36cdd012016-08-22 13:59:31 +03004704 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004705 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004706
David Weinehall36cdd012016-08-22 13:59:31 +03004707 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004708 latencies = dev_priv->wm.skl_latency;
4709 else
David Weinehall36cdd012016-08-22 13:59:31 +03004710 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004711
4712 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004713
4714 return 0;
4715}
4716
4717static int pri_wm_latency_open(struct inode *inode, struct file *file)
4718{
David Weinehall36cdd012016-08-22 13:59:31 +03004719 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004720
David Weinehall36cdd012016-08-22 13:59:31 +03004721 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004722 return -ENODEV;
4723
David Weinehall36cdd012016-08-22 13:59:31 +03004724 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004725}
4726
4727static int spr_wm_latency_open(struct inode *inode, struct file *file)
4728{
David Weinehall36cdd012016-08-22 13:59:31 +03004729 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004730
David Weinehall36cdd012016-08-22 13:59:31 +03004731 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004732 return -ENODEV;
4733
David Weinehall36cdd012016-08-22 13:59:31 +03004734 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004735}
4736
4737static int cur_wm_latency_open(struct inode *inode, struct file *file)
4738{
David Weinehall36cdd012016-08-22 13:59:31 +03004739 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004740
David Weinehall36cdd012016-08-22 13:59:31 +03004741 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004742 return -ENODEV;
4743
David Weinehall36cdd012016-08-22 13:59:31 +03004744 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004745}
4746
4747static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004748 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004749{
4750 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004751 struct drm_i915_private *dev_priv = m->private;
4752 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004753 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004754 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004755 int level;
4756 int ret;
4757 char tmp[32];
4758
David Weinehall36cdd012016-08-22 13:59:31 +03004759 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004760 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004761 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004762 num_levels = 1;
4763 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004764 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004765
Ville Syrjälä369a1342014-01-22 14:36:08 +02004766 if (len >= sizeof(tmp))
4767 return -EINVAL;
4768
4769 if (copy_from_user(tmp, ubuf, len))
4770 return -EFAULT;
4771
4772 tmp[len] = '\0';
4773
Damien Lespiau97e94b22014-11-04 17:06:50 +00004774 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4775 &new[0], &new[1], &new[2], &new[3],
4776 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004777 if (ret != num_levels)
4778 return -EINVAL;
4779
4780 drm_modeset_lock_all(dev);
4781
4782 for (level = 0; level < num_levels; level++)
4783 wm[level] = new[level];
4784
4785 drm_modeset_unlock_all(dev);
4786
4787 return len;
4788}
4789
4790
4791static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4792 size_t len, loff_t *offp)
4793{
4794 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004795 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004796 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004797
David Weinehall36cdd012016-08-22 13:59:31 +03004798 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004799 latencies = dev_priv->wm.skl_latency;
4800 else
David Weinehall36cdd012016-08-22 13:59:31 +03004801 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004802
4803 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004804}
4805
4806static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4807 size_t len, loff_t *offp)
4808{
4809 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004810 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004811 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004812
David Weinehall36cdd012016-08-22 13:59:31 +03004813 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004814 latencies = dev_priv->wm.skl_latency;
4815 else
David Weinehall36cdd012016-08-22 13:59:31 +03004816 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004817
4818 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004819}
4820
4821static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4822 size_t len, loff_t *offp)
4823{
4824 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004825 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004826 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004827
David Weinehall36cdd012016-08-22 13:59:31 +03004828 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004829 latencies = dev_priv->wm.skl_latency;
4830 else
David Weinehall36cdd012016-08-22 13:59:31 +03004831 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004832
4833 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004834}
4835
4836static const struct file_operations i915_pri_wm_latency_fops = {
4837 .owner = THIS_MODULE,
4838 .open = pri_wm_latency_open,
4839 .read = seq_read,
4840 .llseek = seq_lseek,
4841 .release = single_release,
4842 .write = pri_wm_latency_write
4843};
4844
4845static const struct file_operations i915_spr_wm_latency_fops = {
4846 .owner = THIS_MODULE,
4847 .open = spr_wm_latency_open,
4848 .read = seq_read,
4849 .llseek = seq_lseek,
4850 .release = single_release,
4851 .write = spr_wm_latency_write
4852};
4853
4854static const struct file_operations i915_cur_wm_latency_fops = {
4855 .owner = THIS_MODULE,
4856 .open = cur_wm_latency_open,
4857 .read = seq_read,
4858 .llseek = seq_lseek,
4859 .release = single_release,
4860 .write = cur_wm_latency_write
4861};
4862
Kees Cook647416f2013-03-10 14:10:06 -07004863static int
4864i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004865{
David Weinehall36cdd012016-08-22 13:59:31 +03004866 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004867
Chris Wilsond98c52c2016-04-13 17:35:05 +01004868 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004869
Kees Cook647416f2013-03-10 14:10:06 -07004870 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004871}
4872
Kees Cook647416f2013-03-10 14:10:06 -07004873static int
4874i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004875{
David Weinehall36cdd012016-08-22 13:59:31 +03004876 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004877
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004878 /*
4879 * There is no safeguard against this debugfs entry colliding
4880 * with the hangcheck calling same i915_handle_error() in
4881 * parallel, causing an explosion. For now we assume that the
4882 * test harness is responsible enough not to inject gpu hangs
4883 * while it is writing to 'i915_wedged'
4884 */
4885
Chris Wilsond98c52c2016-04-13 17:35:05 +01004886 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004887 return -EAGAIN;
4888
Chris Wilsonc0336662016-05-06 15:40:21 +01004889 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004890 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004891
Kees Cook647416f2013-03-10 14:10:06 -07004892 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004893}
4894
Kees Cook647416f2013-03-10 14:10:06 -07004895DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4896 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004897 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004898
Kees Cook647416f2013-03-10 14:10:06 -07004899static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004900i915_ring_missed_irq_get(void *data, u64 *val)
4901{
David Weinehall36cdd012016-08-22 13:59:31 +03004902 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004903
4904 *val = dev_priv->gpu_error.missed_irq_rings;
4905 return 0;
4906}
4907
4908static int
4909i915_ring_missed_irq_set(void *data, u64 val)
4910{
David Weinehall36cdd012016-08-22 13:59:31 +03004911 struct drm_i915_private *dev_priv = data;
4912 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004913 int ret;
4914
4915 /* Lock against concurrent debugfs callers */
4916 ret = mutex_lock_interruptible(&dev->struct_mutex);
4917 if (ret)
4918 return ret;
4919 dev_priv->gpu_error.missed_irq_rings = val;
4920 mutex_unlock(&dev->struct_mutex);
4921
4922 return 0;
4923}
4924
4925DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4926 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4927 "0x%08llx\n");
4928
4929static int
4930i915_ring_test_irq_get(void *data, u64 *val)
4931{
David Weinehall36cdd012016-08-22 13:59:31 +03004932 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004933
4934 *val = dev_priv->gpu_error.test_irq_rings;
4935
4936 return 0;
4937}
4938
4939static int
4940i915_ring_test_irq_set(void *data, u64 val)
4941{
David Weinehall36cdd012016-08-22 13:59:31 +03004942 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004943
Chris Wilson3a122c22016-06-17 14:35:05 +01004944 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004945 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004946 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004947
4948 return 0;
4949}
4950
4951DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4952 i915_ring_test_irq_get, i915_ring_test_irq_set,
4953 "0x%08llx\n");
4954
Chris Wilsondd624af2013-01-15 12:39:35 +00004955#define DROP_UNBOUND 0x1
4956#define DROP_BOUND 0x2
4957#define DROP_RETIRE 0x4
4958#define DROP_ACTIVE 0x8
4959#define DROP_ALL (DROP_UNBOUND | \
4960 DROP_BOUND | \
4961 DROP_RETIRE | \
4962 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004963static int
4964i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004965{
Kees Cook647416f2013-03-10 14:10:06 -07004966 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004967
Kees Cook647416f2013-03-10 14:10:06 -07004968 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004969}
4970
Kees Cook647416f2013-03-10 14:10:06 -07004971static int
4972i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004973{
David Weinehall36cdd012016-08-22 13:59:31 +03004974 struct drm_i915_private *dev_priv = data;
4975 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004976 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004977
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004978 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004979
4980 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4981 * on ioctls on -EAGAIN. */
4982 ret = mutex_lock_interruptible(&dev->struct_mutex);
4983 if (ret)
4984 return ret;
4985
4986 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004987 ret = i915_gem_wait_for_idle(dev_priv,
4988 I915_WAIT_INTERRUPTIBLE |
4989 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004990 if (ret)
4991 goto unlock;
4992 }
4993
4994 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004995 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004996
Chris Wilson21ab4e72014-09-09 11:16:08 +01004997 if (val & DROP_BOUND)
4998 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004999
Chris Wilson21ab4e72014-09-09 11:16:08 +01005000 if (val & DROP_UNBOUND)
5001 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00005002
5003unlock:
5004 mutex_unlock(&dev->struct_mutex);
5005
Kees Cook647416f2013-03-10 14:10:06 -07005006 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00005007}
5008
Kees Cook647416f2013-03-10 14:10:06 -07005009DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
5010 i915_drop_caches_get, i915_drop_caches_set,
5011 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00005012
Kees Cook647416f2013-03-10 14:10:06 -07005013static int
5014i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005015{
David Weinehall36cdd012016-08-22 13:59:31 +03005016 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005017
David Weinehall36cdd012016-08-22 13:59:31 +03005018 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005019 return -ENODEV;
5020
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005021 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005022 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005023}
5024
Kees Cook647416f2013-03-10 14:10:06 -07005025static int
5026i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005027{
David Weinehall36cdd012016-08-22 13:59:31 +03005028 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305029 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005030 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005031
David Weinehall36cdd012016-08-22 13:59:31 +03005032 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005033 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005034
Kees Cook647416f2013-03-10 14:10:06 -07005035 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005036
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005037 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005038 if (ret)
5039 return ret;
5040
Jesse Barnes358733e2011-07-27 11:53:01 -07005041 /*
5042 * Turbo will still be enabled, but won't go above the set value.
5043 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305044 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005045
Akash Goelbc4d91f2015-02-26 16:09:47 +05305046 hw_max = dev_priv->rps.max_freq;
5047 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005048
Ben Widawskyb39fb292014-03-19 18:31:11 -07005049 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005050 mutex_unlock(&dev_priv->rps.hw_lock);
5051 return -EINVAL;
5052 }
5053
Ben Widawskyb39fb292014-03-19 18:31:11 -07005054 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005055
Chris Wilsondc979972016-05-10 14:10:04 +01005056 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005057
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005058 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005059
Kees Cook647416f2013-03-10 14:10:06 -07005060 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005061}
5062
Kees Cook647416f2013-03-10 14:10:06 -07005063DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5064 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005065 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005066
Kees Cook647416f2013-03-10 14:10:06 -07005067static int
5068i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005069{
David Weinehall36cdd012016-08-22 13:59:31 +03005070 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005071
Chris Wilson62e1baa2016-07-13 09:10:36 +01005072 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005073 return -ENODEV;
5074
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005075 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005076 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005077}
5078
Kees Cook647416f2013-03-10 14:10:06 -07005079static int
5080i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005081{
David Weinehall36cdd012016-08-22 13:59:31 +03005082 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305083 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005084 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005085
Chris Wilson62e1baa2016-07-13 09:10:36 +01005086 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005087 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005088
Kees Cook647416f2013-03-10 14:10:06 -07005089 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005090
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005091 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005092 if (ret)
5093 return ret;
5094
Jesse Barnes1523c312012-05-25 12:34:54 -07005095 /*
5096 * Turbo will still be enabled, but won't go below the set value.
5097 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305098 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005099
Akash Goelbc4d91f2015-02-26 16:09:47 +05305100 hw_max = dev_priv->rps.max_freq;
5101 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005102
David Weinehall36cdd012016-08-22 13:59:31 +03005103 if (val < hw_min ||
5104 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005105 mutex_unlock(&dev_priv->rps.hw_lock);
5106 return -EINVAL;
5107 }
5108
Ben Widawskyb39fb292014-03-19 18:31:11 -07005109 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005110
Chris Wilsondc979972016-05-10 14:10:04 +01005111 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005112
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005113 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005114
Kees Cook647416f2013-03-10 14:10:06 -07005115 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005116}
5117
Kees Cook647416f2013-03-10 14:10:06 -07005118DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5119 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005120 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005121
Kees Cook647416f2013-03-10 14:10:06 -07005122static int
5123i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005124{
David Weinehall36cdd012016-08-22 13:59:31 +03005125 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005126 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005127
David Weinehall36cdd012016-08-22 13:59:31 +03005128 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005129 return -ENODEV;
5130
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005131 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005132
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005133 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005134
5135 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005136
Kees Cook647416f2013-03-10 14:10:06 -07005137 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005138
Kees Cook647416f2013-03-10 14:10:06 -07005139 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005140}
5141
Kees Cook647416f2013-03-10 14:10:06 -07005142static int
5143i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005144{
David Weinehall36cdd012016-08-22 13:59:31 +03005145 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005146 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005147
David Weinehall36cdd012016-08-22 13:59:31 +03005148 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005149 return -ENODEV;
5150
Kees Cook647416f2013-03-10 14:10:06 -07005151 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005152 return -EINVAL;
5153
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005154 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005155 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005156
5157 /* Update the cache sharing policy here as well */
5158 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5159 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5160 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5161 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5162
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005163 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005164 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005165}
5166
Kees Cook647416f2013-03-10 14:10:06 -07005167DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5168 i915_cache_sharing_get, i915_cache_sharing_set,
5169 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005170
David Weinehall36cdd012016-08-22 13:59:31 +03005171static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005172 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005173{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005174 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005175 int ss;
5176 u32 sig1[ss_max], sig2[ss_max];
5177
5178 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5179 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5180 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5181 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5182
5183 for (ss = 0; ss < ss_max; ss++) {
5184 unsigned int eu_cnt;
5185
5186 if (sig1[ss] & CHV_SS_PG_ENABLE)
5187 /* skip disabled subslice */
5188 continue;
5189
Imre Deakf08a0c92016-08-31 19:13:04 +03005190 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005191 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005192 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5193 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5194 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5195 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005196 sseu->eu_total += eu_cnt;
5197 sseu->eu_per_subslice = max_t(unsigned int,
5198 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005199 }
Jeff McGee5d395252015-04-03 18:13:17 -07005200}
5201
David Weinehall36cdd012016-08-22 13:59:31 +03005202static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005203 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005204{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005205 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005206 int s, ss;
5207 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5208
Jeff McGee1c046bc2015-04-03 18:13:18 -07005209 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005210 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005211 s_max = 1;
5212 ss_max = 3;
5213 }
5214
5215 for (s = 0; s < s_max; s++) {
5216 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5217 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5218 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5219 }
5220
Jeff McGee5d395252015-04-03 18:13:17 -07005221 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5222 GEN9_PGCTL_SSA_EU19_ACK |
5223 GEN9_PGCTL_SSA_EU210_ACK |
5224 GEN9_PGCTL_SSA_EU311_ACK;
5225 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5226 GEN9_PGCTL_SSB_EU19_ACK |
5227 GEN9_PGCTL_SSB_EU210_ACK |
5228 GEN9_PGCTL_SSB_EU311_ACK;
5229
5230 for (s = 0; s < s_max; s++) {
5231 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5232 /* skip disabled slice */
5233 continue;
5234
Imre Deakf08a0c92016-08-31 19:13:04 +03005235 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005236
David Weinehall36cdd012016-08-22 13:59:31 +03005237 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005238 sseu->subslice_mask =
5239 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005240
Jeff McGee5d395252015-04-03 18:13:17 -07005241 for (ss = 0; ss < ss_max; ss++) {
5242 unsigned int eu_cnt;
5243
Imre Deak57ec1712016-08-31 19:13:05 +03005244 if (IS_BROXTON(dev_priv)) {
5245 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5246 /* skip disabled subslice */
5247 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005248
Imre Deak57ec1712016-08-31 19:13:05 +03005249 sseu->subslice_mask |= BIT(ss);
5250 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005251
Jeff McGee5d395252015-04-03 18:13:17 -07005252 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5253 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005254 sseu->eu_total += eu_cnt;
5255 sseu->eu_per_subslice = max_t(unsigned int,
5256 sseu->eu_per_subslice,
5257 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005258 }
5259 }
5260}
5261
David Weinehall36cdd012016-08-22 13:59:31 +03005262static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005263 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005264{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005265 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005266 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005267
Imre Deakf08a0c92016-08-31 19:13:04 +03005268 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005269
Imre Deakf08a0c92016-08-31 19:13:04 +03005270 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005271 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005272 sseu->eu_per_subslice =
5273 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005274 sseu->eu_total = sseu->eu_per_subslice *
5275 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005276
5277 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005278 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005279 u8 subslice_7eu =
5280 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005281
Imre Deak915490d2016-08-31 19:13:01 +03005282 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005283 }
5284 }
5285}
5286
Imre Deak615d8902016-08-31 19:13:03 +03005287static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5288 const struct sseu_dev_info *sseu)
5289{
5290 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5291 const char *type = is_available_info ? "Available" : "Enabled";
5292
Imre Deakc67ba532016-08-31 19:13:06 +03005293 seq_printf(m, " %s Slice Mask: %04x\n", type,
5294 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005295 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005296 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005297 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005298 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005299 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5300 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005301 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005302 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005303 seq_printf(m, " %s EU Total: %u\n", type,
5304 sseu->eu_total);
5305 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5306 sseu->eu_per_subslice);
5307
5308 if (!is_available_info)
5309 return;
5310
5311 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5312 if (HAS_POOLED_EU(dev_priv))
5313 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5314
5315 seq_printf(m, " Has Slice Power Gating: %s\n",
5316 yesno(sseu->has_slice_pg));
5317 seq_printf(m, " Has Subslice Power Gating: %s\n",
5318 yesno(sseu->has_subslice_pg));
5319 seq_printf(m, " Has EU Power Gating: %s\n",
5320 yesno(sseu->has_eu_pg));
5321}
5322
Jeff McGee38732182015-02-13 10:27:54 -06005323static int i915_sseu_status(struct seq_file *m, void *unused)
5324{
David Weinehall36cdd012016-08-22 13:59:31 +03005325 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005326 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005327
David Weinehall36cdd012016-08-22 13:59:31 +03005328 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005329 return -ENODEV;
5330
5331 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005332 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005333
Jeff McGee7f992ab2015-02-13 10:27:55 -06005334 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005335 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005336
5337 intel_runtime_pm_get(dev_priv);
5338
David Weinehall36cdd012016-08-22 13:59:31 +03005339 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005340 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005341 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005342 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005343 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005344 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005345 }
David Weinehall238010e2016-08-01 17:33:27 +03005346
5347 intel_runtime_pm_put(dev_priv);
5348
Imre Deak615d8902016-08-31 19:13:03 +03005349 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005350
Jeff McGee38732182015-02-13 10:27:54 -06005351 return 0;
5352}
5353
Ben Widawsky6d794d42011-04-25 11:25:56 -07005354static int i915_forcewake_open(struct inode *inode, struct file *file)
5355{
David Weinehall36cdd012016-08-22 13:59:31 +03005356 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005357
David Weinehall36cdd012016-08-22 13:59:31 +03005358 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005359 return 0;
5360
Chris Wilson6daccb02015-01-16 11:34:35 +02005361 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005362 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005363
5364 return 0;
5365}
5366
Ben Widawskyc43b5632012-04-16 14:07:40 -07005367static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005368{
David Weinehall36cdd012016-08-22 13:59:31 +03005369 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005370
David Weinehall36cdd012016-08-22 13:59:31 +03005371 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005372 return 0;
5373
Mika Kuoppala59bad942015-01-16 11:34:40 +02005374 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005375 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005376
5377 return 0;
5378}
5379
5380static const struct file_operations i915_forcewake_fops = {
5381 .owner = THIS_MODULE,
5382 .open = i915_forcewake_open,
5383 .release = i915_forcewake_release,
5384};
5385
5386static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5387{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005388 struct dentry *ent;
5389
5390 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005391 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005392 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005393 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005394 if (!ent)
5395 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005396
Ben Widawsky8eb57292011-05-11 15:10:58 -07005397 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005398}
5399
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005400static int i915_debugfs_create(struct dentry *root,
5401 struct drm_minor *minor,
5402 const char *name,
5403 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005404{
Jesse Barnes358733e2011-07-27 11:53:01 -07005405 struct dentry *ent;
5406
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005407 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005408 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005409 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005410 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005411 if (!ent)
5412 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005413
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005414 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005415}
5416
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005417static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005418 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005419 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005420 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005421 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005422 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005423 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005424 {"i915_gem_request", i915_gem_request_info, 0},
5425 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005426 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005427 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005428 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5429 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5430 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005431 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005432 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005433 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005434 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005435 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305436 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005437 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005438 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005439 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005440 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005441 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005442 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005443 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005444 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005445 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005446 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005447 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005448 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005449 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005450 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005451 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005452 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005453 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005454 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005455 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005456 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005457 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005458 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005459 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005460 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005461 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005462 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005463 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005464 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005465 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005466 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005467 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305468 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005469 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005470};
Ben Gamari27c202a2009-07-01 22:26:52 -04005471#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005472
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005473static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005474 const char *name;
5475 const struct file_operations *fops;
5476} i915_debugfs_files[] = {
5477 {"i915_wedged", &i915_wedged_fops},
5478 {"i915_max_freq", &i915_max_freq_fops},
5479 {"i915_min_freq", &i915_min_freq_fops},
5480 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005481 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5482 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005483 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005484#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005485 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005486#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005487 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005488 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005489 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5490 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5491 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005492 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005493 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5494 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05305495 {"i915_dp_test_active", &i915_displayport_test_active_fops},
5496 {"i915_guc_log_control", &i915_guc_log_control_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005497};
5498
David Weinehall36cdd012016-08-22 13:59:31 +03005499void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005500{
Daniel Vetterb3783602013-11-14 11:30:42 +01005501 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005502
Damien Lespiau055e3932014-08-18 13:49:10 +01005503 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005504 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005505
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005506 pipe_crc->opened = false;
5507 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005508 init_waitqueue_head(&pipe_crc->wq);
5509 }
5510}
5511
Chris Wilson1dac8912016-06-24 14:00:17 +01005512int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005513{
Chris Wilson91c8a322016-07-05 10:40:23 +01005514 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005515 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005516
Ben Widawsky6d794d42011-04-25 11:25:56 -07005517 ret = i915_forcewake_create(minor->debugfs_root, minor);
5518 if (ret)
5519 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005520
Damien Lespiau07144422013-10-15 18:55:40 +01005521 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5522 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5523 if (ret)
5524 return ret;
5525 }
5526
Daniel Vetter34b96742013-07-04 20:49:44 +02005527 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5528 ret = i915_debugfs_create(minor->debugfs_root, minor,
5529 i915_debugfs_files[i].name,
5530 i915_debugfs_files[i].fops);
5531 if (ret)
5532 return ret;
5533 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005534
Ben Gamari27c202a2009-07-01 22:26:52 -04005535 return drm_debugfs_create_files(i915_debugfs_list,
5536 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005537 minor->debugfs_root, minor);
5538}
5539
Chris Wilson1dac8912016-06-24 14:00:17 +01005540void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005541{
Chris Wilson91c8a322016-07-05 10:40:23 +01005542 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005543 int i;
5544
Ben Gamari27c202a2009-07-01 22:26:52 -04005545 drm_debugfs_remove_files(i915_debugfs_list,
5546 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005547
David Weinehall36cdd012016-08-22 13:59:31 +03005548 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005549 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005550
Daniel Vettere309a992013-10-16 22:55:51 +02005551 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005552 struct drm_info_list *info_list =
5553 (struct drm_info_list *)&i915_pipe_crc_data[i];
5554
5555 drm_debugfs_remove_files(info_list, 1, minor);
5556 }
5557
Daniel Vetter34b96742013-07-04 20:49:44 +02005558 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5559 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005560 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005561
5562 drm_debugfs_remove_files(info_list, 1, minor);
5563 }
Ben Gamari20172632009-02-17 20:08:50 -05005564}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005565
5566struct dpcd_block {
5567 /* DPCD dump start address. */
5568 unsigned int offset;
5569 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5570 unsigned int end;
5571 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5572 size_t size;
5573 /* Only valid for eDP. */
5574 bool edp;
5575};
5576
5577static const struct dpcd_block i915_dpcd_debug[] = {
5578 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5579 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5580 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5581 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5582 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5583 { .offset = DP_SET_POWER },
5584 { .offset = DP_EDP_DPCD_REV },
5585 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5586 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5587 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5588};
5589
5590static int i915_dpcd_show(struct seq_file *m, void *data)
5591{
5592 struct drm_connector *connector = m->private;
5593 struct intel_dp *intel_dp =
5594 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5595 uint8_t buf[16];
5596 ssize_t err;
5597 int i;
5598
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005599 if (connector->status != connector_status_connected)
5600 return -ENODEV;
5601
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005602 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5603 const struct dpcd_block *b = &i915_dpcd_debug[i];
5604 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5605
5606 if (b->edp &&
5607 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5608 continue;
5609
5610 /* low tech for now */
5611 if (WARN_ON(size > sizeof(buf)))
5612 continue;
5613
5614 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5615 if (err <= 0) {
5616 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5617 size, b->offset, err);
5618 continue;
5619 }
5620
5621 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005622 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005623
5624 return 0;
5625}
5626
5627static int i915_dpcd_open(struct inode *inode, struct file *file)
5628{
5629 return single_open(file, i915_dpcd_show, inode->i_private);
5630}
5631
5632static const struct file_operations i915_dpcd_fops = {
5633 .owner = THIS_MODULE,
5634 .open = i915_dpcd_open,
5635 .read = seq_read,
5636 .llseek = seq_lseek,
5637 .release = single_release,
5638};
5639
David Weinehallecbd6782016-08-23 12:23:56 +03005640static int i915_panel_show(struct seq_file *m, void *data)
5641{
5642 struct drm_connector *connector = m->private;
5643 struct intel_dp *intel_dp =
5644 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5645
5646 if (connector->status != connector_status_connected)
5647 return -ENODEV;
5648
5649 seq_printf(m, "Panel power up delay: %d\n",
5650 intel_dp->panel_power_up_delay);
5651 seq_printf(m, "Panel power down delay: %d\n",
5652 intel_dp->panel_power_down_delay);
5653 seq_printf(m, "Backlight on delay: %d\n",
5654 intel_dp->backlight_on_delay);
5655 seq_printf(m, "Backlight off delay: %d\n",
5656 intel_dp->backlight_off_delay);
5657
5658 return 0;
5659}
5660
5661static int i915_panel_open(struct inode *inode, struct file *file)
5662{
5663 return single_open(file, i915_panel_show, inode->i_private);
5664}
5665
5666static const struct file_operations i915_panel_fops = {
5667 .owner = THIS_MODULE,
5668 .open = i915_panel_open,
5669 .read = seq_read,
5670 .llseek = seq_lseek,
5671 .release = single_release,
5672};
5673
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005674/**
5675 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5676 * @connector: pointer to a registered drm_connector
5677 *
5678 * Cleanup will be done by drm_connector_unregister() through a call to
5679 * drm_debugfs_connector_remove().
5680 *
5681 * Returns 0 on success, negative error codes on error.
5682 */
5683int i915_debugfs_connector_add(struct drm_connector *connector)
5684{
5685 struct dentry *root = connector->debugfs_entry;
5686
5687 /* The connector must have been registered beforehands. */
5688 if (!root)
5689 return -ENODEV;
5690
5691 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5692 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005693 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5694 connector, &i915_dpcd_fops);
5695
5696 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5697 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5698 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005699
5700 return 0;
5701}