blob: 2ef75c1a611957c6188402be8422a6e3c1ca4489 [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 Wilsone637d2c2017-03-16 13:19:57 +000030#include <linux/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 Wilsone637d2c2017-03-16 13:19:57 +0000207static int obj_rank_by_stolen(const void *A, const void *B)
Chris Wilson6d2b88852013-08-07 18:30:54 +0100208{
Chris Wilsone637d2c2017-03-16 13:19:57 +0000209 const struct drm_i915_gem_object *a =
210 *(const struct drm_i915_gem_object **)A;
211 const struct drm_i915_gem_object *b =
212 *(const struct drm_i915_gem_object **)B;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100213
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200214 if (a->stolen->start < b->stolen->start)
215 return -1;
216 if (a->stolen->start > b->stolen->start)
217 return 1;
218 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100219}
220
221static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
222{
David Weinehall36cdd012016-08-22 13:59:31 +0300223 struct drm_i915_private *dev_priv = node_to_i915(m->private);
224 struct drm_device *dev = &dev_priv->drm;
Chris Wilsone637d2c2017-03-16 13:19:57 +0000225 struct drm_i915_gem_object **objects;
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 Wilsone637d2c2017-03-16 13:19:57 +0000228 unsigned long total, count, n;
229 int ret;
230
231 total = READ_ONCE(dev_priv->mm.object_count);
Michal Hocko20981052017-05-17 14:23:12 +0200232 objects = kvmalloc_array(total, sizeof(*objects), GFP_KERNEL);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000233 if (!objects)
234 return -ENOMEM;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100235
236 ret = mutex_lock_interruptible(&dev->struct_mutex);
237 if (ret)
Chris Wilsone637d2c2017-03-16 13:19:57 +0000238 goto out;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100239
240 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200241 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000242 if (count == total)
243 break;
244
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245 if (obj->stolen == NULL)
246 continue;
247
Chris Wilsone637d2c2017-03-16 13:19:57 +0000248 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100249 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100250 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000251
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252 }
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200253 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000254 if (count == total)
255 break;
256
Chris Wilson6d2b88852013-08-07 18:30:54 +0100257 if (obj->stolen == NULL)
258 continue;
259
Chris Wilsone637d2c2017-03-16 13:19:57 +0000260 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261 total_obj_size += obj->base.size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262 }
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263
Chris Wilsone637d2c2017-03-16 13:19:57 +0000264 sort(objects, count, sizeof(*objects), obj_rank_by_stolen, NULL);
265
266 seq_puts(m, "Stolen:\n");
267 for (n = 0; n < count; n++) {
268 seq_puts(m, " ");
269 describe_obj(m, objects[n]);
270 seq_putc(m, '\n');
271 }
272 seq_printf(m, "Total %lu objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100273 count, total_obj_size, total_gtt_size);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000274
275 mutex_unlock(&dev->struct_mutex);
276out:
Michal Hocko20981052017-05-17 14:23:12 +0200277 kvfree(objects);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000278 return ret;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100279}
280
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100281struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000282 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300283 unsigned long count;
284 u64 total, unbound;
285 u64 global, shared;
286 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100287};
288
289static int per_file_stats(int id, void *ptr, void *data)
290{
291 struct drm_i915_gem_object *obj = ptr;
292 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000293 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100294
Chris Wilson0caf81b2017-06-17 12:57:44 +0100295 lockdep_assert_held(&obj->base.dev->struct_mutex);
296
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100297 stats->count++;
298 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100299 if (!obj->bind_count)
300 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000301 if (obj->base.name || obj->base.dma_buf)
302 stats->shared += obj->base.size;
303
Chris Wilson894eeec2016-08-04 07:52:20 +0100304 list_for_each_entry(vma, &obj->vma_list, obj_link) {
305 if (!drm_mm_node_allocated(&vma->node))
306 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000307
Chris Wilson3272db52016-08-04 16:32:32 +0100308 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100309 stats->global += vma->node.size;
310 } else {
311 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000312
Chris Wilson2bfa9962016-08-04 07:52:25 +0100313 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000314 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000315 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100316
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100317 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100318 stats->active += vma->node.size;
319 else
320 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100321 }
322
323 return 0;
324}
325
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100326#define print_file_stats(m, name, stats) do { \
327 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300328 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 +0100329 name, \
330 stats.count, \
331 stats.total, \
332 stats.active, \
333 stats.inactive, \
334 stats.global, \
335 stats.shared, \
336 stats.unbound); \
337} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800338
339static void print_batch_pool_stats(struct seq_file *m,
340 struct drm_i915_private *dev_priv)
341{
342 struct drm_i915_gem_object *obj;
343 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000344 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530345 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000346 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800347
348 memset(&stats, 0, sizeof(stats));
349
Akash Goel3b3f1652016-10-13 22:44:48 +0530350 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000351 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100352 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000353 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100354 batch_pool_link)
355 per_file_stats(0, obj, &stats);
356 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100357 }
Brad Volkin493018d2014-12-11 12:13:08 -0800358
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100359 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800360}
361
Chris Wilson15da9562016-05-24 14:53:43 +0100362static int per_file_ctx_stats(int id, void *ptr, void *data)
363{
364 struct i915_gem_context *ctx = ptr;
365 int n;
366
367 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
368 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100369 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100370 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100371 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100372 }
373
374 return 0;
375}
376
377static void print_context_stats(struct seq_file *m,
378 struct drm_i915_private *dev_priv)
379{
David Weinehall36cdd012016-08-22 13:59:31 +0300380 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100381 struct file_stats stats;
382 struct drm_file *file;
383
384 memset(&stats, 0, sizeof(stats));
385
David Weinehall36cdd012016-08-22 13:59:31 +0300386 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100387 if (dev_priv->kernel_context)
388 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
389
David Weinehall36cdd012016-08-22 13:59:31 +0300390 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100391 struct drm_i915_file_private *fpriv = file->driver_priv;
392 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
393 }
David Weinehall36cdd012016-08-22 13:59:31 +0300394 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100395
396 print_file_stats(m, "[k]contexts", stats);
397}
398
David Weinehall36cdd012016-08-22 13:59:31 +0300399static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100400{
David Weinehall36cdd012016-08-22 13:59:31 +0300401 struct drm_i915_private *dev_priv = node_to_i915(m->private);
402 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300403 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100404 u32 count, mapped_count, purgeable_count, dpy_count;
405 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000406 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100407 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100408 int ret;
409
410 ret = mutex_lock_interruptible(&dev->struct_mutex);
411 if (ret)
412 return ret;
413
Chris Wilson3ef7f222016-10-18 13:02:48 +0100414 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000415 dev_priv->mm.object_count,
416 dev_priv->mm.object_memory);
417
Chris Wilson1544c422016-08-15 13:18:16 +0100418 size = count = 0;
419 mapped_size = mapped_count = 0;
420 purgeable_size = purgeable_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200421 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100422 size += obj->base.size;
423 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200424
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100425 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200426 purgeable_size += obj->base.size;
427 ++purgeable_count;
428 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100429
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100430 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100431 mapped_count++;
432 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100433 }
Chris Wilson6299f992010-11-24 12:23:44 +0000434 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100435 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
436
437 size = count = dpy_size = dpy_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200438 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100439 size += obj->base.size;
440 ++count;
441
442 if (obj->pin_display) {
443 dpy_size += obj->base.size;
444 ++dpy_count;
445 }
446
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100447 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100448 purgeable_size += obj->base.size;
449 ++purgeable_count;
450 }
451
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100452 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100453 mapped_count++;
454 mapped_size += obj->base.size;
455 }
456 }
457 seq_printf(m, "%u bound objects, %llu bytes\n",
458 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300459 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200460 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100461 seq_printf(m, "%u mapped objects, %llu bytes\n",
462 mapped_count, mapped_size);
463 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
464 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000465
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300466 seq_printf(m, "%llu [%llu] gtt total\n",
Chris Wilson381b9432017-02-15 08:43:54 +0000467 ggtt->base.total, ggtt->mappable_end);
Chris Wilson73aa8082010-09-30 11:46:12 +0100468
Damien Lespiau267f0c92013-06-24 22:59:48 +0100469 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800470 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200471 mutex_unlock(&dev->struct_mutex);
472
473 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100474 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100475 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
476 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100477 struct drm_i915_file_private *file_priv = file->driver_priv;
478 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900479 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100480
Chris Wilson0caf81b2017-06-17 12:57:44 +0100481 mutex_lock(&dev->struct_mutex);
482
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100483 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000484 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100485 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100486 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100487 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900488 /*
489 * Although we have a valid reference on file->pid, that does
490 * not guarantee that the task_struct who called get_pid() is
491 * still alive (e.g. get_pid(current) => fork() => exit()).
492 * Therefore, we need to protect this ->comm access using RCU.
493 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100494 request = list_first_entry_or_null(&file_priv->mm.request_list,
495 struct drm_i915_gem_request,
Chris Wilsonc8659ef2017-03-02 12:25:25 +0000496 client_link);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900497 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100498 task = pid_task(request && request->ctx->pid ?
499 request->ctx->pid : file->pid,
500 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800501 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900502 rcu_read_unlock();
Chris Wilson0caf81b2017-06-17 12:57:44 +0100503
Chris Wilsonc84455b2016-08-15 10:49:08 +0100504 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100505 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200506 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100507
508 return 0;
509}
510
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100511static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000512{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100513 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300514 struct drm_i915_private *dev_priv = node_to_i915(node);
515 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100516 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000517 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300518 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000519 int count, ret;
520
521 ret = mutex_lock_interruptible(&dev->struct_mutex);
522 if (ret)
523 return ret;
524
525 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200526 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6da84822016-08-15 10:48:44 +0100527 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100528 continue;
529
Damien Lespiau267f0c92013-06-24 22:59:48 +0100530 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000531 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100532 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000533 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100534 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000535 count++;
536 }
537
538 mutex_unlock(&dev->struct_mutex);
539
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300540 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000541 count, total_obj_size, total_gtt_size);
542
543 return 0;
544}
545
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100546static int i915_gem_pageflip_info(struct seq_file *m, void *data)
547{
David Weinehall36cdd012016-08-22 13:59:31 +0300548 struct drm_i915_private *dev_priv = node_to_i915(m->private);
549 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100550 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200551 int ret;
552
553 ret = mutex_lock_interruptible(&dev->struct_mutex);
554 if (ret)
555 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100556
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100557 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800558 const char pipe = pipe_name(crtc->pipe);
559 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200560 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100561
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200562 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200563 work = crtc->flip_work;
564 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800565 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100566 pipe, plane);
567 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200568 u32 pending;
569 u32 addr;
570
571 pending = atomic_read(&work->pending);
572 if (pending) {
573 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
574 pipe, plane);
575 } else {
576 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
577 pipe, plane);
578 }
579 if (work->flip_queued_req) {
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200580 struct intel_engine_cs *engine = work->flip_queued_req->engine;
Daniel Vetter5a21b662016-05-24 17:13:53 +0200581
Chris Wilson312c3c42016-11-24 14:47:50 +0000582 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 +0200583 engine->name,
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200584 work->flip_queued_req->global_seqno,
Chris Wilson312c3c42016-11-24 14:47:50 +0000585 intel_engine_last_submit(engine),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100586 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100587 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200588 } else
589 seq_printf(m, "Flip not associated with any ring\n");
590 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
591 work->flip_queued_vblank,
592 work->flip_ready_vblank,
593 intel_crtc_get_vblank_counter(crtc));
594 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
595
David Weinehall36cdd012016-08-22 13:59:31 +0300596 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200597 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
598 else
599 addr = I915_READ(DSPADDR(crtc->plane));
600 seq_printf(m, "Current scanout address 0x%08x\n", addr);
601
602 if (work->pending_flip_obj) {
603 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
604 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100605 }
606 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200607 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100608 }
609
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200610 mutex_unlock(&dev->struct_mutex);
611
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100612 return 0;
613}
614
Brad Volkin493018d2014-12-11 12:13:08 -0800615static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
616{
David Weinehall36cdd012016-08-22 13:59:31 +0300617 struct drm_i915_private *dev_priv = node_to_i915(m->private);
618 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800619 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000620 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530621 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100622 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000623 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800624
625 ret = mutex_lock_interruptible(&dev->struct_mutex);
626 if (ret)
627 return ret;
628
Akash Goel3b3f1652016-10-13 22:44:48 +0530629 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000630 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100631 int count;
632
633 count = 0;
634 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000635 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100636 batch_pool_link)
637 count++;
638 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000639 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100640
641 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000642 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100643 batch_pool_link) {
644 seq_puts(m, " ");
645 describe_obj(m, obj);
646 seq_putc(m, '\n');
647 }
648
649 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100650 }
Brad Volkin493018d2014-12-11 12:13:08 -0800651 }
652
Chris Wilson8d9d5742015-04-07 16:20:38 +0100653 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800654
655 mutex_unlock(&dev->struct_mutex);
656
657 return 0;
658}
659
Chris Wilson1b365952016-10-04 21:11:31 +0100660static void print_request(struct seq_file *m,
661 struct drm_i915_gem_request *rq,
662 const char *prefix)
663{
Chris Wilson20311bd2016-11-14 20:41:03 +0000664 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100665 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000666 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100667 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100668 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100669}
670
Ben Gamari20172632009-02-17 20:08:50 -0500671static int i915_gem_request_info(struct seq_file *m, void *data)
672{
David Weinehall36cdd012016-08-22 13:59:31 +0300673 struct drm_i915_private *dev_priv = node_to_i915(m->private);
674 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200675 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530676 struct intel_engine_cs *engine;
677 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000678 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100679
680 ret = mutex_lock_interruptible(&dev->struct_mutex);
681 if (ret)
682 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500683
Chris Wilson2d1070b2015-04-01 10:36:56 +0100684 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530685 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100686 int count;
687
688 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100689 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100690 count++;
691 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100692 continue;
693
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000694 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100695 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100696 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100697
698 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500699 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100700 mutex_unlock(&dev->struct_mutex);
701
Chris Wilson2d1070b2015-04-01 10:36:56 +0100702 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100703 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100704
Ben Gamari20172632009-02-17 20:08:50 -0500705 return 0;
706}
707
Chris Wilsonb2223492010-10-27 15:27:33 +0100708static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000709 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100710{
Chris Wilson688e6c72016-07-01 17:23:15 +0100711 struct intel_breadcrumbs *b = &engine->breadcrumbs;
712 struct rb_node *rb;
713
Chris Wilson12471ba2016-04-09 10:57:55 +0100714 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100715 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100716
Chris Wilson61d3dc72017-03-03 19:08:24 +0000717 spin_lock_irq(&b->rb_lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100718 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +0800719 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson688e6c72016-07-01 17:23:15 +0100720
721 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
722 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
723 }
Chris Wilson61d3dc72017-03-03 19:08:24 +0000724 spin_unlock_irq(&b->rb_lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100725}
726
Ben Gamari20172632009-02-17 20:08:50 -0500727static int i915_gem_seqno_info(struct seq_file *m, void *data)
728{
David Weinehall36cdd012016-08-22 13:59:31 +0300729 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000730 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530731 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500732
Akash Goel3b3f1652016-10-13 22:44:48 +0530733 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000734 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100735
Ben Gamari20172632009-02-17 20:08:50 -0500736 return 0;
737}
738
739
740static int i915_interrupt_info(struct seq_file *m, void *data)
741{
David Weinehall36cdd012016-08-22 13:59:31 +0300742 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000743 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530744 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100745 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100746
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200747 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500748
David Weinehall36cdd012016-08-22 13:59:31 +0300749 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300750 seq_printf(m, "Master Interrupt Control:\t%08x\n",
751 I915_READ(GEN8_MASTER_IRQ));
752
753 seq_printf(m, "Display IER:\t%08x\n",
754 I915_READ(VLV_IER));
755 seq_printf(m, "Display IIR:\t%08x\n",
756 I915_READ(VLV_IIR));
757 seq_printf(m, "Display IIR_RW:\t%08x\n",
758 I915_READ(VLV_IIR_RW));
759 seq_printf(m, "Display IMR:\t%08x\n",
760 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100761 for_each_pipe(dev_priv, pipe) {
762 enum intel_display_power_domain power_domain;
763
764 power_domain = POWER_DOMAIN_PIPE(pipe);
765 if (!intel_display_power_get_if_enabled(dev_priv,
766 power_domain)) {
767 seq_printf(m, "Pipe %c power disabled\n",
768 pipe_name(pipe));
769 continue;
770 }
771
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300772 seq_printf(m, "Pipe %c stat:\t%08x\n",
773 pipe_name(pipe),
774 I915_READ(PIPESTAT(pipe)));
775
Chris Wilson9c870d02016-10-24 13:42:15 +0100776 intel_display_power_put(dev_priv, power_domain);
777 }
778
779 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300780 seq_printf(m, "Port hotplug:\t%08x\n",
781 I915_READ(PORT_HOTPLUG_EN));
782 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
783 I915_READ(VLV_DPFLIPSTAT));
784 seq_printf(m, "DPINVGTT:\t%08x\n",
785 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100786 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300787
788 for (i = 0; i < 4; i++) {
789 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
790 i, I915_READ(GEN8_GT_IMR(i)));
791 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
792 i, I915_READ(GEN8_GT_IIR(i)));
793 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
794 i, I915_READ(GEN8_GT_IER(i)));
795 }
796
797 seq_printf(m, "PCU interrupt mask:\t%08x\n",
798 I915_READ(GEN8_PCU_IMR));
799 seq_printf(m, "PCU interrupt identity:\t%08x\n",
800 I915_READ(GEN8_PCU_IIR));
801 seq_printf(m, "PCU interrupt enable:\t%08x\n",
802 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300803 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700804 seq_printf(m, "Master Interrupt Control:\t%08x\n",
805 I915_READ(GEN8_MASTER_IRQ));
806
807 for (i = 0; i < 4; i++) {
808 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
809 i, I915_READ(GEN8_GT_IMR(i)));
810 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
811 i, I915_READ(GEN8_GT_IIR(i)));
812 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
813 i, I915_READ(GEN8_GT_IER(i)));
814 }
815
Damien Lespiau055e3932014-08-18 13:49:10 +0100816 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200817 enum intel_display_power_domain power_domain;
818
819 power_domain = POWER_DOMAIN_PIPE(pipe);
820 if (!intel_display_power_get_if_enabled(dev_priv,
821 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300822 seq_printf(m, "Pipe %c power disabled\n",
823 pipe_name(pipe));
824 continue;
825 }
Ben Widawskya123f152013-11-02 21:07:10 -0700826 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000827 pipe_name(pipe),
828 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700829 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000830 pipe_name(pipe),
831 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700832 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000833 pipe_name(pipe),
834 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200835
836 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700837 }
838
839 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
840 I915_READ(GEN8_DE_PORT_IMR));
841 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
842 I915_READ(GEN8_DE_PORT_IIR));
843 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
844 I915_READ(GEN8_DE_PORT_IER));
845
846 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
847 I915_READ(GEN8_DE_MISC_IMR));
848 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
849 I915_READ(GEN8_DE_MISC_IIR));
850 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
851 I915_READ(GEN8_DE_MISC_IER));
852
853 seq_printf(m, "PCU interrupt mask:\t%08x\n",
854 I915_READ(GEN8_PCU_IMR));
855 seq_printf(m, "PCU interrupt identity:\t%08x\n",
856 I915_READ(GEN8_PCU_IIR));
857 seq_printf(m, "PCU interrupt enable:\t%08x\n",
858 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300859 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700860 seq_printf(m, "Display IER:\t%08x\n",
861 I915_READ(VLV_IER));
862 seq_printf(m, "Display IIR:\t%08x\n",
863 I915_READ(VLV_IIR));
864 seq_printf(m, "Display IIR_RW:\t%08x\n",
865 I915_READ(VLV_IIR_RW));
866 seq_printf(m, "Display IMR:\t%08x\n",
867 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000868 for_each_pipe(dev_priv, pipe) {
869 enum intel_display_power_domain power_domain;
870
871 power_domain = POWER_DOMAIN_PIPE(pipe);
872 if (!intel_display_power_get_if_enabled(dev_priv,
873 power_domain)) {
874 seq_printf(m, "Pipe %c power disabled\n",
875 pipe_name(pipe));
876 continue;
877 }
878
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700879 seq_printf(m, "Pipe %c stat:\t%08x\n",
880 pipe_name(pipe),
881 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000882 intel_display_power_put(dev_priv, power_domain);
883 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700884
885 seq_printf(m, "Master IER:\t%08x\n",
886 I915_READ(VLV_MASTER_IER));
887
888 seq_printf(m, "Render IER:\t%08x\n",
889 I915_READ(GTIER));
890 seq_printf(m, "Render IIR:\t%08x\n",
891 I915_READ(GTIIR));
892 seq_printf(m, "Render IMR:\t%08x\n",
893 I915_READ(GTIMR));
894
895 seq_printf(m, "PM IER:\t\t%08x\n",
896 I915_READ(GEN6_PMIER));
897 seq_printf(m, "PM IIR:\t\t%08x\n",
898 I915_READ(GEN6_PMIIR));
899 seq_printf(m, "PM IMR:\t\t%08x\n",
900 I915_READ(GEN6_PMIMR));
901
902 seq_printf(m, "Port hotplug:\t%08x\n",
903 I915_READ(PORT_HOTPLUG_EN));
904 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
905 I915_READ(VLV_DPFLIPSTAT));
906 seq_printf(m, "DPINVGTT:\t%08x\n",
907 I915_READ(DPINVGTT));
908
David Weinehall36cdd012016-08-22 13:59:31 +0300909 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800910 seq_printf(m, "Interrupt enable: %08x\n",
911 I915_READ(IER));
912 seq_printf(m, "Interrupt identity: %08x\n",
913 I915_READ(IIR));
914 seq_printf(m, "Interrupt mask: %08x\n",
915 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100916 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800917 seq_printf(m, "Pipe %c stat: %08x\n",
918 pipe_name(pipe),
919 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800920 } else {
921 seq_printf(m, "North Display Interrupt enable: %08x\n",
922 I915_READ(DEIER));
923 seq_printf(m, "North Display Interrupt identity: %08x\n",
924 I915_READ(DEIIR));
925 seq_printf(m, "North Display Interrupt mask: %08x\n",
926 I915_READ(DEIMR));
927 seq_printf(m, "South Display Interrupt enable: %08x\n",
928 I915_READ(SDEIER));
929 seq_printf(m, "South Display Interrupt identity: %08x\n",
930 I915_READ(SDEIIR));
931 seq_printf(m, "South Display Interrupt mask: %08x\n",
932 I915_READ(SDEIMR));
933 seq_printf(m, "Graphics Interrupt enable: %08x\n",
934 I915_READ(GTIER));
935 seq_printf(m, "Graphics Interrupt identity: %08x\n",
936 I915_READ(GTIIR));
937 seq_printf(m, "Graphics Interrupt mask: %08x\n",
938 I915_READ(GTIMR));
939 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530940 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300941 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100942 seq_printf(m,
943 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000944 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000945 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000946 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000947 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200948 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100949
Ben Gamari20172632009-02-17 20:08:50 -0500950 return 0;
951}
952
Chris Wilsona6172a82009-02-11 14:26:38 +0000953static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
954{
David Weinehall36cdd012016-08-22 13:59:31 +0300955 struct drm_i915_private *dev_priv = node_to_i915(m->private);
956 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100957 int i, ret;
958
959 ret = mutex_lock_interruptible(&dev->struct_mutex);
960 if (ret)
961 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000962
Chris Wilsona6172a82009-02-11 14:26:38 +0000963 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
964 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100965 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000966
Chris Wilson6c085a72012-08-20 11:40:46 +0200967 seq_printf(m, "Fence %d, pin count = %d, object = ",
968 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100969 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100970 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100971 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100972 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100973 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000974 }
975
Chris Wilson05394f32010-11-08 19:18:58 +0000976 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000977 return 0;
978}
979
Chris Wilson98a2f412016-10-12 10:05:18 +0100980#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000981static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
982 size_t count, loff_t *pos)
983{
984 struct i915_gpu_state *error = file->private_data;
985 struct drm_i915_error_state_buf str;
986 ssize_t ret;
987 loff_t tmp;
988
989 if (!error)
990 return 0;
991
992 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
993 if (ret)
994 return ret;
995
996 ret = i915_error_state_to_str(&str, error);
997 if (ret)
998 goto out;
999
1000 tmp = 0;
1001 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
1002 if (ret < 0)
1003 goto out;
1004
1005 *pos = str.start + ret;
1006out:
1007 i915_error_state_buf_release(&str);
1008 return ret;
1009}
1010
1011static int gpu_state_release(struct inode *inode, struct file *file)
1012{
1013 i915_gpu_state_put(file->private_data);
1014 return 0;
1015}
1016
1017static int i915_gpu_info_open(struct inode *inode, struct file *file)
1018{
Chris Wilson090e5fe2017-03-28 14:14:07 +01001019 struct drm_i915_private *i915 = inode->i_private;
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001020 struct i915_gpu_state *gpu;
1021
Chris Wilson090e5fe2017-03-28 14:14:07 +01001022 intel_runtime_pm_get(i915);
1023 gpu = i915_capture_gpu_state(i915);
1024 intel_runtime_pm_put(i915);
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001025 if (!gpu)
1026 return -ENOMEM;
1027
1028 file->private_data = gpu;
1029 return 0;
1030}
1031
1032static const struct file_operations i915_gpu_info_fops = {
1033 .owner = THIS_MODULE,
1034 .open = i915_gpu_info_open,
1035 .read = gpu_state_read,
1036 .llseek = default_llseek,
1037 .release = gpu_state_release,
1038};
Chris Wilson98a2f412016-10-12 10:05:18 +01001039
Daniel Vetterd5442302012-04-27 15:17:40 +02001040static ssize_t
1041i915_error_state_write(struct file *filp,
1042 const char __user *ubuf,
1043 size_t cnt,
1044 loff_t *ppos)
1045{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001046 struct i915_gpu_state *error = filp->private_data;
1047
1048 if (!error)
1049 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001050
1051 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001052 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +02001053
1054 return cnt;
1055}
1056
1057static int i915_error_state_open(struct inode *inode, struct file *file)
1058{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001059 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001060 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001061}
1062
Daniel Vetterd5442302012-04-27 15:17:40 +02001063static const struct file_operations i915_error_state_fops = {
1064 .owner = THIS_MODULE,
1065 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001066 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001067 .write = i915_error_state_write,
1068 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001069 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +02001070};
Chris Wilson98a2f412016-10-12 10:05:18 +01001071#endif
1072
Kees Cook647416f2013-03-10 14:10:06 -07001073static int
Kees Cook647416f2013-03-10 14:10:06 -07001074i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001075{
David Weinehall36cdd012016-08-22 13:59:31 +03001076 struct drm_i915_private *dev_priv = data;
1077 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001078 int ret;
1079
Mika Kuoppala40633212012-12-04 15:12:00 +02001080 ret = mutex_lock_interruptible(&dev->struct_mutex);
1081 if (ret)
1082 return ret;
1083
Chris Wilson73cb9702016-10-28 13:58:46 +01001084 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001085 mutex_unlock(&dev->struct_mutex);
1086
Kees Cook647416f2013-03-10 14:10:06 -07001087 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001088}
1089
Kees Cook647416f2013-03-10 14:10:06 -07001090DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001091 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001092 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001093
Deepak Sadb4bd12014-03-31 11:30:02 +05301094static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001095{
David Weinehall36cdd012016-08-22 13:59:31 +03001096 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001097 int ret = 0;
1098
1099 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001100
David Weinehall36cdd012016-08-22 13:59:31 +03001101 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001102 u16 rgvswctl = I915_READ16(MEMSWCTL);
1103 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1104
1105 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1106 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1107 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1108 MEMSTAT_VID_SHIFT);
1109 seq_printf(m, "Current P-state: %d\n",
1110 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001111 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001112 u32 freq_sts;
1113
1114 mutex_lock(&dev_priv->rps.hw_lock);
1115 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1116 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1117 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1118
1119 seq_printf(m, "actual GPU freq: %d MHz\n",
1120 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1121
1122 seq_printf(m, "current GPU freq: %d MHz\n",
1123 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1124
1125 seq_printf(m, "max GPU freq: %d MHz\n",
1126 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1127
1128 seq_printf(m, "min GPU freq: %d MHz\n",
1129 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1130
1131 seq_printf(m, "idle GPU freq: %d MHz\n",
1132 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1133
1134 seq_printf(m,
1135 "efficient (RPe) frequency: %d MHz\n",
1136 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1137 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001138 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001139 u32 rp_state_limits;
1140 u32 gt_perf_status;
1141 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001142 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001143 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001144 u32 rpupei, rpcurup, rpprevup;
1145 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001146 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001147 int max_freq;
1148
Bob Paauwe35040562015-06-25 14:54:07 -07001149 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001150 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001151 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1152 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1153 } else {
1154 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1155 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1156 }
1157
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001158 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001159 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001160
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001161 reqf = I915_READ(GEN6_RPNSWREQ);
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001162 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301163 reqf >>= 23;
1164 else {
1165 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001166 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301167 reqf >>= 24;
1168 else
1169 reqf >>= 25;
1170 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001171 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001172
Chris Wilson0d8f9492014-03-27 09:06:14 +00001173 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1174 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1175 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1176
Jesse Barnesccab5c82011-01-18 15:49:25 -08001177 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301178 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1179 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1180 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1181 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1182 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1183 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001184 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301185 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001186 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001187 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1188 else
1189 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001190 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001191
Mika Kuoppala59bad942015-01-16 11:34:40 +02001192 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001193
David Weinehall36cdd012016-08-22 13:59:31 +03001194 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001195 pm_ier = I915_READ(GEN6_PMIER);
1196 pm_imr = I915_READ(GEN6_PMIMR);
1197 pm_isr = I915_READ(GEN6_PMISR);
1198 pm_iir = I915_READ(GEN6_PMIIR);
1199 pm_mask = I915_READ(GEN6_PMINTRMSK);
1200 } else {
1201 pm_ier = I915_READ(GEN8_GT_IER(2));
1202 pm_imr = I915_READ(GEN8_GT_IMR(2));
1203 pm_isr = I915_READ(GEN8_GT_ISR(2));
1204 pm_iir = I915_READ(GEN8_GT_IIR(2));
1205 pm_mask = I915_READ(GEN6_PMINTRMSK);
1206 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001207 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 -03001208 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05301209 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
1210 dev_priv->rps.pm_intrmsk_mbz);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001211 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001212 seq_printf(m, "Render p-state ratio: %d\n",
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001213 (gt_perf_status & (INTEL_GEN(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001214 seq_printf(m, "Render p-state VID: %d\n",
1215 gt_perf_status & 0xff);
1216 seq_printf(m, "Render p-state limit: %d\n",
1217 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001218 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1219 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1220 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1221 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001222 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001223 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301224 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1225 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1226 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1227 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1228 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1229 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001230 seq_printf(m, "Up threshold: %d%%\n",
1231 dev_priv->rps.up_threshold);
1232
Akash Goeld6cda9c2016-04-23 00:05:46 +05301233 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1234 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1235 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1236 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1237 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1238 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001239 seq_printf(m, "Down threshold: %d%%\n",
1240 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001241
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001242 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001243 rp_state_cap >> 16) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001244 max_freq *= (IS_GEN9_BC(dev_priv) ||
1245 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001246 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001247 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001248
1249 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001250 max_freq *= (IS_GEN9_BC(dev_priv) ||
1251 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001252 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001253 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001254
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001255 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001256 rp_state_cap >> 0) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001257 max_freq *= (IS_GEN9_BC(dev_priv) ||
1258 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001259 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001260 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001261 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001262 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001263
Chris Wilsond86ed342015-04-27 13:41:19 +01001264 seq_printf(m, "Current freq: %d MHz\n",
1265 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1266 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001267 seq_printf(m, "Idle freq: %d MHz\n",
1268 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001269 seq_printf(m, "Min freq: %d MHz\n",
1270 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001271 seq_printf(m, "Boost freq: %d MHz\n",
1272 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001273 seq_printf(m, "Max freq: %d MHz\n",
1274 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1275 seq_printf(m,
1276 "efficient (RPe) frequency: %d MHz\n",
1277 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001278 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001279 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001280 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001281
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001282 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001283 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1284 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1285
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001286 intel_runtime_pm_put(dev_priv);
1287 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001288}
1289
Ben Widawskyd6369512016-09-20 16:54:32 +03001290static void i915_instdone_info(struct drm_i915_private *dev_priv,
1291 struct seq_file *m,
1292 struct intel_instdone *instdone)
1293{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001294 int slice;
1295 int subslice;
1296
Ben Widawskyd6369512016-09-20 16:54:32 +03001297 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1298 instdone->instdone);
1299
1300 if (INTEL_GEN(dev_priv) <= 3)
1301 return;
1302
1303 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1304 instdone->slice_common);
1305
1306 if (INTEL_GEN(dev_priv) <= 6)
1307 return;
1308
Ben Widawskyf9e61372016-09-20 16:54:33 +03001309 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1310 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1311 slice, subslice, instdone->sampler[slice][subslice]);
1312
1313 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1314 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1315 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001316}
1317
Chris Wilsonf6544492015-01-26 18:03:04 +02001318static int i915_hangcheck_info(struct seq_file *m, void *unused)
1319{
David Weinehall36cdd012016-08-22 13:59:31 +03001320 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001321 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001322 u64 acthd[I915_NUM_ENGINES];
1323 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001324 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001325 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001326
Chris Wilson8af29b02016-09-09 14:11:47 +01001327 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001328 seq_puts(m, "Wedged\n");
1329 if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
1330 seq_puts(m, "Reset in progress: struct_mutex backoff\n");
1331 if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
1332 seq_puts(m, "Reset in progress: reset handoff to waiter\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001333 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001334 seq_puts(m, "Waiter holding struct mutex\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001335 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001336 seq_puts(m, "struct_mutex blocked for reset\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001337
Chris Wilsonf6544492015-01-26 18:03:04 +02001338 if (!i915.enable_hangcheck) {
Chris Wilson8c185ec2017-03-16 17:13:02 +00001339 seq_puts(m, "Hangcheck disabled\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001340 return 0;
1341 }
1342
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001343 intel_runtime_pm_get(dev_priv);
1344
Akash Goel3b3f1652016-10-13 22:44:48 +05301345 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001346 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001347 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001348 }
1349
Akash Goel3b3f1652016-10-13 22:44:48 +05301350 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001351
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001352 intel_runtime_pm_put(dev_priv);
1353
Chris Wilson8352aea2017-03-03 09:00:56 +00001354 if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
1355 seq_printf(m, "Hangcheck active, timer fires in %dms\n",
Chris Wilsonf6544492015-01-26 18:03:04 +02001356 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1357 jiffies));
Chris Wilson8352aea2017-03-03 09:00:56 +00001358 else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
1359 seq_puts(m, "Hangcheck active, work pending\n");
1360 else
1361 seq_puts(m, "Hangcheck inactive\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001362
Chris Wilsonf73b5672017-03-02 15:03:56 +00001363 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1364
Akash Goel3b3f1652016-10-13 22:44:48 +05301365 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001366 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1367 struct rb_node *rb;
1368
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001369 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001370 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001371 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001372 intel_engine_last_submit(engine),
1373 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001374 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001375 yesno(intel_engine_has_waiter(engine)),
1376 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001377 &dev_priv->gpu_error.missed_irq_rings)),
1378 yesno(engine->hangcheck.stalled));
1379
Chris Wilson61d3dc72017-03-03 19:08:24 +00001380 spin_lock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001381 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001382 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001383
1384 seq_printf(m, "\t%s [%d] waiting for %x\n",
1385 w->tsk->comm, w->tsk->pid, w->seqno);
1386 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001387 spin_unlock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001388
Chris Wilsonf6544492015-01-26 18:03:04 +02001389 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001390 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001391 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001392 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1393 hangcheck_action_to_str(engine->hangcheck.action),
1394 engine->hangcheck.action,
1395 jiffies_to_msecs(jiffies -
1396 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001397
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001398 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001399 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001400
Ben Widawskyd6369512016-09-20 16:54:32 +03001401 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001402
Ben Widawskyd6369512016-09-20 16:54:32 +03001403 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001404
Ben Widawskyd6369512016-09-20 16:54:32 +03001405 i915_instdone_info(dev_priv, m,
1406 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001407 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001408 }
1409
1410 return 0;
1411}
1412
Michel Thierry061d06a2017-06-20 10:57:49 +01001413static int i915_reset_info(struct seq_file *m, void *unused)
1414{
1415 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1416 struct i915_gpu_error *error = &dev_priv->gpu_error;
1417 struct intel_engine_cs *engine;
1418 enum intel_engine_id id;
1419
1420 seq_printf(m, "full gpu reset = %u\n", i915_reset_count(error));
1421
1422 for_each_engine(engine, dev_priv, id) {
1423 seq_printf(m, "%s = %u\n", engine->name,
1424 i915_reset_engine_count(error, engine));
1425 }
1426
1427 return 0;
1428}
1429
Ben Widawsky4d855292011-12-12 19:34:16 -08001430static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001431{
David Weinehall36cdd012016-08-22 13:59:31 +03001432 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001433 u32 rgvmodectl, rstdbyctl;
1434 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001435
Ben Widawsky616fdb52011-10-05 11:44:54 -07001436 rgvmodectl = I915_READ(MEMMODECTL);
1437 rstdbyctl = I915_READ(RSTDBYCTL);
1438 crstandvid = I915_READ16(CRSTANDVID);
1439
Jani Nikula742f4912015-09-03 11:16:09 +03001440 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001441 seq_printf(m, "Boost freq: %d\n",
1442 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1443 MEMMODE_BOOST_FREQ_SHIFT);
1444 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001445 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001446 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001447 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001448 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001449 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001450 seq_printf(m, "Starting frequency: P%d\n",
1451 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001452 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001453 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001454 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1455 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1456 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1457 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001458 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001459 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001460 switch (rstdbyctl & RSX_STATUS_MASK) {
1461 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001462 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001463 break;
1464 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001465 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001466 break;
1467 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001468 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001469 break;
1470 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001471 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001472 break;
1473 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001474 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001475 break;
1476 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001477 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001478 break;
1479 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001480 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001481 break;
1482 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001483
1484 return 0;
1485}
1486
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001487static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001488{
Chris Wilson233ebf52017-03-23 10:19:44 +00001489 struct drm_i915_private *i915 = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001490 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsond2dc94b2017-03-23 10:19:41 +00001491 unsigned int tmp;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001492
Chris Wilson233ebf52017-03-23 10:19:44 +00001493 for_each_fw_domain(fw_domain, i915, tmp)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001494 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001495 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilson233ebf52017-03-23 10:19:44 +00001496 READ_ONCE(fw_domain->wake_count));
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001497
1498 return 0;
1499}
1500
Mika Kuoppala13628772017-03-15 17:43:02 +02001501static void print_rc6_res(struct seq_file *m,
1502 const char *title,
1503 const i915_reg_t reg)
1504{
1505 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1506
1507 seq_printf(m, "%s %u (%llu us)\n",
1508 title, I915_READ(reg),
1509 intel_rc6_residency_us(dev_priv, reg));
1510}
1511
Deepak S669ab5a2014-01-10 15:18:26 +05301512static int vlv_drpc_info(struct seq_file *m)
1513{
David Weinehall36cdd012016-08-22 13:59:31 +03001514 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001515 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301516
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001517 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301518 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1519 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1520
1521 seq_printf(m, "Video Turbo Mode: %s\n",
1522 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1523 seq_printf(m, "Turbo enabled: %s\n",
1524 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1525 seq_printf(m, "HW control enabled: %s\n",
1526 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1527 seq_printf(m, "SW control enabled: %s\n",
1528 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1529 GEN6_RP_MEDIA_SW_MODE));
1530 seq_printf(m, "RC6 Enabled: %s\n",
1531 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1532 GEN6_RC_CTL_EI_MODE(1))));
1533 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001534 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301535 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001536 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301537
Mika Kuoppala13628772017-03-15 17:43:02 +02001538 print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
1539 print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
Imre Deak9cc19be2014-04-14 20:24:24 +03001540
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001541 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301542}
1543
Ben Widawsky4d855292011-12-12 19:34:16 -08001544static int gen6_drpc_info(struct seq_file *m)
1545{
David Weinehall36cdd012016-08-22 13:59:31 +03001546 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001547 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301548 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001549 unsigned forcewake_count;
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001550 int count = 0;
Ben Widawsky4d855292011-12-12 19:34:16 -08001551
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001552 forcewake_count = READ_ONCE(dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001553 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001554 seq_puts(m, "RC information inaccurate because somebody "
1555 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001556 } else {
1557 /* NB: we cannot use forcewake, else we read the wrong values */
1558 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1559 udelay(10);
1560 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1561 }
1562
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001563 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001564 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001565
1566 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1567 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001568 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301569 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1570 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1571 }
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001572
Ben Widawsky44cbd332012-11-06 14:36:36 +00001573 mutex_lock(&dev_priv->rps.hw_lock);
1574 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1575 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001576
1577 seq_printf(m, "Video Turbo Mode: %s\n",
1578 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1579 seq_printf(m, "HW control enabled: %s\n",
1580 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1581 seq_printf(m, "SW control enabled: %s\n",
1582 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1583 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001584 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001585 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1586 seq_printf(m, "RC6 Enabled: %s\n",
1587 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001588 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301589 seq_printf(m, "Render Well Gating Enabled: %s\n",
1590 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1591 seq_printf(m, "Media Well Gating Enabled: %s\n",
1592 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1593 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001594 seq_printf(m, "Deep RC6 Enabled: %s\n",
1595 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1596 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1597 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001598 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001599 switch (gt_core_status & GEN6_RCn_MASK) {
1600 case GEN6_RC0:
1601 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001602 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001603 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001604 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001605 break;
1606 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001607 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001608 break;
1609 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001610 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001611 break;
1612 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001613 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001614 break;
1615 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001616 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001617 break;
1618 }
1619
1620 seq_printf(m, "Core Power Down: %s\n",
1621 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001622 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301623 seq_printf(m, "Render Power Well: %s\n",
1624 (gen9_powergate_status &
1625 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1626 seq_printf(m, "Media Power Well: %s\n",
1627 (gen9_powergate_status &
1628 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1629 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001630
1631 /* Not exactly sure what this is */
Mika Kuoppala13628772017-03-15 17:43:02 +02001632 print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
1633 GEN6_GT_GFX_RC6_LOCKED);
1634 print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
1635 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
1636 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
Ben Widawskycce66a22012-03-27 18:59:38 -07001637
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001638 seq_printf(m, "RC6 voltage: %dmV\n",
1639 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1640 seq_printf(m, "RC6+ voltage: %dmV\n",
1641 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1642 seq_printf(m, "RC6++ voltage: %dmV\n",
1643 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301644 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001645}
1646
1647static int i915_drpc_info(struct seq_file *m, void *unused)
1648{
David Weinehall36cdd012016-08-22 13:59:31 +03001649 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001650 int err;
1651
1652 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001653
David Weinehall36cdd012016-08-22 13:59:31 +03001654 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001655 err = vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001656 else if (INTEL_GEN(dev_priv) >= 6)
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001657 err = gen6_drpc_info(m);
Ben Widawsky4d855292011-12-12 19:34:16 -08001658 else
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001659 err = ironlake_drpc_info(m);
1660
1661 intel_runtime_pm_put(dev_priv);
1662
1663 return err;
Ben Widawsky4d855292011-12-12 19:34:16 -08001664}
1665
Daniel Vetter9a851782015-06-18 10:30:22 +02001666static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1667{
David Weinehall36cdd012016-08-22 13:59:31 +03001668 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001669
1670 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1671 dev_priv->fb_tracking.busy_bits);
1672
1673 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1674 dev_priv->fb_tracking.flip_bits);
1675
1676 return 0;
1677}
1678
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001679static int i915_fbc_status(struct seq_file *m, void *unused)
1680{
David Weinehall36cdd012016-08-22 13:59:31 +03001681 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001682
David Weinehall36cdd012016-08-22 13:59:31 +03001683 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001684 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001685 return 0;
1686 }
1687
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001688 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001689 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001690
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001691 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001692 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001693 else
1694 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001695 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001696
Ville Syrjälä3fd5d1e2017-06-06 15:43:18 +03001697 if (intel_fbc_is_active(dev_priv)) {
1698 u32 mask;
1699
1700 if (INTEL_GEN(dev_priv) >= 8)
1701 mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
1702 else if (INTEL_GEN(dev_priv) >= 7)
1703 mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
1704 else if (INTEL_GEN(dev_priv) >= 5)
1705 mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
1706 else if (IS_G4X(dev_priv))
1707 mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
1708 else
1709 mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
1710 FBC_STAT_COMPRESSED);
1711
1712 seq_printf(m, "Compressing: %s\n", yesno(mask));
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001713 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001714
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001715 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001716 intel_runtime_pm_put(dev_priv);
1717
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001718 return 0;
1719}
1720
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001721static int i915_fbc_false_color_get(void *data, u64 *val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001722{
David Weinehall36cdd012016-08-22 13:59:31 +03001723 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001724
David Weinehall36cdd012016-08-22 13:59:31 +03001725 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001726 return -ENODEV;
1727
Rodrigo Vivida46f932014-08-01 02:04:45 -07001728 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001729
1730 return 0;
1731}
1732
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001733static int i915_fbc_false_color_set(void *data, u64 val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001734{
David Weinehall36cdd012016-08-22 13:59:31 +03001735 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001736 u32 reg;
1737
David Weinehall36cdd012016-08-22 13:59:31 +03001738 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001739 return -ENODEV;
1740
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001741 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001742
1743 reg = I915_READ(ILK_DPFC_CONTROL);
1744 dev_priv->fbc.false_color = val;
1745
1746 I915_WRITE(ILK_DPFC_CONTROL, val ?
1747 (reg | FBC_CTL_FALSE_COLOR) :
1748 (reg & ~FBC_CTL_FALSE_COLOR));
1749
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001750 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001751 return 0;
1752}
1753
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001754DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_false_color_fops,
1755 i915_fbc_false_color_get, i915_fbc_false_color_set,
Rodrigo Vivida46f932014-08-01 02:04:45 -07001756 "%llu\n");
1757
Paulo Zanoni92d44622013-05-31 16:33:24 -03001758static int i915_ips_status(struct seq_file *m, void *unused)
1759{
David Weinehall36cdd012016-08-22 13:59:31 +03001760 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001761
David Weinehall36cdd012016-08-22 13:59:31 +03001762 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001763 seq_puts(m, "not supported\n");
1764 return 0;
1765 }
1766
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001767 intel_runtime_pm_get(dev_priv);
1768
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001769 seq_printf(m, "Enabled by kernel parameter: %s\n",
1770 yesno(i915.enable_ips));
1771
David Weinehall36cdd012016-08-22 13:59:31 +03001772 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001773 seq_puts(m, "Currently: unknown\n");
1774 } else {
1775 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1776 seq_puts(m, "Currently: enabled\n");
1777 else
1778 seq_puts(m, "Currently: disabled\n");
1779 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001780
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001781 intel_runtime_pm_put(dev_priv);
1782
Paulo Zanoni92d44622013-05-31 16:33:24 -03001783 return 0;
1784}
1785
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001786static int i915_sr_status(struct seq_file *m, void *unused)
1787{
David Weinehall36cdd012016-08-22 13:59:31 +03001788 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001789 bool sr_enabled = false;
1790
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001791 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001792 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001793
Chris Wilson7342a722017-03-09 14:20:49 +00001794 if (INTEL_GEN(dev_priv) >= 9)
1795 /* no global SR status; inspect per-plane WM */;
1796 else if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001797 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001798 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001799 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001800 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001801 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001802 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001803 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001804 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001805 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001806 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001807
Chris Wilson9c870d02016-10-24 13:42:15 +01001808 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001809 intel_runtime_pm_put(dev_priv);
1810
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001811 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001812
1813 return 0;
1814}
1815
Jesse Barnes7648fa92010-05-20 14:28:11 -07001816static int i915_emon_status(struct seq_file *m, void *unused)
1817{
David Weinehall36cdd012016-08-22 13:59:31 +03001818 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1819 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001820 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001821 int ret;
1822
David Weinehall36cdd012016-08-22 13:59:31 +03001823 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001824 return -ENODEV;
1825
Chris Wilsonde227ef2010-07-03 07:58:38 +01001826 ret = mutex_lock_interruptible(&dev->struct_mutex);
1827 if (ret)
1828 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001829
1830 temp = i915_mch_val(dev_priv);
1831 chipset = i915_chipset_val(dev_priv);
1832 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001833 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001834
1835 seq_printf(m, "GMCH temp: %ld\n", temp);
1836 seq_printf(m, "Chipset power: %ld\n", chipset);
1837 seq_printf(m, "GFX power: %ld\n", gfx);
1838 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1839
1840 return 0;
1841}
1842
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001843static int i915_ring_freq_table(struct seq_file *m, void *unused)
1844{
David Weinehall36cdd012016-08-22 13:59:31 +03001845 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001846 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001847 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301848 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001849
Carlos Santa26310342016-08-17 12:30:41 -07001850 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001851 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001852 return 0;
1853 }
1854
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001855 intel_runtime_pm_get(dev_priv);
1856
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001857 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001858 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001859 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001860
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001861 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301862 /* Convert GT frequency to 50 HZ units */
1863 min_gpu_freq =
1864 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1865 max_gpu_freq =
1866 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1867 } else {
1868 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1869 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1870 }
1871
Damien Lespiau267f0c92013-06-24 22:59:48 +01001872 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001873
Akash Goelf936ec32015-06-29 14:50:22 +05301874 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001875 ia_freq = gpu_freq;
1876 sandybridge_pcode_read(dev_priv,
1877 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1878 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001879 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301880 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001881 (IS_GEN9_BC(dev_priv) ||
1882 IS_CANNONLAKE(dev_priv) ?
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001883 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001884 ((ia_freq >> 0) & 0xff) * 100,
1885 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001886 }
1887
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001888 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001889
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001890out:
1891 intel_runtime_pm_put(dev_priv);
1892 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001893}
1894
Chris Wilson44834a62010-08-19 16:09:23 +01001895static int i915_opregion(struct seq_file *m, void *unused)
1896{
David Weinehall36cdd012016-08-22 13:59:31 +03001897 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1898 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001899 struct intel_opregion *opregion = &dev_priv->opregion;
1900 int ret;
1901
1902 ret = mutex_lock_interruptible(&dev->struct_mutex);
1903 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001904 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001905
Jani Nikula2455a8e2015-12-14 12:50:53 +02001906 if (opregion->header)
1907 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001908
1909 mutex_unlock(&dev->struct_mutex);
1910
Daniel Vetter0d38f002012-04-21 22:49:10 +02001911out:
Chris Wilson44834a62010-08-19 16:09:23 +01001912 return 0;
1913}
1914
Jani Nikulaada8f952015-12-15 13:17:12 +02001915static int i915_vbt(struct seq_file *m, void *unused)
1916{
David Weinehall36cdd012016-08-22 13:59:31 +03001917 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001918
1919 if (opregion->vbt)
1920 seq_write(m, opregion->vbt, opregion->vbt_size);
1921
1922 return 0;
1923}
1924
Chris Wilson37811fc2010-08-25 22:45:57 +01001925static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1926{
David Weinehall36cdd012016-08-22 13:59:31 +03001927 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1928 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301929 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001930 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001931 int ret;
1932
1933 ret = mutex_lock_interruptible(&dev->struct_mutex);
1934 if (ret)
1935 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001936
Daniel Vetter06957262015-08-10 13:34:08 +02001937#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter346fb4e2017-07-06 15:00:20 +02001938 if (dev_priv->fbdev && dev_priv->fbdev->helper.fb) {
David Weinehall36cdd012016-08-22 13:59:31 +03001939 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001940
Chris Wilson25bcce92016-07-02 15:36:00 +01001941 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1942 fbdev_fb->base.width,
1943 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001944 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001945 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001946 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001947 drm_framebuffer_read_refcount(&fbdev_fb->base));
1948 describe_obj(m, fbdev_fb->obj);
1949 seq_putc(m, '\n');
1950 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001951#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001952
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001953 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001954 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301955 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1956 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001957 continue;
1958
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001959 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 +01001960 fb->base.width,
1961 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001962 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001963 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001964 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001965 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001966 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001967 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001968 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001969 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001970 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001971
1972 return 0;
1973}
1974
Chris Wilson7e37f882016-08-02 22:50:21 +01001975static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001976{
Chris Wilsonfe085f12017-03-21 10:25:52 +00001977 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u)",
1978 ring->space, ring->head, ring->tail);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001979}
1980
Ben Widawskye76d3632011-03-19 18:14:29 -07001981static int i915_context_status(struct seq_file *m, void *unused)
1982{
David Weinehall36cdd012016-08-22 13:59:31 +03001983 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1984 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001985 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001986 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301987 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001988 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001989
Daniel Vetterf3d28872014-05-29 23:23:08 +02001990 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001991 if (ret)
1992 return ret;
1993
Chris Wilson829a0af2017-06-20 12:05:45 +01001994 list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001995 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001996 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001997 struct task_struct *task;
1998
Chris Wilsonc84455b2016-08-15 10:49:08 +01001999 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01002000 if (task) {
2001 seq_printf(m, "(%s [%d]) ",
2002 task->comm, task->pid);
2003 put_task_struct(task);
2004 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01002005 } else if (IS_ERR(ctx->file_priv)) {
2006 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01002007 } else {
2008 seq_puts(m, "(kernel) ");
2009 }
2010
Chris Wilsonbca44d82016-05-24 14:53:41 +01002011 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
2012 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07002013
Akash Goel3b3f1652016-10-13 22:44:48 +05302014 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01002015 struct intel_context *ce = &ctx->engine[engine->id];
2016
2017 seq_printf(m, "%s: ", engine->name);
2018 seq_putc(m, ce->initialised ? 'I' : 'i');
2019 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002020 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01002021 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01002022 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002023 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002024 }
2025
Chris Wilson4ff4b442017-06-16 15:05:16 +01002026 seq_printf(m,
2027 "\tvma hashtable size=%u (actual %lu), count=%u\n",
2028 ctx->vma_lut.ht_size,
2029 BIT(ctx->vma_lut.ht_bits),
2030 ctx->vma_lut.ht_count);
2031
Ben Widawskya33afea2013-09-17 21:12:45 -07002032 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002033 }
2034
Daniel Vetterf3d28872014-05-29 23:23:08 +02002035 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002036
2037 return 0;
2038}
2039
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002040static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002041 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002042 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002043{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002044 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002045 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002046 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002047
Chris Wilson7069b142016-04-28 09:56:52 +01002048 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2049
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002050 if (!vma) {
2051 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002052 return;
2053 }
2054
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002055 if (vma->flags & I915_VMA_GLOBAL_BIND)
2056 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002057 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002058
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002059 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002060 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002061 return;
2062 }
2063
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002064 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2065 if (page) {
2066 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002067
2068 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002069 seq_printf(m,
2070 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2071 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002072 reg_state[j], reg_state[j + 1],
2073 reg_state[j + 2], reg_state[j + 3]);
2074 }
2075 kunmap_atomic(reg_state);
2076 }
2077
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002078 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002079 seq_putc(m, '\n');
2080}
2081
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002082static int i915_dump_lrc(struct seq_file *m, void *unused)
2083{
David Weinehall36cdd012016-08-22 13:59:31 +03002084 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2085 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002086 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002087 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302088 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002089 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002090
2091 if (!i915.enable_execlists) {
2092 seq_printf(m, "Logical Ring Contexts are disabled\n");
2093 return 0;
2094 }
2095
2096 ret = mutex_lock_interruptible(&dev->struct_mutex);
2097 if (ret)
2098 return ret;
2099
Chris Wilson829a0af2017-06-20 12:05:45 +01002100 list_for_each_entry(ctx, &dev_priv->contexts.list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302101 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002102 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002103
2104 mutex_unlock(&dev->struct_mutex);
2105
2106 return 0;
2107}
2108
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002109static const char *swizzle_string(unsigned swizzle)
2110{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002111 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002112 case I915_BIT_6_SWIZZLE_NONE:
2113 return "none";
2114 case I915_BIT_6_SWIZZLE_9:
2115 return "bit9";
2116 case I915_BIT_6_SWIZZLE_9_10:
2117 return "bit9/bit10";
2118 case I915_BIT_6_SWIZZLE_9_11:
2119 return "bit9/bit11";
2120 case I915_BIT_6_SWIZZLE_9_10_11:
2121 return "bit9/bit10/bit11";
2122 case I915_BIT_6_SWIZZLE_9_17:
2123 return "bit9/bit17";
2124 case I915_BIT_6_SWIZZLE_9_10_17:
2125 return "bit9/bit10/bit17";
2126 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002127 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002128 }
2129
2130 return "bug";
2131}
2132
2133static int i915_swizzle_info(struct seq_file *m, void *data)
2134{
David Weinehall36cdd012016-08-22 13:59:31 +03002135 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002136
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002137 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002138
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002139 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2140 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2141 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2142 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2143
David Weinehall36cdd012016-08-22 13:59:31 +03002144 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002145 seq_printf(m, "DDC = 0x%08x\n",
2146 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002147 seq_printf(m, "DDC2 = 0x%08x\n",
2148 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002149 seq_printf(m, "C0DRB3 = 0x%04x\n",
2150 I915_READ16(C0DRB3));
2151 seq_printf(m, "C1DRB3 = 0x%04x\n",
2152 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002153 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002154 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2155 I915_READ(MAD_DIMM_C0));
2156 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2157 I915_READ(MAD_DIMM_C1));
2158 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2159 I915_READ(MAD_DIMM_C2));
2160 seq_printf(m, "TILECTL = 0x%08x\n",
2161 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002162 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002163 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2164 I915_READ(GAMTARBMODE));
2165 else
2166 seq_printf(m, "ARB_MODE = 0x%08x\n",
2167 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002168 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2169 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002170 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002171
2172 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2173 seq_puts(m, "L-shaped memory detected\n");
2174
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002175 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002176
2177 return 0;
2178}
2179
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002180static int per_file_ctx(int id, void *ptr, void *data)
2181{
Chris Wilsone2efd132016-05-24 14:53:34 +01002182 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002183 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002184 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2185
2186 if (!ppgtt) {
2187 seq_printf(m, " no ppgtt for context %d\n",
2188 ctx->user_handle);
2189 return 0;
2190 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002191
Oscar Mateof83d6512014-05-22 14:13:38 +01002192 if (i915_gem_context_is_default(ctx))
2193 seq_puts(m, " default context:\n");
2194 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002195 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002196 ppgtt->debug_dump(ppgtt, m);
2197
2198 return 0;
2199}
2200
David Weinehall36cdd012016-08-22 13:59:31 +03002201static void gen8_ppgtt_info(struct seq_file *m,
2202 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002203{
Ben Widawsky77df6772013-11-02 21:07:30 -07002204 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302205 struct intel_engine_cs *engine;
2206 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002207 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002208
Ben Widawsky77df6772013-11-02 21:07:30 -07002209 if (!ppgtt)
2210 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002211
Akash Goel3b3f1652016-10-13 22:44:48 +05302212 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002213 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002214 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002215 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002216 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002217 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002218 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002219 }
2220 }
2221}
2222
David Weinehall36cdd012016-08-22 13:59:31 +03002223static void gen6_ppgtt_info(struct seq_file *m,
2224 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002225{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002226 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302227 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002228
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002229 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002230 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2231
Akash Goel3b3f1652016-10-13 22:44:48 +05302232 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002233 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002234 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002235 seq_printf(m, "GFX_MODE: 0x%08x\n",
2236 I915_READ(RING_MODE_GEN7(engine)));
2237 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2238 I915_READ(RING_PP_DIR_BASE(engine)));
2239 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2240 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2241 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2242 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002243 }
2244 if (dev_priv->mm.aliasing_ppgtt) {
2245 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2246
Damien Lespiau267f0c92013-06-24 22:59:48 +01002247 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002248 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002249
Ben Widawsky87d60b62013-12-06 14:11:29 -08002250 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002251 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002252
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002253 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002254}
2255
2256static int i915_ppgtt_info(struct seq_file *m, void *data)
2257{
David Weinehall36cdd012016-08-22 13:59:31 +03002258 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2259 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002260 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002261 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002262
Chris Wilson637ee292016-08-22 14:28:20 +01002263 mutex_lock(&dev->filelist_mutex);
2264 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002265 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002266 goto out_unlock;
2267
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002268 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002269
David Weinehall36cdd012016-08-22 13:59:31 +03002270 if (INTEL_GEN(dev_priv) >= 8)
2271 gen8_ppgtt_info(m, dev_priv);
2272 else if (INTEL_GEN(dev_priv) >= 6)
2273 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002274
Michel Thierryea91e402015-07-29 17:23:57 +01002275 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2276 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002277 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002278
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002279 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002280 if (!task) {
2281 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002282 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002283 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002284 seq_printf(m, "\nproc: %s\n", task->comm);
2285 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002286 idr_for_each(&file_priv->context_idr, per_file_ctx,
2287 (void *)(unsigned long)m);
2288 }
2289
Chris Wilson637ee292016-08-22 14:28:20 +01002290out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002291 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002292 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002293out_unlock:
2294 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002295 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002296}
2297
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002298static int count_irq_waiters(struct drm_i915_private *i915)
2299{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002300 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302301 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002302 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002303
Akash Goel3b3f1652016-10-13 22:44:48 +05302304 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002305 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002306
2307 return count;
2308}
2309
Chris Wilson7466c292016-08-15 09:49:33 +01002310static const char *rps_power_to_str(unsigned int power)
2311{
2312 static const char * const strings[] = {
2313 [LOW_POWER] = "low power",
2314 [BETWEEN] = "mixed",
2315 [HIGH_POWER] = "high power",
2316 };
2317
2318 if (power >= ARRAY_SIZE(strings) || !strings[power])
2319 return "unknown";
2320
2321 return strings[power];
2322}
2323
Chris Wilson1854d5c2015-04-07 16:20:32 +01002324static int i915_rps_boost_info(struct seq_file *m, void *data)
2325{
David Weinehall36cdd012016-08-22 13:59:31 +03002326 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2327 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002328 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002329
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002330 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002331 seq_printf(m, "GPU busy? %s [%d requests]\n",
2332 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002333 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002334 seq_printf(m, "Boosts outstanding? %d\n",
2335 atomic_read(&dev_priv->rps.num_waiters));
Chris Wilson7466c292016-08-15 09:49:33 +01002336 seq_printf(m, "Frequency requested %d\n",
2337 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2338 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002339 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2340 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2341 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2342 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002343 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2344 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2345 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2346 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002347
2348 mutex_lock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002349 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2350 struct drm_i915_file_private *file_priv = file->driver_priv;
2351 struct task_struct *task;
2352
2353 rcu_read_lock();
2354 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002355 seq_printf(m, "%s [%d]: %d boosts\n",
Chris Wilson1854d5c2015-04-07 16:20:32 +01002356 task ? task->comm : "<unknown>",
2357 task ? task->pid : -1,
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002358 atomic_read(&file_priv->rps.boosts));
Chris Wilson1854d5c2015-04-07 16:20:32 +01002359 rcu_read_unlock();
2360 }
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002361 seq_printf(m, "Kernel (anonymous) boosts: %d\n",
2362 atomic_read(&dev_priv->rps.boosts));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002363 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002364
Chris Wilson7466c292016-08-15 09:49:33 +01002365 if (INTEL_GEN(dev_priv) >= 6 &&
2366 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002367 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002368 u32 rpup, rpupei;
2369 u32 rpdown, rpdownei;
2370
2371 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2372 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2373 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2374 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2375 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2376 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2377
2378 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2379 rps_power_to_str(dev_priv->rps.power));
2380 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002381 rpup && rpupei ? 100 * rpup / rpupei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002382 dev_priv->rps.up_threshold);
2383 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002384 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002385 dev_priv->rps.down_threshold);
2386 } else {
2387 seq_puts(m, "\nRPS Autotuning inactive\n");
2388 }
2389
Chris Wilson8d3afd72015-05-21 21:01:47 +01002390 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002391}
2392
Ben Widawsky63573eb2013-07-04 11:02:07 -07002393static int i915_llc(struct seq_file *m, void *data)
2394{
David Weinehall36cdd012016-08-22 13:59:31 +03002395 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002396 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002397
David Weinehall36cdd012016-08-22 13:59:31 +03002398 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002399 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2400 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002401
2402 return 0;
2403}
2404
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002405static int i915_huc_load_status_info(struct seq_file *m, void *data)
2406{
2407 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2408 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2409
2410 if (!HAS_HUC_UCODE(dev_priv))
2411 return 0;
2412
2413 seq_puts(m, "HuC firmware status:\n");
2414 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2415 seq_printf(m, "\tfetch: %s\n",
2416 intel_uc_fw_status_repr(huc_fw->fetch_status));
2417 seq_printf(m, "\tload: %s\n",
2418 intel_uc_fw_status_repr(huc_fw->load_status));
2419 seq_printf(m, "\tversion wanted: %d.%d\n",
2420 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2421 seq_printf(m, "\tversion found: %d.%d\n",
2422 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2423 seq_printf(m, "\theader: offset is %d; size = %d\n",
2424 huc_fw->header_offset, huc_fw->header_size);
2425 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2426 huc_fw->ucode_offset, huc_fw->ucode_size);
2427 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2428 huc_fw->rsa_offset, huc_fw->rsa_size);
2429
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302430 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002431 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302432 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002433
2434 return 0;
2435}
2436
Alex Daifdf5d352015-08-12 15:43:37 +01002437static int i915_guc_load_status_info(struct seq_file *m, void *data)
2438{
David Weinehall36cdd012016-08-22 13:59:31 +03002439 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002440 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Daifdf5d352015-08-12 15:43:37 +01002441 u32 tmp, i;
2442
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002443 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002444 return 0;
2445
2446 seq_printf(m, "GuC firmware status:\n");
2447 seq_printf(m, "\tpath: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002448 guc_fw->path);
Alex Daifdf5d352015-08-12 15:43:37 +01002449 seq_printf(m, "\tfetch: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002450 intel_uc_fw_status_repr(guc_fw->fetch_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002451 seq_printf(m, "\tload: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002452 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002453 seq_printf(m, "\tversion wanted: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002454 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
Alex Daifdf5d352015-08-12 15:43:37 +01002455 seq_printf(m, "\tversion found: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002456 guc_fw->major_ver_found, guc_fw->minor_ver_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002457 seq_printf(m, "\theader: offset is %d; size = %d\n",
2458 guc_fw->header_offset, guc_fw->header_size);
2459 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2460 guc_fw->ucode_offset, guc_fw->ucode_size);
2461 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2462 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002463
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302464 intel_runtime_pm_get(dev_priv);
2465
Alex Daifdf5d352015-08-12 15:43:37 +01002466 tmp = I915_READ(GUC_STATUS);
2467
2468 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2469 seq_printf(m, "\tBootrom status = 0x%x\n",
2470 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2471 seq_printf(m, "\tuKernel status = 0x%x\n",
2472 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2473 seq_printf(m, "\tMIA Core status = 0x%x\n",
2474 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2475 seq_puts(m, "\nScratch registers:\n");
2476 for (i = 0; i < 16; i++)
2477 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2478
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302479 intel_runtime_pm_put(dev_priv);
2480
Alex Daifdf5d352015-08-12 15:43:37 +01002481 return 0;
2482}
2483
Akash Goel5aa1ee42016-10-12 21:54:36 +05302484static void i915_guc_log_info(struct seq_file *m,
2485 struct drm_i915_private *dev_priv)
2486{
2487 struct intel_guc *guc = &dev_priv->guc;
2488
2489 seq_puts(m, "\nGuC logging stats:\n");
2490
2491 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2492 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2493 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2494
2495 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2496 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2497 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2498
2499 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2500 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2501 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2502
2503 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2504 guc->log.flush_interrupt_count);
2505
2506 seq_printf(m, "\tCapture miss count: %u\n",
2507 guc->log.capture_miss_count);
2508}
2509
Dave Gordon8b417c22015-08-12 15:43:44 +01002510static void i915_guc_client_info(struct seq_file *m,
2511 struct drm_i915_private *dev_priv,
2512 struct i915_guc_client *client)
2513{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002514 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002515 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002516 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002517
Oscar Mateob09935a2017-03-22 10:39:53 -07002518 seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
2519 client->priority, client->stage_id, client->proc_desc_offset);
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002520 seq_printf(m, "\tDoorbell id %d, offset: 0x%lx, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002521 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002522 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2523 client->wq_size, client->wq_offset, client->wq_tail);
2524
Dave Gordon551aaec2016-05-13 15:36:33 +01002525 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002526
Akash Goel3b3f1652016-10-13 22:44:48 +05302527 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002528 u64 submissions = client->submissions[id];
2529 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002530 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002531 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002532 }
2533 seq_printf(m, "\tTotal: %llu\n", tot);
2534}
2535
Oscar Mateoa8b93702017-05-10 15:04:51 +00002536static bool check_guc_submission(struct seq_file *m)
Dave Gordon8b417c22015-08-12 15:43:44 +01002537{
David Weinehall36cdd012016-08-22 13:59:31 +03002538 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002539 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002540
Chris Wilson334636c2016-11-29 12:10:20 +00002541 if (!guc->execbuf_client) {
2542 seq_printf(m, "GuC submission %s\n",
2543 HAS_GUC_SCHED(dev_priv) ?
2544 "disabled" :
2545 "not supported");
Oscar Mateoa8b93702017-05-10 15:04:51 +00002546 return false;
Chris Wilson334636c2016-11-29 12:10:20 +00002547 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002548
Oscar Mateoa8b93702017-05-10 15:04:51 +00002549 return true;
2550}
2551
Dave Gordon8b417c22015-08-12 15:43:44 +01002552static int i915_guc_info(struct seq_file *m, void *data)
2553{
2554 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2555 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002556
Oscar Mateoa8b93702017-05-10 15:04:51 +00002557 if (!check_guc_submission(m))
Dave Gordon8b417c22015-08-12 15:43:44 +01002558 return 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002559
Dave Gordon9636f6d2016-06-13 17:57:28 +01002560 seq_printf(m, "Doorbell map:\n");
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002561 seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
Chris Wilson334636c2016-11-29 12:10:20 +00002562 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002563
Chris Wilson334636c2016-11-29 12:10:20 +00002564 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2565 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002566
Akash Goel5aa1ee42016-10-12 21:54:36 +05302567 i915_guc_log_info(m, dev_priv);
2568
Dave Gordon8b417c22015-08-12 15:43:44 +01002569 /* Add more as required ... */
2570
2571 return 0;
2572}
2573
Oscar Mateoa8b93702017-05-10 15:04:51 +00002574static int i915_guc_stage_pool(struct seq_file *m, void *data)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002575{
David Weinehall36cdd012016-08-22 13:59:31 +03002576 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Oscar Mateoa8b93702017-05-10 15:04:51 +00002577 const struct intel_guc *guc = &dev_priv->guc;
2578 struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
2579 struct i915_guc_client *client = guc->execbuf_client;
2580 unsigned int tmp;
2581 int index;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002582
Oscar Mateoa8b93702017-05-10 15:04:51 +00002583 if (!check_guc_submission(m))
Alex Dai4c7e77f2015-08-12 15:43:40 +01002584 return 0;
2585
Oscar Mateoa8b93702017-05-10 15:04:51 +00002586 for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
2587 struct intel_engine_cs *engine;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002588
Oscar Mateoa8b93702017-05-10 15:04:51 +00002589 if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
2590 continue;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002591
Oscar Mateoa8b93702017-05-10 15:04:51 +00002592 seq_printf(m, "GuC stage descriptor %u:\n", index);
2593 seq_printf(m, "\tIndex: %u\n", desc->stage_id);
2594 seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
2595 seq_printf(m, "\tPriority: %d\n", desc->priority);
2596 seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
2597 seq_printf(m, "\tEngines used: 0x%x\n",
2598 desc->engines_used);
2599 seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
2600 desc->db_trigger_phy,
2601 desc->db_trigger_cpu,
2602 desc->db_trigger_uk);
2603 seq_printf(m, "\tProcess descriptor: 0x%x\n",
2604 desc->process_desc);
Colin Ian King9a094852017-05-16 10:22:35 +01002605 seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
Oscar Mateoa8b93702017-05-10 15:04:51 +00002606 desc->wq_addr, desc->wq_size);
2607 seq_putc(m, '\n');
2608
2609 for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
2610 u32 guc_engine_id = engine->guc_id;
2611 struct guc_execlist_context *lrc =
2612 &desc->lrc[guc_engine_id];
2613
2614 seq_printf(m, "\t%s LRC:\n", engine->name);
2615 seq_printf(m, "\t\tContext desc: 0x%x\n",
2616 lrc->context_desc);
2617 seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
2618 seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
2619 seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
2620 seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
2621 seq_putc(m, '\n');
2622 }
Alex Dai4c7e77f2015-08-12 15:43:40 +01002623 }
2624
Oscar Mateoa8b93702017-05-10 15:04:51 +00002625 return 0;
2626}
2627
Alex Dai4c7e77f2015-08-12 15:43:40 +01002628static int i915_guc_log_dump(struct seq_file *m, void *data)
2629{
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002630 struct drm_info_node *node = m->private;
2631 struct drm_i915_private *dev_priv = node_to_i915(node);
2632 bool dump_load_err = !!node->info_ent->data;
2633 struct drm_i915_gem_object *obj = NULL;
2634 u32 *log;
2635 int i = 0;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002636
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002637 if (dump_load_err)
2638 obj = dev_priv->guc.load_err_log;
2639 else if (dev_priv->guc.log.vma)
2640 obj = dev_priv->guc.log.vma->obj;
2641
2642 if (!obj)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002643 return 0;
2644
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002645 log = i915_gem_object_pin_map(obj, I915_MAP_WC);
2646 if (IS_ERR(log)) {
2647 DRM_DEBUG("Failed to pin object\n");
2648 seq_puts(m, "(log data unaccessible)\n");
2649 return PTR_ERR(log);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002650 }
2651
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002652 for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
2653 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2654 *(log + i), *(log + i + 1),
2655 *(log + i + 2), *(log + i + 3));
2656
Alex Dai4c7e77f2015-08-12 15:43:40 +01002657 seq_putc(m, '\n');
2658
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002659 i915_gem_object_unpin_map(obj);
2660
Alex Dai4c7e77f2015-08-12 15:43:40 +01002661 return 0;
2662}
2663
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302664static int i915_guc_log_control_get(void *data, u64 *val)
2665{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002666 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302667
2668 if (!dev_priv->guc.log.vma)
2669 return -EINVAL;
2670
2671 *val = i915.guc_log_level;
2672
2673 return 0;
2674}
2675
2676static int i915_guc_log_control_set(void *data, u64 val)
2677{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002678 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302679 int ret;
2680
2681 if (!dev_priv->guc.log.vma)
2682 return -EINVAL;
2683
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002684 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302685 if (ret)
2686 return ret;
2687
2688 intel_runtime_pm_get(dev_priv);
2689 ret = i915_guc_log_control(dev_priv, val);
2690 intel_runtime_pm_put(dev_priv);
2691
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002692 mutex_unlock(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302693 return ret;
2694}
2695
2696DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2697 i915_guc_log_control_get, i915_guc_log_control_set,
2698 "%lld\n");
2699
Chris Wilsonb86bef202017-01-16 13:06:21 +00002700static const char *psr2_live_status(u32 val)
2701{
2702 static const char * const live_status[] = {
2703 "IDLE",
2704 "CAPTURE",
2705 "CAPTURE_FS",
2706 "SLEEP",
2707 "BUFON_FW",
2708 "ML_UP",
2709 "SU_STANDBY",
2710 "FAST_SLEEP",
2711 "DEEP_SLEEP",
2712 "BUF_ON",
2713 "TG_ON"
2714 };
2715
2716 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2717 if (val < ARRAY_SIZE(live_status))
2718 return live_status[val];
2719
2720 return "unknown";
2721}
2722
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002723static int i915_edp_psr_status(struct seq_file *m, void *data)
2724{
David Weinehall36cdd012016-08-22 13:59:31 +03002725 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002726 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002727 u32 stat[3];
2728 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002729 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002730
David Weinehall36cdd012016-08-22 13:59:31 +03002731 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002732 seq_puts(m, "PSR not supported\n");
2733 return 0;
2734 }
2735
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002736 intel_runtime_pm_get(dev_priv);
2737
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002738 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002739 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2740 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002741 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002742 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002743 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2744 dev_priv->psr.busy_frontbuffer_bits);
2745 seq_printf(m, "Re-enable work scheduled: %s\n",
2746 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002747
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302748 if (HAS_DDI(dev_priv)) {
2749 if (dev_priv->psr.psr2_support)
2750 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2751 else
2752 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2753 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002754 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002755 enum transcoder cpu_transcoder =
2756 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2757 enum intel_display_power_domain power_domain;
2758
2759 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2760 if (!intel_display_power_get_if_enabled(dev_priv,
2761 power_domain))
2762 continue;
2763
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002764 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2765 VLV_EDP_PSR_CURR_STATE_MASK;
2766 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2767 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2768 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002769
2770 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002771 }
2772 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002773
2774 seq_printf(m, "Main link in standby mode: %s\n",
2775 yesno(dev_priv->psr.link_standby));
2776
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002777 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002778
David Weinehall36cdd012016-08-22 13:59:31 +03002779 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002780 for_each_pipe(dev_priv, pipe) {
2781 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2782 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2783 seq_printf(m, " pipe %c", pipe_name(pipe));
2784 }
2785 seq_puts(m, "\n");
2786
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002787 /*
2788 * VLV/CHV PSR has no kind of performance counter
2789 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2790 */
David Weinehall36cdd012016-08-22 13:59:31 +03002791 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002792 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002793 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002794
2795 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2796 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302797 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002798 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302799
Chris Wilsonb86bef202017-01-16 13:06:21 +00002800 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2801 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302802 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002803 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002804
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002805 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002806 return 0;
2807}
2808
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002809static int i915_sink_crc(struct seq_file *m, void *data)
2810{
David Weinehall36cdd012016-08-22 13:59:31 +03002811 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2812 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002813 struct intel_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002814 struct drm_connector_list_iter conn_iter;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002815 struct intel_dp *intel_dp = NULL;
2816 int ret;
2817 u8 crc[6];
2818
2819 drm_modeset_lock_all(dev);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002820 drm_connector_list_iter_begin(dev, &conn_iter);
2821 for_each_intel_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002822 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002823
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002824 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002825 continue;
2826
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002827 crtc = connector->base.state->crtc;
2828 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002829 continue;
2830
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002831 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002832 continue;
2833
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002834 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002835
2836 ret = intel_dp_sink_crc(intel_dp, crc);
2837 if (ret)
2838 goto out;
2839
2840 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2841 crc[0], crc[1], crc[2],
2842 crc[3], crc[4], crc[5]);
2843 goto out;
2844 }
2845 ret = -ENODEV;
2846out:
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002847 drm_connector_list_iter_end(&conn_iter);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002848 drm_modeset_unlock_all(dev);
2849 return ret;
2850}
2851
Jesse Barnesec013e72013-08-20 10:29:23 +01002852static int i915_energy_uJ(struct seq_file *m, void *data)
2853{
David Weinehall36cdd012016-08-22 13:59:31 +03002854 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002855 u64 power;
2856 u32 units;
2857
David Weinehall36cdd012016-08-22 13:59:31 +03002858 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002859 return -ENODEV;
2860
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002861 intel_runtime_pm_get(dev_priv);
2862
Jesse Barnesec013e72013-08-20 10:29:23 +01002863 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2864 power = (power & 0x1f00) >> 8;
2865 units = 1000000 / (1 << power); /* convert to uJ */
2866 power = I915_READ(MCH_SECP_NRG_STTS);
2867 power *= units;
2868
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002869 intel_runtime_pm_put(dev_priv);
2870
Jesse Barnesec013e72013-08-20 10:29:23 +01002871 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002872
2873 return 0;
2874}
2875
Damien Lespiau6455c872015-06-04 18:23:57 +01002876static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002877{
David Weinehall36cdd012016-08-22 13:59:31 +03002878 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002879 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002880
Chris Wilsona156e642016-04-03 14:14:21 +01002881 if (!HAS_RUNTIME_PM(dev_priv))
2882 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002883
Chris Wilson67d97da2016-07-04 08:08:31 +01002884 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002885 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002886 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002887#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002888 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002889 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002890#else
2891 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2892#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002893 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002894 pci_power_name(pdev->current_state),
2895 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002896
Jesse Barnesec013e72013-08-20 10:29:23 +01002897 return 0;
2898}
2899
Imre Deak1da51582013-11-25 17:15:35 +02002900static int i915_power_domain_info(struct seq_file *m, void *unused)
2901{
David Weinehall36cdd012016-08-22 13:59:31 +03002902 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002903 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2904 int i;
2905
2906 mutex_lock(&power_domains->lock);
2907
2908 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2909 for (i = 0; i < power_domains->power_well_count; i++) {
2910 struct i915_power_well *power_well;
2911 enum intel_display_power_domain power_domain;
2912
2913 power_well = &power_domains->power_wells[i];
2914 seq_printf(m, "%-25s %d\n", power_well->name,
2915 power_well->count);
2916
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002917 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002918 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002919 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002920 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002921 }
2922
2923 mutex_unlock(&power_domains->lock);
2924
2925 return 0;
2926}
2927
Damien Lespiaub7cec662015-10-27 14:47:01 +02002928static int i915_dmc_info(struct seq_file *m, void *unused)
2929{
David Weinehall36cdd012016-08-22 13:59:31 +03002930 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002931 struct intel_csr *csr;
2932
David Weinehall36cdd012016-08-22 13:59:31 +03002933 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002934 seq_puts(m, "not supported\n");
2935 return 0;
2936 }
2937
2938 csr = &dev_priv->csr;
2939
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002940 intel_runtime_pm_get(dev_priv);
2941
Damien Lespiaub7cec662015-10-27 14:47:01 +02002942 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2943 seq_printf(m, "path: %s\n", csr->fw_path);
2944
2945 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002946 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002947
2948 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2949 CSR_VERSION_MINOR(csr->version));
2950
Mika Kuoppala48de5682017-05-09 13:05:22 +03002951 if (IS_KABYLAKE(dev_priv) ||
2952 (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6))) {
Damien Lespiau83372062015-10-30 17:53:32 +02002953 seq_printf(m, "DC3 -> DC5 count: %d\n",
2954 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2955 seq_printf(m, "DC5 -> DC6 count: %d\n",
2956 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002957 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002958 seq_printf(m, "DC3 -> DC5 count: %d\n",
2959 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002960 }
2961
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002962out:
2963 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2964 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2965 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2966
Damien Lespiau83372062015-10-30 17:53:32 +02002967 intel_runtime_pm_put(dev_priv);
2968
Damien Lespiaub7cec662015-10-27 14:47:01 +02002969 return 0;
2970}
2971
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002972static void intel_seq_print_mode(struct seq_file *m, int tabs,
2973 struct drm_display_mode *mode)
2974{
2975 int i;
2976
2977 for (i = 0; i < tabs; i++)
2978 seq_putc(m, '\t');
2979
2980 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",
2981 mode->base.id, mode->name,
2982 mode->vrefresh, mode->clock,
2983 mode->hdisplay, mode->hsync_start,
2984 mode->hsync_end, mode->htotal,
2985 mode->vdisplay, mode->vsync_start,
2986 mode->vsync_end, mode->vtotal,
2987 mode->type, mode->flags);
2988}
2989
2990static void intel_encoder_info(struct seq_file *m,
2991 struct intel_crtc *intel_crtc,
2992 struct intel_encoder *intel_encoder)
2993{
David Weinehall36cdd012016-08-22 13:59:31 +03002994 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2995 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002996 struct drm_crtc *crtc = &intel_crtc->base;
2997 struct intel_connector *intel_connector;
2998 struct drm_encoder *encoder;
2999
3000 encoder = &intel_encoder->base;
3001 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03003002 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003003 for_each_connector_on_encoder(dev, encoder, intel_connector) {
3004 struct drm_connector *connector = &intel_connector->base;
3005 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
3006 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03003007 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003008 drm_get_connector_status_name(connector->status));
3009 if (connector->status == connector_status_connected) {
3010 struct drm_display_mode *mode = &crtc->mode;
3011 seq_printf(m, ", mode:\n");
3012 intel_seq_print_mode(m, 2, mode);
3013 } else {
3014 seq_putc(m, '\n');
3015 }
3016 }
3017}
3018
3019static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3020{
David Weinehall36cdd012016-08-22 13:59:31 +03003021 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3022 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003023 struct drm_crtc *crtc = &intel_crtc->base;
3024 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02003025 struct drm_plane_state *plane_state = crtc->primary->state;
3026 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003027
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02003028 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07003029 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02003030 fb->base.id, plane_state->src_x >> 16,
3031 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07003032 else
3033 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003034 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
3035 intel_encoder_info(m, intel_crtc, intel_encoder);
3036}
3037
3038static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
3039{
3040 struct drm_display_mode *mode = panel->fixed_mode;
3041
3042 seq_printf(m, "\tfixed mode:\n");
3043 intel_seq_print_mode(m, 2, mode);
3044}
3045
3046static void intel_dp_info(struct seq_file *m,
3047 struct intel_connector *intel_connector)
3048{
3049 struct intel_encoder *intel_encoder = intel_connector->encoder;
3050 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
3051
3052 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03003053 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003054 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003055 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03003056
3057 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
3058 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003059}
3060
Libin Yang9a148a92016-11-28 20:07:05 +08003061static void intel_dp_mst_info(struct seq_file *m,
3062 struct intel_connector *intel_connector)
3063{
3064 struct intel_encoder *intel_encoder = intel_connector->encoder;
3065 struct intel_dp_mst_encoder *intel_mst =
3066 enc_to_mst(&intel_encoder->base);
3067 struct intel_digital_port *intel_dig_port = intel_mst->primary;
3068 struct intel_dp *intel_dp = &intel_dig_port->dp;
3069 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
3070 intel_connector->port);
3071
3072 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
3073}
3074
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003075static void intel_hdmi_info(struct seq_file *m,
3076 struct intel_connector *intel_connector)
3077{
3078 struct intel_encoder *intel_encoder = intel_connector->encoder;
3079 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
3080
Jani Nikula742f4912015-09-03 11:16:09 +03003081 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003082}
3083
3084static void intel_lvds_info(struct seq_file *m,
3085 struct intel_connector *intel_connector)
3086{
3087 intel_panel_info(m, &intel_connector->panel);
3088}
3089
3090static void intel_connector_info(struct seq_file *m,
3091 struct drm_connector *connector)
3092{
3093 struct intel_connector *intel_connector = to_intel_connector(connector);
3094 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08003095 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003096
3097 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03003098 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003099 drm_get_connector_status_name(connector->status));
3100 if (connector->status == connector_status_connected) {
3101 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3102 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3103 connector->display_info.width_mm,
3104 connector->display_info.height_mm);
3105 seq_printf(m, "\tsubpixel order: %s\n",
3106 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3107 seq_printf(m, "\tCEA rev: %d\n",
3108 connector->display_info.cea_rev);
3109 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003110
Maarten Lankhorst77d1f612017-06-26 10:33:49 +02003111 if (!intel_encoder)
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003112 return;
3113
3114 switch (connector->connector_type) {
3115 case DRM_MODE_CONNECTOR_DisplayPort:
3116 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003117 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3118 intel_dp_mst_info(m, intel_connector);
3119 else
3120 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003121 break;
3122 case DRM_MODE_CONNECTOR_LVDS:
3123 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003124 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003125 break;
3126 case DRM_MODE_CONNECTOR_HDMIA:
3127 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3128 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3129 intel_hdmi_info(m, intel_connector);
3130 break;
3131 default:
3132 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003133 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003134
Jesse Barnesf103fc72014-02-20 12:39:57 -08003135 seq_printf(m, "\tmodes:\n");
3136 list_for_each_entry(mode, &connector->modes, head)
3137 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003138}
3139
Robert Fekete3abc4e02015-10-27 16:58:32 +01003140static const char *plane_type(enum drm_plane_type type)
3141{
3142 switch (type) {
3143 case DRM_PLANE_TYPE_OVERLAY:
3144 return "OVL";
3145 case DRM_PLANE_TYPE_PRIMARY:
3146 return "PRI";
3147 case DRM_PLANE_TYPE_CURSOR:
3148 return "CUR";
3149 /*
3150 * Deliberately omitting default: to generate compiler warnings
3151 * when a new drm_plane_type gets added.
3152 */
3153 }
3154
3155 return "unknown";
3156}
3157
3158static const char *plane_rotation(unsigned int rotation)
3159{
3160 static char buf[48];
3161 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003162 * According to doc only one DRM_MODE_ROTATE_ is allowed but this
Robert Fekete3abc4e02015-10-27 16:58:32 +01003163 * will print them all to visualize if the values are misused
3164 */
3165 snprintf(buf, sizeof(buf),
3166 "%s%s%s%s%s%s(0x%08x)",
Robert Fossc2c446a2017-05-19 16:50:17 -04003167 (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
3168 (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
3169 (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
3170 (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
3171 (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
3172 (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003173 rotation);
3174
3175 return buf;
3176}
3177
3178static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3179{
David Weinehall36cdd012016-08-22 13:59:31 +03003180 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3181 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003182 struct intel_plane *intel_plane;
3183
3184 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3185 struct drm_plane_state *state;
3186 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003187 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003188
3189 if (!plane->state) {
3190 seq_puts(m, "plane->state is NULL!\n");
3191 continue;
3192 }
3193
3194 state = plane->state;
3195
Eric Engestrom90844f02016-08-15 01:02:38 +01003196 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003197 drm_get_format_name(state->fb->format->format,
3198 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003199 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003200 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003201 }
3202
Robert Fekete3abc4e02015-10-27 16:58:32 +01003203 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",
3204 plane->base.id,
3205 plane_type(intel_plane->base.type),
3206 state->crtc_x, state->crtc_y,
3207 state->crtc_w, state->crtc_h,
3208 (state->src_x >> 16),
3209 ((state->src_x & 0xffff) * 15625) >> 10,
3210 (state->src_y >> 16),
3211 ((state->src_y & 0xffff) * 15625) >> 10,
3212 (state->src_w >> 16),
3213 ((state->src_w & 0xffff) * 15625) >> 10,
3214 (state->src_h >> 16),
3215 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003216 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003217 plane_rotation(state->rotation));
3218 }
3219}
3220
3221static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3222{
3223 struct intel_crtc_state *pipe_config;
3224 int num_scalers = intel_crtc->num_scalers;
3225 int i;
3226
3227 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3228
3229 /* Not all platformas have a scaler */
3230 if (num_scalers) {
3231 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3232 num_scalers,
3233 pipe_config->scaler_state.scaler_users,
3234 pipe_config->scaler_state.scaler_id);
3235
A.Sunil Kamath58415912016-11-20 23:20:26 +05303236 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003237 struct intel_scaler *sc =
3238 &pipe_config->scaler_state.scalers[i];
3239
3240 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3241 i, yesno(sc->in_use), sc->mode);
3242 }
3243 seq_puts(m, "\n");
3244 } else {
3245 seq_puts(m, "\tNo scalers available on this platform\n");
3246 }
3247}
3248
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003249static int i915_display_info(struct seq_file *m, void *unused)
3250{
David Weinehall36cdd012016-08-22 13:59:31 +03003251 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3252 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003253 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003254 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003255 struct drm_connector_list_iter conn_iter;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003256
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003257 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003258 seq_printf(m, "CRTC info\n");
3259 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003260 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003261 struct intel_crtc_state *pipe_config;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003262
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003263 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003264 pipe_config = to_intel_crtc_state(crtc->base.state);
3265
Robert Fekete3abc4e02015-10-27 16:58:32 +01003266 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003267 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003268 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003269 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3270 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3271
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003272 if (pipe_config->base.active) {
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003273 struct intel_plane *cursor =
3274 to_intel_plane(crtc->base.cursor);
3275
Chris Wilson065f2ec22014-03-12 09:13:13 +00003276 intel_crtc_info(m, crtc);
3277
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003278 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x\n",
3279 yesno(cursor->base.state->visible),
3280 cursor->base.state->crtc_x,
3281 cursor->base.state->crtc_y,
3282 cursor->base.state->crtc_w,
3283 cursor->base.state->crtc_h,
3284 cursor->cursor.base);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003285 intel_scaler_info(m, crtc);
3286 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003287 }
Daniel Vettercace8412014-05-22 17:56:31 +02003288
3289 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3290 yesno(!crtc->cpu_fifo_underrun_disabled),
3291 yesno(!crtc->pch_fifo_underrun_disabled));
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003292 drm_modeset_unlock(&crtc->base.mutex);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003293 }
3294
3295 seq_printf(m, "\n");
3296 seq_printf(m, "Connector info\n");
3297 seq_printf(m, "--------------\n");
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003298 mutex_lock(&dev->mode_config.mutex);
3299 drm_connector_list_iter_begin(dev, &conn_iter);
3300 drm_for_each_connector_iter(connector, &conn_iter)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003301 intel_connector_info(m, connector);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003302 drm_connector_list_iter_end(&conn_iter);
3303 mutex_unlock(&dev->mode_config.mutex);
3304
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003305 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003306
3307 return 0;
3308}
3309
Chris Wilson1b365952016-10-04 21:11:31 +01003310static int i915_engine_info(struct seq_file *m, void *unused)
3311{
3312 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michel Thierry061d06a2017-06-20 10:57:49 +01003313 struct i915_gpu_error *error = &dev_priv->gpu_error;
Chris Wilson1b365952016-10-04 21:11:31 +01003314 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303315 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003316
Chris Wilson9c870d02016-10-24 13:42:15 +01003317 intel_runtime_pm_get(dev_priv);
3318
Chris Wilsonf73b5672017-03-02 15:03:56 +00003319 seq_printf(m, "GT awake? %s\n",
3320 yesno(dev_priv->gt.awake));
3321 seq_printf(m, "Global active requests: %d\n",
3322 dev_priv->gt.active_requests);
3323
Akash Goel3b3f1652016-10-13 22:44:48 +05303324 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003325 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3326 struct drm_i915_gem_request *rq;
3327 struct rb_node *rb;
3328 u64 addr;
3329
3330 seq_printf(m, "%s\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003331 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003332 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003333 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003334 engine->hangcheck.seqno,
Chris Wilsonf73b5672017-03-02 15:03:56 +00003335 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp),
3336 engine->timeline->inflight_seqnos);
Michel Thierry061d06a2017-06-20 10:57:49 +01003337 seq_printf(m, "\tReset count: %d\n",
3338 i915_reset_engine_count(error, engine));
Chris Wilson1b365952016-10-04 21:11:31 +01003339
3340 rcu_read_lock();
3341
3342 seq_printf(m, "\tRequests:\n");
3343
Chris Wilson73cb9702016-10-28 13:58:46 +01003344 rq = list_first_entry(&engine->timeline->requests,
3345 struct drm_i915_gem_request, link);
3346 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003347 print_request(m, rq, "\t\tfirst ");
3348
Chris Wilson73cb9702016-10-28 13:58:46 +01003349 rq = list_last_entry(&engine->timeline->requests,
3350 struct drm_i915_gem_request, link);
3351 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003352 print_request(m, rq, "\t\tlast ");
3353
3354 rq = i915_gem_find_active_request(engine);
3355 if (rq) {
3356 print_request(m, rq, "\t\tactive ");
3357 seq_printf(m,
3358 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3359 rq->head, rq->postfix, rq->tail,
3360 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3361 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3362 }
3363
3364 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3365 I915_READ(RING_START(engine->mmio_base)),
3366 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3367 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3368 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3369 rq ? rq->ring->head : 0);
3370 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3371 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3372 rq ? rq->ring->tail : 0);
3373 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3374 I915_READ(RING_CTL(engine->mmio_base)),
3375 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3376
3377 rcu_read_unlock();
3378
3379 addr = intel_engine_get_active_head(engine);
3380 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3381 upper_32_bits(addr), lower_32_bits(addr));
3382 addr = intel_engine_get_last_batch_head(engine);
3383 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3384 upper_32_bits(addr), lower_32_bits(addr));
3385
3386 if (i915.enable_execlists) {
3387 u32 ptr, read, write;
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003388 unsigned int idx;
Chris Wilson1b365952016-10-04 21:11:31 +01003389
3390 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3391 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3392 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3393
3394 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3395 read = GEN8_CSB_READ_PTR(ptr);
3396 write = GEN8_CSB_WRITE_PTR(ptr);
3397 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3398 read, write);
3399 if (read >= GEN8_CSB_ENTRIES)
3400 read = 0;
3401 if (write >= GEN8_CSB_ENTRIES)
3402 write = 0;
3403 if (read > write)
3404 write += GEN8_CSB_ENTRIES;
3405 while (read < write) {
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003406 idx = ++read % GEN8_CSB_ENTRIES;
Chris Wilson1b365952016-10-04 21:11:31 +01003407 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3408 idx,
3409 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3410 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3411 }
3412
3413 rcu_read_lock();
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003414 for (idx = 0; idx < ARRAY_SIZE(engine->execlist_port); idx++) {
3415 unsigned int count;
3416
3417 rq = port_unpack(&engine->execlist_port[idx],
3418 &count);
3419 if (rq) {
3420 seq_printf(m, "\t\tELSP[%d] count=%d, ",
3421 idx, count);
3422 print_request(m, rq, "rq: ");
3423 } else {
3424 seq_printf(m, "\t\tELSP[%d] idle\n",
3425 idx);
3426 }
Chris Wilson816ee792017-01-24 11:00:03 +00003427 }
Chris Wilson1b365952016-10-04 21:11:31 +01003428 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003429
Chris Wilson663f71e2016-11-14 20:41:00 +00003430 spin_lock_irq(&engine->timeline->lock);
Chris Wilson6c067572017-05-17 13:10:03 +01003431 for (rb = engine->execlist_first; rb; rb = rb_next(rb)){
3432 struct i915_priolist *p =
3433 rb_entry(rb, typeof(*p), node);
3434
3435 list_for_each_entry(rq, &p->requests,
3436 priotree.link)
3437 print_request(m, rq, "\t\tQ ");
Chris Wilsonc8247c02016-10-27 01:03:43 +01003438 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003439 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003440 } else if (INTEL_GEN(dev_priv) > 6) {
3441 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3442 I915_READ(RING_PP_DIR_BASE(engine)));
3443 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3444 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3445 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3446 I915_READ(RING_PP_DIR_DCLV(engine)));
3447 }
3448
Chris Wilson61d3dc72017-03-03 19:08:24 +00003449 spin_lock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003450 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08003451 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson1b365952016-10-04 21:11:31 +01003452
3453 seq_printf(m, "\t%s [%d] waiting for %x\n",
3454 w->tsk->comm, w->tsk->pid, w->seqno);
3455 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00003456 spin_unlock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003457
3458 seq_puts(m, "\n");
3459 }
3460
Chris Wilson9c870d02016-10-24 13:42:15 +01003461 intel_runtime_pm_put(dev_priv);
3462
Chris Wilson1b365952016-10-04 21:11:31 +01003463 return 0;
3464}
3465
Ben Widawskye04934c2014-06-30 09:53:42 -07003466static int i915_semaphore_status(struct seq_file *m, void *unused)
3467{
David Weinehall36cdd012016-08-22 13:59:31 +03003468 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3469 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003470 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003471 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003472 enum intel_engine_id id;
3473 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003474
Chris Wilson39df9192016-07-20 13:31:57 +01003475 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003476 seq_puts(m, "Semaphores are disabled\n");
3477 return 0;
3478 }
3479
3480 ret = mutex_lock_interruptible(&dev->struct_mutex);
3481 if (ret)
3482 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003483 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003484
David Weinehall36cdd012016-08-22 13:59:31 +03003485 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003486 struct page *page;
3487 uint64_t *seqno;
3488
Chris Wilson51d545d2016-08-15 10:49:02 +01003489 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003490
3491 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303492 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003493 uint64_t offset;
3494
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003495 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003496
3497 seq_puts(m, " Last signal:");
3498 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003499 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003500 seq_printf(m, "0x%08llx (0x%02llx) ",
3501 seqno[offset], offset * 8);
3502 }
3503 seq_putc(m, '\n');
3504
3505 seq_puts(m, " Last wait: ");
3506 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003507 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003508 seq_printf(m, "0x%08llx (0x%02llx) ",
3509 seqno[offset], offset * 8);
3510 }
3511 seq_putc(m, '\n');
3512
3513 }
3514 kunmap_atomic(seqno);
3515 } else {
3516 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303517 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003518 for (j = 0; j < num_rings; j++)
3519 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003520 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003521 seq_putc(m, '\n');
3522 }
3523
Paulo Zanoni03872062014-07-09 14:31:57 -03003524 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003525 mutex_unlock(&dev->struct_mutex);
3526 return 0;
3527}
3528
Daniel Vetter728e29d2014-06-25 22:01:53 +03003529static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3530{
David Weinehall36cdd012016-08-22 13:59:31 +03003531 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3532 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003533 int i;
3534
3535 drm_modeset_lock_all(dev);
3536 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3537 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3538
3539 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003540 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003541 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003542 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003543 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003544 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003545 pll->state.hw_state.dpll_md);
3546 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3547 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3548 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003549 }
3550 drm_modeset_unlock_all(dev);
3551
3552 return 0;
3553}
3554
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003555static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003556{
3557 int i;
3558 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003559 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003560 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3561 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003562 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003563 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003564
Arun Siluvery888b5992014-08-26 14:44:51 +01003565 ret = mutex_lock_interruptible(&dev->struct_mutex);
3566 if (ret)
3567 return ret;
3568
3569 intel_runtime_pm_get(dev_priv);
3570
Arun Siluvery33136b02016-01-21 21:43:47 +00003571 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303572 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003573 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003574 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003575 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003576 i915_reg_t addr;
3577 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003578 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003579
Arun Siluvery33136b02016-01-21 21:43:47 +00003580 addr = workarounds->reg[i].addr;
3581 mask = workarounds->reg[i].mask;
3582 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003583 read = I915_READ(addr);
3584 ok = (value & mask) == (read & mask);
3585 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 +02003586 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003587 }
3588
3589 intel_runtime_pm_put(dev_priv);
3590 mutex_unlock(&dev->struct_mutex);
3591
3592 return 0;
3593}
3594
Damien Lespiauc5511e42014-11-04 17:06:51 +00003595static int i915_ddb_info(struct seq_file *m, void *unused)
3596{
David Weinehall36cdd012016-08-22 13:59:31 +03003597 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3598 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003599 struct skl_ddb_allocation *ddb;
3600 struct skl_ddb_entry *entry;
3601 enum pipe pipe;
3602 int plane;
3603
David Weinehall36cdd012016-08-22 13:59:31 +03003604 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003605 return 0;
3606
Damien Lespiauc5511e42014-11-04 17:06:51 +00003607 drm_modeset_lock_all(dev);
3608
3609 ddb = &dev_priv->wm.skl_hw.ddb;
3610
3611 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3612
3613 for_each_pipe(dev_priv, pipe) {
3614 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3615
Matt Roper8b364b42016-10-26 15:51:28 -07003616 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003617 entry = &ddb->plane[pipe][plane];
3618 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3619 entry->start, entry->end,
3620 skl_ddb_entry_size(entry));
3621 }
3622
Matt Roper4969d332015-09-24 15:53:10 -07003623 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003624 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3625 entry->end, skl_ddb_entry_size(entry));
3626 }
3627
3628 drm_modeset_unlock_all(dev);
3629
3630 return 0;
3631}
3632
Vandana Kannana54746e2015-03-03 20:53:10 +05303633static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003634 struct drm_device *dev,
3635 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303636{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003637 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303638 struct i915_drrs *drrs = &dev_priv->drrs;
3639 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003640 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003641 struct drm_connector_list_iter conn_iter;
Vandana Kannana54746e2015-03-03 20:53:10 +05303642
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003643 drm_connector_list_iter_begin(dev, &conn_iter);
3644 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003645 if (connector->state->crtc != &intel_crtc->base)
3646 continue;
3647
3648 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303649 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003650 drm_connector_list_iter_end(&conn_iter);
Vandana Kannana54746e2015-03-03 20:53:10 +05303651
3652 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3653 seq_puts(m, "\tVBT: DRRS_type: Static");
3654 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3655 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3656 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3657 seq_puts(m, "\tVBT: DRRS_type: None");
3658 else
3659 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3660
3661 seq_puts(m, "\n\n");
3662
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003663 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303664 struct intel_panel *panel;
3665
3666 mutex_lock(&drrs->mutex);
3667 /* DRRS Supported */
3668 seq_puts(m, "\tDRRS Supported: Yes\n");
3669
3670 /* disable_drrs() will make drrs->dp NULL */
3671 if (!drrs->dp) {
3672 seq_puts(m, "Idleness DRRS: Disabled");
3673 mutex_unlock(&drrs->mutex);
3674 return;
3675 }
3676
3677 panel = &drrs->dp->attached_connector->panel;
3678 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3679 drrs->busy_frontbuffer_bits);
3680
3681 seq_puts(m, "\n\t\t");
3682 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3683 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3684 vrefresh = panel->fixed_mode->vrefresh;
3685 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3686 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3687 vrefresh = panel->downclock_mode->vrefresh;
3688 } else {
3689 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3690 drrs->refresh_rate_type);
3691 mutex_unlock(&drrs->mutex);
3692 return;
3693 }
3694 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3695
3696 seq_puts(m, "\n\t\t");
3697 mutex_unlock(&drrs->mutex);
3698 } else {
3699 /* DRRS not supported. Print the VBT parameter*/
3700 seq_puts(m, "\tDRRS Supported : No");
3701 }
3702 seq_puts(m, "\n");
3703}
3704
3705static int i915_drrs_status(struct seq_file *m, void *unused)
3706{
David Weinehall36cdd012016-08-22 13:59:31 +03003707 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3708 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303709 struct intel_crtc *intel_crtc;
3710 int active_crtc_cnt = 0;
3711
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003712 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303713 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003714 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303715 active_crtc_cnt++;
3716 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3717
3718 drrs_status_per_crtc(m, dev, intel_crtc);
3719 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303720 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003721 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303722
3723 if (!active_crtc_cnt)
3724 seq_puts(m, "No active crtc found\n");
3725
3726 return 0;
3727}
3728
Dave Airlie11bed952014-05-12 15:22:27 +10003729static int i915_dp_mst_info(struct seq_file *m, void *unused)
3730{
David Weinehall36cdd012016-08-22 13:59:31 +03003731 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3732 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003733 struct intel_encoder *intel_encoder;
3734 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003735 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003736 struct drm_connector_list_iter conn_iter;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003737
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003738 drm_connector_list_iter_begin(dev, &conn_iter);
3739 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003740 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003741 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003742
3743 intel_encoder = intel_attached_encoder(connector);
3744 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3745 continue;
3746
3747 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003748 if (!intel_dig_port->dp.can_mst)
3749 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003750
Jim Bride40ae80c2016-04-14 10:18:37 -07003751 seq_printf(m, "MST Source Port %c\n",
3752 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003753 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3754 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003755 drm_connector_list_iter_end(&conn_iter);
3756
Dave Airlie11bed952014-05-12 15:22:27 +10003757 return 0;
3758}
3759
Todd Previteeb3394fa2015-04-18 00:04:19 -07003760static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003761 const char __user *ubuf,
3762 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003763{
3764 char *input_buffer;
3765 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003766 struct drm_device *dev;
3767 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003768 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003769 struct intel_dp *intel_dp;
3770 int val = 0;
3771
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303772 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003773
Todd Previteeb3394fa2015-04-18 00:04:19 -07003774 if (len == 0)
3775 return 0;
3776
Geliang Tang261aeba2017-05-06 23:40:17 +08003777 input_buffer = memdup_user_nul(ubuf, len);
3778 if (IS_ERR(input_buffer))
3779 return PTR_ERR(input_buffer);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003780
Todd Previteeb3394fa2015-04-18 00:04:19 -07003781 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3782
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003783 drm_connector_list_iter_begin(dev, &conn_iter);
3784 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003785 struct intel_encoder *encoder;
3786
Todd Previteeb3394fa2015-04-18 00:04:19 -07003787 if (connector->connector_type !=
3788 DRM_MODE_CONNECTOR_DisplayPort)
3789 continue;
3790
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003791 encoder = to_intel_encoder(connector->encoder);
3792 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3793 continue;
3794
3795 if (encoder && connector->status == connector_status_connected) {
3796 intel_dp = enc_to_intel_dp(&encoder->base);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003797 status = kstrtoint(input_buffer, 10, &val);
3798 if (status < 0)
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003799 break;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003800 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3801 /* To prevent erroneous activation of the compliance
3802 * testing code, only accept an actual value of 1 here
3803 */
3804 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003805 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003806 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003807 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003808 }
3809 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003810 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003811 kfree(input_buffer);
3812 if (status < 0)
3813 return status;
3814
3815 *offp += len;
3816 return len;
3817}
3818
3819static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3820{
3821 struct drm_device *dev = m->private;
3822 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003823 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003824 struct intel_dp *intel_dp;
3825
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003826 drm_connector_list_iter_begin(dev, &conn_iter);
3827 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003828 struct intel_encoder *encoder;
3829
Todd Previteeb3394fa2015-04-18 00:04:19 -07003830 if (connector->connector_type !=
3831 DRM_MODE_CONNECTOR_DisplayPort)
3832 continue;
3833
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003834 encoder = to_intel_encoder(connector->encoder);
3835 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3836 continue;
3837
3838 if (encoder && connector->status == connector_status_connected) {
3839 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003840 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003841 seq_puts(m, "1");
3842 else
3843 seq_puts(m, "0");
3844 } else
3845 seq_puts(m, "0");
3846 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003847 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003848
3849 return 0;
3850}
3851
3852static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003853 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003854{
David Weinehall36cdd012016-08-22 13:59:31 +03003855 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003856
David Weinehall36cdd012016-08-22 13:59:31 +03003857 return single_open(file, i915_displayport_test_active_show,
3858 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003859}
3860
3861static const struct file_operations i915_displayport_test_active_fops = {
3862 .owner = THIS_MODULE,
3863 .open = i915_displayport_test_active_open,
3864 .read = seq_read,
3865 .llseek = seq_lseek,
3866 .release = single_release,
3867 .write = i915_displayport_test_active_write
3868};
3869
3870static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3871{
3872 struct drm_device *dev = m->private;
3873 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003874 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003875 struct intel_dp *intel_dp;
3876
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003877 drm_connector_list_iter_begin(dev, &conn_iter);
3878 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003879 struct intel_encoder *encoder;
3880
Todd Previteeb3394fa2015-04-18 00:04:19 -07003881 if (connector->connector_type !=
3882 DRM_MODE_CONNECTOR_DisplayPort)
3883 continue;
3884
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003885 encoder = to_intel_encoder(connector->encoder);
3886 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3887 continue;
3888
3889 if (encoder && connector->status == connector_status_connected) {
3890 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003891 if (intel_dp->compliance.test_type ==
3892 DP_TEST_LINK_EDID_READ)
3893 seq_printf(m, "%lx",
3894 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003895 else if (intel_dp->compliance.test_type ==
3896 DP_TEST_LINK_VIDEO_PATTERN) {
3897 seq_printf(m, "hdisplay: %d\n",
3898 intel_dp->compliance.test_data.hdisplay);
3899 seq_printf(m, "vdisplay: %d\n",
3900 intel_dp->compliance.test_data.vdisplay);
3901 seq_printf(m, "bpc: %u\n",
3902 intel_dp->compliance.test_data.bpc);
3903 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003904 } else
3905 seq_puts(m, "0");
3906 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003907 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003908
3909 return 0;
3910}
3911static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003912 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003913{
David Weinehall36cdd012016-08-22 13:59:31 +03003914 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003915
David Weinehall36cdd012016-08-22 13:59:31 +03003916 return single_open(file, i915_displayport_test_data_show,
3917 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003918}
3919
3920static const struct file_operations i915_displayport_test_data_fops = {
3921 .owner = THIS_MODULE,
3922 .open = i915_displayport_test_data_open,
3923 .read = seq_read,
3924 .llseek = seq_lseek,
3925 .release = single_release
3926};
3927
3928static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3929{
3930 struct drm_device *dev = m->private;
3931 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003932 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003933 struct intel_dp *intel_dp;
3934
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003935 drm_connector_list_iter_begin(dev, &conn_iter);
3936 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003937 struct intel_encoder *encoder;
3938
Todd Previteeb3394fa2015-04-18 00:04:19 -07003939 if (connector->connector_type !=
3940 DRM_MODE_CONNECTOR_DisplayPort)
3941 continue;
3942
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003943 encoder = to_intel_encoder(connector->encoder);
3944 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3945 continue;
3946
3947 if (encoder && connector->status == connector_status_connected) {
3948 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003949 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003950 } else
3951 seq_puts(m, "0");
3952 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003953 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003954
3955 return 0;
3956}
3957
3958static int i915_displayport_test_type_open(struct inode *inode,
3959 struct file *file)
3960{
David Weinehall36cdd012016-08-22 13:59:31 +03003961 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003962
David Weinehall36cdd012016-08-22 13:59:31 +03003963 return single_open(file, i915_displayport_test_type_show,
3964 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003965}
3966
3967static const struct file_operations i915_displayport_test_type_fops = {
3968 .owner = THIS_MODULE,
3969 .open = i915_displayport_test_type_open,
3970 .read = seq_read,
3971 .llseek = seq_lseek,
3972 .release = single_release
3973};
3974
Damien Lespiau97e94b22014-11-04 17:06:50 +00003975static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003976{
David Weinehall36cdd012016-08-22 13:59:31 +03003977 struct drm_i915_private *dev_priv = m->private;
3978 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003979 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003980 int num_levels;
3981
David Weinehall36cdd012016-08-22 13:59:31 +03003982 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003983 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003984 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003985 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003986 else if (IS_G4X(dev_priv))
3987 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003988 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003989 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003990
3991 drm_modeset_lock_all(dev);
3992
3993 for (level = 0; level < num_levels; level++) {
3994 unsigned int latency = wm[level];
3995
Damien Lespiau97e94b22014-11-04 17:06:50 +00003996 /*
3997 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003998 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003999 */
Ville Syrjälä04548cb2017-04-21 21:14:29 +03004000 if (INTEL_GEN(dev_priv) >= 9 ||
4001 IS_VALLEYVIEW(dev_priv) ||
4002 IS_CHERRYVIEW(dev_priv) ||
4003 IS_G4X(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004004 latency *= 10;
4005 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004006 latency *= 5;
4007
4008 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004009 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004010 }
4011
4012 drm_modeset_unlock_all(dev);
4013}
4014
4015static int pri_wm_latency_show(struct seq_file *m, void *data)
4016{
David Weinehall36cdd012016-08-22 13:59:31 +03004017 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004018 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004019
David Weinehall36cdd012016-08-22 13:59:31 +03004020 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004021 latencies = dev_priv->wm.skl_latency;
4022 else
David Weinehall36cdd012016-08-22 13:59:31 +03004023 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004024
4025 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004026
4027 return 0;
4028}
4029
4030static int spr_wm_latency_show(struct seq_file *m, void *data)
4031{
David Weinehall36cdd012016-08-22 13:59:31 +03004032 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004033 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004034
David Weinehall36cdd012016-08-22 13:59:31 +03004035 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004036 latencies = dev_priv->wm.skl_latency;
4037 else
David Weinehall36cdd012016-08-22 13:59:31 +03004038 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004039
4040 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004041
4042 return 0;
4043}
4044
4045static int cur_wm_latency_show(struct seq_file *m, void *data)
4046{
David Weinehall36cdd012016-08-22 13:59:31 +03004047 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004048 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004049
David Weinehall36cdd012016-08-22 13:59:31 +03004050 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004051 latencies = dev_priv->wm.skl_latency;
4052 else
David Weinehall36cdd012016-08-22 13:59:31 +03004053 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004054
4055 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004056
4057 return 0;
4058}
4059
4060static int pri_wm_latency_open(struct inode *inode, struct file *file)
4061{
David Weinehall36cdd012016-08-22 13:59:31 +03004062 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004063
Ville Syrjälä04548cb2017-04-21 21:14:29 +03004064 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004065 return -ENODEV;
4066
David Weinehall36cdd012016-08-22 13:59:31 +03004067 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004068}
4069
4070static int spr_wm_latency_open(struct inode *inode, struct file *file)
4071{
David Weinehall36cdd012016-08-22 13:59:31 +03004072 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004073
David Weinehall36cdd012016-08-22 13:59:31 +03004074 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004075 return -ENODEV;
4076
David Weinehall36cdd012016-08-22 13:59:31 +03004077 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004078}
4079
4080static int cur_wm_latency_open(struct inode *inode, struct file *file)
4081{
David Weinehall36cdd012016-08-22 13:59:31 +03004082 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004083
David Weinehall36cdd012016-08-22 13:59:31 +03004084 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004085 return -ENODEV;
4086
David Weinehall36cdd012016-08-22 13:59:31 +03004087 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004088}
4089
4090static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004091 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004092{
4093 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004094 struct drm_i915_private *dev_priv = m->private;
4095 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004096 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004097 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004098 int level;
4099 int ret;
4100 char tmp[32];
4101
David Weinehall36cdd012016-08-22 13:59:31 +03004102 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004103 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004104 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004105 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03004106 else if (IS_G4X(dev_priv))
4107 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004108 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004109 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004110
Ville Syrjälä369a1342014-01-22 14:36:08 +02004111 if (len >= sizeof(tmp))
4112 return -EINVAL;
4113
4114 if (copy_from_user(tmp, ubuf, len))
4115 return -EFAULT;
4116
4117 tmp[len] = '\0';
4118
Damien Lespiau97e94b22014-11-04 17:06:50 +00004119 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4120 &new[0], &new[1], &new[2], &new[3],
4121 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004122 if (ret != num_levels)
4123 return -EINVAL;
4124
4125 drm_modeset_lock_all(dev);
4126
4127 for (level = 0; level < num_levels; level++)
4128 wm[level] = new[level];
4129
4130 drm_modeset_unlock_all(dev);
4131
4132 return len;
4133}
4134
4135
4136static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4137 size_t len, loff_t *offp)
4138{
4139 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004140 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004141 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004142
David Weinehall36cdd012016-08-22 13:59:31 +03004143 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004144 latencies = dev_priv->wm.skl_latency;
4145 else
David Weinehall36cdd012016-08-22 13:59:31 +03004146 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004147
4148 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004149}
4150
4151static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4152 size_t len, loff_t *offp)
4153{
4154 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004155 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004156 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004157
David Weinehall36cdd012016-08-22 13:59:31 +03004158 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004159 latencies = dev_priv->wm.skl_latency;
4160 else
David Weinehall36cdd012016-08-22 13:59:31 +03004161 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004162
4163 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004164}
4165
4166static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4167 size_t len, loff_t *offp)
4168{
4169 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004170 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004171 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004172
David Weinehall36cdd012016-08-22 13:59:31 +03004173 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004174 latencies = dev_priv->wm.skl_latency;
4175 else
David Weinehall36cdd012016-08-22 13:59:31 +03004176 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004177
4178 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004179}
4180
4181static const struct file_operations i915_pri_wm_latency_fops = {
4182 .owner = THIS_MODULE,
4183 .open = pri_wm_latency_open,
4184 .read = seq_read,
4185 .llseek = seq_lseek,
4186 .release = single_release,
4187 .write = pri_wm_latency_write
4188};
4189
4190static const struct file_operations i915_spr_wm_latency_fops = {
4191 .owner = THIS_MODULE,
4192 .open = spr_wm_latency_open,
4193 .read = seq_read,
4194 .llseek = seq_lseek,
4195 .release = single_release,
4196 .write = spr_wm_latency_write
4197};
4198
4199static const struct file_operations i915_cur_wm_latency_fops = {
4200 .owner = THIS_MODULE,
4201 .open = cur_wm_latency_open,
4202 .read = seq_read,
4203 .llseek = seq_lseek,
4204 .release = single_release,
4205 .write = cur_wm_latency_write
4206};
4207
Kees Cook647416f2013-03-10 14:10:06 -07004208static int
4209i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004210{
David Weinehall36cdd012016-08-22 13:59:31 +03004211 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004212
Chris Wilsond98c52c2016-04-13 17:35:05 +01004213 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004214
Kees Cook647416f2013-03-10 14:10:06 -07004215 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004216}
4217
Kees Cook647416f2013-03-10 14:10:06 -07004218static int
4219i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004220{
Chris Wilson598b6b52017-03-25 13:47:35 +00004221 struct drm_i915_private *i915 = data;
4222 struct intel_engine_cs *engine;
4223 unsigned int tmp;
Imre Deakd46c0512014-04-14 20:24:27 +03004224
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004225 /*
4226 * There is no safeguard against this debugfs entry colliding
4227 * with the hangcheck calling same i915_handle_error() in
4228 * parallel, causing an explosion. For now we assume that the
4229 * test harness is responsible enough not to inject gpu hangs
4230 * while it is writing to 'i915_wedged'
4231 */
4232
Chris Wilson598b6b52017-03-25 13:47:35 +00004233 if (i915_reset_backoff(&i915->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004234 return -EAGAIN;
4235
Chris Wilson598b6b52017-03-25 13:47:35 +00004236 for_each_engine_masked(engine, i915, val, tmp) {
4237 engine->hangcheck.seqno = intel_engine_get_seqno(engine);
4238 engine->hangcheck.stalled = true;
4239 }
Imre Deakd46c0512014-04-14 20:24:27 +03004240
Chris Wilson598b6b52017-03-25 13:47:35 +00004241 i915_handle_error(i915, val, "Manually setting wedged to %llu", val);
4242
4243 wait_on_bit(&i915->gpu_error.flags,
Chris Wilsond3df42b2017-03-16 17:13:05 +00004244 I915_RESET_HANDOFF,
4245 TASK_UNINTERRUPTIBLE);
4246
Kees Cook647416f2013-03-10 14:10:06 -07004247 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004248}
4249
Kees Cook647416f2013-03-10 14:10:06 -07004250DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4251 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004252 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004253
Kees Cook647416f2013-03-10 14:10:06 -07004254static int
Chris Wilson64486ae2017-03-07 15:59:08 +00004255fault_irq_set(struct drm_i915_private *i915,
4256 unsigned long *irq,
4257 unsigned long val)
4258{
4259 int err;
4260
4261 err = mutex_lock_interruptible(&i915->drm.struct_mutex);
4262 if (err)
4263 return err;
4264
4265 err = i915_gem_wait_for_idle(i915,
4266 I915_WAIT_LOCKED |
4267 I915_WAIT_INTERRUPTIBLE);
4268 if (err)
4269 goto err_unlock;
4270
Chris Wilson64486ae2017-03-07 15:59:08 +00004271 *irq = val;
4272 mutex_unlock(&i915->drm.struct_mutex);
4273
4274 /* Flush idle worker to disarm irq */
4275 while (flush_delayed_work(&i915->gt.idle_work))
4276 ;
4277
4278 return 0;
4279
4280err_unlock:
4281 mutex_unlock(&i915->drm.struct_mutex);
4282 return err;
4283}
4284
4285static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004286i915_ring_missed_irq_get(void *data, u64 *val)
4287{
David Weinehall36cdd012016-08-22 13:59:31 +03004288 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004289
4290 *val = dev_priv->gpu_error.missed_irq_rings;
4291 return 0;
4292}
4293
4294static int
4295i915_ring_missed_irq_set(void *data, u64 val)
4296{
Chris Wilson64486ae2017-03-07 15:59:08 +00004297 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004298
Chris Wilson64486ae2017-03-07 15:59:08 +00004299 return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004300}
4301
4302DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4303 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4304 "0x%08llx\n");
4305
4306static int
4307i915_ring_test_irq_get(void *data, u64 *val)
4308{
David Weinehall36cdd012016-08-22 13:59:31 +03004309 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004310
4311 *val = dev_priv->gpu_error.test_irq_rings;
4312
4313 return 0;
4314}
4315
4316static int
4317i915_ring_test_irq_set(void *data, u64 val)
4318{
Chris Wilson64486ae2017-03-07 15:59:08 +00004319 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004320
Chris Wilson64486ae2017-03-07 15:59:08 +00004321 val &= INTEL_INFO(i915)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004322 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004323
Chris Wilson64486ae2017-03-07 15:59:08 +00004324 return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004325}
4326
4327DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4328 i915_ring_test_irq_get, i915_ring_test_irq_set,
4329 "0x%08llx\n");
4330
Chris Wilsondd624af2013-01-15 12:39:35 +00004331#define DROP_UNBOUND 0x1
4332#define DROP_BOUND 0x2
4333#define DROP_RETIRE 0x4
4334#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004335#define DROP_FREED 0x10
Chris Wilson8eadc192017-03-08 14:46:22 +00004336#define DROP_SHRINK_ALL 0x20
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004337#define DROP_ALL (DROP_UNBOUND | \
4338 DROP_BOUND | \
4339 DROP_RETIRE | \
4340 DROP_ACTIVE | \
Chris Wilson8eadc192017-03-08 14:46:22 +00004341 DROP_FREED | \
4342 DROP_SHRINK_ALL)
Kees Cook647416f2013-03-10 14:10:06 -07004343static int
4344i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004345{
Kees Cook647416f2013-03-10 14:10:06 -07004346 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004347
Kees Cook647416f2013-03-10 14:10:06 -07004348 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004349}
4350
Kees Cook647416f2013-03-10 14:10:06 -07004351static int
4352i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004353{
David Weinehall36cdd012016-08-22 13:59:31 +03004354 struct drm_i915_private *dev_priv = data;
4355 struct drm_device *dev = &dev_priv->drm;
Chris Wilson00c26cf2017-05-24 17:26:53 +01004356 int ret = 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004357
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004358 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004359
4360 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4361 * on ioctls on -EAGAIN. */
Chris Wilson00c26cf2017-05-24 17:26:53 +01004362 if (val & (DROP_ACTIVE | DROP_RETIRE)) {
4363 ret = mutex_lock_interruptible(&dev->struct_mutex);
Chris Wilsondd624af2013-01-15 12:39:35 +00004364 if (ret)
Chris Wilson00c26cf2017-05-24 17:26:53 +01004365 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004366
Chris Wilson00c26cf2017-05-24 17:26:53 +01004367 if (val & DROP_ACTIVE)
4368 ret = i915_gem_wait_for_idle(dev_priv,
4369 I915_WAIT_INTERRUPTIBLE |
4370 I915_WAIT_LOCKED);
4371
4372 if (val & DROP_RETIRE)
4373 i915_gem_retire_requests(dev_priv);
4374
4375 mutex_unlock(&dev->struct_mutex);
4376 }
Chris Wilsondd624af2013-01-15 12:39:35 +00004377
Daniel Vetter05df49e2017-03-12 21:53:40 +01004378 lockdep_set_current_reclaim_state(GFP_KERNEL);
Chris Wilson21ab4e72014-09-09 11:16:08 +01004379 if (val & DROP_BOUND)
4380 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004381
Chris Wilson21ab4e72014-09-09 11:16:08 +01004382 if (val & DROP_UNBOUND)
4383 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004384
Chris Wilson8eadc192017-03-08 14:46:22 +00004385 if (val & DROP_SHRINK_ALL)
4386 i915_gem_shrink_all(dev_priv);
Daniel Vetter05df49e2017-03-12 21:53:40 +01004387 lockdep_clear_current_reclaim_state();
Chris Wilson8eadc192017-03-08 14:46:22 +00004388
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004389 if (val & DROP_FREED) {
4390 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004391 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004392 }
4393
Kees Cook647416f2013-03-10 14:10:06 -07004394 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004395}
4396
Kees Cook647416f2013-03-10 14:10:06 -07004397DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4398 i915_drop_caches_get, i915_drop_caches_set,
4399 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004400
Kees Cook647416f2013-03-10 14:10:06 -07004401static int
4402i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004403{
David Weinehall36cdd012016-08-22 13:59:31 +03004404 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004405
David Weinehall36cdd012016-08-22 13:59:31 +03004406 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004407 return -ENODEV;
4408
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004409 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004410 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004411}
4412
Kees Cook647416f2013-03-10 14:10:06 -07004413static int
4414i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004415{
David Weinehall36cdd012016-08-22 13:59:31 +03004416 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304417 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004418 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004419
David Weinehall36cdd012016-08-22 13:59:31 +03004420 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004421 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004422
Kees Cook647416f2013-03-10 14:10:06 -07004423 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004424
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004425 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004426 if (ret)
4427 return ret;
4428
Jesse Barnes358733e2011-07-27 11:53:01 -07004429 /*
4430 * Turbo will still be enabled, but won't go above the set value.
4431 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304432 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004433
Akash Goelbc4d91f2015-02-26 16:09:47 +05304434 hw_max = dev_priv->rps.max_freq;
4435 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004436
Ben Widawskyb39fb292014-03-19 18:31:11 -07004437 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004438 mutex_unlock(&dev_priv->rps.hw_lock);
4439 return -EINVAL;
4440 }
4441
Ben Widawskyb39fb292014-03-19 18:31:11 -07004442 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004443
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004444 if (intel_set_rps(dev_priv, val))
4445 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004446
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004447 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004448
Kees Cook647416f2013-03-10 14:10:06 -07004449 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004450}
4451
Kees Cook647416f2013-03-10 14:10:06 -07004452DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4453 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004454 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004455
Kees Cook647416f2013-03-10 14:10:06 -07004456static int
4457i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004458{
David Weinehall36cdd012016-08-22 13:59:31 +03004459 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004460
Chris Wilson62e1baa2016-07-13 09:10:36 +01004461 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004462 return -ENODEV;
4463
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004464 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004465 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004466}
4467
Kees Cook647416f2013-03-10 14:10:06 -07004468static int
4469i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004470{
David Weinehall36cdd012016-08-22 13:59:31 +03004471 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304472 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004473 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004474
Chris Wilson62e1baa2016-07-13 09:10:36 +01004475 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004476 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004477
Kees Cook647416f2013-03-10 14:10:06 -07004478 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004479
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004480 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004481 if (ret)
4482 return ret;
4483
Jesse Barnes1523c312012-05-25 12:34:54 -07004484 /*
4485 * Turbo will still be enabled, but won't go below the set value.
4486 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304487 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004488
Akash Goelbc4d91f2015-02-26 16:09:47 +05304489 hw_max = dev_priv->rps.max_freq;
4490 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004491
David Weinehall36cdd012016-08-22 13:59:31 +03004492 if (val < hw_min ||
4493 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004494 mutex_unlock(&dev_priv->rps.hw_lock);
4495 return -EINVAL;
4496 }
4497
Ben Widawskyb39fb292014-03-19 18:31:11 -07004498 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004499
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004500 if (intel_set_rps(dev_priv, val))
4501 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004502
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004503 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004504
Kees Cook647416f2013-03-10 14:10:06 -07004505 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004506}
4507
Kees Cook647416f2013-03-10 14:10:06 -07004508DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4509 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004510 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004511
Kees Cook647416f2013-03-10 14:10:06 -07004512static int
4513i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004514{
David Weinehall36cdd012016-08-22 13:59:31 +03004515 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004516 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004517
David Weinehall36cdd012016-08-22 13:59:31 +03004518 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004519 return -ENODEV;
4520
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004521 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004522
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004523 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004524
4525 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004526
Kees Cook647416f2013-03-10 14:10:06 -07004527 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004528
Kees Cook647416f2013-03-10 14:10:06 -07004529 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004530}
4531
Kees Cook647416f2013-03-10 14:10:06 -07004532static int
4533i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004534{
David Weinehall36cdd012016-08-22 13:59:31 +03004535 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004536 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004537
David Weinehall36cdd012016-08-22 13:59:31 +03004538 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004539 return -ENODEV;
4540
Kees Cook647416f2013-03-10 14:10:06 -07004541 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004542 return -EINVAL;
4543
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004544 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004545 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004546
4547 /* Update the cache sharing policy here as well */
4548 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4549 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4550 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4551 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4552
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004553 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004554 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004555}
4556
Kees Cook647416f2013-03-10 14:10:06 -07004557DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4558 i915_cache_sharing_get, i915_cache_sharing_set,
4559 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004560
David Weinehall36cdd012016-08-22 13:59:31 +03004561static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004562 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004563{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004564 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004565 int ss;
4566 u32 sig1[ss_max], sig2[ss_max];
4567
4568 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4569 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4570 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4571 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4572
4573 for (ss = 0; ss < ss_max; ss++) {
4574 unsigned int eu_cnt;
4575
4576 if (sig1[ss] & CHV_SS_PG_ENABLE)
4577 /* skip disabled subslice */
4578 continue;
4579
Imre Deakf08a0c92016-08-31 19:13:04 +03004580 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004581 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004582 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4583 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4584 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4585 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004586 sseu->eu_total += eu_cnt;
4587 sseu->eu_per_subslice = max_t(unsigned int,
4588 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004589 }
Jeff McGee5d395252015-04-03 18:13:17 -07004590}
4591
David Weinehall36cdd012016-08-22 13:59:31 +03004592static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004593 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004594{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004595 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004596 int s, ss;
4597 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4598
Jeff McGee1c046bc2015-04-03 18:13:18 -07004599 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004600 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004601 s_max = 1;
4602 ss_max = 3;
4603 }
4604
4605 for (s = 0; s < s_max; s++) {
4606 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4607 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4608 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4609 }
4610
Jeff McGee5d395252015-04-03 18:13:17 -07004611 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4612 GEN9_PGCTL_SSA_EU19_ACK |
4613 GEN9_PGCTL_SSA_EU210_ACK |
4614 GEN9_PGCTL_SSA_EU311_ACK;
4615 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4616 GEN9_PGCTL_SSB_EU19_ACK |
4617 GEN9_PGCTL_SSB_EU210_ACK |
4618 GEN9_PGCTL_SSB_EU311_ACK;
4619
4620 for (s = 0; s < s_max; s++) {
4621 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4622 /* skip disabled slice */
4623 continue;
4624
Imre Deakf08a0c92016-08-31 19:13:04 +03004625 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004626
Rodrigo Vivib976dc52017-01-23 10:32:37 -08004627 if (IS_GEN9_BC(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004628 sseu->subslice_mask =
4629 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004630
Jeff McGee5d395252015-04-03 18:13:17 -07004631 for (ss = 0; ss < ss_max; ss++) {
4632 unsigned int eu_cnt;
4633
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004634 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004635 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4636 /* skip disabled subslice */
4637 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004638
Imre Deak57ec1712016-08-31 19:13:05 +03004639 sseu->subslice_mask |= BIT(ss);
4640 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004641
Jeff McGee5d395252015-04-03 18:13:17 -07004642 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4643 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004644 sseu->eu_total += eu_cnt;
4645 sseu->eu_per_subslice = max_t(unsigned int,
4646 sseu->eu_per_subslice,
4647 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004648 }
4649 }
4650}
4651
David Weinehall36cdd012016-08-22 13:59:31 +03004652static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004653 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004654{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004655 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004656 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004657
Imre Deakf08a0c92016-08-31 19:13:04 +03004658 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004659
Imre Deakf08a0c92016-08-31 19:13:04 +03004660 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004661 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004662 sseu->eu_per_subslice =
4663 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004664 sseu->eu_total = sseu->eu_per_subslice *
4665 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004666
4667 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004668 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004669 u8 subslice_7eu =
4670 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004671
Imre Deak915490d2016-08-31 19:13:01 +03004672 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004673 }
4674 }
4675}
4676
Imre Deak615d8902016-08-31 19:13:03 +03004677static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4678 const struct sseu_dev_info *sseu)
4679{
4680 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4681 const char *type = is_available_info ? "Available" : "Enabled";
4682
Imre Deakc67ba532016-08-31 19:13:06 +03004683 seq_printf(m, " %s Slice Mask: %04x\n", type,
4684 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004685 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004686 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004687 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004688 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004689 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4690 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004691 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004692 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004693 seq_printf(m, " %s EU Total: %u\n", type,
4694 sseu->eu_total);
4695 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4696 sseu->eu_per_subslice);
4697
4698 if (!is_available_info)
4699 return;
4700
4701 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4702 if (HAS_POOLED_EU(dev_priv))
4703 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4704
4705 seq_printf(m, " Has Slice Power Gating: %s\n",
4706 yesno(sseu->has_slice_pg));
4707 seq_printf(m, " Has Subslice Power Gating: %s\n",
4708 yesno(sseu->has_subslice_pg));
4709 seq_printf(m, " Has EU Power Gating: %s\n",
4710 yesno(sseu->has_eu_pg));
4711}
4712
Jeff McGee38732182015-02-13 10:27:54 -06004713static int i915_sseu_status(struct seq_file *m, void *unused)
4714{
David Weinehall36cdd012016-08-22 13:59:31 +03004715 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004716 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004717
David Weinehall36cdd012016-08-22 13:59:31 +03004718 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004719 return -ENODEV;
4720
4721 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004722 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004723
Jeff McGee7f992ab2015-02-13 10:27:55 -06004724 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004725 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004726
4727 intel_runtime_pm_get(dev_priv);
4728
David Weinehall36cdd012016-08-22 13:59:31 +03004729 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004730 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004731 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004732 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004733 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004734 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004735 }
David Weinehall238010e2016-08-01 17:33:27 +03004736
4737 intel_runtime_pm_put(dev_priv);
4738
Imre Deak615d8902016-08-31 19:13:03 +03004739 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004740
Jeff McGee38732182015-02-13 10:27:54 -06004741 return 0;
4742}
4743
Ben Widawsky6d794d42011-04-25 11:25:56 -07004744static int i915_forcewake_open(struct inode *inode, struct file *file)
4745{
David Weinehall36cdd012016-08-22 13:59:31 +03004746 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004747
David Weinehall36cdd012016-08-22 13:59:31 +03004748 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004749 return 0;
4750
Chris Wilson6daccb02015-01-16 11:34:35 +02004751 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004752 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004753
4754 return 0;
4755}
4756
Ben Widawskyc43b5632012-04-16 14:07:40 -07004757static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004758{
David Weinehall36cdd012016-08-22 13:59:31 +03004759 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004760
David Weinehall36cdd012016-08-22 13:59:31 +03004761 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004762 return 0;
4763
Mika Kuoppala59bad942015-01-16 11:34:40 +02004764 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004765 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004766
4767 return 0;
4768}
4769
4770static const struct file_operations i915_forcewake_fops = {
4771 .owner = THIS_MODULE,
4772 .open = i915_forcewake_open,
4773 .release = i915_forcewake_release,
4774};
4775
Lyude317eaa92017-02-03 21:18:25 -05004776static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4777{
4778 struct drm_i915_private *dev_priv = m->private;
4779 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4780
4781 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4782 seq_printf(m, "Detected: %s\n",
4783 yesno(delayed_work_pending(&hotplug->reenable_work)));
4784
4785 return 0;
4786}
4787
4788static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4789 const char __user *ubuf, size_t len,
4790 loff_t *offp)
4791{
4792 struct seq_file *m = file->private_data;
4793 struct drm_i915_private *dev_priv = m->private;
4794 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4795 unsigned int new_threshold;
4796 int i;
4797 char *newline;
4798 char tmp[16];
4799
4800 if (len >= sizeof(tmp))
4801 return -EINVAL;
4802
4803 if (copy_from_user(tmp, ubuf, len))
4804 return -EFAULT;
4805
4806 tmp[len] = '\0';
4807
4808 /* Strip newline, if any */
4809 newline = strchr(tmp, '\n');
4810 if (newline)
4811 *newline = '\0';
4812
4813 if (strcmp(tmp, "reset") == 0)
4814 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4815 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4816 return -EINVAL;
4817
4818 if (new_threshold > 0)
4819 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4820 new_threshold);
4821 else
4822 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4823
4824 spin_lock_irq(&dev_priv->irq_lock);
4825 hotplug->hpd_storm_threshold = new_threshold;
4826 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4827 for_each_hpd_pin(i)
4828 hotplug->stats[i].count = 0;
4829 spin_unlock_irq(&dev_priv->irq_lock);
4830
4831 /* Re-enable hpd immediately if we were in an irq storm */
4832 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4833
4834 return len;
4835}
4836
4837static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4838{
4839 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4840}
4841
4842static const struct file_operations i915_hpd_storm_ctl_fops = {
4843 .owner = THIS_MODULE,
4844 .open = i915_hpd_storm_ctl_open,
4845 .read = seq_read,
4846 .llseek = seq_lseek,
4847 .release = single_release,
4848 .write = i915_hpd_storm_ctl_write
4849};
4850
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004851static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004852 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004853 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004854 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01004855 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004856 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004857 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004858 {"i915_gem_request", i915_gem_request_info, 0},
4859 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004860 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004861 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004862 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004863 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004864 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004865 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07004866 {"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
Oscar Mateoa8b93702017-05-10 15:04:51 +00004867 {"i915_guc_stage_pool", i915_guc_stage_pool, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004868 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304869 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004870 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Michel Thierry061d06a2017-06-20 10:57:49 +01004871 {"i915_reset_info", i915_reset_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004872 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004873 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004874 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004875 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004876 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004877 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004878 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004879 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004880 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004881 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004882 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004883 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004884 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004885 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004886 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004887 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004888 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004889 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004890 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004891 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004892 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004893 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004894 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004895 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004896 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004897 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004898 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004899 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004900 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004901 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304902 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004903 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004904};
Ben Gamari27c202a2009-07-01 22:26:52 -04004905#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004906
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004907static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004908 const char *name;
4909 const struct file_operations *fops;
4910} i915_debugfs_files[] = {
4911 {"i915_wedged", &i915_wedged_fops},
4912 {"i915_max_freq", &i915_max_freq_fops},
4913 {"i915_min_freq", &i915_min_freq_fops},
4914 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004915 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4916 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004917 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004918#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004919 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004920 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004921#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004922 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004923 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004924 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4925 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4926 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Ville Syrjälä4127dc42017-06-06 15:44:12 +03004927 {"i915_fbc_false_color", &i915_fbc_false_color_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004928 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4929 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304930 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004931 {"i915_guc_log_control", &i915_guc_log_control_fops},
4932 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004933};
4934
Chris Wilson1dac8912016-06-24 14:00:17 +01004935int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004936{
Chris Wilson91c8a322016-07-05 10:40:23 +01004937 struct drm_minor *minor = dev_priv->drm.primary;
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004938 struct dentry *ent;
Daniel Vetter34b96742013-07-04 20:49:44 +02004939 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004940
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004941 ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
4942 minor->debugfs_root, to_i915(minor->dev),
4943 &i915_forcewake_fops);
4944 if (!ent)
4945 return -ENOMEM;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004946
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004947 ret = intel_pipe_crc_create(minor);
4948 if (ret)
4949 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004950
Daniel Vetter34b96742013-07-04 20:49:44 +02004951 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004952 ent = debugfs_create_file(i915_debugfs_files[i].name,
4953 S_IRUGO | S_IWUSR,
4954 minor->debugfs_root,
4955 to_i915(minor->dev),
Daniel Vetter34b96742013-07-04 20:49:44 +02004956 i915_debugfs_files[i].fops);
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004957 if (!ent)
4958 return -ENOMEM;
Daniel Vetter34b96742013-07-04 20:49:44 +02004959 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004960
Ben Gamari27c202a2009-07-01 22:26:52 -04004961 return drm_debugfs_create_files(i915_debugfs_list,
4962 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004963 minor->debugfs_root, minor);
4964}
4965
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004966struct dpcd_block {
4967 /* DPCD dump start address. */
4968 unsigned int offset;
4969 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4970 unsigned int end;
4971 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4972 size_t size;
4973 /* Only valid for eDP. */
4974 bool edp;
4975};
4976
4977static const struct dpcd_block i915_dpcd_debug[] = {
4978 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4979 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4980 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4981 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4982 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4983 { .offset = DP_SET_POWER },
4984 { .offset = DP_EDP_DPCD_REV },
4985 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4986 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4987 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4988};
4989
4990static int i915_dpcd_show(struct seq_file *m, void *data)
4991{
4992 struct drm_connector *connector = m->private;
4993 struct intel_dp *intel_dp =
4994 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4995 uint8_t buf[16];
4996 ssize_t err;
4997 int i;
4998
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004999 if (connector->status != connector_status_connected)
5000 return -ENODEV;
5001
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005002 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5003 const struct dpcd_block *b = &i915_dpcd_debug[i];
5004 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5005
5006 if (b->edp &&
5007 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5008 continue;
5009
5010 /* low tech for now */
5011 if (WARN_ON(size > sizeof(buf)))
5012 continue;
5013
5014 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5015 if (err <= 0) {
5016 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5017 size, b->offset, err);
5018 continue;
5019 }
5020
5021 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005022 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005023
5024 return 0;
5025}
5026
5027static int i915_dpcd_open(struct inode *inode, struct file *file)
5028{
5029 return single_open(file, i915_dpcd_show, inode->i_private);
5030}
5031
5032static const struct file_operations i915_dpcd_fops = {
5033 .owner = THIS_MODULE,
5034 .open = i915_dpcd_open,
5035 .read = seq_read,
5036 .llseek = seq_lseek,
5037 .release = single_release,
5038};
5039
David Weinehallecbd6782016-08-23 12:23:56 +03005040static int i915_panel_show(struct seq_file *m, void *data)
5041{
5042 struct drm_connector *connector = m->private;
5043 struct intel_dp *intel_dp =
5044 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5045
5046 if (connector->status != connector_status_connected)
5047 return -ENODEV;
5048
5049 seq_printf(m, "Panel power up delay: %d\n",
5050 intel_dp->panel_power_up_delay);
5051 seq_printf(m, "Panel power down delay: %d\n",
5052 intel_dp->panel_power_down_delay);
5053 seq_printf(m, "Backlight on delay: %d\n",
5054 intel_dp->backlight_on_delay);
5055 seq_printf(m, "Backlight off delay: %d\n",
5056 intel_dp->backlight_off_delay);
5057
5058 return 0;
5059}
5060
5061static int i915_panel_open(struct inode *inode, struct file *file)
5062{
5063 return single_open(file, i915_panel_show, inode->i_private);
5064}
5065
5066static const struct file_operations i915_panel_fops = {
5067 .owner = THIS_MODULE,
5068 .open = i915_panel_open,
5069 .read = seq_read,
5070 .llseek = seq_lseek,
5071 .release = single_release,
5072};
5073
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005074/**
5075 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5076 * @connector: pointer to a registered drm_connector
5077 *
5078 * Cleanup will be done by drm_connector_unregister() through a call to
5079 * drm_debugfs_connector_remove().
5080 *
5081 * Returns 0 on success, negative error codes on error.
5082 */
5083int i915_debugfs_connector_add(struct drm_connector *connector)
5084{
5085 struct dentry *root = connector->debugfs_entry;
5086
5087 /* The connector must have been registered beforehands. */
5088 if (!root)
5089 return -ENODEV;
5090
5091 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5092 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005093 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5094 connector, &i915_dpcd_fops);
5095
5096 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5097 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5098 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005099
5100 return 0;
5101}