blob: 8fdb911344b31079f263f63a0e0e13088b646687 [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
295 stats->count++;
296 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100297 if (!obj->bind_count)
298 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000299 if (obj->base.name || obj->base.dma_buf)
300 stats->shared += obj->base.size;
301
Chris Wilson894eeec2016-08-04 07:52:20 +0100302 list_for_each_entry(vma, &obj->vma_list, obj_link) {
303 if (!drm_mm_node_allocated(&vma->node))
304 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000305
Chris Wilson3272db52016-08-04 16:32:32 +0100306 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100307 stats->global += vma->node.size;
308 } else {
309 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000310
Chris Wilson2bfa9962016-08-04 07:52:25 +0100311 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000312 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000313 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100314
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100315 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100316 stats->active += vma->node.size;
317 else
318 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100319 }
320
321 return 0;
322}
323
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100324#define print_file_stats(m, name, stats) do { \
325 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300326 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 +0100327 name, \
328 stats.count, \
329 stats.total, \
330 stats.active, \
331 stats.inactive, \
332 stats.global, \
333 stats.shared, \
334 stats.unbound); \
335} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800336
337static void print_batch_pool_stats(struct seq_file *m,
338 struct drm_i915_private *dev_priv)
339{
340 struct drm_i915_gem_object *obj;
341 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000342 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530343 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000344 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800345
346 memset(&stats, 0, sizeof(stats));
347
Akash Goel3b3f1652016-10-13 22:44:48 +0530348 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000349 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100350 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000351 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100352 batch_pool_link)
353 per_file_stats(0, obj, &stats);
354 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100355 }
Brad Volkin493018d2014-12-11 12:13:08 -0800356
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100357 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800358}
359
Chris Wilson15da9562016-05-24 14:53:43 +0100360static int per_file_ctx_stats(int id, void *ptr, void *data)
361{
362 struct i915_gem_context *ctx = ptr;
363 int n;
364
365 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
366 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100367 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100368 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100369 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100370 }
371
372 return 0;
373}
374
375static void print_context_stats(struct seq_file *m,
376 struct drm_i915_private *dev_priv)
377{
David Weinehall36cdd012016-08-22 13:59:31 +0300378 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100379 struct file_stats stats;
380 struct drm_file *file;
381
382 memset(&stats, 0, sizeof(stats));
383
David Weinehall36cdd012016-08-22 13:59:31 +0300384 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100385 if (dev_priv->kernel_context)
386 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
387
David Weinehall36cdd012016-08-22 13:59:31 +0300388 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100389 struct drm_i915_file_private *fpriv = file->driver_priv;
390 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
391 }
David Weinehall36cdd012016-08-22 13:59:31 +0300392 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100393
394 print_file_stats(m, "[k]contexts", stats);
395}
396
David Weinehall36cdd012016-08-22 13:59:31 +0300397static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100398{
David Weinehall36cdd012016-08-22 13:59:31 +0300399 struct drm_i915_private *dev_priv = node_to_i915(m->private);
400 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300401 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100402 u32 count, mapped_count, purgeable_count, dpy_count;
403 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000404 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100405 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100406 int ret;
407
408 ret = mutex_lock_interruptible(&dev->struct_mutex);
409 if (ret)
410 return ret;
411
Chris Wilson3ef7f222016-10-18 13:02:48 +0100412 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000413 dev_priv->mm.object_count,
414 dev_priv->mm.object_memory);
415
Chris Wilson1544c422016-08-15 13:18:16 +0100416 size = count = 0;
417 mapped_size = mapped_count = 0;
418 purgeable_size = purgeable_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200419 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100420 size += obj->base.size;
421 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200422
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100423 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200424 purgeable_size += obj->base.size;
425 ++purgeable_count;
426 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100427
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100428 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100429 mapped_count++;
430 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100431 }
Chris Wilson6299f992010-11-24 12:23:44 +0000432 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100433 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
434
435 size = count = dpy_size = dpy_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200436 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100437 size += obj->base.size;
438 ++count;
439
440 if (obj->pin_display) {
441 dpy_size += obj->base.size;
442 ++dpy_count;
443 }
444
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100445 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100446 purgeable_size += obj->base.size;
447 ++purgeable_count;
448 }
449
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100450 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100451 mapped_count++;
452 mapped_size += obj->base.size;
453 }
454 }
455 seq_printf(m, "%u bound objects, %llu bytes\n",
456 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300457 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200458 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100459 seq_printf(m, "%u mapped objects, %llu bytes\n",
460 mapped_count, mapped_size);
461 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
462 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000463
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300464 seq_printf(m, "%llu [%llu] gtt total\n",
Chris Wilson381b9432017-02-15 08:43:54 +0000465 ggtt->base.total, ggtt->mappable_end);
Chris Wilson73aa8082010-09-30 11:46:12 +0100466
Damien Lespiau267f0c92013-06-24 22:59:48 +0100467 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800468 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200469 mutex_unlock(&dev->struct_mutex);
470
471 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100472 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100473 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
474 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100475 struct drm_i915_file_private *file_priv = file->driver_priv;
476 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900477 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100478
479 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000480 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100481 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100482 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100483 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900484 /*
485 * Although we have a valid reference on file->pid, that does
486 * not guarantee that the task_struct who called get_pid() is
487 * still alive (e.g. get_pid(current) => fork() => exit()).
488 * Therefore, we need to protect this ->comm access using RCU.
489 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100490 mutex_lock(&dev->struct_mutex);
491 request = list_first_entry_or_null(&file_priv->mm.request_list,
492 struct drm_i915_gem_request,
Chris Wilsonc8659ef2017-03-02 12:25:25 +0000493 client_link);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900494 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100495 task = pid_task(request && request->ctx->pid ?
496 request->ctx->pid : file->pid,
497 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800498 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900499 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100500 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100501 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200502 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100503
504 return 0;
505}
506
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100507static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000508{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100509 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300510 struct drm_i915_private *dev_priv = node_to_i915(node);
511 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100512 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000513 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300514 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000515 int count, ret;
516
517 ret = mutex_lock_interruptible(&dev->struct_mutex);
518 if (ret)
519 return ret;
520
521 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200522 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6da84822016-08-15 10:48:44 +0100523 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100524 continue;
525
Damien Lespiau267f0c92013-06-24 22:59:48 +0100526 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000527 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100528 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000529 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100530 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000531 count++;
532 }
533
534 mutex_unlock(&dev->struct_mutex);
535
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300536 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000537 count, total_obj_size, total_gtt_size);
538
539 return 0;
540}
541
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542static int i915_gem_pageflip_info(struct seq_file *m, void *data)
543{
David Weinehall36cdd012016-08-22 13:59:31 +0300544 struct drm_i915_private *dev_priv = node_to_i915(m->private);
545 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100546 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200547 int ret;
548
549 ret = mutex_lock_interruptible(&dev->struct_mutex);
550 if (ret)
551 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100552
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100553 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800554 const char pipe = pipe_name(crtc->pipe);
555 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200556 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100557
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200558 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200559 work = crtc->flip_work;
560 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800561 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100562 pipe, plane);
563 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200564 u32 pending;
565 u32 addr;
566
567 pending = atomic_read(&work->pending);
568 if (pending) {
569 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
570 pipe, plane);
571 } else {
572 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
573 pipe, plane);
574 }
575 if (work->flip_queued_req) {
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200576 struct intel_engine_cs *engine = work->flip_queued_req->engine;
Daniel Vetter5a21b662016-05-24 17:13:53 +0200577
Chris Wilson312c3c42016-11-24 14:47:50 +0000578 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 +0200579 engine->name,
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200580 work->flip_queued_req->global_seqno,
Chris Wilson312c3c42016-11-24 14:47:50 +0000581 intel_engine_last_submit(engine),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100582 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100583 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200584 } else
585 seq_printf(m, "Flip not associated with any ring\n");
586 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
587 work->flip_queued_vblank,
588 work->flip_ready_vblank,
589 intel_crtc_get_vblank_counter(crtc));
590 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
591
David Weinehall36cdd012016-08-22 13:59:31 +0300592 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200593 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
594 else
595 addr = I915_READ(DSPADDR(crtc->plane));
596 seq_printf(m, "Current scanout address 0x%08x\n", addr);
597
598 if (work->pending_flip_obj) {
599 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
600 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100601 }
602 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200603 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100604 }
605
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200606 mutex_unlock(&dev->struct_mutex);
607
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100608 return 0;
609}
610
Brad Volkin493018d2014-12-11 12:13:08 -0800611static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
612{
David Weinehall36cdd012016-08-22 13:59:31 +0300613 struct drm_i915_private *dev_priv = node_to_i915(m->private);
614 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800615 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000616 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530617 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100618 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000619 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800620
621 ret = mutex_lock_interruptible(&dev->struct_mutex);
622 if (ret)
623 return ret;
624
Akash Goel3b3f1652016-10-13 22:44:48 +0530625 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000626 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100627 int count;
628
629 count = 0;
630 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000631 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100632 batch_pool_link)
633 count++;
634 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000635 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100636
637 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000638 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100639 batch_pool_link) {
640 seq_puts(m, " ");
641 describe_obj(m, obj);
642 seq_putc(m, '\n');
643 }
644
645 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100646 }
Brad Volkin493018d2014-12-11 12:13:08 -0800647 }
648
Chris Wilson8d9d5742015-04-07 16:20:38 +0100649 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800650
651 mutex_unlock(&dev->struct_mutex);
652
653 return 0;
654}
655
Chris Wilson1b365952016-10-04 21:11:31 +0100656static void print_request(struct seq_file *m,
657 struct drm_i915_gem_request *rq,
658 const char *prefix)
659{
Chris Wilson20311bd2016-11-14 20:41:03 +0000660 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100661 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000662 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100663 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100664 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100665}
666
Ben Gamari20172632009-02-17 20:08:50 -0500667static int i915_gem_request_info(struct seq_file *m, void *data)
668{
David Weinehall36cdd012016-08-22 13:59:31 +0300669 struct drm_i915_private *dev_priv = node_to_i915(m->private);
670 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200671 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530672 struct intel_engine_cs *engine;
673 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000674 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100675
676 ret = mutex_lock_interruptible(&dev->struct_mutex);
677 if (ret)
678 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500679
Chris Wilson2d1070b2015-04-01 10:36:56 +0100680 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530681 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100682 int count;
683
684 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100685 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100686 count++;
687 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100688 continue;
689
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000690 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100691 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100692 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100693
694 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500695 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100696 mutex_unlock(&dev->struct_mutex);
697
Chris Wilson2d1070b2015-04-01 10:36:56 +0100698 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100699 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100700
Ben Gamari20172632009-02-17 20:08:50 -0500701 return 0;
702}
703
Chris Wilsonb2223492010-10-27 15:27:33 +0100704static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000705 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100706{
Chris Wilson688e6c72016-07-01 17:23:15 +0100707 struct intel_breadcrumbs *b = &engine->breadcrumbs;
708 struct rb_node *rb;
709
Chris Wilson12471ba2016-04-09 10:57:55 +0100710 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100711 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100712
Chris Wilson61d3dc72017-03-03 19:08:24 +0000713 spin_lock_irq(&b->rb_lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100714 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +0800715 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson688e6c72016-07-01 17:23:15 +0100716
717 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
718 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
719 }
Chris Wilson61d3dc72017-03-03 19:08:24 +0000720 spin_unlock_irq(&b->rb_lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100721}
722
Ben Gamari20172632009-02-17 20:08:50 -0500723static int i915_gem_seqno_info(struct seq_file *m, void *data)
724{
David Weinehall36cdd012016-08-22 13:59:31 +0300725 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000726 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530727 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500728
Akash Goel3b3f1652016-10-13 22:44:48 +0530729 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000730 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100731
Ben Gamari20172632009-02-17 20:08:50 -0500732 return 0;
733}
734
735
736static int i915_interrupt_info(struct seq_file *m, void *data)
737{
David Weinehall36cdd012016-08-22 13:59:31 +0300738 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000739 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530740 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100741 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100742
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200743 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500744
David Weinehall36cdd012016-08-22 13:59:31 +0300745 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300746 seq_printf(m, "Master Interrupt Control:\t%08x\n",
747 I915_READ(GEN8_MASTER_IRQ));
748
749 seq_printf(m, "Display IER:\t%08x\n",
750 I915_READ(VLV_IER));
751 seq_printf(m, "Display IIR:\t%08x\n",
752 I915_READ(VLV_IIR));
753 seq_printf(m, "Display IIR_RW:\t%08x\n",
754 I915_READ(VLV_IIR_RW));
755 seq_printf(m, "Display IMR:\t%08x\n",
756 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100757 for_each_pipe(dev_priv, pipe) {
758 enum intel_display_power_domain power_domain;
759
760 power_domain = POWER_DOMAIN_PIPE(pipe);
761 if (!intel_display_power_get_if_enabled(dev_priv,
762 power_domain)) {
763 seq_printf(m, "Pipe %c power disabled\n",
764 pipe_name(pipe));
765 continue;
766 }
767
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300768 seq_printf(m, "Pipe %c stat:\t%08x\n",
769 pipe_name(pipe),
770 I915_READ(PIPESTAT(pipe)));
771
Chris Wilson9c870d02016-10-24 13:42:15 +0100772 intel_display_power_put(dev_priv, power_domain);
773 }
774
775 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300776 seq_printf(m, "Port hotplug:\t%08x\n",
777 I915_READ(PORT_HOTPLUG_EN));
778 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
779 I915_READ(VLV_DPFLIPSTAT));
780 seq_printf(m, "DPINVGTT:\t%08x\n",
781 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100782 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300783
784 for (i = 0; i < 4; i++) {
785 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
786 i, I915_READ(GEN8_GT_IMR(i)));
787 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
788 i, I915_READ(GEN8_GT_IIR(i)));
789 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
790 i, I915_READ(GEN8_GT_IER(i)));
791 }
792
793 seq_printf(m, "PCU interrupt mask:\t%08x\n",
794 I915_READ(GEN8_PCU_IMR));
795 seq_printf(m, "PCU interrupt identity:\t%08x\n",
796 I915_READ(GEN8_PCU_IIR));
797 seq_printf(m, "PCU interrupt enable:\t%08x\n",
798 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300799 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700800 seq_printf(m, "Master Interrupt Control:\t%08x\n",
801 I915_READ(GEN8_MASTER_IRQ));
802
803 for (i = 0; i < 4; i++) {
804 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
805 i, I915_READ(GEN8_GT_IMR(i)));
806 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
807 i, I915_READ(GEN8_GT_IIR(i)));
808 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
809 i, I915_READ(GEN8_GT_IER(i)));
810 }
811
Damien Lespiau055e3932014-08-18 13:49:10 +0100812 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200813 enum intel_display_power_domain power_domain;
814
815 power_domain = POWER_DOMAIN_PIPE(pipe);
816 if (!intel_display_power_get_if_enabled(dev_priv,
817 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300818 seq_printf(m, "Pipe %c power disabled\n",
819 pipe_name(pipe));
820 continue;
821 }
Ben Widawskya123f152013-11-02 21:07:10 -0700822 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000823 pipe_name(pipe),
824 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700825 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000826 pipe_name(pipe),
827 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700828 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000829 pipe_name(pipe),
830 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200831
832 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700833 }
834
835 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
836 I915_READ(GEN8_DE_PORT_IMR));
837 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
838 I915_READ(GEN8_DE_PORT_IIR));
839 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
840 I915_READ(GEN8_DE_PORT_IER));
841
842 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
843 I915_READ(GEN8_DE_MISC_IMR));
844 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
845 I915_READ(GEN8_DE_MISC_IIR));
846 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
847 I915_READ(GEN8_DE_MISC_IER));
848
849 seq_printf(m, "PCU interrupt mask:\t%08x\n",
850 I915_READ(GEN8_PCU_IMR));
851 seq_printf(m, "PCU interrupt identity:\t%08x\n",
852 I915_READ(GEN8_PCU_IIR));
853 seq_printf(m, "PCU interrupt enable:\t%08x\n",
854 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300855 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700856 seq_printf(m, "Display IER:\t%08x\n",
857 I915_READ(VLV_IER));
858 seq_printf(m, "Display IIR:\t%08x\n",
859 I915_READ(VLV_IIR));
860 seq_printf(m, "Display IIR_RW:\t%08x\n",
861 I915_READ(VLV_IIR_RW));
862 seq_printf(m, "Display IMR:\t%08x\n",
863 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000864 for_each_pipe(dev_priv, pipe) {
865 enum intel_display_power_domain power_domain;
866
867 power_domain = POWER_DOMAIN_PIPE(pipe);
868 if (!intel_display_power_get_if_enabled(dev_priv,
869 power_domain)) {
870 seq_printf(m, "Pipe %c power disabled\n",
871 pipe_name(pipe));
872 continue;
873 }
874
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700875 seq_printf(m, "Pipe %c stat:\t%08x\n",
876 pipe_name(pipe),
877 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000878 intel_display_power_put(dev_priv, power_domain);
879 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700880
881 seq_printf(m, "Master IER:\t%08x\n",
882 I915_READ(VLV_MASTER_IER));
883
884 seq_printf(m, "Render IER:\t%08x\n",
885 I915_READ(GTIER));
886 seq_printf(m, "Render IIR:\t%08x\n",
887 I915_READ(GTIIR));
888 seq_printf(m, "Render IMR:\t%08x\n",
889 I915_READ(GTIMR));
890
891 seq_printf(m, "PM IER:\t\t%08x\n",
892 I915_READ(GEN6_PMIER));
893 seq_printf(m, "PM IIR:\t\t%08x\n",
894 I915_READ(GEN6_PMIIR));
895 seq_printf(m, "PM IMR:\t\t%08x\n",
896 I915_READ(GEN6_PMIMR));
897
898 seq_printf(m, "Port hotplug:\t%08x\n",
899 I915_READ(PORT_HOTPLUG_EN));
900 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
901 I915_READ(VLV_DPFLIPSTAT));
902 seq_printf(m, "DPINVGTT:\t%08x\n",
903 I915_READ(DPINVGTT));
904
David Weinehall36cdd012016-08-22 13:59:31 +0300905 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800906 seq_printf(m, "Interrupt enable: %08x\n",
907 I915_READ(IER));
908 seq_printf(m, "Interrupt identity: %08x\n",
909 I915_READ(IIR));
910 seq_printf(m, "Interrupt mask: %08x\n",
911 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100912 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800913 seq_printf(m, "Pipe %c stat: %08x\n",
914 pipe_name(pipe),
915 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800916 } else {
917 seq_printf(m, "North Display Interrupt enable: %08x\n",
918 I915_READ(DEIER));
919 seq_printf(m, "North Display Interrupt identity: %08x\n",
920 I915_READ(DEIIR));
921 seq_printf(m, "North Display Interrupt mask: %08x\n",
922 I915_READ(DEIMR));
923 seq_printf(m, "South Display Interrupt enable: %08x\n",
924 I915_READ(SDEIER));
925 seq_printf(m, "South Display Interrupt identity: %08x\n",
926 I915_READ(SDEIIR));
927 seq_printf(m, "South Display Interrupt mask: %08x\n",
928 I915_READ(SDEIMR));
929 seq_printf(m, "Graphics Interrupt enable: %08x\n",
930 I915_READ(GTIER));
931 seq_printf(m, "Graphics Interrupt identity: %08x\n",
932 I915_READ(GTIIR));
933 seq_printf(m, "Graphics Interrupt mask: %08x\n",
934 I915_READ(GTIMR));
935 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530936 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300937 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100938 seq_printf(m,
939 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000940 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000941 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000942 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000943 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200944 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100945
Ben Gamari20172632009-02-17 20:08:50 -0500946 return 0;
947}
948
Chris Wilsona6172a82009-02-11 14:26:38 +0000949static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
950{
David Weinehall36cdd012016-08-22 13:59:31 +0300951 struct drm_i915_private *dev_priv = node_to_i915(m->private);
952 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100953 int i, ret;
954
955 ret = mutex_lock_interruptible(&dev->struct_mutex);
956 if (ret)
957 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000958
Chris Wilsona6172a82009-02-11 14:26:38 +0000959 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
960 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100961 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000962
Chris Wilson6c085a72012-08-20 11:40:46 +0200963 seq_printf(m, "Fence %d, pin count = %d, object = ",
964 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100965 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100966 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100967 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100968 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100969 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000970 }
971
Chris Wilson05394f32010-11-08 19:18:58 +0000972 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000973 return 0;
974}
975
Chris Wilson98a2f412016-10-12 10:05:18 +0100976#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000977static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
978 size_t count, loff_t *pos)
979{
980 struct i915_gpu_state *error = file->private_data;
981 struct drm_i915_error_state_buf str;
982 ssize_t ret;
983 loff_t tmp;
984
985 if (!error)
986 return 0;
987
988 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
989 if (ret)
990 return ret;
991
992 ret = i915_error_state_to_str(&str, error);
993 if (ret)
994 goto out;
995
996 tmp = 0;
997 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
998 if (ret < 0)
999 goto out;
1000
1001 *pos = str.start + ret;
1002out:
1003 i915_error_state_buf_release(&str);
1004 return ret;
1005}
1006
1007static int gpu_state_release(struct inode *inode, struct file *file)
1008{
1009 i915_gpu_state_put(file->private_data);
1010 return 0;
1011}
1012
1013static int i915_gpu_info_open(struct inode *inode, struct file *file)
1014{
Chris Wilson090e5fe2017-03-28 14:14:07 +01001015 struct drm_i915_private *i915 = inode->i_private;
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001016 struct i915_gpu_state *gpu;
1017
Chris Wilson090e5fe2017-03-28 14:14:07 +01001018 intel_runtime_pm_get(i915);
1019 gpu = i915_capture_gpu_state(i915);
1020 intel_runtime_pm_put(i915);
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001021 if (!gpu)
1022 return -ENOMEM;
1023
1024 file->private_data = gpu;
1025 return 0;
1026}
1027
1028static const struct file_operations i915_gpu_info_fops = {
1029 .owner = THIS_MODULE,
1030 .open = i915_gpu_info_open,
1031 .read = gpu_state_read,
1032 .llseek = default_llseek,
1033 .release = gpu_state_release,
1034};
Chris Wilson98a2f412016-10-12 10:05:18 +01001035
Daniel Vetterd5442302012-04-27 15:17:40 +02001036static ssize_t
1037i915_error_state_write(struct file *filp,
1038 const char __user *ubuf,
1039 size_t cnt,
1040 loff_t *ppos)
1041{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001042 struct i915_gpu_state *error = filp->private_data;
1043
1044 if (!error)
1045 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001046
1047 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001048 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +02001049
1050 return cnt;
1051}
1052
1053static int i915_error_state_open(struct inode *inode, struct file *file)
1054{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001055 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001056 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001057}
1058
Daniel Vetterd5442302012-04-27 15:17:40 +02001059static const struct file_operations i915_error_state_fops = {
1060 .owner = THIS_MODULE,
1061 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001062 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001063 .write = i915_error_state_write,
1064 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001065 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +02001066};
Chris Wilson98a2f412016-10-12 10:05:18 +01001067#endif
1068
Kees Cook647416f2013-03-10 14:10:06 -07001069static int
Kees Cook647416f2013-03-10 14:10:06 -07001070i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001071{
David Weinehall36cdd012016-08-22 13:59:31 +03001072 struct drm_i915_private *dev_priv = data;
1073 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001074 int ret;
1075
Mika Kuoppala40633212012-12-04 15:12:00 +02001076 ret = mutex_lock_interruptible(&dev->struct_mutex);
1077 if (ret)
1078 return ret;
1079
Chris Wilson73cb9702016-10-28 13:58:46 +01001080 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001081 mutex_unlock(&dev->struct_mutex);
1082
Kees Cook647416f2013-03-10 14:10:06 -07001083 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001084}
1085
Kees Cook647416f2013-03-10 14:10:06 -07001086DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001087 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001088 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001089
Deepak Sadb4bd12014-03-31 11:30:02 +05301090static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001091{
David Weinehall36cdd012016-08-22 13:59:31 +03001092 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001093 int ret = 0;
1094
1095 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001096
David Weinehall36cdd012016-08-22 13:59:31 +03001097 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001098 u16 rgvswctl = I915_READ16(MEMSWCTL);
1099 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1100
1101 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1102 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1103 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1104 MEMSTAT_VID_SHIFT);
1105 seq_printf(m, "Current P-state: %d\n",
1106 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001107 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001108 u32 freq_sts;
1109
1110 mutex_lock(&dev_priv->rps.hw_lock);
1111 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1112 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1113 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1114
1115 seq_printf(m, "actual GPU freq: %d MHz\n",
1116 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1117
1118 seq_printf(m, "current GPU freq: %d MHz\n",
1119 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1120
1121 seq_printf(m, "max GPU freq: %d MHz\n",
1122 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1123
1124 seq_printf(m, "min GPU freq: %d MHz\n",
1125 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1126
1127 seq_printf(m, "idle GPU freq: %d MHz\n",
1128 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1129
1130 seq_printf(m,
1131 "efficient (RPe) frequency: %d MHz\n",
1132 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1133 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001134 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001135 u32 rp_state_limits;
1136 u32 gt_perf_status;
1137 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001138 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001139 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001140 u32 rpupei, rpcurup, rpprevup;
1141 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001142 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143 int max_freq;
1144
Bob Paauwe35040562015-06-25 14:54:07 -07001145 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001146 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001147 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1148 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1149 } else {
1150 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1151 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1152 }
1153
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001154 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001155 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001156
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001157 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001158 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301159 reqf >>= 23;
1160 else {
1161 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001162 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301163 reqf >>= 24;
1164 else
1165 reqf >>= 25;
1166 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001167 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001168
Chris Wilson0d8f9492014-03-27 09:06:14 +00001169 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1170 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1171 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1172
Jesse Barnesccab5c82011-01-18 15:49:25 -08001173 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301174 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1175 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1176 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1177 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1178 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1179 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001180 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301181 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001182 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001183 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1184 else
1185 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001186 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001187
Mika Kuoppala59bad942015-01-16 11:34:40 +02001188 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001189
David Weinehall36cdd012016-08-22 13:59:31 +03001190 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001191 pm_ier = I915_READ(GEN6_PMIER);
1192 pm_imr = I915_READ(GEN6_PMIMR);
1193 pm_isr = I915_READ(GEN6_PMISR);
1194 pm_iir = I915_READ(GEN6_PMIIR);
1195 pm_mask = I915_READ(GEN6_PMINTRMSK);
1196 } else {
1197 pm_ier = I915_READ(GEN8_GT_IER(2));
1198 pm_imr = I915_READ(GEN8_GT_IMR(2));
1199 pm_isr = I915_READ(GEN8_GT_ISR(2));
1200 pm_iir = I915_READ(GEN8_GT_IIR(2));
1201 pm_mask = I915_READ(GEN6_PMINTRMSK);
1202 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001203 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 -03001204 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05301205 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
1206 dev_priv->rps.pm_intrmsk_mbz);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001207 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001208 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001209 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001210 seq_printf(m, "Render p-state VID: %d\n",
1211 gt_perf_status & 0xff);
1212 seq_printf(m, "Render p-state limit: %d\n",
1213 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001214 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1215 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1216 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1217 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001218 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001219 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301220 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1221 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1222 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1223 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1224 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1225 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001226 seq_printf(m, "Up threshold: %d%%\n",
1227 dev_priv->rps.up_threshold);
1228
Akash Goeld6cda9c2016-04-23 00:05:46 +05301229 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1230 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1231 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1232 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1233 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1234 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001235 seq_printf(m, "Down threshold: %d%%\n",
1236 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001237
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001238 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001239 rp_state_cap >> 16) & 0xff;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001240 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001241 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001242 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001243
1244 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001245 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001246 seq_printf(m, "Nominal (RP1) 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
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001249 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001250 rp_state_cap >> 0) & 0xff;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001251 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001252 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001253 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001254 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001255 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001256
Chris Wilsond86ed342015-04-27 13:41:19 +01001257 seq_printf(m, "Current freq: %d MHz\n",
1258 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1259 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001260 seq_printf(m, "Idle freq: %d MHz\n",
1261 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001262 seq_printf(m, "Min freq: %d MHz\n",
1263 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001264 seq_printf(m, "Boost freq: %d MHz\n",
1265 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001266 seq_printf(m, "Max freq: %d MHz\n",
1267 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1268 seq_printf(m,
1269 "efficient (RPe) frequency: %d MHz\n",
1270 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001271 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001272 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001273 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001274
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001275 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001276 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1277 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1278
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001279 intel_runtime_pm_put(dev_priv);
1280 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001281}
1282
Ben Widawskyd6369512016-09-20 16:54:32 +03001283static void i915_instdone_info(struct drm_i915_private *dev_priv,
1284 struct seq_file *m,
1285 struct intel_instdone *instdone)
1286{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001287 int slice;
1288 int subslice;
1289
Ben Widawskyd6369512016-09-20 16:54:32 +03001290 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1291 instdone->instdone);
1292
1293 if (INTEL_GEN(dev_priv) <= 3)
1294 return;
1295
1296 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1297 instdone->slice_common);
1298
1299 if (INTEL_GEN(dev_priv) <= 6)
1300 return;
1301
Ben Widawskyf9e61372016-09-20 16:54:33 +03001302 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1303 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1304 slice, subslice, instdone->sampler[slice][subslice]);
1305
1306 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1307 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1308 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001309}
1310
Chris Wilsonf6544492015-01-26 18:03:04 +02001311static int i915_hangcheck_info(struct seq_file *m, void *unused)
1312{
David Weinehall36cdd012016-08-22 13:59:31 +03001313 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001314 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001315 u64 acthd[I915_NUM_ENGINES];
1316 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001317 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001318 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001319
Chris Wilson8af29b02016-09-09 14:11:47 +01001320 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001321 seq_puts(m, "Wedged\n");
1322 if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
1323 seq_puts(m, "Reset in progress: struct_mutex backoff\n");
1324 if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
1325 seq_puts(m, "Reset in progress: reset handoff to waiter\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001326 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001327 seq_puts(m, "Waiter holding struct mutex\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001328 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001329 seq_puts(m, "struct_mutex blocked for reset\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001330
Chris Wilsonf6544492015-01-26 18:03:04 +02001331 if (!i915.enable_hangcheck) {
Chris Wilson8c185ec2017-03-16 17:13:02 +00001332 seq_puts(m, "Hangcheck disabled\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001333 return 0;
1334 }
1335
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001336 intel_runtime_pm_get(dev_priv);
1337
Akash Goel3b3f1652016-10-13 22:44:48 +05301338 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001339 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001340 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001341 }
1342
Akash Goel3b3f1652016-10-13 22:44:48 +05301343 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001344
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001345 intel_runtime_pm_put(dev_priv);
1346
Chris Wilson8352aea2017-03-03 09:00:56 +00001347 if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
1348 seq_printf(m, "Hangcheck active, timer fires in %dms\n",
Chris Wilsonf6544492015-01-26 18:03:04 +02001349 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1350 jiffies));
Chris Wilson8352aea2017-03-03 09:00:56 +00001351 else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
1352 seq_puts(m, "Hangcheck active, work pending\n");
1353 else
1354 seq_puts(m, "Hangcheck inactive\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001355
Chris Wilsonf73b5672017-03-02 15:03:56 +00001356 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1357
Akash Goel3b3f1652016-10-13 22:44:48 +05301358 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001359 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1360 struct rb_node *rb;
1361
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001362 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001363 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001364 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001365 intel_engine_last_submit(engine),
1366 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001367 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001368 yesno(intel_engine_has_waiter(engine)),
1369 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001370 &dev_priv->gpu_error.missed_irq_rings)),
1371 yesno(engine->hangcheck.stalled));
1372
Chris Wilson61d3dc72017-03-03 19:08:24 +00001373 spin_lock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001374 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001375 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001376
1377 seq_printf(m, "\t%s [%d] waiting for %x\n",
1378 w->tsk->comm, w->tsk->pid, w->seqno);
1379 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001380 spin_unlock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001381
Chris Wilsonf6544492015-01-26 18:03:04 +02001382 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001383 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001384 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001385 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1386 hangcheck_action_to_str(engine->hangcheck.action),
1387 engine->hangcheck.action,
1388 jiffies_to_msecs(jiffies -
1389 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001390
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001391 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001392 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001393
Ben Widawskyd6369512016-09-20 16:54:32 +03001394 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001395
Ben Widawskyd6369512016-09-20 16:54:32 +03001396 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001397
Ben Widawskyd6369512016-09-20 16:54:32 +03001398 i915_instdone_info(dev_priv, m,
1399 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001400 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001401 }
1402
1403 return 0;
1404}
1405
Ben Widawsky4d855292011-12-12 19:34:16 -08001406static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001407{
David Weinehall36cdd012016-08-22 13:59:31 +03001408 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001409 u32 rgvmodectl, rstdbyctl;
1410 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001411
Ben Widawsky616fdb52011-10-05 11:44:54 -07001412 rgvmodectl = I915_READ(MEMMODECTL);
1413 rstdbyctl = I915_READ(RSTDBYCTL);
1414 crstandvid = I915_READ16(CRSTANDVID);
1415
Jani Nikula742f4912015-09-03 11:16:09 +03001416 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001417 seq_printf(m, "Boost freq: %d\n",
1418 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1419 MEMMODE_BOOST_FREQ_SHIFT);
1420 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001421 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001422 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001423 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001424 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001425 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426 seq_printf(m, "Starting frequency: P%d\n",
1427 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001428 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001429 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001430 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1431 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1432 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1433 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001434 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001435 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001436 switch (rstdbyctl & RSX_STATUS_MASK) {
1437 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001438 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001439 break;
1440 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001442 break;
1443 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 break;
1446 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 break;
1449 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001457 break;
1458 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001459
1460 return 0;
1461}
1462
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001463static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001464{
Chris Wilson233ebf52017-03-23 10:19:44 +00001465 struct drm_i915_private *i915 = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001466 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsond2dc94b2017-03-23 10:19:41 +00001467 unsigned int tmp;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001468
Chris Wilson233ebf52017-03-23 10:19:44 +00001469 for_each_fw_domain(fw_domain, i915, tmp)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001470 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001471 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilson233ebf52017-03-23 10:19:44 +00001472 READ_ONCE(fw_domain->wake_count));
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001473
1474 return 0;
1475}
1476
Mika Kuoppala13628772017-03-15 17:43:02 +02001477static void print_rc6_res(struct seq_file *m,
1478 const char *title,
1479 const i915_reg_t reg)
1480{
1481 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1482
1483 seq_printf(m, "%s %u (%llu us)\n",
1484 title, I915_READ(reg),
1485 intel_rc6_residency_us(dev_priv, reg));
1486}
1487
Deepak S669ab5a2014-01-10 15:18:26 +05301488static int vlv_drpc_info(struct seq_file *m)
1489{
David Weinehall36cdd012016-08-22 13:59:31 +03001490 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001491 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301492
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001493 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301494 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1495 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1496
1497 seq_printf(m, "Video Turbo Mode: %s\n",
1498 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1499 seq_printf(m, "Turbo enabled: %s\n",
1500 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1501 seq_printf(m, "HW control enabled: %s\n",
1502 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1503 seq_printf(m, "SW control enabled: %s\n",
1504 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1505 GEN6_RP_MEDIA_SW_MODE));
1506 seq_printf(m, "RC6 Enabled: %s\n",
1507 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1508 GEN6_RC_CTL_EI_MODE(1))));
1509 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001510 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301511 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001512 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301513
Mika Kuoppala13628772017-03-15 17:43:02 +02001514 print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
1515 print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
Imre Deak9cc19be2014-04-14 20:24:24 +03001516
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001517 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301518}
1519
Ben Widawsky4d855292011-12-12 19:34:16 -08001520static int gen6_drpc_info(struct seq_file *m)
1521{
David Weinehall36cdd012016-08-22 13:59:31 +03001522 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001523 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301524 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001525 unsigned forcewake_count;
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001526 int count = 0;
Ben Widawsky4d855292011-12-12 19:34:16 -08001527
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001528 forcewake_count = READ_ONCE(dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001529 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001530 seq_puts(m, "RC information inaccurate because somebody "
1531 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001532 } else {
1533 /* NB: we cannot use forcewake, else we read the wrong values */
1534 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1535 udelay(10);
1536 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1537 }
1538
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001539 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001540 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001541
1542 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1543 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001544 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301545 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1546 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1547 }
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001548
Ben Widawsky44cbd332012-11-06 14:36:36 +00001549 mutex_lock(&dev_priv->rps.hw_lock);
1550 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1551 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001552
1553 seq_printf(m, "Video Turbo Mode: %s\n",
1554 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1555 seq_printf(m, "HW control enabled: %s\n",
1556 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1557 seq_printf(m, "SW control enabled: %s\n",
1558 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1559 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001560 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001561 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1562 seq_printf(m, "RC6 Enabled: %s\n",
1563 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001564 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301565 seq_printf(m, "Render Well Gating Enabled: %s\n",
1566 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1567 seq_printf(m, "Media Well Gating Enabled: %s\n",
1568 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1569 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001570 seq_printf(m, "Deep RC6 Enabled: %s\n",
1571 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1572 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1573 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001574 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001575 switch (gt_core_status & GEN6_RCn_MASK) {
1576 case GEN6_RC0:
1577 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001578 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001579 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001580 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001581 break;
1582 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001583 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001584 break;
1585 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001586 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 break;
1588 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001589 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001590 break;
1591 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001592 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 break;
1594 }
1595
1596 seq_printf(m, "Core Power Down: %s\n",
1597 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001598 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301599 seq_printf(m, "Render Power Well: %s\n",
1600 (gen9_powergate_status &
1601 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1602 seq_printf(m, "Media Power Well: %s\n",
1603 (gen9_powergate_status &
1604 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1605 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001606
1607 /* Not exactly sure what this is */
Mika Kuoppala13628772017-03-15 17:43:02 +02001608 print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
1609 GEN6_GT_GFX_RC6_LOCKED);
1610 print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
1611 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
1612 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
Ben Widawskycce66a22012-03-27 18:59:38 -07001613
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001614 seq_printf(m, "RC6 voltage: %dmV\n",
1615 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1616 seq_printf(m, "RC6+ voltage: %dmV\n",
1617 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1618 seq_printf(m, "RC6++ voltage: %dmV\n",
1619 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301620 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001621}
1622
1623static int i915_drpc_info(struct seq_file *m, void *unused)
1624{
David Weinehall36cdd012016-08-22 13:59:31 +03001625 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001626 int err;
1627
1628 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001629
David Weinehall36cdd012016-08-22 13:59:31 +03001630 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001631 err = vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001632 else if (INTEL_GEN(dev_priv) >= 6)
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001633 err = gen6_drpc_info(m);
Ben Widawsky4d855292011-12-12 19:34:16 -08001634 else
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001635 err = ironlake_drpc_info(m);
1636
1637 intel_runtime_pm_put(dev_priv);
1638
1639 return err;
Ben Widawsky4d855292011-12-12 19:34:16 -08001640}
1641
Daniel Vetter9a851782015-06-18 10:30:22 +02001642static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1643{
David Weinehall36cdd012016-08-22 13:59:31 +03001644 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001645
1646 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1647 dev_priv->fb_tracking.busy_bits);
1648
1649 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1650 dev_priv->fb_tracking.flip_bits);
1651
1652 return 0;
1653}
1654
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001655static int i915_fbc_status(struct seq_file *m, void *unused)
1656{
David Weinehall36cdd012016-08-22 13:59:31 +03001657 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001658
David Weinehall36cdd012016-08-22 13:59:31 +03001659 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001660 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001661 return 0;
1662 }
1663
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001664 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001665 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001666
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001667 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001668 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001669 else
1670 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001671 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001672
Ville Syrjälä3fd5d1e2017-06-06 15:43:18 +03001673 if (intel_fbc_is_active(dev_priv)) {
1674 u32 mask;
1675
1676 if (INTEL_GEN(dev_priv) >= 8)
1677 mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
1678 else if (INTEL_GEN(dev_priv) >= 7)
1679 mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
1680 else if (INTEL_GEN(dev_priv) >= 5)
1681 mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
1682 else if (IS_G4X(dev_priv))
1683 mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
1684 else
1685 mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
1686 FBC_STAT_COMPRESSED);
1687
1688 seq_printf(m, "Compressing: %s\n", yesno(mask));
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001689 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001690
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001691 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001692 intel_runtime_pm_put(dev_priv);
1693
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001694 return 0;
1695}
1696
Rodrigo Vivida46f932014-08-01 02:04:45 -07001697static int i915_fbc_fc_get(void *data, u64 *val)
1698{
David Weinehall36cdd012016-08-22 13:59:31 +03001699 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001700
David Weinehall36cdd012016-08-22 13:59:31 +03001701 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001702 return -ENODEV;
1703
Rodrigo Vivida46f932014-08-01 02:04:45 -07001704 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001705
1706 return 0;
1707}
1708
1709static int i915_fbc_fc_set(void *data, u64 val)
1710{
David Weinehall36cdd012016-08-22 13:59:31 +03001711 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001712 u32 reg;
1713
David Weinehall36cdd012016-08-22 13:59:31 +03001714 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001715 return -ENODEV;
1716
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001717 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001718
1719 reg = I915_READ(ILK_DPFC_CONTROL);
1720 dev_priv->fbc.false_color = val;
1721
1722 I915_WRITE(ILK_DPFC_CONTROL, val ?
1723 (reg | FBC_CTL_FALSE_COLOR) :
1724 (reg & ~FBC_CTL_FALSE_COLOR));
1725
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001726 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001727 return 0;
1728}
1729
1730DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1731 i915_fbc_fc_get, i915_fbc_fc_set,
1732 "%llu\n");
1733
Paulo Zanoni92d44622013-05-31 16:33:24 -03001734static int i915_ips_status(struct seq_file *m, void *unused)
1735{
David Weinehall36cdd012016-08-22 13:59:31 +03001736 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001737
David Weinehall36cdd012016-08-22 13:59:31 +03001738 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001739 seq_puts(m, "not supported\n");
1740 return 0;
1741 }
1742
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001743 intel_runtime_pm_get(dev_priv);
1744
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001745 seq_printf(m, "Enabled by kernel parameter: %s\n",
1746 yesno(i915.enable_ips));
1747
David Weinehall36cdd012016-08-22 13:59:31 +03001748 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001749 seq_puts(m, "Currently: unknown\n");
1750 } else {
1751 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1752 seq_puts(m, "Currently: enabled\n");
1753 else
1754 seq_puts(m, "Currently: disabled\n");
1755 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001756
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001757 intel_runtime_pm_put(dev_priv);
1758
Paulo Zanoni92d44622013-05-31 16:33:24 -03001759 return 0;
1760}
1761
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001762static int i915_sr_status(struct seq_file *m, void *unused)
1763{
David Weinehall36cdd012016-08-22 13:59:31 +03001764 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001765 bool sr_enabled = false;
1766
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001767 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001768 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001769
Chris Wilson7342a722017-03-09 14:20:49 +00001770 if (INTEL_GEN(dev_priv) >= 9)
1771 /* no global SR status; inspect per-plane WM */;
1772 else if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001773 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001774 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001775 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001776 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001777 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001778 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001779 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001780 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001781 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001782 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001783
Chris Wilson9c870d02016-10-24 13:42:15 +01001784 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001785 intel_runtime_pm_put(dev_priv);
1786
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001787 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001788
1789 return 0;
1790}
1791
Jesse Barnes7648fa92010-05-20 14:28:11 -07001792static int i915_emon_status(struct seq_file *m, void *unused)
1793{
David Weinehall36cdd012016-08-22 13:59:31 +03001794 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1795 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001796 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001797 int ret;
1798
David Weinehall36cdd012016-08-22 13:59:31 +03001799 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001800 return -ENODEV;
1801
Chris Wilsonde227ef2010-07-03 07:58:38 +01001802 ret = mutex_lock_interruptible(&dev->struct_mutex);
1803 if (ret)
1804 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001805
1806 temp = i915_mch_val(dev_priv);
1807 chipset = i915_chipset_val(dev_priv);
1808 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001809 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001810
1811 seq_printf(m, "GMCH temp: %ld\n", temp);
1812 seq_printf(m, "Chipset power: %ld\n", chipset);
1813 seq_printf(m, "GFX power: %ld\n", gfx);
1814 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1815
1816 return 0;
1817}
1818
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001819static int i915_ring_freq_table(struct seq_file *m, void *unused)
1820{
David Weinehall36cdd012016-08-22 13:59:31 +03001821 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001822 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001823 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301824 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001825
Carlos Santa26310342016-08-17 12:30:41 -07001826 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001827 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001828 return 0;
1829 }
1830
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001831 intel_runtime_pm_get(dev_priv);
1832
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001833 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001834 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001835 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001836
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001837 if (IS_GEN9_BC(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301838 /* Convert GT frequency to 50 HZ units */
1839 min_gpu_freq =
1840 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1841 max_gpu_freq =
1842 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1843 } else {
1844 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1845 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1846 }
1847
Damien Lespiau267f0c92013-06-24 22:59:48 +01001848 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001849
Akash Goelf936ec32015-06-29 14:50:22 +05301850 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001851 ia_freq = gpu_freq;
1852 sandybridge_pcode_read(dev_priv,
1853 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1854 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001855 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301856 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001857 (IS_GEN9_BC(dev_priv) ?
1858 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001859 ((ia_freq >> 0) & 0xff) * 100,
1860 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001861 }
1862
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001863 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001864
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001865out:
1866 intel_runtime_pm_put(dev_priv);
1867 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001868}
1869
Chris Wilson44834a62010-08-19 16:09:23 +01001870static int i915_opregion(struct seq_file *m, void *unused)
1871{
David Weinehall36cdd012016-08-22 13:59:31 +03001872 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1873 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001874 struct intel_opregion *opregion = &dev_priv->opregion;
1875 int ret;
1876
1877 ret = mutex_lock_interruptible(&dev->struct_mutex);
1878 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001879 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001880
Jani Nikula2455a8e2015-12-14 12:50:53 +02001881 if (opregion->header)
1882 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001883
1884 mutex_unlock(&dev->struct_mutex);
1885
Daniel Vetter0d38f002012-04-21 22:49:10 +02001886out:
Chris Wilson44834a62010-08-19 16:09:23 +01001887 return 0;
1888}
1889
Jani Nikulaada8f952015-12-15 13:17:12 +02001890static int i915_vbt(struct seq_file *m, void *unused)
1891{
David Weinehall36cdd012016-08-22 13:59:31 +03001892 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001893
1894 if (opregion->vbt)
1895 seq_write(m, opregion->vbt, opregion->vbt_size);
1896
1897 return 0;
1898}
1899
Chris Wilson37811fc2010-08-25 22:45:57 +01001900static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1901{
David Weinehall36cdd012016-08-22 13:59:31 +03001902 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1903 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301904 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001905 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001906 int ret;
1907
1908 ret = mutex_lock_interruptible(&dev->struct_mutex);
1909 if (ret)
1910 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001911
Daniel Vetter06957262015-08-10 13:34:08 +02001912#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001913 if (dev_priv->fbdev) {
1914 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001915
Chris Wilson25bcce92016-07-02 15:36:00 +01001916 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1917 fbdev_fb->base.width,
1918 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001919 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001920 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001921 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001922 drm_framebuffer_read_refcount(&fbdev_fb->base));
1923 describe_obj(m, fbdev_fb->obj);
1924 seq_putc(m, '\n');
1925 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001926#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001927
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001928 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001929 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301930 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1931 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001932 continue;
1933
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001934 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 +01001935 fb->base.width,
1936 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001937 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001938 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001939 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001940 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001941 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001942 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001943 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001944 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001945 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001946
1947 return 0;
1948}
1949
Chris Wilson7e37f882016-08-02 22:50:21 +01001950static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001951{
Chris Wilsonfe085f12017-03-21 10:25:52 +00001952 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u)",
1953 ring->space, ring->head, ring->tail);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001954}
1955
Ben Widawskye76d3632011-03-19 18:14:29 -07001956static int i915_context_status(struct seq_file *m, void *unused)
1957{
David Weinehall36cdd012016-08-22 13:59:31 +03001958 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1959 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001960 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001961 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301962 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001963 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001964
Daniel Vetterf3d28872014-05-29 23:23:08 +02001965 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001966 if (ret)
1967 return ret;
1968
Ben Widawskya33afea2013-09-17 21:12:45 -07001969 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001970 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001971 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001972 struct task_struct *task;
1973
Chris Wilsonc84455b2016-08-15 10:49:08 +01001974 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001975 if (task) {
1976 seq_printf(m, "(%s [%d]) ",
1977 task->comm, task->pid);
1978 put_task_struct(task);
1979 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001980 } else if (IS_ERR(ctx->file_priv)) {
1981 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001982 } else {
1983 seq_puts(m, "(kernel) ");
1984 }
1985
Chris Wilsonbca44d82016-05-24 14:53:41 +01001986 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1987 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001988
Akash Goel3b3f1652016-10-13 22:44:48 +05301989 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001990 struct intel_context *ce = &ctx->engine[engine->id];
1991
1992 seq_printf(m, "%s: ", engine->name);
1993 seq_putc(m, ce->initialised ? 'I' : 'i');
1994 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001995 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001996 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001997 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001998 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001999 }
2000
Ben Widawskya33afea2013-09-17 21:12:45 -07002001 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002002 }
2003
Daniel Vetterf3d28872014-05-29 23:23:08 +02002004 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002005
2006 return 0;
2007}
2008
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002009static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002010 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002011 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002012{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002013 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002014 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002015 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002016
Chris Wilson7069b142016-04-28 09:56:52 +01002017 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2018
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002019 if (!vma) {
2020 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002021 return;
2022 }
2023
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002024 if (vma->flags & I915_VMA_GLOBAL_BIND)
2025 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002026 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002027
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002028 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002029 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002030 return;
2031 }
2032
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002033 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2034 if (page) {
2035 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002036
2037 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002038 seq_printf(m,
2039 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2040 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002041 reg_state[j], reg_state[j + 1],
2042 reg_state[j + 2], reg_state[j + 3]);
2043 }
2044 kunmap_atomic(reg_state);
2045 }
2046
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002047 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002048 seq_putc(m, '\n');
2049}
2050
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002051static int i915_dump_lrc(struct seq_file *m, void *unused)
2052{
David Weinehall36cdd012016-08-22 13:59:31 +03002053 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2054 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002055 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002056 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302057 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002058 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002059
2060 if (!i915.enable_execlists) {
2061 seq_printf(m, "Logical Ring Contexts are disabled\n");
2062 return 0;
2063 }
2064
2065 ret = mutex_lock_interruptible(&dev->struct_mutex);
2066 if (ret)
2067 return ret;
2068
Dave Gordone28e4042016-01-19 19:02:55 +00002069 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302070 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002071 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002072
2073 mutex_unlock(&dev->struct_mutex);
2074
2075 return 0;
2076}
2077
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002078static const char *swizzle_string(unsigned swizzle)
2079{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002080 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002081 case I915_BIT_6_SWIZZLE_NONE:
2082 return "none";
2083 case I915_BIT_6_SWIZZLE_9:
2084 return "bit9";
2085 case I915_BIT_6_SWIZZLE_9_10:
2086 return "bit9/bit10";
2087 case I915_BIT_6_SWIZZLE_9_11:
2088 return "bit9/bit11";
2089 case I915_BIT_6_SWIZZLE_9_10_11:
2090 return "bit9/bit10/bit11";
2091 case I915_BIT_6_SWIZZLE_9_17:
2092 return "bit9/bit17";
2093 case I915_BIT_6_SWIZZLE_9_10_17:
2094 return "bit9/bit10/bit17";
2095 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002096 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002097 }
2098
2099 return "bug";
2100}
2101
2102static int i915_swizzle_info(struct seq_file *m, void *data)
2103{
David Weinehall36cdd012016-08-22 13:59:31 +03002104 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002105
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002106 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002107
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002108 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2109 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2110 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2111 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2112
David Weinehall36cdd012016-08-22 13:59:31 +03002113 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002114 seq_printf(m, "DDC = 0x%08x\n",
2115 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002116 seq_printf(m, "DDC2 = 0x%08x\n",
2117 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002118 seq_printf(m, "C0DRB3 = 0x%04x\n",
2119 I915_READ16(C0DRB3));
2120 seq_printf(m, "C1DRB3 = 0x%04x\n",
2121 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002122 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002123 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2124 I915_READ(MAD_DIMM_C0));
2125 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2126 I915_READ(MAD_DIMM_C1));
2127 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2128 I915_READ(MAD_DIMM_C2));
2129 seq_printf(m, "TILECTL = 0x%08x\n",
2130 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002131 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002132 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2133 I915_READ(GAMTARBMODE));
2134 else
2135 seq_printf(m, "ARB_MODE = 0x%08x\n",
2136 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002137 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2138 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002139 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002140
2141 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2142 seq_puts(m, "L-shaped memory detected\n");
2143
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002144 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002145
2146 return 0;
2147}
2148
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002149static int per_file_ctx(int id, void *ptr, void *data)
2150{
Chris Wilsone2efd132016-05-24 14:53:34 +01002151 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002152 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002153 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2154
2155 if (!ppgtt) {
2156 seq_printf(m, " no ppgtt for context %d\n",
2157 ctx->user_handle);
2158 return 0;
2159 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002160
Oscar Mateof83d6512014-05-22 14:13:38 +01002161 if (i915_gem_context_is_default(ctx))
2162 seq_puts(m, " default context:\n");
2163 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002164 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002165 ppgtt->debug_dump(ppgtt, m);
2166
2167 return 0;
2168}
2169
David Weinehall36cdd012016-08-22 13:59:31 +03002170static void gen8_ppgtt_info(struct seq_file *m,
2171 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002172{
Ben Widawsky77df6772013-11-02 21:07:30 -07002173 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302174 struct intel_engine_cs *engine;
2175 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002176 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002177
Ben Widawsky77df6772013-11-02 21:07:30 -07002178 if (!ppgtt)
2179 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002180
Akash Goel3b3f1652016-10-13 22:44:48 +05302181 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002182 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002183 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002184 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002185 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002186 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002187 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002188 }
2189 }
2190}
2191
David Weinehall36cdd012016-08-22 13:59:31 +03002192static void gen6_ppgtt_info(struct seq_file *m,
2193 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002194{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002195 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302196 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002197
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002198 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002199 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2200
Akash Goel3b3f1652016-10-13 22:44:48 +05302201 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002202 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002203 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002204 seq_printf(m, "GFX_MODE: 0x%08x\n",
2205 I915_READ(RING_MODE_GEN7(engine)));
2206 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2207 I915_READ(RING_PP_DIR_BASE(engine)));
2208 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2209 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2210 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2211 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002212 }
2213 if (dev_priv->mm.aliasing_ppgtt) {
2214 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2215
Damien Lespiau267f0c92013-06-24 22:59:48 +01002216 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002217 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002218
Ben Widawsky87d60b62013-12-06 14:11:29 -08002219 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002220 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002221
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002222 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002223}
2224
2225static int i915_ppgtt_info(struct seq_file *m, void *data)
2226{
David Weinehall36cdd012016-08-22 13:59:31 +03002227 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2228 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002229 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002230 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002231
Chris Wilson637ee292016-08-22 14:28:20 +01002232 mutex_lock(&dev->filelist_mutex);
2233 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002234 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002235 goto out_unlock;
2236
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002237 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002238
David Weinehall36cdd012016-08-22 13:59:31 +03002239 if (INTEL_GEN(dev_priv) >= 8)
2240 gen8_ppgtt_info(m, dev_priv);
2241 else if (INTEL_GEN(dev_priv) >= 6)
2242 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002243
Michel Thierryea91e402015-07-29 17:23:57 +01002244 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2245 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002246 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002247
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002248 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002249 if (!task) {
2250 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002251 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002252 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002253 seq_printf(m, "\nproc: %s\n", task->comm);
2254 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002255 idr_for_each(&file_priv->context_idr, per_file_ctx,
2256 (void *)(unsigned long)m);
2257 }
2258
Chris Wilson637ee292016-08-22 14:28:20 +01002259out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002260 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002261 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002262out_unlock:
2263 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002264 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002265}
2266
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002267static int count_irq_waiters(struct drm_i915_private *i915)
2268{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002269 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302270 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002271 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002272
Akash Goel3b3f1652016-10-13 22:44:48 +05302273 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002274 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002275
2276 return count;
2277}
2278
Chris Wilson7466c292016-08-15 09:49:33 +01002279static const char *rps_power_to_str(unsigned int power)
2280{
2281 static const char * const strings[] = {
2282 [LOW_POWER] = "low power",
2283 [BETWEEN] = "mixed",
2284 [HIGH_POWER] = "high power",
2285 };
2286
2287 if (power >= ARRAY_SIZE(strings) || !strings[power])
2288 return "unknown";
2289
2290 return strings[power];
2291}
2292
Chris Wilson1854d5c2015-04-07 16:20:32 +01002293static int i915_rps_boost_info(struct seq_file *m, void *data)
2294{
David Weinehall36cdd012016-08-22 13:59:31 +03002295 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2296 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002297 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002298
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002299 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002300 seq_printf(m, "GPU busy? %s [%d requests]\n",
2301 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002302 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002303 seq_printf(m, "Frequency requested %d\n",
2304 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2305 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002306 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2307 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2308 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2309 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002310 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2311 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2312 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2313 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002314
2315 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002316 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002317 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2318 struct drm_i915_file_private *file_priv = file->driver_priv;
2319 struct task_struct *task;
2320
2321 rcu_read_lock();
2322 task = pid_task(file->pid, PIDTYPE_PID);
2323 seq_printf(m, "%s [%d]: %d boosts%s\n",
2324 task ? task->comm : "<unknown>",
2325 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002326 file_priv->rps.boosts,
2327 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002328 rcu_read_unlock();
2329 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002330 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002331 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002332 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002333
Chris Wilson7466c292016-08-15 09:49:33 +01002334 if (INTEL_GEN(dev_priv) >= 6 &&
2335 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002336 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002337 u32 rpup, rpupei;
2338 u32 rpdown, rpdownei;
2339
2340 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2341 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2342 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2343 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2344 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2345 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2346
2347 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2348 rps_power_to_str(dev_priv->rps.power));
2349 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002350 rpup && rpupei ? 100 * rpup / rpupei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002351 dev_priv->rps.up_threshold);
2352 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002353 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002354 dev_priv->rps.down_threshold);
2355 } else {
2356 seq_puts(m, "\nRPS Autotuning inactive\n");
2357 }
2358
Chris Wilson8d3afd72015-05-21 21:01:47 +01002359 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002360}
2361
Ben Widawsky63573eb2013-07-04 11:02:07 -07002362static int i915_llc(struct seq_file *m, void *data)
2363{
David Weinehall36cdd012016-08-22 13:59:31 +03002364 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002365 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002366
David Weinehall36cdd012016-08-22 13:59:31 +03002367 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002368 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2369 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002370
2371 return 0;
2372}
2373
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002374static int i915_huc_load_status_info(struct seq_file *m, void *data)
2375{
2376 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2377 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2378
2379 if (!HAS_HUC_UCODE(dev_priv))
2380 return 0;
2381
2382 seq_puts(m, "HuC firmware status:\n");
2383 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2384 seq_printf(m, "\tfetch: %s\n",
2385 intel_uc_fw_status_repr(huc_fw->fetch_status));
2386 seq_printf(m, "\tload: %s\n",
2387 intel_uc_fw_status_repr(huc_fw->load_status));
2388 seq_printf(m, "\tversion wanted: %d.%d\n",
2389 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2390 seq_printf(m, "\tversion found: %d.%d\n",
2391 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2392 seq_printf(m, "\theader: offset is %d; size = %d\n",
2393 huc_fw->header_offset, huc_fw->header_size);
2394 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2395 huc_fw->ucode_offset, huc_fw->ucode_size);
2396 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2397 huc_fw->rsa_offset, huc_fw->rsa_size);
2398
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302399 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002400 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302401 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002402
2403 return 0;
2404}
2405
Alex Daifdf5d352015-08-12 15:43:37 +01002406static int i915_guc_load_status_info(struct seq_file *m, void *data)
2407{
David Weinehall36cdd012016-08-22 13:59:31 +03002408 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002409 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Daifdf5d352015-08-12 15:43:37 +01002410 u32 tmp, i;
2411
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002412 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002413 return 0;
2414
2415 seq_printf(m, "GuC firmware status:\n");
2416 seq_printf(m, "\tpath: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002417 guc_fw->path);
Alex Daifdf5d352015-08-12 15:43:37 +01002418 seq_printf(m, "\tfetch: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002419 intel_uc_fw_status_repr(guc_fw->fetch_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002420 seq_printf(m, "\tload: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002421 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002422 seq_printf(m, "\tversion wanted: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002423 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
Alex Daifdf5d352015-08-12 15:43:37 +01002424 seq_printf(m, "\tversion found: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002425 guc_fw->major_ver_found, guc_fw->minor_ver_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002426 seq_printf(m, "\theader: offset is %d; size = %d\n",
2427 guc_fw->header_offset, guc_fw->header_size);
2428 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2429 guc_fw->ucode_offset, guc_fw->ucode_size);
2430 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2431 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002432
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302433 intel_runtime_pm_get(dev_priv);
2434
Alex Daifdf5d352015-08-12 15:43:37 +01002435 tmp = I915_READ(GUC_STATUS);
2436
2437 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2438 seq_printf(m, "\tBootrom status = 0x%x\n",
2439 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2440 seq_printf(m, "\tuKernel status = 0x%x\n",
2441 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2442 seq_printf(m, "\tMIA Core status = 0x%x\n",
2443 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2444 seq_puts(m, "\nScratch registers:\n");
2445 for (i = 0; i < 16; i++)
2446 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2447
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302448 intel_runtime_pm_put(dev_priv);
2449
Alex Daifdf5d352015-08-12 15:43:37 +01002450 return 0;
2451}
2452
Akash Goel5aa1ee42016-10-12 21:54:36 +05302453static void i915_guc_log_info(struct seq_file *m,
2454 struct drm_i915_private *dev_priv)
2455{
2456 struct intel_guc *guc = &dev_priv->guc;
2457
2458 seq_puts(m, "\nGuC logging stats:\n");
2459
2460 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2461 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2462 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2463
2464 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2465 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2466 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2467
2468 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2469 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2470 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2471
2472 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2473 guc->log.flush_interrupt_count);
2474
2475 seq_printf(m, "\tCapture miss count: %u\n",
2476 guc->log.capture_miss_count);
2477}
2478
Dave Gordon8b417c22015-08-12 15:43:44 +01002479static void i915_guc_client_info(struct seq_file *m,
2480 struct drm_i915_private *dev_priv,
2481 struct i915_guc_client *client)
2482{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002483 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002484 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002485 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002486
Oscar Mateob09935a2017-03-22 10:39:53 -07002487 seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
2488 client->priority, client->stage_id, client->proc_desc_offset);
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002489 seq_printf(m, "\tDoorbell id %d, offset: 0x%lx, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002490 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002491 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2492 client->wq_size, client->wq_offset, client->wq_tail);
2493
Dave Gordon551aaec2016-05-13 15:36:33 +01002494 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002495
Akash Goel3b3f1652016-10-13 22:44:48 +05302496 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002497 u64 submissions = client->submissions[id];
2498 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002499 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002500 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002501 }
2502 seq_printf(m, "\tTotal: %llu\n", tot);
2503}
2504
Oscar Mateoa8b93702017-05-10 15:04:51 +00002505static bool check_guc_submission(struct seq_file *m)
Dave Gordon8b417c22015-08-12 15:43:44 +01002506{
David Weinehall36cdd012016-08-22 13:59:31 +03002507 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002508 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002509
Chris Wilson334636c2016-11-29 12:10:20 +00002510 if (!guc->execbuf_client) {
2511 seq_printf(m, "GuC submission %s\n",
2512 HAS_GUC_SCHED(dev_priv) ?
2513 "disabled" :
2514 "not supported");
Oscar Mateoa8b93702017-05-10 15:04:51 +00002515 return false;
Chris Wilson334636c2016-11-29 12:10:20 +00002516 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002517
Oscar Mateoa8b93702017-05-10 15:04:51 +00002518 return true;
2519}
2520
Dave Gordon8b417c22015-08-12 15:43:44 +01002521static int i915_guc_info(struct seq_file *m, void *data)
2522{
2523 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2524 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002525
Oscar Mateoa8b93702017-05-10 15:04:51 +00002526 if (!check_guc_submission(m))
Dave Gordon8b417c22015-08-12 15:43:44 +01002527 return 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002528
Dave Gordon9636f6d2016-06-13 17:57:28 +01002529 seq_printf(m, "Doorbell map:\n");
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002530 seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
Chris Wilson334636c2016-11-29 12:10:20 +00002531 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002532
Chris Wilson334636c2016-11-29 12:10:20 +00002533 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2534 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002535
Akash Goel5aa1ee42016-10-12 21:54:36 +05302536 i915_guc_log_info(m, dev_priv);
2537
Dave Gordon8b417c22015-08-12 15:43:44 +01002538 /* Add more as required ... */
2539
2540 return 0;
2541}
2542
Oscar Mateoa8b93702017-05-10 15:04:51 +00002543static int i915_guc_stage_pool(struct seq_file *m, void *data)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002544{
David Weinehall36cdd012016-08-22 13:59:31 +03002545 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Oscar Mateoa8b93702017-05-10 15:04:51 +00002546 const struct intel_guc *guc = &dev_priv->guc;
2547 struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
2548 struct i915_guc_client *client = guc->execbuf_client;
2549 unsigned int tmp;
2550 int index;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002551
Oscar Mateoa8b93702017-05-10 15:04:51 +00002552 if (!check_guc_submission(m))
Alex Dai4c7e77f2015-08-12 15:43:40 +01002553 return 0;
2554
Oscar Mateoa8b93702017-05-10 15:04:51 +00002555 for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
2556 struct intel_engine_cs *engine;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002557
Oscar Mateoa8b93702017-05-10 15:04:51 +00002558 if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
2559 continue;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002560
Oscar Mateoa8b93702017-05-10 15:04:51 +00002561 seq_printf(m, "GuC stage descriptor %u:\n", index);
2562 seq_printf(m, "\tIndex: %u\n", desc->stage_id);
2563 seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
2564 seq_printf(m, "\tPriority: %d\n", desc->priority);
2565 seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
2566 seq_printf(m, "\tEngines used: 0x%x\n",
2567 desc->engines_used);
2568 seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
2569 desc->db_trigger_phy,
2570 desc->db_trigger_cpu,
2571 desc->db_trigger_uk);
2572 seq_printf(m, "\tProcess descriptor: 0x%x\n",
2573 desc->process_desc);
Colin Ian King9a094852017-05-16 10:22:35 +01002574 seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
Oscar Mateoa8b93702017-05-10 15:04:51 +00002575 desc->wq_addr, desc->wq_size);
2576 seq_putc(m, '\n');
2577
2578 for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
2579 u32 guc_engine_id = engine->guc_id;
2580 struct guc_execlist_context *lrc =
2581 &desc->lrc[guc_engine_id];
2582
2583 seq_printf(m, "\t%s LRC:\n", engine->name);
2584 seq_printf(m, "\t\tContext desc: 0x%x\n",
2585 lrc->context_desc);
2586 seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
2587 seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
2588 seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
2589 seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
2590 seq_putc(m, '\n');
2591 }
Alex Dai4c7e77f2015-08-12 15:43:40 +01002592 }
2593
Oscar Mateoa8b93702017-05-10 15:04:51 +00002594 return 0;
2595}
2596
Alex Dai4c7e77f2015-08-12 15:43:40 +01002597static int i915_guc_log_dump(struct seq_file *m, void *data)
2598{
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002599 struct drm_info_node *node = m->private;
2600 struct drm_i915_private *dev_priv = node_to_i915(node);
2601 bool dump_load_err = !!node->info_ent->data;
2602 struct drm_i915_gem_object *obj = NULL;
2603 u32 *log;
2604 int i = 0;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002605
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002606 if (dump_load_err)
2607 obj = dev_priv->guc.load_err_log;
2608 else if (dev_priv->guc.log.vma)
2609 obj = dev_priv->guc.log.vma->obj;
2610
2611 if (!obj)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002612 return 0;
2613
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002614 log = i915_gem_object_pin_map(obj, I915_MAP_WC);
2615 if (IS_ERR(log)) {
2616 DRM_DEBUG("Failed to pin object\n");
2617 seq_puts(m, "(log data unaccessible)\n");
2618 return PTR_ERR(log);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002619 }
2620
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002621 for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
2622 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2623 *(log + i), *(log + i + 1),
2624 *(log + i + 2), *(log + i + 3));
2625
Alex Dai4c7e77f2015-08-12 15:43:40 +01002626 seq_putc(m, '\n');
2627
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002628 i915_gem_object_unpin_map(obj);
2629
Alex Dai4c7e77f2015-08-12 15:43:40 +01002630 return 0;
2631}
2632
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302633static int i915_guc_log_control_get(void *data, u64 *val)
2634{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002635 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302636
2637 if (!dev_priv->guc.log.vma)
2638 return -EINVAL;
2639
2640 *val = i915.guc_log_level;
2641
2642 return 0;
2643}
2644
2645static int i915_guc_log_control_set(void *data, u64 val)
2646{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002647 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302648 int ret;
2649
2650 if (!dev_priv->guc.log.vma)
2651 return -EINVAL;
2652
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002653 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302654 if (ret)
2655 return ret;
2656
2657 intel_runtime_pm_get(dev_priv);
2658 ret = i915_guc_log_control(dev_priv, val);
2659 intel_runtime_pm_put(dev_priv);
2660
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002661 mutex_unlock(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302662 return ret;
2663}
2664
2665DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2666 i915_guc_log_control_get, i915_guc_log_control_set,
2667 "%lld\n");
2668
Chris Wilsonb86bef202017-01-16 13:06:21 +00002669static const char *psr2_live_status(u32 val)
2670{
2671 static const char * const live_status[] = {
2672 "IDLE",
2673 "CAPTURE",
2674 "CAPTURE_FS",
2675 "SLEEP",
2676 "BUFON_FW",
2677 "ML_UP",
2678 "SU_STANDBY",
2679 "FAST_SLEEP",
2680 "DEEP_SLEEP",
2681 "BUF_ON",
2682 "TG_ON"
2683 };
2684
2685 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2686 if (val < ARRAY_SIZE(live_status))
2687 return live_status[val];
2688
2689 return "unknown";
2690}
2691
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002692static int i915_edp_psr_status(struct seq_file *m, void *data)
2693{
David Weinehall36cdd012016-08-22 13:59:31 +03002694 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002695 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002696 u32 stat[3];
2697 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002698 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002699
David Weinehall36cdd012016-08-22 13:59:31 +03002700 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002701 seq_puts(m, "PSR not supported\n");
2702 return 0;
2703 }
2704
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002705 intel_runtime_pm_get(dev_priv);
2706
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002707 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002708 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2709 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002710 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002711 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002712 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2713 dev_priv->psr.busy_frontbuffer_bits);
2714 seq_printf(m, "Re-enable work scheduled: %s\n",
2715 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002716
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302717 if (HAS_DDI(dev_priv)) {
2718 if (dev_priv->psr.psr2_support)
2719 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2720 else
2721 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2722 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002723 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002724 enum transcoder cpu_transcoder =
2725 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2726 enum intel_display_power_domain power_domain;
2727
2728 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2729 if (!intel_display_power_get_if_enabled(dev_priv,
2730 power_domain))
2731 continue;
2732
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002733 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2734 VLV_EDP_PSR_CURR_STATE_MASK;
2735 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2736 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2737 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002738
2739 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002740 }
2741 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002742
2743 seq_printf(m, "Main link in standby mode: %s\n",
2744 yesno(dev_priv->psr.link_standby));
2745
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002746 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002747
David Weinehall36cdd012016-08-22 13:59:31 +03002748 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002749 for_each_pipe(dev_priv, pipe) {
2750 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2751 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2752 seq_printf(m, " pipe %c", pipe_name(pipe));
2753 }
2754 seq_puts(m, "\n");
2755
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002756 /*
2757 * VLV/CHV PSR has no kind of performance counter
2758 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2759 */
David Weinehall36cdd012016-08-22 13:59:31 +03002760 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002761 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002762 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002763
2764 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2765 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302766 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002767 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302768
Chris Wilsonb86bef202017-01-16 13:06:21 +00002769 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2770 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302771 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002772 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002773
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002774 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002775 return 0;
2776}
2777
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002778static int i915_sink_crc(struct seq_file *m, void *data)
2779{
David Weinehall36cdd012016-08-22 13:59:31 +03002780 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2781 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002782 struct intel_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002783 struct drm_connector_list_iter conn_iter;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002784 struct intel_dp *intel_dp = NULL;
2785 int ret;
2786 u8 crc[6];
2787
2788 drm_modeset_lock_all(dev);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002789 drm_connector_list_iter_begin(dev, &conn_iter);
2790 for_each_intel_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002791 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002792
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002793 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002794 continue;
2795
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002796 crtc = connector->base.state->crtc;
2797 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002798 continue;
2799
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002800 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002801 continue;
2802
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002803 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002804
2805 ret = intel_dp_sink_crc(intel_dp, crc);
2806 if (ret)
2807 goto out;
2808
2809 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2810 crc[0], crc[1], crc[2],
2811 crc[3], crc[4], crc[5]);
2812 goto out;
2813 }
2814 ret = -ENODEV;
2815out:
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002816 drm_connector_list_iter_end(&conn_iter);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002817 drm_modeset_unlock_all(dev);
2818 return ret;
2819}
2820
Jesse Barnesec013e72013-08-20 10:29:23 +01002821static int i915_energy_uJ(struct seq_file *m, void *data)
2822{
David Weinehall36cdd012016-08-22 13:59:31 +03002823 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002824 u64 power;
2825 u32 units;
2826
David Weinehall36cdd012016-08-22 13:59:31 +03002827 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002828 return -ENODEV;
2829
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002830 intel_runtime_pm_get(dev_priv);
2831
Jesse Barnesec013e72013-08-20 10:29:23 +01002832 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2833 power = (power & 0x1f00) >> 8;
2834 units = 1000000 / (1 << power); /* convert to uJ */
2835 power = I915_READ(MCH_SECP_NRG_STTS);
2836 power *= units;
2837
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002838 intel_runtime_pm_put(dev_priv);
2839
Jesse Barnesec013e72013-08-20 10:29:23 +01002840 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002841
2842 return 0;
2843}
2844
Damien Lespiau6455c872015-06-04 18:23:57 +01002845static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002846{
David Weinehall36cdd012016-08-22 13:59:31 +03002847 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002848 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002849
Chris Wilsona156e642016-04-03 14:14:21 +01002850 if (!HAS_RUNTIME_PM(dev_priv))
2851 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002852
Chris Wilson67d97da2016-07-04 08:08:31 +01002853 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002854 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002855 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002856#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002857 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002858 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002859#else
2860 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2861#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002862 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002863 pci_power_name(pdev->current_state),
2864 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002865
Jesse Barnesec013e72013-08-20 10:29:23 +01002866 return 0;
2867}
2868
Imre Deak1da51582013-11-25 17:15:35 +02002869static int i915_power_domain_info(struct seq_file *m, void *unused)
2870{
David Weinehall36cdd012016-08-22 13:59:31 +03002871 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002872 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2873 int i;
2874
2875 mutex_lock(&power_domains->lock);
2876
2877 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2878 for (i = 0; i < power_domains->power_well_count; i++) {
2879 struct i915_power_well *power_well;
2880 enum intel_display_power_domain power_domain;
2881
2882 power_well = &power_domains->power_wells[i];
2883 seq_printf(m, "%-25s %d\n", power_well->name,
2884 power_well->count);
2885
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002886 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002887 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002888 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002889 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002890 }
2891
2892 mutex_unlock(&power_domains->lock);
2893
2894 return 0;
2895}
2896
Damien Lespiaub7cec662015-10-27 14:47:01 +02002897static int i915_dmc_info(struct seq_file *m, void *unused)
2898{
David Weinehall36cdd012016-08-22 13:59:31 +03002899 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002900 struct intel_csr *csr;
2901
David Weinehall36cdd012016-08-22 13:59:31 +03002902 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002903 seq_puts(m, "not supported\n");
2904 return 0;
2905 }
2906
2907 csr = &dev_priv->csr;
2908
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002909 intel_runtime_pm_get(dev_priv);
2910
Damien Lespiaub7cec662015-10-27 14:47:01 +02002911 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2912 seq_printf(m, "path: %s\n", csr->fw_path);
2913
2914 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002915 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002916
2917 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2918 CSR_VERSION_MINOR(csr->version));
2919
Mika Kuoppala48de5682017-05-09 13:05:22 +03002920 if (IS_KABYLAKE(dev_priv) ||
2921 (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6))) {
Damien Lespiau83372062015-10-30 17:53:32 +02002922 seq_printf(m, "DC3 -> DC5 count: %d\n",
2923 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2924 seq_printf(m, "DC5 -> DC6 count: %d\n",
2925 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002926 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002927 seq_printf(m, "DC3 -> DC5 count: %d\n",
2928 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002929 }
2930
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002931out:
2932 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2933 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2934 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2935
Damien Lespiau83372062015-10-30 17:53:32 +02002936 intel_runtime_pm_put(dev_priv);
2937
Damien Lespiaub7cec662015-10-27 14:47:01 +02002938 return 0;
2939}
2940
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002941static void intel_seq_print_mode(struct seq_file *m, int tabs,
2942 struct drm_display_mode *mode)
2943{
2944 int i;
2945
2946 for (i = 0; i < tabs; i++)
2947 seq_putc(m, '\t');
2948
2949 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",
2950 mode->base.id, mode->name,
2951 mode->vrefresh, mode->clock,
2952 mode->hdisplay, mode->hsync_start,
2953 mode->hsync_end, mode->htotal,
2954 mode->vdisplay, mode->vsync_start,
2955 mode->vsync_end, mode->vtotal,
2956 mode->type, mode->flags);
2957}
2958
2959static void intel_encoder_info(struct seq_file *m,
2960 struct intel_crtc *intel_crtc,
2961 struct intel_encoder *intel_encoder)
2962{
David Weinehall36cdd012016-08-22 13:59:31 +03002963 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2964 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002965 struct drm_crtc *crtc = &intel_crtc->base;
2966 struct intel_connector *intel_connector;
2967 struct drm_encoder *encoder;
2968
2969 encoder = &intel_encoder->base;
2970 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002971 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002972 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2973 struct drm_connector *connector = &intel_connector->base;
2974 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2975 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002976 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002977 drm_get_connector_status_name(connector->status));
2978 if (connector->status == connector_status_connected) {
2979 struct drm_display_mode *mode = &crtc->mode;
2980 seq_printf(m, ", mode:\n");
2981 intel_seq_print_mode(m, 2, mode);
2982 } else {
2983 seq_putc(m, '\n');
2984 }
2985 }
2986}
2987
2988static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2989{
David Weinehall36cdd012016-08-22 13:59:31 +03002990 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2991 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002992 struct drm_crtc *crtc = &intel_crtc->base;
2993 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002994 struct drm_plane_state *plane_state = crtc->primary->state;
2995 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002996
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002997 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002998 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002999 fb->base.id, plane_state->src_x >> 16,
3000 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07003001 else
3002 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003003 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
3004 intel_encoder_info(m, intel_crtc, intel_encoder);
3005}
3006
3007static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
3008{
3009 struct drm_display_mode *mode = panel->fixed_mode;
3010
3011 seq_printf(m, "\tfixed mode:\n");
3012 intel_seq_print_mode(m, 2, mode);
3013}
3014
3015static void intel_dp_info(struct seq_file *m,
3016 struct intel_connector *intel_connector)
3017{
3018 struct intel_encoder *intel_encoder = intel_connector->encoder;
3019 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
3020
3021 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03003022 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003023 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003024 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03003025
3026 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
3027 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003028}
3029
Libin Yang9a148a92016-11-28 20:07:05 +08003030static void intel_dp_mst_info(struct seq_file *m,
3031 struct intel_connector *intel_connector)
3032{
3033 struct intel_encoder *intel_encoder = intel_connector->encoder;
3034 struct intel_dp_mst_encoder *intel_mst =
3035 enc_to_mst(&intel_encoder->base);
3036 struct intel_digital_port *intel_dig_port = intel_mst->primary;
3037 struct intel_dp *intel_dp = &intel_dig_port->dp;
3038 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
3039 intel_connector->port);
3040
3041 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
3042}
3043
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003044static void intel_hdmi_info(struct seq_file *m,
3045 struct intel_connector *intel_connector)
3046{
3047 struct intel_encoder *intel_encoder = intel_connector->encoder;
3048 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
3049
Jani Nikula742f4912015-09-03 11:16:09 +03003050 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003051}
3052
3053static void intel_lvds_info(struct seq_file *m,
3054 struct intel_connector *intel_connector)
3055{
3056 intel_panel_info(m, &intel_connector->panel);
3057}
3058
3059static void intel_connector_info(struct seq_file *m,
3060 struct drm_connector *connector)
3061{
3062 struct intel_connector *intel_connector = to_intel_connector(connector);
3063 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08003064 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003065
3066 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03003067 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003068 drm_get_connector_status_name(connector->status));
3069 if (connector->status == connector_status_connected) {
3070 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3071 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3072 connector->display_info.width_mm,
3073 connector->display_info.height_mm);
3074 seq_printf(m, "\tsubpixel order: %s\n",
3075 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3076 seq_printf(m, "\tCEA rev: %d\n",
3077 connector->display_info.cea_rev);
3078 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003079
3080 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3081 return;
3082
3083 switch (connector->connector_type) {
3084 case DRM_MODE_CONNECTOR_DisplayPort:
3085 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003086 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3087 intel_dp_mst_info(m, intel_connector);
3088 else
3089 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003090 break;
3091 case DRM_MODE_CONNECTOR_LVDS:
3092 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003093 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003094 break;
3095 case DRM_MODE_CONNECTOR_HDMIA:
3096 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3097 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3098 intel_hdmi_info(m, intel_connector);
3099 break;
3100 default:
3101 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003102 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003103
Jesse Barnesf103fc72014-02-20 12:39:57 -08003104 seq_printf(m, "\tmodes:\n");
3105 list_for_each_entry(mode, &connector->modes, head)
3106 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003107}
3108
Robert Fekete3abc4e02015-10-27 16:58:32 +01003109static const char *plane_type(enum drm_plane_type type)
3110{
3111 switch (type) {
3112 case DRM_PLANE_TYPE_OVERLAY:
3113 return "OVL";
3114 case DRM_PLANE_TYPE_PRIMARY:
3115 return "PRI";
3116 case DRM_PLANE_TYPE_CURSOR:
3117 return "CUR";
3118 /*
3119 * Deliberately omitting default: to generate compiler warnings
3120 * when a new drm_plane_type gets added.
3121 */
3122 }
3123
3124 return "unknown";
3125}
3126
3127static const char *plane_rotation(unsigned int rotation)
3128{
3129 static char buf[48];
3130 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003131 * According to doc only one DRM_MODE_ROTATE_ is allowed but this
Robert Fekete3abc4e02015-10-27 16:58:32 +01003132 * will print them all to visualize if the values are misused
3133 */
3134 snprintf(buf, sizeof(buf),
3135 "%s%s%s%s%s%s(0x%08x)",
Robert Fossc2c446a2017-05-19 16:50:17 -04003136 (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
3137 (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
3138 (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
3139 (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
3140 (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
3141 (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003142 rotation);
3143
3144 return buf;
3145}
3146
3147static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3148{
David Weinehall36cdd012016-08-22 13:59:31 +03003149 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3150 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003151 struct intel_plane *intel_plane;
3152
3153 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3154 struct drm_plane_state *state;
3155 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003156 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003157
3158 if (!plane->state) {
3159 seq_puts(m, "plane->state is NULL!\n");
3160 continue;
3161 }
3162
3163 state = plane->state;
3164
Eric Engestrom90844f02016-08-15 01:02:38 +01003165 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003166 drm_get_format_name(state->fb->format->format,
3167 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003168 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003169 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003170 }
3171
Robert Fekete3abc4e02015-10-27 16:58:32 +01003172 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",
3173 plane->base.id,
3174 plane_type(intel_plane->base.type),
3175 state->crtc_x, state->crtc_y,
3176 state->crtc_w, state->crtc_h,
3177 (state->src_x >> 16),
3178 ((state->src_x & 0xffff) * 15625) >> 10,
3179 (state->src_y >> 16),
3180 ((state->src_y & 0xffff) * 15625) >> 10,
3181 (state->src_w >> 16),
3182 ((state->src_w & 0xffff) * 15625) >> 10,
3183 (state->src_h >> 16),
3184 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003185 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003186 plane_rotation(state->rotation));
3187 }
3188}
3189
3190static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3191{
3192 struct intel_crtc_state *pipe_config;
3193 int num_scalers = intel_crtc->num_scalers;
3194 int i;
3195
3196 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3197
3198 /* Not all platformas have a scaler */
3199 if (num_scalers) {
3200 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3201 num_scalers,
3202 pipe_config->scaler_state.scaler_users,
3203 pipe_config->scaler_state.scaler_id);
3204
A.Sunil Kamath58415912016-11-20 23:20:26 +05303205 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003206 struct intel_scaler *sc =
3207 &pipe_config->scaler_state.scalers[i];
3208
3209 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3210 i, yesno(sc->in_use), sc->mode);
3211 }
3212 seq_puts(m, "\n");
3213 } else {
3214 seq_puts(m, "\tNo scalers available on this platform\n");
3215 }
3216}
3217
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003218static int i915_display_info(struct seq_file *m, void *unused)
3219{
David Weinehall36cdd012016-08-22 13:59:31 +03003220 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3221 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003222 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003223 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003224 struct drm_connector_list_iter conn_iter;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003225
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003226 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003227 seq_printf(m, "CRTC info\n");
3228 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003229 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003230 struct intel_crtc_state *pipe_config;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003231
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003232 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003233 pipe_config = to_intel_crtc_state(crtc->base.state);
3234
Robert Fekete3abc4e02015-10-27 16:58:32 +01003235 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003236 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003237 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003238 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3239 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3240
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003241 if (pipe_config->base.active) {
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003242 struct intel_plane *cursor =
3243 to_intel_plane(crtc->base.cursor);
3244
Chris Wilson065f2ec2014-03-12 09:13:13 +00003245 intel_crtc_info(m, crtc);
3246
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003247 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x\n",
3248 yesno(cursor->base.state->visible),
3249 cursor->base.state->crtc_x,
3250 cursor->base.state->crtc_y,
3251 cursor->base.state->crtc_w,
3252 cursor->base.state->crtc_h,
3253 cursor->cursor.base);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003254 intel_scaler_info(m, crtc);
3255 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003256 }
Daniel Vettercace8412014-05-22 17:56:31 +02003257
3258 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3259 yesno(!crtc->cpu_fifo_underrun_disabled),
3260 yesno(!crtc->pch_fifo_underrun_disabled));
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003261 drm_modeset_unlock(&crtc->base.mutex);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003262 }
3263
3264 seq_printf(m, "\n");
3265 seq_printf(m, "Connector info\n");
3266 seq_printf(m, "--------------\n");
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003267 mutex_lock(&dev->mode_config.mutex);
3268 drm_connector_list_iter_begin(dev, &conn_iter);
3269 drm_for_each_connector_iter(connector, &conn_iter)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003270 intel_connector_info(m, connector);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003271 drm_connector_list_iter_end(&conn_iter);
3272 mutex_unlock(&dev->mode_config.mutex);
3273
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003274 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003275
3276 return 0;
3277}
3278
Chris Wilson1b365952016-10-04 21:11:31 +01003279static int i915_engine_info(struct seq_file *m, void *unused)
3280{
3281 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3282 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303283 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003284
Chris Wilson9c870d02016-10-24 13:42:15 +01003285 intel_runtime_pm_get(dev_priv);
3286
Chris Wilsonf73b5672017-03-02 15:03:56 +00003287 seq_printf(m, "GT awake? %s\n",
3288 yesno(dev_priv->gt.awake));
3289 seq_printf(m, "Global active requests: %d\n",
3290 dev_priv->gt.active_requests);
3291
Akash Goel3b3f1652016-10-13 22:44:48 +05303292 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003293 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3294 struct drm_i915_gem_request *rq;
3295 struct rb_node *rb;
3296 u64 addr;
3297
3298 seq_printf(m, "%s\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003299 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003300 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003301 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003302 engine->hangcheck.seqno,
Chris Wilsonf73b5672017-03-02 15:03:56 +00003303 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp),
3304 engine->timeline->inflight_seqnos);
Chris Wilson1b365952016-10-04 21:11:31 +01003305
3306 rcu_read_lock();
3307
3308 seq_printf(m, "\tRequests:\n");
3309
Chris Wilson73cb9702016-10-28 13:58:46 +01003310 rq = list_first_entry(&engine->timeline->requests,
3311 struct drm_i915_gem_request, link);
3312 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003313 print_request(m, rq, "\t\tfirst ");
3314
Chris Wilson73cb9702016-10-28 13:58:46 +01003315 rq = list_last_entry(&engine->timeline->requests,
3316 struct drm_i915_gem_request, link);
3317 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003318 print_request(m, rq, "\t\tlast ");
3319
3320 rq = i915_gem_find_active_request(engine);
3321 if (rq) {
3322 print_request(m, rq, "\t\tactive ");
3323 seq_printf(m,
3324 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3325 rq->head, rq->postfix, rq->tail,
3326 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3327 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3328 }
3329
3330 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3331 I915_READ(RING_START(engine->mmio_base)),
3332 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3333 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3334 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3335 rq ? rq->ring->head : 0);
3336 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3337 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3338 rq ? rq->ring->tail : 0);
3339 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3340 I915_READ(RING_CTL(engine->mmio_base)),
3341 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3342
3343 rcu_read_unlock();
3344
3345 addr = intel_engine_get_active_head(engine);
3346 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3347 upper_32_bits(addr), lower_32_bits(addr));
3348 addr = intel_engine_get_last_batch_head(engine);
3349 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3350 upper_32_bits(addr), lower_32_bits(addr));
3351
3352 if (i915.enable_execlists) {
3353 u32 ptr, read, write;
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003354 unsigned int idx;
Chris Wilson1b365952016-10-04 21:11:31 +01003355
3356 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3357 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3358 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3359
3360 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3361 read = GEN8_CSB_READ_PTR(ptr);
3362 write = GEN8_CSB_WRITE_PTR(ptr);
3363 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3364 read, write);
3365 if (read >= GEN8_CSB_ENTRIES)
3366 read = 0;
3367 if (write >= GEN8_CSB_ENTRIES)
3368 write = 0;
3369 if (read > write)
3370 write += GEN8_CSB_ENTRIES;
3371 while (read < write) {
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003372 idx = ++read % GEN8_CSB_ENTRIES;
Chris Wilson1b365952016-10-04 21:11:31 +01003373 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3374 idx,
3375 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3376 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3377 }
3378
3379 rcu_read_lock();
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003380 for (idx = 0; idx < ARRAY_SIZE(engine->execlist_port); idx++) {
3381 unsigned int count;
3382
3383 rq = port_unpack(&engine->execlist_port[idx],
3384 &count);
3385 if (rq) {
3386 seq_printf(m, "\t\tELSP[%d] count=%d, ",
3387 idx, count);
3388 print_request(m, rq, "rq: ");
3389 } else {
3390 seq_printf(m, "\t\tELSP[%d] idle\n",
3391 idx);
3392 }
Chris Wilson816ee792017-01-24 11:00:03 +00003393 }
Chris Wilson1b365952016-10-04 21:11:31 +01003394 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003395
Chris Wilson663f71e2016-11-14 20:41:00 +00003396 spin_lock_irq(&engine->timeline->lock);
Chris Wilson6c067572017-05-17 13:10:03 +01003397 for (rb = engine->execlist_first; rb; rb = rb_next(rb)){
3398 struct i915_priolist *p =
3399 rb_entry(rb, typeof(*p), node);
3400
3401 list_for_each_entry(rq, &p->requests,
3402 priotree.link)
3403 print_request(m, rq, "\t\tQ ");
Chris Wilsonc8247c02016-10-27 01:03:43 +01003404 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003405 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003406 } else if (INTEL_GEN(dev_priv) > 6) {
3407 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3408 I915_READ(RING_PP_DIR_BASE(engine)));
3409 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3410 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3411 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3412 I915_READ(RING_PP_DIR_DCLV(engine)));
3413 }
3414
Chris Wilson61d3dc72017-03-03 19:08:24 +00003415 spin_lock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003416 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08003417 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson1b365952016-10-04 21:11:31 +01003418
3419 seq_printf(m, "\t%s [%d] waiting for %x\n",
3420 w->tsk->comm, w->tsk->pid, w->seqno);
3421 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00003422 spin_unlock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003423
3424 seq_puts(m, "\n");
3425 }
3426
Chris Wilson9c870d02016-10-24 13:42:15 +01003427 intel_runtime_pm_put(dev_priv);
3428
Chris Wilson1b365952016-10-04 21:11:31 +01003429 return 0;
3430}
3431
Ben Widawskye04934c2014-06-30 09:53:42 -07003432static int i915_semaphore_status(struct seq_file *m, void *unused)
3433{
David Weinehall36cdd012016-08-22 13:59:31 +03003434 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3435 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003436 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003437 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003438 enum intel_engine_id id;
3439 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003440
Chris Wilson39df9192016-07-20 13:31:57 +01003441 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003442 seq_puts(m, "Semaphores are disabled\n");
3443 return 0;
3444 }
3445
3446 ret = mutex_lock_interruptible(&dev->struct_mutex);
3447 if (ret)
3448 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003449 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003450
David Weinehall36cdd012016-08-22 13:59:31 +03003451 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003452 struct page *page;
3453 uint64_t *seqno;
3454
Chris Wilson51d545d2016-08-15 10:49:02 +01003455 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003456
3457 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303458 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003459 uint64_t offset;
3460
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003461 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003462
3463 seq_puts(m, " Last signal:");
3464 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003465 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003466 seq_printf(m, "0x%08llx (0x%02llx) ",
3467 seqno[offset], offset * 8);
3468 }
3469 seq_putc(m, '\n');
3470
3471 seq_puts(m, " Last wait: ");
3472 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003473 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003474 seq_printf(m, "0x%08llx (0x%02llx) ",
3475 seqno[offset], offset * 8);
3476 }
3477 seq_putc(m, '\n');
3478
3479 }
3480 kunmap_atomic(seqno);
3481 } else {
3482 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303483 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003484 for (j = 0; j < num_rings; j++)
3485 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003486 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003487 seq_putc(m, '\n');
3488 }
3489
Paulo Zanoni03872062014-07-09 14:31:57 -03003490 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003491 mutex_unlock(&dev->struct_mutex);
3492 return 0;
3493}
3494
Daniel Vetter728e29d2014-06-25 22:01:53 +03003495static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3496{
David Weinehall36cdd012016-08-22 13:59:31 +03003497 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3498 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003499 int i;
3500
3501 drm_modeset_lock_all(dev);
3502 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3503 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3504
3505 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003506 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003507 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003508 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003509 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003510 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003511 pll->state.hw_state.dpll_md);
3512 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3513 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3514 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003515 }
3516 drm_modeset_unlock_all(dev);
3517
3518 return 0;
3519}
3520
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003521static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003522{
3523 int i;
3524 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003525 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003526 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3527 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003528 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003529 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003530
Arun Siluvery888b5992014-08-26 14:44:51 +01003531 ret = mutex_lock_interruptible(&dev->struct_mutex);
3532 if (ret)
3533 return ret;
3534
3535 intel_runtime_pm_get(dev_priv);
3536
Arun Siluvery33136b02016-01-21 21:43:47 +00003537 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303538 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003539 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003540 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003541 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003542 i915_reg_t addr;
3543 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003544 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003545
Arun Siluvery33136b02016-01-21 21:43:47 +00003546 addr = workarounds->reg[i].addr;
3547 mask = workarounds->reg[i].mask;
3548 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003549 read = I915_READ(addr);
3550 ok = (value & mask) == (read & mask);
3551 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 +02003552 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003553 }
3554
3555 intel_runtime_pm_put(dev_priv);
3556 mutex_unlock(&dev->struct_mutex);
3557
3558 return 0;
3559}
3560
Damien Lespiauc5511e42014-11-04 17:06:51 +00003561static int i915_ddb_info(struct seq_file *m, void *unused)
3562{
David Weinehall36cdd012016-08-22 13:59:31 +03003563 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3564 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003565 struct skl_ddb_allocation *ddb;
3566 struct skl_ddb_entry *entry;
3567 enum pipe pipe;
3568 int plane;
3569
David Weinehall36cdd012016-08-22 13:59:31 +03003570 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003571 return 0;
3572
Damien Lespiauc5511e42014-11-04 17:06:51 +00003573 drm_modeset_lock_all(dev);
3574
3575 ddb = &dev_priv->wm.skl_hw.ddb;
3576
3577 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3578
3579 for_each_pipe(dev_priv, pipe) {
3580 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3581
Matt Roper8b364b42016-10-26 15:51:28 -07003582 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003583 entry = &ddb->plane[pipe][plane];
3584 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3585 entry->start, entry->end,
3586 skl_ddb_entry_size(entry));
3587 }
3588
Matt Roper4969d332015-09-24 15:53:10 -07003589 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003590 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3591 entry->end, skl_ddb_entry_size(entry));
3592 }
3593
3594 drm_modeset_unlock_all(dev);
3595
3596 return 0;
3597}
3598
Vandana Kannana54746e2015-03-03 20:53:10 +05303599static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003600 struct drm_device *dev,
3601 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303602{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003603 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303604 struct i915_drrs *drrs = &dev_priv->drrs;
3605 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003606 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003607 struct drm_connector_list_iter conn_iter;
Vandana Kannana54746e2015-03-03 20:53:10 +05303608
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003609 drm_connector_list_iter_begin(dev, &conn_iter);
3610 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003611 if (connector->state->crtc != &intel_crtc->base)
3612 continue;
3613
3614 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303615 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003616 drm_connector_list_iter_end(&conn_iter);
Vandana Kannana54746e2015-03-03 20:53:10 +05303617
3618 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3619 seq_puts(m, "\tVBT: DRRS_type: Static");
3620 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3621 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3622 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3623 seq_puts(m, "\tVBT: DRRS_type: None");
3624 else
3625 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3626
3627 seq_puts(m, "\n\n");
3628
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003629 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303630 struct intel_panel *panel;
3631
3632 mutex_lock(&drrs->mutex);
3633 /* DRRS Supported */
3634 seq_puts(m, "\tDRRS Supported: Yes\n");
3635
3636 /* disable_drrs() will make drrs->dp NULL */
3637 if (!drrs->dp) {
3638 seq_puts(m, "Idleness DRRS: Disabled");
3639 mutex_unlock(&drrs->mutex);
3640 return;
3641 }
3642
3643 panel = &drrs->dp->attached_connector->panel;
3644 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3645 drrs->busy_frontbuffer_bits);
3646
3647 seq_puts(m, "\n\t\t");
3648 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3649 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3650 vrefresh = panel->fixed_mode->vrefresh;
3651 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3652 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3653 vrefresh = panel->downclock_mode->vrefresh;
3654 } else {
3655 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3656 drrs->refresh_rate_type);
3657 mutex_unlock(&drrs->mutex);
3658 return;
3659 }
3660 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3661
3662 seq_puts(m, "\n\t\t");
3663 mutex_unlock(&drrs->mutex);
3664 } else {
3665 /* DRRS not supported. Print the VBT parameter*/
3666 seq_puts(m, "\tDRRS Supported : No");
3667 }
3668 seq_puts(m, "\n");
3669}
3670
3671static int i915_drrs_status(struct seq_file *m, void *unused)
3672{
David Weinehall36cdd012016-08-22 13:59:31 +03003673 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3674 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303675 struct intel_crtc *intel_crtc;
3676 int active_crtc_cnt = 0;
3677
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003678 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303679 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003680 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303681 active_crtc_cnt++;
3682 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3683
3684 drrs_status_per_crtc(m, dev, intel_crtc);
3685 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303686 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003687 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303688
3689 if (!active_crtc_cnt)
3690 seq_puts(m, "No active crtc found\n");
3691
3692 return 0;
3693}
3694
Dave Airlie11bed952014-05-12 15:22:27 +10003695static int i915_dp_mst_info(struct seq_file *m, void *unused)
3696{
David Weinehall36cdd012016-08-22 13:59:31 +03003697 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3698 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003699 struct intel_encoder *intel_encoder;
3700 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003701 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003702 struct drm_connector_list_iter conn_iter;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003703
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003704 drm_connector_list_iter_begin(dev, &conn_iter);
3705 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003706 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003707 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003708
3709 intel_encoder = intel_attached_encoder(connector);
3710 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3711 continue;
3712
3713 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003714 if (!intel_dig_port->dp.can_mst)
3715 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003716
Jim Bride40ae80c2016-04-14 10:18:37 -07003717 seq_printf(m, "MST Source Port %c\n",
3718 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003719 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3720 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003721 drm_connector_list_iter_end(&conn_iter);
3722
Dave Airlie11bed952014-05-12 15:22:27 +10003723 return 0;
3724}
3725
Todd Previteeb3394fa2015-04-18 00:04:19 -07003726static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003727 const char __user *ubuf,
3728 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003729{
3730 char *input_buffer;
3731 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003732 struct drm_device *dev;
3733 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003734 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003735 struct intel_dp *intel_dp;
3736 int val = 0;
3737
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303738 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003739
Todd Previteeb3394fa2015-04-18 00:04:19 -07003740 if (len == 0)
3741 return 0;
3742
Geliang Tang261aeba2017-05-06 23:40:17 +08003743 input_buffer = memdup_user_nul(ubuf, len);
3744 if (IS_ERR(input_buffer))
3745 return PTR_ERR(input_buffer);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003746
Todd Previteeb3394fa2015-04-18 00:04:19 -07003747 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3748
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003749 drm_connector_list_iter_begin(dev, &conn_iter);
3750 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003751 if (connector->connector_type !=
3752 DRM_MODE_CONNECTOR_DisplayPort)
3753 continue;
3754
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05303755 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07003756 connector->encoder != NULL) {
3757 intel_dp = enc_to_intel_dp(connector->encoder);
3758 status = kstrtoint(input_buffer, 10, &val);
3759 if (status < 0)
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003760 break;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003761 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3762 /* To prevent erroneous activation of the compliance
3763 * testing code, only accept an actual value of 1 here
3764 */
3765 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003766 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003767 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003768 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003769 }
3770 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003771 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003772 kfree(input_buffer);
3773 if (status < 0)
3774 return status;
3775
3776 *offp += len;
3777 return len;
3778}
3779
3780static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3781{
3782 struct drm_device *dev = m->private;
3783 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003784 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003785 struct intel_dp *intel_dp;
3786
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003787 drm_connector_list_iter_begin(dev, &conn_iter);
3788 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003789 if (connector->connector_type !=
3790 DRM_MODE_CONNECTOR_DisplayPort)
3791 continue;
3792
3793 if (connector->status == connector_status_connected &&
3794 connector->encoder != NULL) {
3795 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003796 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003797 seq_puts(m, "1");
3798 else
3799 seq_puts(m, "0");
3800 } else
3801 seq_puts(m, "0");
3802 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003803 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003804
3805 return 0;
3806}
3807
3808static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003809 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003810{
David Weinehall36cdd012016-08-22 13:59:31 +03003811 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003812
David Weinehall36cdd012016-08-22 13:59:31 +03003813 return single_open(file, i915_displayport_test_active_show,
3814 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003815}
3816
3817static const struct file_operations i915_displayport_test_active_fops = {
3818 .owner = THIS_MODULE,
3819 .open = i915_displayport_test_active_open,
3820 .read = seq_read,
3821 .llseek = seq_lseek,
3822 .release = single_release,
3823 .write = i915_displayport_test_active_write
3824};
3825
3826static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3827{
3828 struct drm_device *dev = m->private;
3829 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003830 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003831 struct intel_dp *intel_dp;
3832
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003833 drm_connector_list_iter_begin(dev, &conn_iter);
3834 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003835 if (connector->connector_type !=
3836 DRM_MODE_CONNECTOR_DisplayPort)
3837 continue;
3838
3839 if (connector->status == connector_status_connected &&
3840 connector->encoder != NULL) {
3841 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003842 if (intel_dp->compliance.test_type ==
3843 DP_TEST_LINK_EDID_READ)
3844 seq_printf(m, "%lx",
3845 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003846 else if (intel_dp->compliance.test_type ==
3847 DP_TEST_LINK_VIDEO_PATTERN) {
3848 seq_printf(m, "hdisplay: %d\n",
3849 intel_dp->compliance.test_data.hdisplay);
3850 seq_printf(m, "vdisplay: %d\n",
3851 intel_dp->compliance.test_data.vdisplay);
3852 seq_printf(m, "bpc: %u\n",
3853 intel_dp->compliance.test_data.bpc);
3854 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003855 } else
3856 seq_puts(m, "0");
3857 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003858 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003859
3860 return 0;
3861}
3862static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003863 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003864{
David Weinehall36cdd012016-08-22 13:59:31 +03003865 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003866
David Weinehall36cdd012016-08-22 13:59:31 +03003867 return single_open(file, i915_displayport_test_data_show,
3868 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003869}
3870
3871static const struct file_operations i915_displayport_test_data_fops = {
3872 .owner = THIS_MODULE,
3873 .open = i915_displayport_test_data_open,
3874 .read = seq_read,
3875 .llseek = seq_lseek,
3876 .release = single_release
3877};
3878
3879static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3880{
3881 struct drm_device *dev = m->private;
3882 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003883 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003884 struct intel_dp *intel_dp;
3885
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003886 drm_connector_list_iter_begin(dev, &conn_iter);
3887 drm_for_each_connector_iter(connector, &conn_iter) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003888 if (connector->connector_type !=
3889 DRM_MODE_CONNECTOR_DisplayPort)
3890 continue;
3891
3892 if (connector->status == connector_status_connected &&
3893 connector->encoder != NULL) {
3894 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003895 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003896 } else
3897 seq_puts(m, "0");
3898 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003899 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003900
3901 return 0;
3902}
3903
3904static int i915_displayport_test_type_open(struct inode *inode,
3905 struct file *file)
3906{
David Weinehall36cdd012016-08-22 13:59:31 +03003907 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003908
David Weinehall36cdd012016-08-22 13:59:31 +03003909 return single_open(file, i915_displayport_test_type_show,
3910 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003911}
3912
3913static const struct file_operations i915_displayport_test_type_fops = {
3914 .owner = THIS_MODULE,
3915 .open = i915_displayport_test_type_open,
3916 .read = seq_read,
3917 .llseek = seq_lseek,
3918 .release = single_release
3919};
3920
Damien Lespiau97e94b22014-11-04 17:06:50 +00003921static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003922{
David Weinehall36cdd012016-08-22 13:59:31 +03003923 struct drm_i915_private *dev_priv = m->private;
3924 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003925 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003926 int num_levels;
3927
David Weinehall36cdd012016-08-22 13:59:31 +03003928 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003929 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003930 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003931 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003932 else if (IS_G4X(dev_priv))
3933 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003934 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003935 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003936
3937 drm_modeset_lock_all(dev);
3938
3939 for (level = 0; level < num_levels; level++) {
3940 unsigned int latency = wm[level];
3941
Damien Lespiau97e94b22014-11-04 17:06:50 +00003942 /*
3943 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003944 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003945 */
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003946 if (INTEL_GEN(dev_priv) >= 9 ||
3947 IS_VALLEYVIEW(dev_priv) ||
3948 IS_CHERRYVIEW(dev_priv) ||
3949 IS_G4X(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003950 latency *= 10;
3951 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003952 latency *= 5;
3953
3954 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003955 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003956 }
3957
3958 drm_modeset_unlock_all(dev);
3959}
3960
3961static int pri_wm_latency_show(struct seq_file *m, void *data)
3962{
David Weinehall36cdd012016-08-22 13:59:31 +03003963 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003964 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003965
David Weinehall36cdd012016-08-22 13:59:31 +03003966 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003967 latencies = dev_priv->wm.skl_latency;
3968 else
David Weinehall36cdd012016-08-22 13:59:31 +03003969 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003970
3971 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003972
3973 return 0;
3974}
3975
3976static int spr_wm_latency_show(struct seq_file *m, void *data)
3977{
David Weinehall36cdd012016-08-22 13:59:31 +03003978 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003979 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003980
David Weinehall36cdd012016-08-22 13:59:31 +03003981 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003982 latencies = dev_priv->wm.skl_latency;
3983 else
David Weinehall36cdd012016-08-22 13:59:31 +03003984 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003985
3986 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003987
3988 return 0;
3989}
3990
3991static int cur_wm_latency_show(struct seq_file *m, void *data)
3992{
David Weinehall36cdd012016-08-22 13:59:31 +03003993 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003994 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003995
David Weinehall36cdd012016-08-22 13:59:31 +03003996 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003997 latencies = dev_priv->wm.skl_latency;
3998 else
David Weinehall36cdd012016-08-22 13:59:31 +03003999 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004000
4001 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004002
4003 return 0;
4004}
4005
4006static int pri_wm_latency_open(struct inode *inode, struct file *file)
4007{
David Weinehall36cdd012016-08-22 13:59:31 +03004008 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004009
Ville Syrjälä04548cb2017-04-21 21:14:29 +03004010 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004011 return -ENODEV;
4012
David Weinehall36cdd012016-08-22 13:59:31 +03004013 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004014}
4015
4016static int spr_wm_latency_open(struct inode *inode, struct file *file)
4017{
David Weinehall36cdd012016-08-22 13:59:31 +03004018 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004019
David Weinehall36cdd012016-08-22 13:59:31 +03004020 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004021 return -ENODEV;
4022
David Weinehall36cdd012016-08-22 13:59:31 +03004023 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004024}
4025
4026static int cur_wm_latency_open(struct inode *inode, struct file *file)
4027{
David Weinehall36cdd012016-08-22 13:59:31 +03004028 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004029
David Weinehall36cdd012016-08-22 13:59:31 +03004030 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004031 return -ENODEV;
4032
David Weinehall36cdd012016-08-22 13:59:31 +03004033 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004034}
4035
4036static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004037 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004038{
4039 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004040 struct drm_i915_private *dev_priv = m->private;
4041 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004042 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004043 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004044 int level;
4045 int ret;
4046 char tmp[32];
4047
David Weinehall36cdd012016-08-22 13:59:31 +03004048 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004049 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004050 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004051 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03004052 else if (IS_G4X(dev_priv))
4053 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004054 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004055 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004056
Ville Syrjälä369a1342014-01-22 14:36:08 +02004057 if (len >= sizeof(tmp))
4058 return -EINVAL;
4059
4060 if (copy_from_user(tmp, ubuf, len))
4061 return -EFAULT;
4062
4063 tmp[len] = '\0';
4064
Damien Lespiau97e94b22014-11-04 17:06:50 +00004065 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4066 &new[0], &new[1], &new[2], &new[3],
4067 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004068 if (ret != num_levels)
4069 return -EINVAL;
4070
4071 drm_modeset_lock_all(dev);
4072
4073 for (level = 0; level < num_levels; level++)
4074 wm[level] = new[level];
4075
4076 drm_modeset_unlock_all(dev);
4077
4078 return len;
4079}
4080
4081
4082static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4083 size_t len, loff_t *offp)
4084{
4085 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004086 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004087 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004088
David Weinehall36cdd012016-08-22 13:59:31 +03004089 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004090 latencies = dev_priv->wm.skl_latency;
4091 else
David Weinehall36cdd012016-08-22 13:59:31 +03004092 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004093
4094 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004095}
4096
4097static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4098 size_t len, loff_t *offp)
4099{
4100 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004101 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004102 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004103
David Weinehall36cdd012016-08-22 13:59:31 +03004104 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004105 latencies = dev_priv->wm.skl_latency;
4106 else
David Weinehall36cdd012016-08-22 13:59:31 +03004107 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004108
4109 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004110}
4111
4112static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4113 size_t len, loff_t *offp)
4114{
4115 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004116 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004117 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004118
David Weinehall36cdd012016-08-22 13:59:31 +03004119 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004120 latencies = dev_priv->wm.skl_latency;
4121 else
David Weinehall36cdd012016-08-22 13:59:31 +03004122 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004123
4124 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004125}
4126
4127static const struct file_operations i915_pri_wm_latency_fops = {
4128 .owner = THIS_MODULE,
4129 .open = pri_wm_latency_open,
4130 .read = seq_read,
4131 .llseek = seq_lseek,
4132 .release = single_release,
4133 .write = pri_wm_latency_write
4134};
4135
4136static const struct file_operations i915_spr_wm_latency_fops = {
4137 .owner = THIS_MODULE,
4138 .open = spr_wm_latency_open,
4139 .read = seq_read,
4140 .llseek = seq_lseek,
4141 .release = single_release,
4142 .write = spr_wm_latency_write
4143};
4144
4145static const struct file_operations i915_cur_wm_latency_fops = {
4146 .owner = THIS_MODULE,
4147 .open = cur_wm_latency_open,
4148 .read = seq_read,
4149 .llseek = seq_lseek,
4150 .release = single_release,
4151 .write = cur_wm_latency_write
4152};
4153
Kees Cook647416f2013-03-10 14:10:06 -07004154static int
4155i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004156{
David Weinehall36cdd012016-08-22 13:59:31 +03004157 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004158
Chris Wilsond98c52c2016-04-13 17:35:05 +01004159 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004160
Kees Cook647416f2013-03-10 14:10:06 -07004161 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004162}
4163
Kees Cook647416f2013-03-10 14:10:06 -07004164static int
4165i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004166{
Chris Wilson598b6b52017-03-25 13:47:35 +00004167 struct drm_i915_private *i915 = data;
4168 struct intel_engine_cs *engine;
4169 unsigned int tmp;
Imre Deakd46c0512014-04-14 20:24:27 +03004170
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004171 /*
4172 * There is no safeguard against this debugfs entry colliding
4173 * with the hangcheck calling same i915_handle_error() in
4174 * parallel, causing an explosion. For now we assume that the
4175 * test harness is responsible enough not to inject gpu hangs
4176 * while it is writing to 'i915_wedged'
4177 */
4178
Chris Wilson598b6b52017-03-25 13:47:35 +00004179 if (i915_reset_backoff(&i915->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004180 return -EAGAIN;
4181
Chris Wilson598b6b52017-03-25 13:47:35 +00004182 for_each_engine_masked(engine, i915, val, tmp) {
4183 engine->hangcheck.seqno = intel_engine_get_seqno(engine);
4184 engine->hangcheck.stalled = true;
4185 }
Imre Deakd46c0512014-04-14 20:24:27 +03004186
Chris Wilson598b6b52017-03-25 13:47:35 +00004187 i915_handle_error(i915, val, "Manually setting wedged to %llu", val);
4188
4189 wait_on_bit(&i915->gpu_error.flags,
Chris Wilsond3df42b2017-03-16 17:13:05 +00004190 I915_RESET_HANDOFF,
4191 TASK_UNINTERRUPTIBLE);
4192
Kees Cook647416f2013-03-10 14:10:06 -07004193 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004194}
4195
Kees Cook647416f2013-03-10 14:10:06 -07004196DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4197 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004198 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004199
Kees Cook647416f2013-03-10 14:10:06 -07004200static int
Chris Wilson64486ae2017-03-07 15:59:08 +00004201fault_irq_set(struct drm_i915_private *i915,
4202 unsigned long *irq,
4203 unsigned long val)
4204{
4205 int err;
4206
4207 err = mutex_lock_interruptible(&i915->drm.struct_mutex);
4208 if (err)
4209 return err;
4210
4211 err = i915_gem_wait_for_idle(i915,
4212 I915_WAIT_LOCKED |
4213 I915_WAIT_INTERRUPTIBLE);
4214 if (err)
4215 goto err_unlock;
4216
Chris Wilson64486ae2017-03-07 15:59:08 +00004217 *irq = val;
4218 mutex_unlock(&i915->drm.struct_mutex);
4219
4220 /* Flush idle worker to disarm irq */
4221 while (flush_delayed_work(&i915->gt.idle_work))
4222 ;
4223
4224 return 0;
4225
4226err_unlock:
4227 mutex_unlock(&i915->drm.struct_mutex);
4228 return err;
4229}
4230
4231static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004232i915_ring_missed_irq_get(void *data, u64 *val)
4233{
David Weinehall36cdd012016-08-22 13:59:31 +03004234 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004235
4236 *val = dev_priv->gpu_error.missed_irq_rings;
4237 return 0;
4238}
4239
4240static int
4241i915_ring_missed_irq_set(void *data, u64 val)
4242{
Chris Wilson64486ae2017-03-07 15:59:08 +00004243 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004244
Chris Wilson64486ae2017-03-07 15:59:08 +00004245 return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004246}
4247
4248DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4249 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4250 "0x%08llx\n");
4251
4252static int
4253i915_ring_test_irq_get(void *data, u64 *val)
4254{
David Weinehall36cdd012016-08-22 13:59:31 +03004255 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004256
4257 *val = dev_priv->gpu_error.test_irq_rings;
4258
4259 return 0;
4260}
4261
4262static int
4263i915_ring_test_irq_set(void *data, u64 val)
4264{
Chris Wilson64486ae2017-03-07 15:59:08 +00004265 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004266
Chris Wilson64486ae2017-03-07 15:59:08 +00004267 val &= INTEL_INFO(i915)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004268 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004269
Chris Wilson64486ae2017-03-07 15:59:08 +00004270 return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004271}
4272
4273DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4274 i915_ring_test_irq_get, i915_ring_test_irq_set,
4275 "0x%08llx\n");
4276
Chris Wilsondd624af2013-01-15 12:39:35 +00004277#define DROP_UNBOUND 0x1
4278#define DROP_BOUND 0x2
4279#define DROP_RETIRE 0x4
4280#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004281#define DROP_FREED 0x10
Chris Wilson8eadc192017-03-08 14:46:22 +00004282#define DROP_SHRINK_ALL 0x20
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004283#define DROP_ALL (DROP_UNBOUND | \
4284 DROP_BOUND | \
4285 DROP_RETIRE | \
4286 DROP_ACTIVE | \
Chris Wilson8eadc192017-03-08 14:46:22 +00004287 DROP_FREED | \
4288 DROP_SHRINK_ALL)
Kees Cook647416f2013-03-10 14:10:06 -07004289static int
4290i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004291{
Kees Cook647416f2013-03-10 14:10:06 -07004292 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004293
Kees Cook647416f2013-03-10 14:10:06 -07004294 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004295}
4296
Kees Cook647416f2013-03-10 14:10:06 -07004297static int
4298i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004299{
David Weinehall36cdd012016-08-22 13:59:31 +03004300 struct drm_i915_private *dev_priv = data;
4301 struct drm_device *dev = &dev_priv->drm;
Chris Wilson00c26cf2017-05-24 17:26:53 +01004302 int ret = 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004303
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004304 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004305
4306 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4307 * on ioctls on -EAGAIN. */
Chris Wilson00c26cf2017-05-24 17:26:53 +01004308 if (val & (DROP_ACTIVE | DROP_RETIRE)) {
4309 ret = mutex_lock_interruptible(&dev->struct_mutex);
Chris Wilsondd624af2013-01-15 12:39:35 +00004310 if (ret)
Chris Wilson00c26cf2017-05-24 17:26:53 +01004311 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004312
Chris Wilson00c26cf2017-05-24 17:26:53 +01004313 if (val & DROP_ACTIVE)
4314 ret = i915_gem_wait_for_idle(dev_priv,
4315 I915_WAIT_INTERRUPTIBLE |
4316 I915_WAIT_LOCKED);
4317
4318 if (val & DROP_RETIRE)
4319 i915_gem_retire_requests(dev_priv);
4320
4321 mutex_unlock(&dev->struct_mutex);
4322 }
Chris Wilsondd624af2013-01-15 12:39:35 +00004323
Daniel Vetter05df49e2017-03-12 21:53:40 +01004324 lockdep_set_current_reclaim_state(GFP_KERNEL);
Chris Wilson21ab4e72014-09-09 11:16:08 +01004325 if (val & DROP_BOUND)
4326 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004327
Chris Wilson21ab4e72014-09-09 11:16:08 +01004328 if (val & DROP_UNBOUND)
4329 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004330
Chris Wilson8eadc192017-03-08 14:46:22 +00004331 if (val & DROP_SHRINK_ALL)
4332 i915_gem_shrink_all(dev_priv);
Daniel Vetter05df49e2017-03-12 21:53:40 +01004333 lockdep_clear_current_reclaim_state();
Chris Wilson8eadc192017-03-08 14:46:22 +00004334
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004335 if (val & DROP_FREED) {
4336 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004337 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004338 }
4339
Kees Cook647416f2013-03-10 14:10:06 -07004340 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004341}
4342
Kees Cook647416f2013-03-10 14:10:06 -07004343DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4344 i915_drop_caches_get, i915_drop_caches_set,
4345 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004346
Kees Cook647416f2013-03-10 14:10:06 -07004347static int
4348i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004349{
David Weinehall36cdd012016-08-22 13:59:31 +03004350 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004351
David Weinehall36cdd012016-08-22 13:59:31 +03004352 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004353 return -ENODEV;
4354
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004355 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004356 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004357}
4358
Kees Cook647416f2013-03-10 14:10:06 -07004359static int
4360i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004361{
David Weinehall36cdd012016-08-22 13:59:31 +03004362 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304363 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004364 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004365
David Weinehall36cdd012016-08-22 13:59:31 +03004366 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004367 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004368
Kees Cook647416f2013-03-10 14:10:06 -07004369 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004370
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004371 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004372 if (ret)
4373 return ret;
4374
Jesse Barnes358733e2011-07-27 11:53:01 -07004375 /*
4376 * Turbo will still be enabled, but won't go above the set value.
4377 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304378 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004379
Akash Goelbc4d91f2015-02-26 16:09:47 +05304380 hw_max = dev_priv->rps.max_freq;
4381 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004382
Ben Widawskyb39fb292014-03-19 18:31:11 -07004383 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004384 mutex_unlock(&dev_priv->rps.hw_lock);
4385 return -EINVAL;
4386 }
4387
Ben Widawskyb39fb292014-03-19 18:31:11 -07004388 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004389
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004390 if (intel_set_rps(dev_priv, val))
4391 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004392
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004393 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004394
Kees Cook647416f2013-03-10 14:10:06 -07004395 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004396}
4397
Kees Cook647416f2013-03-10 14:10:06 -07004398DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4399 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004400 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004401
Kees Cook647416f2013-03-10 14:10:06 -07004402static int
4403i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004404{
David Weinehall36cdd012016-08-22 13:59:31 +03004405 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004406
Chris Wilson62e1baa2016-07-13 09:10:36 +01004407 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004408 return -ENODEV;
4409
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004410 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004411 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004412}
4413
Kees Cook647416f2013-03-10 14:10:06 -07004414static int
4415i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004416{
David Weinehall36cdd012016-08-22 13:59:31 +03004417 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304418 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004419 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004420
Chris Wilson62e1baa2016-07-13 09:10:36 +01004421 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004422 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004423
Kees Cook647416f2013-03-10 14:10:06 -07004424 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004425
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004426 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004427 if (ret)
4428 return ret;
4429
Jesse Barnes1523c312012-05-25 12:34:54 -07004430 /*
4431 * Turbo will still be enabled, but won't go below the set value.
4432 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304433 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004434
Akash Goelbc4d91f2015-02-26 16:09:47 +05304435 hw_max = dev_priv->rps.max_freq;
4436 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004437
David Weinehall36cdd012016-08-22 13:59:31 +03004438 if (val < hw_min ||
4439 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004440 mutex_unlock(&dev_priv->rps.hw_lock);
4441 return -EINVAL;
4442 }
4443
Ben Widawskyb39fb292014-03-19 18:31:11 -07004444 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004445
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004446 if (intel_set_rps(dev_priv, val))
4447 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004448
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004449 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004450
Kees Cook647416f2013-03-10 14:10:06 -07004451 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004452}
4453
Kees Cook647416f2013-03-10 14:10:06 -07004454DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4455 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004456 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004457
Kees Cook647416f2013-03-10 14:10:06 -07004458static int
4459i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004460{
David Weinehall36cdd012016-08-22 13:59:31 +03004461 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004462 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004463
David Weinehall36cdd012016-08-22 13:59:31 +03004464 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004465 return -ENODEV;
4466
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004467 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004468
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004469 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004470
4471 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004472
Kees Cook647416f2013-03-10 14:10:06 -07004473 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004474
Kees Cook647416f2013-03-10 14:10:06 -07004475 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004476}
4477
Kees Cook647416f2013-03-10 14:10:06 -07004478static int
4479i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004480{
David Weinehall36cdd012016-08-22 13:59:31 +03004481 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004482 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004483
David Weinehall36cdd012016-08-22 13:59:31 +03004484 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004485 return -ENODEV;
4486
Kees Cook647416f2013-03-10 14:10:06 -07004487 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004488 return -EINVAL;
4489
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004490 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004491 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004492
4493 /* Update the cache sharing policy here as well */
4494 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4495 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4496 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4497 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4498
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004499 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004500 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004501}
4502
Kees Cook647416f2013-03-10 14:10:06 -07004503DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4504 i915_cache_sharing_get, i915_cache_sharing_set,
4505 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004506
David Weinehall36cdd012016-08-22 13:59:31 +03004507static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004508 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004509{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004510 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004511 int ss;
4512 u32 sig1[ss_max], sig2[ss_max];
4513
4514 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4515 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4516 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4517 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4518
4519 for (ss = 0; ss < ss_max; ss++) {
4520 unsigned int eu_cnt;
4521
4522 if (sig1[ss] & CHV_SS_PG_ENABLE)
4523 /* skip disabled subslice */
4524 continue;
4525
Imre Deakf08a0c92016-08-31 19:13:04 +03004526 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004527 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004528 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4529 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4530 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4531 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004532 sseu->eu_total += eu_cnt;
4533 sseu->eu_per_subslice = max_t(unsigned int,
4534 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004535 }
Jeff McGee5d395252015-04-03 18:13:17 -07004536}
4537
David Weinehall36cdd012016-08-22 13:59:31 +03004538static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004539 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004540{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004541 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004542 int s, ss;
4543 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4544
Jeff McGee1c046bc2015-04-03 18:13:18 -07004545 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004546 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004547 s_max = 1;
4548 ss_max = 3;
4549 }
4550
4551 for (s = 0; s < s_max; s++) {
4552 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4553 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4554 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4555 }
4556
Jeff McGee5d395252015-04-03 18:13:17 -07004557 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4558 GEN9_PGCTL_SSA_EU19_ACK |
4559 GEN9_PGCTL_SSA_EU210_ACK |
4560 GEN9_PGCTL_SSA_EU311_ACK;
4561 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4562 GEN9_PGCTL_SSB_EU19_ACK |
4563 GEN9_PGCTL_SSB_EU210_ACK |
4564 GEN9_PGCTL_SSB_EU311_ACK;
4565
4566 for (s = 0; s < s_max; s++) {
4567 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4568 /* skip disabled slice */
4569 continue;
4570
Imre Deakf08a0c92016-08-31 19:13:04 +03004571 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004572
Rodrigo Vivib976dc52017-01-23 10:32:37 -08004573 if (IS_GEN9_BC(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004574 sseu->subslice_mask =
4575 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004576
Jeff McGee5d395252015-04-03 18:13:17 -07004577 for (ss = 0; ss < ss_max; ss++) {
4578 unsigned int eu_cnt;
4579
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004580 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004581 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4582 /* skip disabled subslice */
4583 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004584
Imre Deak57ec1712016-08-31 19:13:05 +03004585 sseu->subslice_mask |= BIT(ss);
4586 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004587
Jeff McGee5d395252015-04-03 18:13:17 -07004588 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4589 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004590 sseu->eu_total += eu_cnt;
4591 sseu->eu_per_subslice = max_t(unsigned int,
4592 sseu->eu_per_subslice,
4593 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004594 }
4595 }
4596}
4597
David Weinehall36cdd012016-08-22 13:59:31 +03004598static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004599 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004600{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004601 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004602 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004603
Imre Deakf08a0c92016-08-31 19:13:04 +03004604 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004605
Imre Deakf08a0c92016-08-31 19:13:04 +03004606 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004607 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004608 sseu->eu_per_subslice =
4609 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004610 sseu->eu_total = sseu->eu_per_subslice *
4611 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004612
4613 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004614 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004615 u8 subslice_7eu =
4616 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004617
Imre Deak915490d2016-08-31 19:13:01 +03004618 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004619 }
4620 }
4621}
4622
Imre Deak615d8902016-08-31 19:13:03 +03004623static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4624 const struct sseu_dev_info *sseu)
4625{
4626 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4627 const char *type = is_available_info ? "Available" : "Enabled";
4628
Imre Deakc67ba532016-08-31 19:13:06 +03004629 seq_printf(m, " %s Slice Mask: %04x\n", type,
4630 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004631 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004632 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004633 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004634 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004635 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4636 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004637 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004638 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004639 seq_printf(m, " %s EU Total: %u\n", type,
4640 sseu->eu_total);
4641 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4642 sseu->eu_per_subslice);
4643
4644 if (!is_available_info)
4645 return;
4646
4647 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4648 if (HAS_POOLED_EU(dev_priv))
4649 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4650
4651 seq_printf(m, " Has Slice Power Gating: %s\n",
4652 yesno(sseu->has_slice_pg));
4653 seq_printf(m, " Has Subslice Power Gating: %s\n",
4654 yesno(sseu->has_subslice_pg));
4655 seq_printf(m, " Has EU Power Gating: %s\n",
4656 yesno(sseu->has_eu_pg));
4657}
4658
Jeff McGee38732182015-02-13 10:27:54 -06004659static int i915_sseu_status(struct seq_file *m, void *unused)
4660{
David Weinehall36cdd012016-08-22 13:59:31 +03004661 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004662 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004663
David Weinehall36cdd012016-08-22 13:59:31 +03004664 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004665 return -ENODEV;
4666
4667 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004668 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004669
Jeff McGee7f992ab2015-02-13 10:27:55 -06004670 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004671 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004672
4673 intel_runtime_pm_get(dev_priv);
4674
David Weinehall36cdd012016-08-22 13:59:31 +03004675 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004676 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004677 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004678 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004679 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004680 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004681 }
David Weinehall238010e2016-08-01 17:33:27 +03004682
4683 intel_runtime_pm_put(dev_priv);
4684
Imre Deak615d8902016-08-31 19:13:03 +03004685 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004686
Jeff McGee38732182015-02-13 10:27:54 -06004687 return 0;
4688}
4689
Ben Widawsky6d794d42011-04-25 11:25:56 -07004690static int i915_forcewake_open(struct inode *inode, struct file *file)
4691{
David Weinehall36cdd012016-08-22 13:59:31 +03004692 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004693
David Weinehall36cdd012016-08-22 13:59:31 +03004694 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004695 return 0;
4696
Chris Wilson6daccb02015-01-16 11:34:35 +02004697 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004698 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004699
4700 return 0;
4701}
4702
Ben Widawskyc43b5632012-04-16 14:07:40 -07004703static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004704{
David Weinehall36cdd012016-08-22 13:59:31 +03004705 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004706
David Weinehall36cdd012016-08-22 13:59:31 +03004707 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004708 return 0;
4709
Mika Kuoppala59bad942015-01-16 11:34:40 +02004710 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004711 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004712
4713 return 0;
4714}
4715
4716static const struct file_operations i915_forcewake_fops = {
4717 .owner = THIS_MODULE,
4718 .open = i915_forcewake_open,
4719 .release = i915_forcewake_release,
4720};
4721
Lyude317eaa92017-02-03 21:18:25 -05004722static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4723{
4724 struct drm_i915_private *dev_priv = m->private;
4725 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4726
4727 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4728 seq_printf(m, "Detected: %s\n",
4729 yesno(delayed_work_pending(&hotplug->reenable_work)));
4730
4731 return 0;
4732}
4733
4734static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4735 const char __user *ubuf, size_t len,
4736 loff_t *offp)
4737{
4738 struct seq_file *m = file->private_data;
4739 struct drm_i915_private *dev_priv = m->private;
4740 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4741 unsigned int new_threshold;
4742 int i;
4743 char *newline;
4744 char tmp[16];
4745
4746 if (len >= sizeof(tmp))
4747 return -EINVAL;
4748
4749 if (copy_from_user(tmp, ubuf, len))
4750 return -EFAULT;
4751
4752 tmp[len] = '\0';
4753
4754 /* Strip newline, if any */
4755 newline = strchr(tmp, '\n');
4756 if (newline)
4757 *newline = '\0';
4758
4759 if (strcmp(tmp, "reset") == 0)
4760 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4761 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4762 return -EINVAL;
4763
4764 if (new_threshold > 0)
4765 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4766 new_threshold);
4767 else
4768 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4769
4770 spin_lock_irq(&dev_priv->irq_lock);
4771 hotplug->hpd_storm_threshold = new_threshold;
4772 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4773 for_each_hpd_pin(i)
4774 hotplug->stats[i].count = 0;
4775 spin_unlock_irq(&dev_priv->irq_lock);
4776
4777 /* Re-enable hpd immediately if we were in an irq storm */
4778 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4779
4780 return len;
4781}
4782
4783static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4784{
4785 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4786}
4787
4788static const struct file_operations i915_hpd_storm_ctl_fops = {
4789 .owner = THIS_MODULE,
4790 .open = i915_hpd_storm_ctl_open,
4791 .read = seq_read,
4792 .llseek = seq_lseek,
4793 .release = single_release,
4794 .write = i915_hpd_storm_ctl_write
4795};
4796
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004797static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004798 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004799 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004800 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01004801 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004802 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004803 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004804 {"i915_gem_request", i915_gem_request_info, 0},
4805 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004806 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004807 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004808 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004809 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004810 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004811 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07004812 {"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
Oscar Mateoa8b93702017-05-10 15:04:51 +00004813 {"i915_guc_stage_pool", i915_guc_stage_pool, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004814 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304815 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004816 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004817 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004818 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004819 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004820 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004821 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004822 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004823 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004824 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004825 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004826 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004827 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01004828 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004829 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004830 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004831 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004832 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004833 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004834 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004835 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004836 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004837 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004838 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004839 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004840 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004841 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004842 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004843 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004844 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004845 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004846 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304847 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004848 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004849};
Ben Gamari27c202a2009-07-01 22:26:52 -04004850#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004851
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004852static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004853 const char *name;
4854 const struct file_operations *fops;
4855} i915_debugfs_files[] = {
4856 {"i915_wedged", &i915_wedged_fops},
4857 {"i915_max_freq", &i915_max_freq_fops},
4858 {"i915_min_freq", &i915_min_freq_fops},
4859 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004860 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4861 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004862 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004863#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004864 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004865 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004866#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004867 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004868 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004869 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4870 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4871 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004872 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004873 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4874 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304875 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004876 {"i915_guc_log_control", &i915_guc_log_control_fops},
4877 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004878};
4879
Chris Wilson1dac8912016-06-24 14:00:17 +01004880int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004881{
Chris Wilson91c8a322016-07-05 10:40:23 +01004882 struct drm_minor *minor = dev_priv->drm.primary;
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004883 struct dentry *ent;
Daniel Vetter34b96742013-07-04 20:49:44 +02004884 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004885
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004886 ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
4887 minor->debugfs_root, to_i915(minor->dev),
4888 &i915_forcewake_fops);
4889 if (!ent)
4890 return -ENOMEM;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004891
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004892 ret = intel_pipe_crc_create(minor);
4893 if (ret)
4894 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004895
Daniel Vetter34b96742013-07-04 20:49:44 +02004896 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004897 ent = debugfs_create_file(i915_debugfs_files[i].name,
4898 S_IRUGO | S_IWUSR,
4899 minor->debugfs_root,
4900 to_i915(minor->dev),
Daniel Vetter34b96742013-07-04 20:49:44 +02004901 i915_debugfs_files[i].fops);
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004902 if (!ent)
4903 return -ENOMEM;
Daniel Vetter34b96742013-07-04 20:49:44 +02004904 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004905
Ben Gamari27c202a2009-07-01 22:26:52 -04004906 return drm_debugfs_create_files(i915_debugfs_list,
4907 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004908 minor->debugfs_root, minor);
4909}
4910
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004911struct dpcd_block {
4912 /* DPCD dump start address. */
4913 unsigned int offset;
4914 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4915 unsigned int end;
4916 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4917 size_t size;
4918 /* Only valid for eDP. */
4919 bool edp;
4920};
4921
4922static const struct dpcd_block i915_dpcd_debug[] = {
4923 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4924 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4925 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4926 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4927 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4928 { .offset = DP_SET_POWER },
4929 { .offset = DP_EDP_DPCD_REV },
4930 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4931 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4932 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4933};
4934
4935static int i915_dpcd_show(struct seq_file *m, void *data)
4936{
4937 struct drm_connector *connector = m->private;
4938 struct intel_dp *intel_dp =
4939 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4940 uint8_t buf[16];
4941 ssize_t err;
4942 int i;
4943
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004944 if (connector->status != connector_status_connected)
4945 return -ENODEV;
4946
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004947 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4948 const struct dpcd_block *b = &i915_dpcd_debug[i];
4949 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4950
4951 if (b->edp &&
4952 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4953 continue;
4954
4955 /* low tech for now */
4956 if (WARN_ON(size > sizeof(buf)))
4957 continue;
4958
4959 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4960 if (err <= 0) {
4961 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4962 size, b->offset, err);
4963 continue;
4964 }
4965
4966 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004967 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004968
4969 return 0;
4970}
4971
4972static int i915_dpcd_open(struct inode *inode, struct file *file)
4973{
4974 return single_open(file, i915_dpcd_show, inode->i_private);
4975}
4976
4977static const struct file_operations i915_dpcd_fops = {
4978 .owner = THIS_MODULE,
4979 .open = i915_dpcd_open,
4980 .read = seq_read,
4981 .llseek = seq_lseek,
4982 .release = single_release,
4983};
4984
David Weinehallecbd6782016-08-23 12:23:56 +03004985static int i915_panel_show(struct seq_file *m, void *data)
4986{
4987 struct drm_connector *connector = m->private;
4988 struct intel_dp *intel_dp =
4989 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4990
4991 if (connector->status != connector_status_connected)
4992 return -ENODEV;
4993
4994 seq_printf(m, "Panel power up delay: %d\n",
4995 intel_dp->panel_power_up_delay);
4996 seq_printf(m, "Panel power down delay: %d\n",
4997 intel_dp->panel_power_down_delay);
4998 seq_printf(m, "Backlight on delay: %d\n",
4999 intel_dp->backlight_on_delay);
5000 seq_printf(m, "Backlight off delay: %d\n",
5001 intel_dp->backlight_off_delay);
5002
5003 return 0;
5004}
5005
5006static int i915_panel_open(struct inode *inode, struct file *file)
5007{
5008 return single_open(file, i915_panel_show, inode->i_private);
5009}
5010
5011static const struct file_operations i915_panel_fops = {
5012 .owner = THIS_MODULE,
5013 .open = i915_panel_open,
5014 .read = seq_read,
5015 .llseek = seq_lseek,
5016 .release = single_release,
5017};
5018
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005019/**
5020 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5021 * @connector: pointer to a registered drm_connector
5022 *
5023 * Cleanup will be done by drm_connector_unregister() through a call to
5024 * drm_debugfs_connector_remove().
5025 *
5026 * Returns 0 on success, negative error codes on error.
5027 */
5028int i915_debugfs_connector_add(struct drm_connector *connector)
5029{
5030 struct dentry *root = connector->debugfs_entry;
5031
5032 /* The connector must have been registered beforehands. */
5033 if (!root)
5034 return -ENODEV;
5035
5036 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5037 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005038 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5039 connector, &i915_dpcd_fops);
5040
5041 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5042 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5043 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005044
5045 return 0;
5046}