blob: 90bc4a89e0d5c5e1487877bb6a396df6d64b06a7 [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 Wilson73cb9702016-10-28 13:58:46 +0100555 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{
634 struct pid *pid = rq->ctx->pid;
635 struct task_struct *task;
636
637 rcu_read_lock();
638 task = pid ? pid_task(pid, PIDTYPE_PID) : NULL;
639 seq_printf(m, "%s%x [%x:%x] @ %d: %s [%d]\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100640 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson1b365952016-10-04 21:11:31 +0100641 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
642 task ? task->comm : "<unknown>",
643 task ? task->pid : -1);
644 rcu_read_unlock();
645}
646
Ben Gamari20172632009-02-17 20:08:50 -0500647static int i915_gem_request_info(struct seq_file *m, void *data)
648{
David Weinehall36cdd012016-08-22 13:59:31 +0300649 struct drm_i915_private *dev_priv = node_to_i915(m->private);
650 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200651 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530652 struct intel_engine_cs *engine;
653 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000654 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100655
656 ret = mutex_lock_interruptible(&dev->struct_mutex);
657 if (ret)
658 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500659
Chris Wilson2d1070b2015-04-01 10:36:56 +0100660 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530661 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100662 int count;
663
664 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100665 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100666 count++;
667 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100668 continue;
669
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000670 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100671 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100672 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100673
674 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500675 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100676 mutex_unlock(&dev->struct_mutex);
677
Chris Wilson2d1070b2015-04-01 10:36:56 +0100678 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100679 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100680
Ben Gamari20172632009-02-17 20:08:50 -0500681 return 0;
682}
683
Chris Wilsonb2223492010-10-27 15:27:33 +0100684static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000685 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100686{
Chris Wilson688e6c72016-07-01 17:23:15 +0100687 struct intel_breadcrumbs *b = &engine->breadcrumbs;
688 struct rb_node *rb;
689
Chris Wilson12471ba2016-04-09 10:57:55 +0100690 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100691 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100692
693 spin_lock(&b->lock);
694 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
695 struct intel_wait *w = container_of(rb, typeof(*w), node);
696
697 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
698 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
699 }
700 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100701}
702
Ben Gamari20172632009-02-17 20:08:50 -0500703static int i915_gem_seqno_info(struct seq_file *m, void *data)
704{
David Weinehall36cdd012016-08-22 13:59:31 +0300705 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000706 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530707 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500708
Akash Goel3b3f1652016-10-13 22:44:48 +0530709 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000710 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100711
Ben Gamari20172632009-02-17 20:08:50 -0500712 return 0;
713}
714
715
716static int i915_interrupt_info(struct seq_file *m, void *data)
717{
David Weinehall36cdd012016-08-22 13:59:31 +0300718 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000719 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530720 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100721 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100722
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200723 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500724
David Weinehall36cdd012016-08-22 13:59:31 +0300725 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300726 seq_printf(m, "Master Interrupt Control:\t%08x\n",
727 I915_READ(GEN8_MASTER_IRQ));
728
729 seq_printf(m, "Display IER:\t%08x\n",
730 I915_READ(VLV_IER));
731 seq_printf(m, "Display IIR:\t%08x\n",
732 I915_READ(VLV_IIR));
733 seq_printf(m, "Display IIR_RW:\t%08x\n",
734 I915_READ(VLV_IIR_RW));
735 seq_printf(m, "Display IMR:\t%08x\n",
736 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100737 for_each_pipe(dev_priv, pipe) {
738 enum intel_display_power_domain power_domain;
739
740 power_domain = POWER_DOMAIN_PIPE(pipe);
741 if (!intel_display_power_get_if_enabled(dev_priv,
742 power_domain)) {
743 seq_printf(m, "Pipe %c power disabled\n",
744 pipe_name(pipe));
745 continue;
746 }
747
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300748 seq_printf(m, "Pipe %c stat:\t%08x\n",
749 pipe_name(pipe),
750 I915_READ(PIPESTAT(pipe)));
751
Chris Wilson9c870d02016-10-24 13:42:15 +0100752 intel_display_power_put(dev_priv, power_domain);
753 }
754
755 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300756 seq_printf(m, "Port hotplug:\t%08x\n",
757 I915_READ(PORT_HOTPLUG_EN));
758 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
759 I915_READ(VLV_DPFLIPSTAT));
760 seq_printf(m, "DPINVGTT:\t%08x\n",
761 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100762 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300763
764 for (i = 0; i < 4; i++) {
765 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
766 i, I915_READ(GEN8_GT_IMR(i)));
767 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
768 i, I915_READ(GEN8_GT_IIR(i)));
769 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
770 i, I915_READ(GEN8_GT_IER(i)));
771 }
772
773 seq_printf(m, "PCU interrupt mask:\t%08x\n",
774 I915_READ(GEN8_PCU_IMR));
775 seq_printf(m, "PCU interrupt identity:\t%08x\n",
776 I915_READ(GEN8_PCU_IIR));
777 seq_printf(m, "PCU interrupt enable:\t%08x\n",
778 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300779 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700780 seq_printf(m, "Master Interrupt Control:\t%08x\n",
781 I915_READ(GEN8_MASTER_IRQ));
782
783 for (i = 0; i < 4; i++) {
784 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
785 i, I915_READ(GEN8_GT_IMR(i)));
786 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
787 i, I915_READ(GEN8_GT_IIR(i)));
788 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
789 i, I915_READ(GEN8_GT_IER(i)));
790 }
791
Damien Lespiau055e3932014-08-18 13:49:10 +0100792 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200793 enum intel_display_power_domain power_domain;
794
795 power_domain = POWER_DOMAIN_PIPE(pipe);
796 if (!intel_display_power_get_if_enabled(dev_priv,
797 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300798 seq_printf(m, "Pipe %c power disabled\n",
799 pipe_name(pipe));
800 continue;
801 }
Ben Widawskya123f152013-11-02 21:07:10 -0700802 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000803 pipe_name(pipe),
804 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700805 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000806 pipe_name(pipe),
807 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700808 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000809 pipe_name(pipe),
810 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200811
812 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700813 }
814
815 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
816 I915_READ(GEN8_DE_PORT_IMR));
817 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
818 I915_READ(GEN8_DE_PORT_IIR));
819 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
820 I915_READ(GEN8_DE_PORT_IER));
821
822 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
823 I915_READ(GEN8_DE_MISC_IMR));
824 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
825 I915_READ(GEN8_DE_MISC_IIR));
826 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
827 I915_READ(GEN8_DE_MISC_IER));
828
829 seq_printf(m, "PCU interrupt mask:\t%08x\n",
830 I915_READ(GEN8_PCU_IMR));
831 seq_printf(m, "PCU interrupt identity:\t%08x\n",
832 I915_READ(GEN8_PCU_IIR));
833 seq_printf(m, "PCU interrupt enable:\t%08x\n",
834 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300835 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700836 seq_printf(m, "Display IER:\t%08x\n",
837 I915_READ(VLV_IER));
838 seq_printf(m, "Display IIR:\t%08x\n",
839 I915_READ(VLV_IIR));
840 seq_printf(m, "Display IIR_RW:\t%08x\n",
841 I915_READ(VLV_IIR_RW));
842 seq_printf(m, "Display IMR:\t%08x\n",
843 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100844 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700845 seq_printf(m, "Pipe %c stat:\t%08x\n",
846 pipe_name(pipe),
847 I915_READ(PIPESTAT(pipe)));
848
849 seq_printf(m, "Master IER:\t%08x\n",
850 I915_READ(VLV_MASTER_IER));
851
852 seq_printf(m, "Render IER:\t%08x\n",
853 I915_READ(GTIER));
854 seq_printf(m, "Render IIR:\t%08x\n",
855 I915_READ(GTIIR));
856 seq_printf(m, "Render IMR:\t%08x\n",
857 I915_READ(GTIMR));
858
859 seq_printf(m, "PM IER:\t\t%08x\n",
860 I915_READ(GEN6_PMIER));
861 seq_printf(m, "PM IIR:\t\t%08x\n",
862 I915_READ(GEN6_PMIIR));
863 seq_printf(m, "PM IMR:\t\t%08x\n",
864 I915_READ(GEN6_PMIMR));
865
866 seq_printf(m, "Port hotplug:\t%08x\n",
867 I915_READ(PORT_HOTPLUG_EN));
868 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
869 I915_READ(VLV_DPFLIPSTAT));
870 seq_printf(m, "DPINVGTT:\t%08x\n",
871 I915_READ(DPINVGTT));
872
David Weinehall36cdd012016-08-22 13:59:31 +0300873 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800874 seq_printf(m, "Interrupt enable: %08x\n",
875 I915_READ(IER));
876 seq_printf(m, "Interrupt identity: %08x\n",
877 I915_READ(IIR));
878 seq_printf(m, "Interrupt mask: %08x\n",
879 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100880 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800881 seq_printf(m, "Pipe %c stat: %08x\n",
882 pipe_name(pipe),
883 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800884 } else {
885 seq_printf(m, "North Display Interrupt enable: %08x\n",
886 I915_READ(DEIER));
887 seq_printf(m, "North Display Interrupt identity: %08x\n",
888 I915_READ(DEIIR));
889 seq_printf(m, "North Display Interrupt mask: %08x\n",
890 I915_READ(DEIMR));
891 seq_printf(m, "South Display Interrupt enable: %08x\n",
892 I915_READ(SDEIER));
893 seq_printf(m, "South Display Interrupt identity: %08x\n",
894 I915_READ(SDEIIR));
895 seq_printf(m, "South Display Interrupt mask: %08x\n",
896 I915_READ(SDEIMR));
897 seq_printf(m, "Graphics Interrupt enable: %08x\n",
898 I915_READ(GTIER));
899 seq_printf(m, "Graphics Interrupt identity: %08x\n",
900 I915_READ(GTIIR));
901 seq_printf(m, "Graphics Interrupt mask: %08x\n",
902 I915_READ(GTIMR));
903 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530904 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300905 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100906 seq_printf(m,
907 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000908 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000909 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000910 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000911 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200912 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100913
Ben Gamari20172632009-02-17 20:08:50 -0500914 return 0;
915}
916
Chris Wilsona6172a82009-02-11 14:26:38 +0000917static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
918{
David Weinehall36cdd012016-08-22 13:59:31 +0300919 struct drm_i915_private *dev_priv = node_to_i915(m->private);
920 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100921 int i, ret;
922
923 ret = mutex_lock_interruptible(&dev->struct_mutex);
924 if (ret)
925 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000926
Chris Wilsona6172a82009-02-11 14:26:38 +0000927 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
928 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100929 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000930
Chris Wilson6c085a72012-08-20 11:40:46 +0200931 seq_printf(m, "Fence %d, pin count = %d, object = ",
932 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100933 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100934 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100935 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100936 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100937 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000938 }
939
Chris Wilson05394f32010-11-08 19:18:58 +0000940 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000941 return 0;
942}
943
Ben Gamari20172632009-02-17 20:08:50 -0500944static int i915_hws_info(struct seq_file *m, void *data)
945{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100946 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300947 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000948 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100949 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100950 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500951
Akash Goel3b3f1652016-10-13 22:44:48 +0530952 engine = dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000953 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500954 if (hws == NULL)
955 return 0;
956
957 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
958 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
959 i * 4,
960 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
961 }
962 return 0;
963}
964
Chris Wilson98a2f412016-10-12 10:05:18 +0100965#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
966
Daniel Vetterd5442302012-04-27 15:17:40 +0200967static ssize_t
968i915_error_state_write(struct file *filp,
969 const char __user *ubuf,
970 size_t cnt,
971 loff_t *ppos)
972{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300973 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200974
975 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100976 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200977
978 return cnt;
979}
980
981static int i915_error_state_open(struct inode *inode, struct file *file)
982{
David Weinehall36cdd012016-08-22 13:59:31 +0300983 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200984 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200985
986 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
987 if (!error_priv)
988 return -ENOMEM;
989
David Weinehall36cdd012016-08-22 13:59:31 +0300990 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200991
David Weinehall36cdd012016-08-22 13:59:31 +0300992 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200993
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300994 file->private_data = error_priv;
995
996 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200997}
998
999static int i915_error_state_release(struct inode *inode, struct file *file)
1000{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001001 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001002
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001003 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001004 kfree(error_priv);
1005
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001006 return 0;
1007}
1008
1009static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1010 size_t count, loff_t *pos)
1011{
1012 struct i915_error_state_file_priv *error_priv = file->private_data;
1013 struct drm_i915_error_state_buf error_str;
1014 loff_t tmp_pos = 0;
1015 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001016 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001017
David Weinehall36cdd012016-08-22 13:59:31 +03001018 ret = i915_error_state_buf_init(&error_str,
1019 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001020 if (ret)
1021 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001022
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001023 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001024 if (ret)
1025 goto out;
1026
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001027 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1028 error_str.buf,
1029 error_str.bytes);
1030
1031 if (ret_count < 0)
1032 ret = ret_count;
1033 else
1034 *pos = error_str.start + ret_count;
1035out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001036 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001037 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001038}
1039
1040static const struct file_operations i915_error_state_fops = {
1041 .owner = THIS_MODULE,
1042 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001043 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001044 .write = i915_error_state_write,
1045 .llseek = default_llseek,
1046 .release = i915_error_state_release,
1047};
1048
Chris Wilson98a2f412016-10-12 10:05:18 +01001049#endif
1050
Kees Cook647416f2013-03-10 14:10:06 -07001051static int
1052i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001053{
David Weinehall36cdd012016-08-22 13:59:31 +03001054 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001055
Chris Wilson73cb9702016-10-28 13:58:46 +01001056 *val = READ_ONCE(dev_priv->gt.global_timeline.next_seqno);
Kees Cook647416f2013-03-10 14:10:06 -07001057 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001058}
1059
Kees Cook647416f2013-03-10 14:10:06 -07001060static int
1061i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001062{
David Weinehall36cdd012016-08-22 13:59:31 +03001063 struct drm_i915_private *dev_priv = data;
1064 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001065 int ret;
1066
Mika Kuoppala40633212012-12-04 15:12:00 +02001067 ret = mutex_lock_interruptible(&dev->struct_mutex);
1068 if (ret)
1069 return ret;
1070
Chris Wilson73cb9702016-10-28 13:58:46 +01001071 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001072 mutex_unlock(&dev->struct_mutex);
1073
Kees Cook647416f2013-03-10 14:10:06 -07001074 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001075}
1076
Kees Cook647416f2013-03-10 14:10:06 -07001077DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1078 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001079 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001080
Deepak Sadb4bd12014-03-31 11:30:02 +05301081static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001082{
David Weinehall36cdd012016-08-22 13:59:31 +03001083 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1084 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001085 int ret = 0;
1086
1087 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001088
David Weinehall36cdd012016-08-22 13:59:31 +03001089 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001090 u16 rgvswctl = I915_READ16(MEMSWCTL);
1091 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1092
1093 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1094 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1095 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1096 MEMSTAT_VID_SHIFT);
1097 seq_printf(m, "Current P-state: %d\n",
1098 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001099 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001100 u32 freq_sts;
1101
1102 mutex_lock(&dev_priv->rps.hw_lock);
1103 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1104 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1105 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1106
1107 seq_printf(m, "actual GPU freq: %d MHz\n",
1108 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1109
1110 seq_printf(m, "current GPU freq: %d MHz\n",
1111 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1112
1113 seq_printf(m, "max GPU freq: %d MHz\n",
1114 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1115
1116 seq_printf(m, "min GPU freq: %d MHz\n",
1117 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1118
1119 seq_printf(m, "idle GPU freq: %d MHz\n",
1120 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1121
1122 seq_printf(m,
1123 "efficient (RPe) frequency: %d MHz\n",
1124 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1125 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001126 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001127 u32 rp_state_limits;
1128 u32 gt_perf_status;
1129 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001130 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001131 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001132 u32 rpupei, rpcurup, rpprevup;
1133 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001134 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001135 int max_freq;
1136
Bob Paauwe35040562015-06-25 14:54:07 -07001137 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001138 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001139 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1140 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1141 } else {
1142 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1143 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1144 }
1145
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001146 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001147 ret = mutex_lock_interruptible(&dev->struct_mutex);
1148 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001149 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001150
Mika Kuoppala59bad942015-01-16 11:34:40 +02001151 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001152
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001153 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001154 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301155 reqf >>= 23;
1156 else {
1157 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001158 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301159 reqf >>= 24;
1160 else
1161 reqf >>= 25;
1162 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001163 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001164
Chris Wilson0d8f9492014-03-27 09:06:14 +00001165 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1166 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1167 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1168
Jesse Barnesccab5c82011-01-18 15:49:25 -08001169 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301170 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1171 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1172 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1173 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1174 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1175 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001176 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301177 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001178 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001179 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1180 else
1181 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001182 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001183
Mika Kuoppala59bad942015-01-16 11:34:40 +02001184 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001185 mutex_unlock(&dev->struct_mutex);
1186
David Weinehall36cdd012016-08-22 13:59:31 +03001187 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001188 pm_ier = I915_READ(GEN6_PMIER);
1189 pm_imr = I915_READ(GEN6_PMIMR);
1190 pm_isr = I915_READ(GEN6_PMISR);
1191 pm_iir = I915_READ(GEN6_PMIIR);
1192 pm_mask = I915_READ(GEN6_PMINTRMSK);
1193 } else {
1194 pm_ier = I915_READ(GEN8_GT_IER(2));
1195 pm_imr = I915_READ(GEN8_GT_IMR(2));
1196 pm_isr = I915_READ(GEN8_GT_ISR(2));
1197 pm_iir = I915_READ(GEN8_GT_IIR(2));
1198 pm_mask = I915_READ(GEN6_PMINTRMSK);
1199 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001200 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 -03001201 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301202 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001203 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001204 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001205 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001206 seq_printf(m, "Render p-state VID: %d\n",
1207 gt_perf_status & 0xff);
1208 seq_printf(m, "Render p-state limit: %d\n",
1209 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001210 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1211 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1212 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1213 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001214 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001215 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301216 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1217 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1218 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1219 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1220 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1221 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001222 seq_printf(m, "Up threshold: %d%%\n",
1223 dev_priv->rps.up_threshold);
1224
Akash Goeld6cda9c2016-04-23 00:05:46 +05301225 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1226 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1227 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1228 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1229 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1230 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001231 seq_printf(m, "Down threshold: %d%%\n",
1232 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001233
David Weinehall36cdd012016-08-22 13:59:31 +03001234 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001235 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001236 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001237 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001238 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001239 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001240
1241 max_freq = (rp_state_cap & 0xff00) >> 8;
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, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001245 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001246
David Weinehall36cdd012016-08-22 13:59:31 +03001247 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001248 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001249 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001250 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001251 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001252 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001253 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001254 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001255
Chris Wilsond86ed342015-04-27 13:41:19 +01001256 seq_printf(m, "Current freq: %d MHz\n",
1257 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1258 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001259 seq_printf(m, "Idle freq: %d MHz\n",
1260 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001261 seq_printf(m, "Min freq: %d MHz\n",
1262 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001263 seq_printf(m, "Boost freq: %d MHz\n",
1264 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001265 seq_printf(m, "Max freq: %d MHz\n",
1266 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1267 seq_printf(m,
1268 "efficient (RPe) frequency: %d MHz\n",
1269 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001270 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001271 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001272 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001273
Mika Kahola1170f282015-09-25 14:00:32 +03001274 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1275 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1276 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1277
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001278out:
1279 intel_runtime_pm_put(dev_priv);
1280 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001281}
1282
Ben Widawskyd6369512016-09-20 16:54:32 +03001283static void i915_instdone_info(struct drm_i915_private *dev_priv,
1284 struct seq_file *m,
1285 struct intel_instdone *instdone)
1286{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001287 int slice;
1288 int subslice;
1289
Ben Widawskyd6369512016-09-20 16:54:32 +03001290 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1291 instdone->instdone);
1292
1293 if (INTEL_GEN(dev_priv) <= 3)
1294 return;
1295
1296 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1297 instdone->slice_common);
1298
1299 if (INTEL_GEN(dev_priv) <= 6)
1300 return;
1301
Ben Widawskyf9e61372016-09-20 16:54:33 +03001302 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1303 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1304 slice, subslice, instdone->sampler[slice][subslice]);
1305
1306 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1307 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1308 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001309}
1310
Chris Wilsonf6544492015-01-26 18:03:04 +02001311static int i915_hangcheck_info(struct seq_file *m, void *unused)
1312{
David Weinehall36cdd012016-08-22 13:59:31 +03001313 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001314 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001315 u64 acthd[I915_NUM_ENGINES];
1316 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001317 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001318 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001319
Chris Wilson8af29b02016-09-09 14:11:47 +01001320 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1321 seq_printf(m, "Wedged\n");
1322 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1323 seq_printf(m, "Reset in progress\n");
1324 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1325 seq_printf(m, "Waiter holding struct mutex\n");
1326 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1327 seq_printf(m, "struct_mutex blocked for reset\n");
1328
Chris Wilsonf6544492015-01-26 18:03:04 +02001329 if (!i915.enable_hangcheck) {
1330 seq_printf(m, "Hangcheck disabled\n");
1331 return 0;
1332 }
1333
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001334 intel_runtime_pm_get(dev_priv);
1335
Akash Goel3b3f1652016-10-13 22:44:48 +05301336 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001337 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001338 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001339 }
1340
Akash Goel3b3f1652016-10-13 22:44:48 +05301341 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001342
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001343 intel_runtime_pm_put(dev_priv);
1344
Chris Wilsonf6544492015-01-26 18:03:04 +02001345 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1346 seq_printf(m, "Hangcheck active, fires in %dms\n",
1347 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1348 jiffies));
1349 } else
1350 seq_printf(m, "Hangcheck inactive\n");
1351
Akash Goel3b3f1652016-10-13 22:44:48 +05301352 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001353 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1354 struct rb_node *rb;
1355
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001356 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001357 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1358 engine->hangcheck.seqno,
1359 seqno[id],
Chris Wilson73cb9702016-10-28 13:58:46 +01001360 engine->timeline->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001361 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1362 yesno(intel_engine_has_waiter(engine)),
1363 yesno(test_bit(engine->id,
1364 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilson33f53712016-10-04 21:11:32 +01001365 spin_lock(&b->lock);
1366 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1367 struct intel_wait *w = container_of(rb, typeof(*w), node);
1368
1369 seq_printf(m, "\t%s [%d] waiting for %x\n",
1370 w->tsk->comm, w->tsk->pid, w->seqno);
1371 }
1372 spin_unlock(&b->lock);
1373
Chris Wilsonf6544492015-01-26 18:03:04 +02001374 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001375 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001376 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001377 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1378 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001379
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001380 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001381 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001382
Ben Widawskyd6369512016-09-20 16:54:32 +03001383 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001384
Ben Widawskyd6369512016-09-20 16:54:32 +03001385 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001386
Ben Widawskyd6369512016-09-20 16:54:32 +03001387 i915_instdone_info(dev_priv, m,
1388 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001389 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001390 }
1391
1392 return 0;
1393}
1394
Ben Widawsky4d855292011-12-12 19:34:16 -08001395static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001396{
David Weinehall36cdd012016-08-22 13:59:31 +03001397 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001398 u32 rgvmodectl, rstdbyctl;
1399 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001400
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001401 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001402
1403 rgvmodectl = I915_READ(MEMMODECTL);
1404 rstdbyctl = I915_READ(RSTDBYCTL);
1405 crstandvid = I915_READ16(CRSTANDVID);
1406
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001407 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001408
Jani Nikula742f4912015-09-03 11:16:09 +03001409 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001410 seq_printf(m, "Boost freq: %d\n",
1411 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1412 MEMMODE_BOOST_FREQ_SHIFT);
1413 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001414 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001415 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001416 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001417 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001418 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001419 seq_printf(m, "Starting frequency: P%d\n",
1420 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001421 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001422 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001423 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1424 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1425 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1426 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001427 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001428 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001429 switch (rstdbyctl & RSX_STATUS_MASK) {
1430 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001431 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001432 break;
1433 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001434 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001435 break;
1436 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001437 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001438 break;
1439 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001440 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001441 break;
1442 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001443 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001444 break;
1445 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001446 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001447 break;
1448 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001449 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001450 break;
1451 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001452
1453 return 0;
1454}
1455
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001456static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001457{
David Weinehall36cdd012016-08-22 13:59:31 +03001458 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001459 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001460
1461 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001462 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001463 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001464 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001465 fw_domain->wake_count);
1466 }
1467 spin_unlock_irq(&dev_priv->uncore.lock);
1468
1469 return 0;
1470}
1471
Deepak S669ab5a2014-01-10 15:18:26 +05301472static int vlv_drpc_info(struct seq_file *m)
1473{
David Weinehall36cdd012016-08-22 13:59:31 +03001474 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001475 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301476
Imre Deakd46c0512014-04-14 20:24:27 +03001477 intel_runtime_pm_get(dev_priv);
1478
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001479 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301480 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1481 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1482
Imre Deakd46c0512014-04-14 20:24:27 +03001483 intel_runtime_pm_put(dev_priv);
1484
Deepak S669ab5a2014-01-10 15:18:26 +05301485 seq_printf(m, "Video Turbo Mode: %s\n",
1486 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1487 seq_printf(m, "Turbo enabled: %s\n",
1488 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1489 seq_printf(m, "HW control enabled: %s\n",
1490 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1491 seq_printf(m, "SW control enabled: %s\n",
1492 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1493 GEN6_RP_MEDIA_SW_MODE));
1494 seq_printf(m, "RC6 Enabled: %s\n",
1495 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1496 GEN6_RC_CTL_EI_MODE(1))));
1497 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001498 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301499 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001500 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301501
Imre Deak9cc19be2014-04-14 20:24:24 +03001502 seq_printf(m, "Render RC6 residency since boot: %u\n",
1503 I915_READ(VLV_GT_RENDER_RC6));
1504 seq_printf(m, "Media RC6 residency since boot: %u\n",
1505 I915_READ(VLV_GT_MEDIA_RC6));
1506
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001507 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301508}
1509
Ben Widawsky4d855292011-12-12 19:34:16 -08001510static int gen6_drpc_info(struct seq_file *m)
1511{
David Weinehall36cdd012016-08-22 13:59:31 +03001512 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1513 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001514 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301515 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001516 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001517 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001518
1519 ret = mutex_lock_interruptible(&dev->struct_mutex);
1520 if (ret)
1521 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001522 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001523
Chris Wilson907b28c2013-07-19 20:36:52 +01001524 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001525 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001526 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001527
1528 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001529 seq_puts(m, "RC information inaccurate because somebody "
1530 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001531 } else {
1532 /* NB: we cannot use forcewake, else we read the wrong values */
1533 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1534 udelay(10);
1535 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1536 }
1537
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001538 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001539 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001540
1541 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1542 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001543 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301544 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1545 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1546 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001548 mutex_lock(&dev_priv->rps.hw_lock);
1549 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1550 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001551
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001552 intel_runtime_pm_put(dev_priv);
1553
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 seq_printf(m, "Video Turbo Mode: %s\n",
1555 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1556 seq_printf(m, "HW control enabled: %s\n",
1557 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1558 seq_printf(m, "SW control enabled: %s\n",
1559 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1560 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001561 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001562 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1563 seq_printf(m, "RC6 Enabled: %s\n",
1564 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001565 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301566 seq_printf(m, "Render Well Gating Enabled: %s\n",
1567 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1568 seq_printf(m, "Media Well Gating Enabled: %s\n",
1569 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1570 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001571 seq_printf(m, "Deep RC6 Enabled: %s\n",
1572 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1573 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1574 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001575 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001576 switch (gt_core_status & GEN6_RCn_MASK) {
1577 case GEN6_RC0:
1578 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001579 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001580 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001581 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001582 break;
1583 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001584 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001585 break;
1586 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001587 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001588 break;
1589 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001590 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001591 break;
1592 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001593 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001594 break;
1595 }
1596
1597 seq_printf(m, "Core Power Down: %s\n",
1598 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001599 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301600 seq_printf(m, "Render Power Well: %s\n",
1601 (gen9_powergate_status &
1602 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1603 seq_printf(m, "Media Power Well: %s\n",
1604 (gen9_powergate_status &
1605 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1606 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001607
1608 /* Not exactly sure what this is */
1609 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1610 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1611 seq_printf(m, "RC6 residency since boot: %u\n",
1612 I915_READ(GEN6_GT_GFX_RC6));
1613 seq_printf(m, "RC6+ residency since boot: %u\n",
1614 I915_READ(GEN6_GT_GFX_RC6p));
1615 seq_printf(m, "RC6++ residency since boot: %u\n",
1616 I915_READ(GEN6_GT_GFX_RC6pp));
1617
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001618 seq_printf(m, "RC6 voltage: %dmV\n",
1619 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1620 seq_printf(m, "RC6+ voltage: %dmV\n",
1621 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1622 seq_printf(m, "RC6++ voltage: %dmV\n",
1623 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301624 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001625}
1626
1627static int i915_drpc_info(struct seq_file *m, void *unused)
1628{
David Weinehall36cdd012016-08-22 13:59:31 +03001629 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001630
David Weinehall36cdd012016-08-22 13:59:31 +03001631 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301632 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001633 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001634 return gen6_drpc_info(m);
1635 else
1636 return ironlake_drpc_info(m);
1637}
1638
Daniel Vetter9a851782015-06-18 10:30:22 +02001639static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1640{
David Weinehall36cdd012016-08-22 13:59:31 +03001641 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001642
1643 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1644 dev_priv->fb_tracking.busy_bits);
1645
1646 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1647 dev_priv->fb_tracking.flip_bits);
1648
1649 return 0;
1650}
1651
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001652static int i915_fbc_status(struct seq_file *m, void *unused)
1653{
David Weinehall36cdd012016-08-22 13:59:31 +03001654 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001655
David Weinehall36cdd012016-08-22 13:59:31 +03001656 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001657 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001658 return 0;
1659 }
1660
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001661 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001662 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001663
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001664 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001665 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001666 else
1667 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001668 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001669
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001670 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1671 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1672 BDW_FBC_COMPRESSION_MASK :
1673 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001674 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001675 yesno(I915_READ(FBC_STATUS2) & mask));
1676 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001677
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001678 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001679 intel_runtime_pm_put(dev_priv);
1680
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001681 return 0;
1682}
1683
Rodrigo Vivida46f932014-08-01 02:04:45 -07001684static int i915_fbc_fc_get(void *data, u64 *val)
1685{
David Weinehall36cdd012016-08-22 13:59:31 +03001686 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001687
David Weinehall36cdd012016-08-22 13:59:31 +03001688 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001689 return -ENODEV;
1690
Rodrigo Vivida46f932014-08-01 02:04:45 -07001691 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001692
1693 return 0;
1694}
1695
1696static int i915_fbc_fc_set(void *data, u64 val)
1697{
David Weinehall36cdd012016-08-22 13:59:31 +03001698 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001699 u32 reg;
1700
David Weinehall36cdd012016-08-22 13:59:31 +03001701 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001702 return -ENODEV;
1703
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001704 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001705
1706 reg = I915_READ(ILK_DPFC_CONTROL);
1707 dev_priv->fbc.false_color = val;
1708
1709 I915_WRITE(ILK_DPFC_CONTROL, val ?
1710 (reg | FBC_CTL_FALSE_COLOR) :
1711 (reg & ~FBC_CTL_FALSE_COLOR));
1712
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001713 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001714 return 0;
1715}
1716
1717DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1718 i915_fbc_fc_get, i915_fbc_fc_set,
1719 "%llu\n");
1720
Paulo Zanoni92d44622013-05-31 16:33:24 -03001721static int i915_ips_status(struct seq_file *m, void *unused)
1722{
David Weinehall36cdd012016-08-22 13:59:31 +03001723 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001724
David Weinehall36cdd012016-08-22 13:59:31 +03001725 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001726 seq_puts(m, "not supported\n");
1727 return 0;
1728 }
1729
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001730 intel_runtime_pm_get(dev_priv);
1731
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001732 seq_printf(m, "Enabled by kernel parameter: %s\n",
1733 yesno(i915.enable_ips));
1734
David Weinehall36cdd012016-08-22 13:59:31 +03001735 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001736 seq_puts(m, "Currently: unknown\n");
1737 } else {
1738 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1739 seq_puts(m, "Currently: enabled\n");
1740 else
1741 seq_puts(m, "Currently: disabled\n");
1742 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001743
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001744 intel_runtime_pm_put(dev_priv);
1745
Paulo Zanoni92d44622013-05-31 16:33:24 -03001746 return 0;
1747}
1748
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001749static int i915_sr_status(struct seq_file *m, void *unused)
1750{
David Weinehall36cdd012016-08-22 13:59:31 +03001751 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001752 bool sr_enabled = false;
1753
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001754 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001755 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001756
David Weinehall36cdd012016-08-22 13:59:31 +03001757 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001758 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001759 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1760 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001761 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001762 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001763 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001764 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001765 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001766 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001767 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001768
Chris Wilson9c870d02016-10-24 13:42:15 +01001769 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001770 intel_runtime_pm_put(dev_priv);
1771
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001772 seq_printf(m, "self-refresh: %s\n",
1773 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001774
1775 return 0;
1776}
1777
Jesse Barnes7648fa92010-05-20 14:28:11 -07001778static int i915_emon_status(struct seq_file *m, void *unused)
1779{
David Weinehall36cdd012016-08-22 13:59:31 +03001780 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1781 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001782 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001783 int ret;
1784
David Weinehall36cdd012016-08-22 13:59:31 +03001785 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001786 return -ENODEV;
1787
Chris Wilsonde227ef2010-07-03 07:58:38 +01001788 ret = mutex_lock_interruptible(&dev->struct_mutex);
1789 if (ret)
1790 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001791
1792 temp = i915_mch_val(dev_priv);
1793 chipset = i915_chipset_val(dev_priv);
1794 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001795 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001796
1797 seq_printf(m, "GMCH temp: %ld\n", temp);
1798 seq_printf(m, "Chipset power: %ld\n", chipset);
1799 seq_printf(m, "GFX power: %ld\n", gfx);
1800 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1801
1802 return 0;
1803}
1804
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001805static int i915_ring_freq_table(struct seq_file *m, void *unused)
1806{
David Weinehall36cdd012016-08-22 13:59:31 +03001807 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001808 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001809 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301810 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001811
Carlos Santa26310342016-08-17 12:30:41 -07001812 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001813 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001814 return 0;
1815 }
1816
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001817 intel_runtime_pm_get(dev_priv);
1818
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001819 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001820 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001821 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001822
David Weinehall36cdd012016-08-22 13:59:31 +03001823 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301824 /* Convert GT frequency to 50 HZ units */
1825 min_gpu_freq =
1826 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1827 max_gpu_freq =
1828 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1829 } else {
1830 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1831 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1832 }
1833
Damien Lespiau267f0c92013-06-24 22:59:48 +01001834 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001835
Akash Goelf936ec32015-06-29 14:50:22 +05301836 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001837 ia_freq = gpu_freq;
1838 sandybridge_pcode_read(dev_priv,
1839 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1840 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001841 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301842 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001843 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001844 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001845 ((ia_freq >> 0) & 0xff) * 100,
1846 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001847 }
1848
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001849 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001850
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001851out:
1852 intel_runtime_pm_put(dev_priv);
1853 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001854}
1855
Chris Wilson44834a62010-08-19 16:09:23 +01001856static int i915_opregion(struct seq_file *m, void *unused)
1857{
David Weinehall36cdd012016-08-22 13:59:31 +03001858 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1859 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001860 struct intel_opregion *opregion = &dev_priv->opregion;
1861 int ret;
1862
1863 ret = mutex_lock_interruptible(&dev->struct_mutex);
1864 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001865 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001866
Jani Nikula2455a8e2015-12-14 12:50:53 +02001867 if (opregion->header)
1868 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001869
1870 mutex_unlock(&dev->struct_mutex);
1871
Daniel Vetter0d38f002012-04-21 22:49:10 +02001872out:
Chris Wilson44834a62010-08-19 16:09:23 +01001873 return 0;
1874}
1875
Jani Nikulaada8f952015-12-15 13:17:12 +02001876static int i915_vbt(struct seq_file *m, void *unused)
1877{
David Weinehall36cdd012016-08-22 13:59:31 +03001878 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001879
1880 if (opregion->vbt)
1881 seq_write(m, opregion->vbt, opregion->vbt_size);
1882
1883 return 0;
1884}
1885
Chris Wilson37811fc2010-08-25 22:45:57 +01001886static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1887{
David Weinehall36cdd012016-08-22 13:59:31 +03001888 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1889 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301890 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001891 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001892 int ret;
1893
1894 ret = mutex_lock_interruptible(&dev->struct_mutex);
1895 if (ret)
1896 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001897
Daniel Vetter06957262015-08-10 13:34:08 +02001898#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001899 if (dev_priv->fbdev) {
1900 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001901
Chris Wilson25bcce92016-07-02 15:36:00 +01001902 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1903 fbdev_fb->base.width,
1904 fbdev_fb->base.height,
1905 fbdev_fb->base.depth,
1906 fbdev_fb->base.bits_per_pixel,
1907 fbdev_fb->base.modifier[0],
1908 drm_framebuffer_read_refcount(&fbdev_fb->base));
1909 describe_obj(m, fbdev_fb->obj);
1910 seq_putc(m, '\n');
1911 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001912#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001913
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001914 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001915 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301916 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1917 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001918 continue;
1919
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001920 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 +01001921 fb->base.width,
1922 fb->base.height,
1923 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001924 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001925 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001926 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001927 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001928 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001929 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001930 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001931 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001932
1933 return 0;
1934}
1935
Chris Wilson7e37f882016-08-02 22:50:21 +01001936static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001937{
1938 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001939 ring->space, ring->head, ring->tail,
1940 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001941}
1942
Ben Widawskye76d3632011-03-19 18:14:29 -07001943static int i915_context_status(struct seq_file *m, void *unused)
1944{
David Weinehall36cdd012016-08-22 13:59:31 +03001945 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1946 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001947 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001948 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301949 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001950 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001951
Daniel Vetterf3d28872014-05-29 23:23:08 +02001952 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001953 if (ret)
1954 return ret;
1955
Ben Widawskya33afea2013-09-17 21:12:45 -07001956 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001957 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001958 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001959 struct task_struct *task;
1960
Chris Wilsonc84455b2016-08-15 10:49:08 +01001961 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001962 if (task) {
1963 seq_printf(m, "(%s [%d]) ",
1964 task->comm, task->pid);
1965 put_task_struct(task);
1966 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001967 } else if (IS_ERR(ctx->file_priv)) {
1968 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001969 } else {
1970 seq_puts(m, "(kernel) ");
1971 }
1972
Chris Wilsonbca44d82016-05-24 14:53:41 +01001973 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1974 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001975
Akash Goel3b3f1652016-10-13 22:44:48 +05301976 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001977 struct intel_context *ce = &ctx->engine[engine->id];
1978
1979 seq_printf(m, "%s: ", engine->name);
1980 seq_putc(m, ce->initialised ? 'I' : 'i');
1981 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001982 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001983 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001984 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001985 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001986 }
1987
Ben Widawskya33afea2013-09-17 21:12:45 -07001988 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001989 }
1990
Daniel Vetterf3d28872014-05-29 23:23:08 +02001991 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001992
1993 return 0;
1994}
1995
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001996static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001997 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001998 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001999{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002000 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002001 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002002 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002003
Chris Wilson7069b142016-04-28 09:56:52 +01002004 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2005
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002006 if (!vma) {
2007 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002008 return;
2009 }
2010
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002011 if (vma->flags & I915_VMA_GLOBAL_BIND)
2012 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002013 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002014
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002015 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002016 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002017 return;
2018 }
2019
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002020 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2021 if (page) {
2022 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002023
2024 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002025 seq_printf(m,
2026 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2027 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002028 reg_state[j], reg_state[j + 1],
2029 reg_state[j + 2], reg_state[j + 3]);
2030 }
2031 kunmap_atomic(reg_state);
2032 }
2033
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002034 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002035 seq_putc(m, '\n');
2036}
2037
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002038static int i915_dump_lrc(struct seq_file *m, void *unused)
2039{
David Weinehall36cdd012016-08-22 13:59:31 +03002040 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2041 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002042 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002043 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302044 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002045 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002046
2047 if (!i915.enable_execlists) {
2048 seq_printf(m, "Logical Ring Contexts are disabled\n");
2049 return 0;
2050 }
2051
2052 ret = mutex_lock_interruptible(&dev->struct_mutex);
2053 if (ret)
2054 return ret;
2055
Dave Gordone28e4042016-01-19 19:02:55 +00002056 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302057 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002058 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002059
2060 mutex_unlock(&dev->struct_mutex);
2061
2062 return 0;
2063}
2064
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002065static const char *swizzle_string(unsigned swizzle)
2066{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002067 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002068 case I915_BIT_6_SWIZZLE_NONE:
2069 return "none";
2070 case I915_BIT_6_SWIZZLE_9:
2071 return "bit9";
2072 case I915_BIT_6_SWIZZLE_9_10:
2073 return "bit9/bit10";
2074 case I915_BIT_6_SWIZZLE_9_11:
2075 return "bit9/bit11";
2076 case I915_BIT_6_SWIZZLE_9_10_11:
2077 return "bit9/bit10/bit11";
2078 case I915_BIT_6_SWIZZLE_9_17:
2079 return "bit9/bit17";
2080 case I915_BIT_6_SWIZZLE_9_10_17:
2081 return "bit9/bit10/bit17";
2082 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002083 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002084 }
2085
2086 return "bug";
2087}
2088
2089static int i915_swizzle_info(struct seq_file *m, void *data)
2090{
David Weinehall36cdd012016-08-22 13:59:31 +03002091 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002092
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002093 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002094
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002095 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2096 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2097 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2098 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2099
David Weinehall36cdd012016-08-22 13:59:31 +03002100 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002101 seq_printf(m, "DDC = 0x%08x\n",
2102 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002103 seq_printf(m, "DDC2 = 0x%08x\n",
2104 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002105 seq_printf(m, "C0DRB3 = 0x%04x\n",
2106 I915_READ16(C0DRB3));
2107 seq_printf(m, "C1DRB3 = 0x%04x\n",
2108 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002109 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002110 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2111 I915_READ(MAD_DIMM_C0));
2112 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2113 I915_READ(MAD_DIMM_C1));
2114 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2115 I915_READ(MAD_DIMM_C2));
2116 seq_printf(m, "TILECTL = 0x%08x\n",
2117 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002118 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002119 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2120 I915_READ(GAMTARBMODE));
2121 else
2122 seq_printf(m, "ARB_MODE = 0x%08x\n",
2123 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002124 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2125 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002126 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002127
2128 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2129 seq_puts(m, "L-shaped memory detected\n");
2130
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002131 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002132
2133 return 0;
2134}
2135
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002136static int per_file_ctx(int id, void *ptr, void *data)
2137{
Chris Wilsone2efd132016-05-24 14:53:34 +01002138 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002139 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002140 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2141
2142 if (!ppgtt) {
2143 seq_printf(m, " no ppgtt for context %d\n",
2144 ctx->user_handle);
2145 return 0;
2146 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002147
Oscar Mateof83d6512014-05-22 14:13:38 +01002148 if (i915_gem_context_is_default(ctx))
2149 seq_puts(m, " default context:\n");
2150 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002151 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002152 ppgtt->debug_dump(ppgtt, m);
2153
2154 return 0;
2155}
2156
David Weinehall36cdd012016-08-22 13:59:31 +03002157static void gen8_ppgtt_info(struct seq_file *m,
2158 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002159{
Ben Widawsky77df6772013-11-02 21:07:30 -07002160 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302161 struct intel_engine_cs *engine;
2162 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002163 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002164
Ben Widawsky77df6772013-11-02 21:07:30 -07002165 if (!ppgtt)
2166 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002167
Akash Goel3b3f1652016-10-13 22:44:48 +05302168 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002169 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002170 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002171 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002172 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002173 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002174 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002175 }
2176 }
2177}
2178
David Weinehall36cdd012016-08-22 13:59:31 +03002179static void gen6_ppgtt_info(struct seq_file *m,
2180 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002181{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002182 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302183 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002184
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002185 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002186 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2187
Akash Goel3b3f1652016-10-13 22:44:48 +05302188 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002189 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002190 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002191 seq_printf(m, "GFX_MODE: 0x%08x\n",
2192 I915_READ(RING_MODE_GEN7(engine)));
2193 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2194 I915_READ(RING_PP_DIR_BASE(engine)));
2195 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2196 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2197 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2198 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002199 }
2200 if (dev_priv->mm.aliasing_ppgtt) {
2201 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2202
Damien Lespiau267f0c92013-06-24 22:59:48 +01002203 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002204 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002205
Ben Widawsky87d60b62013-12-06 14:11:29 -08002206 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002207 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002208
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002209 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002210}
2211
2212static int i915_ppgtt_info(struct seq_file *m, void *data)
2213{
David Weinehall36cdd012016-08-22 13:59:31 +03002214 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2215 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002216 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002217 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002218
Chris Wilson637ee292016-08-22 14:28:20 +01002219 mutex_lock(&dev->filelist_mutex);
2220 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002221 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002222 goto out_unlock;
2223
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002224 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002225
David Weinehall36cdd012016-08-22 13:59:31 +03002226 if (INTEL_GEN(dev_priv) >= 8)
2227 gen8_ppgtt_info(m, dev_priv);
2228 else if (INTEL_GEN(dev_priv) >= 6)
2229 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002230
Michel Thierryea91e402015-07-29 17:23:57 +01002231 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2232 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002233 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002234
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002235 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002236 if (!task) {
2237 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002238 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002239 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002240 seq_printf(m, "\nproc: %s\n", task->comm);
2241 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002242 idr_for_each(&file_priv->context_idr, per_file_ctx,
2243 (void *)(unsigned long)m);
2244 }
2245
Chris Wilson637ee292016-08-22 14:28:20 +01002246out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002247 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002248 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002249out_unlock:
2250 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002251 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002252}
2253
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002254static int count_irq_waiters(struct drm_i915_private *i915)
2255{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002256 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302257 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002258 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002259
Akash Goel3b3f1652016-10-13 22:44:48 +05302260 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002261 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002262
2263 return count;
2264}
2265
Chris Wilson7466c292016-08-15 09:49:33 +01002266static const char *rps_power_to_str(unsigned int power)
2267{
2268 static const char * const strings[] = {
2269 [LOW_POWER] = "low power",
2270 [BETWEEN] = "mixed",
2271 [HIGH_POWER] = "high power",
2272 };
2273
2274 if (power >= ARRAY_SIZE(strings) || !strings[power])
2275 return "unknown";
2276
2277 return strings[power];
2278}
2279
Chris Wilson1854d5c2015-04-07 16:20:32 +01002280static int i915_rps_boost_info(struct seq_file *m, void *data)
2281{
David Weinehall36cdd012016-08-22 13:59:31 +03002282 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2283 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002284 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002285
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002286 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002287 seq_printf(m, "GPU busy? %s [%x]\n",
2288 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002289 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002290 seq_printf(m, "Frequency requested %d\n",
2291 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2292 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002293 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2294 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2295 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2296 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002297 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2298 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2299 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2300 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002301
2302 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002303 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002304 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2305 struct drm_i915_file_private *file_priv = file->driver_priv;
2306 struct task_struct *task;
2307
2308 rcu_read_lock();
2309 task = pid_task(file->pid, PIDTYPE_PID);
2310 seq_printf(m, "%s [%d]: %d boosts%s\n",
2311 task ? task->comm : "<unknown>",
2312 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002313 file_priv->rps.boosts,
2314 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002315 rcu_read_unlock();
2316 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002317 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002318 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002319 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002320
Chris Wilson7466c292016-08-15 09:49:33 +01002321 if (INTEL_GEN(dev_priv) >= 6 &&
2322 dev_priv->rps.enabled &&
2323 dev_priv->gt.active_engines) {
2324 u32 rpup, rpupei;
2325 u32 rpdown, rpdownei;
2326
2327 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2328 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2329 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2330 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2331 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2332 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2333
2334 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2335 rps_power_to_str(dev_priv->rps.power));
2336 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2337 100 * rpup / rpupei,
2338 dev_priv->rps.up_threshold);
2339 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2340 100 * rpdown / rpdownei,
2341 dev_priv->rps.down_threshold);
2342 } else {
2343 seq_puts(m, "\nRPS Autotuning inactive\n");
2344 }
2345
Chris Wilson8d3afd72015-05-21 21:01:47 +01002346 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002347}
2348
Ben Widawsky63573eb2013-07-04 11:02:07 -07002349static int i915_llc(struct seq_file *m, void *data)
2350{
David Weinehall36cdd012016-08-22 13:59:31 +03002351 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002352 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002353
David Weinehall36cdd012016-08-22 13:59:31 +03002354 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002355 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2356 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002357
2358 return 0;
2359}
2360
Alex Daifdf5d352015-08-12 15:43:37 +01002361static int i915_guc_load_status_info(struct seq_file *m, void *data)
2362{
David Weinehall36cdd012016-08-22 13:59:31 +03002363 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002364 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2365 u32 tmp, i;
2366
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002367 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002368 return 0;
2369
2370 seq_printf(m, "GuC firmware status:\n");
2371 seq_printf(m, "\tpath: %s\n",
2372 guc_fw->guc_fw_path);
2373 seq_printf(m, "\tfetch: %s\n",
2374 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2375 seq_printf(m, "\tload: %s\n",
2376 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2377 seq_printf(m, "\tversion wanted: %d.%d\n",
2378 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2379 seq_printf(m, "\tversion found: %d.%d\n",
2380 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002381 seq_printf(m, "\theader: offset is %d; size = %d\n",
2382 guc_fw->header_offset, guc_fw->header_size);
2383 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2384 guc_fw->ucode_offset, guc_fw->ucode_size);
2385 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2386 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002387
2388 tmp = I915_READ(GUC_STATUS);
2389
2390 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2391 seq_printf(m, "\tBootrom status = 0x%x\n",
2392 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2393 seq_printf(m, "\tuKernel status = 0x%x\n",
2394 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2395 seq_printf(m, "\tMIA Core status = 0x%x\n",
2396 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2397 seq_puts(m, "\nScratch registers:\n");
2398 for (i = 0; i < 16; i++)
2399 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2400
2401 return 0;
2402}
2403
Akash Goel5aa1ee42016-10-12 21:54:36 +05302404static void i915_guc_log_info(struct seq_file *m,
2405 struct drm_i915_private *dev_priv)
2406{
2407 struct intel_guc *guc = &dev_priv->guc;
2408
2409 seq_puts(m, "\nGuC logging stats:\n");
2410
2411 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2412 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2413 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2414
2415 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2416 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2417 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2418
2419 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2420 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2421 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2422
2423 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2424 guc->log.flush_interrupt_count);
2425
2426 seq_printf(m, "\tCapture miss count: %u\n",
2427 guc->log.capture_miss_count);
2428}
2429
Dave Gordon8b417c22015-08-12 15:43:44 +01002430static void i915_guc_client_info(struct seq_file *m,
2431 struct drm_i915_private *dev_priv,
2432 struct i915_guc_client *client)
2433{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002434 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002435 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002436 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002437
2438 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2439 client->priority, client->ctx_index, client->proc_desc_offset);
2440 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2441 client->doorbell_id, client->doorbell_offset, client->cookie);
2442 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2443 client->wq_size, client->wq_offset, client->wq_tail);
2444
Dave Gordon551aaec2016-05-13 15:36:33 +01002445 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002446 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2447 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2448
Akash Goel3b3f1652016-10-13 22:44:48 +05302449 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002450 u64 submissions = client->submissions[id];
2451 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002452 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002453 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002454 }
2455 seq_printf(m, "\tTotal: %llu\n", tot);
2456}
2457
2458static int i915_guc_info(struct seq_file *m, void *data)
2459{
David Weinehall36cdd012016-08-22 13:59:31 +03002460 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2461 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002462 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002463 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002464 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002465 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002466 u64 total = 0;
2467
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002468 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002469 return 0;
2470
Alex Dai5a843302015-12-02 16:56:29 -08002471 if (mutex_lock_interruptible(&dev->struct_mutex))
2472 return 0;
2473
Dave Gordon8b417c22015-08-12 15:43:44 +01002474 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002475 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002476 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002477 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002478
2479 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002480
Dave Gordon9636f6d2016-06-13 17:57:28 +01002481 seq_printf(m, "Doorbell map:\n");
2482 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2483 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2484
Dave Gordon8b417c22015-08-12 15:43:44 +01002485 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2486 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2487 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2488 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2489 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2490
2491 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302492 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002493 u64 submissions = guc.submissions[id];
2494 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002495 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002496 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002497 }
2498 seq_printf(m, "\t%s: %llu\n", "Total", total);
2499
2500 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2501 i915_guc_client_info(m, dev_priv, &client);
2502
Akash Goel5aa1ee42016-10-12 21:54:36 +05302503 i915_guc_log_info(m, dev_priv);
2504
Dave Gordon8b417c22015-08-12 15:43:44 +01002505 /* Add more as required ... */
2506
2507 return 0;
2508}
2509
Alex Dai4c7e77f2015-08-12 15:43:40 +01002510static int i915_guc_log_dump(struct seq_file *m, void *data)
2511{
David Weinehall36cdd012016-08-22 13:59:31 +03002512 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002513 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002514 int i = 0, pg;
2515
Akash Goeld6b40b42016-10-12 21:54:29 +05302516 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002517 return 0;
2518
Akash Goeld6b40b42016-10-12 21:54:29 +05302519 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002520 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2521 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002522
2523 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2524 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2525 *(log + i), *(log + i + 1),
2526 *(log + i + 2), *(log + i + 3));
2527
2528 kunmap_atomic(log);
2529 }
2530
2531 seq_putc(m, '\n');
2532
2533 return 0;
2534}
2535
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302536static int i915_guc_log_control_get(void *data, u64 *val)
2537{
2538 struct drm_device *dev = data;
2539 struct drm_i915_private *dev_priv = to_i915(dev);
2540
2541 if (!dev_priv->guc.log.vma)
2542 return -EINVAL;
2543
2544 *val = i915.guc_log_level;
2545
2546 return 0;
2547}
2548
2549static int i915_guc_log_control_set(void *data, u64 val)
2550{
2551 struct drm_device *dev = data;
2552 struct drm_i915_private *dev_priv = to_i915(dev);
2553 int ret;
2554
2555 if (!dev_priv->guc.log.vma)
2556 return -EINVAL;
2557
2558 ret = mutex_lock_interruptible(&dev->struct_mutex);
2559 if (ret)
2560 return ret;
2561
2562 intel_runtime_pm_get(dev_priv);
2563 ret = i915_guc_log_control(dev_priv, val);
2564 intel_runtime_pm_put(dev_priv);
2565
2566 mutex_unlock(&dev->struct_mutex);
2567 return ret;
2568}
2569
2570DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2571 i915_guc_log_control_get, i915_guc_log_control_set,
2572 "%lld\n");
2573
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002574static int i915_edp_psr_status(struct seq_file *m, void *data)
2575{
David Weinehall36cdd012016-08-22 13:59:31 +03002576 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002577 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002578 u32 stat[3];
2579 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002580 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002581
David Weinehall36cdd012016-08-22 13:59:31 +03002582 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002583 seq_puts(m, "PSR not supported\n");
2584 return 0;
2585 }
2586
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002587 intel_runtime_pm_get(dev_priv);
2588
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002589 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002590 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2591 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002592 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002593 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002594 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2595 dev_priv->psr.busy_frontbuffer_bits);
2596 seq_printf(m, "Re-enable work scheduled: %s\n",
2597 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002598
David Weinehall36cdd012016-08-22 13:59:31 +03002599 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002600 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002601 else {
2602 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002603 enum transcoder cpu_transcoder =
2604 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2605 enum intel_display_power_domain power_domain;
2606
2607 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2608 if (!intel_display_power_get_if_enabled(dev_priv,
2609 power_domain))
2610 continue;
2611
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002612 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2613 VLV_EDP_PSR_CURR_STATE_MASK;
2614 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2615 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2616 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002617
2618 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002619 }
2620 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002621
2622 seq_printf(m, "Main link in standby mode: %s\n",
2623 yesno(dev_priv->psr.link_standby));
2624
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002625 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002626
David Weinehall36cdd012016-08-22 13:59:31 +03002627 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002628 for_each_pipe(dev_priv, pipe) {
2629 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2630 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2631 seq_printf(m, " pipe %c", pipe_name(pipe));
2632 }
2633 seq_puts(m, "\n");
2634
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002635 /*
2636 * VLV/CHV PSR has no kind of performance counter
2637 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2638 */
David Weinehall36cdd012016-08-22 13:59:31 +03002639 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002640 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002641 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002642
2643 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2644 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002645 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002646
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002647 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002648 return 0;
2649}
2650
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002651static int i915_sink_crc(struct seq_file *m, void *data)
2652{
David Weinehall36cdd012016-08-22 13:59:31 +03002653 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2654 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002655 struct intel_connector *connector;
2656 struct intel_dp *intel_dp = NULL;
2657 int ret;
2658 u8 crc[6];
2659
2660 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002661 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002662 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002663
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002664 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002665 continue;
2666
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002667 crtc = connector->base.state->crtc;
2668 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002669 continue;
2670
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002671 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002672 continue;
2673
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002674 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002675
2676 ret = intel_dp_sink_crc(intel_dp, crc);
2677 if (ret)
2678 goto out;
2679
2680 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2681 crc[0], crc[1], crc[2],
2682 crc[3], crc[4], crc[5]);
2683 goto out;
2684 }
2685 ret = -ENODEV;
2686out:
2687 drm_modeset_unlock_all(dev);
2688 return ret;
2689}
2690
Jesse Barnesec013e72013-08-20 10:29:23 +01002691static int i915_energy_uJ(struct seq_file *m, void *data)
2692{
David Weinehall36cdd012016-08-22 13:59:31 +03002693 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002694 u64 power;
2695 u32 units;
2696
David Weinehall36cdd012016-08-22 13:59:31 +03002697 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002698 return -ENODEV;
2699
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002700 intel_runtime_pm_get(dev_priv);
2701
Jesse Barnesec013e72013-08-20 10:29:23 +01002702 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2703 power = (power & 0x1f00) >> 8;
2704 units = 1000000 / (1 << power); /* convert to uJ */
2705 power = I915_READ(MCH_SECP_NRG_STTS);
2706 power *= units;
2707
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002708 intel_runtime_pm_put(dev_priv);
2709
Jesse Barnesec013e72013-08-20 10:29:23 +01002710 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002711
2712 return 0;
2713}
2714
Damien Lespiau6455c872015-06-04 18:23:57 +01002715static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002716{
David Weinehall36cdd012016-08-22 13:59:31 +03002717 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002718 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002719
Chris Wilsona156e642016-04-03 14:14:21 +01002720 if (!HAS_RUNTIME_PM(dev_priv))
2721 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002722
Chris Wilson67d97da2016-07-04 08:08:31 +01002723 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002724 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002725 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002726#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002727 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002728 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002729#else
2730 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2731#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002732 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002733 pci_power_name(pdev->current_state),
2734 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002735
Jesse Barnesec013e72013-08-20 10:29:23 +01002736 return 0;
2737}
2738
Imre Deak1da51582013-11-25 17:15:35 +02002739static int i915_power_domain_info(struct seq_file *m, void *unused)
2740{
David Weinehall36cdd012016-08-22 13:59:31 +03002741 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002742 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2743 int i;
2744
2745 mutex_lock(&power_domains->lock);
2746
2747 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2748 for (i = 0; i < power_domains->power_well_count; i++) {
2749 struct i915_power_well *power_well;
2750 enum intel_display_power_domain power_domain;
2751
2752 power_well = &power_domains->power_wells[i];
2753 seq_printf(m, "%-25s %d\n", power_well->name,
2754 power_well->count);
2755
2756 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2757 power_domain++) {
2758 if (!(BIT(power_domain) & power_well->domains))
2759 continue;
2760
2761 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002762 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002763 power_domains->domain_use_count[power_domain]);
2764 }
2765 }
2766
2767 mutex_unlock(&power_domains->lock);
2768
2769 return 0;
2770}
2771
Damien Lespiaub7cec662015-10-27 14:47:01 +02002772static int i915_dmc_info(struct seq_file *m, void *unused)
2773{
David Weinehall36cdd012016-08-22 13:59:31 +03002774 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002775 struct intel_csr *csr;
2776
David Weinehall36cdd012016-08-22 13:59:31 +03002777 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002778 seq_puts(m, "not supported\n");
2779 return 0;
2780 }
2781
2782 csr = &dev_priv->csr;
2783
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002784 intel_runtime_pm_get(dev_priv);
2785
Damien Lespiaub7cec662015-10-27 14:47:01 +02002786 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2787 seq_printf(m, "path: %s\n", csr->fw_path);
2788
2789 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002790 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002791
2792 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2793 CSR_VERSION_MINOR(csr->version));
2794
David Weinehall36cdd012016-08-22 13:59:31 +03002795 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002796 seq_printf(m, "DC3 -> DC5 count: %d\n",
2797 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2798 seq_printf(m, "DC5 -> DC6 count: %d\n",
2799 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002800 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002801 seq_printf(m, "DC3 -> DC5 count: %d\n",
2802 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002803 }
2804
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002805out:
2806 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2807 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2808 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2809
Damien Lespiau83372062015-10-30 17:53:32 +02002810 intel_runtime_pm_put(dev_priv);
2811
Damien Lespiaub7cec662015-10-27 14:47:01 +02002812 return 0;
2813}
2814
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002815static void intel_seq_print_mode(struct seq_file *m, int tabs,
2816 struct drm_display_mode *mode)
2817{
2818 int i;
2819
2820 for (i = 0; i < tabs; i++)
2821 seq_putc(m, '\t');
2822
2823 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",
2824 mode->base.id, mode->name,
2825 mode->vrefresh, mode->clock,
2826 mode->hdisplay, mode->hsync_start,
2827 mode->hsync_end, mode->htotal,
2828 mode->vdisplay, mode->vsync_start,
2829 mode->vsync_end, mode->vtotal,
2830 mode->type, mode->flags);
2831}
2832
2833static void intel_encoder_info(struct seq_file *m,
2834 struct intel_crtc *intel_crtc,
2835 struct intel_encoder *intel_encoder)
2836{
David Weinehall36cdd012016-08-22 13:59:31 +03002837 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2838 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002839 struct drm_crtc *crtc = &intel_crtc->base;
2840 struct intel_connector *intel_connector;
2841 struct drm_encoder *encoder;
2842
2843 encoder = &intel_encoder->base;
2844 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002845 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002846 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2847 struct drm_connector *connector = &intel_connector->base;
2848 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2849 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002850 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002851 drm_get_connector_status_name(connector->status));
2852 if (connector->status == connector_status_connected) {
2853 struct drm_display_mode *mode = &crtc->mode;
2854 seq_printf(m, ", mode:\n");
2855 intel_seq_print_mode(m, 2, mode);
2856 } else {
2857 seq_putc(m, '\n');
2858 }
2859 }
2860}
2861
2862static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2863{
David Weinehall36cdd012016-08-22 13:59:31 +03002864 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2865 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002866 struct drm_crtc *crtc = &intel_crtc->base;
2867 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002868 struct drm_plane_state *plane_state = crtc->primary->state;
2869 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002870
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002871 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002872 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002873 fb->base.id, plane_state->src_x >> 16,
2874 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002875 else
2876 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002877 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2878 intel_encoder_info(m, intel_crtc, intel_encoder);
2879}
2880
2881static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2882{
2883 struct drm_display_mode *mode = panel->fixed_mode;
2884
2885 seq_printf(m, "\tfixed mode:\n");
2886 intel_seq_print_mode(m, 2, mode);
2887}
2888
2889static void intel_dp_info(struct seq_file *m,
2890 struct intel_connector *intel_connector)
2891{
2892 struct intel_encoder *intel_encoder = intel_connector->encoder;
2893 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2894
2895 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002896 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002897 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002898 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002899
2900 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2901 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002902}
2903
2904static void intel_hdmi_info(struct seq_file *m,
2905 struct intel_connector *intel_connector)
2906{
2907 struct intel_encoder *intel_encoder = intel_connector->encoder;
2908 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2909
Jani Nikula742f4912015-09-03 11:16:09 +03002910 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002911}
2912
2913static void intel_lvds_info(struct seq_file *m,
2914 struct intel_connector *intel_connector)
2915{
2916 intel_panel_info(m, &intel_connector->panel);
2917}
2918
2919static void intel_connector_info(struct seq_file *m,
2920 struct drm_connector *connector)
2921{
2922 struct intel_connector *intel_connector = to_intel_connector(connector);
2923 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002924 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002925
2926 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002927 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002928 drm_get_connector_status_name(connector->status));
2929 if (connector->status == connector_status_connected) {
2930 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2931 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2932 connector->display_info.width_mm,
2933 connector->display_info.height_mm);
2934 seq_printf(m, "\tsubpixel order: %s\n",
2935 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2936 seq_printf(m, "\tCEA rev: %d\n",
2937 connector->display_info.cea_rev);
2938 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002939
2940 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2941 return;
2942
2943 switch (connector->connector_type) {
2944 case DRM_MODE_CONNECTOR_DisplayPort:
2945 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002946 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002947 break;
2948 case DRM_MODE_CONNECTOR_LVDS:
2949 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002950 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002951 break;
2952 case DRM_MODE_CONNECTOR_HDMIA:
2953 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2954 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2955 intel_hdmi_info(m, intel_connector);
2956 break;
2957 default:
2958 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002959 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002960
Jesse Barnesf103fc72014-02-20 12:39:57 -08002961 seq_printf(m, "\tmodes:\n");
2962 list_for_each_entry(mode, &connector->modes, head)
2963 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002964}
2965
David Weinehall36cdd012016-08-22 13:59:31 +03002966static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002967{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002968 u32 state;
2969
David Weinehall36cdd012016-08-22 13:59:31 +03002970 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002971 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002972 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002973 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002974
2975 return state;
2976}
2977
David Weinehall36cdd012016-08-22 13:59:31 +03002978static bool cursor_position(struct drm_i915_private *dev_priv,
2979 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002980{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002981 u32 pos;
2982
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002983 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002984
2985 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2986 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2987 *x = -*x;
2988
2989 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2990 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2991 *y = -*y;
2992
David Weinehall36cdd012016-08-22 13:59:31 +03002993 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002994}
2995
Robert Fekete3abc4e02015-10-27 16:58:32 +01002996static const char *plane_type(enum drm_plane_type type)
2997{
2998 switch (type) {
2999 case DRM_PLANE_TYPE_OVERLAY:
3000 return "OVL";
3001 case DRM_PLANE_TYPE_PRIMARY:
3002 return "PRI";
3003 case DRM_PLANE_TYPE_CURSOR:
3004 return "CUR";
3005 /*
3006 * Deliberately omitting default: to generate compiler warnings
3007 * when a new drm_plane_type gets added.
3008 */
3009 }
3010
3011 return "unknown";
3012}
3013
3014static const char *plane_rotation(unsigned int rotation)
3015{
3016 static char buf[48];
3017 /*
3018 * According to doc only one DRM_ROTATE_ is allowed but this
3019 * will print them all to visualize if the values are misused
3020 */
3021 snprintf(buf, sizeof(buf),
3022 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003023 (rotation & DRM_ROTATE_0) ? "0 " : "",
3024 (rotation & DRM_ROTATE_90) ? "90 " : "",
3025 (rotation & DRM_ROTATE_180) ? "180 " : "",
3026 (rotation & DRM_ROTATE_270) ? "270 " : "",
3027 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3028 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003029 rotation);
3030
3031 return buf;
3032}
3033
3034static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3035{
David Weinehall36cdd012016-08-22 13:59:31 +03003036 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3037 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003038 struct intel_plane *intel_plane;
3039
3040 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3041 struct drm_plane_state *state;
3042 struct drm_plane *plane = &intel_plane->base;
Eric Engestromd3828142016-08-15 16:29:55 +01003043 char *format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003044
3045 if (!plane->state) {
3046 seq_puts(m, "plane->state is NULL!\n");
3047 continue;
3048 }
3049
3050 state = plane->state;
3051
Eric Engestrom90844f02016-08-15 01:02:38 +01003052 if (state->fb) {
3053 format_name = drm_get_format_name(state->fb->pixel_format);
3054 } else {
3055 format_name = kstrdup("N/A", GFP_KERNEL);
3056 }
3057
Robert Fekete3abc4e02015-10-27 16:58:32 +01003058 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",
3059 plane->base.id,
3060 plane_type(intel_plane->base.type),
3061 state->crtc_x, state->crtc_y,
3062 state->crtc_w, state->crtc_h,
3063 (state->src_x >> 16),
3064 ((state->src_x & 0xffff) * 15625) >> 10,
3065 (state->src_y >> 16),
3066 ((state->src_y & 0xffff) * 15625) >> 10,
3067 (state->src_w >> 16),
3068 ((state->src_w & 0xffff) * 15625) >> 10,
3069 (state->src_h >> 16),
3070 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestrom90844f02016-08-15 01:02:38 +01003071 format_name,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003072 plane_rotation(state->rotation));
Eric Engestrom90844f02016-08-15 01:02:38 +01003073
3074 kfree(format_name);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003075 }
3076}
3077
3078static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3079{
3080 struct intel_crtc_state *pipe_config;
3081 int num_scalers = intel_crtc->num_scalers;
3082 int i;
3083
3084 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3085
3086 /* Not all platformas have a scaler */
3087 if (num_scalers) {
3088 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3089 num_scalers,
3090 pipe_config->scaler_state.scaler_users,
3091 pipe_config->scaler_state.scaler_id);
3092
3093 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3094 struct intel_scaler *sc =
3095 &pipe_config->scaler_state.scalers[i];
3096
3097 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3098 i, yesno(sc->in_use), sc->mode);
3099 }
3100 seq_puts(m, "\n");
3101 } else {
3102 seq_puts(m, "\tNo scalers available on this platform\n");
3103 }
3104}
3105
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003106static int i915_display_info(struct seq_file *m, void *unused)
3107{
David Weinehall36cdd012016-08-22 13:59:31 +03003108 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3109 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003110 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003111 struct drm_connector *connector;
3112
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003113 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003114 drm_modeset_lock_all(dev);
3115 seq_printf(m, "CRTC info\n");
3116 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003117 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003118 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003119 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003120 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003121
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003122 pipe_config = to_intel_crtc_state(crtc->base.state);
3123
Robert Fekete3abc4e02015-10-27 16:58:32 +01003124 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003125 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003126 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003127 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3128 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3129
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003130 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003131 intel_crtc_info(m, crtc);
3132
David Weinehall36cdd012016-08-22 13:59:31 +03003133 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003134 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 +03003135 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003136 x, y, crtc->base.cursor->state->crtc_w,
3137 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003138 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003139 intel_scaler_info(m, crtc);
3140 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003141 }
Daniel Vettercace8412014-05-22 17:56:31 +02003142
3143 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3144 yesno(!crtc->cpu_fifo_underrun_disabled),
3145 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003146 }
3147
3148 seq_printf(m, "\n");
3149 seq_printf(m, "Connector info\n");
3150 seq_printf(m, "--------------\n");
3151 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3152 intel_connector_info(m, connector);
3153 }
3154 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003155 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003156
3157 return 0;
3158}
3159
Chris Wilson1b365952016-10-04 21:11:31 +01003160static int i915_engine_info(struct seq_file *m, void *unused)
3161{
3162 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3163 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303164 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003165
Chris Wilson9c870d02016-10-24 13:42:15 +01003166 intel_runtime_pm_get(dev_priv);
3167
Akash Goel3b3f1652016-10-13 22:44:48 +05303168 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003169 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3170 struct drm_i915_gem_request *rq;
3171 struct rb_node *rb;
3172 u64 addr;
3173
3174 seq_printf(m, "%s\n", engine->name);
3175 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3176 intel_engine_get_seqno(engine),
Chris Wilson73cb9702016-10-28 13:58:46 +01003177 engine->timeline->last_submitted_seqno,
Chris Wilson1b365952016-10-04 21:11:31 +01003178 engine->hangcheck.seqno,
3179 engine->hangcheck.score);
3180
3181 rcu_read_lock();
3182
3183 seq_printf(m, "\tRequests:\n");
3184
Chris Wilson73cb9702016-10-28 13:58:46 +01003185 rq = list_first_entry(&engine->timeline->requests,
3186 struct drm_i915_gem_request, link);
3187 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003188 print_request(m, rq, "\t\tfirst ");
3189
Chris Wilson73cb9702016-10-28 13:58:46 +01003190 rq = list_last_entry(&engine->timeline->requests,
3191 struct drm_i915_gem_request, link);
3192 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003193 print_request(m, rq, "\t\tlast ");
3194
3195 rq = i915_gem_find_active_request(engine);
3196 if (rq) {
3197 print_request(m, rq, "\t\tactive ");
3198 seq_printf(m,
3199 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3200 rq->head, rq->postfix, rq->tail,
3201 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3202 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3203 }
3204
3205 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3206 I915_READ(RING_START(engine->mmio_base)),
3207 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3208 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3209 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3210 rq ? rq->ring->head : 0);
3211 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3212 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3213 rq ? rq->ring->tail : 0);
3214 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3215 I915_READ(RING_CTL(engine->mmio_base)),
3216 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3217
3218 rcu_read_unlock();
3219
3220 addr = intel_engine_get_active_head(engine);
3221 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3222 upper_32_bits(addr), lower_32_bits(addr));
3223 addr = intel_engine_get_last_batch_head(engine);
3224 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3225 upper_32_bits(addr), lower_32_bits(addr));
3226
3227 if (i915.enable_execlists) {
3228 u32 ptr, read, write;
3229
3230 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3231 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3232 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3233
3234 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3235 read = GEN8_CSB_READ_PTR(ptr);
3236 write = GEN8_CSB_WRITE_PTR(ptr);
3237 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3238 read, write);
3239 if (read >= GEN8_CSB_ENTRIES)
3240 read = 0;
3241 if (write >= GEN8_CSB_ENTRIES)
3242 write = 0;
3243 if (read > write)
3244 write += GEN8_CSB_ENTRIES;
3245 while (read < write) {
3246 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3247
3248 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3249 idx,
3250 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3251 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3252 }
3253
3254 rcu_read_lock();
3255 rq = READ_ONCE(engine->execlist_port[0].request);
3256 if (rq)
3257 print_request(m, rq, "\t\tELSP[0] ");
3258 else
3259 seq_printf(m, "\t\tELSP[0] idle\n");
3260 rq = READ_ONCE(engine->execlist_port[1].request);
3261 if (rq)
3262 print_request(m, rq, "\t\tELSP[1] ");
3263 else
3264 seq_printf(m, "\t\tELSP[1] idle\n");
3265 rcu_read_unlock();
3266 } else if (INTEL_GEN(dev_priv) > 6) {
3267 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3268 I915_READ(RING_PP_DIR_BASE(engine)));
3269 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3270 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3271 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3272 I915_READ(RING_PP_DIR_DCLV(engine)));
3273 }
3274
3275 spin_lock(&b->lock);
3276 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3277 struct intel_wait *w = container_of(rb, typeof(*w), node);
3278
3279 seq_printf(m, "\t%s [%d] waiting for %x\n",
3280 w->tsk->comm, w->tsk->pid, w->seqno);
3281 }
3282 spin_unlock(&b->lock);
3283
3284 seq_puts(m, "\n");
3285 }
3286
Chris Wilson9c870d02016-10-24 13:42:15 +01003287 intel_runtime_pm_put(dev_priv);
3288
Chris Wilson1b365952016-10-04 21:11:31 +01003289 return 0;
3290}
3291
Ben Widawskye04934c2014-06-30 09:53:42 -07003292static int i915_semaphore_status(struct seq_file *m, void *unused)
3293{
David Weinehall36cdd012016-08-22 13:59:31 +03003294 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3295 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003296 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003297 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003298 enum intel_engine_id id;
3299 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003300
Chris Wilson39df9192016-07-20 13:31:57 +01003301 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003302 seq_puts(m, "Semaphores are disabled\n");
3303 return 0;
3304 }
3305
3306 ret = mutex_lock_interruptible(&dev->struct_mutex);
3307 if (ret)
3308 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003309 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003310
David Weinehall36cdd012016-08-22 13:59:31 +03003311 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003312 struct page *page;
3313 uint64_t *seqno;
3314
Chris Wilson51d545d2016-08-15 10:49:02 +01003315 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003316
3317 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303318 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003319 uint64_t offset;
3320
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003321 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003322
3323 seq_puts(m, " Last signal:");
3324 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003325 offset = id * I915_NUM_ENGINES + j;
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 seq_puts(m, " Last wait: ");
3332 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003333 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003334 seq_printf(m, "0x%08llx (0x%02llx) ",
3335 seqno[offset], offset * 8);
3336 }
3337 seq_putc(m, '\n');
3338
3339 }
3340 kunmap_atomic(seqno);
3341 } else {
3342 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303343 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003344 for (j = 0; j < num_rings; j++)
3345 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003346 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003347 seq_putc(m, '\n');
3348 }
3349
3350 seq_puts(m, "\nSync seqno:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05303351 for_each_engine(engine, dev_priv, id) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003352 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003353 seq_printf(m, " 0x%08x ",
3354 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003355 seq_putc(m, '\n');
3356 }
3357 seq_putc(m, '\n');
3358
Paulo Zanoni03872062014-07-09 14:31:57 -03003359 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003360 mutex_unlock(&dev->struct_mutex);
3361 return 0;
3362}
3363
Daniel Vetter728e29d2014-06-25 22:01:53 +03003364static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3365{
David Weinehall36cdd012016-08-22 13:59:31 +03003366 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3367 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003368 int i;
3369
3370 drm_modeset_lock_all(dev);
3371 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3372 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3373
3374 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003375 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3376 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003377 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003378 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3379 seq_printf(m, " dpll_md: 0x%08x\n",
3380 pll->config.hw_state.dpll_md);
3381 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3382 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3383 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003384 }
3385 drm_modeset_unlock_all(dev);
3386
3387 return 0;
3388}
3389
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003390static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003391{
3392 int i;
3393 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003394 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003395 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3396 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003397 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003398 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003399
Arun Siluvery888b5992014-08-26 14:44:51 +01003400 ret = mutex_lock_interruptible(&dev->struct_mutex);
3401 if (ret)
3402 return ret;
3403
3404 intel_runtime_pm_get(dev_priv);
3405
Arun Siluvery33136b02016-01-21 21:43:47 +00003406 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303407 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003408 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003409 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003410 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003411 i915_reg_t addr;
3412 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003413 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003414
Arun Siluvery33136b02016-01-21 21:43:47 +00003415 addr = workarounds->reg[i].addr;
3416 mask = workarounds->reg[i].mask;
3417 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003418 read = I915_READ(addr);
3419 ok = (value & mask) == (read & mask);
3420 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 +02003421 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003422 }
3423
3424 intel_runtime_pm_put(dev_priv);
3425 mutex_unlock(&dev->struct_mutex);
3426
3427 return 0;
3428}
3429
Damien Lespiauc5511e42014-11-04 17:06:51 +00003430static int i915_ddb_info(struct seq_file *m, void *unused)
3431{
David Weinehall36cdd012016-08-22 13:59:31 +03003432 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3433 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003434 struct skl_ddb_allocation *ddb;
3435 struct skl_ddb_entry *entry;
3436 enum pipe pipe;
3437 int plane;
3438
David Weinehall36cdd012016-08-22 13:59:31 +03003439 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003440 return 0;
3441
Damien Lespiauc5511e42014-11-04 17:06:51 +00003442 drm_modeset_lock_all(dev);
3443
3444 ddb = &dev_priv->wm.skl_hw.ddb;
3445
3446 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3447
3448 for_each_pipe(dev_priv, pipe) {
3449 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3450
Matt Roper8b364b42016-10-26 15:51:28 -07003451 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003452 entry = &ddb->plane[pipe][plane];
3453 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3454 entry->start, entry->end,
3455 skl_ddb_entry_size(entry));
3456 }
3457
Matt Roper4969d332015-09-24 15:53:10 -07003458 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003459 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3460 entry->end, skl_ddb_entry_size(entry));
3461 }
3462
3463 drm_modeset_unlock_all(dev);
3464
3465 return 0;
3466}
3467
Vandana Kannana54746e2015-03-03 20:53:10 +05303468static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003469 struct drm_device *dev,
3470 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303471{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003472 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303473 struct i915_drrs *drrs = &dev_priv->drrs;
3474 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003475 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303476
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003477 drm_for_each_connector(connector, dev) {
3478 if (connector->state->crtc != &intel_crtc->base)
3479 continue;
3480
3481 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303482 }
3483
3484 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3485 seq_puts(m, "\tVBT: DRRS_type: Static");
3486 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3487 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3488 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3489 seq_puts(m, "\tVBT: DRRS_type: None");
3490 else
3491 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3492
3493 seq_puts(m, "\n\n");
3494
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003495 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303496 struct intel_panel *panel;
3497
3498 mutex_lock(&drrs->mutex);
3499 /* DRRS Supported */
3500 seq_puts(m, "\tDRRS Supported: Yes\n");
3501
3502 /* disable_drrs() will make drrs->dp NULL */
3503 if (!drrs->dp) {
3504 seq_puts(m, "Idleness DRRS: Disabled");
3505 mutex_unlock(&drrs->mutex);
3506 return;
3507 }
3508
3509 panel = &drrs->dp->attached_connector->panel;
3510 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3511 drrs->busy_frontbuffer_bits);
3512
3513 seq_puts(m, "\n\t\t");
3514 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3515 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3516 vrefresh = panel->fixed_mode->vrefresh;
3517 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3518 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3519 vrefresh = panel->downclock_mode->vrefresh;
3520 } else {
3521 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3522 drrs->refresh_rate_type);
3523 mutex_unlock(&drrs->mutex);
3524 return;
3525 }
3526 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3527
3528 seq_puts(m, "\n\t\t");
3529 mutex_unlock(&drrs->mutex);
3530 } else {
3531 /* DRRS not supported. Print the VBT parameter*/
3532 seq_puts(m, "\tDRRS Supported : No");
3533 }
3534 seq_puts(m, "\n");
3535}
3536
3537static int i915_drrs_status(struct seq_file *m, void *unused)
3538{
David Weinehall36cdd012016-08-22 13:59:31 +03003539 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3540 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303541 struct intel_crtc *intel_crtc;
3542 int active_crtc_cnt = 0;
3543
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003544 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303545 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003546 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303547 active_crtc_cnt++;
3548 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3549
3550 drrs_status_per_crtc(m, dev, intel_crtc);
3551 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303552 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003553 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303554
3555 if (!active_crtc_cnt)
3556 seq_puts(m, "No active crtc found\n");
3557
3558 return 0;
3559}
3560
Damien Lespiau07144422013-10-15 18:55:40 +01003561struct pipe_crc_info {
3562 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003563 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003564 enum pipe pipe;
3565};
3566
Dave Airlie11bed952014-05-12 15:22:27 +10003567static int i915_dp_mst_info(struct seq_file *m, void *unused)
3568{
David Weinehall36cdd012016-08-22 13:59:31 +03003569 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3570 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003571 struct intel_encoder *intel_encoder;
3572 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003573 struct drm_connector *connector;
3574
Dave Airlie11bed952014-05-12 15:22:27 +10003575 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003576 drm_for_each_connector(connector, dev) {
3577 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003578 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003579
3580 intel_encoder = intel_attached_encoder(connector);
3581 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3582 continue;
3583
3584 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003585 if (!intel_dig_port->dp.can_mst)
3586 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003587
Jim Bride40ae80c2016-04-14 10:18:37 -07003588 seq_printf(m, "MST Source Port %c\n",
3589 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003590 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3591 }
3592 drm_modeset_unlock_all(dev);
3593 return 0;
3594}
3595
Damien Lespiau07144422013-10-15 18:55:40 +01003596static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003597{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003598 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003599 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003600 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3601
David Weinehall36cdd012016-08-22 13:59:31 +03003602 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003603 return -ENODEV;
3604
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003605 spin_lock_irq(&pipe_crc->lock);
3606
3607 if (pipe_crc->opened) {
3608 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003609 return -EBUSY; /* already open */
3610 }
3611
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003612 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003613 filep->private_data = inode->i_private;
3614
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003615 spin_unlock_irq(&pipe_crc->lock);
3616
Damien Lespiau07144422013-10-15 18:55:40 +01003617 return 0;
3618}
3619
3620static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3621{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003622 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003623 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003624 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3625
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003626 spin_lock_irq(&pipe_crc->lock);
3627 pipe_crc->opened = false;
3628 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003629
Damien Lespiau07144422013-10-15 18:55:40 +01003630 return 0;
3631}
3632
3633/* (6 fields, 8 chars each, space separated (5) + '\n') */
3634#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3635/* account for \'0' */
3636#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3637
3638static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3639{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003640 assert_spin_locked(&pipe_crc->lock);
3641 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3642 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003643}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003644
Damien Lespiau07144422013-10-15 18:55:40 +01003645static ssize_t
3646i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3647 loff_t *pos)
3648{
3649 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003650 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003651 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3652 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003653 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003654 ssize_t bytes_read;
3655
3656 /*
3657 * Don't allow user space to provide buffers not big enough to hold
3658 * a line of data.
3659 */
3660 if (count < PIPE_CRC_LINE_LEN)
3661 return -EINVAL;
3662
3663 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3664 return 0;
3665
3666 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003667 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003668 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003669 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003670
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003671 if (filep->f_flags & O_NONBLOCK) {
3672 spin_unlock_irq(&pipe_crc->lock);
3673 return -EAGAIN;
3674 }
3675
3676 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3677 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3678 if (ret) {
3679 spin_unlock_irq(&pipe_crc->lock);
3680 return ret;
3681 }
Damien Lespiau07144422013-10-15 18:55:40 +01003682 }
3683
3684 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003685 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003686
Damien Lespiau07144422013-10-15 18:55:40 +01003687 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003688 while (n_entries > 0) {
3689 struct intel_pipe_crc_entry *entry =
3690 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003691
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003692 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3693 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3694 break;
3695
3696 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3697 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3698
Damien Lespiau07144422013-10-15 18:55:40 +01003699 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3700 "%8u %8x %8x %8x %8x %8x\n",
3701 entry->frame, entry->crc[0],
3702 entry->crc[1], entry->crc[2],
3703 entry->crc[3], entry->crc[4]);
3704
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003705 spin_unlock_irq(&pipe_crc->lock);
3706
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003707 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003708 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003709
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003710 user_buf += PIPE_CRC_LINE_LEN;
3711 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003712
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003713 spin_lock_irq(&pipe_crc->lock);
3714 }
3715
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003716 spin_unlock_irq(&pipe_crc->lock);
3717
Damien Lespiau07144422013-10-15 18:55:40 +01003718 return bytes_read;
3719}
3720
3721static const struct file_operations i915_pipe_crc_fops = {
3722 .owner = THIS_MODULE,
3723 .open = i915_pipe_crc_open,
3724 .read = i915_pipe_crc_read,
3725 .release = i915_pipe_crc_release,
3726};
3727
3728static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3729 {
3730 .name = "i915_pipe_A_crc",
3731 .pipe = PIPE_A,
3732 },
3733 {
3734 .name = "i915_pipe_B_crc",
3735 .pipe = PIPE_B,
3736 },
3737 {
3738 .name = "i915_pipe_C_crc",
3739 .pipe = PIPE_C,
3740 },
3741};
3742
3743static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3744 enum pipe pipe)
3745{
David Weinehall36cdd012016-08-22 13:59:31 +03003746 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003747 struct dentry *ent;
3748 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3749
David Weinehall36cdd012016-08-22 13:59:31 +03003750 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003751 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3752 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003753 if (!ent)
3754 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003755
3756 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003757}
3758
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003759static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003760 "none",
3761 "plane1",
3762 "plane2",
3763 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003764 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003765 "TV",
3766 "DP-B",
3767 "DP-C",
3768 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003769 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003770};
3771
3772static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3773{
3774 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3775 return pipe_crc_sources[source];
3776}
3777
Damien Lespiaubd9db022013-10-15 18:55:36 +01003778static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003779{
David Weinehall36cdd012016-08-22 13:59:31 +03003780 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003781 int i;
3782
3783 for (i = 0; i < I915_MAX_PIPES; i++)
3784 seq_printf(m, "%c %s\n", pipe_name(i),
3785 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3786
3787 return 0;
3788}
3789
Damien Lespiaubd9db022013-10-15 18:55:36 +01003790static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003791{
David Weinehall36cdd012016-08-22 13:59:31 +03003792 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003793}
3794
Daniel Vetter46a19182013-11-01 10:50:20 +01003795static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003796 uint32_t *val)
3797{
Daniel Vetter46a19182013-11-01 10:50:20 +01003798 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3799 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3800
3801 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003802 case INTEL_PIPE_CRC_SOURCE_PIPE:
3803 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3804 break;
3805 case INTEL_PIPE_CRC_SOURCE_NONE:
3806 *val = 0;
3807 break;
3808 default:
3809 return -EINVAL;
3810 }
3811
3812 return 0;
3813}
3814
David Weinehall36cdd012016-08-22 13:59:31 +03003815static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3816 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003817 enum intel_pipe_crc_source *source)
3818{
David Weinehall36cdd012016-08-22 13:59:31 +03003819 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003820 struct intel_encoder *encoder;
3821 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003822 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003823 int ret = 0;
3824
3825 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3826
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003827 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003828 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003829 if (!encoder->base.crtc)
3830 continue;
3831
3832 crtc = to_intel_crtc(encoder->base.crtc);
3833
3834 if (crtc->pipe != pipe)
3835 continue;
3836
3837 switch (encoder->type) {
3838 case INTEL_OUTPUT_TVOUT:
3839 *source = INTEL_PIPE_CRC_SOURCE_TV;
3840 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003841 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003842 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003843 dig_port = enc_to_dig_port(&encoder->base);
3844 switch (dig_port->port) {
3845 case PORT_B:
3846 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3847 break;
3848 case PORT_C:
3849 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3850 break;
3851 case PORT_D:
3852 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3853 break;
3854 default:
3855 WARN(1, "nonexisting DP port %c\n",
3856 port_name(dig_port->port));
3857 break;
3858 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003859 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003860 default:
3861 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003862 }
3863 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003864 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003865
3866 return ret;
3867}
3868
David Weinehall36cdd012016-08-22 13:59:31 +03003869static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003870 enum pipe pipe,
3871 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003872 uint32_t *val)
3873{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003874 bool need_stable_symbols = false;
3875
Daniel Vetter46a19182013-11-01 10:50:20 +01003876 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003877 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003878 if (ret)
3879 return ret;
3880 }
3881
3882 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003883 case INTEL_PIPE_CRC_SOURCE_PIPE:
3884 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3885 break;
3886 case INTEL_PIPE_CRC_SOURCE_DP_B:
3887 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003888 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003889 break;
3890 case INTEL_PIPE_CRC_SOURCE_DP_C:
3891 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003892 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003893 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003894 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003895 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003896 return -EINVAL;
3897 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3898 need_stable_symbols = true;
3899 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003900 case INTEL_PIPE_CRC_SOURCE_NONE:
3901 *val = 0;
3902 break;
3903 default:
3904 return -EINVAL;
3905 }
3906
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003907 /*
3908 * When the pipe CRC tap point is after the transcoders we need
3909 * to tweak symbol-level features to produce a deterministic series of
3910 * symbols for a given frame. We need to reset those features only once
3911 * a frame (instead of every nth symbol):
3912 * - DC-balance: used to ensure a better clock recovery from the data
3913 * link (SDVO)
3914 * - DisplayPort scrambling: used for EMI reduction
3915 */
3916 if (need_stable_symbols) {
3917 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3918
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003919 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003920 switch (pipe) {
3921 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003922 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003923 break;
3924 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003925 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003926 break;
3927 case PIPE_C:
3928 tmp |= PIPE_C_SCRAMBLE_RESET;
3929 break;
3930 default:
3931 return -EINVAL;
3932 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003933 I915_WRITE(PORT_DFT2_G4X, tmp);
3934 }
3935
Daniel Vetter7ac01292013-10-18 16:37:06 +02003936 return 0;
3937}
3938
David Weinehall36cdd012016-08-22 13:59:31 +03003939static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003940 enum pipe pipe,
3941 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003942 uint32_t *val)
3943{
Daniel Vetter84093602013-11-01 10:50:21 +01003944 bool need_stable_symbols = false;
3945
Daniel Vetter46a19182013-11-01 10:50:20 +01003946 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003947 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003948 if (ret)
3949 return ret;
3950 }
3951
3952 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003953 case INTEL_PIPE_CRC_SOURCE_PIPE:
3954 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3955 break;
3956 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003957 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003958 return -EINVAL;
3959 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3960 break;
3961 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003962 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003963 return -EINVAL;
3964 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003965 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003966 break;
3967 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003968 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003969 return -EINVAL;
3970 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003971 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003972 break;
3973 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003974 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003975 return -EINVAL;
3976 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003977 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003978 break;
3979 case INTEL_PIPE_CRC_SOURCE_NONE:
3980 *val = 0;
3981 break;
3982 default:
3983 return -EINVAL;
3984 }
3985
Daniel Vetter84093602013-11-01 10:50:21 +01003986 /*
3987 * When the pipe CRC tap point is after the transcoders we need
3988 * to tweak symbol-level features to produce a deterministic series of
3989 * symbols for a given frame. We need to reset those features only once
3990 * a frame (instead of every nth symbol):
3991 * - DC-balance: used to ensure a better clock recovery from the data
3992 * link (SDVO)
3993 * - DisplayPort scrambling: used for EMI reduction
3994 */
3995 if (need_stable_symbols) {
3996 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3997
David Weinehall36cdd012016-08-22 13:59:31 +03003998 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003999
4000 I915_WRITE(PORT_DFT_I9XX,
4001 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
4002
4003 if (pipe == PIPE_A)
4004 tmp |= PIPE_A_SCRAMBLE_RESET;
4005 else
4006 tmp |= PIPE_B_SCRAMBLE_RESET;
4007
4008 I915_WRITE(PORT_DFT2_G4X, tmp);
4009 }
4010
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004011 return 0;
4012}
4013
David Weinehall36cdd012016-08-22 13:59:31 +03004014static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004015 enum pipe pipe)
4016{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004017 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4018
Ville Syrjäläeb736672014-12-09 21:28:28 +02004019 switch (pipe) {
4020 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004021 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004022 break;
4023 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004024 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004025 break;
4026 case PIPE_C:
4027 tmp &= ~PIPE_C_SCRAMBLE_RESET;
4028 break;
4029 default:
4030 return;
4031 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004032 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
4033 tmp &= ~DC_BALANCE_RESET_VLV;
4034 I915_WRITE(PORT_DFT2_G4X, tmp);
4035
4036}
4037
David Weinehall36cdd012016-08-22 13:59:31 +03004038static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01004039 enum pipe pipe)
4040{
Daniel Vetter84093602013-11-01 10:50:21 +01004041 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4042
4043 if (pipe == PIPE_A)
4044 tmp &= ~PIPE_A_SCRAMBLE_RESET;
4045 else
4046 tmp &= ~PIPE_B_SCRAMBLE_RESET;
4047 I915_WRITE(PORT_DFT2_G4X, tmp);
4048
4049 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
4050 I915_WRITE(PORT_DFT_I9XX,
4051 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
4052 }
4053}
4054
Daniel Vetter46a19182013-11-01 10:50:20 +01004055static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004056 uint32_t *val)
4057{
Daniel Vetter46a19182013-11-01 10:50:20 +01004058 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4059 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4060
4061 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004062 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4063 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4064 break;
4065 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4066 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4067 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004068 case INTEL_PIPE_CRC_SOURCE_PIPE:
4069 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4070 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004071 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004072 *val = 0;
4073 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004074 default:
4075 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004076 }
4077
4078 return 0;
4079}
4080
David Weinehall36cdd012016-08-22 13:59:31 +03004081static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4082 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004083{
David Weinehall36cdd012016-08-22 13:59:31 +03004084 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004085 struct intel_crtc *crtc =
4086 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004087 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004088 struct drm_atomic_state *state;
4089 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004090
4091 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004092 state = drm_atomic_state_alloc(dev);
4093 if (!state) {
4094 ret = -ENOMEM;
4095 goto out;
4096 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004097
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004098 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4099 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4100 if (IS_ERR(pipe_config)) {
4101 ret = PTR_ERR(pipe_config);
4102 goto out;
4103 }
4104
4105 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004106 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004107 pipe_config->pch_pfit.enabled != enable)
4108 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004109
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004110 ret = drm_atomic_commit(state);
4111out:
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004112 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
Chris Wilson08536952016-10-14 13:18:18 +01004113 drm_modeset_unlock_all(dev);
4114 drm_atomic_state_put(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004115}
4116
David Weinehall36cdd012016-08-22 13:59:31 +03004117static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004118 enum pipe pipe,
4119 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004120 uint32_t *val)
4121{
Daniel Vetter46a19182013-11-01 10:50:20 +01004122 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4123 *source = INTEL_PIPE_CRC_SOURCE_PF;
4124
4125 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004126 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4127 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4128 break;
4129 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4130 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4131 break;
4132 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004133 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4134 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004135
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004136 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4137 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004138 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004139 *val = 0;
4140 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004141 default:
4142 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004143 }
4144
4145 return 0;
4146}
4147
David Weinehall36cdd012016-08-22 13:59:31 +03004148static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4149 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004150 enum intel_pipe_crc_source source)
4151{
David Weinehall36cdd012016-08-22 13:59:31 +03004152 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004153 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03004154 struct intel_crtc *crtc =
4155 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02004156 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004157 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004158 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004159
Damien Lespiaucc3da172013-10-15 18:55:31 +01004160 if (pipe_crc->source == source)
4161 return 0;
4162
Damien Lespiauae676fc2013-10-15 18:55:32 +01004163 /* forbid changing the source without going back to 'none' */
4164 if (pipe_crc->source && source)
4165 return -EINVAL;
4166
Imre Deake1296492016-02-12 18:55:17 +02004167 power_domain = POWER_DOMAIN_PIPE(pipe);
4168 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004169 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4170 return -EIO;
4171 }
4172
David Weinehall36cdd012016-08-22 13:59:31 +03004173 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004174 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004175 else if (INTEL_GEN(dev_priv) < 5)
4176 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4177 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4178 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4179 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004180 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004181 else
David Weinehall36cdd012016-08-22 13:59:31 +03004182 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004183
4184 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004185 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004186
Damien Lespiau4b584362013-10-15 18:55:33 +01004187 /* none -> real source transition */
4188 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004189 struct intel_pipe_crc_entry *entries;
4190
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004191 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4192 pipe_name(pipe), pipe_crc_source_name(source));
4193
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004194 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4195 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004196 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004197 if (!entries) {
4198 ret = -ENOMEM;
4199 goto out;
4200 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004201
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004202 /*
4203 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4204 * enabled and disabled dynamically based on package C states,
4205 * user space can't make reliable use of the CRCs, so let's just
4206 * completely disable it.
4207 */
4208 hsw_disable_ips(crtc);
4209
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004210 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004211 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004212 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004213 pipe_crc->head = 0;
4214 pipe_crc->tail = 0;
4215 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004216 }
4217
Damien Lespiaucc3da172013-10-15 18:55:31 +01004218 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004219
Daniel Vetter926321d2013-10-16 13:30:34 +02004220 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4221 POSTING_READ(PIPE_CRC_CTL(pipe));
4222
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004223 /* real source -> none transition */
4224 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004225 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004226 struct intel_crtc *crtc =
4227 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004228
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004229 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4230 pipe_name(pipe));
4231
Daniel Vettera33d7102014-06-06 08:22:08 +02004232 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004233 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004234 intel_wait_for_vblank(dev, pipe);
4235 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004236
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004237 spin_lock_irq(&pipe_crc->lock);
4238 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004239 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004240 pipe_crc->head = 0;
4241 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004242 spin_unlock_irq(&pipe_crc->lock);
4243
4244 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004245
David Weinehall36cdd012016-08-22 13:59:31 +03004246 if (IS_G4X(dev_priv))
4247 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4248 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4249 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4250 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4251 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004252
4253 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004254 }
4255
Imre Deake1296492016-02-12 18:55:17 +02004256 ret = 0;
4257
4258out:
4259 intel_display_power_put(dev_priv, power_domain);
4260
4261 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004262}
4263
4264/*
4265 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004266 * command: wsp* object wsp+ name wsp+ source wsp*
4267 * object: 'pipe'
4268 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004269 * source: (none | plane1 | plane2 | pf)
4270 * wsp: (#0x20 | #0x9 | #0xA)+
4271 *
4272 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004273 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4274 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004275 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004276static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004277{
4278 int n_words = 0;
4279
4280 while (*buf) {
4281 char *end;
4282
4283 /* skip leading white space */
4284 buf = skip_spaces(buf);
4285 if (!*buf)
4286 break; /* end of buffer */
4287
4288 /* find end of word */
4289 for (end = buf; *end && !isspace(*end); end++)
4290 ;
4291
4292 if (n_words == max_words) {
4293 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4294 max_words);
4295 return -EINVAL; /* ran out of words[] before bytes */
4296 }
4297
4298 if (*end)
4299 *end++ = '\0';
4300 words[n_words++] = buf;
4301 buf = end;
4302 }
4303
4304 return n_words;
4305}
4306
Damien Lespiaub94dec82013-10-15 18:55:35 +01004307enum intel_pipe_crc_object {
4308 PIPE_CRC_OBJECT_PIPE,
4309};
4310
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004311static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004312 "pipe",
4313};
4314
4315static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004316display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004317{
4318 int i;
4319
4320 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4321 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004322 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004323 return 0;
4324 }
4325
4326 return -EINVAL;
4327}
4328
Damien Lespiaubd9db022013-10-15 18:55:36 +01004329static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004330{
4331 const char name = buf[0];
4332
4333 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4334 return -EINVAL;
4335
4336 *pipe = name - 'A';
4337
4338 return 0;
4339}
4340
4341static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004342display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004343{
4344 int i;
4345
4346 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4347 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004348 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004349 return 0;
4350 }
4351
4352 return -EINVAL;
4353}
4354
David Weinehall36cdd012016-08-22 13:59:31 +03004355static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4356 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004357{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004358#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004359 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004360 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004361 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004362 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004363 enum intel_pipe_crc_source source;
4364
Damien Lespiaubd9db022013-10-15 18:55:36 +01004365 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004366 if (n_words != N_WORDS) {
4367 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4368 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004369 return -EINVAL;
4370 }
4371
Damien Lespiaubd9db022013-10-15 18:55:36 +01004372 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004373 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004374 return -EINVAL;
4375 }
4376
Damien Lespiaubd9db022013-10-15 18:55:36 +01004377 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004378 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4379 return -EINVAL;
4380 }
4381
Damien Lespiaubd9db022013-10-15 18:55:36 +01004382 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004383 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004384 return -EINVAL;
4385 }
4386
David Weinehall36cdd012016-08-22 13:59:31 +03004387 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004388}
4389
Damien Lespiaubd9db022013-10-15 18:55:36 +01004390static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4391 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004392{
4393 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004394 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004395 char *tmpbuf;
4396 int ret;
4397
4398 if (len == 0)
4399 return 0;
4400
4401 if (len > PAGE_SIZE - 1) {
4402 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4403 PAGE_SIZE);
4404 return -E2BIG;
4405 }
4406
4407 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4408 if (!tmpbuf)
4409 return -ENOMEM;
4410
4411 if (copy_from_user(tmpbuf, ubuf, len)) {
4412 ret = -EFAULT;
4413 goto out;
4414 }
4415 tmpbuf[len] = '\0';
4416
David Weinehall36cdd012016-08-22 13:59:31 +03004417 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004418
4419out:
4420 kfree(tmpbuf);
4421 if (ret < 0)
4422 return ret;
4423
4424 *offp += len;
4425 return len;
4426}
4427
Damien Lespiaubd9db022013-10-15 18:55:36 +01004428static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004429 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004430 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004431 .read = seq_read,
4432 .llseek = seq_lseek,
4433 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004434 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004435};
4436
Todd Previteeb3394fa2015-04-18 00:04:19 -07004437static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004438 const char __user *ubuf,
4439 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004440{
4441 char *input_buffer;
4442 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004443 struct drm_device *dev;
4444 struct drm_connector *connector;
4445 struct list_head *connector_list;
4446 struct intel_dp *intel_dp;
4447 int val = 0;
4448
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304449 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004450
Todd Previteeb3394fa2015-04-18 00:04:19 -07004451 connector_list = &dev->mode_config.connector_list;
4452
4453 if (len == 0)
4454 return 0;
4455
4456 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4457 if (!input_buffer)
4458 return -ENOMEM;
4459
4460 if (copy_from_user(input_buffer, ubuf, len)) {
4461 status = -EFAULT;
4462 goto out;
4463 }
4464
4465 input_buffer[len] = '\0';
4466 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4467
4468 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004469 if (connector->connector_type !=
4470 DRM_MODE_CONNECTOR_DisplayPort)
4471 continue;
4472
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304473 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004474 connector->encoder != NULL) {
4475 intel_dp = enc_to_intel_dp(connector->encoder);
4476 status = kstrtoint(input_buffer, 10, &val);
4477 if (status < 0)
4478 goto out;
4479 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4480 /* To prevent erroneous activation of the compliance
4481 * testing code, only accept an actual value of 1 here
4482 */
4483 if (val == 1)
4484 intel_dp->compliance_test_active = 1;
4485 else
4486 intel_dp->compliance_test_active = 0;
4487 }
4488 }
4489out:
4490 kfree(input_buffer);
4491 if (status < 0)
4492 return status;
4493
4494 *offp += len;
4495 return len;
4496}
4497
4498static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4499{
4500 struct drm_device *dev = m->private;
4501 struct drm_connector *connector;
4502 struct list_head *connector_list = &dev->mode_config.connector_list;
4503 struct intel_dp *intel_dp;
4504
Todd Previteeb3394fa2015-04-18 00:04:19 -07004505 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004506 if (connector->connector_type !=
4507 DRM_MODE_CONNECTOR_DisplayPort)
4508 continue;
4509
4510 if (connector->status == connector_status_connected &&
4511 connector->encoder != NULL) {
4512 intel_dp = enc_to_intel_dp(connector->encoder);
4513 if (intel_dp->compliance_test_active)
4514 seq_puts(m, "1");
4515 else
4516 seq_puts(m, "0");
4517 } else
4518 seq_puts(m, "0");
4519 }
4520
4521 return 0;
4522}
4523
4524static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004525 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004526{
David Weinehall36cdd012016-08-22 13:59:31 +03004527 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004528
David Weinehall36cdd012016-08-22 13:59:31 +03004529 return single_open(file, i915_displayport_test_active_show,
4530 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004531}
4532
4533static const struct file_operations i915_displayport_test_active_fops = {
4534 .owner = THIS_MODULE,
4535 .open = i915_displayport_test_active_open,
4536 .read = seq_read,
4537 .llseek = seq_lseek,
4538 .release = single_release,
4539 .write = i915_displayport_test_active_write
4540};
4541
4542static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4543{
4544 struct drm_device *dev = m->private;
4545 struct drm_connector *connector;
4546 struct list_head *connector_list = &dev->mode_config.connector_list;
4547 struct intel_dp *intel_dp;
4548
Todd Previteeb3394fa2015-04-18 00:04:19 -07004549 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004550 if (connector->connector_type !=
4551 DRM_MODE_CONNECTOR_DisplayPort)
4552 continue;
4553
4554 if (connector->status == connector_status_connected &&
4555 connector->encoder != NULL) {
4556 intel_dp = enc_to_intel_dp(connector->encoder);
4557 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4558 } else
4559 seq_puts(m, "0");
4560 }
4561
4562 return 0;
4563}
4564static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004565 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004566{
David Weinehall36cdd012016-08-22 13:59:31 +03004567 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004568
David Weinehall36cdd012016-08-22 13:59:31 +03004569 return single_open(file, i915_displayport_test_data_show,
4570 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004571}
4572
4573static const struct file_operations i915_displayport_test_data_fops = {
4574 .owner = THIS_MODULE,
4575 .open = i915_displayport_test_data_open,
4576 .read = seq_read,
4577 .llseek = seq_lseek,
4578 .release = single_release
4579};
4580
4581static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4582{
4583 struct drm_device *dev = m->private;
4584 struct drm_connector *connector;
4585 struct list_head *connector_list = &dev->mode_config.connector_list;
4586 struct intel_dp *intel_dp;
4587
Todd Previteeb3394fa2015-04-18 00:04:19 -07004588 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004589 if (connector->connector_type !=
4590 DRM_MODE_CONNECTOR_DisplayPort)
4591 continue;
4592
4593 if (connector->status == connector_status_connected &&
4594 connector->encoder != NULL) {
4595 intel_dp = enc_to_intel_dp(connector->encoder);
4596 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4597 } else
4598 seq_puts(m, "0");
4599 }
4600
4601 return 0;
4602}
4603
4604static int i915_displayport_test_type_open(struct inode *inode,
4605 struct file *file)
4606{
David Weinehall36cdd012016-08-22 13:59:31 +03004607 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004608
David Weinehall36cdd012016-08-22 13:59:31 +03004609 return single_open(file, i915_displayport_test_type_show,
4610 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004611}
4612
4613static const struct file_operations i915_displayport_test_type_fops = {
4614 .owner = THIS_MODULE,
4615 .open = i915_displayport_test_type_open,
4616 .read = seq_read,
4617 .llseek = seq_lseek,
4618 .release = single_release
4619};
4620
Damien Lespiau97e94b22014-11-04 17:06:50 +00004621static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004622{
David Weinehall36cdd012016-08-22 13:59:31 +03004623 struct drm_i915_private *dev_priv = m->private;
4624 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004625 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004626 int num_levels;
4627
David Weinehall36cdd012016-08-22 13:59:31 +03004628 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004629 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004630 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004631 num_levels = 1;
4632 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004633 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004634
4635 drm_modeset_lock_all(dev);
4636
4637 for (level = 0; level < num_levels; level++) {
4638 unsigned int latency = wm[level];
4639
Damien Lespiau97e94b22014-11-04 17:06:50 +00004640 /*
4641 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004642 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004643 */
David Weinehall36cdd012016-08-22 13:59:31 +03004644 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4645 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004646 latency *= 10;
4647 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004648 latency *= 5;
4649
4650 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004651 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004652 }
4653
4654 drm_modeset_unlock_all(dev);
4655}
4656
4657static int pri_wm_latency_show(struct seq_file *m, void *data)
4658{
David Weinehall36cdd012016-08-22 13:59:31 +03004659 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004660 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004661
David Weinehall36cdd012016-08-22 13:59:31 +03004662 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004663 latencies = dev_priv->wm.skl_latency;
4664 else
David Weinehall36cdd012016-08-22 13:59:31 +03004665 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004666
4667 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004668
4669 return 0;
4670}
4671
4672static int spr_wm_latency_show(struct seq_file *m, void *data)
4673{
David Weinehall36cdd012016-08-22 13:59:31 +03004674 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004675 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004676
David Weinehall36cdd012016-08-22 13:59:31 +03004677 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004678 latencies = dev_priv->wm.skl_latency;
4679 else
David Weinehall36cdd012016-08-22 13:59:31 +03004680 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004681
4682 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004683
4684 return 0;
4685}
4686
4687static int cur_wm_latency_show(struct seq_file *m, void *data)
4688{
David Weinehall36cdd012016-08-22 13:59:31 +03004689 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004690 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004691
David Weinehall36cdd012016-08-22 13:59:31 +03004692 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004693 latencies = dev_priv->wm.skl_latency;
4694 else
David Weinehall36cdd012016-08-22 13:59:31 +03004695 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004696
4697 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004698
4699 return 0;
4700}
4701
4702static int pri_wm_latency_open(struct inode *inode, struct file *file)
4703{
David Weinehall36cdd012016-08-22 13:59:31 +03004704 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004705
David Weinehall36cdd012016-08-22 13:59:31 +03004706 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004707 return -ENODEV;
4708
David Weinehall36cdd012016-08-22 13:59:31 +03004709 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004710}
4711
4712static int spr_wm_latency_open(struct inode *inode, struct file *file)
4713{
David Weinehall36cdd012016-08-22 13:59:31 +03004714 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004715
David Weinehall36cdd012016-08-22 13:59:31 +03004716 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004717 return -ENODEV;
4718
David Weinehall36cdd012016-08-22 13:59:31 +03004719 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004720}
4721
4722static int cur_wm_latency_open(struct inode *inode, struct file *file)
4723{
David Weinehall36cdd012016-08-22 13:59:31 +03004724 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004725
David Weinehall36cdd012016-08-22 13:59:31 +03004726 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004727 return -ENODEV;
4728
David Weinehall36cdd012016-08-22 13:59:31 +03004729 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004730}
4731
4732static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004733 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004734{
4735 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004736 struct drm_i915_private *dev_priv = m->private;
4737 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004738 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004739 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004740 int level;
4741 int ret;
4742 char tmp[32];
4743
David Weinehall36cdd012016-08-22 13:59:31 +03004744 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004745 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004746 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004747 num_levels = 1;
4748 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004749 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004750
Ville Syrjälä369a1342014-01-22 14:36:08 +02004751 if (len >= sizeof(tmp))
4752 return -EINVAL;
4753
4754 if (copy_from_user(tmp, ubuf, len))
4755 return -EFAULT;
4756
4757 tmp[len] = '\0';
4758
Damien Lespiau97e94b22014-11-04 17:06:50 +00004759 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4760 &new[0], &new[1], &new[2], &new[3],
4761 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004762 if (ret != num_levels)
4763 return -EINVAL;
4764
4765 drm_modeset_lock_all(dev);
4766
4767 for (level = 0; level < num_levels; level++)
4768 wm[level] = new[level];
4769
4770 drm_modeset_unlock_all(dev);
4771
4772 return len;
4773}
4774
4775
4776static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4777 size_t len, loff_t *offp)
4778{
4779 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004780 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004781 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004782
David Weinehall36cdd012016-08-22 13:59:31 +03004783 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004784 latencies = dev_priv->wm.skl_latency;
4785 else
David Weinehall36cdd012016-08-22 13:59:31 +03004786 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004787
4788 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004789}
4790
4791static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4792 size_t len, loff_t *offp)
4793{
4794 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004795 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004796 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004797
David Weinehall36cdd012016-08-22 13:59:31 +03004798 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004799 latencies = dev_priv->wm.skl_latency;
4800 else
David Weinehall36cdd012016-08-22 13:59:31 +03004801 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004802
4803 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004804}
4805
4806static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4807 size_t len, loff_t *offp)
4808{
4809 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004810 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004811 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004812
David Weinehall36cdd012016-08-22 13:59:31 +03004813 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004814 latencies = dev_priv->wm.skl_latency;
4815 else
David Weinehall36cdd012016-08-22 13:59:31 +03004816 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004817
4818 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004819}
4820
4821static const struct file_operations i915_pri_wm_latency_fops = {
4822 .owner = THIS_MODULE,
4823 .open = pri_wm_latency_open,
4824 .read = seq_read,
4825 .llseek = seq_lseek,
4826 .release = single_release,
4827 .write = pri_wm_latency_write
4828};
4829
4830static const struct file_operations i915_spr_wm_latency_fops = {
4831 .owner = THIS_MODULE,
4832 .open = spr_wm_latency_open,
4833 .read = seq_read,
4834 .llseek = seq_lseek,
4835 .release = single_release,
4836 .write = spr_wm_latency_write
4837};
4838
4839static const struct file_operations i915_cur_wm_latency_fops = {
4840 .owner = THIS_MODULE,
4841 .open = cur_wm_latency_open,
4842 .read = seq_read,
4843 .llseek = seq_lseek,
4844 .release = single_release,
4845 .write = cur_wm_latency_write
4846};
4847
Kees Cook647416f2013-03-10 14:10:06 -07004848static int
4849i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004850{
David Weinehall36cdd012016-08-22 13:59:31 +03004851 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004852
Chris Wilsond98c52c2016-04-13 17:35:05 +01004853 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004854
Kees Cook647416f2013-03-10 14:10:06 -07004855 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004856}
4857
Kees Cook647416f2013-03-10 14:10:06 -07004858static int
4859i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004860{
David Weinehall36cdd012016-08-22 13:59:31 +03004861 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004862
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004863 /*
4864 * There is no safeguard against this debugfs entry colliding
4865 * with the hangcheck calling same i915_handle_error() in
4866 * parallel, causing an explosion. For now we assume that the
4867 * test harness is responsible enough not to inject gpu hangs
4868 * while it is writing to 'i915_wedged'
4869 */
4870
Chris Wilsond98c52c2016-04-13 17:35:05 +01004871 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004872 return -EAGAIN;
4873
Chris Wilsonc0336662016-05-06 15:40:21 +01004874 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004875 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004876
Kees Cook647416f2013-03-10 14:10:06 -07004877 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004878}
4879
Kees Cook647416f2013-03-10 14:10:06 -07004880DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4881 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004882 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004883
Kees Cook647416f2013-03-10 14:10:06 -07004884static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004885i915_ring_missed_irq_get(void *data, u64 *val)
4886{
David Weinehall36cdd012016-08-22 13:59:31 +03004887 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004888
4889 *val = dev_priv->gpu_error.missed_irq_rings;
4890 return 0;
4891}
4892
4893static int
4894i915_ring_missed_irq_set(void *data, u64 val)
4895{
David Weinehall36cdd012016-08-22 13:59:31 +03004896 struct drm_i915_private *dev_priv = data;
4897 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004898 int ret;
4899
4900 /* Lock against concurrent debugfs callers */
4901 ret = mutex_lock_interruptible(&dev->struct_mutex);
4902 if (ret)
4903 return ret;
4904 dev_priv->gpu_error.missed_irq_rings = val;
4905 mutex_unlock(&dev->struct_mutex);
4906
4907 return 0;
4908}
4909
4910DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4911 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4912 "0x%08llx\n");
4913
4914static int
4915i915_ring_test_irq_get(void *data, u64 *val)
4916{
David Weinehall36cdd012016-08-22 13:59:31 +03004917 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004918
4919 *val = dev_priv->gpu_error.test_irq_rings;
4920
4921 return 0;
4922}
4923
4924static int
4925i915_ring_test_irq_set(void *data, u64 val)
4926{
David Weinehall36cdd012016-08-22 13:59:31 +03004927 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004928
Chris Wilson3a122c22016-06-17 14:35:05 +01004929 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004930 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004931 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004932
4933 return 0;
4934}
4935
4936DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4937 i915_ring_test_irq_get, i915_ring_test_irq_set,
4938 "0x%08llx\n");
4939
Chris Wilsondd624af2013-01-15 12:39:35 +00004940#define DROP_UNBOUND 0x1
4941#define DROP_BOUND 0x2
4942#define DROP_RETIRE 0x4
4943#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004944#define DROP_FREED 0x10
4945#define DROP_ALL (DROP_UNBOUND | \
4946 DROP_BOUND | \
4947 DROP_RETIRE | \
4948 DROP_ACTIVE | \
4949 DROP_FREED)
Kees Cook647416f2013-03-10 14:10:06 -07004950static int
4951i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004952{
Kees Cook647416f2013-03-10 14:10:06 -07004953 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004954
Kees Cook647416f2013-03-10 14:10:06 -07004955 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004956}
4957
Kees Cook647416f2013-03-10 14:10:06 -07004958static int
4959i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004960{
David Weinehall36cdd012016-08-22 13:59:31 +03004961 struct drm_i915_private *dev_priv = data;
4962 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004963 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004964
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004965 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004966
4967 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4968 * on ioctls on -EAGAIN. */
4969 ret = mutex_lock_interruptible(&dev->struct_mutex);
4970 if (ret)
4971 return ret;
4972
4973 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004974 ret = i915_gem_wait_for_idle(dev_priv,
4975 I915_WAIT_INTERRUPTIBLE |
4976 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004977 if (ret)
4978 goto unlock;
4979 }
4980
4981 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004982 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004983
Chris Wilson21ab4e72014-09-09 11:16:08 +01004984 if (val & DROP_BOUND)
4985 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004986
Chris Wilson21ab4e72014-09-09 11:16:08 +01004987 if (val & DROP_UNBOUND)
4988 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004989
4990unlock:
4991 mutex_unlock(&dev->struct_mutex);
4992
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004993 if (val & DROP_FREED) {
4994 synchronize_rcu();
4995 flush_work(&dev_priv->mm.free_work);
4996 }
4997
Kees Cook647416f2013-03-10 14:10:06 -07004998 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004999}
5000
Kees Cook647416f2013-03-10 14:10:06 -07005001DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
5002 i915_drop_caches_get, i915_drop_caches_set,
5003 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00005004
Kees Cook647416f2013-03-10 14:10:06 -07005005static int
5006i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005007{
David Weinehall36cdd012016-08-22 13:59:31 +03005008 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005009
David Weinehall36cdd012016-08-22 13:59:31 +03005010 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005011 return -ENODEV;
5012
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005013 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005014 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005015}
5016
Kees Cook647416f2013-03-10 14:10:06 -07005017static int
5018i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005019{
David Weinehall36cdd012016-08-22 13:59:31 +03005020 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305021 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005022 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005023
David Weinehall36cdd012016-08-22 13:59:31 +03005024 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005025 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005026
Kees Cook647416f2013-03-10 14:10:06 -07005027 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005028
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005029 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005030 if (ret)
5031 return ret;
5032
Jesse Barnes358733e2011-07-27 11:53:01 -07005033 /*
5034 * Turbo will still be enabled, but won't go above the set value.
5035 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305036 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005037
Akash Goelbc4d91f2015-02-26 16:09:47 +05305038 hw_max = dev_priv->rps.max_freq;
5039 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005040
Ben Widawskyb39fb292014-03-19 18:31:11 -07005041 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005042 mutex_unlock(&dev_priv->rps.hw_lock);
5043 return -EINVAL;
5044 }
5045
Ben Widawskyb39fb292014-03-19 18:31:11 -07005046 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005047
Chris Wilsondc979972016-05-10 14:10:04 +01005048 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005049
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005050 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005051
Kees Cook647416f2013-03-10 14:10:06 -07005052 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005053}
5054
Kees Cook647416f2013-03-10 14:10:06 -07005055DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5056 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005057 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005058
Kees Cook647416f2013-03-10 14:10:06 -07005059static int
5060i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005061{
David Weinehall36cdd012016-08-22 13:59:31 +03005062 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005063
Chris Wilson62e1baa2016-07-13 09:10:36 +01005064 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005065 return -ENODEV;
5066
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005067 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005068 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005069}
5070
Kees Cook647416f2013-03-10 14:10:06 -07005071static int
5072i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005073{
David Weinehall36cdd012016-08-22 13:59:31 +03005074 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305075 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005076 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005077
Chris Wilson62e1baa2016-07-13 09:10:36 +01005078 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005079 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005080
Kees Cook647416f2013-03-10 14:10:06 -07005081 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005082
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005083 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005084 if (ret)
5085 return ret;
5086
Jesse Barnes1523c312012-05-25 12:34:54 -07005087 /*
5088 * Turbo will still be enabled, but won't go below the set value.
5089 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305090 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005091
Akash Goelbc4d91f2015-02-26 16:09:47 +05305092 hw_max = dev_priv->rps.max_freq;
5093 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005094
David Weinehall36cdd012016-08-22 13:59:31 +03005095 if (val < hw_min ||
5096 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005097 mutex_unlock(&dev_priv->rps.hw_lock);
5098 return -EINVAL;
5099 }
5100
Ben Widawskyb39fb292014-03-19 18:31:11 -07005101 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005102
Chris Wilsondc979972016-05-10 14:10:04 +01005103 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005104
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005105 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005106
Kees Cook647416f2013-03-10 14:10:06 -07005107 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005108}
5109
Kees Cook647416f2013-03-10 14:10:06 -07005110DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5111 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005112 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005113
Kees Cook647416f2013-03-10 14:10:06 -07005114static int
5115i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005116{
David Weinehall36cdd012016-08-22 13:59:31 +03005117 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005118 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005119
David Weinehall36cdd012016-08-22 13:59:31 +03005120 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005121 return -ENODEV;
5122
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005123 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005124
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005125 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005126
5127 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005128
Kees Cook647416f2013-03-10 14:10:06 -07005129 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005130
Kees Cook647416f2013-03-10 14:10:06 -07005131 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005132}
5133
Kees Cook647416f2013-03-10 14:10:06 -07005134static int
5135i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005136{
David Weinehall36cdd012016-08-22 13:59:31 +03005137 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005138 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005139
David Weinehall36cdd012016-08-22 13:59:31 +03005140 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005141 return -ENODEV;
5142
Kees Cook647416f2013-03-10 14:10:06 -07005143 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005144 return -EINVAL;
5145
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005146 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005147 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005148
5149 /* Update the cache sharing policy here as well */
5150 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5151 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5152 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5153 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5154
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005155 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005156 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005157}
5158
Kees Cook647416f2013-03-10 14:10:06 -07005159DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5160 i915_cache_sharing_get, i915_cache_sharing_set,
5161 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005162
David Weinehall36cdd012016-08-22 13:59:31 +03005163static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005164 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005165{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005166 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005167 int ss;
5168 u32 sig1[ss_max], sig2[ss_max];
5169
5170 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5171 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5172 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5173 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5174
5175 for (ss = 0; ss < ss_max; ss++) {
5176 unsigned int eu_cnt;
5177
5178 if (sig1[ss] & CHV_SS_PG_ENABLE)
5179 /* skip disabled subslice */
5180 continue;
5181
Imre Deakf08a0c92016-08-31 19:13:04 +03005182 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005183 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005184 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5185 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5186 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5187 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005188 sseu->eu_total += eu_cnt;
5189 sseu->eu_per_subslice = max_t(unsigned int,
5190 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005191 }
Jeff McGee5d395252015-04-03 18:13:17 -07005192}
5193
David Weinehall36cdd012016-08-22 13:59:31 +03005194static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005195 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005196{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005197 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005198 int s, ss;
5199 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5200
Jeff McGee1c046bc2015-04-03 18:13:18 -07005201 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005202 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005203 s_max = 1;
5204 ss_max = 3;
5205 }
5206
5207 for (s = 0; s < s_max; s++) {
5208 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5209 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5210 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5211 }
5212
Jeff McGee5d395252015-04-03 18:13:17 -07005213 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5214 GEN9_PGCTL_SSA_EU19_ACK |
5215 GEN9_PGCTL_SSA_EU210_ACK |
5216 GEN9_PGCTL_SSA_EU311_ACK;
5217 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5218 GEN9_PGCTL_SSB_EU19_ACK |
5219 GEN9_PGCTL_SSB_EU210_ACK |
5220 GEN9_PGCTL_SSB_EU311_ACK;
5221
5222 for (s = 0; s < s_max; s++) {
5223 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5224 /* skip disabled slice */
5225 continue;
5226
Imre Deakf08a0c92016-08-31 19:13:04 +03005227 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005228
David Weinehall36cdd012016-08-22 13:59:31 +03005229 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005230 sseu->subslice_mask =
5231 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005232
Jeff McGee5d395252015-04-03 18:13:17 -07005233 for (ss = 0; ss < ss_max; ss++) {
5234 unsigned int eu_cnt;
5235
Imre Deak57ec1712016-08-31 19:13:05 +03005236 if (IS_BROXTON(dev_priv)) {
5237 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5238 /* skip disabled subslice */
5239 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005240
Imre Deak57ec1712016-08-31 19:13:05 +03005241 sseu->subslice_mask |= BIT(ss);
5242 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005243
Jeff McGee5d395252015-04-03 18:13:17 -07005244 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5245 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005246 sseu->eu_total += eu_cnt;
5247 sseu->eu_per_subslice = max_t(unsigned int,
5248 sseu->eu_per_subslice,
5249 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005250 }
5251 }
5252}
5253
David Weinehall36cdd012016-08-22 13:59:31 +03005254static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005255 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005256{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005257 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005258 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005259
Imre Deakf08a0c92016-08-31 19:13:04 +03005260 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005261
Imre Deakf08a0c92016-08-31 19:13:04 +03005262 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005263 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005264 sseu->eu_per_subslice =
5265 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005266 sseu->eu_total = sseu->eu_per_subslice *
5267 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005268
5269 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005270 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005271 u8 subslice_7eu =
5272 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005273
Imre Deak915490d2016-08-31 19:13:01 +03005274 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005275 }
5276 }
5277}
5278
Imre Deak615d8902016-08-31 19:13:03 +03005279static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5280 const struct sseu_dev_info *sseu)
5281{
5282 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5283 const char *type = is_available_info ? "Available" : "Enabled";
5284
Imre Deakc67ba532016-08-31 19:13:06 +03005285 seq_printf(m, " %s Slice Mask: %04x\n", type,
5286 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005287 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005288 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005289 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005290 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005291 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5292 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005293 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005294 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005295 seq_printf(m, " %s EU Total: %u\n", type,
5296 sseu->eu_total);
5297 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5298 sseu->eu_per_subslice);
5299
5300 if (!is_available_info)
5301 return;
5302
5303 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5304 if (HAS_POOLED_EU(dev_priv))
5305 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5306
5307 seq_printf(m, " Has Slice Power Gating: %s\n",
5308 yesno(sseu->has_slice_pg));
5309 seq_printf(m, " Has Subslice Power Gating: %s\n",
5310 yesno(sseu->has_subslice_pg));
5311 seq_printf(m, " Has EU Power Gating: %s\n",
5312 yesno(sseu->has_eu_pg));
5313}
5314
Jeff McGee38732182015-02-13 10:27:54 -06005315static int i915_sseu_status(struct seq_file *m, void *unused)
5316{
David Weinehall36cdd012016-08-22 13:59:31 +03005317 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005318 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005319
David Weinehall36cdd012016-08-22 13:59:31 +03005320 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005321 return -ENODEV;
5322
5323 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005324 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005325
Jeff McGee7f992ab2015-02-13 10:27:55 -06005326 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005327 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005328
5329 intel_runtime_pm_get(dev_priv);
5330
David Weinehall36cdd012016-08-22 13:59:31 +03005331 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005332 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005333 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005334 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005335 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005336 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005337 }
David Weinehall238010e2016-08-01 17:33:27 +03005338
5339 intel_runtime_pm_put(dev_priv);
5340
Imre Deak615d8902016-08-31 19:13:03 +03005341 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005342
Jeff McGee38732182015-02-13 10:27:54 -06005343 return 0;
5344}
5345
Ben Widawsky6d794d42011-04-25 11:25:56 -07005346static int i915_forcewake_open(struct inode *inode, struct file *file)
5347{
David Weinehall36cdd012016-08-22 13:59:31 +03005348 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005349
David Weinehall36cdd012016-08-22 13:59:31 +03005350 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005351 return 0;
5352
Chris Wilson6daccb02015-01-16 11:34:35 +02005353 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005354 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005355
5356 return 0;
5357}
5358
Ben Widawskyc43b5632012-04-16 14:07:40 -07005359static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005360{
David Weinehall36cdd012016-08-22 13:59:31 +03005361 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005362
David Weinehall36cdd012016-08-22 13:59:31 +03005363 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005364 return 0;
5365
Mika Kuoppala59bad942015-01-16 11:34:40 +02005366 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005367 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005368
5369 return 0;
5370}
5371
5372static const struct file_operations i915_forcewake_fops = {
5373 .owner = THIS_MODULE,
5374 .open = i915_forcewake_open,
5375 .release = i915_forcewake_release,
5376};
5377
5378static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5379{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005380 struct dentry *ent;
5381
5382 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005383 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005384 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005385 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005386 if (!ent)
5387 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005388
Ben Widawsky8eb57292011-05-11 15:10:58 -07005389 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005390}
5391
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005392static int i915_debugfs_create(struct dentry *root,
5393 struct drm_minor *minor,
5394 const char *name,
5395 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005396{
Jesse Barnes358733e2011-07-27 11:53:01 -07005397 struct dentry *ent;
5398
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005399 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005400 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005401 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005402 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005403 if (!ent)
5404 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005405
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005406 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005407}
5408
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005409static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005410 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005411 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005412 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005413 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005414 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005415 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005416 {"i915_gem_request", i915_gem_request_info, 0},
5417 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005418 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005419 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005420 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5421 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5422 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005423 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005424 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005425 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005426 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005427 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305428 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005429 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005430 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005431 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005432 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005433 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005434 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005435 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005436 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005437 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005438 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005439 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005440 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005441 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005442 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005443 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005444 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005445 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005446 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005447 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005448 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005449 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005450 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005451 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005452 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005453 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005454 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005455 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005456 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005457 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005458 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005459 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305460 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005461 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005462};
Ben Gamari27c202a2009-07-01 22:26:52 -04005463#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005464
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005465static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005466 const char *name;
5467 const struct file_operations *fops;
5468} i915_debugfs_files[] = {
5469 {"i915_wedged", &i915_wedged_fops},
5470 {"i915_max_freq", &i915_max_freq_fops},
5471 {"i915_min_freq", &i915_min_freq_fops},
5472 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005473 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5474 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005475 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005476#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005477 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005478#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005479 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005480 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005481 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5482 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5483 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005484 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005485 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5486 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05305487 {"i915_dp_test_active", &i915_displayport_test_active_fops},
5488 {"i915_guc_log_control", &i915_guc_log_control_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005489};
5490
David Weinehall36cdd012016-08-22 13:59:31 +03005491void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005492{
Daniel Vetterb3783602013-11-14 11:30:42 +01005493 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005494
Damien Lespiau055e3932014-08-18 13:49:10 +01005495 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005496 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005497
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005498 pipe_crc->opened = false;
5499 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005500 init_waitqueue_head(&pipe_crc->wq);
5501 }
5502}
5503
Chris Wilson1dac8912016-06-24 14:00:17 +01005504int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005505{
Chris Wilson91c8a322016-07-05 10:40:23 +01005506 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005507 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005508
Ben Widawsky6d794d42011-04-25 11:25:56 -07005509 ret = i915_forcewake_create(minor->debugfs_root, minor);
5510 if (ret)
5511 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005512
Damien Lespiau07144422013-10-15 18:55:40 +01005513 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5514 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5515 if (ret)
5516 return ret;
5517 }
5518
Daniel Vetter34b96742013-07-04 20:49:44 +02005519 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5520 ret = i915_debugfs_create(minor->debugfs_root, minor,
5521 i915_debugfs_files[i].name,
5522 i915_debugfs_files[i].fops);
5523 if (ret)
5524 return ret;
5525 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005526
Ben Gamari27c202a2009-07-01 22:26:52 -04005527 return drm_debugfs_create_files(i915_debugfs_list,
5528 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005529 minor->debugfs_root, minor);
5530}
5531
Chris Wilson1dac8912016-06-24 14:00:17 +01005532void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005533{
Chris Wilson91c8a322016-07-05 10:40:23 +01005534 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005535 int i;
5536
Ben Gamari27c202a2009-07-01 22:26:52 -04005537 drm_debugfs_remove_files(i915_debugfs_list,
5538 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005539
David Weinehall36cdd012016-08-22 13:59:31 +03005540 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005541 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005542
Daniel Vettere309a992013-10-16 22:55:51 +02005543 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005544 struct drm_info_list *info_list =
5545 (struct drm_info_list *)&i915_pipe_crc_data[i];
5546
5547 drm_debugfs_remove_files(info_list, 1, minor);
5548 }
5549
Daniel Vetter34b96742013-07-04 20:49:44 +02005550 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5551 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005552 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005553
5554 drm_debugfs_remove_files(info_list, 1, minor);
5555 }
Ben Gamari20172632009-02-17 20:08:50 -05005556}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005557
5558struct dpcd_block {
5559 /* DPCD dump start address. */
5560 unsigned int offset;
5561 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5562 unsigned int end;
5563 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5564 size_t size;
5565 /* Only valid for eDP. */
5566 bool edp;
5567};
5568
5569static const struct dpcd_block i915_dpcd_debug[] = {
5570 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5571 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5572 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5573 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5574 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5575 { .offset = DP_SET_POWER },
5576 { .offset = DP_EDP_DPCD_REV },
5577 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5578 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5579 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5580};
5581
5582static int i915_dpcd_show(struct seq_file *m, void *data)
5583{
5584 struct drm_connector *connector = m->private;
5585 struct intel_dp *intel_dp =
5586 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5587 uint8_t buf[16];
5588 ssize_t err;
5589 int i;
5590
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005591 if (connector->status != connector_status_connected)
5592 return -ENODEV;
5593
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005594 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5595 const struct dpcd_block *b = &i915_dpcd_debug[i];
5596 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5597
5598 if (b->edp &&
5599 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5600 continue;
5601
5602 /* low tech for now */
5603 if (WARN_ON(size > sizeof(buf)))
5604 continue;
5605
5606 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5607 if (err <= 0) {
5608 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5609 size, b->offset, err);
5610 continue;
5611 }
5612
5613 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005614 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005615
5616 return 0;
5617}
5618
5619static int i915_dpcd_open(struct inode *inode, struct file *file)
5620{
5621 return single_open(file, i915_dpcd_show, inode->i_private);
5622}
5623
5624static const struct file_operations i915_dpcd_fops = {
5625 .owner = THIS_MODULE,
5626 .open = i915_dpcd_open,
5627 .read = seq_read,
5628 .llseek = seq_lseek,
5629 .release = single_release,
5630};
5631
David Weinehallecbd6782016-08-23 12:23:56 +03005632static int i915_panel_show(struct seq_file *m, void *data)
5633{
5634 struct drm_connector *connector = m->private;
5635 struct intel_dp *intel_dp =
5636 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5637
5638 if (connector->status != connector_status_connected)
5639 return -ENODEV;
5640
5641 seq_printf(m, "Panel power up delay: %d\n",
5642 intel_dp->panel_power_up_delay);
5643 seq_printf(m, "Panel power down delay: %d\n",
5644 intel_dp->panel_power_down_delay);
5645 seq_printf(m, "Backlight on delay: %d\n",
5646 intel_dp->backlight_on_delay);
5647 seq_printf(m, "Backlight off delay: %d\n",
5648 intel_dp->backlight_off_delay);
5649
5650 return 0;
5651}
5652
5653static int i915_panel_open(struct inode *inode, struct file *file)
5654{
5655 return single_open(file, i915_panel_show, inode->i_private);
5656}
5657
5658static const struct file_operations i915_panel_fops = {
5659 .owner = THIS_MODULE,
5660 .open = i915_panel_open,
5661 .read = seq_read,
5662 .llseek = seq_lseek,
5663 .release = single_release,
5664};
5665
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005666/**
5667 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5668 * @connector: pointer to a registered drm_connector
5669 *
5670 * Cleanup will be done by drm_connector_unregister() through a call to
5671 * drm_debugfs_connector_remove().
5672 *
5673 * Returns 0 on success, negative error codes on error.
5674 */
5675int i915_debugfs_connector_add(struct drm_connector *connector)
5676{
5677 struct dentry *root = connector->debugfs_entry;
5678
5679 /* The connector must have been registered beforehands. */
5680 if (!root)
5681 return -ENODEV;
5682
5683 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5684 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005685 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5686 connector, &i915_dpcd_fops);
5687
5688 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5689 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5690 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005691
5692 return 0;
5693}