blob: d62cf2e51d1258b4d16759cc96ffcab805434327 [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
Chris Wilsonf3cd4742009-10-13 22:20:20 +010029#include <linux/debugfs.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010030#include <linux/list_sort.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010031#include "intel_drv.h"
Ben Gamari20172632009-02-17 20:08:50 -050032
David Weinehall36cdd012016-08-22 13:59:31 +030033static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
34{
35 return to_i915(node->minor->dev);
36}
37
Chris Wilson418e3cd2017-02-06 21:36:08 +000038static __always_inline void seq_print_param(struct seq_file *m,
39 const char *name,
40 const char *type,
41 const void *x)
42{
43 if (!__builtin_strcmp(type, "bool"))
44 seq_printf(m, "i915.%s=%s\n", name, yesno(*(const bool *)x));
45 else if (!__builtin_strcmp(type, "int"))
46 seq_printf(m, "i915.%s=%d\n", name, *(const int *)x);
47 else if (!__builtin_strcmp(type, "unsigned int"))
48 seq_printf(m, "i915.%s=%u\n", name, *(const unsigned int *)x);
Chris Wilson1d6aa7a2017-02-21 16:26:19 +000049 else if (!__builtin_strcmp(type, "char *"))
50 seq_printf(m, "i915.%s=%s\n", name, *(const char **)x);
Chris Wilson418e3cd2017-02-06 21:36:08 +000051 else
52 BUILD_BUG();
53}
54
Chris Wilson70d39fe2010-08-25 16:03:34 +010055static int i915_capabilities(struct seq_file *m, void *data)
56{
David Weinehall36cdd012016-08-22 13:59:31 +030057 struct drm_i915_private *dev_priv = node_to_i915(m->private);
58 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010059
David Weinehall36cdd012016-08-22 13:59:31 +030060 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
Jani Nikula2e0d26f2016-12-01 14:49:55 +020061 seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
David Weinehall36cdd012016-08-22 13:59:31 +030062 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Chris Wilson418e3cd2017-02-06 21:36:08 +000063
Damien Lespiau79fc46d2013-04-23 16:37:17 +010064#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030065 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010066#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010067
Chris Wilson418e3cd2017-02-06 21:36:08 +000068 kernel_param_lock(THIS_MODULE);
69#define PRINT_PARAM(T, x) seq_print_param(m, #x, #T, &i915.x);
70 I915_PARAMS_FOR_EACH(PRINT_PARAM);
71#undef PRINT_PARAM
72 kernel_param_unlock(THIS_MODULE);
73
Chris Wilson70d39fe2010-08-25 16:03:34 +010074 return 0;
75}
Ben Gamari433e12f2009-02-17 20:08:51 -050076
Imre Deaka7363de2016-05-12 16:18:52 +030077static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000078{
Chris Wilson573adb32016-08-04 16:32:39 +010079 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000080}
81
Imre Deaka7363de2016-05-12 16:18:52 +030082static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010083{
84 return obj->pin_display ? 'p' : ' ';
85}
86
Imre Deaka7363de2016-05-12 16:18:52 +030087static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000088{
Chris Wilson3e510a82016-08-05 10:14:23 +010089 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -040090 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010091 case I915_TILING_NONE: return ' ';
92 case I915_TILING_X: return 'X';
93 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -040094 }
Chris Wilsona6172a82009-02-11 14:26:38 +000095}
96
Imre Deaka7363de2016-05-12 16:18:52 +030097static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -070098{
Chris Wilson275f0392016-10-24 13:42:14 +010099 return !list_empty(&obj->userfault_link) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100100}
101
Imre Deaka7363de2016-05-12 16:18:52 +0300102static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100103{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100104 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700105}
106
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100107static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
108{
109 u64 size = 0;
110 struct i915_vma *vma;
111
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000112 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100113 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100114 size += vma->node.size;
115 }
116
117 return size;
118}
119
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Chris Wilsonb4716182015-04-27 13:41:17 +0100123 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000124 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700125 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100126 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800127 int pin_count = 0;
128
Chris Wilson188c1ab2016-04-03 14:14:20 +0100129 lockdep_assert_held(&obj->base.dev->struct_mutex);
130
Chris Wilsond07f0e52016-10-28 13:58:44 +0100131 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100132 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100133 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100134 get_pin_flag(obj),
135 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700136 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100137 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800138 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100139 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100140 obj->base.write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300141 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100142 obj->mm.dirty ? " dirty" : "",
143 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100144 if (obj->base.name)
145 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000146 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100147 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800148 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300149 }
150 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100151 if (obj->pin_display)
152 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000153 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100154 if (!drm_mm_node_allocated(&vma->node))
155 continue;
156
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100157 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100158 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100159 vma->node.start, vma->node.size);
Chris Wilson21976852017-01-12 11:21:08 +0000160 if (i915_vma_is_ggtt(vma)) {
161 switch (vma->ggtt_view.type) {
162 case I915_GGTT_VIEW_NORMAL:
163 seq_puts(m, ", normal");
164 break;
165
166 case I915_GGTT_VIEW_PARTIAL:
167 seq_printf(m, ", partial [%08llx+%x]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000168 vma->ggtt_view.partial.offset << PAGE_SHIFT,
169 vma->ggtt_view.partial.size << PAGE_SHIFT);
Chris Wilson21976852017-01-12 11:21:08 +0000170 break;
171
172 case I915_GGTT_VIEW_ROTATED:
173 seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000174 vma->ggtt_view.rotated.plane[0].width,
175 vma->ggtt_view.rotated.plane[0].height,
176 vma->ggtt_view.rotated.plane[0].stride,
177 vma->ggtt_view.rotated.plane[0].offset,
178 vma->ggtt_view.rotated.plane[1].width,
179 vma->ggtt_view.rotated.plane[1].height,
180 vma->ggtt_view.rotated.plane[1].stride,
181 vma->ggtt_view.rotated.plane[1].offset);
Chris Wilson21976852017-01-12 11:21:08 +0000182 break;
183
184 default:
185 MISSING_CASE(vma->ggtt_view.type);
186 break;
187 }
188 }
Chris Wilson49ef5292016-08-18 17:17:00 +0100189 if (vma->fence)
190 seq_printf(m, " , fence: %d%s",
191 vma->fence->id,
192 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000193 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700194 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000195 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100196 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100197
Chris Wilsond07f0e52016-10-28 13:58:44 +0100198 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100199 if (engine)
200 seq_printf(m, " (%s)", engine->name);
201
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100202 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
203 if (frontbuffer_bits)
204 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100205}
206
Chris Wilson6d2b88852013-08-07 18:30:54 +0100207static int obj_rank_by_stolen(void *priv,
208 struct list_head *A, struct list_head *B)
209{
210 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200211 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100212 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200213 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100214
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200215 if (a->stolen->start < b->stolen->start)
216 return -1;
217 if (a->stolen->start > b->stolen->start)
218 return 1;
219 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100220}
221
222static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
223{
David Weinehall36cdd012016-08-22 13:59:31 +0300224 struct drm_i915_private *dev_priv = node_to_i915(m->private);
225 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100226 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300227 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100228 LIST_HEAD(stolen);
229 int count, ret;
230
231 ret = mutex_lock_interruptible(&dev->struct_mutex);
232 if (ret)
233 return ret;
234
235 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200236 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100237 if (obj->stolen == NULL)
238 continue;
239
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200240 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100241
242 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100243 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100244 count++;
245 }
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200246 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100247 if (obj->stolen == NULL)
248 continue;
249
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200250 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100251
252 total_obj_size += obj->base.size;
253 count++;
254 }
255 list_sort(NULL, &stolen, obj_rank_by_stolen);
256 seq_puts(m, "Stolen:\n");
257 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200258 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100259 seq_puts(m, " ");
260 describe_obj(m, obj);
261 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200262 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263 }
264 mutex_unlock(&dev->struct_mutex);
265
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300266 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100267 count, total_obj_size, total_gtt_size);
268 return 0;
269}
270
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100271struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000272 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300273 unsigned long count;
274 u64 total, unbound;
275 u64 global, shared;
276 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100277};
278
279static int per_file_stats(int id, void *ptr, void *data)
280{
281 struct drm_i915_gem_object *obj = ptr;
282 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000283 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100284
285 stats->count++;
286 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100287 if (!obj->bind_count)
288 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000289 if (obj->base.name || obj->base.dma_buf)
290 stats->shared += obj->base.size;
291
Chris Wilson894eeec2016-08-04 07:52:20 +0100292 list_for_each_entry(vma, &obj->vma_list, obj_link) {
293 if (!drm_mm_node_allocated(&vma->node))
294 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000295
Chris Wilson3272db52016-08-04 16:32:32 +0100296 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100297 stats->global += vma->node.size;
298 } else {
299 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000300
Chris Wilson2bfa9962016-08-04 07:52:25 +0100301 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000302 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000303 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100304
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100305 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100306 stats->active += vma->node.size;
307 else
308 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100309 }
310
311 return 0;
312}
313
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100314#define print_file_stats(m, name, stats) do { \
315 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300316 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 +0100317 name, \
318 stats.count, \
319 stats.total, \
320 stats.active, \
321 stats.inactive, \
322 stats.global, \
323 stats.shared, \
324 stats.unbound); \
325} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800326
327static void print_batch_pool_stats(struct seq_file *m,
328 struct drm_i915_private *dev_priv)
329{
330 struct drm_i915_gem_object *obj;
331 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000332 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530333 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000334 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800335
336 memset(&stats, 0, sizeof(stats));
337
Akash Goel3b3f1652016-10-13 22:44:48 +0530338 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000339 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100340 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000341 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100342 batch_pool_link)
343 per_file_stats(0, obj, &stats);
344 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100345 }
Brad Volkin493018d2014-12-11 12:13:08 -0800346
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100347 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800348}
349
Chris Wilson15da9562016-05-24 14:53:43 +0100350static int per_file_ctx_stats(int id, void *ptr, void *data)
351{
352 struct i915_gem_context *ctx = ptr;
353 int n;
354
355 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
356 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100357 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100358 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100359 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100360 }
361
362 return 0;
363}
364
365static void print_context_stats(struct seq_file *m,
366 struct drm_i915_private *dev_priv)
367{
David Weinehall36cdd012016-08-22 13:59:31 +0300368 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100369 struct file_stats stats;
370 struct drm_file *file;
371
372 memset(&stats, 0, sizeof(stats));
373
David Weinehall36cdd012016-08-22 13:59:31 +0300374 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100375 if (dev_priv->kernel_context)
376 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
377
David Weinehall36cdd012016-08-22 13:59:31 +0300378 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100379 struct drm_i915_file_private *fpriv = file->driver_priv;
380 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
381 }
David Weinehall36cdd012016-08-22 13:59:31 +0300382 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100383
384 print_file_stats(m, "[k]contexts", stats);
385}
386
David Weinehall36cdd012016-08-22 13:59:31 +0300387static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100388{
David Weinehall36cdd012016-08-22 13:59:31 +0300389 struct drm_i915_private *dev_priv = node_to_i915(m->private);
390 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300391 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100392 u32 count, mapped_count, purgeable_count, dpy_count;
393 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000394 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100395 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100396 int ret;
397
398 ret = mutex_lock_interruptible(&dev->struct_mutex);
399 if (ret)
400 return ret;
401
Chris Wilson3ef7f222016-10-18 13:02:48 +0100402 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000403 dev_priv->mm.object_count,
404 dev_priv->mm.object_memory);
405
Chris Wilson1544c422016-08-15 13:18:16 +0100406 size = count = 0;
407 mapped_size = mapped_count = 0;
408 purgeable_size = purgeable_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200409 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100410 size += obj->base.size;
411 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200412
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100413 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200414 purgeable_size += obj->base.size;
415 ++purgeable_count;
416 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100417
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100418 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100419 mapped_count++;
420 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100421 }
Chris Wilson6299f992010-11-24 12:23:44 +0000422 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100423 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
424
425 size = count = dpy_size = dpy_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200426 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100427 size += obj->base.size;
428 ++count;
429
430 if (obj->pin_display) {
431 dpy_size += obj->base.size;
432 ++dpy_count;
433 }
434
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100435 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100436 purgeable_size += obj->base.size;
437 ++purgeable_count;
438 }
439
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100440 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100441 mapped_count++;
442 mapped_size += obj->base.size;
443 }
444 }
445 seq_printf(m, "%u bound objects, %llu bytes\n",
446 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300447 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200448 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100449 seq_printf(m, "%u mapped objects, %llu bytes\n",
450 mapped_count, mapped_size);
451 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
452 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000453
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300454 seq_printf(m, "%llu [%llu] gtt total\n",
Chris Wilson381b9432017-02-15 08:43:54 +0000455 ggtt->base.total, ggtt->mappable_end);
Chris Wilson73aa8082010-09-30 11:46:12 +0100456
Damien Lespiau267f0c92013-06-24 22:59:48 +0100457 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800458 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200459 mutex_unlock(&dev->struct_mutex);
460
461 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100462 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100463 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
464 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100465 struct drm_i915_file_private *file_priv = file->driver_priv;
466 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900467 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100468
469 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000470 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100471 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100472 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100473 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900474 /*
475 * Although we have a valid reference on file->pid, that does
476 * not guarantee that the task_struct who called get_pid() is
477 * still alive (e.g. get_pid(current) => fork() => exit()).
478 * Therefore, we need to protect this ->comm access using RCU.
479 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100480 mutex_lock(&dev->struct_mutex);
481 request = list_first_entry_or_null(&file_priv->mm.request_list,
482 struct drm_i915_gem_request,
Chris Wilsonc8659ef2017-03-02 12:25:25 +0000483 client_link);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900484 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100485 task = pid_task(request && request->ctx->pid ?
486 request->ctx->pid : file->pid,
487 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800488 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900489 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100490 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100491 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200492 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100493
494 return 0;
495}
496
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100497static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000498{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100499 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300500 struct drm_i915_private *dev_priv = node_to_i915(node);
501 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100502 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000503 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300504 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000505 int count, ret;
506
507 ret = mutex_lock_interruptible(&dev->struct_mutex);
508 if (ret)
509 return ret;
510
511 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200512 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6da84822016-08-15 10:48:44 +0100513 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100514 continue;
515
Damien Lespiau267f0c92013-06-24 22:59:48 +0100516 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000517 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100518 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000519 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100520 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000521 count++;
522 }
523
524 mutex_unlock(&dev->struct_mutex);
525
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300526 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000527 count, total_obj_size, total_gtt_size);
528
529 return 0;
530}
531
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100532static int i915_gem_pageflip_info(struct seq_file *m, void *data)
533{
David Weinehall36cdd012016-08-22 13:59:31 +0300534 struct drm_i915_private *dev_priv = node_to_i915(m->private);
535 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100536 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200537 int ret;
538
539 ret = mutex_lock_interruptible(&dev->struct_mutex);
540 if (ret)
541 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100543 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800544 const char pipe = pipe_name(crtc->pipe);
545 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200546 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100547
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200548 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200549 work = crtc->flip_work;
550 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800551 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100552 pipe, plane);
553 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200554 u32 pending;
555 u32 addr;
556
557 pending = atomic_read(&work->pending);
558 if (pending) {
559 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
560 pipe, plane);
561 } else {
562 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
563 pipe, plane);
564 }
565 if (work->flip_queued_req) {
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200566 struct intel_engine_cs *engine = work->flip_queued_req->engine;
Daniel Vetter5a21b662016-05-24 17:13:53 +0200567
Chris Wilson312c3c42016-11-24 14:47:50 +0000568 seq_printf(m, "Flip queued on %s at seqno %x, last submitted seqno %x [current breadcrumb %x], completed? %d\n",
Daniel Vetter5a21b662016-05-24 17:13:53 +0200569 engine->name,
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200570 work->flip_queued_req->global_seqno,
Chris Wilson312c3c42016-11-24 14:47:50 +0000571 intel_engine_last_submit(engine),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100572 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100573 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200574 } else
575 seq_printf(m, "Flip not associated with any ring\n");
576 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
577 work->flip_queued_vblank,
578 work->flip_ready_vblank,
579 intel_crtc_get_vblank_counter(crtc));
580 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
581
David Weinehall36cdd012016-08-22 13:59:31 +0300582 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200583 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
584 else
585 addr = I915_READ(DSPADDR(crtc->plane));
586 seq_printf(m, "Current scanout address 0x%08x\n", addr);
587
588 if (work->pending_flip_obj) {
589 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
590 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100591 }
592 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200593 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100594 }
595
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200596 mutex_unlock(&dev->struct_mutex);
597
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100598 return 0;
599}
600
Brad Volkin493018d2014-12-11 12:13:08 -0800601static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
602{
David Weinehall36cdd012016-08-22 13:59:31 +0300603 struct drm_i915_private *dev_priv = node_to_i915(m->private);
604 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800605 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000606 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530607 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100608 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000609 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800610
611 ret = mutex_lock_interruptible(&dev->struct_mutex);
612 if (ret)
613 return ret;
614
Akash Goel3b3f1652016-10-13 22:44:48 +0530615 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000616 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100617 int count;
618
619 count = 0;
620 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000621 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100622 batch_pool_link)
623 count++;
624 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000625 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100626
627 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000628 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100629 batch_pool_link) {
630 seq_puts(m, " ");
631 describe_obj(m, obj);
632 seq_putc(m, '\n');
633 }
634
635 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100636 }
Brad Volkin493018d2014-12-11 12:13:08 -0800637 }
638
Chris Wilson8d9d5742015-04-07 16:20:38 +0100639 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800640
641 mutex_unlock(&dev->struct_mutex);
642
643 return 0;
644}
645
Chris Wilson1b365952016-10-04 21:11:31 +0100646static void print_request(struct seq_file *m,
647 struct drm_i915_gem_request *rq,
648 const char *prefix)
649{
Chris Wilson20311bd2016-11-14 20:41:03 +0000650 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100651 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000652 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100653 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100654 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100655}
656
Ben Gamari20172632009-02-17 20:08:50 -0500657static int i915_gem_request_info(struct seq_file *m, void *data)
658{
David Weinehall36cdd012016-08-22 13:59:31 +0300659 struct drm_i915_private *dev_priv = node_to_i915(m->private);
660 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200661 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530662 struct intel_engine_cs *engine;
663 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000664 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100665
666 ret = mutex_lock_interruptible(&dev->struct_mutex);
667 if (ret)
668 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500669
Chris Wilson2d1070b2015-04-01 10:36:56 +0100670 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530671 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100672 int count;
673
674 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100675 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100676 count++;
677 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100678 continue;
679
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000680 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100681 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100682 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100683
684 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500685 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100686 mutex_unlock(&dev->struct_mutex);
687
Chris Wilson2d1070b2015-04-01 10:36:56 +0100688 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100689 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100690
Ben Gamari20172632009-02-17 20:08:50 -0500691 return 0;
692}
693
Chris Wilsonb2223492010-10-27 15:27:33 +0100694static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000695 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100696{
Chris Wilson688e6c72016-07-01 17:23:15 +0100697 struct intel_breadcrumbs *b = &engine->breadcrumbs;
698 struct rb_node *rb;
699
Chris Wilson12471ba2016-04-09 10:57:55 +0100700 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100701 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100702
Chris Wilson61d3dc72017-03-03 19:08:24 +0000703 spin_lock_irq(&b->rb_lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100704 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +0800705 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson688e6c72016-07-01 17:23:15 +0100706
707 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
708 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
709 }
Chris Wilson61d3dc72017-03-03 19:08:24 +0000710 spin_unlock_irq(&b->rb_lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100711}
712
Ben Gamari20172632009-02-17 20:08:50 -0500713static int i915_gem_seqno_info(struct seq_file *m, void *data)
714{
David Weinehall36cdd012016-08-22 13:59:31 +0300715 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000716 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530717 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500718
Akash Goel3b3f1652016-10-13 22:44:48 +0530719 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000720 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100721
Ben Gamari20172632009-02-17 20:08:50 -0500722 return 0;
723}
724
725
726static int i915_interrupt_info(struct seq_file *m, void *data)
727{
David Weinehall36cdd012016-08-22 13:59:31 +0300728 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000729 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530730 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100731 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100732
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200733 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500734
David Weinehall36cdd012016-08-22 13:59:31 +0300735 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300736 seq_printf(m, "Master Interrupt Control:\t%08x\n",
737 I915_READ(GEN8_MASTER_IRQ));
738
739 seq_printf(m, "Display IER:\t%08x\n",
740 I915_READ(VLV_IER));
741 seq_printf(m, "Display IIR:\t%08x\n",
742 I915_READ(VLV_IIR));
743 seq_printf(m, "Display IIR_RW:\t%08x\n",
744 I915_READ(VLV_IIR_RW));
745 seq_printf(m, "Display IMR:\t%08x\n",
746 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100747 for_each_pipe(dev_priv, pipe) {
748 enum intel_display_power_domain power_domain;
749
750 power_domain = POWER_DOMAIN_PIPE(pipe);
751 if (!intel_display_power_get_if_enabled(dev_priv,
752 power_domain)) {
753 seq_printf(m, "Pipe %c power disabled\n",
754 pipe_name(pipe));
755 continue;
756 }
757
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300758 seq_printf(m, "Pipe %c stat:\t%08x\n",
759 pipe_name(pipe),
760 I915_READ(PIPESTAT(pipe)));
761
Chris Wilson9c870d02016-10-24 13:42:15 +0100762 intel_display_power_put(dev_priv, power_domain);
763 }
764
765 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300766 seq_printf(m, "Port hotplug:\t%08x\n",
767 I915_READ(PORT_HOTPLUG_EN));
768 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
769 I915_READ(VLV_DPFLIPSTAT));
770 seq_printf(m, "DPINVGTT:\t%08x\n",
771 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100772 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300773
774 for (i = 0; i < 4; i++) {
775 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
776 i, I915_READ(GEN8_GT_IMR(i)));
777 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
778 i, I915_READ(GEN8_GT_IIR(i)));
779 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
780 i, I915_READ(GEN8_GT_IER(i)));
781 }
782
783 seq_printf(m, "PCU interrupt mask:\t%08x\n",
784 I915_READ(GEN8_PCU_IMR));
785 seq_printf(m, "PCU interrupt identity:\t%08x\n",
786 I915_READ(GEN8_PCU_IIR));
787 seq_printf(m, "PCU interrupt enable:\t%08x\n",
788 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300789 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700790 seq_printf(m, "Master Interrupt Control:\t%08x\n",
791 I915_READ(GEN8_MASTER_IRQ));
792
793 for (i = 0; i < 4; i++) {
794 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
795 i, I915_READ(GEN8_GT_IMR(i)));
796 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
797 i, I915_READ(GEN8_GT_IIR(i)));
798 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
799 i, I915_READ(GEN8_GT_IER(i)));
800 }
801
Damien Lespiau055e3932014-08-18 13:49:10 +0100802 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200803 enum intel_display_power_domain power_domain;
804
805 power_domain = POWER_DOMAIN_PIPE(pipe);
806 if (!intel_display_power_get_if_enabled(dev_priv,
807 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300808 seq_printf(m, "Pipe %c power disabled\n",
809 pipe_name(pipe));
810 continue;
811 }
Ben Widawskya123f152013-11-02 21:07:10 -0700812 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000813 pipe_name(pipe),
814 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700815 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000816 pipe_name(pipe),
817 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700818 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000819 pipe_name(pipe),
820 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200821
822 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700823 }
824
825 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
826 I915_READ(GEN8_DE_PORT_IMR));
827 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
828 I915_READ(GEN8_DE_PORT_IIR));
829 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
830 I915_READ(GEN8_DE_PORT_IER));
831
832 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
833 I915_READ(GEN8_DE_MISC_IMR));
834 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
835 I915_READ(GEN8_DE_MISC_IIR));
836 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
837 I915_READ(GEN8_DE_MISC_IER));
838
839 seq_printf(m, "PCU interrupt mask:\t%08x\n",
840 I915_READ(GEN8_PCU_IMR));
841 seq_printf(m, "PCU interrupt identity:\t%08x\n",
842 I915_READ(GEN8_PCU_IIR));
843 seq_printf(m, "PCU interrupt enable:\t%08x\n",
844 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300845 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700846 seq_printf(m, "Display IER:\t%08x\n",
847 I915_READ(VLV_IER));
848 seq_printf(m, "Display IIR:\t%08x\n",
849 I915_READ(VLV_IIR));
850 seq_printf(m, "Display IIR_RW:\t%08x\n",
851 I915_READ(VLV_IIR_RW));
852 seq_printf(m, "Display IMR:\t%08x\n",
853 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000854 for_each_pipe(dev_priv, pipe) {
855 enum intel_display_power_domain power_domain;
856
857 power_domain = POWER_DOMAIN_PIPE(pipe);
858 if (!intel_display_power_get_if_enabled(dev_priv,
859 power_domain)) {
860 seq_printf(m, "Pipe %c power disabled\n",
861 pipe_name(pipe));
862 continue;
863 }
864
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700865 seq_printf(m, "Pipe %c stat:\t%08x\n",
866 pipe_name(pipe),
867 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000868 intel_display_power_put(dev_priv, power_domain);
869 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700870
871 seq_printf(m, "Master IER:\t%08x\n",
872 I915_READ(VLV_MASTER_IER));
873
874 seq_printf(m, "Render IER:\t%08x\n",
875 I915_READ(GTIER));
876 seq_printf(m, "Render IIR:\t%08x\n",
877 I915_READ(GTIIR));
878 seq_printf(m, "Render IMR:\t%08x\n",
879 I915_READ(GTIMR));
880
881 seq_printf(m, "PM IER:\t\t%08x\n",
882 I915_READ(GEN6_PMIER));
883 seq_printf(m, "PM IIR:\t\t%08x\n",
884 I915_READ(GEN6_PMIIR));
885 seq_printf(m, "PM IMR:\t\t%08x\n",
886 I915_READ(GEN6_PMIMR));
887
888 seq_printf(m, "Port hotplug:\t%08x\n",
889 I915_READ(PORT_HOTPLUG_EN));
890 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
891 I915_READ(VLV_DPFLIPSTAT));
892 seq_printf(m, "DPINVGTT:\t%08x\n",
893 I915_READ(DPINVGTT));
894
David Weinehall36cdd012016-08-22 13:59:31 +0300895 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800896 seq_printf(m, "Interrupt enable: %08x\n",
897 I915_READ(IER));
898 seq_printf(m, "Interrupt identity: %08x\n",
899 I915_READ(IIR));
900 seq_printf(m, "Interrupt mask: %08x\n",
901 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100902 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800903 seq_printf(m, "Pipe %c stat: %08x\n",
904 pipe_name(pipe),
905 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800906 } else {
907 seq_printf(m, "North Display Interrupt enable: %08x\n",
908 I915_READ(DEIER));
909 seq_printf(m, "North Display Interrupt identity: %08x\n",
910 I915_READ(DEIIR));
911 seq_printf(m, "North Display Interrupt mask: %08x\n",
912 I915_READ(DEIMR));
913 seq_printf(m, "South Display Interrupt enable: %08x\n",
914 I915_READ(SDEIER));
915 seq_printf(m, "South Display Interrupt identity: %08x\n",
916 I915_READ(SDEIIR));
917 seq_printf(m, "South Display Interrupt mask: %08x\n",
918 I915_READ(SDEIMR));
919 seq_printf(m, "Graphics Interrupt enable: %08x\n",
920 I915_READ(GTIER));
921 seq_printf(m, "Graphics Interrupt identity: %08x\n",
922 I915_READ(GTIIR));
923 seq_printf(m, "Graphics Interrupt mask: %08x\n",
924 I915_READ(GTIMR));
925 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530926 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300927 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100928 seq_printf(m,
929 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000930 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000931 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000932 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000933 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200934 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100935
Ben Gamari20172632009-02-17 20:08:50 -0500936 return 0;
937}
938
Chris Wilsona6172a82009-02-11 14:26:38 +0000939static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
940{
David Weinehall36cdd012016-08-22 13:59:31 +0300941 struct drm_i915_private *dev_priv = node_to_i915(m->private);
942 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100943 int i, ret;
944
945 ret = mutex_lock_interruptible(&dev->struct_mutex);
946 if (ret)
947 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000948
Chris Wilsona6172a82009-02-11 14:26:38 +0000949 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
950 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100951 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000952
Chris Wilson6c085a72012-08-20 11:40:46 +0200953 seq_printf(m, "Fence %d, pin count = %d, object = ",
954 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100955 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100956 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100957 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100958 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100959 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000960 }
961
Chris Wilson05394f32010-11-08 19:18:58 +0000962 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000963 return 0;
964}
965
Chris Wilson98a2f412016-10-12 10:05:18 +0100966#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000967static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
968 size_t count, loff_t *pos)
969{
970 struct i915_gpu_state *error = file->private_data;
971 struct drm_i915_error_state_buf str;
972 ssize_t ret;
973 loff_t tmp;
974
975 if (!error)
976 return 0;
977
978 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
979 if (ret)
980 return ret;
981
982 ret = i915_error_state_to_str(&str, error);
983 if (ret)
984 goto out;
985
986 tmp = 0;
987 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
988 if (ret < 0)
989 goto out;
990
991 *pos = str.start + ret;
992out:
993 i915_error_state_buf_release(&str);
994 return ret;
995}
996
997static int gpu_state_release(struct inode *inode, struct file *file)
998{
999 i915_gpu_state_put(file->private_data);
1000 return 0;
1001}
1002
1003static int i915_gpu_info_open(struct inode *inode, struct file *file)
1004{
1005 struct i915_gpu_state *gpu;
1006
1007 gpu = i915_capture_gpu_state(inode->i_private);
1008 if (!gpu)
1009 return -ENOMEM;
1010
1011 file->private_data = gpu;
1012 return 0;
1013}
1014
1015static const struct file_operations i915_gpu_info_fops = {
1016 .owner = THIS_MODULE,
1017 .open = i915_gpu_info_open,
1018 .read = gpu_state_read,
1019 .llseek = default_llseek,
1020 .release = gpu_state_release,
1021};
Chris Wilson98a2f412016-10-12 10:05:18 +01001022
Daniel Vetterd5442302012-04-27 15:17:40 +02001023static ssize_t
1024i915_error_state_write(struct file *filp,
1025 const char __user *ubuf,
1026 size_t cnt,
1027 loff_t *ppos)
1028{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001029 struct i915_gpu_state *error = filp->private_data;
1030
1031 if (!error)
1032 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001033
1034 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001035 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +02001036
1037 return cnt;
1038}
1039
1040static int i915_error_state_open(struct inode *inode, struct file *file)
1041{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001042 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001043 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001044}
1045
Daniel Vetterd5442302012-04-27 15:17:40 +02001046static const struct file_operations i915_error_state_fops = {
1047 .owner = THIS_MODULE,
1048 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001049 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001050 .write = i915_error_state_write,
1051 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001052 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +02001053};
Chris Wilson98a2f412016-10-12 10:05:18 +01001054#endif
1055
Kees Cook647416f2013-03-10 14:10:06 -07001056static int
Kees Cook647416f2013-03-10 14:10:06 -07001057i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001058{
David Weinehall36cdd012016-08-22 13:59:31 +03001059 struct drm_i915_private *dev_priv = data;
1060 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001061 int ret;
1062
Mika Kuoppala40633212012-12-04 15:12:00 +02001063 ret = mutex_lock_interruptible(&dev->struct_mutex);
1064 if (ret)
1065 return ret;
1066
Chris Wilson73cb9702016-10-28 13:58:46 +01001067 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001068 mutex_unlock(&dev->struct_mutex);
1069
Kees Cook647416f2013-03-10 14:10:06 -07001070 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001071}
1072
Kees Cook647416f2013-03-10 14:10:06 -07001073DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001074 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001075 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001076
Deepak Sadb4bd12014-03-31 11:30:02 +05301077static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001078{
David Weinehall36cdd012016-08-22 13:59:31 +03001079 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001080 int ret = 0;
1081
1082 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001083
David Weinehall36cdd012016-08-22 13:59:31 +03001084 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001085 u16 rgvswctl = I915_READ16(MEMSWCTL);
1086 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1087
1088 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1089 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1090 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1091 MEMSTAT_VID_SHIFT);
1092 seq_printf(m, "Current P-state: %d\n",
1093 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001094 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001095 u32 freq_sts;
1096
1097 mutex_lock(&dev_priv->rps.hw_lock);
1098 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1099 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1100 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1101
1102 seq_printf(m, "actual GPU freq: %d MHz\n",
1103 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1104
1105 seq_printf(m, "current GPU freq: %d MHz\n",
1106 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1107
1108 seq_printf(m, "max GPU freq: %d MHz\n",
1109 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1110
1111 seq_printf(m, "min GPU freq: %d MHz\n",
1112 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1113
1114 seq_printf(m, "idle GPU freq: %d MHz\n",
1115 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1116
1117 seq_printf(m,
1118 "efficient (RPe) frequency: %d MHz\n",
1119 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1120 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001121 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001122 u32 rp_state_limits;
1123 u32 gt_perf_status;
1124 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001125 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001126 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001127 u32 rpupei, rpcurup, rpprevup;
1128 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001129 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001130 int max_freq;
1131
Bob Paauwe35040562015-06-25 14:54:07 -07001132 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001133 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001134 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1135 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1136 } else {
1137 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1138 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1139 }
1140
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001141 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001142 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001144 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001145 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301146 reqf >>= 23;
1147 else {
1148 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001149 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301150 reqf >>= 24;
1151 else
1152 reqf >>= 25;
1153 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001154 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001155
Chris Wilson0d8f9492014-03-27 09:06:14 +00001156 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1157 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1158 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1159
Jesse Barnesccab5c82011-01-18 15:49:25 -08001160 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301161 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1162 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1163 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1164 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1165 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1166 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001167 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301168 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001169 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001170 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1171 else
1172 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001173 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001174
Mika Kuoppala59bad942015-01-16 11:34:40 +02001175 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001176
David Weinehall36cdd012016-08-22 13:59:31 +03001177 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001178 pm_ier = I915_READ(GEN6_PMIER);
1179 pm_imr = I915_READ(GEN6_PMIMR);
1180 pm_isr = I915_READ(GEN6_PMISR);
1181 pm_iir = I915_READ(GEN6_PMIIR);
1182 pm_mask = I915_READ(GEN6_PMINTRMSK);
1183 } else {
1184 pm_ier = I915_READ(GEN8_GT_IER(2));
1185 pm_imr = I915_READ(GEN8_GT_IMR(2));
1186 pm_isr = I915_READ(GEN8_GT_ISR(2));
1187 pm_iir = I915_READ(GEN8_GT_IIR(2));
1188 pm_mask = I915_READ(GEN6_PMINTRMSK);
1189 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001190 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 -03001191 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05301192 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
1193 dev_priv->rps.pm_intrmsk_mbz);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001194 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001195 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001196 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001197 seq_printf(m, "Render p-state VID: %d\n",
1198 gt_perf_status & 0xff);
1199 seq_printf(m, "Render p-state limit: %d\n",
1200 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001201 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1202 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1203 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1204 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001205 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001206 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301207 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1208 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1209 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1210 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1211 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1212 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001213 seq_printf(m, "Up threshold: %d%%\n",
1214 dev_priv->rps.up_threshold);
1215
Akash Goeld6cda9c2016-04-23 00:05:46 +05301216 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1217 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1218 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1219 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1220 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1221 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001222 seq_printf(m, "Down threshold: %d%%\n",
1223 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001224
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001225 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001226 rp_state_cap >> 16) & 0xff;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001227 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001228 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001229 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001230
1231 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001232 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001233 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001234 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001235
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001236 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001237 rp_state_cap >> 0) & 0xff;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001238 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001239 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001240 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001241 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001242 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001243
Chris Wilsond86ed342015-04-27 13:41:19 +01001244 seq_printf(m, "Current freq: %d MHz\n",
1245 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1246 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001247 seq_printf(m, "Idle freq: %d MHz\n",
1248 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001249 seq_printf(m, "Min freq: %d MHz\n",
1250 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001251 seq_printf(m, "Boost freq: %d MHz\n",
1252 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001253 seq_printf(m, "Max freq: %d MHz\n",
1254 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1255 seq_printf(m,
1256 "efficient (RPe) frequency: %d MHz\n",
1257 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001259 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001261
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001262 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001263 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1264 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1265
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001266 intel_runtime_pm_put(dev_priv);
1267 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001268}
1269
Ben Widawskyd6369512016-09-20 16:54:32 +03001270static void i915_instdone_info(struct drm_i915_private *dev_priv,
1271 struct seq_file *m,
1272 struct intel_instdone *instdone)
1273{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001274 int slice;
1275 int subslice;
1276
Ben Widawskyd6369512016-09-20 16:54:32 +03001277 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1278 instdone->instdone);
1279
1280 if (INTEL_GEN(dev_priv) <= 3)
1281 return;
1282
1283 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1284 instdone->slice_common);
1285
1286 if (INTEL_GEN(dev_priv) <= 6)
1287 return;
1288
Ben Widawskyf9e61372016-09-20 16:54:33 +03001289 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1290 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1291 slice, subslice, instdone->sampler[slice][subslice]);
1292
1293 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1294 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1295 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001296}
1297
Chris Wilsonf6544492015-01-26 18:03:04 +02001298static int i915_hangcheck_info(struct seq_file *m, void *unused)
1299{
David Weinehall36cdd012016-08-22 13:59:31 +03001300 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001301 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001302 u64 acthd[I915_NUM_ENGINES];
1303 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001304 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001305 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001306
Chris Wilson8af29b02016-09-09 14:11:47 +01001307 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001308 seq_puts(m, "Wedged\n");
1309 if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
1310 seq_puts(m, "Reset in progress: struct_mutex backoff\n");
1311 if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
1312 seq_puts(m, "Reset in progress: reset handoff to waiter\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001313 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001314 seq_puts(m, "Waiter holding struct mutex\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001315 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001316 seq_puts(m, "struct_mutex blocked for reset\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001317
Chris Wilsonf6544492015-01-26 18:03:04 +02001318 if (!i915.enable_hangcheck) {
Chris Wilson8c185ec2017-03-16 17:13:02 +00001319 seq_puts(m, "Hangcheck disabled\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001320 return 0;
1321 }
1322
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001323 intel_runtime_pm_get(dev_priv);
1324
Akash Goel3b3f1652016-10-13 22:44:48 +05301325 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001326 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001327 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001328 }
1329
Akash Goel3b3f1652016-10-13 22:44:48 +05301330 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001331
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001332 intel_runtime_pm_put(dev_priv);
1333
Chris Wilson8352aea2017-03-03 09:00:56 +00001334 if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
1335 seq_printf(m, "Hangcheck active, timer fires in %dms\n",
Chris Wilsonf6544492015-01-26 18:03:04 +02001336 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1337 jiffies));
Chris Wilson8352aea2017-03-03 09:00:56 +00001338 else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
1339 seq_puts(m, "Hangcheck active, work pending\n");
1340 else
1341 seq_puts(m, "Hangcheck inactive\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001342
Chris Wilsonf73b5672017-03-02 15:03:56 +00001343 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1344
Akash Goel3b3f1652016-10-13 22:44:48 +05301345 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001346 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1347 struct rb_node *rb;
1348
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001349 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001350 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001351 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001352 intel_engine_last_submit(engine),
1353 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001354 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001355 yesno(intel_engine_has_waiter(engine)),
1356 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001357 &dev_priv->gpu_error.missed_irq_rings)),
1358 yesno(engine->hangcheck.stalled));
1359
Chris Wilson61d3dc72017-03-03 19:08:24 +00001360 spin_lock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001361 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001362 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001363
1364 seq_printf(m, "\t%s [%d] waiting for %x\n",
1365 w->tsk->comm, w->tsk->pid, w->seqno);
1366 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001367 spin_unlock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001368
Chris Wilsonf6544492015-01-26 18:03:04 +02001369 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001370 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001371 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001372 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1373 hangcheck_action_to_str(engine->hangcheck.action),
1374 engine->hangcheck.action,
1375 jiffies_to_msecs(jiffies -
1376 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001377
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001378 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001379 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001380
Ben Widawskyd6369512016-09-20 16:54:32 +03001381 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001382
Ben Widawskyd6369512016-09-20 16:54:32 +03001383 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001384
Ben Widawskyd6369512016-09-20 16:54:32 +03001385 i915_instdone_info(dev_priv, m,
1386 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001387 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001388 }
1389
1390 return 0;
1391}
1392
Ben Widawsky4d855292011-12-12 19:34:16 -08001393static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001394{
David Weinehall36cdd012016-08-22 13:59:31 +03001395 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001396 u32 rgvmodectl, rstdbyctl;
1397 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001398
Ben Widawsky616fdb52011-10-05 11:44:54 -07001399 rgvmodectl = I915_READ(MEMMODECTL);
1400 rstdbyctl = I915_READ(RSTDBYCTL);
1401 crstandvid = I915_READ16(CRSTANDVID);
1402
Jani Nikula742f4912015-09-03 11:16:09 +03001403 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001404 seq_printf(m, "Boost freq: %d\n",
1405 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1406 MEMMODE_BOOST_FREQ_SHIFT);
1407 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001408 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001409 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001410 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001411 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001412 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001413 seq_printf(m, "Starting frequency: P%d\n",
1414 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001415 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001416 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001417 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1418 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1419 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1420 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001421 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001422 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001423 switch (rstdbyctl & RSX_STATUS_MASK) {
1424 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001425 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001426 break;
1427 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001428 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001429 break;
1430 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001431 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001432 break;
1433 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001434 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001435 break;
1436 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001437 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001438 break;
1439 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001440 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001441 break;
1442 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001443 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001444 break;
1445 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001446
1447 return 0;
1448}
1449
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001450static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001451{
David Weinehall36cdd012016-08-22 13:59:31 +03001452 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001453 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001454
1455 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001456 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001457 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001458 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001459 fw_domain->wake_count);
1460 }
1461 spin_unlock_irq(&dev_priv->uncore.lock);
1462
1463 return 0;
1464}
1465
Mika Kuoppala13628772017-03-15 17:43:02 +02001466static void print_rc6_res(struct seq_file *m,
1467 const char *title,
1468 const i915_reg_t reg)
1469{
1470 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1471
1472 seq_printf(m, "%s %u (%llu us)\n",
1473 title, I915_READ(reg),
1474 intel_rc6_residency_us(dev_priv, reg));
1475}
1476
Deepak S669ab5a2014-01-10 15:18:26 +05301477static int vlv_drpc_info(struct seq_file *m)
1478{
David Weinehall36cdd012016-08-22 13:59:31 +03001479 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001480 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301481
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001482 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301483 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1484 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1485
1486 seq_printf(m, "Video Turbo Mode: %s\n",
1487 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1488 seq_printf(m, "Turbo enabled: %s\n",
1489 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1490 seq_printf(m, "HW control enabled: %s\n",
1491 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1492 seq_printf(m, "SW control enabled: %s\n",
1493 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1494 GEN6_RP_MEDIA_SW_MODE));
1495 seq_printf(m, "RC6 Enabled: %s\n",
1496 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1497 GEN6_RC_CTL_EI_MODE(1))));
1498 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001499 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301500 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001501 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301502
Mika Kuoppala13628772017-03-15 17:43:02 +02001503 print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
1504 print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
Imre Deak9cc19be2014-04-14 20:24:24 +03001505
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001506 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301507}
1508
Ben Widawsky4d855292011-12-12 19:34:16 -08001509static int gen6_drpc_info(struct seq_file *m)
1510{
David Weinehall36cdd012016-08-22 13:59:31 +03001511 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001512 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301513 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001514 unsigned forcewake_count;
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001515 int count = 0;
Ben Widawsky4d855292011-12-12 19:34:16 -08001516
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001517 forcewake_count = READ_ONCE(dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001518 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001519 seq_puts(m, "RC information inaccurate because somebody "
1520 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001521 } else {
1522 /* NB: we cannot use forcewake, else we read the wrong values */
1523 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1524 udelay(10);
1525 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1526 }
1527
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001528 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001529 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001530
1531 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1532 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001533 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301534 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1535 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1536 }
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001537
Ben Widawsky44cbd332012-11-06 14:36:36 +00001538 mutex_lock(&dev_priv->rps.hw_lock);
1539 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1540 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001541
1542 seq_printf(m, "Video Turbo Mode: %s\n",
1543 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1544 seq_printf(m, "HW control enabled: %s\n",
1545 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1546 seq_printf(m, "SW control enabled: %s\n",
1547 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1548 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001549 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001550 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1551 seq_printf(m, "RC6 Enabled: %s\n",
1552 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001553 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301554 seq_printf(m, "Render Well Gating Enabled: %s\n",
1555 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1556 seq_printf(m, "Media Well Gating Enabled: %s\n",
1557 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1558 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 seq_printf(m, "Deep RC6 Enabled: %s\n",
1560 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1561 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1562 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001563 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001564 switch (gt_core_status & GEN6_RCn_MASK) {
1565 case GEN6_RC0:
1566 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001567 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001568 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001569 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001570 break;
1571 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001572 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001573 break;
1574 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001575 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001576 break;
1577 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001578 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001579 break;
1580 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001581 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001582 break;
1583 }
1584
1585 seq_printf(m, "Core Power Down: %s\n",
1586 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001587 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301588 seq_printf(m, "Render Power Well: %s\n",
1589 (gen9_powergate_status &
1590 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1591 seq_printf(m, "Media Power Well: %s\n",
1592 (gen9_powergate_status &
1593 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1594 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001595
1596 /* Not exactly sure what this is */
Mika Kuoppala13628772017-03-15 17:43:02 +02001597 print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
1598 GEN6_GT_GFX_RC6_LOCKED);
1599 print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
1600 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
1601 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
Ben Widawskycce66a22012-03-27 18:59:38 -07001602
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001603 seq_printf(m, "RC6 voltage: %dmV\n",
1604 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1605 seq_printf(m, "RC6+ voltage: %dmV\n",
1606 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1607 seq_printf(m, "RC6++ voltage: %dmV\n",
1608 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301609 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001610}
1611
1612static int i915_drpc_info(struct seq_file *m, void *unused)
1613{
David Weinehall36cdd012016-08-22 13:59:31 +03001614 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001615 int err;
1616
1617 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001618
David Weinehall36cdd012016-08-22 13:59:31 +03001619 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001620 err = vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001621 else if (INTEL_GEN(dev_priv) >= 6)
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001622 err = gen6_drpc_info(m);
Ben Widawsky4d855292011-12-12 19:34:16 -08001623 else
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001624 err = ironlake_drpc_info(m);
1625
1626 intel_runtime_pm_put(dev_priv);
1627
1628 return err;
Ben Widawsky4d855292011-12-12 19:34:16 -08001629}
1630
Daniel Vetter9a851782015-06-18 10:30:22 +02001631static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1632{
David Weinehall36cdd012016-08-22 13:59:31 +03001633 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001634
1635 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1636 dev_priv->fb_tracking.busy_bits);
1637
1638 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1639 dev_priv->fb_tracking.flip_bits);
1640
1641 return 0;
1642}
1643
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001644static int i915_fbc_status(struct seq_file *m, void *unused)
1645{
David Weinehall36cdd012016-08-22 13:59:31 +03001646 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001647
David Weinehall36cdd012016-08-22 13:59:31 +03001648 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001649 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001650 return 0;
1651 }
1652
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001653 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001654 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001655
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001656 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001657 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001658 else
1659 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001660 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001661
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001662 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1663 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1664 BDW_FBC_COMPRESSION_MASK :
1665 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001666 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001667 yesno(I915_READ(FBC_STATUS2) & mask));
1668 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001669
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001670 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001671 intel_runtime_pm_put(dev_priv);
1672
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001673 return 0;
1674}
1675
Rodrigo Vivida46f932014-08-01 02:04:45 -07001676static int i915_fbc_fc_get(void *data, u64 *val)
1677{
David Weinehall36cdd012016-08-22 13:59:31 +03001678 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001679
David Weinehall36cdd012016-08-22 13:59:31 +03001680 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001681 return -ENODEV;
1682
Rodrigo Vivida46f932014-08-01 02:04:45 -07001683 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001684
1685 return 0;
1686}
1687
1688static int i915_fbc_fc_set(void *data, u64 val)
1689{
David Weinehall36cdd012016-08-22 13:59:31 +03001690 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001691 u32 reg;
1692
David Weinehall36cdd012016-08-22 13:59:31 +03001693 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001694 return -ENODEV;
1695
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001696 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001697
1698 reg = I915_READ(ILK_DPFC_CONTROL);
1699 dev_priv->fbc.false_color = val;
1700
1701 I915_WRITE(ILK_DPFC_CONTROL, val ?
1702 (reg | FBC_CTL_FALSE_COLOR) :
1703 (reg & ~FBC_CTL_FALSE_COLOR));
1704
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001705 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001706 return 0;
1707}
1708
1709DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1710 i915_fbc_fc_get, i915_fbc_fc_set,
1711 "%llu\n");
1712
Paulo Zanoni92d44622013-05-31 16:33:24 -03001713static int i915_ips_status(struct seq_file *m, void *unused)
1714{
David Weinehall36cdd012016-08-22 13:59:31 +03001715 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001716
David Weinehall36cdd012016-08-22 13:59:31 +03001717 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001718 seq_puts(m, "not supported\n");
1719 return 0;
1720 }
1721
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001722 intel_runtime_pm_get(dev_priv);
1723
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001724 seq_printf(m, "Enabled by kernel parameter: %s\n",
1725 yesno(i915.enable_ips));
1726
David Weinehall36cdd012016-08-22 13:59:31 +03001727 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001728 seq_puts(m, "Currently: unknown\n");
1729 } else {
1730 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1731 seq_puts(m, "Currently: enabled\n");
1732 else
1733 seq_puts(m, "Currently: disabled\n");
1734 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001735
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001736 intel_runtime_pm_put(dev_priv);
1737
Paulo Zanoni92d44622013-05-31 16:33:24 -03001738 return 0;
1739}
1740
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001741static int i915_sr_status(struct seq_file *m, void *unused)
1742{
David Weinehall36cdd012016-08-22 13:59:31 +03001743 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001744 bool sr_enabled = false;
1745
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001746 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001747 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001748
Chris Wilson7342a722017-03-09 14:20:49 +00001749 if (INTEL_GEN(dev_priv) >= 9)
1750 /* no global SR status; inspect per-plane WM */;
1751 else if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001752 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001753 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001754 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001755 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001756 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001757 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001758 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001759 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001760 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001761 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001762
Chris Wilson9c870d02016-10-24 13:42:15 +01001763 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001764 intel_runtime_pm_put(dev_priv);
1765
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001766 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001767
1768 return 0;
1769}
1770
Jesse Barnes7648fa92010-05-20 14:28:11 -07001771static int i915_emon_status(struct seq_file *m, void *unused)
1772{
David Weinehall36cdd012016-08-22 13:59:31 +03001773 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1774 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001775 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001776 int ret;
1777
David Weinehall36cdd012016-08-22 13:59:31 +03001778 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001779 return -ENODEV;
1780
Chris Wilsonde227ef2010-07-03 07:58:38 +01001781 ret = mutex_lock_interruptible(&dev->struct_mutex);
1782 if (ret)
1783 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001784
1785 temp = i915_mch_val(dev_priv);
1786 chipset = i915_chipset_val(dev_priv);
1787 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001788 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001789
1790 seq_printf(m, "GMCH temp: %ld\n", temp);
1791 seq_printf(m, "Chipset power: %ld\n", chipset);
1792 seq_printf(m, "GFX power: %ld\n", gfx);
1793 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1794
1795 return 0;
1796}
1797
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001798static int i915_ring_freq_table(struct seq_file *m, void *unused)
1799{
David Weinehall36cdd012016-08-22 13:59:31 +03001800 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001801 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001802 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301803 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001804
Carlos Santa26310342016-08-17 12:30:41 -07001805 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001806 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001807 return 0;
1808 }
1809
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001810 intel_runtime_pm_get(dev_priv);
1811
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001812 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001813 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001814 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001815
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001816 if (IS_GEN9_BC(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301817 /* Convert GT frequency to 50 HZ units */
1818 min_gpu_freq =
1819 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1820 max_gpu_freq =
1821 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1822 } else {
1823 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1824 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1825 }
1826
Damien Lespiau267f0c92013-06-24 22:59:48 +01001827 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001828
Akash Goelf936ec32015-06-29 14:50:22 +05301829 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001830 ia_freq = gpu_freq;
1831 sandybridge_pcode_read(dev_priv,
1832 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1833 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001834 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301835 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001836 (IS_GEN9_BC(dev_priv) ?
1837 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001838 ((ia_freq >> 0) & 0xff) * 100,
1839 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001840 }
1841
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001842 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001843
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001844out:
1845 intel_runtime_pm_put(dev_priv);
1846 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001847}
1848
Chris Wilson44834a62010-08-19 16:09:23 +01001849static int i915_opregion(struct seq_file *m, void *unused)
1850{
David Weinehall36cdd012016-08-22 13:59:31 +03001851 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1852 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001853 struct intel_opregion *opregion = &dev_priv->opregion;
1854 int ret;
1855
1856 ret = mutex_lock_interruptible(&dev->struct_mutex);
1857 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001858 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001859
Jani Nikula2455a8e2015-12-14 12:50:53 +02001860 if (opregion->header)
1861 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001862
1863 mutex_unlock(&dev->struct_mutex);
1864
Daniel Vetter0d38f002012-04-21 22:49:10 +02001865out:
Chris Wilson44834a62010-08-19 16:09:23 +01001866 return 0;
1867}
1868
Jani Nikulaada8f952015-12-15 13:17:12 +02001869static int i915_vbt(struct seq_file *m, void *unused)
1870{
David Weinehall36cdd012016-08-22 13:59:31 +03001871 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001872
1873 if (opregion->vbt)
1874 seq_write(m, opregion->vbt, opregion->vbt_size);
1875
1876 return 0;
1877}
1878
Chris Wilson37811fc2010-08-25 22:45:57 +01001879static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1880{
David Weinehall36cdd012016-08-22 13:59:31 +03001881 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1882 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301883 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001884 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001885 int ret;
1886
1887 ret = mutex_lock_interruptible(&dev->struct_mutex);
1888 if (ret)
1889 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001890
Daniel Vetter06957262015-08-10 13:34:08 +02001891#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001892 if (dev_priv->fbdev) {
1893 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001894
Chris Wilson25bcce92016-07-02 15:36:00 +01001895 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1896 fbdev_fb->base.width,
1897 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001898 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001899 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001900 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001901 drm_framebuffer_read_refcount(&fbdev_fb->base));
1902 describe_obj(m, fbdev_fb->obj);
1903 seq_putc(m, '\n');
1904 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001905#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001906
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001907 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001908 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301909 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1910 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001911 continue;
1912
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001913 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 +01001914 fb->base.width,
1915 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001916 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001917 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001918 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001919 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001920 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001921 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001922 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001923 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001924 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001925
1926 return 0;
1927}
1928
Chris Wilson7e37f882016-08-02 22:50:21 +01001929static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001930{
1931 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001932 ring->space, ring->head, ring->tail,
1933 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001934}
1935
Ben Widawskye76d3632011-03-19 18:14:29 -07001936static int i915_context_status(struct seq_file *m, void *unused)
1937{
David Weinehall36cdd012016-08-22 13:59:31 +03001938 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1939 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001940 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001941 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301942 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001943 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001944
Daniel Vetterf3d28872014-05-29 23:23:08 +02001945 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001946 if (ret)
1947 return ret;
1948
Ben Widawskya33afea2013-09-17 21:12:45 -07001949 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001950 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001951 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001952 struct task_struct *task;
1953
Chris Wilsonc84455b2016-08-15 10:49:08 +01001954 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001955 if (task) {
1956 seq_printf(m, "(%s [%d]) ",
1957 task->comm, task->pid);
1958 put_task_struct(task);
1959 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001960 } else if (IS_ERR(ctx->file_priv)) {
1961 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001962 } else {
1963 seq_puts(m, "(kernel) ");
1964 }
1965
Chris Wilsonbca44d82016-05-24 14:53:41 +01001966 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1967 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001968
Akash Goel3b3f1652016-10-13 22:44:48 +05301969 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001970 struct intel_context *ce = &ctx->engine[engine->id];
1971
1972 seq_printf(m, "%s: ", engine->name);
1973 seq_putc(m, ce->initialised ? 'I' : 'i');
1974 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001975 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001976 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001977 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001978 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001979 }
1980
Ben Widawskya33afea2013-09-17 21:12:45 -07001981 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001982 }
1983
Daniel Vetterf3d28872014-05-29 23:23:08 +02001984 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001985
1986 return 0;
1987}
1988
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001989static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001990 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001991 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001992{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001993 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001994 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001995 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001996
Chris Wilson7069b142016-04-28 09:56:52 +01001997 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1998
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001999 if (!vma) {
2000 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002001 return;
2002 }
2003
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002004 if (vma->flags & I915_VMA_GLOBAL_BIND)
2005 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002006 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002007
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002008 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002009 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002010 return;
2011 }
2012
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002013 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2014 if (page) {
2015 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002016
2017 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002018 seq_printf(m,
2019 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2020 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002021 reg_state[j], reg_state[j + 1],
2022 reg_state[j + 2], reg_state[j + 3]);
2023 }
2024 kunmap_atomic(reg_state);
2025 }
2026
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002027 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002028 seq_putc(m, '\n');
2029}
2030
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002031static int i915_dump_lrc(struct seq_file *m, void *unused)
2032{
David Weinehall36cdd012016-08-22 13:59:31 +03002033 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2034 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002035 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002036 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302037 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002038 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002039
2040 if (!i915.enable_execlists) {
2041 seq_printf(m, "Logical Ring Contexts are disabled\n");
2042 return 0;
2043 }
2044
2045 ret = mutex_lock_interruptible(&dev->struct_mutex);
2046 if (ret)
2047 return ret;
2048
Dave Gordone28e4042016-01-19 19:02:55 +00002049 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302050 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002051 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002052
2053 mutex_unlock(&dev->struct_mutex);
2054
2055 return 0;
2056}
2057
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002058static const char *swizzle_string(unsigned swizzle)
2059{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002060 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002061 case I915_BIT_6_SWIZZLE_NONE:
2062 return "none";
2063 case I915_BIT_6_SWIZZLE_9:
2064 return "bit9";
2065 case I915_BIT_6_SWIZZLE_9_10:
2066 return "bit9/bit10";
2067 case I915_BIT_6_SWIZZLE_9_11:
2068 return "bit9/bit11";
2069 case I915_BIT_6_SWIZZLE_9_10_11:
2070 return "bit9/bit10/bit11";
2071 case I915_BIT_6_SWIZZLE_9_17:
2072 return "bit9/bit17";
2073 case I915_BIT_6_SWIZZLE_9_10_17:
2074 return "bit9/bit10/bit17";
2075 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002076 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002077 }
2078
2079 return "bug";
2080}
2081
2082static int i915_swizzle_info(struct seq_file *m, void *data)
2083{
David Weinehall36cdd012016-08-22 13:59:31 +03002084 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002085
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002086 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002087
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002088 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2089 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2090 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2091 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2092
David Weinehall36cdd012016-08-22 13:59:31 +03002093 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002094 seq_printf(m, "DDC = 0x%08x\n",
2095 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002096 seq_printf(m, "DDC2 = 0x%08x\n",
2097 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002098 seq_printf(m, "C0DRB3 = 0x%04x\n",
2099 I915_READ16(C0DRB3));
2100 seq_printf(m, "C1DRB3 = 0x%04x\n",
2101 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002102 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002103 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2104 I915_READ(MAD_DIMM_C0));
2105 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2106 I915_READ(MAD_DIMM_C1));
2107 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2108 I915_READ(MAD_DIMM_C2));
2109 seq_printf(m, "TILECTL = 0x%08x\n",
2110 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002111 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002112 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2113 I915_READ(GAMTARBMODE));
2114 else
2115 seq_printf(m, "ARB_MODE = 0x%08x\n",
2116 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002117 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2118 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002119 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002120
2121 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2122 seq_puts(m, "L-shaped memory detected\n");
2123
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002124 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002125
2126 return 0;
2127}
2128
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002129static int per_file_ctx(int id, void *ptr, void *data)
2130{
Chris Wilsone2efd132016-05-24 14:53:34 +01002131 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002132 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002133 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2134
2135 if (!ppgtt) {
2136 seq_printf(m, " no ppgtt for context %d\n",
2137 ctx->user_handle);
2138 return 0;
2139 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002140
Oscar Mateof83d6512014-05-22 14:13:38 +01002141 if (i915_gem_context_is_default(ctx))
2142 seq_puts(m, " default context:\n");
2143 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002144 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002145 ppgtt->debug_dump(ppgtt, m);
2146
2147 return 0;
2148}
2149
David Weinehall36cdd012016-08-22 13:59:31 +03002150static void gen8_ppgtt_info(struct seq_file *m,
2151 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002152{
Ben Widawsky77df6772013-11-02 21:07:30 -07002153 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302154 struct intel_engine_cs *engine;
2155 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002156 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002157
Ben Widawsky77df6772013-11-02 21:07:30 -07002158 if (!ppgtt)
2159 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002160
Akash Goel3b3f1652016-10-13 22:44:48 +05302161 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002162 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002163 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002164 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002165 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002166 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002167 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002168 }
2169 }
2170}
2171
David Weinehall36cdd012016-08-22 13:59:31 +03002172static void gen6_ppgtt_info(struct seq_file *m,
2173 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002174{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002175 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302176 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002177
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002178 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002179 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2180
Akash Goel3b3f1652016-10-13 22:44:48 +05302181 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002182 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002183 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002184 seq_printf(m, "GFX_MODE: 0x%08x\n",
2185 I915_READ(RING_MODE_GEN7(engine)));
2186 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2187 I915_READ(RING_PP_DIR_BASE(engine)));
2188 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2189 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2190 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2191 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002192 }
2193 if (dev_priv->mm.aliasing_ppgtt) {
2194 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2195
Damien Lespiau267f0c92013-06-24 22:59:48 +01002196 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002197 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002198
Ben Widawsky87d60b62013-12-06 14:11:29 -08002199 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002200 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002201
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002202 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002203}
2204
2205static int i915_ppgtt_info(struct seq_file *m, void *data)
2206{
David Weinehall36cdd012016-08-22 13:59:31 +03002207 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2208 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002209 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002210 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002211
Chris Wilson637ee292016-08-22 14:28:20 +01002212 mutex_lock(&dev->filelist_mutex);
2213 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002214 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002215 goto out_unlock;
2216
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002217 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002218
David Weinehall36cdd012016-08-22 13:59:31 +03002219 if (INTEL_GEN(dev_priv) >= 8)
2220 gen8_ppgtt_info(m, dev_priv);
2221 else if (INTEL_GEN(dev_priv) >= 6)
2222 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002223
Michel Thierryea91e402015-07-29 17:23:57 +01002224 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2225 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002226 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002227
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002228 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002229 if (!task) {
2230 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002231 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002232 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002233 seq_printf(m, "\nproc: %s\n", task->comm);
2234 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002235 idr_for_each(&file_priv->context_idr, per_file_ctx,
2236 (void *)(unsigned long)m);
2237 }
2238
Chris Wilson637ee292016-08-22 14:28:20 +01002239out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002240 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002241 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002242out_unlock:
2243 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002244 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002245}
2246
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002247static int count_irq_waiters(struct drm_i915_private *i915)
2248{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002249 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302250 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002251 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002252
Akash Goel3b3f1652016-10-13 22:44:48 +05302253 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002254 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002255
2256 return count;
2257}
2258
Chris Wilson7466c292016-08-15 09:49:33 +01002259static const char *rps_power_to_str(unsigned int power)
2260{
2261 static const char * const strings[] = {
2262 [LOW_POWER] = "low power",
2263 [BETWEEN] = "mixed",
2264 [HIGH_POWER] = "high power",
2265 };
2266
2267 if (power >= ARRAY_SIZE(strings) || !strings[power])
2268 return "unknown";
2269
2270 return strings[power];
2271}
2272
Chris Wilson1854d5c2015-04-07 16:20:32 +01002273static int i915_rps_boost_info(struct seq_file *m, void *data)
2274{
David Weinehall36cdd012016-08-22 13:59:31 +03002275 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2276 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002277 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002278
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002279 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002280 seq_printf(m, "GPU busy? %s [%d requests]\n",
2281 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002282 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002283 seq_printf(m, "Frequency requested %d\n",
2284 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2285 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002286 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2287 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2288 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2289 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002290 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2291 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2292 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2293 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002294
2295 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002296 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002297 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2298 struct drm_i915_file_private *file_priv = file->driver_priv;
2299 struct task_struct *task;
2300
2301 rcu_read_lock();
2302 task = pid_task(file->pid, PIDTYPE_PID);
2303 seq_printf(m, "%s [%d]: %d boosts%s\n",
2304 task ? task->comm : "<unknown>",
2305 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002306 file_priv->rps.boosts,
2307 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002308 rcu_read_unlock();
2309 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002310 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002311 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002312 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002313
Chris Wilson7466c292016-08-15 09:49:33 +01002314 if (INTEL_GEN(dev_priv) >= 6 &&
2315 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002316 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002317 u32 rpup, rpupei;
2318 u32 rpdown, rpdownei;
2319
2320 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2321 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2322 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2323 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2324 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2325 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2326
2327 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2328 rps_power_to_str(dev_priv->rps.power));
2329 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002330 rpup && rpupei ? 100 * rpup / rpupei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002331 dev_priv->rps.up_threshold);
2332 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002333 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002334 dev_priv->rps.down_threshold);
2335 } else {
2336 seq_puts(m, "\nRPS Autotuning inactive\n");
2337 }
2338
Chris Wilson8d3afd72015-05-21 21:01:47 +01002339 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002340}
2341
Ben Widawsky63573eb2013-07-04 11:02:07 -07002342static int i915_llc(struct seq_file *m, void *data)
2343{
David Weinehall36cdd012016-08-22 13:59:31 +03002344 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002345 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002346
David Weinehall36cdd012016-08-22 13:59:31 +03002347 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002348 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2349 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002350
2351 return 0;
2352}
2353
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002354static int i915_huc_load_status_info(struct seq_file *m, void *data)
2355{
2356 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2357 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2358
2359 if (!HAS_HUC_UCODE(dev_priv))
2360 return 0;
2361
2362 seq_puts(m, "HuC firmware status:\n");
2363 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2364 seq_printf(m, "\tfetch: %s\n",
2365 intel_uc_fw_status_repr(huc_fw->fetch_status));
2366 seq_printf(m, "\tload: %s\n",
2367 intel_uc_fw_status_repr(huc_fw->load_status));
2368 seq_printf(m, "\tversion wanted: %d.%d\n",
2369 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2370 seq_printf(m, "\tversion found: %d.%d\n",
2371 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2372 seq_printf(m, "\theader: offset is %d; size = %d\n",
2373 huc_fw->header_offset, huc_fw->header_size);
2374 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2375 huc_fw->ucode_offset, huc_fw->ucode_size);
2376 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2377 huc_fw->rsa_offset, huc_fw->rsa_size);
2378
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302379 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002380 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302381 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002382
2383 return 0;
2384}
2385
Alex Daifdf5d352015-08-12 15:43:37 +01002386static int i915_guc_load_status_info(struct seq_file *m, void *data)
2387{
David Weinehall36cdd012016-08-22 13:59:31 +03002388 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002389 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Daifdf5d352015-08-12 15:43:37 +01002390 u32 tmp, i;
2391
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002392 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002393 return 0;
2394
2395 seq_printf(m, "GuC firmware status:\n");
2396 seq_printf(m, "\tpath: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002397 guc_fw->path);
Alex Daifdf5d352015-08-12 15:43:37 +01002398 seq_printf(m, "\tfetch: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002399 intel_uc_fw_status_repr(guc_fw->fetch_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002400 seq_printf(m, "\tload: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002401 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002402 seq_printf(m, "\tversion wanted: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002403 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
Alex Daifdf5d352015-08-12 15:43:37 +01002404 seq_printf(m, "\tversion found: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002405 guc_fw->major_ver_found, guc_fw->minor_ver_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002406 seq_printf(m, "\theader: offset is %d; size = %d\n",
2407 guc_fw->header_offset, guc_fw->header_size);
2408 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2409 guc_fw->ucode_offset, guc_fw->ucode_size);
2410 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2411 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002412
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302413 intel_runtime_pm_get(dev_priv);
2414
Alex Daifdf5d352015-08-12 15:43:37 +01002415 tmp = I915_READ(GUC_STATUS);
2416
2417 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2418 seq_printf(m, "\tBootrom status = 0x%x\n",
2419 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2420 seq_printf(m, "\tuKernel status = 0x%x\n",
2421 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2422 seq_printf(m, "\tMIA Core status = 0x%x\n",
2423 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2424 seq_puts(m, "\nScratch registers:\n");
2425 for (i = 0; i < 16; i++)
2426 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2427
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302428 intel_runtime_pm_put(dev_priv);
2429
Alex Daifdf5d352015-08-12 15:43:37 +01002430 return 0;
2431}
2432
Akash Goel5aa1ee42016-10-12 21:54:36 +05302433static void i915_guc_log_info(struct seq_file *m,
2434 struct drm_i915_private *dev_priv)
2435{
2436 struct intel_guc *guc = &dev_priv->guc;
2437
2438 seq_puts(m, "\nGuC logging stats:\n");
2439
2440 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2441 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2442 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2443
2444 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2445 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2446 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2447
2448 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2449 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2450 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2451
2452 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2453 guc->log.flush_interrupt_count);
2454
2455 seq_printf(m, "\tCapture miss count: %u\n",
2456 guc->log.capture_miss_count);
2457}
2458
Dave Gordon8b417c22015-08-12 15:43:44 +01002459static void i915_guc_client_info(struct seq_file *m,
2460 struct drm_i915_private *dev_priv,
2461 struct i915_guc_client *client)
2462{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002463 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002464 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002465 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002466
2467 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2468 client->priority, client->ctx_index, client->proc_desc_offset);
2469 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002470 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002471 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2472 client->wq_size, client->wq_offset, client->wq_tail);
2473
Dave Gordon551aaec2016-05-13 15:36:33 +01002474 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002475 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2476 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2477
Akash Goel3b3f1652016-10-13 22:44:48 +05302478 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002479 u64 submissions = client->submissions[id];
2480 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002481 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002482 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002483 }
2484 seq_printf(m, "\tTotal: %llu\n", tot);
2485}
2486
2487static int i915_guc_info(struct seq_file *m, void *data)
2488{
David Weinehall36cdd012016-08-22 13:59:31 +03002489 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002490 const struct intel_guc *guc = &dev_priv->guc;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002491 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002492 enum intel_engine_id id;
Chris Wilson334636c2016-11-29 12:10:20 +00002493 u64 total;
Dave Gordon8b417c22015-08-12 15:43:44 +01002494
Chris Wilson334636c2016-11-29 12:10:20 +00002495 if (!guc->execbuf_client) {
2496 seq_printf(m, "GuC submission %s\n",
2497 HAS_GUC_SCHED(dev_priv) ?
2498 "disabled" :
2499 "not supported");
Dave Gordon8b417c22015-08-12 15:43:44 +01002500 return 0;
Chris Wilson334636c2016-11-29 12:10:20 +00002501 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002502
Dave Gordon9636f6d2016-06-13 17:57:28 +01002503 seq_printf(m, "Doorbell map:\n");
Chris Wilson334636c2016-11-29 12:10:20 +00002504 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc->doorbell_bitmap);
2505 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002506
Chris Wilson334636c2016-11-29 12:10:20 +00002507 seq_printf(m, "GuC total action count: %llu\n", guc->action_count);
2508 seq_printf(m, "GuC action failure count: %u\n", guc->action_fail);
2509 seq_printf(m, "GuC last action command: 0x%x\n", guc->action_cmd);
2510 seq_printf(m, "GuC last action status: 0x%x\n", guc->action_status);
2511 seq_printf(m, "GuC last action error code: %d\n", guc->action_err);
Dave Gordon8b417c22015-08-12 15:43:44 +01002512
Chris Wilson334636c2016-11-29 12:10:20 +00002513 total = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002514 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302515 for_each_engine(engine, dev_priv, id) {
Chris Wilson334636c2016-11-29 12:10:20 +00002516 u64 submissions = guc->submissions[id];
Dave Gordonc18468c2016-08-09 15:19:22 +01002517 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002518 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Chris Wilson334636c2016-11-29 12:10:20 +00002519 engine->name, submissions, guc->last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002520 }
2521 seq_printf(m, "\t%s: %llu\n", "Total", total);
2522
Chris Wilson334636c2016-11-29 12:10:20 +00002523 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2524 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002525
Akash Goel5aa1ee42016-10-12 21:54:36 +05302526 i915_guc_log_info(m, dev_priv);
2527
Dave Gordon8b417c22015-08-12 15:43:44 +01002528 /* Add more as required ... */
2529
2530 return 0;
2531}
2532
Alex Dai4c7e77f2015-08-12 15:43:40 +01002533static int i915_guc_log_dump(struct seq_file *m, void *data)
2534{
David Weinehall36cdd012016-08-22 13:59:31 +03002535 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002536 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002537 int i = 0, pg;
2538
Akash Goeld6b40b42016-10-12 21:54:29 +05302539 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002540 return 0;
2541
Akash Goeld6b40b42016-10-12 21:54:29 +05302542 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002543 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2544 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002545
2546 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2547 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2548 *(log + i), *(log + i + 1),
2549 *(log + i + 2), *(log + i + 3));
2550
2551 kunmap_atomic(log);
2552 }
2553
2554 seq_putc(m, '\n');
2555
2556 return 0;
2557}
2558
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302559static int i915_guc_log_control_get(void *data, u64 *val)
2560{
2561 struct drm_device *dev = data;
2562 struct drm_i915_private *dev_priv = to_i915(dev);
2563
2564 if (!dev_priv->guc.log.vma)
2565 return -EINVAL;
2566
2567 *val = i915.guc_log_level;
2568
2569 return 0;
2570}
2571
2572static int i915_guc_log_control_set(void *data, u64 val)
2573{
2574 struct drm_device *dev = data;
2575 struct drm_i915_private *dev_priv = to_i915(dev);
2576 int ret;
2577
2578 if (!dev_priv->guc.log.vma)
2579 return -EINVAL;
2580
2581 ret = mutex_lock_interruptible(&dev->struct_mutex);
2582 if (ret)
2583 return ret;
2584
2585 intel_runtime_pm_get(dev_priv);
2586 ret = i915_guc_log_control(dev_priv, val);
2587 intel_runtime_pm_put(dev_priv);
2588
2589 mutex_unlock(&dev->struct_mutex);
2590 return ret;
2591}
2592
2593DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2594 i915_guc_log_control_get, i915_guc_log_control_set,
2595 "%lld\n");
2596
Chris Wilsonb86bef202017-01-16 13:06:21 +00002597static const char *psr2_live_status(u32 val)
2598{
2599 static const char * const live_status[] = {
2600 "IDLE",
2601 "CAPTURE",
2602 "CAPTURE_FS",
2603 "SLEEP",
2604 "BUFON_FW",
2605 "ML_UP",
2606 "SU_STANDBY",
2607 "FAST_SLEEP",
2608 "DEEP_SLEEP",
2609 "BUF_ON",
2610 "TG_ON"
2611 };
2612
2613 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2614 if (val < ARRAY_SIZE(live_status))
2615 return live_status[val];
2616
2617 return "unknown";
2618}
2619
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002620static int i915_edp_psr_status(struct seq_file *m, void *data)
2621{
David Weinehall36cdd012016-08-22 13:59:31 +03002622 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002623 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002624 u32 stat[3];
2625 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002626 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002627
David Weinehall36cdd012016-08-22 13:59:31 +03002628 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002629 seq_puts(m, "PSR not supported\n");
2630 return 0;
2631 }
2632
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002633 intel_runtime_pm_get(dev_priv);
2634
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002635 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002636 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2637 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002638 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002639 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002640 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2641 dev_priv->psr.busy_frontbuffer_bits);
2642 seq_printf(m, "Re-enable work scheduled: %s\n",
2643 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002644
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302645 if (HAS_DDI(dev_priv)) {
2646 if (dev_priv->psr.psr2_support)
2647 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2648 else
2649 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2650 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002651 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002652 enum transcoder cpu_transcoder =
2653 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2654 enum intel_display_power_domain power_domain;
2655
2656 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2657 if (!intel_display_power_get_if_enabled(dev_priv,
2658 power_domain))
2659 continue;
2660
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002661 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2662 VLV_EDP_PSR_CURR_STATE_MASK;
2663 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2664 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2665 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002666
2667 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002668 }
2669 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002670
2671 seq_printf(m, "Main link in standby mode: %s\n",
2672 yesno(dev_priv->psr.link_standby));
2673
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002674 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002675
David Weinehall36cdd012016-08-22 13:59:31 +03002676 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002677 for_each_pipe(dev_priv, pipe) {
2678 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2679 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2680 seq_printf(m, " pipe %c", pipe_name(pipe));
2681 }
2682 seq_puts(m, "\n");
2683
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002684 /*
2685 * VLV/CHV PSR has no kind of performance counter
2686 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2687 */
David Weinehall36cdd012016-08-22 13:59:31 +03002688 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002689 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002690 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002691
2692 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2693 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302694 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002695 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302696
Chris Wilsonb86bef202017-01-16 13:06:21 +00002697 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2698 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302699 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002700 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002701
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002702 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002703 return 0;
2704}
2705
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002706static int i915_sink_crc(struct seq_file *m, void *data)
2707{
David Weinehall36cdd012016-08-22 13:59:31 +03002708 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2709 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002710 struct intel_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002711 struct drm_connector_list_iter conn_iter;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002712 struct intel_dp *intel_dp = NULL;
2713 int ret;
2714 u8 crc[6];
2715
2716 drm_modeset_lock_all(dev);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002717 drm_connector_list_iter_begin(dev, &conn_iter);
2718 for_each_intel_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002719 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002720
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002721 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002722 continue;
2723
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002724 crtc = connector->base.state->crtc;
2725 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002726 continue;
2727
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002728 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002729 continue;
2730
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002731 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002732
2733 ret = intel_dp_sink_crc(intel_dp, crc);
2734 if (ret)
2735 goto out;
2736
2737 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2738 crc[0], crc[1], crc[2],
2739 crc[3], crc[4], crc[5]);
2740 goto out;
2741 }
2742 ret = -ENODEV;
2743out:
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002744 drm_connector_list_iter_end(&conn_iter);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002745 drm_modeset_unlock_all(dev);
2746 return ret;
2747}
2748
Jesse Barnesec013e72013-08-20 10:29:23 +01002749static int i915_energy_uJ(struct seq_file *m, void *data)
2750{
David Weinehall36cdd012016-08-22 13:59:31 +03002751 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002752 u64 power;
2753 u32 units;
2754
David Weinehall36cdd012016-08-22 13:59:31 +03002755 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002756 return -ENODEV;
2757
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002758 intel_runtime_pm_get(dev_priv);
2759
Jesse Barnesec013e72013-08-20 10:29:23 +01002760 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2761 power = (power & 0x1f00) >> 8;
2762 units = 1000000 / (1 << power); /* convert to uJ */
2763 power = I915_READ(MCH_SECP_NRG_STTS);
2764 power *= units;
2765
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002766 intel_runtime_pm_put(dev_priv);
2767
Jesse Barnesec013e72013-08-20 10:29:23 +01002768 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002769
2770 return 0;
2771}
2772
Damien Lespiau6455c872015-06-04 18:23:57 +01002773static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002774{
David Weinehall36cdd012016-08-22 13:59:31 +03002775 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002776 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002777
Chris Wilsona156e642016-04-03 14:14:21 +01002778 if (!HAS_RUNTIME_PM(dev_priv))
2779 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002780
Chris Wilson67d97da2016-07-04 08:08:31 +01002781 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002782 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002783 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002784#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002785 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002786 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002787#else
2788 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2789#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002790 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002791 pci_power_name(pdev->current_state),
2792 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002793
Jesse Barnesec013e72013-08-20 10:29:23 +01002794 return 0;
2795}
2796
Imre Deak1da51582013-11-25 17:15:35 +02002797static int i915_power_domain_info(struct seq_file *m, void *unused)
2798{
David Weinehall36cdd012016-08-22 13:59:31 +03002799 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002800 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2801 int i;
2802
2803 mutex_lock(&power_domains->lock);
2804
2805 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2806 for (i = 0; i < power_domains->power_well_count; i++) {
2807 struct i915_power_well *power_well;
2808 enum intel_display_power_domain power_domain;
2809
2810 power_well = &power_domains->power_wells[i];
2811 seq_printf(m, "%-25s %d\n", power_well->name,
2812 power_well->count);
2813
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002814 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002815 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002816 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002817 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002818 }
2819
2820 mutex_unlock(&power_domains->lock);
2821
2822 return 0;
2823}
2824
Damien Lespiaub7cec662015-10-27 14:47:01 +02002825static int i915_dmc_info(struct seq_file *m, void *unused)
2826{
David Weinehall36cdd012016-08-22 13:59:31 +03002827 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002828 struct intel_csr *csr;
2829
David Weinehall36cdd012016-08-22 13:59:31 +03002830 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002831 seq_puts(m, "not supported\n");
2832 return 0;
2833 }
2834
2835 csr = &dev_priv->csr;
2836
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002837 intel_runtime_pm_get(dev_priv);
2838
Damien Lespiaub7cec662015-10-27 14:47:01 +02002839 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2840 seq_printf(m, "path: %s\n", csr->fw_path);
2841
2842 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002843 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002844
2845 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2846 CSR_VERSION_MINOR(csr->version));
2847
David Weinehall36cdd012016-08-22 13:59:31 +03002848 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002849 seq_printf(m, "DC3 -> DC5 count: %d\n",
2850 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2851 seq_printf(m, "DC5 -> DC6 count: %d\n",
2852 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002853 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002854 seq_printf(m, "DC3 -> DC5 count: %d\n",
2855 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002856 }
2857
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002858out:
2859 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2860 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2861 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2862
Damien Lespiau83372062015-10-30 17:53:32 +02002863 intel_runtime_pm_put(dev_priv);
2864
Damien Lespiaub7cec662015-10-27 14:47:01 +02002865 return 0;
2866}
2867
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002868static void intel_seq_print_mode(struct seq_file *m, int tabs,
2869 struct drm_display_mode *mode)
2870{
2871 int i;
2872
2873 for (i = 0; i < tabs; i++)
2874 seq_putc(m, '\t');
2875
2876 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",
2877 mode->base.id, mode->name,
2878 mode->vrefresh, mode->clock,
2879 mode->hdisplay, mode->hsync_start,
2880 mode->hsync_end, mode->htotal,
2881 mode->vdisplay, mode->vsync_start,
2882 mode->vsync_end, mode->vtotal,
2883 mode->type, mode->flags);
2884}
2885
2886static void intel_encoder_info(struct seq_file *m,
2887 struct intel_crtc *intel_crtc,
2888 struct intel_encoder *intel_encoder)
2889{
David Weinehall36cdd012016-08-22 13:59:31 +03002890 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2891 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002892 struct drm_crtc *crtc = &intel_crtc->base;
2893 struct intel_connector *intel_connector;
2894 struct drm_encoder *encoder;
2895
2896 encoder = &intel_encoder->base;
2897 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002898 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002899 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2900 struct drm_connector *connector = &intel_connector->base;
2901 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2902 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002903 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002904 drm_get_connector_status_name(connector->status));
2905 if (connector->status == connector_status_connected) {
2906 struct drm_display_mode *mode = &crtc->mode;
2907 seq_printf(m, ", mode:\n");
2908 intel_seq_print_mode(m, 2, mode);
2909 } else {
2910 seq_putc(m, '\n');
2911 }
2912 }
2913}
2914
2915static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2916{
David Weinehall36cdd012016-08-22 13:59:31 +03002917 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2918 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002919 struct drm_crtc *crtc = &intel_crtc->base;
2920 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002921 struct drm_plane_state *plane_state = crtc->primary->state;
2922 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002923
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002924 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002925 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002926 fb->base.id, plane_state->src_x >> 16,
2927 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002928 else
2929 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002930 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2931 intel_encoder_info(m, intel_crtc, intel_encoder);
2932}
2933
2934static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2935{
2936 struct drm_display_mode *mode = panel->fixed_mode;
2937
2938 seq_printf(m, "\tfixed mode:\n");
2939 intel_seq_print_mode(m, 2, mode);
2940}
2941
2942static void intel_dp_info(struct seq_file *m,
2943 struct intel_connector *intel_connector)
2944{
2945 struct intel_encoder *intel_encoder = intel_connector->encoder;
2946 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2947
2948 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002949 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002950 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002951 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002952
2953 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2954 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002955}
2956
Libin Yang9a148a92016-11-28 20:07:05 +08002957static void intel_dp_mst_info(struct seq_file *m,
2958 struct intel_connector *intel_connector)
2959{
2960 struct intel_encoder *intel_encoder = intel_connector->encoder;
2961 struct intel_dp_mst_encoder *intel_mst =
2962 enc_to_mst(&intel_encoder->base);
2963 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2964 struct intel_dp *intel_dp = &intel_dig_port->dp;
2965 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2966 intel_connector->port);
2967
2968 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2969}
2970
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002971static void intel_hdmi_info(struct seq_file *m,
2972 struct intel_connector *intel_connector)
2973{
2974 struct intel_encoder *intel_encoder = intel_connector->encoder;
2975 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2976
Jani Nikula742f4912015-09-03 11:16:09 +03002977 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002978}
2979
2980static void intel_lvds_info(struct seq_file *m,
2981 struct intel_connector *intel_connector)
2982{
2983 intel_panel_info(m, &intel_connector->panel);
2984}
2985
2986static void intel_connector_info(struct seq_file *m,
2987 struct drm_connector *connector)
2988{
2989 struct intel_connector *intel_connector = to_intel_connector(connector);
2990 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002991 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002992
2993 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002994 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002995 drm_get_connector_status_name(connector->status));
2996 if (connector->status == connector_status_connected) {
2997 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2998 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2999 connector->display_info.width_mm,
3000 connector->display_info.height_mm);
3001 seq_printf(m, "\tsubpixel order: %s\n",
3002 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3003 seq_printf(m, "\tCEA rev: %d\n",
3004 connector->display_info.cea_rev);
3005 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003006
3007 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3008 return;
3009
3010 switch (connector->connector_type) {
3011 case DRM_MODE_CONNECTOR_DisplayPort:
3012 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003013 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3014 intel_dp_mst_info(m, intel_connector);
3015 else
3016 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003017 break;
3018 case DRM_MODE_CONNECTOR_LVDS:
3019 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003020 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003021 break;
3022 case DRM_MODE_CONNECTOR_HDMIA:
3023 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3024 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3025 intel_hdmi_info(m, intel_connector);
3026 break;
3027 default:
3028 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003029 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003030
Jesse Barnesf103fc72014-02-20 12:39:57 -08003031 seq_printf(m, "\tmodes:\n");
3032 list_for_each_entry(mode, &connector->modes, head)
3033 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003034}
3035
David Weinehall36cdd012016-08-22 13:59:31 +03003036static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec22014-03-12 09:13:13 +00003037{
Chris Wilson065f2ec22014-03-12 09:13:13 +00003038 u32 state;
3039
Jani Nikula2a307c22016-11-30 17:43:04 +02003040 if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003041 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003042 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003043 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003044
3045 return state;
3046}
3047
David Weinehall36cdd012016-08-22 13:59:31 +03003048static bool cursor_position(struct drm_i915_private *dev_priv,
3049 int pipe, int *x, int *y)
Chris Wilson065f2ec22014-03-12 09:13:13 +00003050{
Chris Wilson065f2ec22014-03-12 09:13:13 +00003051 u32 pos;
3052
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003053 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00003054
3055 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3056 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3057 *x = -*x;
3058
3059 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3060 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3061 *y = -*y;
3062
David Weinehall36cdd012016-08-22 13:59:31 +03003063 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec22014-03-12 09:13:13 +00003064}
3065
Robert Fekete3abc4e02015-10-27 16:58:32 +01003066static const char *plane_type(enum drm_plane_type type)
3067{
3068 switch (type) {
3069 case DRM_PLANE_TYPE_OVERLAY:
3070 return "OVL";
3071 case DRM_PLANE_TYPE_PRIMARY:
3072 return "PRI";
3073 case DRM_PLANE_TYPE_CURSOR:
3074 return "CUR";
3075 /*
3076 * Deliberately omitting default: to generate compiler warnings
3077 * when a new drm_plane_type gets added.
3078 */
3079 }
3080
3081 return "unknown";
3082}
3083
3084static const char *plane_rotation(unsigned int rotation)
3085{
3086 static char buf[48];
3087 /*
3088 * According to doc only one DRM_ROTATE_ is allowed but this
3089 * will print them all to visualize if the values are misused
3090 */
3091 snprintf(buf, sizeof(buf),
3092 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003093 (rotation & DRM_ROTATE_0) ? "0 " : "",
3094 (rotation & DRM_ROTATE_90) ? "90 " : "",
3095 (rotation & DRM_ROTATE_180) ? "180 " : "",
3096 (rotation & DRM_ROTATE_270) ? "270 " : "",
3097 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3098 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003099 rotation);
3100
3101 return buf;
3102}
3103
3104static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3105{
David Weinehall36cdd012016-08-22 13:59:31 +03003106 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3107 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003108 struct intel_plane *intel_plane;
3109
3110 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3111 struct drm_plane_state *state;
3112 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003113 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003114
3115 if (!plane->state) {
3116 seq_puts(m, "plane->state is NULL!\n");
3117 continue;
3118 }
3119
3120 state = plane->state;
3121
Eric Engestrom90844f02016-08-15 01:02:38 +01003122 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003123 drm_get_format_name(state->fb->format->format,
3124 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003125 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003126 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003127 }
3128
Robert Fekete3abc4e02015-10-27 16:58:32 +01003129 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",
3130 plane->base.id,
3131 plane_type(intel_plane->base.type),
3132 state->crtc_x, state->crtc_y,
3133 state->crtc_w, state->crtc_h,
3134 (state->src_x >> 16),
3135 ((state->src_x & 0xffff) * 15625) >> 10,
3136 (state->src_y >> 16),
3137 ((state->src_y & 0xffff) * 15625) >> 10,
3138 (state->src_w >> 16),
3139 ((state->src_w & 0xffff) * 15625) >> 10,
3140 (state->src_h >> 16),
3141 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003142 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003143 plane_rotation(state->rotation));
3144 }
3145}
3146
3147static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3148{
3149 struct intel_crtc_state *pipe_config;
3150 int num_scalers = intel_crtc->num_scalers;
3151 int i;
3152
3153 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3154
3155 /* Not all platformas have a scaler */
3156 if (num_scalers) {
3157 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3158 num_scalers,
3159 pipe_config->scaler_state.scaler_users,
3160 pipe_config->scaler_state.scaler_id);
3161
A.Sunil Kamath58415912016-11-20 23:20:26 +05303162 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003163 struct intel_scaler *sc =
3164 &pipe_config->scaler_state.scalers[i];
3165
3166 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3167 i, yesno(sc->in_use), sc->mode);
3168 }
3169 seq_puts(m, "\n");
3170 } else {
3171 seq_puts(m, "\tNo scalers available on this platform\n");
3172 }
3173}
3174
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003175static int i915_display_info(struct seq_file *m, void *unused)
3176{
David Weinehall36cdd012016-08-22 13:59:31 +03003177 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3178 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003179 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003180 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003181 struct drm_connector_list_iter conn_iter;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003182
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003183 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003184 seq_printf(m, "CRTC info\n");
3185 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003186 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003187 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003188 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003189 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003190
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003191 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003192 pipe_config = to_intel_crtc_state(crtc->base.state);
3193
Robert Fekete3abc4e02015-10-27 16:58:32 +01003194 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003195 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003196 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003197 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3198 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3199
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003200 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003201 intel_crtc_info(m, crtc);
3202
David Weinehall36cdd012016-08-22 13:59:31 +03003203 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003204 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 +03003205 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003206 x, y, crtc->base.cursor->state->crtc_w,
3207 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003208 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003209 intel_scaler_info(m, crtc);
3210 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003211 }
Daniel Vettercace8412014-05-22 17:56:31 +02003212
3213 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3214 yesno(!crtc->cpu_fifo_underrun_disabled),
3215 yesno(!crtc->pch_fifo_underrun_disabled));
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003216 drm_modeset_unlock(&crtc->base.mutex);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003217 }
3218
3219 seq_printf(m, "\n");
3220 seq_printf(m, "Connector info\n");
3221 seq_printf(m, "--------------\n");
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003222 mutex_lock(&dev->mode_config.mutex);
3223 drm_connector_list_iter_begin(dev, &conn_iter);
3224 drm_for_each_connector_iter(connector, &conn_iter)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003225 intel_connector_info(m, connector);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003226 drm_connector_list_iter_end(&conn_iter);
3227 mutex_unlock(&dev->mode_config.mutex);
3228
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003229 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003230
3231 return 0;
3232}
3233
Chris Wilson1b365952016-10-04 21:11:31 +01003234static int i915_engine_info(struct seq_file *m, void *unused)
3235{
3236 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3237 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303238 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003239
Chris Wilson9c870d02016-10-24 13:42:15 +01003240 intel_runtime_pm_get(dev_priv);
3241
Chris Wilsonf73b5672017-03-02 15:03:56 +00003242 seq_printf(m, "GT awake? %s\n",
3243 yesno(dev_priv->gt.awake));
3244 seq_printf(m, "Global active requests: %d\n",
3245 dev_priv->gt.active_requests);
3246
Akash Goel3b3f1652016-10-13 22:44:48 +05303247 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003248 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3249 struct drm_i915_gem_request *rq;
3250 struct rb_node *rb;
3251 u64 addr;
3252
3253 seq_printf(m, "%s\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003254 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003255 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003256 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003257 engine->hangcheck.seqno,
Chris Wilsonf73b5672017-03-02 15:03:56 +00003258 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp),
3259 engine->timeline->inflight_seqnos);
Chris Wilson1b365952016-10-04 21:11:31 +01003260
3261 rcu_read_lock();
3262
3263 seq_printf(m, "\tRequests:\n");
3264
Chris Wilson73cb9702016-10-28 13:58:46 +01003265 rq = list_first_entry(&engine->timeline->requests,
3266 struct drm_i915_gem_request, link);
3267 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003268 print_request(m, rq, "\t\tfirst ");
3269
Chris Wilson73cb9702016-10-28 13:58:46 +01003270 rq = list_last_entry(&engine->timeline->requests,
3271 struct drm_i915_gem_request, link);
3272 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003273 print_request(m, rq, "\t\tlast ");
3274
3275 rq = i915_gem_find_active_request(engine);
3276 if (rq) {
3277 print_request(m, rq, "\t\tactive ");
3278 seq_printf(m,
3279 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3280 rq->head, rq->postfix, rq->tail,
3281 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3282 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3283 }
3284
3285 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3286 I915_READ(RING_START(engine->mmio_base)),
3287 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3288 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3289 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3290 rq ? rq->ring->head : 0);
3291 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3292 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3293 rq ? rq->ring->tail : 0);
3294 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3295 I915_READ(RING_CTL(engine->mmio_base)),
3296 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3297
3298 rcu_read_unlock();
3299
3300 addr = intel_engine_get_active_head(engine);
3301 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3302 upper_32_bits(addr), lower_32_bits(addr));
3303 addr = intel_engine_get_last_batch_head(engine);
3304 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3305 upper_32_bits(addr), lower_32_bits(addr));
3306
3307 if (i915.enable_execlists) {
3308 u32 ptr, read, write;
Chris Wilson20311bd2016-11-14 20:41:03 +00003309 struct rb_node *rb;
Chris Wilson1b365952016-10-04 21:11:31 +01003310
3311 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3312 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3313 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3314
3315 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3316 read = GEN8_CSB_READ_PTR(ptr);
3317 write = GEN8_CSB_WRITE_PTR(ptr);
3318 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3319 read, write);
3320 if (read >= GEN8_CSB_ENTRIES)
3321 read = 0;
3322 if (write >= GEN8_CSB_ENTRIES)
3323 write = 0;
3324 if (read > write)
3325 write += GEN8_CSB_ENTRIES;
3326 while (read < write) {
3327 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3328
3329 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3330 idx,
3331 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3332 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3333 }
3334
3335 rcu_read_lock();
3336 rq = READ_ONCE(engine->execlist_port[0].request);
Chris Wilson816ee792017-01-24 11:00:03 +00003337 if (rq) {
3338 seq_printf(m, "\t\tELSP[0] count=%d, ",
3339 engine->execlist_port[0].count);
3340 print_request(m, rq, "rq: ");
3341 } else {
Chris Wilson1b365952016-10-04 21:11:31 +01003342 seq_printf(m, "\t\tELSP[0] idle\n");
Chris Wilson816ee792017-01-24 11:00:03 +00003343 }
Chris Wilson1b365952016-10-04 21:11:31 +01003344 rq = READ_ONCE(engine->execlist_port[1].request);
Chris Wilson816ee792017-01-24 11:00:03 +00003345 if (rq) {
3346 seq_printf(m, "\t\tELSP[1] count=%d, ",
3347 engine->execlist_port[1].count);
3348 print_request(m, rq, "rq: ");
3349 } else {
Chris Wilson1b365952016-10-04 21:11:31 +01003350 seq_printf(m, "\t\tELSP[1] idle\n");
Chris Wilson816ee792017-01-24 11:00:03 +00003351 }
Chris Wilson1b365952016-10-04 21:11:31 +01003352 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003353
Chris Wilson663f71e2016-11-14 20:41:00 +00003354 spin_lock_irq(&engine->timeline->lock);
Chris Wilson20311bd2016-11-14 20:41:03 +00003355 for (rb = engine->execlist_first; rb; rb = rb_next(rb)) {
3356 rq = rb_entry(rb, typeof(*rq), priotree.node);
Chris Wilsonc8247c02016-10-27 01:03:43 +01003357 print_request(m, rq, "\t\tQ ");
3358 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003359 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003360 } else if (INTEL_GEN(dev_priv) > 6) {
3361 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3362 I915_READ(RING_PP_DIR_BASE(engine)));
3363 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3364 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3365 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3366 I915_READ(RING_PP_DIR_DCLV(engine)));
3367 }
3368
Chris Wilson61d3dc72017-03-03 19:08:24 +00003369 spin_lock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003370 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08003371 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson1b365952016-10-04 21:11:31 +01003372
3373 seq_printf(m, "\t%s [%d] waiting for %x\n",
3374 w->tsk->comm, w->tsk->pid, w->seqno);
3375 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00003376 spin_unlock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003377
3378 seq_puts(m, "\n");
3379 }
3380
Chris Wilson9c870d02016-10-24 13:42:15 +01003381 intel_runtime_pm_put(dev_priv);
3382
Chris Wilson1b365952016-10-04 21:11:31 +01003383 return 0;
3384}
3385
Ben Widawskye04934c2014-06-30 09:53:42 -07003386static int i915_semaphore_status(struct seq_file *m, void *unused)
3387{
David Weinehall36cdd012016-08-22 13:59:31 +03003388 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3389 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003390 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003391 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003392 enum intel_engine_id id;
3393 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003394
Chris Wilson39df9192016-07-20 13:31:57 +01003395 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003396 seq_puts(m, "Semaphores are disabled\n");
3397 return 0;
3398 }
3399
3400 ret = mutex_lock_interruptible(&dev->struct_mutex);
3401 if (ret)
3402 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003403 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003404
David Weinehall36cdd012016-08-22 13:59:31 +03003405 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003406 struct page *page;
3407 uint64_t *seqno;
3408
Chris Wilson51d545d2016-08-15 10:49:02 +01003409 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003410
3411 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303412 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003413 uint64_t offset;
3414
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003415 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003416
3417 seq_puts(m, " Last signal:");
3418 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003419 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003420 seq_printf(m, "0x%08llx (0x%02llx) ",
3421 seqno[offset], offset * 8);
3422 }
3423 seq_putc(m, '\n');
3424
3425 seq_puts(m, " Last wait: ");
3426 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003427 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003428 seq_printf(m, "0x%08llx (0x%02llx) ",
3429 seqno[offset], offset * 8);
3430 }
3431 seq_putc(m, '\n');
3432
3433 }
3434 kunmap_atomic(seqno);
3435 } else {
3436 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303437 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003438 for (j = 0; j < num_rings; j++)
3439 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003440 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003441 seq_putc(m, '\n');
3442 }
3443
Paulo Zanoni03872062014-07-09 14:31:57 -03003444 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003445 mutex_unlock(&dev->struct_mutex);
3446 return 0;
3447}
3448
Daniel Vetter728e29d2014-06-25 22:01:53 +03003449static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3450{
David Weinehall36cdd012016-08-22 13:59:31 +03003451 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3452 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003453 int i;
3454
3455 drm_modeset_lock_all(dev);
3456 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3457 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3458
3459 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003460 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003461 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003462 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003463 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003464 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003465 pll->state.hw_state.dpll_md);
3466 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3467 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3468 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003469 }
3470 drm_modeset_unlock_all(dev);
3471
3472 return 0;
3473}
3474
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003475static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003476{
3477 int i;
3478 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003479 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003480 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3481 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003482 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003483 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003484
Arun Siluvery888b5992014-08-26 14:44:51 +01003485 ret = mutex_lock_interruptible(&dev->struct_mutex);
3486 if (ret)
3487 return ret;
3488
3489 intel_runtime_pm_get(dev_priv);
3490
Arun Siluvery33136b02016-01-21 21:43:47 +00003491 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303492 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003493 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003494 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003495 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003496 i915_reg_t addr;
3497 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003498 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003499
Arun Siluvery33136b02016-01-21 21:43:47 +00003500 addr = workarounds->reg[i].addr;
3501 mask = workarounds->reg[i].mask;
3502 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003503 read = I915_READ(addr);
3504 ok = (value & mask) == (read & mask);
3505 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 +02003506 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003507 }
3508
3509 intel_runtime_pm_put(dev_priv);
3510 mutex_unlock(&dev->struct_mutex);
3511
3512 return 0;
3513}
3514
Damien Lespiauc5511e42014-11-04 17:06:51 +00003515static int i915_ddb_info(struct seq_file *m, void *unused)
3516{
David Weinehall36cdd012016-08-22 13:59:31 +03003517 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3518 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003519 struct skl_ddb_allocation *ddb;
3520 struct skl_ddb_entry *entry;
3521 enum pipe pipe;
3522 int plane;
3523
David Weinehall36cdd012016-08-22 13:59:31 +03003524 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003525 return 0;
3526
Damien Lespiauc5511e42014-11-04 17:06:51 +00003527 drm_modeset_lock_all(dev);
3528
3529 ddb = &dev_priv->wm.skl_hw.ddb;
3530
3531 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3532
3533 for_each_pipe(dev_priv, pipe) {
3534 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3535
Matt Roper8b364b42016-10-26 15:51:28 -07003536 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003537 entry = &ddb->plane[pipe][plane];
3538 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3539 entry->start, entry->end,
3540 skl_ddb_entry_size(entry));
3541 }
3542
Matt Roper4969d332015-09-24 15:53:10 -07003543 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003544 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3545 entry->end, skl_ddb_entry_size(entry));
3546 }
3547
3548 drm_modeset_unlock_all(dev);
3549
3550 return 0;
3551}
3552
Vandana Kannana54746e2015-03-03 20:53:10 +05303553static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003554 struct drm_device *dev,
3555 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303556{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003557 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303558 struct i915_drrs *drrs = &dev_priv->drrs;
3559 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003560 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003561 struct drm_connector_list_iter conn_iter;
Vandana Kannana54746e2015-03-03 20:53:10 +05303562
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003563 drm_connector_list_iter_begin(dev, &conn_iter);
3564 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003565 if (connector->state->crtc != &intel_crtc->base)
3566 continue;
3567
3568 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303569 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003570 drm_connector_list_iter_end(&conn_iter);
Vandana Kannana54746e2015-03-03 20:53:10 +05303571
3572 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3573 seq_puts(m, "\tVBT: DRRS_type: Static");
3574 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3575 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3576 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3577 seq_puts(m, "\tVBT: DRRS_type: None");
3578 else
3579 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3580
3581 seq_puts(m, "\n\n");
3582
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003583 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303584 struct intel_panel *panel;
3585
3586 mutex_lock(&drrs->mutex);
3587 /* DRRS Supported */
3588 seq_puts(m, "\tDRRS Supported: Yes\n");
3589
3590 /* disable_drrs() will make drrs->dp NULL */
3591 if (!drrs->dp) {
3592 seq_puts(m, "Idleness DRRS: Disabled");
3593 mutex_unlock(&drrs->mutex);
3594 return;
3595 }
3596
3597 panel = &drrs->dp->attached_connector->panel;
3598 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3599 drrs->busy_frontbuffer_bits);
3600
3601 seq_puts(m, "\n\t\t");
3602 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3603 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3604 vrefresh = panel->fixed_mode->vrefresh;
3605 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3606 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3607 vrefresh = panel->downclock_mode->vrefresh;
3608 } else {
3609 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3610 drrs->refresh_rate_type);
3611 mutex_unlock(&drrs->mutex);
3612 return;
3613 }
3614 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3615
3616 seq_puts(m, "\n\t\t");
3617 mutex_unlock(&drrs->mutex);
3618 } else {
3619 /* DRRS not supported. Print the VBT parameter*/
3620 seq_puts(m, "\tDRRS Supported : No");
3621 }
3622 seq_puts(m, "\n");
3623}
3624
3625static int i915_drrs_status(struct seq_file *m, void *unused)
3626{
David Weinehall36cdd012016-08-22 13:59:31 +03003627 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3628 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303629 struct intel_crtc *intel_crtc;
3630 int active_crtc_cnt = 0;
3631
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003632 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303633 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003634 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303635 active_crtc_cnt++;
3636 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3637
3638 drrs_status_per_crtc(m, dev, intel_crtc);
3639 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303640 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003641 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303642
3643 if (!active_crtc_cnt)
3644 seq_puts(m, "No active crtc found\n");
3645
3646 return 0;
3647}
3648
Dave Airlie11bed952014-05-12 15:22:27 +10003649static int i915_dp_mst_info(struct seq_file *m, void *unused)
3650{
David Weinehall36cdd012016-08-22 13:59:31 +03003651 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3652 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003653 struct intel_encoder *intel_encoder;
3654 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003655 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003656 struct drm_connector_list_iter conn_iter;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003657
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003658 drm_connector_list_iter_begin(dev, &conn_iter);
3659 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003660 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003661 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003662
3663 intel_encoder = intel_attached_encoder(connector);
3664 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3665 continue;
3666
3667 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003668 if (!intel_dig_port->dp.can_mst)
3669 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003670
Jim Bride40ae80c2016-04-14 10:18:37 -07003671 seq_printf(m, "MST Source Port %c\n",
3672 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003673 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3674 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003675 drm_connector_list_iter_end(&conn_iter);
3676
Dave Airlie11bed952014-05-12 15:22:27 +10003677 return 0;
3678}
3679
Todd Previteeb3394fa2015-04-18 00:04:19 -07003680static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003681 const char __user *ubuf,
3682 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003683{
3684 char *input_buffer;
3685 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003686 struct drm_device *dev;
3687 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003688 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003689 struct intel_dp *intel_dp;
3690 int val = 0;
3691
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303692 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003693
Todd Previteeb3394fa2015-04-18 00:04:19 -07003694 if (len == 0)
3695 return 0;
3696
3697 input_buffer = kmalloc(len + 1, GFP_KERNEL);
3698 if (!input_buffer)
3699 return -ENOMEM;
3700
3701 if (copy_from_user(input_buffer, ubuf, len)) {
3702 status = -EFAULT;
3703 goto out;
3704 }
3705
3706 input_buffer[len] = '\0';
3707 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3708
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003709 drm_connector_list_iter_begin(dev, &conn_iter);
3710 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003711 if (connector->connector_type !=
3712 DRM_MODE_CONNECTOR_DisplayPort)
3713 continue;
3714
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05303715 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07003716 connector->encoder != NULL) {
3717 intel_dp = enc_to_intel_dp(connector->encoder);
3718 status = kstrtoint(input_buffer, 10, &val);
3719 if (status < 0)
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003720 break;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003721 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3722 /* To prevent erroneous activation of the compliance
3723 * testing code, only accept an actual value of 1 here
3724 */
3725 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003726 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003727 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003728 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003729 }
3730 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003731 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003732out:
3733 kfree(input_buffer);
3734 if (status < 0)
3735 return status;
3736
3737 *offp += len;
3738 return len;
3739}
3740
3741static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3742{
3743 struct drm_device *dev = m->private;
3744 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003745 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003746 struct intel_dp *intel_dp;
3747
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003748 drm_connector_list_iter_begin(dev, &conn_iter);
3749 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003750 if (connector->connector_type !=
3751 DRM_MODE_CONNECTOR_DisplayPort)
3752 continue;
3753
3754 if (connector->status == connector_status_connected &&
3755 connector->encoder != NULL) {
3756 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003757 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003758 seq_puts(m, "1");
3759 else
3760 seq_puts(m, "0");
3761 } else
3762 seq_puts(m, "0");
3763 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003764 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003765
3766 return 0;
3767}
3768
3769static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003770 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003771{
David Weinehall36cdd012016-08-22 13:59:31 +03003772 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003773
David Weinehall36cdd012016-08-22 13:59:31 +03003774 return single_open(file, i915_displayport_test_active_show,
3775 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003776}
3777
3778static const struct file_operations i915_displayport_test_active_fops = {
3779 .owner = THIS_MODULE,
3780 .open = i915_displayport_test_active_open,
3781 .read = seq_read,
3782 .llseek = seq_lseek,
3783 .release = single_release,
3784 .write = i915_displayport_test_active_write
3785};
3786
3787static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3788{
3789 struct drm_device *dev = m->private;
3790 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003791 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003792 struct intel_dp *intel_dp;
3793
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003794 drm_connector_list_iter_begin(dev, &conn_iter);
3795 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003796 if (connector->connector_type !=
3797 DRM_MODE_CONNECTOR_DisplayPort)
3798 continue;
3799
3800 if (connector->status == connector_status_connected &&
3801 connector->encoder != NULL) {
3802 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003803 if (intel_dp->compliance.test_type ==
3804 DP_TEST_LINK_EDID_READ)
3805 seq_printf(m, "%lx",
3806 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003807 else if (intel_dp->compliance.test_type ==
3808 DP_TEST_LINK_VIDEO_PATTERN) {
3809 seq_printf(m, "hdisplay: %d\n",
3810 intel_dp->compliance.test_data.hdisplay);
3811 seq_printf(m, "vdisplay: %d\n",
3812 intel_dp->compliance.test_data.vdisplay);
3813 seq_printf(m, "bpc: %u\n",
3814 intel_dp->compliance.test_data.bpc);
3815 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003816 } else
3817 seq_puts(m, "0");
3818 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003819 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003820
3821 return 0;
3822}
3823static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003824 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003825{
David Weinehall36cdd012016-08-22 13:59:31 +03003826 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003827
David Weinehall36cdd012016-08-22 13:59:31 +03003828 return single_open(file, i915_displayport_test_data_show,
3829 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003830}
3831
3832static const struct file_operations i915_displayport_test_data_fops = {
3833 .owner = THIS_MODULE,
3834 .open = i915_displayport_test_data_open,
3835 .read = seq_read,
3836 .llseek = seq_lseek,
3837 .release = single_release
3838};
3839
3840static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3841{
3842 struct drm_device *dev = m->private;
3843 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003844 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003845 struct intel_dp *intel_dp;
3846
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003847 drm_connector_list_iter_begin(dev, &conn_iter);
3848 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003849 if (connector->connector_type !=
3850 DRM_MODE_CONNECTOR_DisplayPort)
3851 continue;
3852
3853 if (connector->status == connector_status_connected &&
3854 connector->encoder != NULL) {
3855 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003856 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003857 } else
3858 seq_puts(m, "0");
3859 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003860 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003861
3862 return 0;
3863}
3864
3865static int i915_displayport_test_type_open(struct inode *inode,
3866 struct file *file)
3867{
David Weinehall36cdd012016-08-22 13:59:31 +03003868 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003869
David Weinehall36cdd012016-08-22 13:59:31 +03003870 return single_open(file, i915_displayport_test_type_show,
3871 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003872}
3873
3874static const struct file_operations i915_displayport_test_type_fops = {
3875 .owner = THIS_MODULE,
3876 .open = i915_displayport_test_type_open,
3877 .read = seq_read,
3878 .llseek = seq_lseek,
3879 .release = single_release
3880};
3881
Damien Lespiau97e94b22014-11-04 17:06:50 +00003882static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003883{
David Weinehall36cdd012016-08-22 13:59:31 +03003884 struct drm_i915_private *dev_priv = m->private;
3885 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003886 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003887 int num_levels;
3888
David Weinehall36cdd012016-08-22 13:59:31 +03003889 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003890 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003891 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003892 num_levels = 1;
3893 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003894 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003895
3896 drm_modeset_lock_all(dev);
3897
3898 for (level = 0; level < num_levels; level++) {
3899 unsigned int latency = wm[level];
3900
Damien Lespiau97e94b22014-11-04 17:06:50 +00003901 /*
3902 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003903 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003904 */
David Weinehall36cdd012016-08-22 13:59:31 +03003905 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
3906 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003907 latency *= 10;
3908 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003909 latency *= 5;
3910
3911 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003912 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003913 }
3914
3915 drm_modeset_unlock_all(dev);
3916}
3917
3918static int pri_wm_latency_show(struct seq_file *m, void *data)
3919{
David Weinehall36cdd012016-08-22 13:59:31 +03003920 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003921 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003922
David Weinehall36cdd012016-08-22 13:59:31 +03003923 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003924 latencies = dev_priv->wm.skl_latency;
3925 else
David Weinehall36cdd012016-08-22 13:59:31 +03003926 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003927
3928 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003929
3930 return 0;
3931}
3932
3933static int spr_wm_latency_show(struct seq_file *m, void *data)
3934{
David Weinehall36cdd012016-08-22 13:59:31 +03003935 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003936 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003937
David Weinehall36cdd012016-08-22 13:59:31 +03003938 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003939 latencies = dev_priv->wm.skl_latency;
3940 else
David Weinehall36cdd012016-08-22 13:59:31 +03003941 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003942
3943 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003944
3945 return 0;
3946}
3947
3948static int cur_wm_latency_show(struct seq_file *m, void *data)
3949{
David Weinehall36cdd012016-08-22 13:59:31 +03003950 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003951 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003952
David Weinehall36cdd012016-08-22 13:59:31 +03003953 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003954 latencies = dev_priv->wm.skl_latency;
3955 else
David Weinehall36cdd012016-08-22 13:59:31 +03003956 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003957
3958 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003959
3960 return 0;
3961}
3962
3963static int pri_wm_latency_open(struct inode *inode, struct file *file)
3964{
David Weinehall36cdd012016-08-22 13:59:31 +03003965 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003966
David Weinehall36cdd012016-08-22 13:59:31 +03003967 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003968 return -ENODEV;
3969
David Weinehall36cdd012016-08-22 13:59:31 +03003970 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003971}
3972
3973static int spr_wm_latency_open(struct inode *inode, struct file *file)
3974{
David Weinehall36cdd012016-08-22 13:59:31 +03003975 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003976
David Weinehall36cdd012016-08-22 13:59:31 +03003977 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003978 return -ENODEV;
3979
David Weinehall36cdd012016-08-22 13:59:31 +03003980 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003981}
3982
3983static int cur_wm_latency_open(struct inode *inode, struct file *file)
3984{
David Weinehall36cdd012016-08-22 13:59:31 +03003985 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003986
David Weinehall36cdd012016-08-22 13:59:31 +03003987 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003988 return -ENODEV;
3989
David Weinehall36cdd012016-08-22 13:59:31 +03003990 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003991}
3992
3993static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003994 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003995{
3996 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003997 struct drm_i915_private *dev_priv = m->private;
3998 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003999 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004000 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004001 int level;
4002 int ret;
4003 char tmp[32];
4004
David Weinehall36cdd012016-08-22 13:59:31 +03004005 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004006 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004007 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004008 num_levels = 1;
4009 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004010 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004011
Ville Syrjälä369a1342014-01-22 14:36:08 +02004012 if (len >= sizeof(tmp))
4013 return -EINVAL;
4014
4015 if (copy_from_user(tmp, ubuf, len))
4016 return -EFAULT;
4017
4018 tmp[len] = '\0';
4019
Damien Lespiau97e94b22014-11-04 17:06:50 +00004020 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4021 &new[0], &new[1], &new[2], &new[3],
4022 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004023 if (ret != num_levels)
4024 return -EINVAL;
4025
4026 drm_modeset_lock_all(dev);
4027
4028 for (level = 0; level < num_levels; level++)
4029 wm[level] = new[level];
4030
4031 drm_modeset_unlock_all(dev);
4032
4033 return len;
4034}
4035
4036
4037static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4038 size_t len, loff_t *offp)
4039{
4040 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004041 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004042 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004043
David Weinehall36cdd012016-08-22 13:59:31 +03004044 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004045 latencies = dev_priv->wm.skl_latency;
4046 else
David Weinehall36cdd012016-08-22 13:59:31 +03004047 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004048
4049 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004050}
4051
4052static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4053 size_t len, loff_t *offp)
4054{
4055 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004056 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004057 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004058
David Weinehall36cdd012016-08-22 13:59:31 +03004059 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004060 latencies = dev_priv->wm.skl_latency;
4061 else
David Weinehall36cdd012016-08-22 13:59:31 +03004062 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004063
4064 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004065}
4066
4067static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4068 size_t len, loff_t *offp)
4069{
4070 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004071 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004072 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004073
David Weinehall36cdd012016-08-22 13:59:31 +03004074 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004075 latencies = dev_priv->wm.skl_latency;
4076 else
David Weinehall36cdd012016-08-22 13:59:31 +03004077 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004078
4079 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004080}
4081
4082static const struct file_operations i915_pri_wm_latency_fops = {
4083 .owner = THIS_MODULE,
4084 .open = pri_wm_latency_open,
4085 .read = seq_read,
4086 .llseek = seq_lseek,
4087 .release = single_release,
4088 .write = pri_wm_latency_write
4089};
4090
4091static const struct file_operations i915_spr_wm_latency_fops = {
4092 .owner = THIS_MODULE,
4093 .open = spr_wm_latency_open,
4094 .read = seq_read,
4095 .llseek = seq_lseek,
4096 .release = single_release,
4097 .write = spr_wm_latency_write
4098};
4099
4100static const struct file_operations i915_cur_wm_latency_fops = {
4101 .owner = THIS_MODULE,
4102 .open = cur_wm_latency_open,
4103 .read = seq_read,
4104 .llseek = seq_lseek,
4105 .release = single_release,
4106 .write = cur_wm_latency_write
4107};
4108
Kees Cook647416f2013-03-10 14:10:06 -07004109static int
4110i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004111{
David Weinehall36cdd012016-08-22 13:59:31 +03004112 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004113
Chris Wilsond98c52c2016-04-13 17:35:05 +01004114 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004115
Kees Cook647416f2013-03-10 14:10:06 -07004116 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004117}
4118
Kees Cook647416f2013-03-10 14:10:06 -07004119static int
4120i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004121{
David Weinehall36cdd012016-08-22 13:59:31 +03004122 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004123
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004124 /*
4125 * There is no safeguard against this debugfs entry colliding
4126 * with the hangcheck calling same i915_handle_error() in
4127 * parallel, causing an explosion. For now we assume that the
4128 * test harness is responsible enough not to inject gpu hangs
4129 * while it is writing to 'i915_wedged'
4130 */
4131
Chris Wilson8c185ec2017-03-16 17:13:02 +00004132 if (i915_reset_backoff(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004133 return -EAGAIN;
4134
Chris Wilsonc0336662016-05-06 15:40:21 +01004135 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004136 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004137
Kees Cook647416f2013-03-10 14:10:06 -07004138 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004139}
4140
Kees Cook647416f2013-03-10 14:10:06 -07004141DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4142 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004143 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004144
Kees Cook647416f2013-03-10 14:10:06 -07004145static int
Chris Wilson64486ae2017-03-07 15:59:08 +00004146fault_irq_set(struct drm_i915_private *i915,
4147 unsigned long *irq,
4148 unsigned long val)
4149{
4150 int err;
4151
4152 err = mutex_lock_interruptible(&i915->drm.struct_mutex);
4153 if (err)
4154 return err;
4155
4156 err = i915_gem_wait_for_idle(i915,
4157 I915_WAIT_LOCKED |
4158 I915_WAIT_INTERRUPTIBLE);
4159 if (err)
4160 goto err_unlock;
4161
4162 /* Retire to kick idle work */
4163 i915_gem_retire_requests(i915);
4164 GEM_BUG_ON(i915->gt.active_requests);
4165
4166 *irq = val;
4167 mutex_unlock(&i915->drm.struct_mutex);
4168
4169 /* Flush idle worker to disarm irq */
4170 while (flush_delayed_work(&i915->gt.idle_work))
4171 ;
4172
4173 return 0;
4174
4175err_unlock:
4176 mutex_unlock(&i915->drm.struct_mutex);
4177 return err;
4178}
4179
4180static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004181i915_ring_missed_irq_get(void *data, u64 *val)
4182{
David Weinehall36cdd012016-08-22 13:59:31 +03004183 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004184
4185 *val = dev_priv->gpu_error.missed_irq_rings;
4186 return 0;
4187}
4188
4189static int
4190i915_ring_missed_irq_set(void *data, u64 val)
4191{
Chris Wilson64486ae2017-03-07 15:59:08 +00004192 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004193
Chris Wilson64486ae2017-03-07 15:59:08 +00004194 return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004195}
4196
4197DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4198 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4199 "0x%08llx\n");
4200
4201static int
4202i915_ring_test_irq_get(void *data, u64 *val)
4203{
David Weinehall36cdd012016-08-22 13:59:31 +03004204 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004205
4206 *val = dev_priv->gpu_error.test_irq_rings;
4207
4208 return 0;
4209}
4210
4211static int
4212i915_ring_test_irq_set(void *data, u64 val)
4213{
Chris Wilson64486ae2017-03-07 15:59:08 +00004214 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004215
Chris Wilson64486ae2017-03-07 15:59:08 +00004216 val &= INTEL_INFO(i915)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004217 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004218
Chris Wilson64486ae2017-03-07 15:59:08 +00004219 return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004220}
4221
4222DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4223 i915_ring_test_irq_get, i915_ring_test_irq_set,
4224 "0x%08llx\n");
4225
Chris Wilsondd624af2013-01-15 12:39:35 +00004226#define DROP_UNBOUND 0x1
4227#define DROP_BOUND 0x2
4228#define DROP_RETIRE 0x4
4229#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004230#define DROP_FREED 0x10
Chris Wilson8eadc192017-03-08 14:46:22 +00004231#define DROP_SHRINK_ALL 0x20
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004232#define DROP_ALL (DROP_UNBOUND | \
4233 DROP_BOUND | \
4234 DROP_RETIRE | \
4235 DROP_ACTIVE | \
Chris Wilson8eadc192017-03-08 14:46:22 +00004236 DROP_FREED | \
4237 DROP_SHRINK_ALL)
Kees Cook647416f2013-03-10 14:10:06 -07004238static int
4239i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004240{
Kees Cook647416f2013-03-10 14:10:06 -07004241 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004242
Kees Cook647416f2013-03-10 14:10:06 -07004243 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004244}
4245
Kees Cook647416f2013-03-10 14:10:06 -07004246static int
4247i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004248{
David Weinehall36cdd012016-08-22 13:59:31 +03004249 struct drm_i915_private *dev_priv = data;
4250 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004251 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004252
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004253 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004254
4255 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4256 * on ioctls on -EAGAIN. */
4257 ret = mutex_lock_interruptible(&dev->struct_mutex);
4258 if (ret)
4259 return ret;
4260
4261 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004262 ret = i915_gem_wait_for_idle(dev_priv,
4263 I915_WAIT_INTERRUPTIBLE |
4264 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004265 if (ret)
4266 goto unlock;
4267 }
4268
4269 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004270 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004271
Daniel Vetter05df49e2017-03-12 21:53:40 +01004272 lockdep_set_current_reclaim_state(GFP_KERNEL);
Chris Wilson21ab4e72014-09-09 11:16:08 +01004273 if (val & DROP_BOUND)
4274 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004275
Chris Wilson21ab4e72014-09-09 11:16:08 +01004276 if (val & DROP_UNBOUND)
4277 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004278
Chris Wilson8eadc192017-03-08 14:46:22 +00004279 if (val & DROP_SHRINK_ALL)
4280 i915_gem_shrink_all(dev_priv);
Daniel Vetter05df49e2017-03-12 21:53:40 +01004281 lockdep_clear_current_reclaim_state();
Chris Wilson8eadc192017-03-08 14:46:22 +00004282
Chris Wilsondd624af2013-01-15 12:39:35 +00004283unlock:
4284 mutex_unlock(&dev->struct_mutex);
4285
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004286 if (val & DROP_FREED) {
4287 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004288 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004289 }
4290
Kees Cook647416f2013-03-10 14:10:06 -07004291 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004292}
4293
Kees Cook647416f2013-03-10 14:10:06 -07004294DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4295 i915_drop_caches_get, i915_drop_caches_set,
4296 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004297
Kees Cook647416f2013-03-10 14:10:06 -07004298static int
4299i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004300{
David Weinehall36cdd012016-08-22 13:59:31 +03004301 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004302
David Weinehall36cdd012016-08-22 13:59:31 +03004303 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004304 return -ENODEV;
4305
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004306 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004307 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004308}
4309
Kees Cook647416f2013-03-10 14:10:06 -07004310static int
4311i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004312{
David Weinehall36cdd012016-08-22 13:59:31 +03004313 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304314 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004315 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004316
David Weinehall36cdd012016-08-22 13:59:31 +03004317 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004318 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004319
Kees Cook647416f2013-03-10 14:10:06 -07004320 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004321
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004322 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004323 if (ret)
4324 return ret;
4325
Jesse Barnes358733e2011-07-27 11:53:01 -07004326 /*
4327 * Turbo will still be enabled, but won't go above the set value.
4328 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304329 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004330
Akash Goelbc4d91f2015-02-26 16:09:47 +05304331 hw_max = dev_priv->rps.max_freq;
4332 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004333
Ben Widawskyb39fb292014-03-19 18:31:11 -07004334 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004335 mutex_unlock(&dev_priv->rps.hw_lock);
4336 return -EINVAL;
4337 }
4338
Ben Widawskyb39fb292014-03-19 18:31:11 -07004339 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004340
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004341 if (intel_set_rps(dev_priv, val))
4342 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004343
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004344 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004345
Kees Cook647416f2013-03-10 14:10:06 -07004346 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004347}
4348
Kees Cook647416f2013-03-10 14:10:06 -07004349DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4350 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004351 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004352
Kees Cook647416f2013-03-10 14:10:06 -07004353static int
4354i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004355{
David Weinehall36cdd012016-08-22 13:59:31 +03004356 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004357
Chris Wilson62e1baa2016-07-13 09:10:36 +01004358 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004359 return -ENODEV;
4360
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004361 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004362 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004363}
4364
Kees Cook647416f2013-03-10 14:10:06 -07004365static int
4366i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004367{
David Weinehall36cdd012016-08-22 13:59:31 +03004368 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304369 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004370 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004371
Chris Wilson62e1baa2016-07-13 09:10:36 +01004372 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004373 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004374
Kees Cook647416f2013-03-10 14:10:06 -07004375 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004376
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004377 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004378 if (ret)
4379 return ret;
4380
Jesse Barnes1523c312012-05-25 12:34:54 -07004381 /*
4382 * Turbo will still be enabled, but won't go below the set value.
4383 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304384 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004385
Akash Goelbc4d91f2015-02-26 16:09:47 +05304386 hw_max = dev_priv->rps.max_freq;
4387 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004388
David Weinehall36cdd012016-08-22 13:59:31 +03004389 if (val < hw_min ||
4390 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004391 mutex_unlock(&dev_priv->rps.hw_lock);
4392 return -EINVAL;
4393 }
4394
Ben Widawskyb39fb292014-03-19 18:31:11 -07004395 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004396
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004397 if (intel_set_rps(dev_priv, val))
4398 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004399
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004400 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004401
Kees Cook647416f2013-03-10 14:10:06 -07004402 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004403}
4404
Kees Cook647416f2013-03-10 14:10:06 -07004405DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4406 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004407 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004408
Kees Cook647416f2013-03-10 14:10:06 -07004409static int
4410i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004411{
David Weinehall36cdd012016-08-22 13:59:31 +03004412 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004413 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004414
David Weinehall36cdd012016-08-22 13:59:31 +03004415 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004416 return -ENODEV;
4417
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004418 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004419
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004420 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004421
4422 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004423
Kees Cook647416f2013-03-10 14:10:06 -07004424 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004425
Kees Cook647416f2013-03-10 14:10:06 -07004426 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004427}
4428
Kees Cook647416f2013-03-10 14:10:06 -07004429static int
4430i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004431{
David Weinehall36cdd012016-08-22 13:59:31 +03004432 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004433 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004434
David Weinehall36cdd012016-08-22 13:59:31 +03004435 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004436 return -ENODEV;
4437
Kees Cook647416f2013-03-10 14:10:06 -07004438 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004439 return -EINVAL;
4440
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004441 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004442 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004443
4444 /* Update the cache sharing policy here as well */
4445 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4446 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4447 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4448 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4449
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004450 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004451 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004452}
4453
Kees Cook647416f2013-03-10 14:10:06 -07004454DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4455 i915_cache_sharing_get, i915_cache_sharing_set,
4456 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004457
David Weinehall36cdd012016-08-22 13:59:31 +03004458static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004459 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004460{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004461 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004462 int ss;
4463 u32 sig1[ss_max], sig2[ss_max];
4464
4465 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4466 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4467 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4468 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4469
4470 for (ss = 0; ss < ss_max; ss++) {
4471 unsigned int eu_cnt;
4472
4473 if (sig1[ss] & CHV_SS_PG_ENABLE)
4474 /* skip disabled subslice */
4475 continue;
4476
Imre Deakf08a0c92016-08-31 19:13:04 +03004477 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004478 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004479 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4480 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4481 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4482 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004483 sseu->eu_total += eu_cnt;
4484 sseu->eu_per_subslice = max_t(unsigned int,
4485 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004486 }
Jeff McGee5d395252015-04-03 18:13:17 -07004487}
4488
David Weinehall36cdd012016-08-22 13:59:31 +03004489static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004490 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004491{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004492 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004493 int s, ss;
4494 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4495
Jeff McGee1c046bc2015-04-03 18:13:18 -07004496 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004497 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004498 s_max = 1;
4499 ss_max = 3;
4500 }
4501
4502 for (s = 0; s < s_max; s++) {
4503 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4504 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4505 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4506 }
4507
Jeff McGee5d395252015-04-03 18:13:17 -07004508 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4509 GEN9_PGCTL_SSA_EU19_ACK |
4510 GEN9_PGCTL_SSA_EU210_ACK |
4511 GEN9_PGCTL_SSA_EU311_ACK;
4512 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4513 GEN9_PGCTL_SSB_EU19_ACK |
4514 GEN9_PGCTL_SSB_EU210_ACK |
4515 GEN9_PGCTL_SSB_EU311_ACK;
4516
4517 for (s = 0; s < s_max; s++) {
4518 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4519 /* skip disabled slice */
4520 continue;
4521
Imre Deakf08a0c92016-08-31 19:13:04 +03004522 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004523
Rodrigo Vivib976dc52017-01-23 10:32:37 -08004524 if (IS_GEN9_BC(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004525 sseu->subslice_mask =
4526 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004527
Jeff McGee5d395252015-04-03 18:13:17 -07004528 for (ss = 0; ss < ss_max; ss++) {
4529 unsigned int eu_cnt;
4530
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004531 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004532 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4533 /* skip disabled subslice */
4534 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004535
Imre Deak57ec1712016-08-31 19:13:05 +03004536 sseu->subslice_mask |= BIT(ss);
4537 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004538
Jeff McGee5d395252015-04-03 18:13:17 -07004539 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4540 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004541 sseu->eu_total += eu_cnt;
4542 sseu->eu_per_subslice = max_t(unsigned int,
4543 sseu->eu_per_subslice,
4544 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004545 }
4546 }
4547}
4548
David Weinehall36cdd012016-08-22 13:59:31 +03004549static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004550 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004551{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004552 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004553 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004554
Imre Deakf08a0c92016-08-31 19:13:04 +03004555 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004556
Imre Deakf08a0c92016-08-31 19:13:04 +03004557 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004558 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004559 sseu->eu_per_subslice =
4560 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004561 sseu->eu_total = sseu->eu_per_subslice *
4562 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004563
4564 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004565 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004566 u8 subslice_7eu =
4567 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004568
Imre Deak915490d2016-08-31 19:13:01 +03004569 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004570 }
4571 }
4572}
4573
Imre Deak615d8902016-08-31 19:13:03 +03004574static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4575 const struct sseu_dev_info *sseu)
4576{
4577 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4578 const char *type = is_available_info ? "Available" : "Enabled";
4579
Imre Deakc67ba532016-08-31 19:13:06 +03004580 seq_printf(m, " %s Slice Mask: %04x\n", type,
4581 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004582 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004583 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004584 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004585 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004586 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4587 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004588 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004589 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004590 seq_printf(m, " %s EU Total: %u\n", type,
4591 sseu->eu_total);
4592 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4593 sseu->eu_per_subslice);
4594
4595 if (!is_available_info)
4596 return;
4597
4598 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4599 if (HAS_POOLED_EU(dev_priv))
4600 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4601
4602 seq_printf(m, " Has Slice Power Gating: %s\n",
4603 yesno(sseu->has_slice_pg));
4604 seq_printf(m, " Has Subslice Power Gating: %s\n",
4605 yesno(sseu->has_subslice_pg));
4606 seq_printf(m, " Has EU Power Gating: %s\n",
4607 yesno(sseu->has_eu_pg));
4608}
4609
Jeff McGee38732182015-02-13 10:27:54 -06004610static int i915_sseu_status(struct seq_file *m, void *unused)
4611{
David Weinehall36cdd012016-08-22 13:59:31 +03004612 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004613 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004614
David Weinehall36cdd012016-08-22 13:59:31 +03004615 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004616 return -ENODEV;
4617
4618 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004619 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004620
Jeff McGee7f992ab2015-02-13 10:27:55 -06004621 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004622 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004623
4624 intel_runtime_pm_get(dev_priv);
4625
David Weinehall36cdd012016-08-22 13:59:31 +03004626 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004627 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004628 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004629 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004630 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004631 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004632 }
David Weinehall238010e2016-08-01 17:33:27 +03004633
4634 intel_runtime_pm_put(dev_priv);
4635
Imre Deak615d8902016-08-31 19:13:03 +03004636 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004637
Jeff McGee38732182015-02-13 10:27:54 -06004638 return 0;
4639}
4640
Ben Widawsky6d794d42011-04-25 11:25:56 -07004641static int i915_forcewake_open(struct inode *inode, struct file *file)
4642{
David Weinehall36cdd012016-08-22 13:59:31 +03004643 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004644
David Weinehall36cdd012016-08-22 13:59:31 +03004645 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004646 return 0;
4647
Chris Wilson6daccb02015-01-16 11:34:35 +02004648 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004649 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004650
4651 return 0;
4652}
4653
Ben Widawskyc43b5632012-04-16 14:07:40 -07004654static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004655{
David Weinehall36cdd012016-08-22 13:59:31 +03004656 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004657
David Weinehall36cdd012016-08-22 13:59:31 +03004658 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004659 return 0;
4660
Mika Kuoppala59bad942015-01-16 11:34:40 +02004661 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004662 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004663
4664 return 0;
4665}
4666
4667static const struct file_operations i915_forcewake_fops = {
4668 .owner = THIS_MODULE,
4669 .open = i915_forcewake_open,
4670 .release = i915_forcewake_release,
4671};
4672
Lyude317eaa92017-02-03 21:18:25 -05004673static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4674{
4675 struct drm_i915_private *dev_priv = m->private;
4676 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4677
4678 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4679 seq_printf(m, "Detected: %s\n",
4680 yesno(delayed_work_pending(&hotplug->reenable_work)));
4681
4682 return 0;
4683}
4684
4685static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4686 const char __user *ubuf, size_t len,
4687 loff_t *offp)
4688{
4689 struct seq_file *m = file->private_data;
4690 struct drm_i915_private *dev_priv = m->private;
4691 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4692 unsigned int new_threshold;
4693 int i;
4694 char *newline;
4695 char tmp[16];
4696
4697 if (len >= sizeof(tmp))
4698 return -EINVAL;
4699
4700 if (copy_from_user(tmp, ubuf, len))
4701 return -EFAULT;
4702
4703 tmp[len] = '\0';
4704
4705 /* Strip newline, if any */
4706 newline = strchr(tmp, '\n');
4707 if (newline)
4708 *newline = '\0';
4709
4710 if (strcmp(tmp, "reset") == 0)
4711 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4712 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4713 return -EINVAL;
4714
4715 if (new_threshold > 0)
4716 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4717 new_threshold);
4718 else
4719 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4720
4721 spin_lock_irq(&dev_priv->irq_lock);
4722 hotplug->hpd_storm_threshold = new_threshold;
4723 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4724 for_each_hpd_pin(i)
4725 hotplug->stats[i].count = 0;
4726 spin_unlock_irq(&dev_priv->irq_lock);
4727
4728 /* Re-enable hpd immediately if we were in an irq storm */
4729 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4730
4731 return len;
4732}
4733
4734static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4735{
4736 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4737}
4738
4739static const struct file_operations i915_hpd_storm_ctl_fops = {
4740 .owner = THIS_MODULE,
4741 .open = i915_hpd_storm_ctl_open,
4742 .read = seq_read,
4743 .llseek = seq_lseek,
4744 .release = single_release,
4745 .write = i915_hpd_storm_ctl_write
4746};
4747
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004748static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004749 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004750 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004751 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01004752 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004753 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004754 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004755 {"i915_gem_request", i915_gem_request_info, 0},
4756 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004757 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004758 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004759 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004760 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004761 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004762 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004763 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304764 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004765 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004766 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004767 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004768 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004769 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004770 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004771 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004772 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004773 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004774 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004775 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004776 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004777 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004778 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004779 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004780 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004781 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004782 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004783 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004784 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004785 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004786 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004787 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004788 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004789 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004790 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004791 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004792 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004793 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004794 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004795 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304796 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004797 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004798};
Ben Gamari27c202a2009-07-01 22:26:52 -04004799#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004800
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004801static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004802 const char *name;
4803 const struct file_operations *fops;
4804} i915_debugfs_files[] = {
4805 {"i915_wedged", &i915_wedged_fops},
4806 {"i915_max_freq", &i915_max_freq_fops},
4807 {"i915_min_freq", &i915_min_freq_fops},
4808 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004809 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4810 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004811 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004812#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004813 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004814 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004815#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004816 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004817 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004818 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4819 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4820 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004821 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004822 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4823 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304824 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004825 {"i915_guc_log_control", &i915_guc_log_control_fops},
4826 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004827};
4828
Chris Wilson1dac8912016-06-24 14:00:17 +01004829int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004830{
Chris Wilson91c8a322016-07-05 10:40:23 +01004831 struct drm_minor *minor = dev_priv->drm.primary;
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004832 struct dentry *ent;
Daniel Vetter34b96742013-07-04 20:49:44 +02004833 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004834
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004835 ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
4836 minor->debugfs_root, to_i915(minor->dev),
4837 &i915_forcewake_fops);
4838 if (!ent)
4839 return -ENOMEM;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004840
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004841 ret = intel_pipe_crc_create(minor);
4842 if (ret)
4843 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004844
Daniel Vetter34b96742013-07-04 20:49:44 +02004845 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004846 ent = debugfs_create_file(i915_debugfs_files[i].name,
4847 S_IRUGO | S_IWUSR,
4848 minor->debugfs_root,
4849 to_i915(minor->dev),
Daniel Vetter34b96742013-07-04 20:49:44 +02004850 i915_debugfs_files[i].fops);
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004851 if (!ent)
4852 return -ENOMEM;
Daniel Vetter34b96742013-07-04 20:49:44 +02004853 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004854
Ben Gamari27c202a2009-07-01 22:26:52 -04004855 return drm_debugfs_create_files(i915_debugfs_list,
4856 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004857 minor->debugfs_root, minor);
4858}
4859
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004860struct dpcd_block {
4861 /* DPCD dump start address. */
4862 unsigned int offset;
4863 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4864 unsigned int end;
4865 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4866 size_t size;
4867 /* Only valid for eDP. */
4868 bool edp;
4869};
4870
4871static const struct dpcd_block i915_dpcd_debug[] = {
4872 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4873 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4874 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4875 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4876 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4877 { .offset = DP_SET_POWER },
4878 { .offset = DP_EDP_DPCD_REV },
4879 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4880 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4881 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4882};
4883
4884static int i915_dpcd_show(struct seq_file *m, void *data)
4885{
4886 struct drm_connector *connector = m->private;
4887 struct intel_dp *intel_dp =
4888 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4889 uint8_t buf[16];
4890 ssize_t err;
4891 int i;
4892
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004893 if (connector->status != connector_status_connected)
4894 return -ENODEV;
4895
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004896 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4897 const struct dpcd_block *b = &i915_dpcd_debug[i];
4898 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4899
4900 if (b->edp &&
4901 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4902 continue;
4903
4904 /* low tech for now */
4905 if (WARN_ON(size > sizeof(buf)))
4906 continue;
4907
4908 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4909 if (err <= 0) {
4910 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4911 size, b->offset, err);
4912 continue;
4913 }
4914
4915 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004916 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004917
4918 return 0;
4919}
4920
4921static int i915_dpcd_open(struct inode *inode, struct file *file)
4922{
4923 return single_open(file, i915_dpcd_show, inode->i_private);
4924}
4925
4926static const struct file_operations i915_dpcd_fops = {
4927 .owner = THIS_MODULE,
4928 .open = i915_dpcd_open,
4929 .read = seq_read,
4930 .llseek = seq_lseek,
4931 .release = single_release,
4932};
4933
David Weinehallecbd6782016-08-23 12:23:56 +03004934static int i915_panel_show(struct seq_file *m, void *data)
4935{
4936 struct drm_connector *connector = m->private;
4937 struct intel_dp *intel_dp =
4938 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4939
4940 if (connector->status != connector_status_connected)
4941 return -ENODEV;
4942
4943 seq_printf(m, "Panel power up delay: %d\n",
4944 intel_dp->panel_power_up_delay);
4945 seq_printf(m, "Panel power down delay: %d\n",
4946 intel_dp->panel_power_down_delay);
4947 seq_printf(m, "Backlight on delay: %d\n",
4948 intel_dp->backlight_on_delay);
4949 seq_printf(m, "Backlight off delay: %d\n",
4950 intel_dp->backlight_off_delay);
4951
4952 return 0;
4953}
4954
4955static int i915_panel_open(struct inode *inode, struct file *file)
4956{
4957 return single_open(file, i915_panel_show, inode->i_private);
4958}
4959
4960static const struct file_operations i915_panel_fops = {
4961 .owner = THIS_MODULE,
4962 .open = i915_panel_open,
4963 .read = seq_read,
4964 .llseek = seq_lseek,
4965 .release = single_release,
4966};
4967
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004968/**
4969 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4970 * @connector: pointer to a registered drm_connector
4971 *
4972 * Cleanup will be done by drm_connector_unregister() through a call to
4973 * drm_debugfs_connector_remove().
4974 *
4975 * Returns 0 on success, negative error codes on error.
4976 */
4977int i915_debugfs_connector_add(struct drm_connector *connector)
4978{
4979 struct dentry *root = connector->debugfs_entry;
4980
4981 /* The connector must have been registered beforehands. */
4982 if (!root)
4983 return -ENODEV;
4984
4985 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4986 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03004987 debugfs_create_file("i915_dpcd", S_IRUGO, root,
4988 connector, &i915_dpcd_fops);
4989
4990 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4991 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
4992 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004993
4994 return 0;
4995}