blob: 791bfc76007594541f921d3d69555b82a57e701a [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;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200220 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100221 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 }
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200230 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100231 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;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200393 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
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;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200410 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100411 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;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200496 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
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) {
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200550 struct intel_engine_cs *engine = work->flip_queued_req->engine;
Daniel Vetter5a21b662016-05-24 17:13:53 +0200551
552 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
553 engine->name,
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200554 work->flip_queued_req->global_seqno,
Chris Wilson28176ef2016-10-28 13:58:56 +0100555 atomic_read(&dev_priv->gt.global_timeline.next_seqno),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100556 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100557 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200558 } else
559 seq_printf(m, "Flip not associated with any ring\n");
560 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
561 work->flip_queued_vblank,
562 work->flip_ready_vblank,
563 intel_crtc_get_vblank_counter(crtc));
564 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
565
David Weinehall36cdd012016-08-22 13:59:31 +0300566 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200567 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
568 else
569 addr = I915_READ(DSPADDR(crtc->plane));
570 seq_printf(m, "Current scanout address 0x%08x\n", addr);
571
572 if (work->pending_flip_obj) {
573 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
574 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100575 }
576 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200577 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100578 }
579
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200580 mutex_unlock(&dev->struct_mutex);
581
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100582 return 0;
583}
584
Brad Volkin493018d2014-12-11 12:13:08 -0800585static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
586{
David Weinehall36cdd012016-08-22 13:59:31 +0300587 struct drm_i915_private *dev_priv = node_to_i915(m->private);
588 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800589 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000590 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530591 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100592 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000593 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800594
595 ret = mutex_lock_interruptible(&dev->struct_mutex);
596 if (ret)
597 return ret;
598
Akash Goel3b3f1652016-10-13 22:44:48 +0530599 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000600 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100601 int count;
602
603 count = 0;
604 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000605 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100606 batch_pool_link)
607 count++;
608 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000609 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100610
611 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000612 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100613 batch_pool_link) {
614 seq_puts(m, " ");
615 describe_obj(m, obj);
616 seq_putc(m, '\n');
617 }
618
619 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100620 }
Brad Volkin493018d2014-12-11 12:13:08 -0800621 }
622
Chris Wilson8d9d5742015-04-07 16:20:38 +0100623 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800624
625 mutex_unlock(&dev->struct_mutex);
626
627 return 0;
628}
629
Chris Wilson1b365952016-10-04 21:11:31 +0100630static void print_request(struct seq_file *m,
631 struct drm_i915_gem_request *rq,
632 const char *prefix)
633{
Chris Wilson20311bd2016-11-14 20:41:03 +0000634 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100635 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000636 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100637 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100638 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100639}
640
Ben Gamari20172632009-02-17 20:08:50 -0500641static int i915_gem_request_info(struct seq_file *m, void *data)
642{
David Weinehall36cdd012016-08-22 13:59:31 +0300643 struct drm_i915_private *dev_priv = node_to_i915(m->private);
644 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200645 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530646 struct intel_engine_cs *engine;
647 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000648 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100649
650 ret = mutex_lock_interruptible(&dev->struct_mutex);
651 if (ret)
652 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500653
Chris Wilson2d1070b2015-04-01 10:36:56 +0100654 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530655 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100656 int count;
657
658 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100659 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100660 count++;
661 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100662 continue;
663
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000664 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100665 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100666 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100667
668 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500669 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100670 mutex_unlock(&dev->struct_mutex);
671
Chris Wilson2d1070b2015-04-01 10:36:56 +0100672 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100673 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100674
Ben Gamari20172632009-02-17 20:08:50 -0500675 return 0;
676}
677
Chris Wilsonb2223492010-10-27 15:27:33 +0100678static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000679 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100680{
Chris Wilson688e6c72016-07-01 17:23:15 +0100681 struct intel_breadcrumbs *b = &engine->breadcrumbs;
682 struct rb_node *rb;
683
Chris Wilson12471ba2016-04-09 10:57:55 +0100684 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100685 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100686
Chris Wilsonf6168e32016-10-28 13:58:55 +0100687 spin_lock_irq(&b->lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100688 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
689 struct intel_wait *w = container_of(rb, typeof(*w), node);
690
691 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
692 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
693 }
Chris Wilsonf6168e32016-10-28 13:58:55 +0100694 spin_unlock_irq(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100695}
696
Ben Gamari20172632009-02-17 20:08:50 -0500697static int i915_gem_seqno_info(struct seq_file *m, void *data)
698{
David Weinehall36cdd012016-08-22 13:59:31 +0300699 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000700 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530701 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500702
Akash Goel3b3f1652016-10-13 22:44:48 +0530703 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000704 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100705
Ben Gamari20172632009-02-17 20:08:50 -0500706 return 0;
707}
708
709
710static int i915_interrupt_info(struct seq_file *m, void *data)
711{
David Weinehall36cdd012016-08-22 13:59:31 +0300712 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000713 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530714 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100715 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100716
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200717 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500718
David Weinehall36cdd012016-08-22 13:59:31 +0300719 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300720 seq_printf(m, "Master Interrupt Control:\t%08x\n",
721 I915_READ(GEN8_MASTER_IRQ));
722
723 seq_printf(m, "Display IER:\t%08x\n",
724 I915_READ(VLV_IER));
725 seq_printf(m, "Display IIR:\t%08x\n",
726 I915_READ(VLV_IIR));
727 seq_printf(m, "Display IIR_RW:\t%08x\n",
728 I915_READ(VLV_IIR_RW));
729 seq_printf(m, "Display IMR:\t%08x\n",
730 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100731 for_each_pipe(dev_priv, pipe) {
732 enum intel_display_power_domain power_domain;
733
734 power_domain = POWER_DOMAIN_PIPE(pipe);
735 if (!intel_display_power_get_if_enabled(dev_priv,
736 power_domain)) {
737 seq_printf(m, "Pipe %c power disabled\n",
738 pipe_name(pipe));
739 continue;
740 }
741
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300742 seq_printf(m, "Pipe %c stat:\t%08x\n",
743 pipe_name(pipe),
744 I915_READ(PIPESTAT(pipe)));
745
Chris Wilson9c870d02016-10-24 13:42:15 +0100746 intel_display_power_put(dev_priv, power_domain);
747 }
748
749 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300750 seq_printf(m, "Port hotplug:\t%08x\n",
751 I915_READ(PORT_HOTPLUG_EN));
752 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
753 I915_READ(VLV_DPFLIPSTAT));
754 seq_printf(m, "DPINVGTT:\t%08x\n",
755 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100756 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300757
758 for (i = 0; i < 4; i++) {
759 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
760 i, I915_READ(GEN8_GT_IMR(i)));
761 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
762 i, I915_READ(GEN8_GT_IIR(i)));
763 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
764 i, I915_READ(GEN8_GT_IER(i)));
765 }
766
767 seq_printf(m, "PCU interrupt mask:\t%08x\n",
768 I915_READ(GEN8_PCU_IMR));
769 seq_printf(m, "PCU interrupt identity:\t%08x\n",
770 I915_READ(GEN8_PCU_IIR));
771 seq_printf(m, "PCU interrupt enable:\t%08x\n",
772 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300773 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700774 seq_printf(m, "Master Interrupt Control:\t%08x\n",
775 I915_READ(GEN8_MASTER_IRQ));
776
777 for (i = 0; i < 4; i++) {
778 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
779 i, I915_READ(GEN8_GT_IMR(i)));
780 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
781 i, I915_READ(GEN8_GT_IIR(i)));
782 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
783 i, I915_READ(GEN8_GT_IER(i)));
784 }
785
Damien Lespiau055e3932014-08-18 13:49:10 +0100786 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200787 enum intel_display_power_domain power_domain;
788
789 power_domain = POWER_DOMAIN_PIPE(pipe);
790 if (!intel_display_power_get_if_enabled(dev_priv,
791 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300792 seq_printf(m, "Pipe %c power disabled\n",
793 pipe_name(pipe));
794 continue;
795 }
Ben Widawskya123f152013-11-02 21:07:10 -0700796 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000797 pipe_name(pipe),
798 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700799 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000800 pipe_name(pipe),
801 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700802 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000803 pipe_name(pipe),
804 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200805
806 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700807 }
808
809 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
810 I915_READ(GEN8_DE_PORT_IMR));
811 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
812 I915_READ(GEN8_DE_PORT_IIR));
813 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
814 I915_READ(GEN8_DE_PORT_IER));
815
816 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
817 I915_READ(GEN8_DE_MISC_IMR));
818 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
819 I915_READ(GEN8_DE_MISC_IIR));
820 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
821 I915_READ(GEN8_DE_MISC_IER));
822
823 seq_printf(m, "PCU interrupt mask:\t%08x\n",
824 I915_READ(GEN8_PCU_IMR));
825 seq_printf(m, "PCU interrupt identity:\t%08x\n",
826 I915_READ(GEN8_PCU_IIR));
827 seq_printf(m, "PCU interrupt enable:\t%08x\n",
828 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300829 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700830 seq_printf(m, "Display IER:\t%08x\n",
831 I915_READ(VLV_IER));
832 seq_printf(m, "Display IIR:\t%08x\n",
833 I915_READ(VLV_IIR));
834 seq_printf(m, "Display IIR_RW:\t%08x\n",
835 I915_READ(VLV_IIR_RW));
836 seq_printf(m, "Display IMR:\t%08x\n",
837 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100838 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700839 seq_printf(m, "Pipe %c stat:\t%08x\n",
840 pipe_name(pipe),
841 I915_READ(PIPESTAT(pipe)));
842
843 seq_printf(m, "Master IER:\t%08x\n",
844 I915_READ(VLV_MASTER_IER));
845
846 seq_printf(m, "Render IER:\t%08x\n",
847 I915_READ(GTIER));
848 seq_printf(m, "Render IIR:\t%08x\n",
849 I915_READ(GTIIR));
850 seq_printf(m, "Render IMR:\t%08x\n",
851 I915_READ(GTIMR));
852
853 seq_printf(m, "PM IER:\t\t%08x\n",
854 I915_READ(GEN6_PMIER));
855 seq_printf(m, "PM IIR:\t\t%08x\n",
856 I915_READ(GEN6_PMIIR));
857 seq_printf(m, "PM IMR:\t\t%08x\n",
858 I915_READ(GEN6_PMIMR));
859
860 seq_printf(m, "Port hotplug:\t%08x\n",
861 I915_READ(PORT_HOTPLUG_EN));
862 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
863 I915_READ(VLV_DPFLIPSTAT));
864 seq_printf(m, "DPINVGTT:\t%08x\n",
865 I915_READ(DPINVGTT));
866
David Weinehall36cdd012016-08-22 13:59:31 +0300867 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800868 seq_printf(m, "Interrupt enable: %08x\n",
869 I915_READ(IER));
870 seq_printf(m, "Interrupt identity: %08x\n",
871 I915_READ(IIR));
872 seq_printf(m, "Interrupt mask: %08x\n",
873 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100874 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800875 seq_printf(m, "Pipe %c stat: %08x\n",
876 pipe_name(pipe),
877 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800878 } else {
879 seq_printf(m, "North Display Interrupt enable: %08x\n",
880 I915_READ(DEIER));
881 seq_printf(m, "North Display Interrupt identity: %08x\n",
882 I915_READ(DEIIR));
883 seq_printf(m, "North Display Interrupt mask: %08x\n",
884 I915_READ(DEIMR));
885 seq_printf(m, "South Display Interrupt enable: %08x\n",
886 I915_READ(SDEIER));
887 seq_printf(m, "South Display Interrupt identity: %08x\n",
888 I915_READ(SDEIIR));
889 seq_printf(m, "South Display Interrupt mask: %08x\n",
890 I915_READ(SDEIMR));
891 seq_printf(m, "Graphics Interrupt enable: %08x\n",
892 I915_READ(GTIER));
893 seq_printf(m, "Graphics Interrupt identity: %08x\n",
894 I915_READ(GTIIR));
895 seq_printf(m, "Graphics Interrupt mask: %08x\n",
896 I915_READ(GTIMR));
897 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530898 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300899 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100900 seq_printf(m,
901 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000902 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000903 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000904 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000905 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200906 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100907
Ben Gamari20172632009-02-17 20:08:50 -0500908 return 0;
909}
910
Chris Wilsona6172a82009-02-11 14:26:38 +0000911static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
912{
David Weinehall36cdd012016-08-22 13:59:31 +0300913 struct drm_i915_private *dev_priv = node_to_i915(m->private);
914 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100915 int i, ret;
916
917 ret = mutex_lock_interruptible(&dev->struct_mutex);
918 if (ret)
919 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000920
Chris Wilsona6172a82009-02-11 14:26:38 +0000921 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
922 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100923 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000924
Chris Wilson6c085a72012-08-20 11:40:46 +0200925 seq_printf(m, "Fence %d, pin count = %d, object = ",
926 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100927 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100928 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100929 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100930 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100931 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000932 }
933
Chris Wilson05394f32010-11-08 19:18:58 +0000934 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000935 return 0;
936}
937
Chris Wilson98a2f412016-10-12 10:05:18 +0100938#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
939
Daniel Vetterd5442302012-04-27 15:17:40 +0200940static ssize_t
941i915_error_state_write(struct file *filp,
942 const char __user *ubuf,
943 size_t cnt,
944 loff_t *ppos)
945{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300946 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200947
948 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100949 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200950
951 return cnt;
952}
953
954static int i915_error_state_open(struct inode *inode, struct file *file)
955{
David Weinehall36cdd012016-08-22 13:59:31 +0300956 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200957 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200958
959 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
960 if (!error_priv)
961 return -ENOMEM;
962
David Weinehall36cdd012016-08-22 13:59:31 +0300963 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200964
David Weinehall36cdd012016-08-22 13:59:31 +0300965 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200966
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300967 file->private_data = error_priv;
968
969 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200970}
971
972static int i915_error_state_release(struct inode *inode, struct file *file)
973{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300974 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200975
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300976 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200977 kfree(error_priv);
978
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300979 return 0;
980}
981
982static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
983 size_t count, loff_t *pos)
984{
985 struct i915_error_state_file_priv *error_priv = file->private_data;
986 struct drm_i915_error_state_buf error_str;
987 loff_t tmp_pos = 0;
988 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300989 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300990
David Weinehall36cdd012016-08-22 13:59:31 +0300991 ret = i915_error_state_buf_init(&error_str,
992 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300993 if (ret)
994 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300995
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300996 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300997 if (ret)
998 goto out;
999
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001000 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1001 error_str.buf,
1002 error_str.bytes);
1003
1004 if (ret_count < 0)
1005 ret = ret_count;
1006 else
1007 *pos = error_str.start + ret_count;
1008out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001009 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001010 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001011}
1012
1013static const struct file_operations i915_error_state_fops = {
1014 .owner = THIS_MODULE,
1015 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001016 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001017 .write = i915_error_state_write,
1018 .llseek = default_llseek,
1019 .release = i915_error_state_release,
1020};
1021
Chris Wilson98a2f412016-10-12 10:05:18 +01001022#endif
1023
Kees Cook647416f2013-03-10 14:10:06 -07001024static int
1025i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001026{
David Weinehall36cdd012016-08-22 13:59:31 +03001027 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001028
Chris Wilson3acd2402016-11-24 09:47:52 +00001029 *val = 1 + atomic_read(&dev_priv->gt.global_timeline.next_seqno);
Kees Cook647416f2013-03-10 14:10:06 -07001030 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001031}
1032
Kees Cook647416f2013-03-10 14:10:06 -07001033static int
1034i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001035{
David Weinehall36cdd012016-08-22 13:59:31 +03001036 struct drm_i915_private *dev_priv = data;
1037 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001038 int ret;
1039
Mika Kuoppala40633212012-12-04 15:12:00 +02001040 ret = mutex_lock_interruptible(&dev->struct_mutex);
1041 if (ret)
1042 return ret;
1043
Chris Wilson73cb9702016-10-28 13:58:46 +01001044 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001045 mutex_unlock(&dev->struct_mutex);
1046
Kees Cook647416f2013-03-10 14:10:06 -07001047 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001048}
1049
Kees Cook647416f2013-03-10 14:10:06 -07001050DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1051 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001052 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001053
Deepak Sadb4bd12014-03-31 11:30:02 +05301054static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001055{
David Weinehall36cdd012016-08-22 13:59:31 +03001056 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1057 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001058 int ret = 0;
1059
1060 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001061
David Weinehall36cdd012016-08-22 13:59:31 +03001062 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001063 u16 rgvswctl = I915_READ16(MEMSWCTL);
1064 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1065
1066 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1067 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1068 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1069 MEMSTAT_VID_SHIFT);
1070 seq_printf(m, "Current P-state: %d\n",
1071 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001072 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001073 u32 freq_sts;
1074
1075 mutex_lock(&dev_priv->rps.hw_lock);
1076 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1077 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1078 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1079
1080 seq_printf(m, "actual GPU freq: %d MHz\n",
1081 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1082
1083 seq_printf(m, "current GPU freq: %d MHz\n",
1084 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1085
1086 seq_printf(m, "max GPU freq: %d MHz\n",
1087 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1088
1089 seq_printf(m, "min GPU freq: %d MHz\n",
1090 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1091
1092 seq_printf(m, "idle GPU freq: %d MHz\n",
1093 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1094
1095 seq_printf(m,
1096 "efficient (RPe) frequency: %d MHz\n",
1097 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1098 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001099 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001100 u32 rp_state_limits;
1101 u32 gt_perf_status;
1102 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001103 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001104 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001105 u32 rpupei, rpcurup, rpprevup;
1106 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001107 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001108 int max_freq;
1109
Bob Paauwe35040562015-06-25 14:54:07 -07001110 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001111 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001112 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1113 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1114 } else {
1115 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1116 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1117 }
1118
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001119 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001120 ret = mutex_lock_interruptible(&dev->struct_mutex);
1121 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001122 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001123
Mika Kuoppala59bad942015-01-16 11:34:40 +02001124 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001125
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001126 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001127 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301128 reqf >>= 23;
1129 else {
1130 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001131 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301132 reqf >>= 24;
1133 else
1134 reqf >>= 25;
1135 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001136 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001137
Chris Wilson0d8f9492014-03-27 09:06:14 +00001138 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1139 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1140 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1141
Jesse Barnesccab5c82011-01-18 15:49:25 -08001142 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301143 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1144 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1145 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1146 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1147 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1148 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001149 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301150 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001151 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001152 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1153 else
1154 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001155 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001156
Mika Kuoppala59bad942015-01-16 11:34:40 +02001157 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001158 mutex_unlock(&dev->struct_mutex);
1159
David Weinehall36cdd012016-08-22 13:59:31 +03001160 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001161 pm_ier = I915_READ(GEN6_PMIER);
1162 pm_imr = I915_READ(GEN6_PMIMR);
1163 pm_isr = I915_READ(GEN6_PMISR);
1164 pm_iir = I915_READ(GEN6_PMIIR);
1165 pm_mask = I915_READ(GEN6_PMINTRMSK);
1166 } else {
1167 pm_ier = I915_READ(GEN8_GT_IER(2));
1168 pm_imr = I915_READ(GEN8_GT_IMR(2));
1169 pm_isr = I915_READ(GEN8_GT_ISR(2));
1170 pm_iir = I915_READ(GEN8_GT_IIR(2));
1171 pm_mask = I915_READ(GEN6_PMINTRMSK);
1172 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001173 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 -03001174 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301175 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001176 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001177 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001178 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001179 seq_printf(m, "Render p-state VID: %d\n",
1180 gt_perf_status & 0xff);
1181 seq_printf(m, "Render p-state limit: %d\n",
1182 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001183 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1184 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1185 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1186 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001187 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001188 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301189 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1190 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1191 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1192 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1193 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1194 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001195 seq_printf(m, "Up threshold: %d%%\n",
1196 dev_priv->rps.up_threshold);
1197
Akash Goeld6cda9c2016-04-23 00:05:46 +05301198 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1199 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1200 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1201 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1202 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1203 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001204 seq_printf(m, "Down threshold: %d%%\n",
1205 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001206
David Weinehall36cdd012016-08-22 13:59:31 +03001207 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001208 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001209 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001210 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001211 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001212 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001213
1214 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001215 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001216 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001217 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001218 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001219
David Weinehall36cdd012016-08-22 13:59:31 +03001220 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001221 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001222 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001223 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001224 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001225 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001226 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001227 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001228
Chris Wilsond86ed342015-04-27 13:41:19 +01001229 seq_printf(m, "Current freq: %d MHz\n",
1230 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1231 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001232 seq_printf(m, "Idle freq: %d MHz\n",
1233 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001234 seq_printf(m, "Min freq: %d MHz\n",
1235 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001236 seq_printf(m, "Boost freq: %d MHz\n",
1237 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001238 seq_printf(m, "Max freq: %d MHz\n",
1239 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1240 seq_printf(m,
1241 "efficient (RPe) frequency: %d MHz\n",
1242 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001243 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001244 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001245 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001246
Mika Kahola1170f282015-09-25 14:00:32 +03001247 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1248 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1249 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1250
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001251out:
1252 intel_runtime_pm_put(dev_priv);
1253 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001254}
1255
Ben Widawskyd6369512016-09-20 16:54:32 +03001256static void i915_instdone_info(struct drm_i915_private *dev_priv,
1257 struct seq_file *m,
1258 struct intel_instdone *instdone)
1259{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001260 int slice;
1261 int subslice;
1262
Ben Widawskyd6369512016-09-20 16:54:32 +03001263 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1264 instdone->instdone);
1265
1266 if (INTEL_GEN(dev_priv) <= 3)
1267 return;
1268
1269 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1270 instdone->slice_common);
1271
1272 if (INTEL_GEN(dev_priv) <= 6)
1273 return;
1274
Ben Widawskyf9e61372016-09-20 16:54:33 +03001275 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1276 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1277 slice, subslice, instdone->sampler[slice][subslice]);
1278
1279 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1280 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1281 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001282}
1283
Chris Wilsonf6544492015-01-26 18:03:04 +02001284static int i915_hangcheck_info(struct seq_file *m, void *unused)
1285{
David Weinehall36cdd012016-08-22 13:59:31 +03001286 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001287 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001288 u64 acthd[I915_NUM_ENGINES];
1289 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001290 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001291 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001292
Chris Wilson8af29b02016-09-09 14:11:47 +01001293 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1294 seq_printf(m, "Wedged\n");
1295 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1296 seq_printf(m, "Reset in progress\n");
1297 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1298 seq_printf(m, "Waiter holding struct mutex\n");
1299 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1300 seq_printf(m, "struct_mutex blocked for reset\n");
1301
Chris Wilsonf6544492015-01-26 18:03:04 +02001302 if (!i915.enable_hangcheck) {
1303 seq_printf(m, "Hangcheck disabled\n");
1304 return 0;
1305 }
1306
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001307 intel_runtime_pm_get(dev_priv);
1308
Akash Goel3b3f1652016-10-13 22:44:48 +05301309 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001310 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001311 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001312 }
1313
Akash Goel3b3f1652016-10-13 22:44:48 +05301314 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001315
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001316 intel_runtime_pm_put(dev_priv);
1317
Chris Wilsonf6544492015-01-26 18:03:04 +02001318 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1319 seq_printf(m, "Hangcheck active, fires in %dms\n",
1320 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1321 jiffies));
1322 } else
1323 seq_printf(m, "Hangcheck inactive\n");
1324
Akash Goel3b3f1652016-10-13 22:44:48 +05301325 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001326 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1327 struct rb_node *rb;
1328
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001329 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001330 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001331 engine->hangcheck.seqno, seqno[id],
1332 intel_engine_last_submit(engine));
Chris Wilson83348ba2016-08-09 17:47:51 +01001333 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1334 yesno(intel_engine_has_waiter(engine)),
1335 yesno(test_bit(engine->id,
1336 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilsonf6168e32016-10-28 13:58:55 +01001337 spin_lock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001338 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1339 struct intel_wait *w = container_of(rb, typeof(*w), node);
1340
1341 seq_printf(m, "\t%s [%d] waiting for %x\n",
1342 w->tsk->comm, w->tsk->pid, w->seqno);
1343 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01001344 spin_unlock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001345
Chris Wilsonf6544492015-01-26 18:03:04 +02001346 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001347 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001348 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001349 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1350 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001351
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001352 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001353 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001354
Ben Widawskyd6369512016-09-20 16:54:32 +03001355 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001356
Ben Widawskyd6369512016-09-20 16:54:32 +03001357 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001358
Ben Widawskyd6369512016-09-20 16:54:32 +03001359 i915_instdone_info(dev_priv, m,
1360 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001361 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001362 }
1363
1364 return 0;
1365}
1366
Ben Widawsky4d855292011-12-12 19:34:16 -08001367static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001368{
David Weinehall36cdd012016-08-22 13:59:31 +03001369 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001370 u32 rgvmodectl, rstdbyctl;
1371 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001372
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001373 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001374
1375 rgvmodectl = I915_READ(MEMMODECTL);
1376 rstdbyctl = I915_READ(RSTDBYCTL);
1377 crstandvid = I915_READ16(CRSTANDVID);
1378
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001379 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001380
Jani Nikula742f4912015-09-03 11:16:09 +03001381 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001382 seq_printf(m, "Boost freq: %d\n",
1383 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1384 MEMMODE_BOOST_FREQ_SHIFT);
1385 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001386 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001387 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001388 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001389 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001390 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001391 seq_printf(m, "Starting frequency: P%d\n",
1392 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001393 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001394 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001395 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1396 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1397 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1398 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001399 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001400 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001401 switch (rstdbyctl & RSX_STATUS_MASK) {
1402 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001403 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001404 break;
1405 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001406 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001407 break;
1408 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001409 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001410 break;
1411 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001412 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001413 break;
1414 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001415 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001416 break;
1417 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001418 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001419 break;
1420 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001421 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001422 break;
1423 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001424
1425 return 0;
1426}
1427
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001428static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001429{
David Weinehall36cdd012016-08-22 13:59:31 +03001430 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001431 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001432
1433 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001434 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001435 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001436 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001437 fw_domain->wake_count);
1438 }
1439 spin_unlock_irq(&dev_priv->uncore.lock);
1440
1441 return 0;
1442}
1443
Deepak S669ab5a2014-01-10 15:18:26 +05301444static int vlv_drpc_info(struct seq_file *m)
1445{
David Weinehall36cdd012016-08-22 13:59:31 +03001446 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001447 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301448
Imre Deakd46c0512014-04-14 20:24:27 +03001449 intel_runtime_pm_get(dev_priv);
1450
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001451 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301452 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1453 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1454
Imre Deakd46c0512014-04-14 20:24:27 +03001455 intel_runtime_pm_put(dev_priv);
1456
Deepak S669ab5a2014-01-10 15:18:26 +05301457 seq_printf(m, "Video Turbo Mode: %s\n",
1458 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1459 seq_printf(m, "Turbo enabled: %s\n",
1460 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1461 seq_printf(m, "HW control enabled: %s\n",
1462 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1463 seq_printf(m, "SW control enabled: %s\n",
1464 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1465 GEN6_RP_MEDIA_SW_MODE));
1466 seq_printf(m, "RC6 Enabled: %s\n",
1467 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1468 GEN6_RC_CTL_EI_MODE(1))));
1469 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001470 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301471 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001472 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301473
Imre Deak9cc19be2014-04-14 20:24:24 +03001474 seq_printf(m, "Render RC6 residency since boot: %u\n",
1475 I915_READ(VLV_GT_RENDER_RC6));
1476 seq_printf(m, "Media RC6 residency since boot: %u\n",
1477 I915_READ(VLV_GT_MEDIA_RC6));
1478
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001479 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301480}
1481
Ben Widawsky4d855292011-12-12 19:34:16 -08001482static int gen6_drpc_info(struct seq_file *m)
1483{
David Weinehall36cdd012016-08-22 13:59:31 +03001484 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1485 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001486 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301487 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001488 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001489 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001490
1491 ret = mutex_lock_interruptible(&dev->struct_mutex);
1492 if (ret)
1493 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001494 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001495
Chris Wilson907b28c2013-07-19 20:36:52 +01001496 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001497 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001498 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001499
1500 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001501 seq_puts(m, "RC information inaccurate because somebody "
1502 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001503 } else {
1504 /* NB: we cannot use forcewake, else we read the wrong values */
1505 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1506 udelay(10);
1507 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1508 }
1509
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001510 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001511 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001512
1513 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1514 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001515 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301516 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1517 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1518 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001519 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001520 mutex_lock(&dev_priv->rps.hw_lock);
1521 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1522 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001523
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001524 intel_runtime_pm_put(dev_priv);
1525
Ben Widawsky4d855292011-12-12 19:34:16 -08001526 seq_printf(m, "Video Turbo Mode: %s\n",
1527 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1528 seq_printf(m, "HW control enabled: %s\n",
1529 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1530 seq_printf(m, "SW control enabled: %s\n",
1531 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1532 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001533 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001534 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1535 seq_printf(m, "RC6 Enabled: %s\n",
1536 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001537 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301538 seq_printf(m, "Render Well Gating Enabled: %s\n",
1539 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1540 seq_printf(m, "Media Well Gating Enabled: %s\n",
1541 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1542 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001543 seq_printf(m, "Deep RC6 Enabled: %s\n",
1544 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1545 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1546 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001547 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001548 switch (gt_core_status & GEN6_RCn_MASK) {
1549 case GEN6_RC0:
1550 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001551 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001552 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001553 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 break;
1555 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001556 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001557 break;
1558 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001559 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001560 break;
1561 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001562 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 break;
1564 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001565 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001566 break;
1567 }
1568
1569 seq_printf(m, "Core Power Down: %s\n",
1570 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001571 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301572 seq_printf(m, "Render Power Well: %s\n",
1573 (gen9_powergate_status &
1574 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1575 seq_printf(m, "Media Power Well: %s\n",
1576 (gen9_powergate_status &
1577 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1578 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001579
1580 /* Not exactly sure what this is */
1581 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1582 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1583 seq_printf(m, "RC6 residency since boot: %u\n",
1584 I915_READ(GEN6_GT_GFX_RC6));
1585 seq_printf(m, "RC6+ residency since boot: %u\n",
1586 I915_READ(GEN6_GT_GFX_RC6p));
1587 seq_printf(m, "RC6++ residency since boot: %u\n",
1588 I915_READ(GEN6_GT_GFX_RC6pp));
1589
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001590 seq_printf(m, "RC6 voltage: %dmV\n",
1591 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1592 seq_printf(m, "RC6+ voltage: %dmV\n",
1593 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1594 seq_printf(m, "RC6++ voltage: %dmV\n",
1595 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301596 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001597}
1598
1599static int i915_drpc_info(struct seq_file *m, void *unused)
1600{
David Weinehall36cdd012016-08-22 13:59:31 +03001601 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001602
David Weinehall36cdd012016-08-22 13:59:31 +03001603 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301604 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001605 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001606 return gen6_drpc_info(m);
1607 else
1608 return ironlake_drpc_info(m);
1609}
1610
Daniel Vetter9a851782015-06-18 10:30:22 +02001611static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1612{
David Weinehall36cdd012016-08-22 13:59:31 +03001613 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001614
1615 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1616 dev_priv->fb_tracking.busy_bits);
1617
1618 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1619 dev_priv->fb_tracking.flip_bits);
1620
1621 return 0;
1622}
1623
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001624static int i915_fbc_status(struct seq_file *m, void *unused)
1625{
David Weinehall36cdd012016-08-22 13:59:31 +03001626 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001627
David Weinehall36cdd012016-08-22 13:59:31 +03001628 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001629 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001630 return 0;
1631 }
1632
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001633 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001634 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001635
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001636 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001637 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001638 else
1639 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001640 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001641
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001642 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1643 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1644 BDW_FBC_COMPRESSION_MASK :
1645 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001646 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001647 yesno(I915_READ(FBC_STATUS2) & mask));
1648 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001649
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001650 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001651 intel_runtime_pm_put(dev_priv);
1652
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001653 return 0;
1654}
1655
Rodrigo Vivida46f932014-08-01 02:04:45 -07001656static int i915_fbc_fc_get(void *data, u64 *val)
1657{
David Weinehall36cdd012016-08-22 13:59:31 +03001658 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001659
David Weinehall36cdd012016-08-22 13:59:31 +03001660 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001661 return -ENODEV;
1662
Rodrigo Vivida46f932014-08-01 02:04:45 -07001663 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001664
1665 return 0;
1666}
1667
1668static int i915_fbc_fc_set(void *data, u64 val)
1669{
David Weinehall36cdd012016-08-22 13:59:31 +03001670 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001671 u32 reg;
1672
David Weinehall36cdd012016-08-22 13:59:31 +03001673 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001674 return -ENODEV;
1675
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001676 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001677
1678 reg = I915_READ(ILK_DPFC_CONTROL);
1679 dev_priv->fbc.false_color = val;
1680
1681 I915_WRITE(ILK_DPFC_CONTROL, val ?
1682 (reg | FBC_CTL_FALSE_COLOR) :
1683 (reg & ~FBC_CTL_FALSE_COLOR));
1684
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001685 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001686 return 0;
1687}
1688
1689DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1690 i915_fbc_fc_get, i915_fbc_fc_set,
1691 "%llu\n");
1692
Paulo Zanoni92d44622013-05-31 16:33:24 -03001693static int i915_ips_status(struct seq_file *m, void *unused)
1694{
David Weinehall36cdd012016-08-22 13:59:31 +03001695 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001696
David Weinehall36cdd012016-08-22 13:59:31 +03001697 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001698 seq_puts(m, "not supported\n");
1699 return 0;
1700 }
1701
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001702 intel_runtime_pm_get(dev_priv);
1703
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001704 seq_printf(m, "Enabled by kernel parameter: %s\n",
1705 yesno(i915.enable_ips));
1706
David Weinehall36cdd012016-08-22 13:59:31 +03001707 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001708 seq_puts(m, "Currently: unknown\n");
1709 } else {
1710 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1711 seq_puts(m, "Currently: enabled\n");
1712 else
1713 seq_puts(m, "Currently: disabled\n");
1714 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001715
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001716 intel_runtime_pm_put(dev_priv);
1717
Paulo Zanoni92d44622013-05-31 16:33:24 -03001718 return 0;
1719}
1720
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001721static int i915_sr_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);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001724 bool sr_enabled = false;
1725
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001726 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001727 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001728
David Weinehall36cdd012016-08-22 13:59:31 +03001729 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001730 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001731 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1732 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001733 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001734 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001735 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001736 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001737 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001738 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001739 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001740
Chris Wilson9c870d02016-10-24 13:42:15 +01001741 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001742 intel_runtime_pm_put(dev_priv);
1743
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001744 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001745
1746 return 0;
1747}
1748
Jesse Barnes7648fa92010-05-20 14:28:11 -07001749static int i915_emon_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);
1752 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001753 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001754 int ret;
1755
David Weinehall36cdd012016-08-22 13:59:31 +03001756 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001757 return -ENODEV;
1758
Chris Wilsonde227ef2010-07-03 07:58:38 +01001759 ret = mutex_lock_interruptible(&dev->struct_mutex);
1760 if (ret)
1761 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001762
1763 temp = i915_mch_val(dev_priv);
1764 chipset = i915_chipset_val(dev_priv);
1765 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001766 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001767
1768 seq_printf(m, "GMCH temp: %ld\n", temp);
1769 seq_printf(m, "Chipset power: %ld\n", chipset);
1770 seq_printf(m, "GFX power: %ld\n", gfx);
1771 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1772
1773 return 0;
1774}
1775
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001776static int i915_ring_freq_table(struct seq_file *m, void *unused)
1777{
David Weinehall36cdd012016-08-22 13:59:31 +03001778 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001779 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001780 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301781 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001782
Carlos Santa26310342016-08-17 12:30:41 -07001783 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001784 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001785 return 0;
1786 }
1787
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001788 intel_runtime_pm_get(dev_priv);
1789
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001790 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001791 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001792 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001793
David Weinehall36cdd012016-08-22 13:59:31 +03001794 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301795 /* Convert GT frequency to 50 HZ units */
1796 min_gpu_freq =
1797 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1798 max_gpu_freq =
1799 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1800 } else {
1801 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1802 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1803 }
1804
Damien Lespiau267f0c92013-06-24 22:59:48 +01001805 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001806
Akash Goelf936ec32015-06-29 14:50:22 +05301807 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001808 ia_freq = gpu_freq;
1809 sandybridge_pcode_read(dev_priv,
1810 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1811 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001812 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301813 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001814 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001815 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001816 ((ia_freq >> 0) & 0xff) * 100,
1817 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001818 }
1819
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001820 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001821
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001822out:
1823 intel_runtime_pm_put(dev_priv);
1824 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001825}
1826
Chris Wilson44834a62010-08-19 16:09:23 +01001827static int i915_opregion(struct seq_file *m, void *unused)
1828{
David Weinehall36cdd012016-08-22 13:59:31 +03001829 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1830 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001831 struct intel_opregion *opregion = &dev_priv->opregion;
1832 int ret;
1833
1834 ret = mutex_lock_interruptible(&dev->struct_mutex);
1835 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001836 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001837
Jani Nikula2455a8e2015-12-14 12:50:53 +02001838 if (opregion->header)
1839 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001840
1841 mutex_unlock(&dev->struct_mutex);
1842
Daniel Vetter0d38f002012-04-21 22:49:10 +02001843out:
Chris Wilson44834a62010-08-19 16:09:23 +01001844 return 0;
1845}
1846
Jani Nikulaada8f952015-12-15 13:17:12 +02001847static int i915_vbt(struct seq_file *m, void *unused)
1848{
David Weinehall36cdd012016-08-22 13:59:31 +03001849 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001850
1851 if (opregion->vbt)
1852 seq_write(m, opregion->vbt, opregion->vbt_size);
1853
1854 return 0;
1855}
1856
Chris Wilson37811fc2010-08-25 22:45:57 +01001857static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1858{
David Weinehall36cdd012016-08-22 13:59:31 +03001859 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1860 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301861 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001862 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001863 int ret;
1864
1865 ret = mutex_lock_interruptible(&dev->struct_mutex);
1866 if (ret)
1867 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001868
Daniel Vetter06957262015-08-10 13:34:08 +02001869#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001870 if (dev_priv->fbdev) {
1871 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001872
Chris Wilson25bcce92016-07-02 15:36:00 +01001873 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1874 fbdev_fb->base.width,
1875 fbdev_fb->base.height,
1876 fbdev_fb->base.depth,
1877 fbdev_fb->base.bits_per_pixel,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001878 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001879 drm_framebuffer_read_refcount(&fbdev_fb->base));
1880 describe_obj(m, fbdev_fb->obj);
1881 seq_putc(m, '\n');
1882 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001883#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001884
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001885 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001886 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301887 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1888 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001889 continue;
1890
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001891 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 +01001892 fb->base.width,
1893 fb->base.height,
1894 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001895 fb->base.bits_per_pixel,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001896 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001897 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001898 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001899 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001900 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001901 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001902 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001903
1904 return 0;
1905}
1906
Chris Wilson7e37f882016-08-02 22:50:21 +01001907static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001908{
1909 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001910 ring->space, ring->head, ring->tail,
1911 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001912}
1913
Ben Widawskye76d3632011-03-19 18:14:29 -07001914static int i915_context_status(struct seq_file *m, void *unused)
1915{
David Weinehall36cdd012016-08-22 13:59:31 +03001916 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1917 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001918 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001919 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301920 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001921 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001922
Daniel Vetterf3d28872014-05-29 23:23:08 +02001923 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001924 if (ret)
1925 return ret;
1926
Ben Widawskya33afea2013-09-17 21:12:45 -07001927 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001928 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001929 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001930 struct task_struct *task;
1931
Chris Wilsonc84455b2016-08-15 10:49:08 +01001932 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001933 if (task) {
1934 seq_printf(m, "(%s [%d]) ",
1935 task->comm, task->pid);
1936 put_task_struct(task);
1937 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001938 } else if (IS_ERR(ctx->file_priv)) {
1939 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001940 } else {
1941 seq_puts(m, "(kernel) ");
1942 }
1943
Chris Wilsonbca44d82016-05-24 14:53:41 +01001944 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1945 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001946
Akash Goel3b3f1652016-10-13 22:44:48 +05301947 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001948 struct intel_context *ce = &ctx->engine[engine->id];
1949
1950 seq_printf(m, "%s: ", engine->name);
1951 seq_putc(m, ce->initialised ? 'I' : 'i');
1952 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001953 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001954 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001955 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001956 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001957 }
1958
Ben Widawskya33afea2013-09-17 21:12:45 -07001959 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001960 }
1961
Daniel Vetterf3d28872014-05-29 23:23:08 +02001962 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001963
1964 return 0;
1965}
1966
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001967static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001968 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001969 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001970{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001971 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001972 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001973 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001974
Chris Wilson7069b142016-04-28 09:56:52 +01001975 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1976
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001977 if (!vma) {
1978 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001979 return;
1980 }
1981
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001982 if (vma->flags & I915_VMA_GLOBAL_BIND)
1983 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01001984 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001985
Chris Wilsona4f5ea62016-10-28 13:58:35 +01001986 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001987 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001988 return;
1989 }
1990
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001991 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
1992 if (page) {
1993 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001994
1995 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001996 seq_printf(m,
1997 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1998 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001999 reg_state[j], reg_state[j + 1],
2000 reg_state[j + 2], reg_state[j + 3]);
2001 }
2002 kunmap_atomic(reg_state);
2003 }
2004
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002005 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002006 seq_putc(m, '\n');
2007}
2008
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002009static int i915_dump_lrc(struct seq_file *m, void *unused)
2010{
David Weinehall36cdd012016-08-22 13:59:31 +03002011 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2012 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002013 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002014 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302015 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002016 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002017
2018 if (!i915.enable_execlists) {
2019 seq_printf(m, "Logical Ring Contexts are disabled\n");
2020 return 0;
2021 }
2022
2023 ret = mutex_lock_interruptible(&dev->struct_mutex);
2024 if (ret)
2025 return ret;
2026
Dave Gordone28e4042016-01-19 19:02:55 +00002027 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302028 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002029 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002030
2031 mutex_unlock(&dev->struct_mutex);
2032
2033 return 0;
2034}
2035
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002036static const char *swizzle_string(unsigned swizzle)
2037{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002038 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002039 case I915_BIT_6_SWIZZLE_NONE:
2040 return "none";
2041 case I915_BIT_6_SWIZZLE_9:
2042 return "bit9";
2043 case I915_BIT_6_SWIZZLE_9_10:
2044 return "bit9/bit10";
2045 case I915_BIT_6_SWIZZLE_9_11:
2046 return "bit9/bit11";
2047 case I915_BIT_6_SWIZZLE_9_10_11:
2048 return "bit9/bit10/bit11";
2049 case I915_BIT_6_SWIZZLE_9_17:
2050 return "bit9/bit17";
2051 case I915_BIT_6_SWIZZLE_9_10_17:
2052 return "bit9/bit10/bit17";
2053 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002054 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002055 }
2056
2057 return "bug";
2058}
2059
2060static int i915_swizzle_info(struct seq_file *m, void *data)
2061{
David Weinehall36cdd012016-08-22 13:59:31 +03002062 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002063
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002064 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002065
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002066 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2067 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2068 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2069 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2070
David Weinehall36cdd012016-08-22 13:59:31 +03002071 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002072 seq_printf(m, "DDC = 0x%08x\n",
2073 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002074 seq_printf(m, "DDC2 = 0x%08x\n",
2075 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002076 seq_printf(m, "C0DRB3 = 0x%04x\n",
2077 I915_READ16(C0DRB3));
2078 seq_printf(m, "C1DRB3 = 0x%04x\n",
2079 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002080 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002081 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2082 I915_READ(MAD_DIMM_C0));
2083 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2084 I915_READ(MAD_DIMM_C1));
2085 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2086 I915_READ(MAD_DIMM_C2));
2087 seq_printf(m, "TILECTL = 0x%08x\n",
2088 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002089 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002090 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2091 I915_READ(GAMTARBMODE));
2092 else
2093 seq_printf(m, "ARB_MODE = 0x%08x\n",
2094 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002095 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2096 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002097 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002098
2099 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2100 seq_puts(m, "L-shaped memory detected\n");
2101
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002102 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002103
2104 return 0;
2105}
2106
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002107static int per_file_ctx(int id, void *ptr, void *data)
2108{
Chris Wilsone2efd132016-05-24 14:53:34 +01002109 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002110 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002111 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2112
2113 if (!ppgtt) {
2114 seq_printf(m, " no ppgtt for context %d\n",
2115 ctx->user_handle);
2116 return 0;
2117 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002118
Oscar Mateof83d6512014-05-22 14:13:38 +01002119 if (i915_gem_context_is_default(ctx))
2120 seq_puts(m, " default context:\n");
2121 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002122 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002123 ppgtt->debug_dump(ppgtt, m);
2124
2125 return 0;
2126}
2127
David Weinehall36cdd012016-08-22 13:59:31 +03002128static void gen8_ppgtt_info(struct seq_file *m,
2129 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002130{
Ben Widawsky77df6772013-11-02 21:07:30 -07002131 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302132 struct intel_engine_cs *engine;
2133 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002134 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002135
Ben Widawsky77df6772013-11-02 21:07:30 -07002136 if (!ppgtt)
2137 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002138
Akash Goel3b3f1652016-10-13 22:44:48 +05302139 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002140 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002141 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002142 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002143 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002144 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002145 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002146 }
2147 }
2148}
2149
David Weinehall36cdd012016-08-22 13:59:31 +03002150static void gen6_ppgtt_info(struct seq_file *m,
2151 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002152{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002153 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302154 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002155
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002156 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002157 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2158
Akash Goel3b3f1652016-10-13 22:44:48 +05302159 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002160 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002161 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002162 seq_printf(m, "GFX_MODE: 0x%08x\n",
2163 I915_READ(RING_MODE_GEN7(engine)));
2164 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2165 I915_READ(RING_PP_DIR_BASE(engine)));
2166 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2167 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2168 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2169 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002170 }
2171 if (dev_priv->mm.aliasing_ppgtt) {
2172 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2173
Damien Lespiau267f0c92013-06-24 22:59:48 +01002174 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002175 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002176
Ben Widawsky87d60b62013-12-06 14:11:29 -08002177 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002178 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002179
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002180 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002181}
2182
2183static int i915_ppgtt_info(struct seq_file *m, void *data)
2184{
David Weinehall36cdd012016-08-22 13:59:31 +03002185 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2186 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002187 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002188 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002189
Chris Wilson637ee292016-08-22 14:28:20 +01002190 mutex_lock(&dev->filelist_mutex);
2191 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002192 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002193 goto out_unlock;
2194
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002195 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002196
David Weinehall36cdd012016-08-22 13:59:31 +03002197 if (INTEL_GEN(dev_priv) >= 8)
2198 gen8_ppgtt_info(m, dev_priv);
2199 else if (INTEL_GEN(dev_priv) >= 6)
2200 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002201
Michel Thierryea91e402015-07-29 17:23:57 +01002202 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2203 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002204 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002205
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002206 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002207 if (!task) {
2208 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002209 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002210 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002211 seq_printf(m, "\nproc: %s\n", task->comm);
2212 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002213 idr_for_each(&file_priv->context_idr, per_file_ctx,
2214 (void *)(unsigned long)m);
2215 }
2216
Chris Wilson637ee292016-08-22 14:28:20 +01002217out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002218 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002219 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002220out_unlock:
2221 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002222 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002223}
2224
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002225static int count_irq_waiters(struct drm_i915_private *i915)
2226{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002227 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302228 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002229 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002230
Akash Goel3b3f1652016-10-13 22:44:48 +05302231 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002232 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002233
2234 return count;
2235}
2236
Chris Wilson7466c292016-08-15 09:49:33 +01002237static const char *rps_power_to_str(unsigned int power)
2238{
2239 static const char * const strings[] = {
2240 [LOW_POWER] = "low power",
2241 [BETWEEN] = "mixed",
2242 [HIGH_POWER] = "high power",
2243 };
2244
2245 if (power >= ARRAY_SIZE(strings) || !strings[power])
2246 return "unknown";
2247
2248 return strings[power];
2249}
2250
Chris Wilson1854d5c2015-04-07 16:20:32 +01002251static int i915_rps_boost_info(struct seq_file *m, void *data)
2252{
David Weinehall36cdd012016-08-22 13:59:31 +03002253 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2254 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002255 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002256
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002257 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002258 seq_printf(m, "GPU busy? %s [%d requests]\n",
2259 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002260 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002261 seq_printf(m, "Frequency requested %d\n",
2262 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2263 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002264 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2265 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2266 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2267 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002268 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2269 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2270 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2271 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002272
2273 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002274 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002275 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2276 struct drm_i915_file_private *file_priv = file->driver_priv;
2277 struct task_struct *task;
2278
2279 rcu_read_lock();
2280 task = pid_task(file->pid, PIDTYPE_PID);
2281 seq_printf(m, "%s [%d]: %d boosts%s\n",
2282 task ? task->comm : "<unknown>",
2283 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002284 file_priv->rps.boosts,
2285 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002286 rcu_read_unlock();
2287 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002288 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002289 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002290 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002291
Chris Wilson7466c292016-08-15 09:49:33 +01002292 if (INTEL_GEN(dev_priv) >= 6 &&
2293 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002294 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002295 u32 rpup, rpupei;
2296 u32 rpdown, rpdownei;
2297
2298 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2299 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2300 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2301 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2302 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2303 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2304
2305 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2306 rps_power_to_str(dev_priv->rps.power));
2307 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2308 100 * rpup / rpupei,
2309 dev_priv->rps.up_threshold);
2310 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2311 100 * rpdown / rpdownei,
2312 dev_priv->rps.down_threshold);
2313 } else {
2314 seq_puts(m, "\nRPS Autotuning inactive\n");
2315 }
2316
Chris Wilson8d3afd72015-05-21 21:01:47 +01002317 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002318}
2319
Ben Widawsky63573eb2013-07-04 11:02:07 -07002320static int i915_llc(struct seq_file *m, void *data)
2321{
David Weinehall36cdd012016-08-22 13:59:31 +03002322 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002323 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002324
David Weinehall36cdd012016-08-22 13:59:31 +03002325 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002326 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2327 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002328
2329 return 0;
2330}
2331
Alex Daifdf5d352015-08-12 15:43:37 +01002332static int i915_guc_load_status_info(struct seq_file *m, void *data)
2333{
David Weinehall36cdd012016-08-22 13:59:31 +03002334 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002335 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2336 u32 tmp, i;
2337
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002338 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002339 return 0;
2340
2341 seq_printf(m, "GuC firmware status:\n");
2342 seq_printf(m, "\tpath: %s\n",
2343 guc_fw->guc_fw_path);
2344 seq_printf(m, "\tfetch: %s\n",
2345 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2346 seq_printf(m, "\tload: %s\n",
2347 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2348 seq_printf(m, "\tversion wanted: %d.%d\n",
2349 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2350 seq_printf(m, "\tversion found: %d.%d\n",
2351 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002352 seq_printf(m, "\theader: offset is %d; size = %d\n",
2353 guc_fw->header_offset, guc_fw->header_size);
2354 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2355 guc_fw->ucode_offset, guc_fw->ucode_size);
2356 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2357 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002358
2359 tmp = I915_READ(GUC_STATUS);
2360
2361 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2362 seq_printf(m, "\tBootrom status = 0x%x\n",
2363 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2364 seq_printf(m, "\tuKernel status = 0x%x\n",
2365 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2366 seq_printf(m, "\tMIA Core status = 0x%x\n",
2367 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2368 seq_puts(m, "\nScratch registers:\n");
2369 for (i = 0; i < 16; i++)
2370 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2371
2372 return 0;
2373}
2374
Akash Goel5aa1ee42016-10-12 21:54:36 +05302375static void i915_guc_log_info(struct seq_file *m,
2376 struct drm_i915_private *dev_priv)
2377{
2378 struct intel_guc *guc = &dev_priv->guc;
2379
2380 seq_puts(m, "\nGuC logging stats:\n");
2381
2382 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2383 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2384 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2385
2386 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2387 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2388 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2389
2390 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2391 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2392 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2393
2394 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2395 guc->log.flush_interrupt_count);
2396
2397 seq_printf(m, "\tCapture miss count: %u\n",
2398 guc->log.capture_miss_count);
2399}
2400
Dave Gordon8b417c22015-08-12 15:43:44 +01002401static void i915_guc_client_info(struct seq_file *m,
2402 struct drm_i915_private *dev_priv,
2403 struct i915_guc_client *client)
2404{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002405 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002406 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002407 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002408
2409 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2410 client->priority, client->ctx_index, client->proc_desc_offset);
2411 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2412 client->doorbell_id, client->doorbell_offset, client->cookie);
2413 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2414 client->wq_size, client->wq_offset, client->wq_tail);
2415
Dave Gordon551aaec2016-05-13 15:36:33 +01002416 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002417 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2418 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2419
Akash Goel3b3f1652016-10-13 22:44:48 +05302420 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002421 u64 submissions = client->submissions[id];
2422 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002423 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002424 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002425 }
2426 seq_printf(m, "\tTotal: %llu\n", tot);
2427}
2428
2429static int i915_guc_info(struct seq_file *m, void *data)
2430{
David Weinehall36cdd012016-08-22 13:59:31 +03002431 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2432 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002433 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002434 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002435 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002436 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002437 u64 total = 0;
2438
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002439 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002440 return 0;
2441
Alex Dai5a843302015-12-02 16:56:29 -08002442 if (mutex_lock_interruptible(&dev->struct_mutex))
2443 return 0;
2444
Dave Gordon8b417c22015-08-12 15:43:44 +01002445 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002446 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002447 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002448 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002449
2450 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002451
Dave Gordon9636f6d2016-06-13 17:57:28 +01002452 seq_printf(m, "Doorbell map:\n");
2453 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2454 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2455
Dave Gordon8b417c22015-08-12 15:43:44 +01002456 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2457 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2458 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2459 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2460 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2461
2462 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302463 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002464 u64 submissions = guc.submissions[id];
2465 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002466 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002467 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002468 }
2469 seq_printf(m, "\t%s: %llu\n", "Total", total);
2470
2471 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2472 i915_guc_client_info(m, dev_priv, &client);
2473
Akash Goel5aa1ee42016-10-12 21:54:36 +05302474 i915_guc_log_info(m, dev_priv);
2475
Dave Gordon8b417c22015-08-12 15:43:44 +01002476 /* Add more as required ... */
2477
2478 return 0;
2479}
2480
Alex Dai4c7e77f2015-08-12 15:43:40 +01002481static int i915_guc_log_dump(struct seq_file *m, void *data)
2482{
David Weinehall36cdd012016-08-22 13:59:31 +03002483 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002484 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002485 int i = 0, pg;
2486
Akash Goeld6b40b42016-10-12 21:54:29 +05302487 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002488 return 0;
2489
Akash Goeld6b40b42016-10-12 21:54:29 +05302490 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002491 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2492 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002493
2494 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2495 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2496 *(log + i), *(log + i + 1),
2497 *(log + i + 2), *(log + i + 3));
2498
2499 kunmap_atomic(log);
2500 }
2501
2502 seq_putc(m, '\n');
2503
2504 return 0;
2505}
2506
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302507static int i915_guc_log_control_get(void *data, u64 *val)
2508{
2509 struct drm_device *dev = data;
2510 struct drm_i915_private *dev_priv = to_i915(dev);
2511
2512 if (!dev_priv->guc.log.vma)
2513 return -EINVAL;
2514
2515 *val = i915.guc_log_level;
2516
2517 return 0;
2518}
2519
2520static int i915_guc_log_control_set(void *data, u64 val)
2521{
2522 struct drm_device *dev = data;
2523 struct drm_i915_private *dev_priv = to_i915(dev);
2524 int ret;
2525
2526 if (!dev_priv->guc.log.vma)
2527 return -EINVAL;
2528
2529 ret = mutex_lock_interruptible(&dev->struct_mutex);
2530 if (ret)
2531 return ret;
2532
2533 intel_runtime_pm_get(dev_priv);
2534 ret = i915_guc_log_control(dev_priv, val);
2535 intel_runtime_pm_put(dev_priv);
2536
2537 mutex_unlock(&dev->struct_mutex);
2538 return ret;
2539}
2540
2541DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2542 i915_guc_log_control_get, i915_guc_log_control_set,
2543 "%lld\n");
2544
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002545static int i915_edp_psr_status(struct seq_file *m, void *data)
2546{
David Weinehall36cdd012016-08-22 13:59:31 +03002547 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002548 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002549 u32 stat[3];
2550 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002551 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002552
David Weinehall36cdd012016-08-22 13:59:31 +03002553 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002554 seq_puts(m, "PSR not supported\n");
2555 return 0;
2556 }
2557
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002558 intel_runtime_pm_get(dev_priv);
2559
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002560 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002561 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2562 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002563 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002564 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002565 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2566 dev_priv->psr.busy_frontbuffer_bits);
2567 seq_printf(m, "Re-enable work scheduled: %s\n",
2568 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002569
David Weinehall36cdd012016-08-22 13:59:31 +03002570 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002571 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002572 else {
2573 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002574 enum transcoder cpu_transcoder =
2575 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2576 enum intel_display_power_domain power_domain;
2577
2578 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2579 if (!intel_display_power_get_if_enabled(dev_priv,
2580 power_domain))
2581 continue;
2582
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002583 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2584 VLV_EDP_PSR_CURR_STATE_MASK;
2585 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2586 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2587 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002588
2589 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002590 }
2591 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002592
2593 seq_printf(m, "Main link in standby mode: %s\n",
2594 yesno(dev_priv->psr.link_standby));
2595
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002596 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002597
David Weinehall36cdd012016-08-22 13:59:31 +03002598 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002599 for_each_pipe(dev_priv, pipe) {
2600 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2601 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2602 seq_printf(m, " pipe %c", pipe_name(pipe));
2603 }
2604 seq_puts(m, "\n");
2605
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002606 /*
2607 * VLV/CHV PSR has no kind of performance counter
2608 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2609 */
David Weinehall36cdd012016-08-22 13:59:31 +03002610 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002611 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002612 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002613
2614 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2615 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002616 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002617
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002618 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002619 return 0;
2620}
2621
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002622static int i915_sink_crc(struct seq_file *m, void *data)
2623{
David Weinehall36cdd012016-08-22 13:59:31 +03002624 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2625 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002626 struct intel_connector *connector;
2627 struct intel_dp *intel_dp = NULL;
2628 int ret;
2629 u8 crc[6];
2630
2631 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002632 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002633 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002634
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002635 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002636 continue;
2637
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002638 crtc = connector->base.state->crtc;
2639 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002640 continue;
2641
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002642 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002643 continue;
2644
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002645 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002646
2647 ret = intel_dp_sink_crc(intel_dp, crc);
2648 if (ret)
2649 goto out;
2650
2651 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2652 crc[0], crc[1], crc[2],
2653 crc[3], crc[4], crc[5]);
2654 goto out;
2655 }
2656 ret = -ENODEV;
2657out:
2658 drm_modeset_unlock_all(dev);
2659 return ret;
2660}
2661
Jesse Barnesec013e72013-08-20 10:29:23 +01002662static int i915_energy_uJ(struct seq_file *m, void *data)
2663{
David Weinehall36cdd012016-08-22 13:59:31 +03002664 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002665 u64 power;
2666 u32 units;
2667
David Weinehall36cdd012016-08-22 13:59:31 +03002668 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002669 return -ENODEV;
2670
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002671 intel_runtime_pm_get(dev_priv);
2672
Jesse Barnesec013e72013-08-20 10:29:23 +01002673 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2674 power = (power & 0x1f00) >> 8;
2675 units = 1000000 / (1 << power); /* convert to uJ */
2676 power = I915_READ(MCH_SECP_NRG_STTS);
2677 power *= units;
2678
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002679 intel_runtime_pm_put(dev_priv);
2680
Jesse Barnesec013e72013-08-20 10:29:23 +01002681 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002682
2683 return 0;
2684}
2685
Damien Lespiau6455c872015-06-04 18:23:57 +01002686static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002687{
David Weinehall36cdd012016-08-22 13:59:31 +03002688 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002689 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002690
Chris Wilsona156e642016-04-03 14:14:21 +01002691 if (!HAS_RUNTIME_PM(dev_priv))
2692 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002693
Chris Wilson67d97da2016-07-04 08:08:31 +01002694 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002695 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002696 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002697#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002698 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002699 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002700#else
2701 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2702#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002703 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002704 pci_power_name(pdev->current_state),
2705 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002706
Jesse Barnesec013e72013-08-20 10:29:23 +01002707 return 0;
2708}
2709
Imre Deak1da51582013-11-25 17:15:35 +02002710static int i915_power_domain_info(struct seq_file *m, void *unused)
2711{
David Weinehall36cdd012016-08-22 13:59:31 +03002712 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002713 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2714 int i;
2715
2716 mutex_lock(&power_domains->lock);
2717
2718 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2719 for (i = 0; i < power_domains->power_well_count; i++) {
2720 struct i915_power_well *power_well;
2721 enum intel_display_power_domain power_domain;
2722
2723 power_well = &power_domains->power_wells[i];
2724 seq_printf(m, "%-25s %d\n", power_well->name,
2725 power_well->count);
2726
2727 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2728 power_domain++) {
2729 if (!(BIT(power_domain) & power_well->domains))
2730 continue;
2731
2732 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002733 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002734 power_domains->domain_use_count[power_domain]);
2735 }
2736 }
2737
2738 mutex_unlock(&power_domains->lock);
2739
2740 return 0;
2741}
2742
Damien Lespiaub7cec662015-10-27 14:47:01 +02002743static int i915_dmc_info(struct seq_file *m, void *unused)
2744{
David Weinehall36cdd012016-08-22 13:59:31 +03002745 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002746 struct intel_csr *csr;
2747
David Weinehall36cdd012016-08-22 13:59:31 +03002748 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002749 seq_puts(m, "not supported\n");
2750 return 0;
2751 }
2752
2753 csr = &dev_priv->csr;
2754
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002755 intel_runtime_pm_get(dev_priv);
2756
Damien Lespiaub7cec662015-10-27 14:47:01 +02002757 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2758 seq_printf(m, "path: %s\n", csr->fw_path);
2759
2760 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002761 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002762
2763 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2764 CSR_VERSION_MINOR(csr->version));
2765
David Weinehall36cdd012016-08-22 13:59:31 +03002766 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002767 seq_printf(m, "DC3 -> DC5 count: %d\n",
2768 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2769 seq_printf(m, "DC5 -> DC6 count: %d\n",
2770 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002771 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002772 seq_printf(m, "DC3 -> DC5 count: %d\n",
2773 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002774 }
2775
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002776out:
2777 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2778 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2779 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2780
Damien Lespiau83372062015-10-30 17:53:32 +02002781 intel_runtime_pm_put(dev_priv);
2782
Damien Lespiaub7cec662015-10-27 14:47:01 +02002783 return 0;
2784}
2785
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002786static void intel_seq_print_mode(struct seq_file *m, int tabs,
2787 struct drm_display_mode *mode)
2788{
2789 int i;
2790
2791 for (i = 0; i < tabs; i++)
2792 seq_putc(m, '\t');
2793
2794 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",
2795 mode->base.id, mode->name,
2796 mode->vrefresh, mode->clock,
2797 mode->hdisplay, mode->hsync_start,
2798 mode->hsync_end, mode->htotal,
2799 mode->vdisplay, mode->vsync_start,
2800 mode->vsync_end, mode->vtotal,
2801 mode->type, mode->flags);
2802}
2803
2804static void intel_encoder_info(struct seq_file *m,
2805 struct intel_crtc *intel_crtc,
2806 struct intel_encoder *intel_encoder)
2807{
David Weinehall36cdd012016-08-22 13:59:31 +03002808 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2809 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002810 struct drm_crtc *crtc = &intel_crtc->base;
2811 struct intel_connector *intel_connector;
2812 struct drm_encoder *encoder;
2813
2814 encoder = &intel_encoder->base;
2815 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002816 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002817 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2818 struct drm_connector *connector = &intel_connector->base;
2819 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2820 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002821 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002822 drm_get_connector_status_name(connector->status));
2823 if (connector->status == connector_status_connected) {
2824 struct drm_display_mode *mode = &crtc->mode;
2825 seq_printf(m, ", mode:\n");
2826 intel_seq_print_mode(m, 2, mode);
2827 } else {
2828 seq_putc(m, '\n');
2829 }
2830 }
2831}
2832
2833static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2834{
David Weinehall36cdd012016-08-22 13:59:31 +03002835 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2836 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002837 struct drm_crtc *crtc = &intel_crtc->base;
2838 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002839 struct drm_plane_state *plane_state = crtc->primary->state;
2840 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002841
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002842 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002843 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002844 fb->base.id, plane_state->src_x >> 16,
2845 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002846 else
2847 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002848 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2849 intel_encoder_info(m, intel_crtc, intel_encoder);
2850}
2851
2852static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2853{
2854 struct drm_display_mode *mode = panel->fixed_mode;
2855
2856 seq_printf(m, "\tfixed mode:\n");
2857 intel_seq_print_mode(m, 2, mode);
2858}
2859
2860static void intel_dp_info(struct seq_file *m,
2861 struct intel_connector *intel_connector)
2862{
2863 struct intel_encoder *intel_encoder = intel_connector->encoder;
2864 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2865
2866 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002867 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002868 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002869 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002870
2871 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2872 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002873}
2874
2875static void intel_hdmi_info(struct seq_file *m,
2876 struct intel_connector *intel_connector)
2877{
2878 struct intel_encoder *intel_encoder = intel_connector->encoder;
2879 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2880
Jani Nikula742f4912015-09-03 11:16:09 +03002881 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002882}
2883
2884static void intel_lvds_info(struct seq_file *m,
2885 struct intel_connector *intel_connector)
2886{
2887 intel_panel_info(m, &intel_connector->panel);
2888}
2889
2890static void intel_connector_info(struct seq_file *m,
2891 struct drm_connector *connector)
2892{
2893 struct intel_connector *intel_connector = to_intel_connector(connector);
2894 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002895 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002896
2897 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002898 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002899 drm_get_connector_status_name(connector->status));
2900 if (connector->status == connector_status_connected) {
2901 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2902 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2903 connector->display_info.width_mm,
2904 connector->display_info.height_mm);
2905 seq_printf(m, "\tsubpixel order: %s\n",
2906 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2907 seq_printf(m, "\tCEA rev: %d\n",
2908 connector->display_info.cea_rev);
2909 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002910
2911 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2912 return;
2913
2914 switch (connector->connector_type) {
2915 case DRM_MODE_CONNECTOR_DisplayPort:
2916 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002917 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002918 break;
2919 case DRM_MODE_CONNECTOR_LVDS:
2920 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002921 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002922 break;
2923 case DRM_MODE_CONNECTOR_HDMIA:
2924 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2925 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2926 intel_hdmi_info(m, intel_connector);
2927 break;
2928 default:
2929 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002930 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002931
Jesse Barnesf103fc72014-02-20 12:39:57 -08002932 seq_printf(m, "\tmodes:\n");
2933 list_for_each_entry(mode, &connector->modes, head)
2934 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002935}
2936
David Weinehall36cdd012016-08-22 13:59:31 +03002937static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002938{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002939 u32 state;
2940
David Weinehall36cdd012016-08-22 13:59:31 +03002941 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002942 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002943 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002944 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002945
2946 return state;
2947}
2948
David Weinehall36cdd012016-08-22 13:59:31 +03002949static bool cursor_position(struct drm_i915_private *dev_priv,
2950 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002951{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002952 u32 pos;
2953
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002954 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002955
2956 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2957 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2958 *x = -*x;
2959
2960 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2961 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2962 *y = -*y;
2963
David Weinehall36cdd012016-08-22 13:59:31 +03002964 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002965}
2966
Robert Fekete3abc4e02015-10-27 16:58:32 +01002967static const char *plane_type(enum drm_plane_type type)
2968{
2969 switch (type) {
2970 case DRM_PLANE_TYPE_OVERLAY:
2971 return "OVL";
2972 case DRM_PLANE_TYPE_PRIMARY:
2973 return "PRI";
2974 case DRM_PLANE_TYPE_CURSOR:
2975 return "CUR";
2976 /*
2977 * Deliberately omitting default: to generate compiler warnings
2978 * when a new drm_plane_type gets added.
2979 */
2980 }
2981
2982 return "unknown";
2983}
2984
2985static const char *plane_rotation(unsigned int rotation)
2986{
2987 static char buf[48];
2988 /*
2989 * According to doc only one DRM_ROTATE_ is allowed but this
2990 * will print them all to visualize if the values are misused
2991 */
2992 snprintf(buf, sizeof(buf),
2993 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03002994 (rotation & DRM_ROTATE_0) ? "0 " : "",
2995 (rotation & DRM_ROTATE_90) ? "90 " : "",
2996 (rotation & DRM_ROTATE_180) ? "180 " : "",
2997 (rotation & DRM_ROTATE_270) ? "270 " : "",
2998 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
2999 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003000 rotation);
3001
3002 return buf;
3003}
3004
3005static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3006{
David Weinehall36cdd012016-08-22 13:59:31 +03003007 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3008 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003009 struct intel_plane *intel_plane;
3010
3011 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3012 struct drm_plane_state *state;
3013 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003014 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003015
3016 if (!plane->state) {
3017 seq_puts(m, "plane->state is NULL!\n");
3018 continue;
3019 }
3020
3021 state = plane->state;
3022
Eric Engestrom90844f02016-08-15 01:02:38 +01003023 if (state->fb) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003024 drm_get_format_name(state->fb->pixel_format, &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003025 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003026 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003027 }
3028
Robert Fekete3abc4e02015-10-27 16:58:32 +01003029 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",
3030 plane->base.id,
3031 plane_type(intel_plane->base.type),
3032 state->crtc_x, state->crtc_y,
3033 state->crtc_w, state->crtc_h,
3034 (state->src_x >> 16),
3035 ((state->src_x & 0xffff) * 15625) >> 10,
3036 (state->src_y >> 16),
3037 ((state->src_y & 0xffff) * 15625) >> 10,
3038 (state->src_w >> 16),
3039 ((state->src_w & 0xffff) * 15625) >> 10,
3040 (state->src_h >> 16),
3041 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003042 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003043 plane_rotation(state->rotation));
3044 }
3045}
3046
3047static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3048{
3049 struct intel_crtc_state *pipe_config;
3050 int num_scalers = intel_crtc->num_scalers;
3051 int i;
3052
3053 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3054
3055 /* Not all platformas have a scaler */
3056 if (num_scalers) {
3057 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3058 num_scalers,
3059 pipe_config->scaler_state.scaler_users,
3060 pipe_config->scaler_state.scaler_id);
3061
3062 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3063 struct intel_scaler *sc =
3064 &pipe_config->scaler_state.scalers[i];
3065
3066 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3067 i, yesno(sc->in_use), sc->mode);
3068 }
3069 seq_puts(m, "\n");
3070 } else {
3071 seq_puts(m, "\tNo scalers available on this platform\n");
3072 }
3073}
3074
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003075static int i915_display_info(struct seq_file *m, void *unused)
3076{
David Weinehall36cdd012016-08-22 13:59:31 +03003077 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3078 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003079 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003080 struct drm_connector *connector;
3081
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003082 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003083 drm_modeset_lock_all(dev);
3084 seq_printf(m, "CRTC info\n");
3085 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003086 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003087 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003088 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003089 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003090
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003091 pipe_config = to_intel_crtc_state(crtc->base.state);
3092
Robert Fekete3abc4e02015-10-27 16:58:32 +01003093 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003094 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003095 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003096 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3097 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3098
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003099 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003100 intel_crtc_info(m, crtc);
3101
David Weinehall36cdd012016-08-22 13:59:31 +03003102 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003103 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 +03003104 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003105 x, y, crtc->base.cursor->state->crtc_w,
3106 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003107 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003108 intel_scaler_info(m, crtc);
3109 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003110 }
Daniel Vettercace8412014-05-22 17:56:31 +02003111
3112 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3113 yesno(!crtc->cpu_fifo_underrun_disabled),
3114 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003115 }
3116
3117 seq_printf(m, "\n");
3118 seq_printf(m, "Connector info\n");
3119 seq_printf(m, "--------------\n");
3120 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3121 intel_connector_info(m, connector);
3122 }
3123 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003124 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003125
3126 return 0;
3127}
3128
Chris Wilson1b365952016-10-04 21:11:31 +01003129static int i915_engine_info(struct seq_file *m, void *unused)
3130{
3131 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3132 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303133 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003134
Chris Wilson9c870d02016-10-24 13:42:15 +01003135 intel_runtime_pm_get(dev_priv);
3136
Akash Goel3b3f1652016-10-13 22:44:48 +05303137 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003138 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3139 struct drm_i915_gem_request *rq;
3140 struct rb_node *rb;
3141 u64 addr;
3142
3143 seq_printf(m, "%s\n", engine->name);
3144 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3145 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003146 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003147 engine->hangcheck.seqno,
3148 engine->hangcheck.score);
3149
3150 rcu_read_lock();
3151
3152 seq_printf(m, "\tRequests:\n");
3153
Chris Wilson73cb9702016-10-28 13:58:46 +01003154 rq = list_first_entry(&engine->timeline->requests,
3155 struct drm_i915_gem_request, link);
3156 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003157 print_request(m, rq, "\t\tfirst ");
3158
Chris Wilson73cb9702016-10-28 13:58:46 +01003159 rq = list_last_entry(&engine->timeline->requests,
3160 struct drm_i915_gem_request, link);
3161 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003162 print_request(m, rq, "\t\tlast ");
3163
3164 rq = i915_gem_find_active_request(engine);
3165 if (rq) {
3166 print_request(m, rq, "\t\tactive ");
3167 seq_printf(m,
3168 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3169 rq->head, rq->postfix, rq->tail,
3170 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3171 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3172 }
3173
3174 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3175 I915_READ(RING_START(engine->mmio_base)),
3176 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3177 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3178 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3179 rq ? rq->ring->head : 0);
3180 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3181 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3182 rq ? rq->ring->tail : 0);
3183 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3184 I915_READ(RING_CTL(engine->mmio_base)),
3185 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3186
3187 rcu_read_unlock();
3188
3189 addr = intel_engine_get_active_head(engine);
3190 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3191 upper_32_bits(addr), lower_32_bits(addr));
3192 addr = intel_engine_get_last_batch_head(engine);
3193 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3194 upper_32_bits(addr), lower_32_bits(addr));
3195
3196 if (i915.enable_execlists) {
3197 u32 ptr, read, write;
Chris Wilson20311bd2016-11-14 20:41:03 +00003198 struct rb_node *rb;
Chris Wilson1b365952016-10-04 21:11:31 +01003199
3200 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3201 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3202 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3203
3204 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3205 read = GEN8_CSB_READ_PTR(ptr);
3206 write = GEN8_CSB_WRITE_PTR(ptr);
3207 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3208 read, write);
3209 if (read >= GEN8_CSB_ENTRIES)
3210 read = 0;
3211 if (write >= GEN8_CSB_ENTRIES)
3212 write = 0;
3213 if (read > write)
3214 write += GEN8_CSB_ENTRIES;
3215 while (read < write) {
3216 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3217
3218 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3219 idx,
3220 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3221 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3222 }
3223
3224 rcu_read_lock();
3225 rq = READ_ONCE(engine->execlist_port[0].request);
3226 if (rq)
3227 print_request(m, rq, "\t\tELSP[0] ");
3228 else
3229 seq_printf(m, "\t\tELSP[0] idle\n");
3230 rq = READ_ONCE(engine->execlist_port[1].request);
3231 if (rq)
3232 print_request(m, rq, "\t\tELSP[1] ");
3233 else
3234 seq_printf(m, "\t\tELSP[1] idle\n");
3235 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003236
Chris Wilson663f71e2016-11-14 20:41:00 +00003237 spin_lock_irq(&engine->timeline->lock);
Chris Wilson20311bd2016-11-14 20:41:03 +00003238 for (rb = engine->execlist_first; rb; rb = rb_next(rb)) {
3239 rq = rb_entry(rb, typeof(*rq), priotree.node);
Chris Wilsonc8247c02016-10-27 01:03:43 +01003240 print_request(m, rq, "\t\tQ ");
3241 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003242 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003243 } else if (INTEL_GEN(dev_priv) > 6) {
3244 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3245 I915_READ(RING_PP_DIR_BASE(engine)));
3246 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3247 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3248 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3249 I915_READ(RING_PP_DIR_DCLV(engine)));
3250 }
3251
Chris Wilsonf6168e32016-10-28 13:58:55 +01003252 spin_lock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003253 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3254 struct intel_wait *w = container_of(rb, typeof(*w), node);
3255
3256 seq_printf(m, "\t%s [%d] waiting for %x\n",
3257 w->tsk->comm, w->tsk->pid, w->seqno);
3258 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01003259 spin_unlock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003260
3261 seq_puts(m, "\n");
3262 }
3263
Chris Wilson9c870d02016-10-24 13:42:15 +01003264 intel_runtime_pm_put(dev_priv);
3265
Chris Wilson1b365952016-10-04 21:11:31 +01003266 return 0;
3267}
3268
Ben Widawskye04934c2014-06-30 09:53:42 -07003269static int i915_semaphore_status(struct seq_file *m, void *unused)
3270{
David Weinehall36cdd012016-08-22 13:59:31 +03003271 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3272 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003273 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003274 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003275 enum intel_engine_id id;
3276 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003277
Chris Wilson39df9192016-07-20 13:31:57 +01003278 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003279 seq_puts(m, "Semaphores are disabled\n");
3280 return 0;
3281 }
3282
3283 ret = mutex_lock_interruptible(&dev->struct_mutex);
3284 if (ret)
3285 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003286 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003287
David Weinehall36cdd012016-08-22 13:59:31 +03003288 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003289 struct page *page;
3290 uint64_t *seqno;
3291
Chris Wilson51d545d2016-08-15 10:49:02 +01003292 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003293
3294 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303295 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003296 uint64_t offset;
3297
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003298 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003299
3300 seq_puts(m, " Last signal:");
3301 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003302 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003303 seq_printf(m, "0x%08llx (0x%02llx) ",
3304 seqno[offset], offset * 8);
3305 }
3306 seq_putc(m, '\n');
3307
3308 seq_puts(m, " Last wait: ");
3309 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003310 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003311 seq_printf(m, "0x%08llx (0x%02llx) ",
3312 seqno[offset], offset * 8);
3313 }
3314 seq_putc(m, '\n');
3315
3316 }
3317 kunmap_atomic(seqno);
3318 } else {
3319 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303320 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003321 for (j = 0; j < num_rings; j++)
3322 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003323 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003324 seq_putc(m, '\n');
3325 }
3326
Paulo Zanoni03872062014-07-09 14:31:57 -03003327 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003328 mutex_unlock(&dev->struct_mutex);
3329 return 0;
3330}
3331
Daniel Vetter728e29d2014-06-25 22:01:53 +03003332static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3333{
David Weinehall36cdd012016-08-22 13:59:31 +03003334 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3335 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003336 int i;
3337
3338 drm_modeset_lock_all(dev);
3339 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3340 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3341
3342 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003343 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3344 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003345 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003346 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3347 seq_printf(m, " dpll_md: 0x%08x\n",
3348 pll->config.hw_state.dpll_md);
3349 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3350 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3351 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003352 }
3353 drm_modeset_unlock_all(dev);
3354
3355 return 0;
3356}
3357
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003358static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003359{
3360 int i;
3361 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003362 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003363 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3364 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003365 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003366 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003367
Arun Siluvery888b5992014-08-26 14:44:51 +01003368 ret = mutex_lock_interruptible(&dev->struct_mutex);
3369 if (ret)
3370 return ret;
3371
3372 intel_runtime_pm_get(dev_priv);
3373
Arun Siluvery33136b02016-01-21 21:43:47 +00003374 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303375 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003376 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003377 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003378 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003379 i915_reg_t addr;
3380 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003381 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003382
Arun Siluvery33136b02016-01-21 21:43:47 +00003383 addr = workarounds->reg[i].addr;
3384 mask = workarounds->reg[i].mask;
3385 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003386 read = I915_READ(addr);
3387 ok = (value & mask) == (read & mask);
3388 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 +02003389 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003390 }
3391
3392 intel_runtime_pm_put(dev_priv);
3393 mutex_unlock(&dev->struct_mutex);
3394
3395 return 0;
3396}
3397
Damien Lespiauc5511e42014-11-04 17:06:51 +00003398static int i915_ddb_info(struct seq_file *m, void *unused)
3399{
David Weinehall36cdd012016-08-22 13:59:31 +03003400 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3401 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003402 struct skl_ddb_allocation *ddb;
3403 struct skl_ddb_entry *entry;
3404 enum pipe pipe;
3405 int plane;
3406
David Weinehall36cdd012016-08-22 13:59:31 +03003407 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003408 return 0;
3409
Damien Lespiauc5511e42014-11-04 17:06:51 +00003410 drm_modeset_lock_all(dev);
3411
3412 ddb = &dev_priv->wm.skl_hw.ddb;
3413
3414 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3415
3416 for_each_pipe(dev_priv, pipe) {
3417 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3418
Matt Roper8b364b42016-10-26 15:51:28 -07003419 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003420 entry = &ddb->plane[pipe][plane];
3421 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3422 entry->start, entry->end,
3423 skl_ddb_entry_size(entry));
3424 }
3425
Matt Roper4969d332015-09-24 15:53:10 -07003426 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003427 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3428 entry->end, skl_ddb_entry_size(entry));
3429 }
3430
3431 drm_modeset_unlock_all(dev);
3432
3433 return 0;
3434}
3435
Vandana Kannana54746e2015-03-03 20:53:10 +05303436static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003437 struct drm_device *dev,
3438 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303439{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003440 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303441 struct i915_drrs *drrs = &dev_priv->drrs;
3442 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003443 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303444
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003445 drm_for_each_connector(connector, dev) {
3446 if (connector->state->crtc != &intel_crtc->base)
3447 continue;
3448
3449 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303450 }
3451
3452 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3453 seq_puts(m, "\tVBT: DRRS_type: Static");
3454 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3455 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3456 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3457 seq_puts(m, "\tVBT: DRRS_type: None");
3458 else
3459 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3460
3461 seq_puts(m, "\n\n");
3462
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003463 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303464 struct intel_panel *panel;
3465
3466 mutex_lock(&drrs->mutex);
3467 /* DRRS Supported */
3468 seq_puts(m, "\tDRRS Supported: Yes\n");
3469
3470 /* disable_drrs() will make drrs->dp NULL */
3471 if (!drrs->dp) {
3472 seq_puts(m, "Idleness DRRS: Disabled");
3473 mutex_unlock(&drrs->mutex);
3474 return;
3475 }
3476
3477 panel = &drrs->dp->attached_connector->panel;
3478 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3479 drrs->busy_frontbuffer_bits);
3480
3481 seq_puts(m, "\n\t\t");
3482 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3483 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3484 vrefresh = panel->fixed_mode->vrefresh;
3485 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3486 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3487 vrefresh = panel->downclock_mode->vrefresh;
3488 } else {
3489 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3490 drrs->refresh_rate_type);
3491 mutex_unlock(&drrs->mutex);
3492 return;
3493 }
3494 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3495
3496 seq_puts(m, "\n\t\t");
3497 mutex_unlock(&drrs->mutex);
3498 } else {
3499 /* DRRS not supported. Print the VBT parameter*/
3500 seq_puts(m, "\tDRRS Supported : No");
3501 }
3502 seq_puts(m, "\n");
3503}
3504
3505static int i915_drrs_status(struct seq_file *m, void *unused)
3506{
David Weinehall36cdd012016-08-22 13:59:31 +03003507 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3508 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303509 struct intel_crtc *intel_crtc;
3510 int active_crtc_cnt = 0;
3511
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003512 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303513 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003514 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303515 active_crtc_cnt++;
3516 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3517
3518 drrs_status_per_crtc(m, dev, intel_crtc);
3519 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303520 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003521 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303522
3523 if (!active_crtc_cnt)
3524 seq_puts(m, "No active crtc found\n");
3525
3526 return 0;
3527}
3528
Damien Lespiau07144422013-10-15 18:55:40 +01003529struct pipe_crc_info {
3530 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003531 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003532 enum pipe pipe;
3533};
3534
Dave Airlie11bed952014-05-12 15:22:27 +10003535static int i915_dp_mst_info(struct seq_file *m, void *unused)
3536{
David Weinehall36cdd012016-08-22 13:59:31 +03003537 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3538 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003539 struct intel_encoder *intel_encoder;
3540 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003541 struct drm_connector *connector;
3542
Dave Airlie11bed952014-05-12 15:22:27 +10003543 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003544 drm_for_each_connector(connector, dev) {
3545 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003546 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003547
3548 intel_encoder = intel_attached_encoder(connector);
3549 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3550 continue;
3551
3552 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003553 if (!intel_dig_port->dp.can_mst)
3554 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003555
Jim Bride40ae80c2016-04-14 10:18:37 -07003556 seq_printf(m, "MST Source Port %c\n",
3557 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003558 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3559 }
3560 drm_modeset_unlock_all(dev);
3561 return 0;
3562}
3563
Damien Lespiau07144422013-10-15 18:55:40 +01003564static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003565{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003566 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003567 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003568 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3569
David Weinehall36cdd012016-08-22 13:59:31 +03003570 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003571 return -ENODEV;
3572
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003573 spin_lock_irq(&pipe_crc->lock);
3574
3575 if (pipe_crc->opened) {
3576 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003577 return -EBUSY; /* already open */
3578 }
3579
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003580 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003581 filep->private_data = inode->i_private;
3582
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003583 spin_unlock_irq(&pipe_crc->lock);
3584
Damien Lespiau07144422013-10-15 18:55:40 +01003585 return 0;
3586}
3587
3588static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3589{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003590 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003591 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003592 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3593
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003594 spin_lock_irq(&pipe_crc->lock);
3595 pipe_crc->opened = false;
3596 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003597
Damien Lespiau07144422013-10-15 18:55:40 +01003598 return 0;
3599}
3600
3601/* (6 fields, 8 chars each, space separated (5) + '\n') */
3602#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3603/* account for \'0' */
3604#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3605
3606static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3607{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003608 assert_spin_locked(&pipe_crc->lock);
3609 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3610 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003611}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003612
Damien Lespiau07144422013-10-15 18:55:40 +01003613static ssize_t
3614i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3615 loff_t *pos)
3616{
3617 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003618 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003619 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3620 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003621 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003622 ssize_t bytes_read;
3623
3624 /*
3625 * Don't allow user space to provide buffers not big enough to hold
3626 * a line of data.
3627 */
3628 if (count < PIPE_CRC_LINE_LEN)
3629 return -EINVAL;
3630
3631 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3632 return 0;
3633
3634 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003635 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003636 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003637 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003638
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003639 if (filep->f_flags & O_NONBLOCK) {
3640 spin_unlock_irq(&pipe_crc->lock);
3641 return -EAGAIN;
3642 }
3643
3644 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3645 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3646 if (ret) {
3647 spin_unlock_irq(&pipe_crc->lock);
3648 return ret;
3649 }
Damien Lespiau07144422013-10-15 18:55:40 +01003650 }
3651
3652 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003653 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003654
Damien Lespiau07144422013-10-15 18:55:40 +01003655 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003656 while (n_entries > 0) {
3657 struct intel_pipe_crc_entry *entry =
3658 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003659
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003660 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3661 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3662 break;
3663
3664 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3665 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3666
Damien Lespiau07144422013-10-15 18:55:40 +01003667 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3668 "%8u %8x %8x %8x %8x %8x\n",
3669 entry->frame, entry->crc[0],
3670 entry->crc[1], entry->crc[2],
3671 entry->crc[3], entry->crc[4]);
3672
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003673 spin_unlock_irq(&pipe_crc->lock);
3674
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003675 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003676 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003677
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003678 user_buf += PIPE_CRC_LINE_LEN;
3679 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003680
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003681 spin_lock_irq(&pipe_crc->lock);
3682 }
3683
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003684 spin_unlock_irq(&pipe_crc->lock);
3685
Damien Lespiau07144422013-10-15 18:55:40 +01003686 return bytes_read;
3687}
3688
3689static const struct file_operations i915_pipe_crc_fops = {
3690 .owner = THIS_MODULE,
3691 .open = i915_pipe_crc_open,
3692 .read = i915_pipe_crc_read,
3693 .release = i915_pipe_crc_release,
3694};
3695
3696static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3697 {
3698 .name = "i915_pipe_A_crc",
3699 .pipe = PIPE_A,
3700 },
3701 {
3702 .name = "i915_pipe_B_crc",
3703 .pipe = PIPE_B,
3704 },
3705 {
3706 .name = "i915_pipe_C_crc",
3707 .pipe = PIPE_C,
3708 },
3709};
3710
3711static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3712 enum pipe pipe)
3713{
David Weinehall36cdd012016-08-22 13:59:31 +03003714 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003715 struct dentry *ent;
3716 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3717
David Weinehall36cdd012016-08-22 13:59:31 +03003718 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003719 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3720 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003721 if (!ent)
3722 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003723
3724 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003725}
3726
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003727static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003728 "none",
3729 "plane1",
3730 "plane2",
3731 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003732 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003733 "TV",
3734 "DP-B",
3735 "DP-C",
3736 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003737 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003738};
3739
3740static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3741{
3742 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3743 return pipe_crc_sources[source];
3744}
3745
Damien Lespiaubd9db022013-10-15 18:55:36 +01003746static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003747{
David Weinehall36cdd012016-08-22 13:59:31 +03003748 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003749 int i;
3750
3751 for (i = 0; i < I915_MAX_PIPES; i++)
3752 seq_printf(m, "%c %s\n", pipe_name(i),
3753 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3754
3755 return 0;
3756}
3757
Damien Lespiaubd9db022013-10-15 18:55:36 +01003758static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003759{
David Weinehall36cdd012016-08-22 13:59:31 +03003760 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003761}
3762
Daniel Vetter46a19182013-11-01 10:50:20 +01003763static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003764 uint32_t *val)
3765{
Daniel Vetter46a19182013-11-01 10:50:20 +01003766 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3767 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3768
3769 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003770 case INTEL_PIPE_CRC_SOURCE_PIPE:
3771 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3772 break;
3773 case INTEL_PIPE_CRC_SOURCE_NONE:
3774 *val = 0;
3775 break;
3776 default:
3777 return -EINVAL;
3778 }
3779
3780 return 0;
3781}
3782
David Weinehall36cdd012016-08-22 13:59:31 +03003783static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3784 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003785 enum intel_pipe_crc_source *source)
3786{
David Weinehall36cdd012016-08-22 13:59:31 +03003787 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003788 struct intel_encoder *encoder;
3789 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003790 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003791 int ret = 0;
3792
3793 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3794
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003795 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003796 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003797 if (!encoder->base.crtc)
3798 continue;
3799
3800 crtc = to_intel_crtc(encoder->base.crtc);
3801
3802 if (crtc->pipe != pipe)
3803 continue;
3804
3805 switch (encoder->type) {
3806 case INTEL_OUTPUT_TVOUT:
3807 *source = INTEL_PIPE_CRC_SOURCE_TV;
3808 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003809 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003810 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003811 dig_port = enc_to_dig_port(&encoder->base);
3812 switch (dig_port->port) {
3813 case PORT_B:
3814 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3815 break;
3816 case PORT_C:
3817 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3818 break;
3819 case PORT_D:
3820 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3821 break;
3822 default:
3823 WARN(1, "nonexisting DP port %c\n",
3824 port_name(dig_port->port));
3825 break;
3826 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003827 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003828 default:
3829 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003830 }
3831 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003832 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003833
3834 return ret;
3835}
3836
David Weinehall36cdd012016-08-22 13:59:31 +03003837static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003838 enum pipe pipe,
3839 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003840 uint32_t *val)
3841{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003842 bool need_stable_symbols = false;
3843
Daniel Vetter46a19182013-11-01 10:50:20 +01003844 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003845 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003846 if (ret)
3847 return ret;
3848 }
3849
3850 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003851 case INTEL_PIPE_CRC_SOURCE_PIPE:
3852 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3853 break;
3854 case INTEL_PIPE_CRC_SOURCE_DP_B:
3855 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003856 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003857 break;
3858 case INTEL_PIPE_CRC_SOURCE_DP_C:
3859 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003860 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003861 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003862 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003863 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003864 return -EINVAL;
3865 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3866 need_stable_symbols = true;
3867 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003868 case INTEL_PIPE_CRC_SOURCE_NONE:
3869 *val = 0;
3870 break;
3871 default:
3872 return -EINVAL;
3873 }
3874
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003875 /*
3876 * When the pipe CRC tap point is after the transcoders we need
3877 * to tweak symbol-level features to produce a deterministic series of
3878 * symbols for a given frame. We need to reset those features only once
3879 * a frame (instead of every nth symbol):
3880 * - DC-balance: used to ensure a better clock recovery from the data
3881 * link (SDVO)
3882 * - DisplayPort scrambling: used for EMI reduction
3883 */
3884 if (need_stable_symbols) {
3885 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3886
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003887 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003888 switch (pipe) {
3889 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003890 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003891 break;
3892 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003893 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003894 break;
3895 case PIPE_C:
3896 tmp |= PIPE_C_SCRAMBLE_RESET;
3897 break;
3898 default:
3899 return -EINVAL;
3900 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003901 I915_WRITE(PORT_DFT2_G4X, tmp);
3902 }
3903
Daniel Vetter7ac01292013-10-18 16:37:06 +02003904 return 0;
3905}
3906
David Weinehall36cdd012016-08-22 13:59:31 +03003907static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003908 enum pipe pipe,
3909 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003910 uint32_t *val)
3911{
Daniel Vetter84093602013-11-01 10:50:21 +01003912 bool need_stable_symbols = false;
3913
Daniel Vetter46a19182013-11-01 10:50:20 +01003914 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003915 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003916 if (ret)
3917 return ret;
3918 }
3919
3920 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003921 case INTEL_PIPE_CRC_SOURCE_PIPE:
3922 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3923 break;
3924 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003925 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003926 return -EINVAL;
3927 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3928 break;
3929 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003930 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003931 return -EINVAL;
3932 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003933 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003934 break;
3935 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003936 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003937 return -EINVAL;
3938 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003939 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003940 break;
3941 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003942 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003943 return -EINVAL;
3944 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003945 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003946 break;
3947 case INTEL_PIPE_CRC_SOURCE_NONE:
3948 *val = 0;
3949 break;
3950 default:
3951 return -EINVAL;
3952 }
3953
Daniel Vetter84093602013-11-01 10:50:21 +01003954 /*
3955 * When the pipe CRC tap point is after the transcoders we need
3956 * to tweak symbol-level features to produce a deterministic series of
3957 * symbols for a given frame. We need to reset those features only once
3958 * a frame (instead of every nth symbol):
3959 * - DC-balance: used to ensure a better clock recovery from the data
3960 * link (SDVO)
3961 * - DisplayPort scrambling: used for EMI reduction
3962 */
3963 if (need_stable_symbols) {
3964 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3965
David Weinehall36cdd012016-08-22 13:59:31 +03003966 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003967
3968 I915_WRITE(PORT_DFT_I9XX,
3969 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3970
3971 if (pipe == PIPE_A)
3972 tmp |= PIPE_A_SCRAMBLE_RESET;
3973 else
3974 tmp |= PIPE_B_SCRAMBLE_RESET;
3975
3976 I915_WRITE(PORT_DFT2_G4X, tmp);
3977 }
3978
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003979 return 0;
3980}
3981
David Weinehall36cdd012016-08-22 13:59:31 +03003982static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003983 enum pipe pipe)
3984{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003985 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3986
Ville Syrjäläeb736672014-12-09 21:28:28 +02003987 switch (pipe) {
3988 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003989 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003990 break;
3991 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003992 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003993 break;
3994 case PIPE_C:
3995 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3996 break;
3997 default:
3998 return;
3999 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004000 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
4001 tmp &= ~DC_BALANCE_RESET_VLV;
4002 I915_WRITE(PORT_DFT2_G4X, tmp);
4003
4004}
4005
David Weinehall36cdd012016-08-22 13:59:31 +03004006static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01004007 enum pipe pipe)
4008{
Daniel Vetter84093602013-11-01 10:50:21 +01004009 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4010
4011 if (pipe == PIPE_A)
4012 tmp &= ~PIPE_A_SCRAMBLE_RESET;
4013 else
4014 tmp &= ~PIPE_B_SCRAMBLE_RESET;
4015 I915_WRITE(PORT_DFT2_G4X, tmp);
4016
4017 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
4018 I915_WRITE(PORT_DFT_I9XX,
4019 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
4020 }
4021}
4022
Daniel Vetter46a19182013-11-01 10:50:20 +01004023static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004024 uint32_t *val)
4025{
Daniel Vetter46a19182013-11-01 10:50:20 +01004026 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4027 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4028
4029 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004030 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4031 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4032 break;
4033 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4034 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4035 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004036 case INTEL_PIPE_CRC_SOURCE_PIPE:
4037 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4038 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004039 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004040 *val = 0;
4041 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004042 default:
4043 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004044 }
4045
4046 return 0;
4047}
4048
David Weinehall36cdd012016-08-22 13:59:31 +03004049static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4050 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004051{
David Weinehall36cdd012016-08-22 13:59:31 +03004052 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä98187832016-10-31 22:37:10 +02004053 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004054 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004055 struct drm_atomic_state *state;
4056 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004057
4058 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004059 state = drm_atomic_state_alloc(dev);
4060 if (!state) {
4061 ret = -ENOMEM;
4062 goto out;
4063 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004064
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004065 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4066 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4067 if (IS_ERR(pipe_config)) {
4068 ret = PTR_ERR(pipe_config);
4069 goto out;
4070 }
4071
4072 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004073 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004074 pipe_config->pch_pfit.enabled != enable)
4075 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004076
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004077 ret = drm_atomic_commit(state);
4078out:
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004079 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
Chris Wilson08536952016-10-14 13:18:18 +01004080 drm_modeset_unlock_all(dev);
4081 drm_atomic_state_put(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004082}
4083
David Weinehall36cdd012016-08-22 13:59:31 +03004084static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004085 enum pipe pipe,
4086 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004087 uint32_t *val)
4088{
Daniel Vetter46a19182013-11-01 10:50:20 +01004089 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4090 *source = INTEL_PIPE_CRC_SOURCE_PF;
4091
4092 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004093 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4094 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4095 break;
4096 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4097 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4098 break;
4099 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004100 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4101 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004102
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004103 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4104 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004105 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004106 *val = 0;
4107 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004108 default:
4109 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004110 }
4111
4112 return 0;
4113}
4114
David Weinehall36cdd012016-08-22 13:59:31 +03004115static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4116 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004117 enum intel_pipe_crc_source source)
4118{
Damien Lespiaucc3da172013-10-15 18:55:31 +01004119 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02004120 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Imre Deake1296492016-02-12 18:55:17 +02004121 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004122 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004123 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004124
Damien Lespiaucc3da172013-10-15 18:55:31 +01004125 if (pipe_crc->source == source)
4126 return 0;
4127
Damien Lespiauae676fc2013-10-15 18:55:32 +01004128 /* forbid changing the source without going back to 'none' */
4129 if (pipe_crc->source && source)
4130 return -EINVAL;
4131
Imre Deake1296492016-02-12 18:55:17 +02004132 power_domain = POWER_DOMAIN_PIPE(pipe);
4133 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004134 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4135 return -EIO;
4136 }
4137
David Weinehall36cdd012016-08-22 13:59:31 +03004138 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004139 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004140 else if (INTEL_GEN(dev_priv) < 5)
4141 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4142 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4143 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4144 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004145 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004146 else
David Weinehall36cdd012016-08-22 13:59:31 +03004147 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004148
4149 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004150 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004151
Damien Lespiau4b584362013-10-15 18:55:33 +01004152 /* none -> real source transition */
4153 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004154 struct intel_pipe_crc_entry *entries;
4155
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004156 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4157 pipe_name(pipe), pipe_crc_source_name(source));
4158
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004159 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4160 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004161 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004162 if (!entries) {
4163 ret = -ENOMEM;
4164 goto out;
4165 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004166
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004167 /*
4168 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4169 * enabled and disabled dynamically based on package C states,
4170 * user space can't make reliable use of the CRCs, so let's just
4171 * completely disable it.
4172 */
4173 hsw_disable_ips(crtc);
4174
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004175 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004176 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004177 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004178 pipe_crc->head = 0;
4179 pipe_crc->tail = 0;
4180 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004181 }
4182
Damien Lespiaucc3da172013-10-15 18:55:31 +01004183 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004184
Daniel Vetter926321d2013-10-16 13:30:34 +02004185 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4186 POSTING_READ(PIPE_CRC_CTL(pipe));
4187
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004188 /* real source -> none transition */
4189 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004190 struct intel_pipe_crc_entry *entries;
Ville Syrjälä98187832016-10-31 22:37:10 +02004191 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
4192 pipe);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004193
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004194 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4195 pipe_name(pipe));
4196
Daniel Vettera33d7102014-06-06 08:22:08 +02004197 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004198 if (crtc->base.state->active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004199 intel_wait_for_vblank(dev_priv, pipe);
Daniel Vettera33d7102014-06-06 08:22:08 +02004200 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004201
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004202 spin_lock_irq(&pipe_crc->lock);
4203 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004204 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004205 pipe_crc->head = 0;
4206 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004207 spin_unlock_irq(&pipe_crc->lock);
4208
4209 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004210
David Weinehall36cdd012016-08-22 13:59:31 +03004211 if (IS_G4X(dev_priv))
4212 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4213 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4214 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4215 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4216 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004217
4218 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004219 }
4220
Imre Deake1296492016-02-12 18:55:17 +02004221 ret = 0;
4222
4223out:
4224 intel_display_power_put(dev_priv, power_domain);
4225
4226 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004227}
4228
4229/*
4230 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004231 * command: wsp* object wsp+ name wsp+ source wsp*
4232 * object: 'pipe'
4233 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004234 * source: (none | plane1 | plane2 | pf)
4235 * wsp: (#0x20 | #0x9 | #0xA)+
4236 *
4237 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004238 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4239 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004240 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004241static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004242{
4243 int n_words = 0;
4244
4245 while (*buf) {
4246 char *end;
4247
4248 /* skip leading white space */
4249 buf = skip_spaces(buf);
4250 if (!*buf)
4251 break; /* end of buffer */
4252
4253 /* find end of word */
4254 for (end = buf; *end && !isspace(*end); end++)
4255 ;
4256
4257 if (n_words == max_words) {
4258 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4259 max_words);
4260 return -EINVAL; /* ran out of words[] before bytes */
4261 }
4262
4263 if (*end)
4264 *end++ = '\0';
4265 words[n_words++] = buf;
4266 buf = end;
4267 }
4268
4269 return n_words;
4270}
4271
Damien Lespiaub94dec82013-10-15 18:55:35 +01004272enum intel_pipe_crc_object {
4273 PIPE_CRC_OBJECT_PIPE,
4274};
4275
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004276static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004277 "pipe",
4278};
4279
4280static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004281display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004282{
4283 int i;
4284
4285 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4286 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004287 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004288 return 0;
4289 }
4290
4291 return -EINVAL;
4292}
4293
Damien Lespiaubd9db022013-10-15 18:55:36 +01004294static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004295{
4296 const char name = buf[0];
4297
4298 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4299 return -EINVAL;
4300
4301 *pipe = name - 'A';
4302
4303 return 0;
4304}
4305
4306static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004307display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004308{
4309 int i;
4310
4311 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4312 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004313 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004314 return 0;
4315 }
4316
4317 return -EINVAL;
4318}
4319
David Weinehall36cdd012016-08-22 13:59:31 +03004320static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4321 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004322{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004323#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004324 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004325 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004326 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004327 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004328 enum intel_pipe_crc_source source;
4329
Damien Lespiaubd9db022013-10-15 18:55:36 +01004330 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004331 if (n_words != N_WORDS) {
4332 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4333 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004334 return -EINVAL;
4335 }
4336
Damien Lespiaubd9db022013-10-15 18:55:36 +01004337 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004338 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004339 return -EINVAL;
4340 }
4341
Damien Lespiaubd9db022013-10-15 18:55:36 +01004342 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004343 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4344 return -EINVAL;
4345 }
4346
Damien Lespiaubd9db022013-10-15 18:55:36 +01004347 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004348 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004349 return -EINVAL;
4350 }
4351
David Weinehall36cdd012016-08-22 13:59:31 +03004352 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004353}
4354
Damien Lespiaubd9db022013-10-15 18:55:36 +01004355static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4356 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004357{
4358 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004359 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004360 char *tmpbuf;
4361 int ret;
4362
4363 if (len == 0)
4364 return 0;
4365
4366 if (len > PAGE_SIZE - 1) {
4367 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4368 PAGE_SIZE);
4369 return -E2BIG;
4370 }
4371
4372 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4373 if (!tmpbuf)
4374 return -ENOMEM;
4375
4376 if (copy_from_user(tmpbuf, ubuf, len)) {
4377 ret = -EFAULT;
4378 goto out;
4379 }
4380 tmpbuf[len] = '\0';
4381
David Weinehall36cdd012016-08-22 13:59:31 +03004382 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004383
4384out:
4385 kfree(tmpbuf);
4386 if (ret < 0)
4387 return ret;
4388
4389 *offp += len;
4390 return len;
4391}
4392
Damien Lespiaubd9db022013-10-15 18:55:36 +01004393static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004394 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004395 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004396 .read = seq_read,
4397 .llseek = seq_lseek,
4398 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004399 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004400};
4401
Todd Previteeb3394fa2015-04-18 00:04:19 -07004402static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004403 const char __user *ubuf,
4404 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004405{
4406 char *input_buffer;
4407 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004408 struct drm_device *dev;
4409 struct drm_connector *connector;
4410 struct list_head *connector_list;
4411 struct intel_dp *intel_dp;
4412 int val = 0;
4413
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304414 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004415
Todd Previteeb3394fa2015-04-18 00:04:19 -07004416 connector_list = &dev->mode_config.connector_list;
4417
4418 if (len == 0)
4419 return 0;
4420
4421 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4422 if (!input_buffer)
4423 return -ENOMEM;
4424
4425 if (copy_from_user(input_buffer, ubuf, len)) {
4426 status = -EFAULT;
4427 goto out;
4428 }
4429
4430 input_buffer[len] = '\0';
4431 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4432
4433 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004434 if (connector->connector_type !=
4435 DRM_MODE_CONNECTOR_DisplayPort)
4436 continue;
4437
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304438 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004439 connector->encoder != NULL) {
4440 intel_dp = enc_to_intel_dp(connector->encoder);
4441 status = kstrtoint(input_buffer, 10, &val);
4442 if (status < 0)
4443 goto out;
4444 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4445 /* To prevent erroneous activation of the compliance
4446 * testing code, only accept an actual value of 1 here
4447 */
4448 if (val == 1)
4449 intel_dp->compliance_test_active = 1;
4450 else
4451 intel_dp->compliance_test_active = 0;
4452 }
4453 }
4454out:
4455 kfree(input_buffer);
4456 if (status < 0)
4457 return status;
4458
4459 *offp += len;
4460 return len;
4461}
4462
4463static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4464{
4465 struct drm_device *dev = m->private;
4466 struct drm_connector *connector;
4467 struct list_head *connector_list = &dev->mode_config.connector_list;
4468 struct intel_dp *intel_dp;
4469
Todd Previteeb3394fa2015-04-18 00:04:19 -07004470 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004471 if (connector->connector_type !=
4472 DRM_MODE_CONNECTOR_DisplayPort)
4473 continue;
4474
4475 if (connector->status == connector_status_connected &&
4476 connector->encoder != NULL) {
4477 intel_dp = enc_to_intel_dp(connector->encoder);
4478 if (intel_dp->compliance_test_active)
4479 seq_puts(m, "1");
4480 else
4481 seq_puts(m, "0");
4482 } else
4483 seq_puts(m, "0");
4484 }
4485
4486 return 0;
4487}
4488
4489static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004490 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004491{
David Weinehall36cdd012016-08-22 13:59:31 +03004492 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004493
David Weinehall36cdd012016-08-22 13:59:31 +03004494 return single_open(file, i915_displayport_test_active_show,
4495 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004496}
4497
4498static const struct file_operations i915_displayport_test_active_fops = {
4499 .owner = THIS_MODULE,
4500 .open = i915_displayport_test_active_open,
4501 .read = seq_read,
4502 .llseek = seq_lseek,
4503 .release = single_release,
4504 .write = i915_displayport_test_active_write
4505};
4506
4507static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4508{
4509 struct drm_device *dev = m->private;
4510 struct drm_connector *connector;
4511 struct list_head *connector_list = &dev->mode_config.connector_list;
4512 struct intel_dp *intel_dp;
4513
Todd Previteeb3394fa2015-04-18 00:04:19 -07004514 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004515 if (connector->connector_type !=
4516 DRM_MODE_CONNECTOR_DisplayPort)
4517 continue;
4518
4519 if (connector->status == connector_status_connected &&
4520 connector->encoder != NULL) {
4521 intel_dp = enc_to_intel_dp(connector->encoder);
4522 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4523 } else
4524 seq_puts(m, "0");
4525 }
4526
4527 return 0;
4528}
4529static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004530 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004531{
David Weinehall36cdd012016-08-22 13:59:31 +03004532 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004533
David Weinehall36cdd012016-08-22 13:59:31 +03004534 return single_open(file, i915_displayport_test_data_show,
4535 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004536}
4537
4538static const struct file_operations i915_displayport_test_data_fops = {
4539 .owner = THIS_MODULE,
4540 .open = i915_displayport_test_data_open,
4541 .read = seq_read,
4542 .llseek = seq_lseek,
4543 .release = single_release
4544};
4545
4546static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4547{
4548 struct drm_device *dev = m->private;
4549 struct drm_connector *connector;
4550 struct list_head *connector_list = &dev->mode_config.connector_list;
4551 struct intel_dp *intel_dp;
4552
Todd Previteeb3394fa2015-04-18 00:04:19 -07004553 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004554 if (connector->connector_type !=
4555 DRM_MODE_CONNECTOR_DisplayPort)
4556 continue;
4557
4558 if (connector->status == connector_status_connected &&
4559 connector->encoder != NULL) {
4560 intel_dp = enc_to_intel_dp(connector->encoder);
4561 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4562 } else
4563 seq_puts(m, "0");
4564 }
4565
4566 return 0;
4567}
4568
4569static int i915_displayport_test_type_open(struct inode *inode,
4570 struct file *file)
4571{
David Weinehall36cdd012016-08-22 13:59:31 +03004572 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004573
David Weinehall36cdd012016-08-22 13:59:31 +03004574 return single_open(file, i915_displayport_test_type_show,
4575 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004576}
4577
4578static const struct file_operations i915_displayport_test_type_fops = {
4579 .owner = THIS_MODULE,
4580 .open = i915_displayport_test_type_open,
4581 .read = seq_read,
4582 .llseek = seq_lseek,
4583 .release = single_release
4584};
4585
Damien Lespiau97e94b22014-11-04 17:06:50 +00004586static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004587{
David Weinehall36cdd012016-08-22 13:59:31 +03004588 struct drm_i915_private *dev_priv = m->private;
4589 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004590 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004591 int num_levels;
4592
David Weinehall36cdd012016-08-22 13:59:31 +03004593 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004594 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004595 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004596 num_levels = 1;
4597 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004598 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004599
4600 drm_modeset_lock_all(dev);
4601
4602 for (level = 0; level < num_levels; level++) {
4603 unsigned int latency = wm[level];
4604
Damien Lespiau97e94b22014-11-04 17:06:50 +00004605 /*
4606 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004607 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004608 */
David Weinehall36cdd012016-08-22 13:59:31 +03004609 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4610 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004611 latency *= 10;
4612 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004613 latency *= 5;
4614
4615 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004616 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004617 }
4618
4619 drm_modeset_unlock_all(dev);
4620}
4621
4622static int pri_wm_latency_show(struct seq_file *m, void *data)
4623{
David Weinehall36cdd012016-08-22 13:59:31 +03004624 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004625 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004626
David Weinehall36cdd012016-08-22 13:59:31 +03004627 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004628 latencies = dev_priv->wm.skl_latency;
4629 else
David Weinehall36cdd012016-08-22 13:59:31 +03004630 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004631
4632 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004633
4634 return 0;
4635}
4636
4637static int spr_wm_latency_show(struct seq_file *m, void *data)
4638{
David Weinehall36cdd012016-08-22 13:59:31 +03004639 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004640 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004641
David Weinehall36cdd012016-08-22 13:59:31 +03004642 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004643 latencies = dev_priv->wm.skl_latency;
4644 else
David Weinehall36cdd012016-08-22 13:59:31 +03004645 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004646
4647 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004648
4649 return 0;
4650}
4651
4652static int cur_wm_latency_show(struct seq_file *m, void *data)
4653{
David Weinehall36cdd012016-08-22 13:59:31 +03004654 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004655 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004656
David Weinehall36cdd012016-08-22 13:59:31 +03004657 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004658 latencies = dev_priv->wm.skl_latency;
4659 else
David Weinehall36cdd012016-08-22 13:59:31 +03004660 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004661
4662 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004663
4664 return 0;
4665}
4666
4667static int pri_wm_latency_open(struct inode *inode, struct file *file)
4668{
David Weinehall36cdd012016-08-22 13:59:31 +03004669 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004670
David Weinehall36cdd012016-08-22 13:59:31 +03004671 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004672 return -ENODEV;
4673
David Weinehall36cdd012016-08-22 13:59:31 +03004674 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004675}
4676
4677static int spr_wm_latency_open(struct inode *inode, struct file *file)
4678{
David Weinehall36cdd012016-08-22 13:59:31 +03004679 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004680
David Weinehall36cdd012016-08-22 13:59:31 +03004681 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004682 return -ENODEV;
4683
David Weinehall36cdd012016-08-22 13:59:31 +03004684 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004685}
4686
4687static int cur_wm_latency_open(struct inode *inode, struct file *file)
4688{
David Weinehall36cdd012016-08-22 13:59:31 +03004689 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004690
David Weinehall36cdd012016-08-22 13:59:31 +03004691 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004692 return -ENODEV;
4693
David Weinehall36cdd012016-08-22 13:59:31 +03004694 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004695}
4696
4697static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004698 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004699{
4700 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004701 struct drm_i915_private *dev_priv = m->private;
4702 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004703 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004704 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004705 int level;
4706 int ret;
4707 char tmp[32];
4708
David Weinehall36cdd012016-08-22 13:59:31 +03004709 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004710 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004711 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004712 num_levels = 1;
4713 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004714 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004715
Ville Syrjälä369a1342014-01-22 14:36:08 +02004716 if (len >= sizeof(tmp))
4717 return -EINVAL;
4718
4719 if (copy_from_user(tmp, ubuf, len))
4720 return -EFAULT;
4721
4722 tmp[len] = '\0';
4723
Damien Lespiau97e94b22014-11-04 17:06:50 +00004724 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4725 &new[0], &new[1], &new[2], &new[3],
4726 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004727 if (ret != num_levels)
4728 return -EINVAL;
4729
4730 drm_modeset_lock_all(dev);
4731
4732 for (level = 0; level < num_levels; level++)
4733 wm[level] = new[level];
4734
4735 drm_modeset_unlock_all(dev);
4736
4737 return len;
4738}
4739
4740
4741static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4742 size_t len, loff_t *offp)
4743{
4744 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004745 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004746 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004747
David Weinehall36cdd012016-08-22 13:59:31 +03004748 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004749 latencies = dev_priv->wm.skl_latency;
4750 else
David Weinehall36cdd012016-08-22 13:59:31 +03004751 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004752
4753 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004754}
4755
4756static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4757 size_t len, loff_t *offp)
4758{
4759 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004760 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004761 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004762
David Weinehall36cdd012016-08-22 13:59:31 +03004763 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004764 latencies = dev_priv->wm.skl_latency;
4765 else
David Weinehall36cdd012016-08-22 13:59:31 +03004766 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004767
4768 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004769}
4770
4771static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4772 size_t len, loff_t *offp)
4773{
4774 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004775 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004776 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004777
David Weinehall36cdd012016-08-22 13:59:31 +03004778 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004779 latencies = dev_priv->wm.skl_latency;
4780 else
David Weinehall36cdd012016-08-22 13:59:31 +03004781 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004782
4783 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004784}
4785
4786static const struct file_operations i915_pri_wm_latency_fops = {
4787 .owner = THIS_MODULE,
4788 .open = pri_wm_latency_open,
4789 .read = seq_read,
4790 .llseek = seq_lseek,
4791 .release = single_release,
4792 .write = pri_wm_latency_write
4793};
4794
4795static const struct file_operations i915_spr_wm_latency_fops = {
4796 .owner = THIS_MODULE,
4797 .open = spr_wm_latency_open,
4798 .read = seq_read,
4799 .llseek = seq_lseek,
4800 .release = single_release,
4801 .write = spr_wm_latency_write
4802};
4803
4804static const struct file_operations i915_cur_wm_latency_fops = {
4805 .owner = THIS_MODULE,
4806 .open = cur_wm_latency_open,
4807 .read = seq_read,
4808 .llseek = seq_lseek,
4809 .release = single_release,
4810 .write = cur_wm_latency_write
4811};
4812
Kees Cook647416f2013-03-10 14:10:06 -07004813static int
4814i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004815{
David Weinehall36cdd012016-08-22 13:59:31 +03004816 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004817
Chris Wilsond98c52c2016-04-13 17:35:05 +01004818 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004819
Kees Cook647416f2013-03-10 14:10:06 -07004820 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004821}
4822
Kees Cook647416f2013-03-10 14:10:06 -07004823static int
4824i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004825{
David Weinehall36cdd012016-08-22 13:59:31 +03004826 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004827
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004828 /*
4829 * There is no safeguard against this debugfs entry colliding
4830 * with the hangcheck calling same i915_handle_error() in
4831 * parallel, causing an explosion. For now we assume that the
4832 * test harness is responsible enough not to inject gpu hangs
4833 * while it is writing to 'i915_wedged'
4834 */
4835
Chris Wilsond98c52c2016-04-13 17:35:05 +01004836 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004837 return -EAGAIN;
4838
Chris Wilsonc0336662016-05-06 15:40:21 +01004839 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004840 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004841
Kees Cook647416f2013-03-10 14:10:06 -07004842 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004843}
4844
Kees Cook647416f2013-03-10 14:10:06 -07004845DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4846 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004847 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004848
Kees Cook647416f2013-03-10 14:10:06 -07004849static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004850i915_ring_missed_irq_get(void *data, u64 *val)
4851{
David Weinehall36cdd012016-08-22 13:59:31 +03004852 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004853
4854 *val = dev_priv->gpu_error.missed_irq_rings;
4855 return 0;
4856}
4857
4858static int
4859i915_ring_missed_irq_set(void *data, u64 val)
4860{
David Weinehall36cdd012016-08-22 13:59:31 +03004861 struct drm_i915_private *dev_priv = data;
4862 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004863 int ret;
4864
4865 /* Lock against concurrent debugfs callers */
4866 ret = mutex_lock_interruptible(&dev->struct_mutex);
4867 if (ret)
4868 return ret;
4869 dev_priv->gpu_error.missed_irq_rings = val;
4870 mutex_unlock(&dev->struct_mutex);
4871
4872 return 0;
4873}
4874
4875DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4876 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4877 "0x%08llx\n");
4878
4879static int
4880i915_ring_test_irq_get(void *data, u64 *val)
4881{
David Weinehall36cdd012016-08-22 13:59:31 +03004882 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004883
4884 *val = dev_priv->gpu_error.test_irq_rings;
4885
4886 return 0;
4887}
4888
4889static int
4890i915_ring_test_irq_set(void *data, u64 val)
4891{
David Weinehall36cdd012016-08-22 13:59:31 +03004892 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004893
Chris Wilson3a122c22016-06-17 14:35:05 +01004894 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004895 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004896 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004897
4898 return 0;
4899}
4900
4901DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4902 i915_ring_test_irq_get, i915_ring_test_irq_set,
4903 "0x%08llx\n");
4904
Chris Wilsondd624af2013-01-15 12:39:35 +00004905#define DROP_UNBOUND 0x1
4906#define DROP_BOUND 0x2
4907#define DROP_RETIRE 0x4
4908#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004909#define DROP_FREED 0x10
4910#define DROP_ALL (DROP_UNBOUND | \
4911 DROP_BOUND | \
4912 DROP_RETIRE | \
4913 DROP_ACTIVE | \
4914 DROP_FREED)
Kees Cook647416f2013-03-10 14:10:06 -07004915static int
4916i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004917{
Kees Cook647416f2013-03-10 14:10:06 -07004918 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004919
Kees Cook647416f2013-03-10 14:10:06 -07004920 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004921}
4922
Kees Cook647416f2013-03-10 14:10:06 -07004923static int
4924i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004925{
David Weinehall36cdd012016-08-22 13:59:31 +03004926 struct drm_i915_private *dev_priv = data;
4927 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004928 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004929
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004930 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004931
4932 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4933 * on ioctls on -EAGAIN. */
4934 ret = mutex_lock_interruptible(&dev->struct_mutex);
4935 if (ret)
4936 return ret;
4937
4938 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004939 ret = i915_gem_wait_for_idle(dev_priv,
4940 I915_WAIT_INTERRUPTIBLE |
4941 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004942 if (ret)
4943 goto unlock;
4944 }
4945
4946 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004947 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004948
Chris Wilson21ab4e72014-09-09 11:16:08 +01004949 if (val & DROP_BOUND)
4950 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004951
Chris Wilson21ab4e72014-09-09 11:16:08 +01004952 if (val & DROP_UNBOUND)
4953 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004954
4955unlock:
4956 mutex_unlock(&dev->struct_mutex);
4957
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004958 if (val & DROP_FREED) {
4959 synchronize_rcu();
4960 flush_work(&dev_priv->mm.free_work);
4961 }
4962
Kees Cook647416f2013-03-10 14:10:06 -07004963 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004964}
4965
Kees Cook647416f2013-03-10 14:10:06 -07004966DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4967 i915_drop_caches_get, i915_drop_caches_set,
4968 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004969
Kees Cook647416f2013-03-10 14:10:06 -07004970static int
4971i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004972{
David Weinehall36cdd012016-08-22 13:59:31 +03004973 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004974
David Weinehall36cdd012016-08-22 13:59:31 +03004975 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004976 return -ENODEV;
4977
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004978 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004979 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004980}
4981
Kees Cook647416f2013-03-10 14:10:06 -07004982static int
4983i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004984{
David Weinehall36cdd012016-08-22 13:59:31 +03004985 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304986 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004987 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004988
David Weinehall36cdd012016-08-22 13:59:31 +03004989 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004990 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004991
Kees Cook647416f2013-03-10 14:10:06 -07004992 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004993
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004994 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004995 if (ret)
4996 return ret;
4997
Jesse Barnes358733e2011-07-27 11:53:01 -07004998 /*
4999 * Turbo will still be enabled, but won't go above the set value.
5000 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305001 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005002
Akash Goelbc4d91f2015-02-26 16:09:47 +05305003 hw_max = dev_priv->rps.max_freq;
5004 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005005
Ben Widawskyb39fb292014-03-19 18:31:11 -07005006 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005007 mutex_unlock(&dev_priv->rps.hw_lock);
5008 return -EINVAL;
5009 }
5010
Ben Widawskyb39fb292014-03-19 18:31:11 -07005011 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005012
Chris Wilsondc979972016-05-10 14:10:04 +01005013 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005014
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005015 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005016
Kees Cook647416f2013-03-10 14:10:06 -07005017 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005018}
5019
Kees Cook647416f2013-03-10 14:10:06 -07005020DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5021 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005022 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005023
Kees Cook647416f2013-03-10 14:10:06 -07005024static int
5025i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005026{
David Weinehall36cdd012016-08-22 13:59:31 +03005027 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005028
Chris Wilson62e1baa2016-07-13 09:10:36 +01005029 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005030 return -ENODEV;
5031
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005032 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005033 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005034}
5035
Kees Cook647416f2013-03-10 14:10:06 -07005036static int
5037i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005038{
David Weinehall36cdd012016-08-22 13:59:31 +03005039 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305040 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005041 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005042
Chris Wilson62e1baa2016-07-13 09:10:36 +01005043 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005044 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005045
Kees Cook647416f2013-03-10 14:10:06 -07005046 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005047
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005048 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005049 if (ret)
5050 return ret;
5051
Jesse Barnes1523c312012-05-25 12:34:54 -07005052 /*
5053 * Turbo will still be enabled, but won't go below the set value.
5054 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305055 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005056
Akash Goelbc4d91f2015-02-26 16:09:47 +05305057 hw_max = dev_priv->rps.max_freq;
5058 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005059
David Weinehall36cdd012016-08-22 13:59:31 +03005060 if (val < hw_min ||
5061 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005062 mutex_unlock(&dev_priv->rps.hw_lock);
5063 return -EINVAL;
5064 }
5065
Ben Widawskyb39fb292014-03-19 18:31:11 -07005066 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005067
Chris Wilsondc979972016-05-10 14:10:04 +01005068 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005069
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005070 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005071
Kees Cook647416f2013-03-10 14:10:06 -07005072 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005073}
5074
Kees Cook647416f2013-03-10 14:10:06 -07005075DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5076 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005077 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005078
Kees Cook647416f2013-03-10 14:10:06 -07005079static int
5080i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005081{
David Weinehall36cdd012016-08-22 13:59:31 +03005082 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005083 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005084
David Weinehall36cdd012016-08-22 13:59:31 +03005085 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005086 return -ENODEV;
5087
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005088 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005089
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005090 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005091
5092 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005093
Kees Cook647416f2013-03-10 14:10:06 -07005094 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005095
Kees Cook647416f2013-03-10 14:10:06 -07005096 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005097}
5098
Kees Cook647416f2013-03-10 14:10:06 -07005099static int
5100i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005101{
David Weinehall36cdd012016-08-22 13:59:31 +03005102 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005103 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005104
David Weinehall36cdd012016-08-22 13:59:31 +03005105 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005106 return -ENODEV;
5107
Kees Cook647416f2013-03-10 14:10:06 -07005108 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005109 return -EINVAL;
5110
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005111 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005112 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005113
5114 /* Update the cache sharing policy here as well */
5115 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5116 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5117 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5118 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5119
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005120 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005121 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005122}
5123
Kees Cook647416f2013-03-10 14:10:06 -07005124DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5125 i915_cache_sharing_get, i915_cache_sharing_set,
5126 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005127
David Weinehall36cdd012016-08-22 13:59:31 +03005128static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005129 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005130{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005131 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005132 int ss;
5133 u32 sig1[ss_max], sig2[ss_max];
5134
5135 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5136 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5137 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5138 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5139
5140 for (ss = 0; ss < ss_max; ss++) {
5141 unsigned int eu_cnt;
5142
5143 if (sig1[ss] & CHV_SS_PG_ENABLE)
5144 /* skip disabled subslice */
5145 continue;
5146
Imre Deakf08a0c92016-08-31 19:13:04 +03005147 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005148 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005149 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5150 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5151 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5152 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005153 sseu->eu_total += eu_cnt;
5154 sseu->eu_per_subslice = max_t(unsigned int,
5155 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005156 }
Jeff McGee5d395252015-04-03 18:13:17 -07005157}
5158
David Weinehall36cdd012016-08-22 13:59:31 +03005159static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005160 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005161{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005162 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005163 int s, ss;
5164 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5165
Jeff McGee1c046bc2015-04-03 18:13:18 -07005166 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005167 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005168 s_max = 1;
5169 ss_max = 3;
5170 }
5171
5172 for (s = 0; s < s_max; s++) {
5173 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5174 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5175 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5176 }
5177
Jeff McGee5d395252015-04-03 18:13:17 -07005178 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5179 GEN9_PGCTL_SSA_EU19_ACK |
5180 GEN9_PGCTL_SSA_EU210_ACK |
5181 GEN9_PGCTL_SSA_EU311_ACK;
5182 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5183 GEN9_PGCTL_SSB_EU19_ACK |
5184 GEN9_PGCTL_SSB_EU210_ACK |
5185 GEN9_PGCTL_SSB_EU311_ACK;
5186
5187 for (s = 0; s < s_max; s++) {
5188 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5189 /* skip disabled slice */
5190 continue;
5191
Imre Deakf08a0c92016-08-31 19:13:04 +03005192 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005193
David Weinehall36cdd012016-08-22 13:59:31 +03005194 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005195 sseu->subslice_mask =
5196 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005197
Jeff McGee5d395252015-04-03 18:13:17 -07005198 for (ss = 0; ss < ss_max; ss++) {
5199 unsigned int eu_cnt;
5200
Imre Deak57ec1712016-08-31 19:13:05 +03005201 if (IS_BROXTON(dev_priv)) {
5202 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5203 /* skip disabled subslice */
5204 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005205
Imre Deak57ec1712016-08-31 19:13:05 +03005206 sseu->subslice_mask |= BIT(ss);
5207 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005208
Jeff McGee5d395252015-04-03 18:13:17 -07005209 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5210 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005211 sseu->eu_total += eu_cnt;
5212 sseu->eu_per_subslice = max_t(unsigned int,
5213 sseu->eu_per_subslice,
5214 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005215 }
5216 }
5217}
5218
David Weinehall36cdd012016-08-22 13:59:31 +03005219static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005220 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005221{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005222 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005223 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005224
Imre Deakf08a0c92016-08-31 19:13:04 +03005225 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005226
Imre Deakf08a0c92016-08-31 19:13:04 +03005227 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005228 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005229 sseu->eu_per_subslice =
5230 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005231 sseu->eu_total = sseu->eu_per_subslice *
5232 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005233
5234 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005235 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005236 u8 subslice_7eu =
5237 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005238
Imre Deak915490d2016-08-31 19:13:01 +03005239 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005240 }
5241 }
5242}
5243
Imre Deak615d8902016-08-31 19:13:03 +03005244static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5245 const struct sseu_dev_info *sseu)
5246{
5247 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5248 const char *type = is_available_info ? "Available" : "Enabled";
5249
Imre Deakc67ba532016-08-31 19:13:06 +03005250 seq_printf(m, " %s Slice Mask: %04x\n", type,
5251 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005252 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005253 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005254 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005255 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005256 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5257 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005258 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005259 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005260 seq_printf(m, " %s EU Total: %u\n", type,
5261 sseu->eu_total);
5262 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5263 sseu->eu_per_subslice);
5264
5265 if (!is_available_info)
5266 return;
5267
5268 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5269 if (HAS_POOLED_EU(dev_priv))
5270 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5271
5272 seq_printf(m, " Has Slice Power Gating: %s\n",
5273 yesno(sseu->has_slice_pg));
5274 seq_printf(m, " Has Subslice Power Gating: %s\n",
5275 yesno(sseu->has_subslice_pg));
5276 seq_printf(m, " Has EU Power Gating: %s\n",
5277 yesno(sseu->has_eu_pg));
5278}
5279
Jeff McGee38732182015-02-13 10:27:54 -06005280static int i915_sseu_status(struct seq_file *m, void *unused)
5281{
David Weinehall36cdd012016-08-22 13:59:31 +03005282 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005283 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005284
David Weinehall36cdd012016-08-22 13:59:31 +03005285 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005286 return -ENODEV;
5287
5288 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005289 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005290
Jeff McGee7f992ab2015-02-13 10:27:55 -06005291 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005292 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005293
5294 intel_runtime_pm_get(dev_priv);
5295
David Weinehall36cdd012016-08-22 13:59:31 +03005296 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005297 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005298 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005299 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005300 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005301 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005302 }
David Weinehall238010e2016-08-01 17:33:27 +03005303
5304 intel_runtime_pm_put(dev_priv);
5305
Imre Deak615d8902016-08-31 19:13:03 +03005306 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005307
Jeff McGee38732182015-02-13 10:27:54 -06005308 return 0;
5309}
5310
Ben Widawsky6d794d42011-04-25 11:25:56 -07005311static int i915_forcewake_open(struct inode *inode, struct file *file)
5312{
David Weinehall36cdd012016-08-22 13:59:31 +03005313 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005314
David Weinehall36cdd012016-08-22 13:59:31 +03005315 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005316 return 0;
5317
Chris Wilson6daccb02015-01-16 11:34:35 +02005318 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005319 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005320
5321 return 0;
5322}
5323
Ben Widawskyc43b5632012-04-16 14:07:40 -07005324static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005325{
David Weinehall36cdd012016-08-22 13:59:31 +03005326 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005327
David Weinehall36cdd012016-08-22 13:59:31 +03005328 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005329 return 0;
5330
Mika Kuoppala59bad942015-01-16 11:34:40 +02005331 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005332 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005333
5334 return 0;
5335}
5336
5337static const struct file_operations i915_forcewake_fops = {
5338 .owner = THIS_MODULE,
5339 .open = i915_forcewake_open,
5340 .release = i915_forcewake_release,
5341};
5342
5343static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5344{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005345 struct dentry *ent;
5346
5347 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005348 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005349 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005350 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005351 if (!ent)
5352 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005353
Ben Widawsky8eb57292011-05-11 15:10:58 -07005354 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005355}
5356
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005357static int i915_debugfs_create(struct dentry *root,
5358 struct drm_minor *minor,
5359 const char *name,
5360 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005361{
Jesse Barnes358733e2011-07-27 11:53:01 -07005362 struct dentry *ent;
5363
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005364 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005365 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005366 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005367 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005368 if (!ent)
5369 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005370
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005371 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005372}
5373
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005374static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005375 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005376 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005377 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005378 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005379 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005380 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005381 {"i915_gem_request", i915_gem_request_info, 0},
5382 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005383 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005384 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08005385 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005386 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005387 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005388 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305389 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005390 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005391 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005392 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005393 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005394 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005395 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005396 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005397 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005398 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005399 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005400 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005401 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005402 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005403 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005404 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005405 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005406 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005407 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005408 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005409 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005410 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005411 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005412 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005413 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005414 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005415 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005416 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005417 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005418 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005419 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005420 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305421 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005422 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005423};
Ben Gamari27c202a2009-07-01 22:26:52 -04005424#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005425
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005426static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005427 const char *name;
5428 const struct file_operations *fops;
5429} i915_debugfs_files[] = {
5430 {"i915_wedged", &i915_wedged_fops},
5431 {"i915_max_freq", &i915_max_freq_fops},
5432 {"i915_min_freq", &i915_min_freq_fops},
5433 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005434 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5435 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005436 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005437#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005438 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005439#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005440 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005441 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005442 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5443 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5444 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005445 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005446 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5447 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05305448 {"i915_dp_test_active", &i915_displayport_test_active_fops},
5449 {"i915_guc_log_control", &i915_guc_log_control_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005450};
5451
David Weinehall36cdd012016-08-22 13:59:31 +03005452void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005453{
Daniel Vetterb3783602013-11-14 11:30:42 +01005454 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005455
Damien Lespiau055e3932014-08-18 13:49:10 +01005456 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005457 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005458
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005459 pipe_crc->opened = false;
5460 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005461 init_waitqueue_head(&pipe_crc->wq);
5462 }
5463}
5464
Chris Wilson1dac8912016-06-24 14:00:17 +01005465int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005466{
Chris Wilson91c8a322016-07-05 10:40:23 +01005467 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005468 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005469
Ben Widawsky6d794d42011-04-25 11:25:56 -07005470 ret = i915_forcewake_create(minor->debugfs_root, minor);
5471 if (ret)
5472 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005473
Damien Lespiau07144422013-10-15 18:55:40 +01005474 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5475 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5476 if (ret)
5477 return ret;
5478 }
5479
Daniel Vetter34b96742013-07-04 20:49:44 +02005480 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5481 ret = i915_debugfs_create(minor->debugfs_root, minor,
5482 i915_debugfs_files[i].name,
5483 i915_debugfs_files[i].fops);
5484 if (ret)
5485 return ret;
5486 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005487
Ben Gamari27c202a2009-07-01 22:26:52 -04005488 return drm_debugfs_create_files(i915_debugfs_list,
5489 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005490 minor->debugfs_root, minor);
5491}
5492
Chris Wilson1dac8912016-06-24 14:00:17 +01005493void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005494{
Chris Wilson91c8a322016-07-05 10:40:23 +01005495 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005496 int i;
5497
Ben Gamari27c202a2009-07-01 22:26:52 -04005498 drm_debugfs_remove_files(i915_debugfs_list,
5499 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005500
David Weinehall36cdd012016-08-22 13:59:31 +03005501 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005502 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005503
Daniel Vettere309a992013-10-16 22:55:51 +02005504 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005505 struct drm_info_list *info_list =
5506 (struct drm_info_list *)&i915_pipe_crc_data[i];
5507
5508 drm_debugfs_remove_files(info_list, 1, minor);
5509 }
5510
Daniel Vetter34b96742013-07-04 20:49:44 +02005511 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5512 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005513 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005514
5515 drm_debugfs_remove_files(info_list, 1, minor);
5516 }
Ben Gamari20172632009-02-17 20:08:50 -05005517}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005518
5519struct dpcd_block {
5520 /* DPCD dump start address. */
5521 unsigned int offset;
5522 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5523 unsigned int end;
5524 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5525 size_t size;
5526 /* Only valid for eDP. */
5527 bool edp;
5528};
5529
5530static const struct dpcd_block i915_dpcd_debug[] = {
5531 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5532 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5533 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5534 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5535 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5536 { .offset = DP_SET_POWER },
5537 { .offset = DP_EDP_DPCD_REV },
5538 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5539 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5540 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5541};
5542
5543static int i915_dpcd_show(struct seq_file *m, void *data)
5544{
5545 struct drm_connector *connector = m->private;
5546 struct intel_dp *intel_dp =
5547 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5548 uint8_t buf[16];
5549 ssize_t err;
5550 int i;
5551
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005552 if (connector->status != connector_status_connected)
5553 return -ENODEV;
5554
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005555 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5556 const struct dpcd_block *b = &i915_dpcd_debug[i];
5557 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5558
5559 if (b->edp &&
5560 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5561 continue;
5562
5563 /* low tech for now */
5564 if (WARN_ON(size > sizeof(buf)))
5565 continue;
5566
5567 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5568 if (err <= 0) {
5569 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5570 size, b->offset, err);
5571 continue;
5572 }
5573
5574 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005575 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005576
5577 return 0;
5578}
5579
5580static int i915_dpcd_open(struct inode *inode, struct file *file)
5581{
5582 return single_open(file, i915_dpcd_show, inode->i_private);
5583}
5584
5585static const struct file_operations i915_dpcd_fops = {
5586 .owner = THIS_MODULE,
5587 .open = i915_dpcd_open,
5588 .read = seq_read,
5589 .llseek = seq_lseek,
5590 .release = single_release,
5591};
5592
David Weinehallecbd6782016-08-23 12:23:56 +03005593static int i915_panel_show(struct seq_file *m, void *data)
5594{
5595 struct drm_connector *connector = m->private;
5596 struct intel_dp *intel_dp =
5597 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5598
5599 if (connector->status != connector_status_connected)
5600 return -ENODEV;
5601
5602 seq_printf(m, "Panel power up delay: %d\n",
5603 intel_dp->panel_power_up_delay);
5604 seq_printf(m, "Panel power down delay: %d\n",
5605 intel_dp->panel_power_down_delay);
5606 seq_printf(m, "Backlight on delay: %d\n",
5607 intel_dp->backlight_on_delay);
5608 seq_printf(m, "Backlight off delay: %d\n",
5609 intel_dp->backlight_off_delay);
5610
5611 return 0;
5612}
5613
5614static int i915_panel_open(struct inode *inode, struct file *file)
5615{
5616 return single_open(file, i915_panel_show, inode->i_private);
5617}
5618
5619static const struct file_operations i915_panel_fops = {
5620 .owner = THIS_MODULE,
5621 .open = i915_panel_open,
5622 .read = seq_read,
5623 .llseek = seq_lseek,
5624 .release = single_release,
5625};
5626
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005627/**
5628 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5629 * @connector: pointer to a registered drm_connector
5630 *
5631 * Cleanup will be done by drm_connector_unregister() through a call to
5632 * drm_debugfs_connector_remove().
5633 *
5634 * Returns 0 on success, negative error codes on error.
5635 */
5636int i915_debugfs_connector_add(struct drm_connector *connector)
5637{
5638 struct dentry *root = connector->debugfs_entry;
5639
5640 /* The connector must have been registered beforehands. */
5641 if (!root)
5642 return -ENODEV;
5643
5644 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5645 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005646 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5647 connector, &i915_dpcd_fops);
5648
5649 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5650 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5651 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005652
5653 return 0;
5654}