blob: bf19192dcc3b09e0c2b132485468b5992ab18916 [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{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100115 return obj->mm.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;
139
Chris Wilson188c1ab2016-04-03 14:14:20 +0100140 lockdep_assert_held(&obj->base.dev->struct_mutex);
141
Chris Wilsond07f0e52016-10-28 13:58:44 +0100142 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100143 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100144 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100145 get_pin_flag(obj),
146 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700147 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100148 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800149 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100151 obj->base.write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300152 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100153 obj->mm.dirty ? " dirty" : "",
154 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100155 if (obj->base.name)
156 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000157 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100158 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800159 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300160 }
161 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100162 if (obj->pin_display)
163 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000164 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100165 if (!drm_mm_node_allocated(&vma->node))
166 continue;
167
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100168 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100169 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100170 vma->node.start, vma->node.size);
Chris Wilson3272db52016-08-04 16:32:32 +0100171 if (i915_vma_is_ggtt(vma))
Chris Wilson596c5922016-02-26 11:03:20 +0000172 seq_printf(m, ", type: %u", vma->ggtt_view.type);
Chris Wilson49ef5292016-08-18 17:17:00 +0100173 if (vma->fence)
174 seq_printf(m, " , fence: %d%s",
175 vma->fence->id,
176 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000177 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700178 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000179 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100180 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100181
Chris Wilsond07f0e52016-10-28 13:58:44 +0100182 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100183 if (engine)
184 seq_printf(m, " (%s)", engine->name);
185
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100186 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
187 if (frontbuffer_bits)
188 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100189}
190
Chris Wilson6d2b88852013-08-07 18:30:54 +0100191static int obj_rank_by_stolen(void *priv,
192 struct list_head *A, struct list_head *B)
193{
194 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200195 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100196 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200197 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100198
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200199 if (a->stolen->start < b->stolen->start)
200 return -1;
201 if (a->stolen->start > b->stolen->start)
202 return 1;
203 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100204}
205
206static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
207{
David Weinehall36cdd012016-08-22 13:59:31 +0300208 struct drm_i915_private *dev_priv = node_to_i915(m->private);
209 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100210 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300211 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100212 LIST_HEAD(stolen);
213 int count, ret;
214
215 ret = mutex_lock_interruptible(&dev->struct_mutex);
216 if (ret)
217 return ret;
218
219 total_obj_size = total_gtt_size = count = 0;
220 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
221 if (obj->stolen == NULL)
222 continue;
223
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200224 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100225
226 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100227 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100228 count++;
229 }
230 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
231 if (obj->stolen == NULL)
232 continue;
233
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200234 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100235
236 total_obj_size += obj->base.size;
237 count++;
238 }
239 list_sort(NULL, &stolen, obj_rank_by_stolen);
240 seq_puts(m, "Stolen:\n");
241 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200242 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100243 seq_puts(m, " ");
244 describe_obj(m, obj);
245 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200246 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100247 }
248 mutex_unlock(&dev->struct_mutex);
249
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300250 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100251 count, total_obj_size, total_gtt_size);
252 return 0;
253}
254
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100255struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000256 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300257 unsigned long count;
258 u64 total, unbound;
259 u64 global, shared;
260 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100261};
262
263static int per_file_stats(int id, void *ptr, void *data)
264{
265 struct drm_i915_gem_object *obj = ptr;
266 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000267 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100268
269 stats->count++;
270 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100271 if (!obj->bind_count)
272 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000273 if (obj->base.name || obj->base.dma_buf)
274 stats->shared += obj->base.size;
275
Chris Wilson894eeec2016-08-04 07:52:20 +0100276 list_for_each_entry(vma, &obj->vma_list, obj_link) {
277 if (!drm_mm_node_allocated(&vma->node))
278 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000279
Chris Wilson3272db52016-08-04 16:32:32 +0100280 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100281 stats->global += vma->node.size;
282 } else {
283 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000284
Chris Wilson2bfa9962016-08-04 07:52:25 +0100285 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000286 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000287 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100288
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100289 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100290 stats->active += vma->node.size;
291 else
292 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100293 }
294
295 return 0;
296}
297
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100298#define print_file_stats(m, name, stats) do { \
299 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300300 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 +0100301 name, \
302 stats.count, \
303 stats.total, \
304 stats.active, \
305 stats.inactive, \
306 stats.global, \
307 stats.shared, \
308 stats.unbound); \
309} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800310
311static void print_batch_pool_stats(struct seq_file *m,
312 struct drm_i915_private *dev_priv)
313{
314 struct drm_i915_gem_object *obj;
315 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000316 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530317 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000318 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800319
320 memset(&stats, 0, sizeof(stats));
321
Akash Goel3b3f1652016-10-13 22:44:48 +0530322 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000323 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100324 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000325 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100326 batch_pool_link)
327 per_file_stats(0, obj, &stats);
328 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100329 }
Brad Volkin493018d2014-12-11 12:13:08 -0800330
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100331 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800332}
333
Chris Wilson15da9562016-05-24 14:53:43 +0100334static int per_file_ctx_stats(int id, void *ptr, void *data)
335{
336 struct i915_gem_context *ctx = ptr;
337 int n;
338
339 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
340 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100341 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100342 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100343 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100344 }
345
346 return 0;
347}
348
349static void print_context_stats(struct seq_file *m,
350 struct drm_i915_private *dev_priv)
351{
David Weinehall36cdd012016-08-22 13:59:31 +0300352 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100353 struct file_stats stats;
354 struct drm_file *file;
355
356 memset(&stats, 0, sizeof(stats));
357
David Weinehall36cdd012016-08-22 13:59:31 +0300358 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100359 if (dev_priv->kernel_context)
360 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
361
David Weinehall36cdd012016-08-22 13:59:31 +0300362 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100363 struct drm_i915_file_private *fpriv = file->driver_priv;
364 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
365 }
David Weinehall36cdd012016-08-22 13:59:31 +0300366 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100367
368 print_file_stats(m, "[k]contexts", stats);
369}
370
David Weinehall36cdd012016-08-22 13:59:31 +0300371static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100372{
David Weinehall36cdd012016-08-22 13:59:31 +0300373 struct drm_i915_private *dev_priv = node_to_i915(m->private);
374 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300375 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100376 u32 count, mapped_count, purgeable_count, dpy_count;
377 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000378 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100379 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100380 int ret;
381
382 ret = mutex_lock_interruptible(&dev->struct_mutex);
383 if (ret)
384 return ret;
385
Chris Wilson3ef7f222016-10-18 13:02:48 +0100386 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000387 dev_priv->mm.object_count,
388 dev_priv->mm.object_memory);
389
Chris Wilson1544c422016-08-15 13:18:16 +0100390 size = count = 0;
391 mapped_size = mapped_count = 0;
392 purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700393 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100394 size += obj->base.size;
395 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200396
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100397 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200398 purgeable_size += obj->base.size;
399 ++purgeable_count;
400 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100401
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100402 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100403 mapped_count++;
404 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100405 }
Chris Wilson6299f992010-11-24 12:23:44 +0000406 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100407 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
408
409 size = count = dpy_size = dpy_count = 0;
410 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
411 size += obj->base.size;
412 ++count;
413
414 if (obj->pin_display) {
415 dpy_size += obj->base.size;
416 ++dpy_count;
417 }
418
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100419 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100420 purgeable_size += obj->base.size;
421 ++purgeable_count;
422 }
423
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100424 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100425 mapped_count++;
426 mapped_size += obj->base.size;
427 }
428 }
429 seq_printf(m, "%u bound objects, %llu bytes\n",
430 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300431 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200432 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100433 seq_printf(m, "%u mapped objects, %llu bytes\n",
434 mapped_count, mapped_size);
435 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
436 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000437
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300438 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300439 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100440
Damien Lespiau267f0c92013-06-24 22:59:48 +0100441 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800442 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200443 mutex_unlock(&dev->struct_mutex);
444
445 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100446 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100447 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
448 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100449 struct drm_i915_file_private *file_priv = file->driver_priv;
450 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900451 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100452
453 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000454 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100455 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100456 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100457 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900458 /*
459 * Although we have a valid reference on file->pid, that does
460 * not guarantee that the task_struct who called get_pid() is
461 * still alive (e.g. get_pid(current) => fork() => exit()).
462 * Therefore, we need to protect this ->comm access using RCU.
463 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100464 mutex_lock(&dev->struct_mutex);
465 request = list_first_entry_or_null(&file_priv->mm.request_list,
466 struct drm_i915_gem_request,
467 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900468 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100469 task = pid_task(request && request->ctx->pid ?
470 request->ctx->pid : file->pid,
471 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800472 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900473 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100474 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100475 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200476 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100477
478 return 0;
479}
480
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100481static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000482{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100483 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300484 struct drm_i915_private *dev_priv = node_to_i915(node);
485 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100486 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000487 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300488 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000489 int count, ret;
490
491 ret = mutex_lock_interruptible(&dev->struct_mutex);
492 if (ret)
493 return ret;
494
495 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700496 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6da84822016-08-15 10:48:44 +0100497 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100498 continue;
499
Damien Lespiau267f0c92013-06-24 22:59:48 +0100500 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000501 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100502 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000503 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100504 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000505 count++;
506 }
507
508 mutex_unlock(&dev->struct_mutex);
509
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300510 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000511 count, total_obj_size, total_gtt_size);
512
513 return 0;
514}
515
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100516static int i915_gem_pageflip_info(struct seq_file *m, void *data)
517{
David Weinehall36cdd012016-08-22 13:59:31 +0300518 struct drm_i915_private *dev_priv = node_to_i915(m->private);
519 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100520 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200521 int ret;
522
523 ret = mutex_lock_interruptible(&dev->struct_mutex);
524 if (ret)
525 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100526
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100527 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800528 const char pipe = pipe_name(crtc->pipe);
529 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200530 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100531
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200532 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200533 work = crtc->flip_work;
534 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800535 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100536 pipe, plane);
537 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200538 u32 pending;
539 u32 addr;
540
541 pending = atomic_read(&work->pending);
542 if (pending) {
543 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
544 pipe, plane);
545 } else {
546 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
547 pipe, plane);
548 }
549 if (work->flip_queued_req) {
550 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
551
552 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
553 engine->name,
554 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilson28176ef2016-10-28 13:58:56 +0100555 atomic_read(&dev_priv->gt.global_timeline.next_seqno),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100556 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100557 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200558 } else
559 seq_printf(m, "Flip not associated with any ring\n");
560 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
561 work->flip_queued_vblank,
562 work->flip_ready_vblank,
563 intel_crtc_get_vblank_counter(crtc));
564 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
565
David Weinehall36cdd012016-08-22 13:59:31 +0300566 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200567 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
568 else
569 addr = I915_READ(DSPADDR(crtc->plane));
570 seq_printf(m, "Current scanout address 0x%08x\n", addr);
571
572 if (work->pending_flip_obj) {
573 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
574 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100575 }
576 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200577 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100578 }
579
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200580 mutex_unlock(&dev->struct_mutex);
581
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100582 return 0;
583}
584
Brad Volkin493018d2014-12-11 12:13:08 -0800585static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
586{
David Weinehall36cdd012016-08-22 13:59:31 +0300587 struct drm_i915_private *dev_priv = node_to_i915(m->private);
588 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800589 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000590 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530591 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100592 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000593 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800594
595 ret = mutex_lock_interruptible(&dev->struct_mutex);
596 if (ret)
597 return ret;
598
Akash Goel3b3f1652016-10-13 22:44:48 +0530599 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000600 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100601 int count;
602
603 count = 0;
604 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000605 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100606 batch_pool_link)
607 count++;
608 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000609 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100610
611 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000612 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100613 batch_pool_link) {
614 seq_puts(m, " ");
615 describe_obj(m, obj);
616 seq_putc(m, '\n');
617 }
618
619 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100620 }
Brad Volkin493018d2014-12-11 12:13:08 -0800621 }
622
Chris Wilson8d9d5742015-04-07 16:20:38 +0100623 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800624
625 mutex_unlock(&dev->struct_mutex);
626
627 return 0;
628}
629
Chris Wilson1b365952016-10-04 21:11:31 +0100630static void print_request(struct seq_file *m,
631 struct drm_i915_gem_request *rq,
632 const char *prefix)
633{
Chris Wilson562f5d42016-10-28 13:58:54 +0100634 seq_printf(m, "%s%x [%x:%x] @ %d: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100635 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson1b365952016-10-04 21:11:31 +0100636 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100637 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100638}
639
Ben Gamari20172632009-02-17 20:08:50 -0500640static int i915_gem_request_info(struct seq_file *m, void *data)
641{
David Weinehall36cdd012016-08-22 13:59:31 +0300642 struct drm_i915_private *dev_priv = node_to_i915(m->private);
643 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200644 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530645 struct intel_engine_cs *engine;
646 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000647 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100648
649 ret = mutex_lock_interruptible(&dev->struct_mutex);
650 if (ret)
651 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500652
Chris Wilson2d1070b2015-04-01 10:36:56 +0100653 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530654 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100655 int count;
656
657 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100658 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100659 count++;
660 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100661 continue;
662
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000663 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100664 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100665 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100666
667 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500668 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100669 mutex_unlock(&dev->struct_mutex);
670
Chris Wilson2d1070b2015-04-01 10:36:56 +0100671 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100672 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100673
Ben Gamari20172632009-02-17 20:08:50 -0500674 return 0;
675}
676
Chris Wilsonb2223492010-10-27 15:27:33 +0100677static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000678 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100679{
Chris Wilson688e6c72016-07-01 17:23:15 +0100680 struct intel_breadcrumbs *b = &engine->breadcrumbs;
681 struct rb_node *rb;
682
Chris Wilson12471ba2016-04-09 10:57:55 +0100683 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100684 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100685
Chris Wilsonf6168e32016-10-28 13:58:55 +0100686 spin_lock_irq(&b->lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100687 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
688 struct intel_wait *w = container_of(rb, typeof(*w), node);
689
690 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
691 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
692 }
Chris Wilsonf6168e32016-10-28 13:58:55 +0100693 spin_unlock_irq(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100694}
695
Ben Gamari20172632009-02-17 20:08:50 -0500696static int i915_gem_seqno_info(struct seq_file *m, void *data)
697{
David Weinehall36cdd012016-08-22 13:59:31 +0300698 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000699 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530700 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500701
Akash Goel3b3f1652016-10-13 22:44:48 +0530702 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000703 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100704
Ben Gamari20172632009-02-17 20:08:50 -0500705 return 0;
706}
707
708
709static int i915_interrupt_info(struct seq_file *m, void *data)
710{
David Weinehall36cdd012016-08-22 13:59:31 +0300711 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000712 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530713 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100714 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100715
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200716 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500717
David Weinehall36cdd012016-08-22 13:59:31 +0300718 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300719 seq_printf(m, "Master Interrupt Control:\t%08x\n",
720 I915_READ(GEN8_MASTER_IRQ));
721
722 seq_printf(m, "Display IER:\t%08x\n",
723 I915_READ(VLV_IER));
724 seq_printf(m, "Display IIR:\t%08x\n",
725 I915_READ(VLV_IIR));
726 seq_printf(m, "Display IIR_RW:\t%08x\n",
727 I915_READ(VLV_IIR_RW));
728 seq_printf(m, "Display IMR:\t%08x\n",
729 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100730 for_each_pipe(dev_priv, pipe) {
731 enum intel_display_power_domain power_domain;
732
733 power_domain = POWER_DOMAIN_PIPE(pipe);
734 if (!intel_display_power_get_if_enabled(dev_priv,
735 power_domain)) {
736 seq_printf(m, "Pipe %c power disabled\n",
737 pipe_name(pipe));
738 continue;
739 }
740
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300741 seq_printf(m, "Pipe %c stat:\t%08x\n",
742 pipe_name(pipe),
743 I915_READ(PIPESTAT(pipe)));
744
Chris Wilson9c870d02016-10-24 13:42:15 +0100745 intel_display_power_put(dev_priv, power_domain);
746 }
747
748 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300749 seq_printf(m, "Port hotplug:\t%08x\n",
750 I915_READ(PORT_HOTPLUG_EN));
751 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
752 I915_READ(VLV_DPFLIPSTAT));
753 seq_printf(m, "DPINVGTT:\t%08x\n",
754 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100755 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300756
757 for (i = 0; i < 4; i++) {
758 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
759 i, I915_READ(GEN8_GT_IMR(i)));
760 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
761 i, I915_READ(GEN8_GT_IIR(i)));
762 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
763 i, I915_READ(GEN8_GT_IER(i)));
764 }
765
766 seq_printf(m, "PCU interrupt mask:\t%08x\n",
767 I915_READ(GEN8_PCU_IMR));
768 seq_printf(m, "PCU interrupt identity:\t%08x\n",
769 I915_READ(GEN8_PCU_IIR));
770 seq_printf(m, "PCU interrupt enable:\t%08x\n",
771 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300772 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700773 seq_printf(m, "Master Interrupt Control:\t%08x\n",
774 I915_READ(GEN8_MASTER_IRQ));
775
776 for (i = 0; i < 4; i++) {
777 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
778 i, I915_READ(GEN8_GT_IMR(i)));
779 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
780 i, I915_READ(GEN8_GT_IIR(i)));
781 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
782 i, I915_READ(GEN8_GT_IER(i)));
783 }
784
Damien Lespiau055e3932014-08-18 13:49:10 +0100785 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200786 enum intel_display_power_domain power_domain;
787
788 power_domain = POWER_DOMAIN_PIPE(pipe);
789 if (!intel_display_power_get_if_enabled(dev_priv,
790 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300791 seq_printf(m, "Pipe %c power disabled\n",
792 pipe_name(pipe));
793 continue;
794 }
Ben Widawskya123f152013-11-02 21:07:10 -0700795 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000796 pipe_name(pipe),
797 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700798 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000799 pipe_name(pipe),
800 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700801 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000802 pipe_name(pipe),
803 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200804
805 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700806 }
807
808 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
809 I915_READ(GEN8_DE_PORT_IMR));
810 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
811 I915_READ(GEN8_DE_PORT_IIR));
812 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
813 I915_READ(GEN8_DE_PORT_IER));
814
815 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
816 I915_READ(GEN8_DE_MISC_IMR));
817 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
818 I915_READ(GEN8_DE_MISC_IIR));
819 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
820 I915_READ(GEN8_DE_MISC_IER));
821
822 seq_printf(m, "PCU interrupt mask:\t%08x\n",
823 I915_READ(GEN8_PCU_IMR));
824 seq_printf(m, "PCU interrupt identity:\t%08x\n",
825 I915_READ(GEN8_PCU_IIR));
826 seq_printf(m, "PCU interrupt enable:\t%08x\n",
827 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300828 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700829 seq_printf(m, "Display IER:\t%08x\n",
830 I915_READ(VLV_IER));
831 seq_printf(m, "Display IIR:\t%08x\n",
832 I915_READ(VLV_IIR));
833 seq_printf(m, "Display IIR_RW:\t%08x\n",
834 I915_READ(VLV_IIR_RW));
835 seq_printf(m, "Display IMR:\t%08x\n",
836 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100837 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700838 seq_printf(m, "Pipe %c stat:\t%08x\n",
839 pipe_name(pipe),
840 I915_READ(PIPESTAT(pipe)));
841
842 seq_printf(m, "Master IER:\t%08x\n",
843 I915_READ(VLV_MASTER_IER));
844
845 seq_printf(m, "Render IER:\t%08x\n",
846 I915_READ(GTIER));
847 seq_printf(m, "Render IIR:\t%08x\n",
848 I915_READ(GTIIR));
849 seq_printf(m, "Render IMR:\t%08x\n",
850 I915_READ(GTIMR));
851
852 seq_printf(m, "PM IER:\t\t%08x\n",
853 I915_READ(GEN6_PMIER));
854 seq_printf(m, "PM IIR:\t\t%08x\n",
855 I915_READ(GEN6_PMIIR));
856 seq_printf(m, "PM IMR:\t\t%08x\n",
857 I915_READ(GEN6_PMIMR));
858
859 seq_printf(m, "Port hotplug:\t%08x\n",
860 I915_READ(PORT_HOTPLUG_EN));
861 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
862 I915_READ(VLV_DPFLIPSTAT));
863 seq_printf(m, "DPINVGTT:\t%08x\n",
864 I915_READ(DPINVGTT));
865
David Weinehall36cdd012016-08-22 13:59:31 +0300866 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800867 seq_printf(m, "Interrupt enable: %08x\n",
868 I915_READ(IER));
869 seq_printf(m, "Interrupt identity: %08x\n",
870 I915_READ(IIR));
871 seq_printf(m, "Interrupt mask: %08x\n",
872 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100873 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800874 seq_printf(m, "Pipe %c stat: %08x\n",
875 pipe_name(pipe),
876 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800877 } else {
878 seq_printf(m, "North Display Interrupt enable: %08x\n",
879 I915_READ(DEIER));
880 seq_printf(m, "North Display Interrupt identity: %08x\n",
881 I915_READ(DEIIR));
882 seq_printf(m, "North Display Interrupt mask: %08x\n",
883 I915_READ(DEIMR));
884 seq_printf(m, "South Display Interrupt enable: %08x\n",
885 I915_READ(SDEIER));
886 seq_printf(m, "South Display Interrupt identity: %08x\n",
887 I915_READ(SDEIIR));
888 seq_printf(m, "South Display Interrupt mask: %08x\n",
889 I915_READ(SDEIMR));
890 seq_printf(m, "Graphics Interrupt enable: %08x\n",
891 I915_READ(GTIER));
892 seq_printf(m, "Graphics Interrupt identity: %08x\n",
893 I915_READ(GTIIR));
894 seq_printf(m, "Graphics Interrupt mask: %08x\n",
895 I915_READ(GTIMR));
896 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530897 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300898 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100899 seq_printf(m,
900 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000901 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000902 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000903 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000904 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200905 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100906
Ben Gamari20172632009-02-17 20:08:50 -0500907 return 0;
908}
909
Chris Wilsona6172a82009-02-11 14:26:38 +0000910static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
911{
David Weinehall36cdd012016-08-22 13:59:31 +0300912 struct drm_i915_private *dev_priv = node_to_i915(m->private);
913 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100914 int i, ret;
915
916 ret = mutex_lock_interruptible(&dev->struct_mutex);
917 if (ret)
918 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000919
Chris Wilsona6172a82009-02-11 14:26:38 +0000920 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
921 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100922 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000923
Chris Wilson6c085a72012-08-20 11:40:46 +0200924 seq_printf(m, "Fence %d, pin count = %d, object = ",
925 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100926 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100927 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100928 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100929 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100930 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000931 }
932
Chris Wilson05394f32010-11-08 19:18:58 +0000933 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000934 return 0;
935}
936
Ben Gamari20172632009-02-17 20:08:50 -0500937static int i915_hws_info(struct seq_file *m, void *data)
938{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100939 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300940 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000941 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100942 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100943 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500944
Akash Goel3b3f1652016-10-13 22:44:48 +0530945 engine = dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000946 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500947 if (hws == NULL)
948 return 0;
949
950 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
951 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
952 i * 4,
953 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
954 }
955 return 0;
956}
957
Chris Wilson98a2f412016-10-12 10:05:18 +0100958#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
959
Daniel Vetterd5442302012-04-27 15:17:40 +0200960static ssize_t
961i915_error_state_write(struct file *filp,
962 const char __user *ubuf,
963 size_t cnt,
964 loff_t *ppos)
965{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300966 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200967
968 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100969 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200970
971 return cnt;
972}
973
974static int i915_error_state_open(struct inode *inode, struct file *file)
975{
David Weinehall36cdd012016-08-22 13:59:31 +0300976 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200977 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200978
979 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
980 if (!error_priv)
981 return -ENOMEM;
982
David Weinehall36cdd012016-08-22 13:59:31 +0300983 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200984
David Weinehall36cdd012016-08-22 13:59:31 +0300985 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200986
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300987 file->private_data = error_priv;
988
989 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200990}
991
992static int i915_error_state_release(struct inode *inode, struct file *file)
993{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300994 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200995
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300996 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200997 kfree(error_priv);
998
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300999 return 0;
1000}
1001
1002static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1003 size_t count, loff_t *pos)
1004{
1005 struct i915_error_state_file_priv *error_priv = file->private_data;
1006 struct drm_i915_error_state_buf error_str;
1007 loff_t tmp_pos = 0;
1008 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001009 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001010
David Weinehall36cdd012016-08-22 13:59:31 +03001011 ret = i915_error_state_buf_init(&error_str,
1012 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001013 if (ret)
1014 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001015
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001016 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001017 if (ret)
1018 goto out;
1019
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001020 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1021 error_str.buf,
1022 error_str.bytes);
1023
1024 if (ret_count < 0)
1025 ret = ret_count;
1026 else
1027 *pos = error_str.start + ret_count;
1028out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001029 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001030 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001031}
1032
1033static const struct file_operations i915_error_state_fops = {
1034 .owner = THIS_MODULE,
1035 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001036 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001037 .write = i915_error_state_write,
1038 .llseek = default_llseek,
1039 .release = i915_error_state_release,
1040};
1041
Chris Wilson98a2f412016-10-12 10:05:18 +01001042#endif
1043
Kees Cook647416f2013-03-10 14:10:06 -07001044static int
1045i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001046{
David Weinehall36cdd012016-08-22 13:59:31 +03001047 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001048
Chris Wilson28176ef2016-10-28 13:58:56 +01001049 *val = atomic_read(&dev_priv->gt.global_timeline.next_seqno);
Kees Cook647416f2013-03-10 14:10:06 -07001050 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001051}
1052
Kees Cook647416f2013-03-10 14:10:06 -07001053static int
1054i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001055{
David Weinehall36cdd012016-08-22 13:59:31 +03001056 struct drm_i915_private *dev_priv = data;
1057 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001058 int ret;
1059
Mika Kuoppala40633212012-12-04 15:12:00 +02001060 ret = mutex_lock_interruptible(&dev->struct_mutex);
1061 if (ret)
1062 return ret;
1063
Chris Wilson73cb9702016-10-28 13:58:46 +01001064 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001065 mutex_unlock(&dev->struct_mutex);
1066
Kees Cook647416f2013-03-10 14:10:06 -07001067 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001068}
1069
Kees Cook647416f2013-03-10 14:10:06 -07001070DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1071 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001072 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001073
Deepak Sadb4bd12014-03-31 11:30:02 +05301074static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001075{
David Weinehall36cdd012016-08-22 13:59:31 +03001076 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1077 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001078 int ret = 0;
1079
1080 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001081
David Weinehall36cdd012016-08-22 13:59:31 +03001082 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001083 u16 rgvswctl = I915_READ16(MEMSWCTL);
1084 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1085
1086 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1087 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1088 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1089 MEMSTAT_VID_SHIFT);
1090 seq_printf(m, "Current P-state: %d\n",
1091 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001092 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001093 u32 freq_sts;
1094
1095 mutex_lock(&dev_priv->rps.hw_lock);
1096 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1097 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1098 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1099
1100 seq_printf(m, "actual GPU freq: %d MHz\n",
1101 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1102
1103 seq_printf(m, "current GPU freq: %d MHz\n",
1104 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1105
1106 seq_printf(m, "max GPU freq: %d MHz\n",
1107 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1108
1109 seq_printf(m, "min GPU freq: %d MHz\n",
1110 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1111
1112 seq_printf(m, "idle GPU freq: %d MHz\n",
1113 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1114
1115 seq_printf(m,
1116 "efficient (RPe) frequency: %d MHz\n",
1117 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1118 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001119 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001120 u32 rp_state_limits;
1121 u32 gt_perf_status;
1122 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001123 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001124 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001125 u32 rpupei, rpcurup, rpprevup;
1126 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001127 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001128 int max_freq;
1129
Bob Paauwe35040562015-06-25 14:54:07 -07001130 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001131 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001132 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1133 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1134 } else {
1135 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1136 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1137 }
1138
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001139 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001140 ret = mutex_lock_interruptible(&dev->struct_mutex);
1141 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001142 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001143
Mika Kuoppala59bad942015-01-16 11:34:40 +02001144 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001145
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001146 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001147 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301148 reqf >>= 23;
1149 else {
1150 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001151 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301152 reqf >>= 24;
1153 else
1154 reqf >>= 25;
1155 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001156 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001157
Chris Wilson0d8f9492014-03-27 09:06:14 +00001158 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1159 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1160 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1161
Jesse Barnesccab5c82011-01-18 15:49:25 -08001162 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301163 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1164 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1165 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1166 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1167 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1168 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001169 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301170 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001171 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001172 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1173 else
1174 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001175 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001176
Mika Kuoppala59bad942015-01-16 11:34:40 +02001177 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001178 mutex_unlock(&dev->struct_mutex);
1179
David Weinehall36cdd012016-08-22 13:59:31 +03001180 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001181 pm_ier = I915_READ(GEN6_PMIER);
1182 pm_imr = I915_READ(GEN6_PMIMR);
1183 pm_isr = I915_READ(GEN6_PMISR);
1184 pm_iir = I915_READ(GEN6_PMIIR);
1185 pm_mask = I915_READ(GEN6_PMINTRMSK);
1186 } else {
1187 pm_ier = I915_READ(GEN8_GT_IER(2));
1188 pm_imr = I915_READ(GEN8_GT_IMR(2));
1189 pm_isr = I915_READ(GEN8_GT_ISR(2));
1190 pm_iir = I915_READ(GEN8_GT_IIR(2));
1191 pm_mask = I915_READ(GEN6_PMINTRMSK);
1192 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001193 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 -03001194 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301195 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001196 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001197 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001198 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001199 seq_printf(m, "Render p-state VID: %d\n",
1200 gt_perf_status & 0xff);
1201 seq_printf(m, "Render p-state limit: %d\n",
1202 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001203 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1204 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1205 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1206 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001207 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001208 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301209 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1210 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1211 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1212 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1213 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1214 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001215 seq_printf(m, "Up threshold: %d%%\n",
1216 dev_priv->rps.up_threshold);
1217
Akash Goeld6cda9c2016-04-23 00:05:46 +05301218 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1219 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1220 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1221 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1222 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1223 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001224 seq_printf(m, "Down threshold: %d%%\n",
1225 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001226
David Weinehall36cdd012016-08-22 13:59:31 +03001227 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001228 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001229 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001230 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001231 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001232 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001233
1234 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001235 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001236 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001237 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001238 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001239
David Weinehall36cdd012016-08-22 13:59:31 +03001240 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001241 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001242 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001243 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001244 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001245 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001246 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001247 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001248
Chris Wilsond86ed342015-04-27 13:41:19 +01001249 seq_printf(m, "Current freq: %d MHz\n",
1250 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1251 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001252 seq_printf(m, "Idle freq: %d MHz\n",
1253 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001254 seq_printf(m, "Min freq: %d MHz\n",
1255 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001256 seq_printf(m, "Boost freq: %d MHz\n",
1257 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001258 seq_printf(m, "Max freq: %d MHz\n",
1259 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1260 seq_printf(m,
1261 "efficient (RPe) frequency: %d MHz\n",
1262 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001264 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001265 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001266
Mika Kahola1170f282015-09-25 14:00:32 +03001267 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1268 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1269 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1270
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001271out:
1272 intel_runtime_pm_put(dev_priv);
1273 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001274}
1275
Ben Widawskyd6369512016-09-20 16:54:32 +03001276static void i915_instdone_info(struct drm_i915_private *dev_priv,
1277 struct seq_file *m,
1278 struct intel_instdone *instdone)
1279{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001280 int slice;
1281 int subslice;
1282
Ben Widawskyd6369512016-09-20 16:54:32 +03001283 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1284 instdone->instdone);
1285
1286 if (INTEL_GEN(dev_priv) <= 3)
1287 return;
1288
1289 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1290 instdone->slice_common);
1291
1292 if (INTEL_GEN(dev_priv) <= 6)
1293 return;
1294
Ben Widawskyf9e61372016-09-20 16:54:33 +03001295 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1296 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1297 slice, subslice, instdone->sampler[slice][subslice]);
1298
1299 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1300 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1301 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001302}
1303
Chris Wilsonf6544492015-01-26 18:03:04 +02001304static int i915_hangcheck_info(struct seq_file *m, void *unused)
1305{
David Weinehall36cdd012016-08-22 13:59:31 +03001306 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001307 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001308 u64 acthd[I915_NUM_ENGINES];
1309 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001310 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001311 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001312
Chris Wilson8af29b02016-09-09 14:11:47 +01001313 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1314 seq_printf(m, "Wedged\n");
1315 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1316 seq_printf(m, "Reset in progress\n");
1317 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1318 seq_printf(m, "Waiter holding struct mutex\n");
1319 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1320 seq_printf(m, "struct_mutex blocked for reset\n");
1321
Chris Wilsonf6544492015-01-26 18:03:04 +02001322 if (!i915.enable_hangcheck) {
1323 seq_printf(m, "Hangcheck disabled\n");
1324 return 0;
1325 }
1326
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001327 intel_runtime_pm_get(dev_priv);
1328
Akash Goel3b3f1652016-10-13 22:44:48 +05301329 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001330 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001331 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001332 }
1333
Akash Goel3b3f1652016-10-13 22:44:48 +05301334 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001335
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001336 intel_runtime_pm_put(dev_priv);
1337
Chris Wilsonf6544492015-01-26 18:03:04 +02001338 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1339 seq_printf(m, "Hangcheck active, fires in %dms\n",
1340 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1341 jiffies));
1342 } else
1343 seq_printf(m, "Hangcheck inactive\n");
1344
Akash Goel3b3f1652016-10-13 22:44:48 +05301345 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001346 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1347 struct rb_node *rb;
1348
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001349 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001350 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001351 engine->hangcheck.seqno, seqno[id],
1352 intel_engine_last_submit(engine));
Chris Wilson83348ba2016-08-09 17:47:51 +01001353 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1354 yesno(intel_engine_has_waiter(engine)),
1355 yesno(test_bit(engine->id,
1356 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilsonf6168e32016-10-28 13:58:55 +01001357 spin_lock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001358 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1359 struct intel_wait *w = container_of(rb, typeof(*w), node);
1360
1361 seq_printf(m, "\t%s [%d] waiting for %x\n",
1362 w->tsk->comm, w->tsk->pid, w->seqno);
1363 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01001364 spin_unlock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001365
Chris Wilsonf6544492015-01-26 18:03:04 +02001366 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001367 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001368 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001369 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1370 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001371
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001372 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001373 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001374
Ben Widawskyd6369512016-09-20 16:54:32 +03001375 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001376
Ben Widawskyd6369512016-09-20 16:54:32 +03001377 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001378
Ben Widawskyd6369512016-09-20 16:54:32 +03001379 i915_instdone_info(dev_priv, m,
1380 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001381 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001382 }
1383
1384 return 0;
1385}
1386
Ben Widawsky4d855292011-12-12 19:34:16 -08001387static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001388{
David Weinehall36cdd012016-08-22 13:59:31 +03001389 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001390 u32 rgvmodectl, rstdbyctl;
1391 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001392
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001393 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001394
1395 rgvmodectl = I915_READ(MEMMODECTL);
1396 rstdbyctl = I915_READ(RSTDBYCTL);
1397 crstandvid = I915_READ16(CRSTANDVID);
1398
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001399 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001400
Jani Nikula742f4912015-09-03 11:16:09 +03001401 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001402 seq_printf(m, "Boost freq: %d\n",
1403 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1404 MEMMODE_BOOST_FREQ_SHIFT);
1405 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001406 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001407 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001408 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001409 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001410 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001411 seq_printf(m, "Starting frequency: P%d\n",
1412 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001413 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001414 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001415 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1416 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1417 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1418 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001419 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001420 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001421 switch (rstdbyctl & RSX_STATUS_MASK) {
1422 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001423 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001424 break;
1425 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001426 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001427 break;
1428 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001429 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001430 break;
1431 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001432 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001433 break;
1434 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001435 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001436 break;
1437 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001438 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001439 break;
1440 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001442 break;
1443 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001444
1445 return 0;
1446}
1447
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001448static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001449{
David Weinehall36cdd012016-08-22 13:59:31 +03001450 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001451 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001452
1453 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001454 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001455 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001456 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001457 fw_domain->wake_count);
1458 }
1459 spin_unlock_irq(&dev_priv->uncore.lock);
1460
1461 return 0;
1462}
1463
Deepak S669ab5a2014-01-10 15:18:26 +05301464static int vlv_drpc_info(struct seq_file *m)
1465{
David Weinehall36cdd012016-08-22 13:59:31 +03001466 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001467 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301468
Imre Deakd46c0512014-04-14 20:24:27 +03001469 intel_runtime_pm_get(dev_priv);
1470
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001471 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301472 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1473 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1474
Imre Deakd46c0512014-04-14 20:24:27 +03001475 intel_runtime_pm_put(dev_priv);
1476
Deepak S669ab5a2014-01-10 15:18:26 +05301477 seq_printf(m, "Video Turbo Mode: %s\n",
1478 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1479 seq_printf(m, "Turbo enabled: %s\n",
1480 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1481 seq_printf(m, "HW control enabled: %s\n",
1482 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1483 seq_printf(m, "SW control enabled: %s\n",
1484 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1485 GEN6_RP_MEDIA_SW_MODE));
1486 seq_printf(m, "RC6 Enabled: %s\n",
1487 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1488 GEN6_RC_CTL_EI_MODE(1))));
1489 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001490 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301491 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001492 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301493
Imre Deak9cc19be2014-04-14 20:24:24 +03001494 seq_printf(m, "Render RC6 residency since boot: %u\n",
1495 I915_READ(VLV_GT_RENDER_RC6));
1496 seq_printf(m, "Media RC6 residency since boot: %u\n",
1497 I915_READ(VLV_GT_MEDIA_RC6));
1498
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001499 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301500}
1501
Ben Widawsky4d855292011-12-12 19:34:16 -08001502static int gen6_drpc_info(struct seq_file *m)
1503{
David Weinehall36cdd012016-08-22 13:59:31 +03001504 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1505 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001506 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301507 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001508 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001509 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001510
1511 ret = mutex_lock_interruptible(&dev->struct_mutex);
1512 if (ret)
1513 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001514 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001515
Chris Wilson907b28c2013-07-19 20:36:52 +01001516 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001517 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001518 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001519
1520 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001521 seq_puts(m, "RC information inaccurate because somebody "
1522 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001523 } else {
1524 /* NB: we cannot use forcewake, else we read the wrong values */
1525 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1526 udelay(10);
1527 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1528 }
1529
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001530 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001531 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001532
1533 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1534 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001535 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301536 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1537 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1538 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001539 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001540 mutex_lock(&dev_priv->rps.hw_lock);
1541 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1542 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001543
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001544 intel_runtime_pm_put(dev_priv);
1545
Ben Widawsky4d855292011-12-12 19:34:16 -08001546 seq_printf(m, "Video Turbo Mode: %s\n",
1547 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1548 seq_printf(m, "HW control enabled: %s\n",
1549 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1550 seq_printf(m, "SW control enabled: %s\n",
1551 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1552 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001553 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1555 seq_printf(m, "RC6 Enabled: %s\n",
1556 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001557 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301558 seq_printf(m, "Render Well Gating Enabled: %s\n",
1559 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1560 seq_printf(m, "Media Well Gating Enabled: %s\n",
1561 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1562 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 seq_printf(m, "Deep RC6 Enabled: %s\n",
1564 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1565 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1566 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001567 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001568 switch (gt_core_status & GEN6_RCn_MASK) {
1569 case GEN6_RC0:
1570 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001571 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001572 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001573 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001574 break;
1575 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001576 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001577 break;
1578 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001579 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001580 break;
1581 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001582 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001583 break;
1584 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001585 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001586 break;
1587 }
1588
1589 seq_printf(m, "Core Power Down: %s\n",
1590 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001591 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301592 seq_printf(m, "Render Power Well: %s\n",
1593 (gen9_powergate_status &
1594 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1595 seq_printf(m, "Media Power Well: %s\n",
1596 (gen9_powergate_status &
1597 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1598 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001599
1600 /* Not exactly sure what this is */
1601 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1602 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1603 seq_printf(m, "RC6 residency since boot: %u\n",
1604 I915_READ(GEN6_GT_GFX_RC6));
1605 seq_printf(m, "RC6+ residency since boot: %u\n",
1606 I915_READ(GEN6_GT_GFX_RC6p));
1607 seq_printf(m, "RC6++ residency since boot: %u\n",
1608 I915_READ(GEN6_GT_GFX_RC6pp));
1609
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001610 seq_printf(m, "RC6 voltage: %dmV\n",
1611 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1612 seq_printf(m, "RC6+ voltage: %dmV\n",
1613 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1614 seq_printf(m, "RC6++ voltage: %dmV\n",
1615 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301616 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001617}
1618
1619static int i915_drpc_info(struct seq_file *m, void *unused)
1620{
David Weinehall36cdd012016-08-22 13:59:31 +03001621 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001622
David Weinehall36cdd012016-08-22 13:59:31 +03001623 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301624 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001625 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001626 return gen6_drpc_info(m);
1627 else
1628 return ironlake_drpc_info(m);
1629}
1630
Daniel Vetter9a851782015-06-18 10:30:22 +02001631static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1632{
David Weinehall36cdd012016-08-22 13:59:31 +03001633 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001634
1635 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1636 dev_priv->fb_tracking.busy_bits);
1637
1638 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1639 dev_priv->fb_tracking.flip_bits);
1640
1641 return 0;
1642}
1643
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001644static int i915_fbc_status(struct seq_file *m, void *unused)
1645{
David Weinehall36cdd012016-08-22 13:59:31 +03001646 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001647
David Weinehall36cdd012016-08-22 13:59:31 +03001648 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001649 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001650 return 0;
1651 }
1652
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001653 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001654 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001655
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001656 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001657 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001658 else
1659 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001660 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001661
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001662 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1663 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1664 BDW_FBC_COMPRESSION_MASK :
1665 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001666 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001667 yesno(I915_READ(FBC_STATUS2) & mask));
1668 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001669
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001670 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001671 intel_runtime_pm_put(dev_priv);
1672
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001673 return 0;
1674}
1675
Rodrigo Vivida46f932014-08-01 02:04:45 -07001676static int i915_fbc_fc_get(void *data, u64 *val)
1677{
David Weinehall36cdd012016-08-22 13:59:31 +03001678 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001679
David Weinehall36cdd012016-08-22 13:59:31 +03001680 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001681 return -ENODEV;
1682
Rodrigo Vivida46f932014-08-01 02:04:45 -07001683 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001684
1685 return 0;
1686}
1687
1688static int i915_fbc_fc_set(void *data, u64 val)
1689{
David Weinehall36cdd012016-08-22 13:59:31 +03001690 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001691 u32 reg;
1692
David Weinehall36cdd012016-08-22 13:59:31 +03001693 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001694 return -ENODEV;
1695
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001696 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001697
1698 reg = I915_READ(ILK_DPFC_CONTROL);
1699 dev_priv->fbc.false_color = val;
1700
1701 I915_WRITE(ILK_DPFC_CONTROL, val ?
1702 (reg | FBC_CTL_FALSE_COLOR) :
1703 (reg & ~FBC_CTL_FALSE_COLOR));
1704
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001705 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001706 return 0;
1707}
1708
1709DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1710 i915_fbc_fc_get, i915_fbc_fc_set,
1711 "%llu\n");
1712
Paulo Zanoni92d44622013-05-31 16:33:24 -03001713static int i915_ips_status(struct seq_file *m, void *unused)
1714{
David Weinehall36cdd012016-08-22 13:59:31 +03001715 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001716
David Weinehall36cdd012016-08-22 13:59:31 +03001717 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001718 seq_puts(m, "not supported\n");
1719 return 0;
1720 }
1721
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001722 intel_runtime_pm_get(dev_priv);
1723
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001724 seq_printf(m, "Enabled by kernel parameter: %s\n",
1725 yesno(i915.enable_ips));
1726
David Weinehall36cdd012016-08-22 13:59:31 +03001727 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001728 seq_puts(m, "Currently: unknown\n");
1729 } else {
1730 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1731 seq_puts(m, "Currently: enabled\n");
1732 else
1733 seq_puts(m, "Currently: disabled\n");
1734 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001735
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001736 intel_runtime_pm_put(dev_priv);
1737
Paulo Zanoni92d44622013-05-31 16:33:24 -03001738 return 0;
1739}
1740
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001741static int i915_sr_status(struct seq_file *m, void *unused)
1742{
David Weinehall36cdd012016-08-22 13:59:31 +03001743 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001744 bool sr_enabled = false;
1745
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001746 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001747 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001748
David Weinehall36cdd012016-08-22 13:59:31 +03001749 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001750 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001751 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1752 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001753 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001754 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001755 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001756 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001757 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001758 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001759 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001760
Chris Wilson9c870d02016-10-24 13:42:15 +01001761 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001762 intel_runtime_pm_put(dev_priv);
1763
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001764 seq_printf(m, "self-refresh: %s\n",
1765 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001766
1767 return 0;
1768}
1769
Jesse Barnes7648fa92010-05-20 14:28:11 -07001770static int i915_emon_status(struct seq_file *m, void *unused)
1771{
David Weinehall36cdd012016-08-22 13:59:31 +03001772 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1773 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001774 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001775 int ret;
1776
David Weinehall36cdd012016-08-22 13:59:31 +03001777 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001778 return -ENODEV;
1779
Chris Wilsonde227ef2010-07-03 07:58:38 +01001780 ret = mutex_lock_interruptible(&dev->struct_mutex);
1781 if (ret)
1782 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001783
1784 temp = i915_mch_val(dev_priv);
1785 chipset = i915_chipset_val(dev_priv);
1786 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001787 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001788
1789 seq_printf(m, "GMCH temp: %ld\n", temp);
1790 seq_printf(m, "Chipset power: %ld\n", chipset);
1791 seq_printf(m, "GFX power: %ld\n", gfx);
1792 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1793
1794 return 0;
1795}
1796
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001797static int i915_ring_freq_table(struct seq_file *m, void *unused)
1798{
David Weinehall36cdd012016-08-22 13:59:31 +03001799 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001800 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001801 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301802 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001803
Carlos Santa26310342016-08-17 12:30:41 -07001804 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001805 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001806 return 0;
1807 }
1808
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001809 intel_runtime_pm_get(dev_priv);
1810
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001811 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001812 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001813 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001814
David Weinehall36cdd012016-08-22 13:59:31 +03001815 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301816 /* Convert GT frequency to 50 HZ units */
1817 min_gpu_freq =
1818 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1819 max_gpu_freq =
1820 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1821 } else {
1822 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1823 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1824 }
1825
Damien Lespiau267f0c92013-06-24 22:59:48 +01001826 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827
Akash Goelf936ec32015-06-29 14:50:22 +05301828 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001829 ia_freq = gpu_freq;
1830 sandybridge_pcode_read(dev_priv,
1831 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1832 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001833 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301834 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001835 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001836 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001837 ((ia_freq >> 0) & 0xff) * 100,
1838 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001839 }
1840
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001841 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001842
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001843out:
1844 intel_runtime_pm_put(dev_priv);
1845 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001846}
1847
Chris Wilson44834a62010-08-19 16:09:23 +01001848static int i915_opregion(struct seq_file *m, void *unused)
1849{
David Weinehall36cdd012016-08-22 13:59:31 +03001850 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1851 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001852 struct intel_opregion *opregion = &dev_priv->opregion;
1853 int ret;
1854
1855 ret = mutex_lock_interruptible(&dev->struct_mutex);
1856 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001857 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001858
Jani Nikula2455a8e2015-12-14 12:50:53 +02001859 if (opregion->header)
1860 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001861
1862 mutex_unlock(&dev->struct_mutex);
1863
Daniel Vetter0d38f002012-04-21 22:49:10 +02001864out:
Chris Wilson44834a62010-08-19 16:09:23 +01001865 return 0;
1866}
1867
Jani Nikulaada8f952015-12-15 13:17:12 +02001868static int i915_vbt(struct seq_file *m, void *unused)
1869{
David Weinehall36cdd012016-08-22 13:59:31 +03001870 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001871
1872 if (opregion->vbt)
1873 seq_write(m, opregion->vbt, opregion->vbt_size);
1874
1875 return 0;
1876}
1877
Chris Wilson37811fc2010-08-25 22:45:57 +01001878static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1879{
David Weinehall36cdd012016-08-22 13:59:31 +03001880 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1881 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301882 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001883 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001884 int ret;
1885
1886 ret = mutex_lock_interruptible(&dev->struct_mutex);
1887 if (ret)
1888 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001889
Daniel Vetter06957262015-08-10 13:34:08 +02001890#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001891 if (dev_priv->fbdev) {
1892 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001893
Chris Wilson25bcce92016-07-02 15:36:00 +01001894 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1895 fbdev_fb->base.width,
1896 fbdev_fb->base.height,
1897 fbdev_fb->base.depth,
1898 fbdev_fb->base.bits_per_pixel,
1899 fbdev_fb->base.modifier[0],
1900 drm_framebuffer_read_refcount(&fbdev_fb->base));
1901 describe_obj(m, fbdev_fb->obj);
1902 seq_putc(m, '\n');
1903 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001904#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001905
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001906 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001907 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301908 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1909 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001910 continue;
1911
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001912 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 +01001913 fb->base.width,
1914 fb->base.height,
1915 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001916 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001917 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001918 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001919 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001920 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001921 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001922 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001923 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001924
1925 return 0;
1926}
1927
Chris Wilson7e37f882016-08-02 22:50:21 +01001928static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001929{
1930 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001931 ring->space, ring->head, ring->tail,
1932 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001933}
1934
Ben Widawskye76d3632011-03-19 18:14:29 -07001935static int i915_context_status(struct seq_file *m, void *unused)
1936{
David Weinehall36cdd012016-08-22 13:59:31 +03001937 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1938 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001939 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001940 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301941 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001942 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001943
Daniel Vetterf3d28872014-05-29 23:23:08 +02001944 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001945 if (ret)
1946 return ret;
1947
Ben Widawskya33afea2013-09-17 21:12:45 -07001948 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001949 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001950 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001951 struct task_struct *task;
1952
Chris Wilsonc84455b2016-08-15 10:49:08 +01001953 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001954 if (task) {
1955 seq_printf(m, "(%s [%d]) ",
1956 task->comm, task->pid);
1957 put_task_struct(task);
1958 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001959 } else if (IS_ERR(ctx->file_priv)) {
1960 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001961 } else {
1962 seq_puts(m, "(kernel) ");
1963 }
1964
Chris Wilsonbca44d82016-05-24 14:53:41 +01001965 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1966 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001967
Akash Goel3b3f1652016-10-13 22:44:48 +05301968 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001969 struct intel_context *ce = &ctx->engine[engine->id];
1970
1971 seq_printf(m, "%s: ", engine->name);
1972 seq_putc(m, ce->initialised ? 'I' : 'i');
1973 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001974 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001975 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001976 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001977 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001978 }
1979
Ben Widawskya33afea2013-09-17 21:12:45 -07001980 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001981 }
1982
Daniel Vetterf3d28872014-05-29 23:23:08 +02001983 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001984
1985 return 0;
1986}
1987
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001988static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001989 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001990 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001991{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001992 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001993 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001994 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001995
Chris Wilson7069b142016-04-28 09:56:52 +01001996 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1997
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001998 if (!vma) {
1999 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002000 return;
2001 }
2002
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002003 if (vma->flags & I915_VMA_GLOBAL_BIND)
2004 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002005 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002006
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002007 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002008 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002009 return;
2010 }
2011
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002012 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2013 if (page) {
2014 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002015
2016 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002017 seq_printf(m,
2018 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2019 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002020 reg_state[j], reg_state[j + 1],
2021 reg_state[j + 2], reg_state[j + 3]);
2022 }
2023 kunmap_atomic(reg_state);
2024 }
2025
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002026 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002027 seq_putc(m, '\n');
2028}
2029
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002030static int i915_dump_lrc(struct seq_file *m, void *unused)
2031{
David Weinehall36cdd012016-08-22 13:59:31 +03002032 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2033 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002034 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002035 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302036 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002037 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002038
2039 if (!i915.enable_execlists) {
2040 seq_printf(m, "Logical Ring Contexts are disabled\n");
2041 return 0;
2042 }
2043
2044 ret = mutex_lock_interruptible(&dev->struct_mutex);
2045 if (ret)
2046 return ret;
2047
Dave Gordone28e4042016-01-19 19:02:55 +00002048 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302049 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002050 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002051
2052 mutex_unlock(&dev->struct_mutex);
2053
2054 return 0;
2055}
2056
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002057static const char *swizzle_string(unsigned swizzle)
2058{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002059 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002060 case I915_BIT_6_SWIZZLE_NONE:
2061 return "none";
2062 case I915_BIT_6_SWIZZLE_9:
2063 return "bit9";
2064 case I915_BIT_6_SWIZZLE_9_10:
2065 return "bit9/bit10";
2066 case I915_BIT_6_SWIZZLE_9_11:
2067 return "bit9/bit11";
2068 case I915_BIT_6_SWIZZLE_9_10_11:
2069 return "bit9/bit10/bit11";
2070 case I915_BIT_6_SWIZZLE_9_17:
2071 return "bit9/bit17";
2072 case I915_BIT_6_SWIZZLE_9_10_17:
2073 return "bit9/bit10/bit17";
2074 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002075 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002076 }
2077
2078 return "bug";
2079}
2080
2081static int i915_swizzle_info(struct seq_file *m, void *data)
2082{
David Weinehall36cdd012016-08-22 13:59:31 +03002083 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002084
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002085 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002086
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002087 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2088 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2089 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2090 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2091
David Weinehall36cdd012016-08-22 13:59:31 +03002092 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002093 seq_printf(m, "DDC = 0x%08x\n",
2094 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002095 seq_printf(m, "DDC2 = 0x%08x\n",
2096 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002097 seq_printf(m, "C0DRB3 = 0x%04x\n",
2098 I915_READ16(C0DRB3));
2099 seq_printf(m, "C1DRB3 = 0x%04x\n",
2100 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002101 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002102 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2103 I915_READ(MAD_DIMM_C0));
2104 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2105 I915_READ(MAD_DIMM_C1));
2106 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2107 I915_READ(MAD_DIMM_C2));
2108 seq_printf(m, "TILECTL = 0x%08x\n",
2109 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002110 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002111 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2112 I915_READ(GAMTARBMODE));
2113 else
2114 seq_printf(m, "ARB_MODE = 0x%08x\n",
2115 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002116 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2117 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002118 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002119
2120 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2121 seq_puts(m, "L-shaped memory detected\n");
2122
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002123 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002124
2125 return 0;
2126}
2127
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002128static int per_file_ctx(int id, void *ptr, void *data)
2129{
Chris Wilsone2efd132016-05-24 14:53:34 +01002130 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002131 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002132 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2133
2134 if (!ppgtt) {
2135 seq_printf(m, " no ppgtt for context %d\n",
2136 ctx->user_handle);
2137 return 0;
2138 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002139
Oscar Mateof83d6512014-05-22 14:13:38 +01002140 if (i915_gem_context_is_default(ctx))
2141 seq_puts(m, " default context:\n");
2142 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002143 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002144 ppgtt->debug_dump(ppgtt, m);
2145
2146 return 0;
2147}
2148
David Weinehall36cdd012016-08-22 13:59:31 +03002149static void gen8_ppgtt_info(struct seq_file *m,
2150 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002151{
Ben Widawsky77df6772013-11-02 21:07:30 -07002152 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302153 struct intel_engine_cs *engine;
2154 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002155 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002156
Ben Widawsky77df6772013-11-02 21:07:30 -07002157 if (!ppgtt)
2158 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002159
Akash Goel3b3f1652016-10-13 22:44:48 +05302160 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002161 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002162 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002163 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002164 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002165 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002166 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002167 }
2168 }
2169}
2170
David Weinehall36cdd012016-08-22 13:59:31 +03002171static void gen6_ppgtt_info(struct seq_file *m,
2172 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002173{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002174 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302175 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002176
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002177 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002178 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2179
Akash Goel3b3f1652016-10-13 22:44:48 +05302180 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002181 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002182 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002183 seq_printf(m, "GFX_MODE: 0x%08x\n",
2184 I915_READ(RING_MODE_GEN7(engine)));
2185 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2186 I915_READ(RING_PP_DIR_BASE(engine)));
2187 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2188 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2189 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2190 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002191 }
2192 if (dev_priv->mm.aliasing_ppgtt) {
2193 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2194
Damien Lespiau267f0c92013-06-24 22:59:48 +01002195 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002196 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002197
Ben Widawsky87d60b62013-12-06 14:11:29 -08002198 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002199 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002200
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002201 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002202}
2203
2204static int i915_ppgtt_info(struct seq_file *m, void *data)
2205{
David Weinehall36cdd012016-08-22 13:59:31 +03002206 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2207 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002208 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002209 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002210
Chris Wilson637ee292016-08-22 14:28:20 +01002211 mutex_lock(&dev->filelist_mutex);
2212 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002213 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002214 goto out_unlock;
2215
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002216 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002217
David Weinehall36cdd012016-08-22 13:59:31 +03002218 if (INTEL_GEN(dev_priv) >= 8)
2219 gen8_ppgtt_info(m, dev_priv);
2220 else if (INTEL_GEN(dev_priv) >= 6)
2221 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002222
Michel Thierryea91e402015-07-29 17:23:57 +01002223 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2224 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002225 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002226
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002227 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002228 if (!task) {
2229 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002230 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002231 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002232 seq_printf(m, "\nproc: %s\n", task->comm);
2233 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002234 idr_for_each(&file_priv->context_idr, per_file_ctx,
2235 (void *)(unsigned long)m);
2236 }
2237
Chris Wilson637ee292016-08-22 14:28:20 +01002238out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002239 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002240 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002241out_unlock:
2242 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002243 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002244}
2245
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002246static int count_irq_waiters(struct drm_i915_private *i915)
2247{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002248 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302249 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002250 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002251
Akash Goel3b3f1652016-10-13 22:44:48 +05302252 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002253 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002254
2255 return count;
2256}
2257
Chris Wilson7466c292016-08-15 09:49:33 +01002258static const char *rps_power_to_str(unsigned int power)
2259{
2260 static const char * const strings[] = {
2261 [LOW_POWER] = "low power",
2262 [BETWEEN] = "mixed",
2263 [HIGH_POWER] = "high power",
2264 };
2265
2266 if (power >= ARRAY_SIZE(strings) || !strings[power])
2267 return "unknown";
2268
2269 return strings[power];
2270}
2271
Chris Wilson1854d5c2015-04-07 16:20:32 +01002272static int i915_rps_boost_info(struct seq_file *m, void *data)
2273{
David Weinehall36cdd012016-08-22 13:59:31 +03002274 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2275 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002276 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002277
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002278 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002279 seq_printf(m, "GPU busy? %s [%d requests]\n",
2280 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002281 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002282 seq_printf(m, "Frequency requested %d\n",
2283 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2284 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002285 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2286 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2287 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2288 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002289 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2290 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2291 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2292 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002293
2294 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002295 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002296 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2297 struct drm_i915_file_private *file_priv = file->driver_priv;
2298 struct task_struct *task;
2299
2300 rcu_read_lock();
2301 task = pid_task(file->pid, PIDTYPE_PID);
2302 seq_printf(m, "%s [%d]: %d boosts%s\n",
2303 task ? task->comm : "<unknown>",
2304 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002305 file_priv->rps.boosts,
2306 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002307 rcu_read_unlock();
2308 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002309 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002310 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002311 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002312
Chris Wilson7466c292016-08-15 09:49:33 +01002313 if (INTEL_GEN(dev_priv) >= 6 &&
2314 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002315 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002316 u32 rpup, rpupei;
2317 u32 rpdown, rpdownei;
2318
2319 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2320 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2321 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2322 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2323 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2324 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2325
2326 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2327 rps_power_to_str(dev_priv->rps.power));
2328 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2329 100 * rpup / rpupei,
2330 dev_priv->rps.up_threshold);
2331 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2332 100 * rpdown / rpdownei,
2333 dev_priv->rps.down_threshold);
2334 } else {
2335 seq_puts(m, "\nRPS Autotuning inactive\n");
2336 }
2337
Chris Wilson8d3afd72015-05-21 21:01:47 +01002338 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002339}
2340
Ben Widawsky63573eb2013-07-04 11:02:07 -07002341static int i915_llc(struct seq_file *m, void *data)
2342{
David Weinehall36cdd012016-08-22 13:59:31 +03002343 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002344 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002345
David Weinehall36cdd012016-08-22 13:59:31 +03002346 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002347 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2348 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002349
2350 return 0;
2351}
2352
Alex Daifdf5d352015-08-12 15:43:37 +01002353static int i915_guc_load_status_info(struct seq_file *m, void *data)
2354{
David Weinehall36cdd012016-08-22 13:59:31 +03002355 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002356 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2357 u32 tmp, i;
2358
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002359 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002360 return 0;
2361
2362 seq_printf(m, "GuC firmware status:\n");
2363 seq_printf(m, "\tpath: %s\n",
2364 guc_fw->guc_fw_path);
2365 seq_printf(m, "\tfetch: %s\n",
2366 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2367 seq_printf(m, "\tload: %s\n",
2368 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2369 seq_printf(m, "\tversion wanted: %d.%d\n",
2370 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2371 seq_printf(m, "\tversion found: %d.%d\n",
2372 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002373 seq_printf(m, "\theader: offset is %d; size = %d\n",
2374 guc_fw->header_offset, guc_fw->header_size);
2375 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2376 guc_fw->ucode_offset, guc_fw->ucode_size);
2377 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2378 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002379
2380 tmp = I915_READ(GUC_STATUS);
2381
2382 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2383 seq_printf(m, "\tBootrom status = 0x%x\n",
2384 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2385 seq_printf(m, "\tuKernel status = 0x%x\n",
2386 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2387 seq_printf(m, "\tMIA Core status = 0x%x\n",
2388 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2389 seq_puts(m, "\nScratch registers:\n");
2390 for (i = 0; i < 16; i++)
2391 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2392
2393 return 0;
2394}
2395
Akash Goel5aa1ee42016-10-12 21:54:36 +05302396static void i915_guc_log_info(struct seq_file *m,
2397 struct drm_i915_private *dev_priv)
2398{
2399 struct intel_guc *guc = &dev_priv->guc;
2400
2401 seq_puts(m, "\nGuC logging stats:\n");
2402
2403 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2404 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2405 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2406
2407 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2408 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2409 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2410
2411 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2412 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2413 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2414
2415 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2416 guc->log.flush_interrupt_count);
2417
2418 seq_printf(m, "\tCapture miss count: %u\n",
2419 guc->log.capture_miss_count);
2420}
2421
Dave Gordon8b417c22015-08-12 15:43:44 +01002422static void i915_guc_client_info(struct seq_file *m,
2423 struct drm_i915_private *dev_priv,
2424 struct i915_guc_client *client)
2425{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002426 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002427 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002428 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002429
2430 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2431 client->priority, client->ctx_index, client->proc_desc_offset);
2432 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2433 client->doorbell_id, client->doorbell_offset, client->cookie);
2434 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2435 client->wq_size, client->wq_offset, client->wq_tail);
2436
Dave Gordon551aaec2016-05-13 15:36:33 +01002437 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002438 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2439 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2440
Akash Goel3b3f1652016-10-13 22:44:48 +05302441 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002442 u64 submissions = client->submissions[id];
2443 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002444 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002445 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002446 }
2447 seq_printf(m, "\tTotal: %llu\n", tot);
2448}
2449
2450static int i915_guc_info(struct seq_file *m, void *data)
2451{
David Weinehall36cdd012016-08-22 13:59:31 +03002452 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2453 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002454 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002455 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002456 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002457 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002458 u64 total = 0;
2459
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002460 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002461 return 0;
2462
Alex Dai5a843302015-12-02 16:56:29 -08002463 if (mutex_lock_interruptible(&dev->struct_mutex))
2464 return 0;
2465
Dave Gordon8b417c22015-08-12 15:43:44 +01002466 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002467 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002468 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002469 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002470
2471 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002472
Dave Gordon9636f6d2016-06-13 17:57:28 +01002473 seq_printf(m, "Doorbell map:\n");
2474 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2475 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2476
Dave Gordon8b417c22015-08-12 15:43:44 +01002477 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2478 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2479 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2480 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2481 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2482
2483 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302484 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002485 u64 submissions = guc.submissions[id];
2486 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002487 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002488 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002489 }
2490 seq_printf(m, "\t%s: %llu\n", "Total", total);
2491
2492 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2493 i915_guc_client_info(m, dev_priv, &client);
2494
Akash Goel5aa1ee42016-10-12 21:54:36 +05302495 i915_guc_log_info(m, dev_priv);
2496
Dave Gordon8b417c22015-08-12 15:43:44 +01002497 /* Add more as required ... */
2498
2499 return 0;
2500}
2501
Alex Dai4c7e77f2015-08-12 15:43:40 +01002502static int i915_guc_log_dump(struct seq_file *m, void *data)
2503{
David Weinehall36cdd012016-08-22 13:59:31 +03002504 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002505 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002506 int i = 0, pg;
2507
Akash Goeld6b40b42016-10-12 21:54:29 +05302508 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002509 return 0;
2510
Akash Goeld6b40b42016-10-12 21:54:29 +05302511 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002512 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2513 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002514
2515 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2516 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2517 *(log + i), *(log + i + 1),
2518 *(log + i + 2), *(log + i + 3));
2519
2520 kunmap_atomic(log);
2521 }
2522
2523 seq_putc(m, '\n');
2524
2525 return 0;
2526}
2527
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302528static int i915_guc_log_control_get(void *data, u64 *val)
2529{
2530 struct drm_device *dev = data;
2531 struct drm_i915_private *dev_priv = to_i915(dev);
2532
2533 if (!dev_priv->guc.log.vma)
2534 return -EINVAL;
2535
2536 *val = i915.guc_log_level;
2537
2538 return 0;
2539}
2540
2541static int i915_guc_log_control_set(void *data, u64 val)
2542{
2543 struct drm_device *dev = data;
2544 struct drm_i915_private *dev_priv = to_i915(dev);
2545 int ret;
2546
2547 if (!dev_priv->guc.log.vma)
2548 return -EINVAL;
2549
2550 ret = mutex_lock_interruptible(&dev->struct_mutex);
2551 if (ret)
2552 return ret;
2553
2554 intel_runtime_pm_get(dev_priv);
2555 ret = i915_guc_log_control(dev_priv, val);
2556 intel_runtime_pm_put(dev_priv);
2557
2558 mutex_unlock(&dev->struct_mutex);
2559 return ret;
2560}
2561
2562DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2563 i915_guc_log_control_get, i915_guc_log_control_set,
2564 "%lld\n");
2565
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002566static int i915_edp_psr_status(struct seq_file *m, void *data)
2567{
David Weinehall36cdd012016-08-22 13:59:31 +03002568 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002569 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002570 u32 stat[3];
2571 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002572 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002573
David Weinehall36cdd012016-08-22 13:59:31 +03002574 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002575 seq_puts(m, "PSR not supported\n");
2576 return 0;
2577 }
2578
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002579 intel_runtime_pm_get(dev_priv);
2580
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002581 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002582 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2583 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002584 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002585 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002586 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2587 dev_priv->psr.busy_frontbuffer_bits);
2588 seq_printf(m, "Re-enable work scheduled: %s\n",
2589 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002590
David Weinehall36cdd012016-08-22 13:59:31 +03002591 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002592 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002593 else {
2594 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002595 enum transcoder cpu_transcoder =
2596 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2597 enum intel_display_power_domain power_domain;
2598
2599 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2600 if (!intel_display_power_get_if_enabled(dev_priv,
2601 power_domain))
2602 continue;
2603
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002604 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2605 VLV_EDP_PSR_CURR_STATE_MASK;
2606 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2607 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2608 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002609
2610 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002611 }
2612 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002613
2614 seq_printf(m, "Main link in standby mode: %s\n",
2615 yesno(dev_priv->psr.link_standby));
2616
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002617 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002618
David Weinehall36cdd012016-08-22 13:59:31 +03002619 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002620 for_each_pipe(dev_priv, pipe) {
2621 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2622 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2623 seq_printf(m, " pipe %c", pipe_name(pipe));
2624 }
2625 seq_puts(m, "\n");
2626
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002627 /*
2628 * VLV/CHV PSR has no kind of performance counter
2629 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2630 */
David Weinehall36cdd012016-08-22 13:59:31 +03002631 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002632 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002633 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002634
2635 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2636 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002637 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002638
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002639 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002640 return 0;
2641}
2642
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002643static int i915_sink_crc(struct seq_file *m, void *data)
2644{
David Weinehall36cdd012016-08-22 13:59:31 +03002645 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2646 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002647 struct intel_connector *connector;
2648 struct intel_dp *intel_dp = NULL;
2649 int ret;
2650 u8 crc[6];
2651
2652 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002653 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002654 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002655
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002656 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002657 continue;
2658
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002659 crtc = connector->base.state->crtc;
2660 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002661 continue;
2662
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002663 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002664 continue;
2665
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002666 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002667
2668 ret = intel_dp_sink_crc(intel_dp, crc);
2669 if (ret)
2670 goto out;
2671
2672 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2673 crc[0], crc[1], crc[2],
2674 crc[3], crc[4], crc[5]);
2675 goto out;
2676 }
2677 ret = -ENODEV;
2678out:
2679 drm_modeset_unlock_all(dev);
2680 return ret;
2681}
2682
Jesse Barnesec013e72013-08-20 10:29:23 +01002683static int i915_energy_uJ(struct seq_file *m, void *data)
2684{
David Weinehall36cdd012016-08-22 13:59:31 +03002685 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002686 u64 power;
2687 u32 units;
2688
David Weinehall36cdd012016-08-22 13:59:31 +03002689 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002690 return -ENODEV;
2691
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002692 intel_runtime_pm_get(dev_priv);
2693
Jesse Barnesec013e72013-08-20 10:29:23 +01002694 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2695 power = (power & 0x1f00) >> 8;
2696 units = 1000000 / (1 << power); /* convert to uJ */
2697 power = I915_READ(MCH_SECP_NRG_STTS);
2698 power *= units;
2699
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002700 intel_runtime_pm_put(dev_priv);
2701
Jesse Barnesec013e72013-08-20 10:29:23 +01002702 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002703
2704 return 0;
2705}
2706
Damien Lespiau6455c872015-06-04 18:23:57 +01002707static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002708{
David Weinehall36cdd012016-08-22 13:59:31 +03002709 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002710 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002711
Chris Wilsona156e642016-04-03 14:14:21 +01002712 if (!HAS_RUNTIME_PM(dev_priv))
2713 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002714
Chris Wilson67d97da2016-07-04 08:08:31 +01002715 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002716 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002717 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002718#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002719 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002720 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002721#else
2722 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2723#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002724 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002725 pci_power_name(pdev->current_state),
2726 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002727
Jesse Barnesec013e72013-08-20 10:29:23 +01002728 return 0;
2729}
2730
Imre Deak1da51582013-11-25 17:15:35 +02002731static int i915_power_domain_info(struct seq_file *m, void *unused)
2732{
David Weinehall36cdd012016-08-22 13:59:31 +03002733 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002734 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2735 int i;
2736
2737 mutex_lock(&power_domains->lock);
2738
2739 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2740 for (i = 0; i < power_domains->power_well_count; i++) {
2741 struct i915_power_well *power_well;
2742 enum intel_display_power_domain power_domain;
2743
2744 power_well = &power_domains->power_wells[i];
2745 seq_printf(m, "%-25s %d\n", power_well->name,
2746 power_well->count);
2747
2748 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2749 power_domain++) {
2750 if (!(BIT(power_domain) & power_well->domains))
2751 continue;
2752
2753 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002754 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002755 power_domains->domain_use_count[power_domain]);
2756 }
2757 }
2758
2759 mutex_unlock(&power_domains->lock);
2760
2761 return 0;
2762}
2763
Damien Lespiaub7cec662015-10-27 14:47:01 +02002764static int i915_dmc_info(struct seq_file *m, void *unused)
2765{
David Weinehall36cdd012016-08-22 13:59:31 +03002766 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002767 struct intel_csr *csr;
2768
David Weinehall36cdd012016-08-22 13:59:31 +03002769 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002770 seq_puts(m, "not supported\n");
2771 return 0;
2772 }
2773
2774 csr = &dev_priv->csr;
2775
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002776 intel_runtime_pm_get(dev_priv);
2777
Damien Lespiaub7cec662015-10-27 14:47:01 +02002778 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2779 seq_printf(m, "path: %s\n", csr->fw_path);
2780
2781 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002782 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002783
2784 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2785 CSR_VERSION_MINOR(csr->version));
2786
David Weinehall36cdd012016-08-22 13:59:31 +03002787 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002788 seq_printf(m, "DC3 -> DC5 count: %d\n",
2789 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2790 seq_printf(m, "DC5 -> DC6 count: %d\n",
2791 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002792 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002793 seq_printf(m, "DC3 -> DC5 count: %d\n",
2794 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002795 }
2796
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002797out:
2798 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2799 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2800 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2801
Damien Lespiau83372062015-10-30 17:53:32 +02002802 intel_runtime_pm_put(dev_priv);
2803
Damien Lespiaub7cec662015-10-27 14:47:01 +02002804 return 0;
2805}
2806
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002807static void intel_seq_print_mode(struct seq_file *m, int tabs,
2808 struct drm_display_mode *mode)
2809{
2810 int i;
2811
2812 for (i = 0; i < tabs; i++)
2813 seq_putc(m, '\t');
2814
2815 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",
2816 mode->base.id, mode->name,
2817 mode->vrefresh, mode->clock,
2818 mode->hdisplay, mode->hsync_start,
2819 mode->hsync_end, mode->htotal,
2820 mode->vdisplay, mode->vsync_start,
2821 mode->vsync_end, mode->vtotal,
2822 mode->type, mode->flags);
2823}
2824
2825static void intel_encoder_info(struct seq_file *m,
2826 struct intel_crtc *intel_crtc,
2827 struct intel_encoder *intel_encoder)
2828{
David Weinehall36cdd012016-08-22 13:59:31 +03002829 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2830 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002831 struct drm_crtc *crtc = &intel_crtc->base;
2832 struct intel_connector *intel_connector;
2833 struct drm_encoder *encoder;
2834
2835 encoder = &intel_encoder->base;
2836 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002837 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002838 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2839 struct drm_connector *connector = &intel_connector->base;
2840 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2841 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002842 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002843 drm_get_connector_status_name(connector->status));
2844 if (connector->status == connector_status_connected) {
2845 struct drm_display_mode *mode = &crtc->mode;
2846 seq_printf(m, ", mode:\n");
2847 intel_seq_print_mode(m, 2, mode);
2848 } else {
2849 seq_putc(m, '\n');
2850 }
2851 }
2852}
2853
2854static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2855{
David Weinehall36cdd012016-08-22 13:59:31 +03002856 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2857 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002858 struct drm_crtc *crtc = &intel_crtc->base;
2859 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002860 struct drm_plane_state *plane_state = crtc->primary->state;
2861 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002862
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002863 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002864 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002865 fb->base.id, plane_state->src_x >> 16,
2866 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002867 else
2868 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002869 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2870 intel_encoder_info(m, intel_crtc, intel_encoder);
2871}
2872
2873static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2874{
2875 struct drm_display_mode *mode = panel->fixed_mode;
2876
2877 seq_printf(m, "\tfixed mode:\n");
2878 intel_seq_print_mode(m, 2, mode);
2879}
2880
2881static void intel_dp_info(struct seq_file *m,
2882 struct intel_connector *intel_connector)
2883{
2884 struct intel_encoder *intel_encoder = intel_connector->encoder;
2885 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2886
2887 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002888 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002889 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002890 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002891
2892 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2893 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002894}
2895
2896static void intel_hdmi_info(struct seq_file *m,
2897 struct intel_connector *intel_connector)
2898{
2899 struct intel_encoder *intel_encoder = intel_connector->encoder;
2900 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2901
Jani Nikula742f4912015-09-03 11:16:09 +03002902 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002903}
2904
2905static void intel_lvds_info(struct seq_file *m,
2906 struct intel_connector *intel_connector)
2907{
2908 intel_panel_info(m, &intel_connector->panel);
2909}
2910
2911static void intel_connector_info(struct seq_file *m,
2912 struct drm_connector *connector)
2913{
2914 struct intel_connector *intel_connector = to_intel_connector(connector);
2915 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002916 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002917
2918 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002919 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002920 drm_get_connector_status_name(connector->status));
2921 if (connector->status == connector_status_connected) {
2922 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2923 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2924 connector->display_info.width_mm,
2925 connector->display_info.height_mm);
2926 seq_printf(m, "\tsubpixel order: %s\n",
2927 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2928 seq_printf(m, "\tCEA rev: %d\n",
2929 connector->display_info.cea_rev);
2930 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002931
2932 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2933 return;
2934
2935 switch (connector->connector_type) {
2936 case DRM_MODE_CONNECTOR_DisplayPort:
2937 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002938 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002939 break;
2940 case DRM_MODE_CONNECTOR_LVDS:
2941 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002942 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002943 break;
2944 case DRM_MODE_CONNECTOR_HDMIA:
2945 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2946 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2947 intel_hdmi_info(m, intel_connector);
2948 break;
2949 default:
2950 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002951 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002952
Jesse Barnesf103fc72014-02-20 12:39:57 -08002953 seq_printf(m, "\tmodes:\n");
2954 list_for_each_entry(mode, &connector->modes, head)
2955 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002956}
2957
David Weinehall36cdd012016-08-22 13:59:31 +03002958static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002959{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002960 u32 state;
2961
David Weinehall36cdd012016-08-22 13:59:31 +03002962 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002963 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002964 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002965 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002966
2967 return state;
2968}
2969
David Weinehall36cdd012016-08-22 13:59:31 +03002970static bool cursor_position(struct drm_i915_private *dev_priv,
2971 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002972{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002973 u32 pos;
2974
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002975 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002976
2977 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2978 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2979 *x = -*x;
2980
2981 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2982 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2983 *y = -*y;
2984
David Weinehall36cdd012016-08-22 13:59:31 +03002985 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002986}
2987
Robert Fekete3abc4e02015-10-27 16:58:32 +01002988static const char *plane_type(enum drm_plane_type type)
2989{
2990 switch (type) {
2991 case DRM_PLANE_TYPE_OVERLAY:
2992 return "OVL";
2993 case DRM_PLANE_TYPE_PRIMARY:
2994 return "PRI";
2995 case DRM_PLANE_TYPE_CURSOR:
2996 return "CUR";
2997 /*
2998 * Deliberately omitting default: to generate compiler warnings
2999 * when a new drm_plane_type gets added.
3000 */
3001 }
3002
3003 return "unknown";
3004}
3005
3006static const char *plane_rotation(unsigned int rotation)
3007{
3008 static char buf[48];
3009 /*
3010 * According to doc only one DRM_ROTATE_ is allowed but this
3011 * will print them all to visualize if the values are misused
3012 */
3013 snprintf(buf, sizeof(buf),
3014 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003015 (rotation & DRM_ROTATE_0) ? "0 " : "",
3016 (rotation & DRM_ROTATE_90) ? "90 " : "",
3017 (rotation & DRM_ROTATE_180) ? "180 " : "",
3018 (rotation & DRM_ROTATE_270) ? "270 " : "",
3019 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3020 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003021 rotation);
3022
3023 return buf;
3024}
3025
3026static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3027{
David Weinehall36cdd012016-08-22 13:59:31 +03003028 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3029 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003030 struct intel_plane *intel_plane;
3031
3032 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3033 struct drm_plane_state *state;
3034 struct drm_plane *plane = &intel_plane->base;
Eric Engestromd3828142016-08-15 16:29:55 +01003035 char *format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003036
3037 if (!plane->state) {
3038 seq_puts(m, "plane->state is NULL!\n");
3039 continue;
3040 }
3041
3042 state = plane->state;
3043
Eric Engestrom90844f02016-08-15 01:02:38 +01003044 if (state->fb) {
3045 format_name = drm_get_format_name(state->fb->pixel_format);
3046 } else {
3047 format_name = kstrdup("N/A", GFP_KERNEL);
3048 }
3049
Robert Fekete3abc4e02015-10-27 16:58:32 +01003050 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",
3051 plane->base.id,
3052 plane_type(intel_plane->base.type),
3053 state->crtc_x, state->crtc_y,
3054 state->crtc_w, state->crtc_h,
3055 (state->src_x >> 16),
3056 ((state->src_x & 0xffff) * 15625) >> 10,
3057 (state->src_y >> 16),
3058 ((state->src_y & 0xffff) * 15625) >> 10,
3059 (state->src_w >> 16),
3060 ((state->src_w & 0xffff) * 15625) >> 10,
3061 (state->src_h >> 16),
3062 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestrom90844f02016-08-15 01:02:38 +01003063 format_name,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003064 plane_rotation(state->rotation));
Eric Engestrom90844f02016-08-15 01:02:38 +01003065
3066 kfree(format_name);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003067 }
3068}
3069
3070static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3071{
3072 struct intel_crtc_state *pipe_config;
3073 int num_scalers = intel_crtc->num_scalers;
3074 int i;
3075
3076 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3077
3078 /* Not all platformas have a scaler */
3079 if (num_scalers) {
3080 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3081 num_scalers,
3082 pipe_config->scaler_state.scaler_users,
3083 pipe_config->scaler_state.scaler_id);
3084
3085 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3086 struct intel_scaler *sc =
3087 &pipe_config->scaler_state.scalers[i];
3088
3089 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3090 i, yesno(sc->in_use), sc->mode);
3091 }
3092 seq_puts(m, "\n");
3093 } else {
3094 seq_puts(m, "\tNo scalers available on this platform\n");
3095 }
3096}
3097
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003098static int i915_display_info(struct seq_file *m, void *unused)
3099{
David Weinehall36cdd012016-08-22 13:59:31 +03003100 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3101 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003102 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003103 struct drm_connector *connector;
3104
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003105 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003106 drm_modeset_lock_all(dev);
3107 seq_printf(m, "CRTC info\n");
3108 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003109 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003110 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003111 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003112 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003113
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003114 pipe_config = to_intel_crtc_state(crtc->base.state);
3115
Robert Fekete3abc4e02015-10-27 16:58:32 +01003116 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003117 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003118 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003119 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3120 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3121
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003122 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003123 intel_crtc_info(m, crtc);
3124
David Weinehall36cdd012016-08-22 13:59:31 +03003125 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003126 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 +03003127 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003128 x, y, crtc->base.cursor->state->crtc_w,
3129 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003130 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003131 intel_scaler_info(m, crtc);
3132 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003133 }
Daniel Vettercace8412014-05-22 17:56:31 +02003134
3135 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3136 yesno(!crtc->cpu_fifo_underrun_disabled),
3137 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003138 }
3139
3140 seq_printf(m, "\n");
3141 seq_printf(m, "Connector info\n");
3142 seq_printf(m, "--------------\n");
3143 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3144 intel_connector_info(m, connector);
3145 }
3146 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003147 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003148
3149 return 0;
3150}
3151
Chris Wilson1b365952016-10-04 21:11:31 +01003152static int i915_engine_info(struct seq_file *m, void *unused)
3153{
3154 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3155 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303156 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003157
Chris Wilson9c870d02016-10-24 13:42:15 +01003158 intel_runtime_pm_get(dev_priv);
3159
Akash Goel3b3f1652016-10-13 22:44:48 +05303160 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003161 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3162 struct drm_i915_gem_request *rq;
3163 struct rb_node *rb;
3164 u64 addr;
3165
3166 seq_printf(m, "%s\n", engine->name);
3167 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3168 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003169 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003170 engine->hangcheck.seqno,
3171 engine->hangcheck.score);
3172
3173 rcu_read_lock();
3174
3175 seq_printf(m, "\tRequests:\n");
3176
Chris Wilson73cb9702016-10-28 13:58:46 +01003177 rq = list_first_entry(&engine->timeline->requests,
3178 struct drm_i915_gem_request, link);
3179 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003180 print_request(m, rq, "\t\tfirst ");
3181
Chris Wilson73cb9702016-10-28 13:58:46 +01003182 rq = list_last_entry(&engine->timeline->requests,
3183 struct drm_i915_gem_request, link);
3184 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003185 print_request(m, rq, "\t\tlast ");
3186
3187 rq = i915_gem_find_active_request(engine);
3188 if (rq) {
3189 print_request(m, rq, "\t\tactive ");
3190 seq_printf(m,
3191 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3192 rq->head, rq->postfix, rq->tail,
3193 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3194 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3195 }
3196
3197 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3198 I915_READ(RING_START(engine->mmio_base)),
3199 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3200 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3201 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3202 rq ? rq->ring->head : 0);
3203 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3204 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3205 rq ? rq->ring->tail : 0);
3206 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3207 I915_READ(RING_CTL(engine->mmio_base)),
3208 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3209
3210 rcu_read_unlock();
3211
3212 addr = intel_engine_get_active_head(engine);
3213 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3214 upper_32_bits(addr), lower_32_bits(addr));
3215 addr = intel_engine_get_last_batch_head(engine);
3216 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3217 upper_32_bits(addr), lower_32_bits(addr));
3218
3219 if (i915.enable_execlists) {
3220 u32 ptr, read, write;
3221
3222 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3223 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3224 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3225
3226 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3227 read = GEN8_CSB_READ_PTR(ptr);
3228 write = GEN8_CSB_WRITE_PTR(ptr);
3229 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3230 read, write);
3231 if (read >= GEN8_CSB_ENTRIES)
3232 read = 0;
3233 if (write >= GEN8_CSB_ENTRIES)
3234 write = 0;
3235 if (read > write)
3236 write += GEN8_CSB_ENTRIES;
3237 while (read < write) {
3238 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3239
3240 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3241 idx,
3242 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3243 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3244 }
3245
3246 rcu_read_lock();
3247 rq = READ_ONCE(engine->execlist_port[0].request);
3248 if (rq)
3249 print_request(m, rq, "\t\tELSP[0] ");
3250 else
3251 seq_printf(m, "\t\tELSP[0] idle\n");
3252 rq = READ_ONCE(engine->execlist_port[1].request);
3253 if (rq)
3254 print_request(m, rq, "\t\tELSP[1] ");
3255 else
3256 seq_printf(m, "\t\tELSP[1] idle\n");
3257 rcu_read_unlock();
3258 } else if (INTEL_GEN(dev_priv) > 6) {
3259 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3260 I915_READ(RING_PP_DIR_BASE(engine)));
3261 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3262 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3263 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3264 I915_READ(RING_PP_DIR_DCLV(engine)));
3265 }
3266
Chris Wilsonf6168e32016-10-28 13:58:55 +01003267 spin_lock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003268 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3269 struct intel_wait *w = container_of(rb, typeof(*w), node);
3270
3271 seq_printf(m, "\t%s [%d] waiting for %x\n",
3272 w->tsk->comm, w->tsk->pid, w->seqno);
3273 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01003274 spin_unlock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003275
3276 seq_puts(m, "\n");
3277 }
3278
Chris Wilson9c870d02016-10-24 13:42:15 +01003279 intel_runtime_pm_put(dev_priv);
3280
Chris Wilson1b365952016-10-04 21:11:31 +01003281 return 0;
3282}
3283
Ben Widawskye04934c2014-06-30 09:53:42 -07003284static int i915_semaphore_status(struct seq_file *m, void *unused)
3285{
David Weinehall36cdd012016-08-22 13:59:31 +03003286 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3287 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003288 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003289 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003290 enum intel_engine_id id;
3291 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003292
Chris Wilson39df9192016-07-20 13:31:57 +01003293 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003294 seq_puts(m, "Semaphores are disabled\n");
3295 return 0;
3296 }
3297
3298 ret = mutex_lock_interruptible(&dev->struct_mutex);
3299 if (ret)
3300 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003301 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003302
David Weinehall36cdd012016-08-22 13:59:31 +03003303 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003304 struct page *page;
3305 uint64_t *seqno;
3306
Chris Wilson51d545d2016-08-15 10:49:02 +01003307 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003308
3309 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303310 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003311 uint64_t offset;
3312
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003313 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003314
3315 seq_puts(m, " Last signal:");
3316 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003317 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003318 seq_printf(m, "0x%08llx (0x%02llx) ",
3319 seqno[offset], offset * 8);
3320 }
3321 seq_putc(m, '\n');
3322
3323 seq_puts(m, " Last wait: ");
3324 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003325 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003326 seq_printf(m, "0x%08llx (0x%02llx) ",
3327 seqno[offset], offset * 8);
3328 }
3329 seq_putc(m, '\n');
3330
3331 }
3332 kunmap_atomic(seqno);
3333 } else {
3334 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303335 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003336 for (j = 0; j < num_rings; j++)
3337 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003338 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003339 seq_putc(m, '\n');
3340 }
3341
Paulo Zanoni03872062014-07-09 14:31:57 -03003342 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003343 mutex_unlock(&dev->struct_mutex);
3344 return 0;
3345}
3346
Daniel Vetter728e29d2014-06-25 22:01:53 +03003347static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3348{
David Weinehall36cdd012016-08-22 13:59:31 +03003349 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3350 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003351 int i;
3352
3353 drm_modeset_lock_all(dev);
3354 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3355 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3356
3357 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003358 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3359 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003360 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003361 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3362 seq_printf(m, " dpll_md: 0x%08x\n",
3363 pll->config.hw_state.dpll_md);
3364 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3365 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3366 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003367 }
3368 drm_modeset_unlock_all(dev);
3369
3370 return 0;
3371}
3372
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003373static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003374{
3375 int i;
3376 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003377 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003378 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3379 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003380 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003381 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003382
Arun Siluvery888b5992014-08-26 14:44:51 +01003383 ret = mutex_lock_interruptible(&dev->struct_mutex);
3384 if (ret)
3385 return ret;
3386
3387 intel_runtime_pm_get(dev_priv);
3388
Arun Siluvery33136b02016-01-21 21:43:47 +00003389 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303390 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003391 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003392 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003393 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003394 i915_reg_t addr;
3395 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003396 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003397
Arun Siluvery33136b02016-01-21 21:43:47 +00003398 addr = workarounds->reg[i].addr;
3399 mask = workarounds->reg[i].mask;
3400 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003401 read = I915_READ(addr);
3402 ok = (value & mask) == (read & mask);
3403 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 +02003404 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003405 }
3406
3407 intel_runtime_pm_put(dev_priv);
3408 mutex_unlock(&dev->struct_mutex);
3409
3410 return 0;
3411}
3412
Damien Lespiauc5511e42014-11-04 17:06:51 +00003413static int i915_ddb_info(struct seq_file *m, void *unused)
3414{
David Weinehall36cdd012016-08-22 13:59:31 +03003415 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3416 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003417 struct skl_ddb_allocation *ddb;
3418 struct skl_ddb_entry *entry;
3419 enum pipe pipe;
3420 int plane;
3421
David Weinehall36cdd012016-08-22 13:59:31 +03003422 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003423 return 0;
3424
Damien Lespiauc5511e42014-11-04 17:06:51 +00003425 drm_modeset_lock_all(dev);
3426
3427 ddb = &dev_priv->wm.skl_hw.ddb;
3428
3429 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3430
3431 for_each_pipe(dev_priv, pipe) {
3432 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3433
Matt Roper8b364b42016-10-26 15:51:28 -07003434 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003435 entry = &ddb->plane[pipe][plane];
3436 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3437 entry->start, entry->end,
3438 skl_ddb_entry_size(entry));
3439 }
3440
Matt Roper4969d332015-09-24 15:53:10 -07003441 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003442 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3443 entry->end, skl_ddb_entry_size(entry));
3444 }
3445
3446 drm_modeset_unlock_all(dev);
3447
3448 return 0;
3449}
3450
Vandana Kannana54746e2015-03-03 20:53:10 +05303451static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003452 struct drm_device *dev,
3453 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303454{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003455 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303456 struct i915_drrs *drrs = &dev_priv->drrs;
3457 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003458 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303459
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003460 drm_for_each_connector(connector, dev) {
3461 if (connector->state->crtc != &intel_crtc->base)
3462 continue;
3463
3464 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303465 }
3466
3467 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3468 seq_puts(m, "\tVBT: DRRS_type: Static");
3469 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3470 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3471 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3472 seq_puts(m, "\tVBT: DRRS_type: None");
3473 else
3474 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3475
3476 seq_puts(m, "\n\n");
3477
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003478 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303479 struct intel_panel *panel;
3480
3481 mutex_lock(&drrs->mutex);
3482 /* DRRS Supported */
3483 seq_puts(m, "\tDRRS Supported: Yes\n");
3484
3485 /* disable_drrs() will make drrs->dp NULL */
3486 if (!drrs->dp) {
3487 seq_puts(m, "Idleness DRRS: Disabled");
3488 mutex_unlock(&drrs->mutex);
3489 return;
3490 }
3491
3492 panel = &drrs->dp->attached_connector->panel;
3493 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3494 drrs->busy_frontbuffer_bits);
3495
3496 seq_puts(m, "\n\t\t");
3497 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3498 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3499 vrefresh = panel->fixed_mode->vrefresh;
3500 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3501 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3502 vrefresh = panel->downclock_mode->vrefresh;
3503 } else {
3504 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3505 drrs->refresh_rate_type);
3506 mutex_unlock(&drrs->mutex);
3507 return;
3508 }
3509 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3510
3511 seq_puts(m, "\n\t\t");
3512 mutex_unlock(&drrs->mutex);
3513 } else {
3514 /* DRRS not supported. Print the VBT parameter*/
3515 seq_puts(m, "\tDRRS Supported : No");
3516 }
3517 seq_puts(m, "\n");
3518}
3519
3520static int i915_drrs_status(struct seq_file *m, void *unused)
3521{
David Weinehall36cdd012016-08-22 13:59:31 +03003522 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3523 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303524 struct intel_crtc *intel_crtc;
3525 int active_crtc_cnt = 0;
3526
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003527 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303528 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003529 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303530 active_crtc_cnt++;
3531 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3532
3533 drrs_status_per_crtc(m, dev, intel_crtc);
3534 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303535 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003536 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303537
3538 if (!active_crtc_cnt)
3539 seq_puts(m, "No active crtc found\n");
3540
3541 return 0;
3542}
3543
Damien Lespiau07144422013-10-15 18:55:40 +01003544struct pipe_crc_info {
3545 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003546 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003547 enum pipe pipe;
3548};
3549
Dave Airlie11bed952014-05-12 15:22:27 +10003550static int i915_dp_mst_info(struct seq_file *m, void *unused)
3551{
David Weinehall36cdd012016-08-22 13:59:31 +03003552 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3553 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003554 struct intel_encoder *intel_encoder;
3555 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003556 struct drm_connector *connector;
3557
Dave Airlie11bed952014-05-12 15:22:27 +10003558 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003559 drm_for_each_connector(connector, dev) {
3560 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003561 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003562
3563 intel_encoder = intel_attached_encoder(connector);
3564 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3565 continue;
3566
3567 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003568 if (!intel_dig_port->dp.can_mst)
3569 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003570
Jim Bride40ae80c2016-04-14 10:18:37 -07003571 seq_printf(m, "MST Source Port %c\n",
3572 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003573 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3574 }
3575 drm_modeset_unlock_all(dev);
3576 return 0;
3577}
3578
Damien Lespiau07144422013-10-15 18:55:40 +01003579static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003580{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003581 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003582 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003583 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3584
David Weinehall36cdd012016-08-22 13:59:31 +03003585 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003586 return -ENODEV;
3587
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003588 spin_lock_irq(&pipe_crc->lock);
3589
3590 if (pipe_crc->opened) {
3591 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003592 return -EBUSY; /* already open */
3593 }
3594
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003595 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003596 filep->private_data = inode->i_private;
3597
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003598 spin_unlock_irq(&pipe_crc->lock);
3599
Damien Lespiau07144422013-10-15 18:55:40 +01003600 return 0;
3601}
3602
3603static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3604{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003605 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003606 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003607 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3608
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003609 spin_lock_irq(&pipe_crc->lock);
3610 pipe_crc->opened = false;
3611 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003612
Damien Lespiau07144422013-10-15 18:55:40 +01003613 return 0;
3614}
3615
3616/* (6 fields, 8 chars each, space separated (5) + '\n') */
3617#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3618/* account for \'0' */
3619#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3620
3621static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3622{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003623 assert_spin_locked(&pipe_crc->lock);
3624 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3625 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003626}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003627
Damien Lespiau07144422013-10-15 18:55:40 +01003628static ssize_t
3629i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3630 loff_t *pos)
3631{
3632 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003633 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003634 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3635 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003636 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003637 ssize_t bytes_read;
3638
3639 /*
3640 * Don't allow user space to provide buffers not big enough to hold
3641 * a line of data.
3642 */
3643 if (count < PIPE_CRC_LINE_LEN)
3644 return -EINVAL;
3645
3646 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3647 return 0;
3648
3649 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003650 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003651 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003652 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003653
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003654 if (filep->f_flags & O_NONBLOCK) {
3655 spin_unlock_irq(&pipe_crc->lock);
3656 return -EAGAIN;
3657 }
3658
3659 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3660 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3661 if (ret) {
3662 spin_unlock_irq(&pipe_crc->lock);
3663 return ret;
3664 }
Damien Lespiau07144422013-10-15 18:55:40 +01003665 }
3666
3667 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003668 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003669
Damien Lespiau07144422013-10-15 18:55:40 +01003670 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003671 while (n_entries > 0) {
3672 struct intel_pipe_crc_entry *entry =
3673 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003674
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003675 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3676 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3677 break;
3678
3679 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3680 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3681
Damien Lespiau07144422013-10-15 18:55:40 +01003682 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3683 "%8u %8x %8x %8x %8x %8x\n",
3684 entry->frame, entry->crc[0],
3685 entry->crc[1], entry->crc[2],
3686 entry->crc[3], entry->crc[4]);
3687
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003688 spin_unlock_irq(&pipe_crc->lock);
3689
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003690 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003691 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003692
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003693 user_buf += PIPE_CRC_LINE_LEN;
3694 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003695
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003696 spin_lock_irq(&pipe_crc->lock);
3697 }
3698
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003699 spin_unlock_irq(&pipe_crc->lock);
3700
Damien Lespiau07144422013-10-15 18:55:40 +01003701 return bytes_read;
3702}
3703
3704static const struct file_operations i915_pipe_crc_fops = {
3705 .owner = THIS_MODULE,
3706 .open = i915_pipe_crc_open,
3707 .read = i915_pipe_crc_read,
3708 .release = i915_pipe_crc_release,
3709};
3710
3711static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3712 {
3713 .name = "i915_pipe_A_crc",
3714 .pipe = PIPE_A,
3715 },
3716 {
3717 .name = "i915_pipe_B_crc",
3718 .pipe = PIPE_B,
3719 },
3720 {
3721 .name = "i915_pipe_C_crc",
3722 .pipe = PIPE_C,
3723 },
3724};
3725
3726static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3727 enum pipe pipe)
3728{
David Weinehall36cdd012016-08-22 13:59:31 +03003729 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003730 struct dentry *ent;
3731 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3732
David Weinehall36cdd012016-08-22 13:59:31 +03003733 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003734 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3735 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003736 if (!ent)
3737 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003738
3739 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003740}
3741
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003742static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003743 "none",
3744 "plane1",
3745 "plane2",
3746 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003747 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003748 "TV",
3749 "DP-B",
3750 "DP-C",
3751 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003752 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003753};
3754
3755static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3756{
3757 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3758 return pipe_crc_sources[source];
3759}
3760
Damien Lespiaubd9db022013-10-15 18:55:36 +01003761static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003762{
David Weinehall36cdd012016-08-22 13:59:31 +03003763 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003764 int i;
3765
3766 for (i = 0; i < I915_MAX_PIPES; i++)
3767 seq_printf(m, "%c %s\n", pipe_name(i),
3768 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3769
3770 return 0;
3771}
3772
Damien Lespiaubd9db022013-10-15 18:55:36 +01003773static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003774{
David Weinehall36cdd012016-08-22 13:59:31 +03003775 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003776}
3777
Daniel Vetter46a19182013-11-01 10:50:20 +01003778static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003779 uint32_t *val)
3780{
Daniel Vetter46a19182013-11-01 10:50:20 +01003781 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3782 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3783
3784 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003785 case INTEL_PIPE_CRC_SOURCE_PIPE:
3786 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3787 break;
3788 case INTEL_PIPE_CRC_SOURCE_NONE:
3789 *val = 0;
3790 break;
3791 default:
3792 return -EINVAL;
3793 }
3794
3795 return 0;
3796}
3797
David Weinehall36cdd012016-08-22 13:59:31 +03003798static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3799 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003800 enum intel_pipe_crc_source *source)
3801{
David Weinehall36cdd012016-08-22 13:59:31 +03003802 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003803 struct intel_encoder *encoder;
3804 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003805 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003806 int ret = 0;
3807
3808 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3809
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003810 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003811 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003812 if (!encoder->base.crtc)
3813 continue;
3814
3815 crtc = to_intel_crtc(encoder->base.crtc);
3816
3817 if (crtc->pipe != pipe)
3818 continue;
3819
3820 switch (encoder->type) {
3821 case INTEL_OUTPUT_TVOUT:
3822 *source = INTEL_PIPE_CRC_SOURCE_TV;
3823 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003824 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003825 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003826 dig_port = enc_to_dig_port(&encoder->base);
3827 switch (dig_port->port) {
3828 case PORT_B:
3829 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3830 break;
3831 case PORT_C:
3832 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3833 break;
3834 case PORT_D:
3835 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3836 break;
3837 default:
3838 WARN(1, "nonexisting DP port %c\n",
3839 port_name(dig_port->port));
3840 break;
3841 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003842 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003843 default:
3844 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003845 }
3846 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003847 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003848
3849 return ret;
3850}
3851
David Weinehall36cdd012016-08-22 13:59:31 +03003852static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003853 enum pipe pipe,
3854 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003855 uint32_t *val)
3856{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003857 bool need_stable_symbols = false;
3858
Daniel Vetter46a19182013-11-01 10:50:20 +01003859 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003860 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003861 if (ret)
3862 return ret;
3863 }
3864
3865 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003866 case INTEL_PIPE_CRC_SOURCE_PIPE:
3867 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3868 break;
3869 case INTEL_PIPE_CRC_SOURCE_DP_B:
3870 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003871 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003872 break;
3873 case INTEL_PIPE_CRC_SOURCE_DP_C:
3874 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003875 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003876 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003877 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003878 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003879 return -EINVAL;
3880 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3881 need_stable_symbols = true;
3882 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003883 case INTEL_PIPE_CRC_SOURCE_NONE:
3884 *val = 0;
3885 break;
3886 default:
3887 return -EINVAL;
3888 }
3889
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003890 /*
3891 * When the pipe CRC tap point is after the transcoders we need
3892 * to tweak symbol-level features to produce a deterministic series of
3893 * symbols for a given frame. We need to reset those features only once
3894 * a frame (instead of every nth symbol):
3895 * - DC-balance: used to ensure a better clock recovery from the data
3896 * link (SDVO)
3897 * - DisplayPort scrambling: used for EMI reduction
3898 */
3899 if (need_stable_symbols) {
3900 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3901
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003902 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003903 switch (pipe) {
3904 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003905 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003906 break;
3907 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003908 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003909 break;
3910 case PIPE_C:
3911 tmp |= PIPE_C_SCRAMBLE_RESET;
3912 break;
3913 default:
3914 return -EINVAL;
3915 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003916 I915_WRITE(PORT_DFT2_G4X, tmp);
3917 }
3918
Daniel Vetter7ac01292013-10-18 16:37:06 +02003919 return 0;
3920}
3921
David Weinehall36cdd012016-08-22 13:59:31 +03003922static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003923 enum pipe pipe,
3924 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003925 uint32_t *val)
3926{
Daniel Vetter84093602013-11-01 10:50:21 +01003927 bool need_stable_symbols = false;
3928
Daniel Vetter46a19182013-11-01 10:50:20 +01003929 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003930 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003931 if (ret)
3932 return ret;
3933 }
3934
3935 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003936 case INTEL_PIPE_CRC_SOURCE_PIPE:
3937 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3938 break;
3939 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003940 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003941 return -EINVAL;
3942 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3943 break;
3944 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003945 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003946 return -EINVAL;
3947 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003948 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003949 break;
3950 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003951 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003952 return -EINVAL;
3953 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003954 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003955 break;
3956 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003957 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003958 return -EINVAL;
3959 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003960 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003961 break;
3962 case INTEL_PIPE_CRC_SOURCE_NONE:
3963 *val = 0;
3964 break;
3965 default:
3966 return -EINVAL;
3967 }
3968
Daniel Vetter84093602013-11-01 10:50:21 +01003969 /*
3970 * When the pipe CRC tap point is after the transcoders we need
3971 * to tweak symbol-level features to produce a deterministic series of
3972 * symbols for a given frame. We need to reset those features only once
3973 * a frame (instead of every nth symbol):
3974 * - DC-balance: used to ensure a better clock recovery from the data
3975 * link (SDVO)
3976 * - DisplayPort scrambling: used for EMI reduction
3977 */
3978 if (need_stable_symbols) {
3979 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3980
David Weinehall36cdd012016-08-22 13:59:31 +03003981 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003982
3983 I915_WRITE(PORT_DFT_I9XX,
3984 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3985
3986 if (pipe == PIPE_A)
3987 tmp |= PIPE_A_SCRAMBLE_RESET;
3988 else
3989 tmp |= PIPE_B_SCRAMBLE_RESET;
3990
3991 I915_WRITE(PORT_DFT2_G4X, tmp);
3992 }
3993
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003994 return 0;
3995}
3996
David Weinehall36cdd012016-08-22 13:59:31 +03003997static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003998 enum pipe pipe)
3999{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004000 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4001
Ville Syrjäläeb736672014-12-09 21:28:28 +02004002 switch (pipe) {
4003 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004004 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004005 break;
4006 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004007 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004008 break;
4009 case PIPE_C:
4010 tmp &= ~PIPE_C_SCRAMBLE_RESET;
4011 break;
4012 default:
4013 return;
4014 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004015 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
4016 tmp &= ~DC_BALANCE_RESET_VLV;
4017 I915_WRITE(PORT_DFT2_G4X, tmp);
4018
4019}
4020
David Weinehall36cdd012016-08-22 13:59:31 +03004021static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01004022 enum pipe pipe)
4023{
Daniel Vetter84093602013-11-01 10:50:21 +01004024 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4025
4026 if (pipe == PIPE_A)
4027 tmp &= ~PIPE_A_SCRAMBLE_RESET;
4028 else
4029 tmp &= ~PIPE_B_SCRAMBLE_RESET;
4030 I915_WRITE(PORT_DFT2_G4X, tmp);
4031
4032 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
4033 I915_WRITE(PORT_DFT_I9XX,
4034 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
4035 }
4036}
4037
Daniel Vetter46a19182013-11-01 10:50:20 +01004038static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004039 uint32_t *val)
4040{
Daniel Vetter46a19182013-11-01 10:50:20 +01004041 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4042 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4043
4044 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004045 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4046 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4047 break;
4048 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4049 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4050 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004051 case INTEL_PIPE_CRC_SOURCE_PIPE:
4052 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4053 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004054 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004055 *val = 0;
4056 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004057 default:
4058 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004059 }
4060
4061 return 0;
4062}
4063
David Weinehall36cdd012016-08-22 13:59:31 +03004064static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4065 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004066{
David Weinehall36cdd012016-08-22 13:59:31 +03004067 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004068 struct intel_crtc *crtc =
4069 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004070 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004071 struct drm_atomic_state *state;
4072 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004073
4074 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004075 state = drm_atomic_state_alloc(dev);
4076 if (!state) {
4077 ret = -ENOMEM;
4078 goto out;
4079 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004080
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004081 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4082 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4083 if (IS_ERR(pipe_config)) {
4084 ret = PTR_ERR(pipe_config);
4085 goto out;
4086 }
4087
4088 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004089 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004090 pipe_config->pch_pfit.enabled != enable)
4091 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004092
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004093 ret = drm_atomic_commit(state);
4094out:
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004095 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
Chris Wilson08536952016-10-14 13:18:18 +01004096 drm_modeset_unlock_all(dev);
4097 drm_atomic_state_put(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004098}
4099
David Weinehall36cdd012016-08-22 13:59:31 +03004100static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004101 enum pipe pipe,
4102 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004103 uint32_t *val)
4104{
Daniel Vetter46a19182013-11-01 10:50:20 +01004105 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4106 *source = INTEL_PIPE_CRC_SOURCE_PF;
4107
4108 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004109 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4110 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4111 break;
4112 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4113 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4114 break;
4115 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004116 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4117 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004118
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004119 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4120 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004121 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004122 *val = 0;
4123 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004124 default:
4125 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004126 }
4127
4128 return 0;
4129}
4130
David Weinehall36cdd012016-08-22 13:59:31 +03004131static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4132 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004133 enum intel_pipe_crc_source source)
4134{
David Weinehall36cdd012016-08-22 13:59:31 +03004135 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004136 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03004137 struct intel_crtc *crtc =
4138 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02004139 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004140 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004141 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004142
Damien Lespiaucc3da172013-10-15 18:55:31 +01004143 if (pipe_crc->source == source)
4144 return 0;
4145
Damien Lespiauae676fc2013-10-15 18:55:32 +01004146 /* forbid changing the source without going back to 'none' */
4147 if (pipe_crc->source && source)
4148 return -EINVAL;
4149
Imre Deake1296492016-02-12 18:55:17 +02004150 power_domain = POWER_DOMAIN_PIPE(pipe);
4151 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004152 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4153 return -EIO;
4154 }
4155
David Weinehall36cdd012016-08-22 13:59:31 +03004156 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004157 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004158 else if (INTEL_GEN(dev_priv) < 5)
4159 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4160 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4161 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4162 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004163 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004164 else
David Weinehall36cdd012016-08-22 13:59:31 +03004165 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004166
4167 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004168 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004169
Damien Lespiau4b584362013-10-15 18:55:33 +01004170 /* none -> real source transition */
4171 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004172 struct intel_pipe_crc_entry *entries;
4173
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004174 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4175 pipe_name(pipe), pipe_crc_source_name(source));
4176
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004177 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4178 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004179 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004180 if (!entries) {
4181 ret = -ENOMEM;
4182 goto out;
4183 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004184
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004185 /*
4186 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4187 * enabled and disabled dynamically based on package C states,
4188 * user space can't make reliable use of the CRCs, so let's just
4189 * completely disable it.
4190 */
4191 hsw_disable_ips(crtc);
4192
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004193 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004194 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004195 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004196 pipe_crc->head = 0;
4197 pipe_crc->tail = 0;
4198 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004199 }
4200
Damien Lespiaucc3da172013-10-15 18:55:31 +01004201 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004202
Daniel Vetter926321d2013-10-16 13:30:34 +02004203 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4204 POSTING_READ(PIPE_CRC_CTL(pipe));
4205
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004206 /* real source -> none transition */
4207 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004208 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004209 struct intel_crtc *crtc =
4210 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004211
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004212 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4213 pipe_name(pipe));
4214
Daniel Vettera33d7102014-06-06 08:22:08 +02004215 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004216 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004217 intel_wait_for_vblank(dev, pipe);
4218 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004219
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004220 spin_lock_irq(&pipe_crc->lock);
4221 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004222 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004223 pipe_crc->head = 0;
4224 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004225 spin_unlock_irq(&pipe_crc->lock);
4226
4227 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004228
David Weinehall36cdd012016-08-22 13:59:31 +03004229 if (IS_G4X(dev_priv))
4230 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4231 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4232 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4233 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4234 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004235
4236 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004237 }
4238
Imre Deake1296492016-02-12 18:55:17 +02004239 ret = 0;
4240
4241out:
4242 intel_display_power_put(dev_priv, power_domain);
4243
4244 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004245}
4246
4247/*
4248 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004249 * command: wsp* object wsp+ name wsp+ source wsp*
4250 * object: 'pipe'
4251 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004252 * source: (none | plane1 | plane2 | pf)
4253 * wsp: (#0x20 | #0x9 | #0xA)+
4254 *
4255 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004256 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4257 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004258 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004259static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004260{
4261 int n_words = 0;
4262
4263 while (*buf) {
4264 char *end;
4265
4266 /* skip leading white space */
4267 buf = skip_spaces(buf);
4268 if (!*buf)
4269 break; /* end of buffer */
4270
4271 /* find end of word */
4272 for (end = buf; *end && !isspace(*end); end++)
4273 ;
4274
4275 if (n_words == max_words) {
4276 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4277 max_words);
4278 return -EINVAL; /* ran out of words[] before bytes */
4279 }
4280
4281 if (*end)
4282 *end++ = '\0';
4283 words[n_words++] = buf;
4284 buf = end;
4285 }
4286
4287 return n_words;
4288}
4289
Damien Lespiaub94dec82013-10-15 18:55:35 +01004290enum intel_pipe_crc_object {
4291 PIPE_CRC_OBJECT_PIPE,
4292};
4293
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004294static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004295 "pipe",
4296};
4297
4298static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004299display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004300{
4301 int i;
4302
4303 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4304 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004305 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004306 return 0;
4307 }
4308
4309 return -EINVAL;
4310}
4311
Damien Lespiaubd9db022013-10-15 18:55:36 +01004312static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004313{
4314 const char name = buf[0];
4315
4316 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4317 return -EINVAL;
4318
4319 *pipe = name - 'A';
4320
4321 return 0;
4322}
4323
4324static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004325display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004326{
4327 int i;
4328
4329 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4330 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004331 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004332 return 0;
4333 }
4334
4335 return -EINVAL;
4336}
4337
David Weinehall36cdd012016-08-22 13:59:31 +03004338static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4339 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004340{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004341#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004342 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004343 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004344 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004345 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004346 enum intel_pipe_crc_source source;
4347
Damien Lespiaubd9db022013-10-15 18:55:36 +01004348 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004349 if (n_words != N_WORDS) {
4350 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4351 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004352 return -EINVAL;
4353 }
4354
Damien Lespiaubd9db022013-10-15 18:55:36 +01004355 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004356 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004357 return -EINVAL;
4358 }
4359
Damien Lespiaubd9db022013-10-15 18:55:36 +01004360 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004361 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4362 return -EINVAL;
4363 }
4364
Damien Lespiaubd9db022013-10-15 18:55:36 +01004365 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004366 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004367 return -EINVAL;
4368 }
4369
David Weinehall36cdd012016-08-22 13:59:31 +03004370 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004371}
4372
Damien Lespiaubd9db022013-10-15 18:55:36 +01004373static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4374 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004375{
4376 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004377 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004378 char *tmpbuf;
4379 int ret;
4380
4381 if (len == 0)
4382 return 0;
4383
4384 if (len > PAGE_SIZE - 1) {
4385 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4386 PAGE_SIZE);
4387 return -E2BIG;
4388 }
4389
4390 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4391 if (!tmpbuf)
4392 return -ENOMEM;
4393
4394 if (copy_from_user(tmpbuf, ubuf, len)) {
4395 ret = -EFAULT;
4396 goto out;
4397 }
4398 tmpbuf[len] = '\0';
4399
David Weinehall36cdd012016-08-22 13:59:31 +03004400 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004401
4402out:
4403 kfree(tmpbuf);
4404 if (ret < 0)
4405 return ret;
4406
4407 *offp += len;
4408 return len;
4409}
4410
Damien Lespiaubd9db022013-10-15 18:55:36 +01004411static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004412 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004413 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004414 .read = seq_read,
4415 .llseek = seq_lseek,
4416 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004417 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004418};
4419
Todd Previteeb3394fa2015-04-18 00:04:19 -07004420static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004421 const char __user *ubuf,
4422 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004423{
4424 char *input_buffer;
4425 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004426 struct drm_device *dev;
4427 struct drm_connector *connector;
4428 struct list_head *connector_list;
4429 struct intel_dp *intel_dp;
4430 int val = 0;
4431
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304432 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004433
Todd Previteeb3394fa2015-04-18 00:04:19 -07004434 connector_list = &dev->mode_config.connector_list;
4435
4436 if (len == 0)
4437 return 0;
4438
4439 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4440 if (!input_buffer)
4441 return -ENOMEM;
4442
4443 if (copy_from_user(input_buffer, ubuf, len)) {
4444 status = -EFAULT;
4445 goto out;
4446 }
4447
4448 input_buffer[len] = '\0';
4449 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4450
4451 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004452 if (connector->connector_type !=
4453 DRM_MODE_CONNECTOR_DisplayPort)
4454 continue;
4455
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304456 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004457 connector->encoder != NULL) {
4458 intel_dp = enc_to_intel_dp(connector->encoder);
4459 status = kstrtoint(input_buffer, 10, &val);
4460 if (status < 0)
4461 goto out;
4462 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4463 /* To prevent erroneous activation of the compliance
4464 * testing code, only accept an actual value of 1 here
4465 */
4466 if (val == 1)
4467 intel_dp->compliance_test_active = 1;
4468 else
4469 intel_dp->compliance_test_active = 0;
4470 }
4471 }
4472out:
4473 kfree(input_buffer);
4474 if (status < 0)
4475 return status;
4476
4477 *offp += len;
4478 return len;
4479}
4480
4481static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4482{
4483 struct drm_device *dev = m->private;
4484 struct drm_connector *connector;
4485 struct list_head *connector_list = &dev->mode_config.connector_list;
4486 struct intel_dp *intel_dp;
4487
Todd Previteeb3394fa2015-04-18 00:04:19 -07004488 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004489 if (connector->connector_type !=
4490 DRM_MODE_CONNECTOR_DisplayPort)
4491 continue;
4492
4493 if (connector->status == connector_status_connected &&
4494 connector->encoder != NULL) {
4495 intel_dp = enc_to_intel_dp(connector->encoder);
4496 if (intel_dp->compliance_test_active)
4497 seq_puts(m, "1");
4498 else
4499 seq_puts(m, "0");
4500 } else
4501 seq_puts(m, "0");
4502 }
4503
4504 return 0;
4505}
4506
4507static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004508 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004509{
David Weinehall36cdd012016-08-22 13:59:31 +03004510 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004511
David Weinehall36cdd012016-08-22 13:59:31 +03004512 return single_open(file, i915_displayport_test_active_show,
4513 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004514}
4515
4516static const struct file_operations i915_displayport_test_active_fops = {
4517 .owner = THIS_MODULE,
4518 .open = i915_displayport_test_active_open,
4519 .read = seq_read,
4520 .llseek = seq_lseek,
4521 .release = single_release,
4522 .write = i915_displayport_test_active_write
4523};
4524
4525static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4526{
4527 struct drm_device *dev = m->private;
4528 struct drm_connector *connector;
4529 struct list_head *connector_list = &dev->mode_config.connector_list;
4530 struct intel_dp *intel_dp;
4531
Todd Previteeb3394fa2015-04-18 00:04:19 -07004532 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004533 if (connector->connector_type !=
4534 DRM_MODE_CONNECTOR_DisplayPort)
4535 continue;
4536
4537 if (connector->status == connector_status_connected &&
4538 connector->encoder != NULL) {
4539 intel_dp = enc_to_intel_dp(connector->encoder);
4540 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4541 } else
4542 seq_puts(m, "0");
4543 }
4544
4545 return 0;
4546}
4547static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004548 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004549{
David Weinehall36cdd012016-08-22 13:59:31 +03004550 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004551
David Weinehall36cdd012016-08-22 13:59:31 +03004552 return single_open(file, i915_displayport_test_data_show,
4553 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004554}
4555
4556static const struct file_operations i915_displayport_test_data_fops = {
4557 .owner = THIS_MODULE,
4558 .open = i915_displayport_test_data_open,
4559 .read = seq_read,
4560 .llseek = seq_lseek,
4561 .release = single_release
4562};
4563
4564static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4565{
4566 struct drm_device *dev = m->private;
4567 struct drm_connector *connector;
4568 struct list_head *connector_list = &dev->mode_config.connector_list;
4569 struct intel_dp *intel_dp;
4570
Todd Previteeb3394fa2015-04-18 00:04:19 -07004571 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004572 if (connector->connector_type !=
4573 DRM_MODE_CONNECTOR_DisplayPort)
4574 continue;
4575
4576 if (connector->status == connector_status_connected &&
4577 connector->encoder != NULL) {
4578 intel_dp = enc_to_intel_dp(connector->encoder);
4579 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4580 } else
4581 seq_puts(m, "0");
4582 }
4583
4584 return 0;
4585}
4586
4587static int i915_displayport_test_type_open(struct inode *inode,
4588 struct file *file)
4589{
David Weinehall36cdd012016-08-22 13:59:31 +03004590 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004591
David Weinehall36cdd012016-08-22 13:59:31 +03004592 return single_open(file, i915_displayport_test_type_show,
4593 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004594}
4595
4596static const struct file_operations i915_displayport_test_type_fops = {
4597 .owner = THIS_MODULE,
4598 .open = i915_displayport_test_type_open,
4599 .read = seq_read,
4600 .llseek = seq_lseek,
4601 .release = single_release
4602};
4603
Damien Lespiau97e94b22014-11-04 17:06:50 +00004604static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004605{
David Weinehall36cdd012016-08-22 13:59:31 +03004606 struct drm_i915_private *dev_priv = m->private;
4607 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004608 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004609 int num_levels;
4610
David Weinehall36cdd012016-08-22 13:59:31 +03004611 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004612 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004613 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004614 num_levels = 1;
4615 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004616 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004617
4618 drm_modeset_lock_all(dev);
4619
4620 for (level = 0; level < num_levels; level++) {
4621 unsigned int latency = wm[level];
4622
Damien Lespiau97e94b22014-11-04 17:06:50 +00004623 /*
4624 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004625 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004626 */
David Weinehall36cdd012016-08-22 13:59:31 +03004627 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4628 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004629 latency *= 10;
4630 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004631 latency *= 5;
4632
4633 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004634 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004635 }
4636
4637 drm_modeset_unlock_all(dev);
4638}
4639
4640static int pri_wm_latency_show(struct seq_file *m, void *data)
4641{
David Weinehall36cdd012016-08-22 13:59:31 +03004642 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004643 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004644
David Weinehall36cdd012016-08-22 13:59:31 +03004645 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004646 latencies = dev_priv->wm.skl_latency;
4647 else
David Weinehall36cdd012016-08-22 13:59:31 +03004648 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004649
4650 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004651
4652 return 0;
4653}
4654
4655static int spr_wm_latency_show(struct seq_file *m, void *data)
4656{
David Weinehall36cdd012016-08-22 13:59:31 +03004657 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004658 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004659
David Weinehall36cdd012016-08-22 13:59:31 +03004660 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004661 latencies = dev_priv->wm.skl_latency;
4662 else
David Weinehall36cdd012016-08-22 13:59:31 +03004663 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004664
4665 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004666
4667 return 0;
4668}
4669
4670static int cur_wm_latency_show(struct seq_file *m, void *data)
4671{
David Weinehall36cdd012016-08-22 13:59:31 +03004672 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004673 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004674
David Weinehall36cdd012016-08-22 13:59:31 +03004675 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004676 latencies = dev_priv->wm.skl_latency;
4677 else
David Weinehall36cdd012016-08-22 13:59:31 +03004678 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004679
4680 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004681
4682 return 0;
4683}
4684
4685static int pri_wm_latency_open(struct inode *inode, struct file *file)
4686{
David Weinehall36cdd012016-08-22 13:59:31 +03004687 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004688
David Weinehall36cdd012016-08-22 13:59:31 +03004689 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004690 return -ENODEV;
4691
David Weinehall36cdd012016-08-22 13:59:31 +03004692 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004693}
4694
4695static int spr_wm_latency_open(struct inode *inode, struct file *file)
4696{
David Weinehall36cdd012016-08-22 13:59:31 +03004697 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004698
David Weinehall36cdd012016-08-22 13:59:31 +03004699 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004700 return -ENODEV;
4701
David Weinehall36cdd012016-08-22 13:59:31 +03004702 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004703}
4704
4705static int cur_wm_latency_open(struct inode *inode, struct file *file)
4706{
David Weinehall36cdd012016-08-22 13:59:31 +03004707 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004708
David Weinehall36cdd012016-08-22 13:59:31 +03004709 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004710 return -ENODEV;
4711
David Weinehall36cdd012016-08-22 13:59:31 +03004712 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004713}
4714
4715static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004716 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004717{
4718 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004719 struct drm_i915_private *dev_priv = m->private;
4720 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004721 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004722 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004723 int level;
4724 int ret;
4725 char tmp[32];
4726
David Weinehall36cdd012016-08-22 13:59:31 +03004727 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004728 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004729 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004730 num_levels = 1;
4731 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004732 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004733
Ville Syrjälä369a1342014-01-22 14:36:08 +02004734 if (len >= sizeof(tmp))
4735 return -EINVAL;
4736
4737 if (copy_from_user(tmp, ubuf, len))
4738 return -EFAULT;
4739
4740 tmp[len] = '\0';
4741
Damien Lespiau97e94b22014-11-04 17:06:50 +00004742 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4743 &new[0], &new[1], &new[2], &new[3],
4744 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004745 if (ret != num_levels)
4746 return -EINVAL;
4747
4748 drm_modeset_lock_all(dev);
4749
4750 for (level = 0; level < num_levels; level++)
4751 wm[level] = new[level];
4752
4753 drm_modeset_unlock_all(dev);
4754
4755 return len;
4756}
4757
4758
4759static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4760 size_t len, loff_t *offp)
4761{
4762 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004763 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004764 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004765
David Weinehall36cdd012016-08-22 13:59:31 +03004766 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004767 latencies = dev_priv->wm.skl_latency;
4768 else
David Weinehall36cdd012016-08-22 13:59:31 +03004769 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004770
4771 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004772}
4773
4774static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4775 size_t len, loff_t *offp)
4776{
4777 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004778 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004779 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004780
David Weinehall36cdd012016-08-22 13:59:31 +03004781 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004782 latencies = dev_priv->wm.skl_latency;
4783 else
David Weinehall36cdd012016-08-22 13:59:31 +03004784 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004785
4786 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004787}
4788
4789static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4790 size_t len, loff_t *offp)
4791{
4792 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004793 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004794 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004795
David Weinehall36cdd012016-08-22 13:59:31 +03004796 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004797 latencies = dev_priv->wm.skl_latency;
4798 else
David Weinehall36cdd012016-08-22 13:59:31 +03004799 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004800
4801 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004802}
4803
4804static const struct file_operations i915_pri_wm_latency_fops = {
4805 .owner = THIS_MODULE,
4806 .open = pri_wm_latency_open,
4807 .read = seq_read,
4808 .llseek = seq_lseek,
4809 .release = single_release,
4810 .write = pri_wm_latency_write
4811};
4812
4813static const struct file_operations i915_spr_wm_latency_fops = {
4814 .owner = THIS_MODULE,
4815 .open = spr_wm_latency_open,
4816 .read = seq_read,
4817 .llseek = seq_lseek,
4818 .release = single_release,
4819 .write = spr_wm_latency_write
4820};
4821
4822static const struct file_operations i915_cur_wm_latency_fops = {
4823 .owner = THIS_MODULE,
4824 .open = cur_wm_latency_open,
4825 .read = seq_read,
4826 .llseek = seq_lseek,
4827 .release = single_release,
4828 .write = cur_wm_latency_write
4829};
4830
Kees Cook647416f2013-03-10 14:10:06 -07004831static int
4832i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004833{
David Weinehall36cdd012016-08-22 13:59:31 +03004834 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004835
Chris Wilsond98c52c2016-04-13 17:35:05 +01004836 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004837
Kees Cook647416f2013-03-10 14:10:06 -07004838 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004839}
4840
Kees Cook647416f2013-03-10 14:10:06 -07004841static int
4842i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004843{
David Weinehall36cdd012016-08-22 13:59:31 +03004844 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004845
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004846 /*
4847 * There is no safeguard against this debugfs entry colliding
4848 * with the hangcheck calling same i915_handle_error() in
4849 * parallel, causing an explosion. For now we assume that the
4850 * test harness is responsible enough not to inject gpu hangs
4851 * while it is writing to 'i915_wedged'
4852 */
4853
Chris Wilsond98c52c2016-04-13 17:35:05 +01004854 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004855 return -EAGAIN;
4856
Chris Wilsonc0336662016-05-06 15:40:21 +01004857 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004858 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004859
Kees Cook647416f2013-03-10 14:10:06 -07004860 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004861}
4862
Kees Cook647416f2013-03-10 14:10:06 -07004863DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4864 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004865 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004866
Kees Cook647416f2013-03-10 14:10:06 -07004867static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004868i915_ring_missed_irq_get(void *data, u64 *val)
4869{
David Weinehall36cdd012016-08-22 13:59:31 +03004870 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004871
4872 *val = dev_priv->gpu_error.missed_irq_rings;
4873 return 0;
4874}
4875
4876static int
4877i915_ring_missed_irq_set(void *data, u64 val)
4878{
David Weinehall36cdd012016-08-22 13:59:31 +03004879 struct drm_i915_private *dev_priv = data;
4880 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004881 int ret;
4882
4883 /* Lock against concurrent debugfs callers */
4884 ret = mutex_lock_interruptible(&dev->struct_mutex);
4885 if (ret)
4886 return ret;
4887 dev_priv->gpu_error.missed_irq_rings = val;
4888 mutex_unlock(&dev->struct_mutex);
4889
4890 return 0;
4891}
4892
4893DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4894 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4895 "0x%08llx\n");
4896
4897static int
4898i915_ring_test_irq_get(void *data, u64 *val)
4899{
David Weinehall36cdd012016-08-22 13:59:31 +03004900 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004901
4902 *val = dev_priv->gpu_error.test_irq_rings;
4903
4904 return 0;
4905}
4906
4907static int
4908i915_ring_test_irq_set(void *data, u64 val)
4909{
David Weinehall36cdd012016-08-22 13:59:31 +03004910 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004911
Chris Wilson3a122c22016-06-17 14:35:05 +01004912 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004913 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004914 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004915
4916 return 0;
4917}
4918
4919DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4920 i915_ring_test_irq_get, i915_ring_test_irq_set,
4921 "0x%08llx\n");
4922
Chris Wilsondd624af2013-01-15 12:39:35 +00004923#define DROP_UNBOUND 0x1
4924#define DROP_BOUND 0x2
4925#define DROP_RETIRE 0x4
4926#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004927#define DROP_FREED 0x10
4928#define DROP_ALL (DROP_UNBOUND | \
4929 DROP_BOUND | \
4930 DROP_RETIRE | \
4931 DROP_ACTIVE | \
4932 DROP_FREED)
Kees Cook647416f2013-03-10 14:10:06 -07004933static int
4934i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004935{
Kees Cook647416f2013-03-10 14:10:06 -07004936 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004937
Kees Cook647416f2013-03-10 14:10:06 -07004938 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004939}
4940
Kees Cook647416f2013-03-10 14:10:06 -07004941static int
4942i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004943{
David Weinehall36cdd012016-08-22 13:59:31 +03004944 struct drm_i915_private *dev_priv = data;
4945 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004946 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004947
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004948 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004949
4950 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4951 * on ioctls on -EAGAIN. */
4952 ret = mutex_lock_interruptible(&dev->struct_mutex);
4953 if (ret)
4954 return ret;
4955
4956 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004957 ret = i915_gem_wait_for_idle(dev_priv,
4958 I915_WAIT_INTERRUPTIBLE |
4959 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004960 if (ret)
4961 goto unlock;
4962 }
4963
4964 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004965 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004966
Chris Wilson21ab4e72014-09-09 11:16:08 +01004967 if (val & DROP_BOUND)
4968 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004969
Chris Wilson21ab4e72014-09-09 11:16:08 +01004970 if (val & DROP_UNBOUND)
4971 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004972
4973unlock:
4974 mutex_unlock(&dev->struct_mutex);
4975
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004976 if (val & DROP_FREED) {
4977 synchronize_rcu();
4978 flush_work(&dev_priv->mm.free_work);
4979 }
4980
Kees Cook647416f2013-03-10 14:10:06 -07004981 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004982}
4983
Kees Cook647416f2013-03-10 14:10:06 -07004984DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4985 i915_drop_caches_get, i915_drop_caches_set,
4986 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004987
Kees Cook647416f2013-03-10 14:10:06 -07004988static int
4989i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004990{
David Weinehall36cdd012016-08-22 13:59:31 +03004991 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004992
David Weinehall36cdd012016-08-22 13:59:31 +03004993 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004994 return -ENODEV;
4995
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004996 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004997 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004998}
4999
Kees Cook647416f2013-03-10 14:10:06 -07005000static int
5001i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005002{
David Weinehall36cdd012016-08-22 13:59:31 +03005003 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305004 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005005 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005006
David Weinehall36cdd012016-08-22 13:59:31 +03005007 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005008 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005009
Kees Cook647416f2013-03-10 14:10:06 -07005010 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005011
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005012 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005013 if (ret)
5014 return ret;
5015
Jesse Barnes358733e2011-07-27 11:53:01 -07005016 /*
5017 * Turbo will still be enabled, but won't go above the set value.
5018 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305019 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005020
Akash Goelbc4d91f2015-02-26 16:09:47 +05305021 hw_max = dev_priv->rps.max_freq;
5022 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005023
Ben Widawskyb39fb292014-03-19 18:31:11 -07005024 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005025 mutex_unlock(&dev_priv->rps.hw_lock);
5026 return -EINVAL;
5027 }
5028
Ben Widawskyb39fb292014-03-19 18:31:11 -07005029 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005030
Chris Wilsondc979972016-05-10 14:10:04 +01005031 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005032
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005033 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005034
Kees Cook647416f2013-03-10 14:10:06 -07005035 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005036}
5037
Kees Cook647416f2013-03-10 14:10:06 -07005038DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5039 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005040 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005041
Kees Cook647416f2013-03-10 14:10:06 -07005042static int
5043i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005044{
David Weinehall36cdd012016-08-22 13:59:31 +03005045 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005046
Chris Wilson62e1baa2016-07-13 09:10:36 +01005047 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005048 return -ENODEV;
5049
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005050 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005051 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005052}
5053
Kees Cook647416f2013-03-10 14:10:06 -07005054static int
5055i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005056{
David Weinehall36cdd012016-08-22 13:59:31 +03005057 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305058 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005059 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005060
Chris Wilson62e1baa2016-07-13 09:10:36 +01005061 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005062 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005063
Kees Cook647416f2013-03-10 14:10:06 -07005064 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005065
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005066 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005067 if (ret)
5068 return ret;
5069
Jesse Barnes1523c312012-05-25 12:34:54 -07005070 /*
5071 * Turbo will still be enabled, but won't go below the set value.
5072 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305073 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005074
Akash Goelbc4d91f2015-02-26 16:09:47 +05305075 hw_max = dev_priv->rps.max_freq;
5076 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005077
David Weinehall36cdd012016-08-22 13:59:31 +03005078 if (val < hw_min ||
5079 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005080 mutex_unlock(&dev_priv->rps.hw_lock);
5081 return -EINVAL;
5082 }
5083
Ben Widawskyb39fb292014-03-19 18:31:11 -07005084 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005085
Chris Wilsondc979972016-05-10 14:10:04 +01005086 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005087
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005088 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005089
Kees Cook647416f2013-03-10 14:10:06 -07005090 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005091}
5092
Kees Cook647416f2013-03-10 14:10:06 -07005093DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5094 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005095 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005096
Kees Cook647416f2013-03-10 14:10:06 -07005097static int
5098i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005099{
David Weinehall36cdd012016-08-22 13:59:31 +03005100 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005101 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005102
David Weinehall36cdd012016-08-22 13:59:31 +03005103 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005104 return -ENODEV;
5105
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005106 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005107
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005108 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005109
5110 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005111
Kees Cook647416f2013-03-10 14:10:06 -07005112 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005113
Kees Cook647416f2013-03-10 14:10:06 -07005114 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005115}
5116
Kees Cook647416f2013-03-10 14:10:06 -07005117static int
5118i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005119{
David Weinehall36cdd012016-08-22 13:59:31 +03005120 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005121 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005122
David Weinehall36cdd012016-08-22 13:59:31 +03005123 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005124 return -ENODEV;
5125
Kees Cook647416f2013-03-10 14:10:06 -07005126 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005127 return -EINVAL;
5128
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005129 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005130 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005131
5132 /* Update the cache sharing policy here as well */
5133 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5134 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5135 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5136 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5137
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005138 intel_runtime_pm_put(dev_priv);
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 -07005142DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5143 i915_cache_sharing_get, i915_cache_sharing_set,
5144 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005145
David Weinehall36cdd012016-08-22 13:59:31 +03005146static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005147 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005148{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005149 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005150 int ss;
5151 u32 sig1[ss_max], sig2[ss_max];
5152
5153 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5154 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5155 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5156 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5157
5158 for (ss = 0; ss < ss_max; ss++) {
5159 unsigned int eu_cnt;
5160
5161 if (sig1[ss] & CHV_SS_PG_ENABLE)
5162 /* skip disabled subslice */
5163 continue;
5164
Imre Deakf08a0c92016-08-31 19:13:04 +03005165 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005166 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005167 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5168 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5169 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5170 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005171 sseu->eu_total += eu_cnt;
5172 sseu->eu_per_subslice = max_t(unsigned int,
5173 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005174 }
Jeff McGee5d395252015-04-03 18:13:17 -07005175}
5176
David Weinehall36cdd012016-08-22 13:59:31 +03005177static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005178 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005179{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005180 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005181 int s, ss;
5182 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5183
Jeff McGee1c046bc2015-04-03 18:13:18 -07005184 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005185 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005186 s_max = 1;
5187 ss_max = 3;
5188 }
5189
5190 for (s = 0; s < s_max; s++) {
5191 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5192 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5193 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5194 }
5195
Jeff McGee5d395252015-04-03 18:13:17 -07005196 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5197 GEN9_PGCTL_SSA_EU19_ACK |
5198 GEN9_PGCTL_SSA_EU210_ACK |
5199 GEN9_PGCTL_SSA_EU311_ACK;
5200 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5201 GEN9_PGCTL_SSB_EU19_ACK |
5202 GEN9_PGCTL_SSB_EU210_ACK |
5203 GEN9_PGCTL_SSB_EU311_ACK;
5204
5205 for (s = 0; s < s_max; s++) {
5206 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5207 /* skip disabled slice */
5208 continue;
5209
Imre Deakf08a0c92016-08-31 19:13:04 +03005210 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005211
David Weinehall36cdd012016-08-22 13:59:31 +03005212 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005213 sseu->subslice_mask =
5214 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005215
Jeff McGee5d395252015-04-03 18:13:17 -07005216 for (ss = 0; ss < ss_max; ss++) {
5217 unsigned int eu_cnt;
5218
Imre Deak57ec1712016-08-31 19:13:05 +03005219 if (IS_BROXTON(dev_priv)) {
5220 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5221 /* skip disabled subslice */
5222 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005223
Imre Deak57ec1712016-08-31 19:13:05 +03005224 sseu->subslice_mask |= BIT(ss);
5225 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005226
Jeff McGee5d395252015-04-03 18:13:17 -07005227 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5228 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005229 sseu->eu_total += eu_cnt;
5230 sseu->eu_per_subslice = max_t(unsigned int,
5231 sseu->eu_per_subslice,
5232 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005233 }
5234 }
5235}
5236
David Weinehall36cdd012016-08-22 13:59:31 +03005237static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005238 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005239{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005240 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005241 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005242
Imre Deakf08a0c92016-08-31 19:13:04 +03005243 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005244
Imre Deakf08a0c92016-08-31 19:13:04 +03005245 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005246 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005247 sseu->eu_per_subslice =
5248 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005249 sseu->eu_total = sseu->eu_per_subslice *
5250 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005251
5252 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005253 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005254 u8 subslice_7eu =
5255 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005256
Imre Deak915490d2016-08-31 19:13:01 +03005257 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005258 }
5259 }
5260}
5261
Imre Deak615d8902016-08-31 19:13:03 +03005262static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5263 const struct sseu_dev_info *sseu)
5264{
5265 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5266 const char *type = is_available_info ? "Available" : "Enabled";
5267
Imre Deakc67ba532016-08-31 19:13:06 +03005268 seq_printf(m, " %s Slice Mask: %04x\n", type,
5269 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005270 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005271 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005272 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005273 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005274 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5275 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005276 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005277 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005278 seq_printf(m, " %s EU Total: %u\n", type,
5279 sseu->eu_total);
5280 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5281 sseu->eu_per_subslice);
5282
5283 if (!is_available_info)
5284 return;
5285
5286 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5287 if (HAS_POOLED_EU(dev_priv))
5288 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5289
5290 seq_printf(m, " Has Slice Power Gating: %s\n",
5291 yesno(sseu->has_slice_pg));
5292 seq_printf(m, " Has Subslice Power Gating: %s\n",
5293 yesno(sseu->has_subslice_pg));
5294 seq_printf(m, " Has EU Power Gating: %s\n",
5295 yesno(sseu->has_eu_pg));
5296}
5297
Jeff McGee38732182015-02-13 10:27:54 -06005298static int i915_sseu_status(struct seq_file *m, void *unused)
5299{
David Weinehall36cdd012016-08-22 13:59:31 +03005300 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005301 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005302
David Weinehall36cdd012016-08-22 13:59:31 +03005303 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005304 return -ENODEV;
5305
5306 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005307 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005308
Jeff McGee7f992ab2015-02-13 10:27:55 -06005309 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005310 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005311
5312 intel_runtime_pm_get(dev_priv);
5313
David Weinehall36cdd012016-08-22 13:59:31 +03005314 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005315 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005316 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005317 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005318 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005319 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005320 }
David Weinehall238010e2016-08-01 17:33:27 +03005321
5322 intel_runtime_pm_put(dev_priv);
5323
Imre Deak615d8902016-08-31 19:13:03 +03005324 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005325
Jeff McGee38732182015-02-13 10:27:54 -06005326 return 0;
5327}
5328
Ben Widawsky6d794d42011-04-25 11:25:56 -07005329static int i915_forcewake_open(struct inode *inode, struct file *file)
5330{
David Weinehall36cdd012016-08-22 13:59:31 +03005331 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005332
David Weinehall36cdd012016-08-22 13:59:31 +03005333 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005334 return 0;
5335
Chris Wilson6daccb02015-01-16 11:34:35 +02005336 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005337 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005338
5339 return 0;
5340}
5341
Ben Widawskyc43b5632012-04-16 14:07:40 -07005342static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005343{
David Weinehall36cdd012016-08-22 13:59:31 +03005344 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005345
David Weinehall36cdd012016-08-22 13:59:31 +03005346 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005347 return 0;
5348
Mika Kuoppala59bad942015-01-16 11:34:40 +02005349 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005350 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005351
5352 return 0;
5353}
5354
5355static const struct file_operations i915_forcewake_fops = {
5356 .owner = THIS_MODULE,
5357 .open = i915_forcewake_open,
5358 .release = i915_forcewake_release,
5359};
5360
5361static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5362{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005363 struct dentry *ent;
5364
5365 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005366 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005367 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005368 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005369 if (!ent)
5370 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005371
Ben Widawsky8eb57292011-05-11 15:10:58 -07005372 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005373}
5374
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005375static int i915_debugfs_create(struct dentry *root,
5376 struct drm_minor *minor,
5377 const char *name,
5378 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005379{
Jesse Barnes358733e2011-07-27 11:53:01 -07005380 struct dentry *ent;
5381
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005382 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005383 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005384 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005385 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005386 if (!ent)
5387 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005388
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005389 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005390}
5391
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005392static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005393 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005394 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005395 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005396 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005397 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005398 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005399 {"i915_gem_request", i915_gem_request_info, 0},
5400 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005401 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005402 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005403 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5404 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5405 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005406 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005407 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005408 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005409 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005410 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305411 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005412 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005413 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005414 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005415 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005416 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005417 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005418 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005419 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005420 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005421 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005422 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005423 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005424 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005425 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005426 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005427 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005428 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005429 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005430 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005431 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005432 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005433 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005434 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005435 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005436 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005437 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005438 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005439 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005440 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005441 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005442 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305443 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005444 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005445};
Ben Gamari27c202a2009-07-01 22:26:52 -04005446#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005447
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005448static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005449 const char *name;
5450 const struct file_operations *fops;
5451} i915_debugfs_files[] = {
5452 {"i915_wedged", &i915_wedged_fops},
5453 {"i915_max_freq", &i915_max_freq_fops},
5454 {"i915_min_freq", &i915_min_freq_fops},
5455 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005456 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5457 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005458 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005459#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005460 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005461#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005462 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005463 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005464 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5465 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5466 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005467 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005468 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5469 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05305470 {"i915_dp_test_active", &i915_displayport_test_active_fops},
5471 {"i915_guc_log_control", &i915_guc_log_control_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005472};
5473
David Weinehall36cdd012016-08-22 13:59:31 +03005474void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005475{
Daniel Vetterb3783602013-11-14 11:30:42 +01005476 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005477
Damien Lespiau055e3932014-08-18 13:49:10 +01005478 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005479 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005480
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005481 pipe_crc->opened = false;
5482 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005483 init_waitqueue_head(&pipe_crc->wq);
5484 }
5485}
5486
Chris Wilson1dac8912016-06-24 14:00:17 +01005487int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005488{
Chris Wilson91c8a322016-07-05 10:40:23 +01005489 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005490 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005491
Ben Widawsky6d794d42011-04-25 11:25:56 -07005492 ret = i915_forcewake_create(minor->debugfs_root, minor);
5493 if (ret)
5494 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005495
Damien Lespiau07144422013-10-15 18:55:40 +01005496 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5497 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5498 if (ret)
5499 return ret;
5500 }
5501
Daniel Vetter34b96742013-07-04 20:49:44 +02005502 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5503 ret = i915_debugfs_create(minor->debugfs_root, minor,
5504 i915_debugfs_files[i].name,
5505 i915_debugfs_files[i].fops);
5506 if (ret)
5507 return ret;
5508 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005509
Ben Gamari27c202a2009-07-01 22:26:52 -04005510 return drm_debugfs_create_files(i915_debugfs_list,
5511 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005512 minor->debugfs_root, minor);
5513}
5514
Chris Wilson1dac8912016-06-24 14:00:17 +01005515void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005516{
Chris Wilson91c8a322016-07-05 10:40:23 +01005517 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005518 int i;
5519
Ben Gamari27c202a2009-07-01 22:26:52 -04005520 drm_debugfs_remove_files(i915_debugfs_list,
5521 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005522
David Weinehall36cdd012016-08-22 13:59:31 +03005523 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005524 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005525
Daniel Vettere309a992013-10-16 22:55:51 +02005526 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005527 struct drm_info_list *info_list =
5528 (struct drm_info_list *)&i915_pipe_crc_data[i];
5529
5530 drm_debugfs_remove_files(info_list, 1, minor);
5531 }
5532
Daniel Vetter34b96742013-07-04 20:49:44 +02005533 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5534 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005535 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005536
5537 drm_debugfs_remove_files(info_list, 1, minor);
5538 }
Ben Gamari20172632009-02-17 20:08:50 -05005539}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005540
5541struct dpcd_block {
5542 /* DPCD dump start address. */
5543 unsigned int offset;
5544 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5545 unsigned int end;
5546 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5547 size_t size;
5548 /* Only valid for eDP. */
5549 bool edp;
5550};
5551
5552static const struct dpcd_block i915_dpcd_debug[] = {
5553 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5554 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5555 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5556 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5557 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5558 { .offset = DP_SET_POWER },
5559 { .offset = DP_EDP_DPCD_REV },
5560 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5561 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5562 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5563};
5564
5565static int i915_dpcd_show(struct seq_file *m, void *data)
5566{
5567 struct drm_connector *connector = m->private;
5568 struct intel_dp *intel_dp =
5569 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5570 uint8_t buf[16];
5571 ssize_t err;
5572 int i;
5573
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005574 if (connector->status != connector_status_connected)
5575 return -ENODEV;
5576
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005577 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5578 const struct dpcd_block *b = &i915_dpcd_debug[i];
5579 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5580
5581 if (b->edp &&
5582 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5583 continue;
5584
5585 /* low tech for now */
5586 if (WARN_ON(size > sizeof(buf)))
5587 continue;
5588
5589 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5590 if (err <= 0) {
5591 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5592 size, b->offset, err);
5593 continue;
5594 }
5595
5596 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005597 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005598
5599 return 0;
5600}
5601
5602static int i915_dpcd_open(struct inode *inode, struct file *file)
5603{
5604 return single_open(file, i915_dpcd_show, inode->i_private);
5605}
5606
5607static const struct file_operations i915_dpcd_fops = {
5608 .owner = THIS_MODULE,
5609 .open = i915_dpcd_open,
5610 .read = seq_read,
5611 .llseek = seq_lseek,
5612 .release = single_release,
5613};
5614
David Weinehallecbd6782016-08-23 12:23:56 +03005615static int i915_panel_show(struct seq_file *m, void *data)
5616{
5617 struct drm_connector *connector = m->private;
5618 struct intel_dp *intel_dp =
5619 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5620
5621 if (connector->status != connector_status_connected)
5622 return -ENODEV;
5623
5624 seq_printf(m, "Panel power up delay: %d\n",
5625 intel_dp->panel_power_up_delay);
5626 seq_printf(m, "Panel power down delay: %d\n",
5627 intel_dp->panel_power_down_delay);
5628 seq_printf(m, "Backlight on delay: %d\n",
5629 intel_dp->backlight_on_delay);
5630 seq_printf(m, "Backlight off delay: %d\n",
5631 intel_dp->backlight_off_delay);
5632
5633 return 0;
5634}
5635
5636static int i915_panel_open(struct inode *inode, struct file *file)
5637{
5638 return single_open(file, i915_panel_show, inode->i_private);
5639}
5640
5641static const struct file_operations i915_panel_fops = {
5642 .owner = THIS_MODULE,
5643 .open = i915_panel_open,
5644 .read = seq_read,
5645 .llseek = seq_lseek,
5646 .release = single_release,
5647};
5648
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005649/**
5650 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5651 * @connector: pointer to a registered drm_connector
5652 *
5653 * Cleanup will be done by drm_connector_unregister() through a call to
5654 * drm_debugfs_connector_remove().
5655 *
5656 * Returns 0 on success, negative error codes on error.
5657 */
5658int i915_debugfs_connector_add(struct drm_connector *connector)
5659{
5660 struct dentry *root = connector->debugfs_entry;
5661
5662 /* The connector must have been registered beforehands. */
5663 if (!root)
5664 return -ENODEV;
5665
5666 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5667 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005668 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5669 connector, &i915_dpcd_fops);
5670
5671 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5672 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5673 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005674
5675 return 0;
5676}