blob: 329fb3649dc30f7b056ab0b762f26df21018866d [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
Chris Wilsonf3cd4742009-10-13 22:20:20 +010029#include <linux/debugfs.h>
Chris Wilsone637d2c2017-03-16 13:19:57 +000030#include <linux/sort.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010031#include "intel_drv.h"
Ben Gamari20172632009-02-17 20:08:50 -050032
David Weinehall36cdd012016-08-22 13:59:31 +030033static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
34{
35 return to_i915(node->minor->dev);
36}
37
Chris Wilson418e3cd2017-02-06 21:36:08 +000038static __always_inline void seq_print_param(struct seq_file *m,
39 const char *name,
40 const char *type,
41 const void *x)
42{
43 if (!__builtin_strcmp(type, "bool"))
44 seq_printf(m, "i915.%s=%s\n", name, yesno(*(const bool *)x));
45 else if (!__builtin_strcmp(type, "int"))
46 seq_printf(m, "i915.%s=%d\n", name, *(const int *)x);
47 else if (!__builtin_strcmp(type, "unsigned int"))
48 seq_printf(m, "i915.%s=%u\n", name, *(const unsigned int *)x);
Chris Wilson1d6aa7a2017-02-21 16:26:19 +000049 else if (!__builtin_strcmp(type, "char *"))
50 seq_printf(m, "i915.%s=%s\n", name, *(const char **)x);
Chris Wilson418e3cd2017-02-06 21:36:08 +000051 else
52 BUILD_BUG();
53}
54
Chris Wilson70d39fe2010-08-25 16:03:34 +010055static int i915_capabilities(struct seq_file *m, void *data)
56{
David Weinehall36cdd012016-08-22 13:59:31 +030057 struct drm_i915_private *dev_priv = node_to_i915(m->private);
58 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010059
David Weinehall36cdd012016-08-22 13:59:31 +030060 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
Jani Nikula2e0d26f2016-12-01 14:49:55 +020061 seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
David Weinehall36cdd012016-08-22 13:59:31 +030062 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Chris Wilson418e3cd2017-02-06 21:36:08 +000063
Damien Lespiau79fc46d2013-04-23 16:37:17 +010064#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030065 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010066#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010067
Chris Wilson418e3cd2017-02-06 21:36:08 +000068 kernel_param_lock(THIS_MODULE);
69#define PRINT_PARAM(T, x) seq_print_param(m, #x, #T, &i915.x);
70 I915_PARAMS_FOR_EACH(PRINT_PARAM);
71#undef PRINT_PARAM
72 kernel_param_unlock(THIS_MODULE);
73
Chris Wilson70d39fe2010-08-25 16:03:34 +010074 return 0;
75}
Ben Gamari433e12f2009-02-17 20:08:51 -050076
Imre Deaka7363de2016-05-12 16:18:52 +030077static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000078{
Chris Wilson573adb32016-08-04 16:32:39 +010079 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000080}
81
Imre Deaka7363de2016-05-12 16:18:52 +030082static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010083{
84 return obj->pin_display ? 'p' : ' ';
85}
86
Imre Deaka7363de2016-05-12 16:18:52 +030087static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000088{
Chris Wilson3e510a82016-08-05 10:14:23 +010089 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -040090 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010091 case I915_TILING_NONE: return ' ';
92 case I915_TILING_X: return 'X';
93 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -040094 }
Chris Wilsona6172a82009-02-11 14:26:38 +000095}
96
Imre Deaka7363de2016-05-12 16:18:52 +030097static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -070098{
Chris Wilson275f0392016-10-24 13:42:14 +010099 return !list_empty(&obj->userfault_link) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100100}
101
Imre Deaka7363de2016-05-12 16:18:52 +0300102static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100103{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100104 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700105}
106
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100107static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
108{
109 u64 size = 0;
110 struct i915_vma *vma;
111
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000112 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100113 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100114 size += vma->node.size;
115 }
116
117 return size;
118}
119
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Chris Wilsonb4716182015-04-27 13:41:17 +0100123 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000124 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700125 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100126 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800127 int pin_count = 0;
128
Chris Wilson188c1ab2016-04-03 14:14:20 +0100129 lockdep_assert_held(&obj->base.dev->struct_mutex);
130
Chris Wilsond07f0e52016-10-28 13:58:44 +0100131 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100132 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100133 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100134 get_pin_flag(obj),
135 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700136 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100137 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800138 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100139 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100140 obj->base.write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300141 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100142 obj->mm.dirty ? " dirty" : "",
143 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100144 if (obj->base.name)
145 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000146 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100147 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800148 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300149 }
150 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100151 if (obj->pin_display)
152 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000153 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100154 if (!drm_mm_node_allocated(&vma->node))
155 continue;
156
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100157 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100158 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100159 vma->node.start, vma->node.size);
Chris Wilson21976852017-01-12 11:21:08 +0000160 if (i915_vma_is_ggtt(vma)) {
161 switch (vma->ggtt_view.type) {
162 case I915_GGTT_VIEW_NORMAL:
163 seq_puts(m, ", normal");
164 break;
165
166 case I915_GGTT_VIEW_PARTIAL:
167 seq_printf(m, ", partial [%08llx+%x]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000168 vma->ggtt_view.partial.offset << PAGE_SHIFT,
169 vma->ggtt_view.partial.size << PAGE_SHIFT);
Chris Wilson21976852017-01-12 11:21:08 +0000170 break;
171
172 case I915_GGTT_VIEW_ROTATED:
173 seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000174 vma->ggtt_view.rotated.plane[0].width,
175 vma->ggtt_view.rotated.plane[0].height,
176 vma->ggtt_view.rotated.plane[0].stride,
177 vma->ggtt_view.rotated.plane[0].offset,
178 vma->ggtt_view.rotated.plane[1].width,
179 vma->ggtt_view.rotated.plane[1].height,
180 vma->ggtt_view.rotated.plane[1].stride,
181 vma->ggtt_view.rotated.plane[1].offset);
Chris Wilson21976852017-01-12 11:21:08 +0000182 break;
183
184 default:
185 MISSING_CASE(vma->ggtt_view.type);
186 break;
187 }
188 }
Chris Wilson49ef5292016-08-18 17:17:00 +0100189 if (vma->fence)
190 seq_printf(m, " , fence: %d%s",
191 vma->fence->id,
192 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000193 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700194 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000195 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100196 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100197
Chris Wilsond07f0e52016-10-28 13:58:44 +0100198 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100199 if (engine)
200 seq_printf(m, " (%s)", engine->name);
201
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100202 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
203 if (frontbuffer_bits)
204 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100205}
206
Chris Wilsone637d2c2017-03-16 13:19:57 +0000207static int obj_rank_by_stolen(const void *A, const void *B)
Chris Wilson6d2b88852013-08-07 18:30:54 +0100208{
Chris Wilsone637d2c2017-03-16 13:19:57 +0000209 const struct drm_i915_gem_object *a =
210 *(const struct drm_i915_gem_object **)A;
211 const struct drm_i915_gem_object *b =
212 *(const struct drm_i915_gem_object **)B;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100213
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200214 if (a->stolen->start < b->stolen->start)
215 return -1;
216 if (a->stolen->start > b->stolen->start)
217 return 1;
218 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100219}
220
221static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
222{
David Weinehall36cdd012016-08-22 13:59:31 +0300223 struct drm_i915_private *dev_priv = node_to_i915(m->private);
224 struct drm_device *dev = &dev_priv->drm;
Chris Wilsone637d2c2017-03-16 13:19:57 +0000225 struct drm_i915_gem_object **objects;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100226 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300227 u64 total_obj_size, total_gtt_size;
Chris Wilsone637d2c2017-03-16 13:19:57 +0000228 unsigned long total, count, n;
229 int ret;
230
231 total = READ_ONCE(dev_priv->mm.object_count);
Michal Hocko20981052017-05-17 14:23:12 +0200232 objects = kvmalloc_array(total, sizeof(*objects), GFP_KERNEL);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000233 if (!objects)
234 return -ENOMEM;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100235
236 ret = mutex_lock_interruptible(&dev->struct_mutex);
237 if (ret)
Chris Wilsone637d2c2017-03-16 13:19:57 +0000238 goto out;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100239
240 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200241 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000242 if (count == total)
243 break;
244
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245 if (obj->stolen == NULL)
246 continue;
247
Chris Wilsone637d2c2017-03-16 13:19:57 +0000248 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100249 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100250 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000251
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252 }
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200253 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000254 if (count == total)
255 break;
256
Chris Wilson6d2b88852013-08-07 18:30:54 +0100257 if (obj->stolen == NULL)
258 continue;
259
Chris Wilsone637d2c2017-03-16 13:19:57 +0000260 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261 total_obj_size += obj->base.size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262 }
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263
Chris Wilsone637d2c2017-03-16 13:19:57 +0000264 sort(objects, count, sizeof(*objects), obj_rank_by_stolen, NULL);
265
266 seq_puts(m, "Stolen:\n");
267 for (n = 0; n < count; n++) {
268 seq_puts(m, " ");
269 describe_obj(m, objects[n]);
270 seq_putc(m, '\n');
271 }
272 seq_printf(m, "Total %lu objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100273 count, total_obj_size, total_gtt_size);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000274
275 mutex_unlock(&dev->struct_mutex);
276out:
Michal Hocko20981052017-05-17 14:23:12 +0200277 kvfree(objects);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000278 return ret;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100279}
280
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100281struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000282 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300283 unsigned long count;
284 u64 total, unbound;
285 u64 global, shared;
286 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100287};
288
289static int per_file_stats(int id, void *ptr, void *data)
290{
291 struct drm_i915_gem_object *obj = ptr;
292 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000293 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100294
Chris Wilson0caf81b2017-06-17 12:57:44 +0100295 lockdep_assert_held(&obj->base.dev->struct_mutex);
296
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100297 stats->count++;
298 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100299 if (!obj->bind_count)
300 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000301 if (obj->base.name || obj->base.dma_buf)
302 stats->shared += obj->base.size;
303
Chris Wilson894eeec2016-08-04 07:52:20 +0100304 list_for_each_entry(vma, &obj->vma_list, obj_link) {
305 if (!drm_mm_node_allocated(&vma->node))
306 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000307
Chris Wilson3272db52016-08-04 16:32:32 +0100308 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100309 stats->global += vma->node.size;
310 } else {
311 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000312
Chris Wilson2bfa9962016-08-04 07:52:25 +0100313 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000314 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000315 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100316
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100317 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100318 stats->active += vma->node.size;
319 else
320 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100321 }
322
323 return 0;
324}
325
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100326#define print_file_stats(m, name, stats) do { \
327 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300328 seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100329 name, \
330 stats.count, \
331 stats.total, \
332 stats.active, \
333 stats.inactive, \
334 stats.global, \
335 stats.shared, \
336 stats.unbound); \
337} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800338
339static void print_batch_pool_stats(struct seq_file *m,
340 struct drm_i915_private *dev_priv)
341{
342 struct drm_i915_gem_object *obj;
343 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000344 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530345 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000346 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800347
348 memset(&stats, 0, sizeof(stats));
349
Akash Goel3b3f1652016-10-13 22:44:48 +0530350 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000351 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100352 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000353 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100354 batch_pool_link)
355 per_file_stats(0, obj, &stats);
356 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100357 }
Brad Volkin493018d2014-12-11 12:13:08 -0800358
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100359 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800360}
361
Chris Wilson15da9562016-05-24 14:53:43 +0100362static int per_file_ctx_stats(int id, void *ptr, void *data)
363{
364 struct i915_gem_context *ctx = ptr;
365 int n;
366
367 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
368 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100369 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100370 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100371 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100372 }
373
374 return 0;
375}
376
377static void print_context_stats(struct seq_file *m,
378 struct drm_i915_private *dev_priv)
379{
David Weinehall36cdd012016-08-22 13:59:31 +0300380 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100381 struct file_stats stats;
382 struct drm_file *file;
383
384 memset(&stats, 0, sizeof(stats));
385
David Weinehall36cdd012016-08-22 13:59:31 +0300386 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100387 if (dev_priv->kernel_context)
388 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
389
David Weinehall36cdd012016-08-22 13:59:31 +0300390 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100391 struct drm_i915_file_private *fpriv = file->driver_priv;
392 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
393 }
David Weinehall36cdd012016-08-22 13:59:31 +0300394 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100395
396 print_file_stats(m, "[k]contexts", stats);
397}
398
David Weinehall36cdd012016-08-22 13:59:31 +0300399static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100400{
David Weinehall36cdd012016-08-22 13:59:31 +0300401 struct drm_i915_private *dev_priv = node_to_i915(m->private);
402 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300403 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100404 u32 count, mapped_count, purgeable_count, dpy_count;
405 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000406 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100407 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100408 int ret;
409
410 ret = mutex_lock_interruptible(&dev->struct_mutex);
411 if (ret)
412 return ret;
413
Chris Wilson3ef7f222016-10-18 13:02:48 +0100414 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000415 dev_priv->mm.object_count,
416 dev_priv->mm.object_memory);
417
Chris Wilson1544c422016-08-15 13:18:16 +0100418 size = count = 0;
419 mapped_size = mapped_count = 0;
420 purgeable_size = purgeable_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200421 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100422 size += obj->base.size;
423 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200424
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100425 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200426 purgeable_size += obj->base.size;
427 ++purgeable_count;
428 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100429
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100430 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100431 mapped_count++;
432 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100433 }
Chris Wilson6299f992010-11-24 12:23:44 +0000434 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100435 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
436
437 size = count = dpy_size = dpy_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200438 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100439 size += obj->base.size;
440 ++count;
441
442 if (obj->pin_display) {
443 dpy_size += obj->base.size;
444 ++dpy_count;
445 }
446
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100447 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100448 purgeable_size += obj->base.size;
449 ++purgeable_count;
450 }
451
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100452 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100453 mapped_count++;
454 mapped_size += obj->base.size;
455 }
456 }
457 seq_printf(m, "%u bound objects, %llu bytes\n",
458 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300459 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200460 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100461 seq_printf(m, "%u mapped objects, %llu bytes\n",
462 mapped_count, mapped_size);
463 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
464 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000465
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300466 seq_printf(m, "%llu [%llu] gtt total\n",
Chris Wilson381b9432017-02-15 08:43:54 +0000467 ggtt->base.total, ggtt->mappable_end);
Chris Wilson73aa8082010-09-30 11:46:12 +0100468
Damien Lespiau267f0c92013-06-24 22:59:48 +0100469 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800470 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200471 mutex_unlock(&dev->struct_mutex);
472
473 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100474 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100475 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
476 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100477 struct drm_i915_file_private *file_priv = file->driver_priv;
478 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900479 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100480
Chris Wilson0caf81b2017-06-17 12:57:44 +0100481 mutex_lock(&dev->struct_mutex);
482
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100483 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000484 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100485 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100486 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100487 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900488 /*
489 * Although we have a valid reference on file->pid, that does
490 * not guarantee that the task_struct who called get_pid() is
491 * still alive (e.g. get_pid(current) => fork() => exit()).
492 * Therefore, we need to protect this ->comm access using RCU.
493 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100494 request = list_first_entry_or_null(&file_priv->mm.request_list,
495 struct drm_i915_gem_request,
Chris Wilsonc8659ef2017-03-02 12:25:25 +0000496 client_link);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900497 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100498 task = pid_task(request && request->ctx->pid ?
499 request->ctx->pid : file->pid,
500 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800501 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900502 rcu_read_unlock();
Chris Wilson0caf81b2017-06-17 12:57:44 +0100503
Chris Wilsonc84455b2016-08-15 10:49:08 +0100504 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100505 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200506 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100507
508 return 0;
509}
510
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100511static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000512{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100513 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300514 struct drm_i915_private *dev_priv = node_to_i915(node);
515 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100516 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000517 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300518 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000519 int count, ret;
520
521 ret = mutex_lock_interruptible(&dev->struct_mutex);
522 if (ret)
523 return ret;
524
525 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200526 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6da84822016-08-15 10:48:44 +0100527 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100528 continue;
529
Damien Lespiau267f0c92013-06-24 22:59:48 +0100530 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000531 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100532 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000533 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100534 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000535 count++;
536 }
537
538 mutex_unlock(&dev->struct_mutex);
539
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300540 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000541 count, total_obj_size, total_gtt_size);
542
543 return 0;
544}
545
Brad Volkin493018d2014-12-11 12:13:08 -0800546static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
547{
David Weinehall36cdd012016-08-22 13:59:31 +0300548 struct drm_i915_private *dev_priv = node_to_i915(m->private);
549 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800550 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000551 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530552 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100553 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000554 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800555
556 ret = mutex_lock_interruptible(&dev->struct_mutex);
557 if (ret)
558 return ret;
559
Akash Goel3b3f1652016-10-13 22:44:48 +0530560 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000561 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100562 int count;
563
564 count = 0;
565 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000566 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100567 batch_pool_link)
568 count++;
569 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000570 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100571
572 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000573 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100574 batch_pool_link) {
575 seq_puts(m, " ");
576 describe_obj(m, obj);
577 seq_putc(m, '\n');
578 }
579
580 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100581 }
Brad Volkin493018d2014-12-11 12:13:08 -0800582 }
583
Chris Wilson8d9d5742015-04-07 16:20:38 +0100584 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800585
586 mutex_unlock(&dev->struct_mutex);
587
588 return 0;
589}
590
Chris Wilson1b365952016-10-04 21:11:31 +0100591static void print_request(struct seq_file *m,
592 struct drm_i915_gem_request *rq,
593 const char *prefix)
594{
Chris Wilson20311bd2016-11-14 20:41:03 +0000595 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100596 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000597 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100598 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100599 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100600}
601
Ben Gamari20172632009-02-17 20:08:50 -0500602static int i915_gem_request_info(struct seq_file *m, void *data)
603{
David Weinehall36cdd012016-08-22 13:59:31 +0300604 struct drm_i915_private *dev_priv = node_to_i915(m->private);
605 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200606 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530607 struct intel_engine_cs *engine;
608 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000609 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100610
611 ret = mutex_lock_interruptible(&dev->struct_mutex);
612 if (ret)
613 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500614
Chris Wilson2d1070b2015-04-01 10:36:56 +0100615 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530616 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100617 int count;
618
619 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100620 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100621 count++;
622 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100623 continue;
624
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000625 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100626 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100627 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100628
629 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500630 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100631 mutex_unlock(&dev->struct_mutex);
632
Chris Wilson2d1070b2015-04-01 10:36:56 +0100633 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100634 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100635
Ben Gamari20172632009-02-17 20:08:50 -0500636 return 0;
637}
638
Chris Wilsonb2223492010-10-27 15:27:33 +0100639static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000640 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100641{
Chris Wilson688e6c72016-07-01 17:23:15 +0100642 struct intel_breadcrumbs *b = &engine->breadcrumbs;
643 struct rb_node *rb;
644
Chris Wilson12471ba2016-04-09 10:57:55 +0100645 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100646 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100647
Chris Wilson61d3dc72017-03-03 19:08:24 +0000648 spin_lock_irq(&b->rb_lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100649 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +0800650 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson688e6c72016-07-01 17:23:15 +0100651
652 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
653 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
654 }
Chris Wilson61d3dc72017-03-03 19:08:24 +0000655 spin_unlock_irq(&b->rb_lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100656}
657
Ben Gamari20172632009-02-17 20:08:50 -0500658static int i915_gem_seqno_info(struct seq_file *m, void *data)
659{
David Weinehall36cdd012016-08-22 13:59:31 +0300660 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000661 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530662 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500663
Akash Goel3b3f1652016-10-13 22:44:48 +0530664 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000665 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100666
Ben Gamari20172632009-02-17 20:08:50 -0500667 return 0;
668}
669
670
671static int i915_interrupt_info(struct seq_file *m, void *data)
672{
David Weinehall36cdd012016-08-22 13:59:31 +0300673 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000674 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530675 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100676 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100677
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200678 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500679
David Weinehall36cdd012016-08-22 13:59:31 +0300680 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300681 seq_printf(m, "Master Interrupt Control:\t%08x\n",
682 I915_READ(GEN8_MASTER_IRQ));
683
684 seq_printf(m, "Display IER:\t%08x\n",
685 I915_READ(VLV_IER));
686 seq_printf(m, "Display IIR:\t%08x\n",
687 I915_READ(VLV_IIR));
688 seq_printf(m, "Display IIR_RW:\t%08x\n",
689 I915_READ(VLV_IIR_RW));
690 seq_printf(m, "Display IMR:\t%08x\n",
691 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100692 for_each_pipe(dev_priv, pipe) {
693 enum intel_display_power_domain power_domain;
694
695 power_domain = POWER_DOMAIN_PIPE(pipe);
696 if (!intel_display_power_get_if_enabled(dev_priv,
697 power_domain)) {
698 seq_printf(m, "Pipe %c power disabled\n",
699 pipe_name(pipe));
700 continue;
701 }
702
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300703 seq_printf(m, "Pipe %c stat:\t%08x\n",
704 pipe_name(pipe),
705 I915_READ(PIPESTAT(pipe)));
706
Chris Wilson9c870d02016-10-24 13:42:15 +0100707 intel_display_power_put(dev_priv, power_domain);
708 }
709
710 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300711 seq_printf(m, "Port hotplug:\t%08x\n",
712 I915_READ(PORT_HOTPLUG_EN));
713 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
714 I915_READ(VLV_DPFLIPSTAT));
715 seq_printf(m, "DPINVGTT:\t%08x\n",
716 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100717 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300718
719 for (i = 0; i < 4; i++) {
720 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
721 i, I915_READ(GEN8_GT_IMR(i)));
722 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
723 i, I915_READ(GEN8_GT_IIR(i)));
724 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
725 i, I915_READ(GEN8_GT_IER(i)));
726 }
727
728 seq_printf(m, "PCU interrupt mask:\t%08x\n",
729 I915_READ(GEN8_PCU_IMR));
730 seq_printf(m, "PCU interrupt identity:\t%08x\n",
731 I915_READ(GEN8_PCU_IIR));
732 seq_printf(m, "PCU interrupt enable:\t%08x\n",
733 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300734 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700735 seq_printf(m, "Master Interrupt Control:\t%08x\n",
736 I915_READ(GEN8_MASTER_IRQ));
737
738 for (i = 0; i < 4; i++) {
739 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
740 i, I915_READ(GEN8_GT_IMR(i)));
741 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
742 i, I915_READ(GEN8_GT_IIR(i)));
743 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
744 i, I915_READ(GEN8_GT_IER(i)));
745 }
746
Damien Lespiau055e3932014-08-18 13:49:10 +0100747 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200748 enum intel_display_power_domain power_domain;
749
750 power_domain = POWER_DOMAIN_PIPE(pipe);
751 if (!intel_display_power_get_if_enabled(dev_priv,
752 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300753 seq_printf(m, "Pipe %c power disabled\n",
754 pipe_name(pipe));
755 continue;
756 }
Ben Widawskya123f152013-11-02 21:07:10 -0700757 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000758 pipe_name(pipe),
759 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700760 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000761 pipe_name(pipe),
762 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700763 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000764 pipe_name(pipe),
765 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200766
767 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700768 }
769
770 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
771 I915_READ(GEN8_DE_PORT_IMR));
772 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
773 I915_READ(GEN8_DE_PORT_IIR));
774 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
775 I915_READ(GEN8_DE_PORT_IER));
776
777 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
778 I915_READ(GEN8_DE_MISC_IMR));
779 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
780 I915_READ(GEN8_DE_MISC_IIR));
781 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
782 I915_READ(GEN8_DE_MISC_IER));
783
784 seq_printf(m, "PCU interrupt mask:\t%08x\n",
785 I915_READ(GEN8_PCU_IMR));
786 seq_printf(m, "PCU interrupt identity:\t%08x\n",
787 I915_READ(GEN8_PCU_IIR));
788 seq_printf(m, "PCU interrupt enable:\t%08x\n",
789 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300790 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700791 seq_printf(m, "Display IER:\t%08x\n",
792 I915_READ(VLV_IER));
793 seq_printf(m, "Display IIR:\t%08x\n",
794 I915_READ(VLV_IIR));
795 seq_printf(m, "Display IIR_RW:\t%08x\n",
796 I915_READ(VLV_IIR_RW));
797 seq_printf(m, "Display IMR:\t%08x\n",
798 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000799 for_each_pipe(dev_priv, pipe) {
800 enum intel_display_power_domain power_domain;
801
802 power_domain = POWER_DOMAIN_PIPE(pipe);
803 if (!intel_display_power_get_if_enabled(dev_priv,
804 power_domain)) {
805 seq_printf(m, "Pipe %c power disabled\n",
806 pipe_name(pipe));
807 continue;
808 }
809
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700810 seq_printf(m, "Pipe %c stat:\t%08x\n",
811 pipe_name(pipe),
812 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000813 intel_display_power_put(dev_priv, power_domain);
814 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700815
816 seq_printf(m, "Master IER:\t%08x\n",
817 I915_READ(VLV_MASTER_IER));
818
819 seq_printf(m, "Render IER:\t%08x\n",
820 I915_READ(GTIER));
821 seq_printf(m, "Render IIR:\t%08x\n",
822 I915_READ(GTIIR));
823 seq_printf(m, "Render IMR:\t%08x\n",
824 I915_READ(GTIMR));
825
826 seq_printf(m, "PM IER:\t\t%08x\n",
827 I915_READ(GEN6_PMIER));
828 seq_printf(m, "PM IIR:\t\t%08x\n",
829 I915_READ(GEN6_PMIIR));
830 seq_printf(m, "PM IMR:\t\t%08x\n",
831 I915_READ(GEN6_PMIMR));
832
833 seq_printf(m, "Port hotplug:\t%08x\n",
834 I915_READ(PORT_HOTPLUG_EN));
835 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
836 I915_READ(VLV_DPFLIPSTAT));
837 seq_printf(m, "DPINVGTT:\t%08x\n",
838 I915_READ(DPINVGTT));
839
David Weinehall36cdd012016-08-22 13:59:31 +0300840 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800841 seq_printf(m, "Interrupt enable: %08x\n",
842 I915_READ(IER));
843 seq_printf(m, "Interrupt identity: %08x\n",
844 I915_READ(IIR));
845 seq_printf(m, "Interrupt mask: %08x\n",
846 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100847 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800848 seq_printf(m, "Pipe %c stat: %08x\n",
849 pipe_name(pipe),
850 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800851 } else {
852 seq_printf(m, "North Display Interrupt enable: %08x\n",
853 I915_READ(DEIER));
854 seq_printf(m, "North Display Interrupt identity: %08x\n",
855 I915_READ(DEIIR));
856 seq_printf(m, "North Display Interrupt mask: %08x\n",
857 I915_READ(DEIMR));
858 seq_printf(m, "South Display Interrupt enable: %08x\n",
859 I915_READ(SDEIER));
860 seq_printf(m, "South Display Interrupt identity: %08x\n",
861 I915_READ(SDEIIR));
862 seq_printf(m, "South Display Interrupt mask: %08x\n",
863 I915_READ(SDEIMR));
864 seq_printf(m, "Graphics Interrupt enable: %08x\n",
865 I915_READ(GTIER));
866 seq_printf(m, "Graphics Interrupt identity: %08x\n",
867 I915_READ(GTIIR));
868 seq_printf(m, "Graphics Interrupt mask: %08x\n",
869 I915_READ(GTIMR));
870 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530871 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300872 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100873 seq_printf(m,
874 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000875 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000876 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000877 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000878 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200879 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100880
Ben Gamari20172632009-02-17 20:08:50 -0500881 return 0;
882}
883
Chris Wilsona6172a82009-02-11 14:26:38 +0000884static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
885{
David Weinehall36cdd012016-08-22 13:59:31 +0300886 struct drm_i915_private *dev_priv = node_to_i915(m->private);
887 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100888 int i, ret;
889
890 ret = mutex_lock_interruptible(&dev->struct_mutex);
891 if (ret)
892 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000893
Chris Wilsona6172a82009-02-11 14:26:38 +0000894 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
895 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100896 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000897
Chris Wilson6c085a72012-08-20 11:40:46 +0200898 seq_printf(m, "Fence %d, pin count = %d, object = ",
899 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100900 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100901 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100902 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100903 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100904 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000905 }
906
Chris Wilson05394f32010-11-08 19:18:58 +0000907 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000908 return 0;
909}
910
Chris Wilson98a2f412016-10-12 10:05:18 +0100911#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000912static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
913 size_t count, loff_t *pos)
914{
915 struct i915_gpu_state *error = file->private_data;
916 struct drm_i915_error_state_buf str;
917 ssize_t ret;
918 loff_t tmp;
919
920 if (!error)
921 return 0;
922
923 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
924 if (ret)
925 return ret;
926
927 ret = i915_error_state_to_str(&str, error);
928 if (ret)
929 goto out;
930
931 tmp = 0;
932 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
933 if (ret < 0)
934 goto out;
935
936 *pos = str.start + ret;
937out:
938 i915_error_state_buf_release(&str);
939 return ret;
940}
941
942static int gpu_state_release(struct inode *inode, struct file *file)
943{
944 i915_gpu_state_put(file->private_data);
945 return 0;
946}
947
948static int i915_gpu_info_open(struct inode *inode, struct file *file)
949{
Chris Wilson090e5fe2017-03-28 14:14:07 +0100950 struct drm_i915_private *i915 = inode->i_private;
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000951 struct i915_gpu_state *gpu;
952
Chris Wilson090e5fe2017-03-28 14:14:07 +0100953 intel_runtime_pm_get(i915);
954 gpu = i915_capture_gpu_state(i915);
955 intel_runtime_pm_put(i915);
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000956 if (!gpu)
957 return -ENOMEM;
958
959 file->private_data = gpu;
960 return 0;
961}
962
963static const struct file_operations i915_gpu_info_fops = {
964 .owner = THIS_MODULE,
965 .open = i915_gpu_info_open,
966 .read = gpu_state_read,
967 .llseek = default_llseek,
968 .release = gpu_state_release,
969};
Chris Wilson98a2f412016-10-12 10:05:18 +0100970
Daniel Vetterd5442302012-04-27 15:17:40 +0200971static ssize_t
972i915_error_state_write(struct file *filp,
973 const char __user *ubuf,
974 size_t cnt,
975 loff_t *ppos)
976{
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000977 struct i915_gpu_state *error = filp->private_data;
978
979 if (!error)
980 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200981
982 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000983 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +0200984
985 return cnt;
986}
987
988static int i915_error_state_open(struct inode *inode, struct file *file)
989{
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000990 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300991 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200992}
993
Daniel Vetterd5442302012-04-27 15:17:40 +0200994static const struct file_operations i915_error_state_fops = {
995 .owner = THIS_MODULE,
996 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000997 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200998 .write = i915_error_state_write,
999 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001000 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +02001001};
Chris Wilson98a2f412016-10-12 10:05:18 +01001002#endif
1003
Kees Cook647416f2013-03-10 14:10:06 -07001004static int
Kees Cook647416f2013-03-10 14:10:06 -07001005i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001006{
David Weinehall36cdd012016-08-22 13:59:31 +03001007 struct drm_i915_private *dev_priv = data;
1008 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001009 int ret;
1010
Mika Kuoppala40633212012-12-04 15:12:00 +02001011 ret = mutex_lock_interruptible(&dev->struct_mutex);
1012 if (ret)
1013 return ret;
1014
Chris Wilson73cb9702016-10-28 13:58:46 +01001015 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001016 mutex_unlock(&dev->struct_mutex);
1017
Kees Cook647416f2013-03-10 14:10:06 -07001018 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001019}
1020
Kees Cook647416f2013-03-10 14:10:06 -07001021DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001022 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001023 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001024
Deepak Sadb4bd12014-03-31 11:30:02 +05301025static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001026{
David Weinehall36cdd012016-08-22 13:59:31 +03001027 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001028 int ret = 0;
1029
1030 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001031
David Weinehall36cdd012016-08-22 13:59:31 +03001032 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001033 u16 rgvswctl = I915_READ16(MEMSWCTL);
1034 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1035
1036 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1037 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1038 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1039 MEMSTAT_VID_SHIFT);
1040 seq_printf(m, "Current P-state: %d\n",
1041 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001042 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001043 u32 freq_sts;
1044
1045 mutex_lock(&dev_priv->rps.hw_lock);
1046 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1047 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1048 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1049
1050 seq_printf(m, "actual GPU freq: %d MHz\n",
1051 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1052
1053 seq_printf(m, "current GPU freq: %d MHz\n",
1054 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1055
1056 seq_printf(m, "max GPU freq: %d MHz\n",
1057 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1058
1059 seq_printf(m, "min GPU freq: %d MHz\n",
1060 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1061
1062 seq_printf(m, "idle GPU freq: %d MHz\n",
1063 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1064
1065 seq_printf(m,
1066 "efficient (RPe) frequency: %d MHz\n",
1067 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1068 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001069 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001070 u32 rp_state_limits;
1071 u32 gt_perf_status;
1072 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001073 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001074 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001075 u32 rpupei, rpcurup, rpprevup;
1076 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001077 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001078 int max_freq;
1079
Bob Paauwe35040562015-06-25 14:54:07 -07001080 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001081 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001082 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1083 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1084 } else {
1085 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1086 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1087 }
1088
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001089 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001090 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001091
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001092 reqf = I915_READ(GEN6_RPNSWREQ);
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001093 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301094 reqf >>= 23;
1095 else {
1096 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001097 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301098 reqf >>= 24;
1099 else
1100 reqf >>= 25;
1101 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001102 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001103
Chris Wilson0d8f9492014-03-27 09:06:14 +00001104 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1105 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1106 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1107
Jesse Barnesccab5c82011-01-18 15:49:25 -08001108 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301109 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1110 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1111 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1112 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1113 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1114 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001115 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301116 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001117 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001118 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1119 else
1120 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001121 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001122
Mika Kuoppala59bad942015-01-16 11:34:40 +02001123 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001124
David Weinehall36cdd012016-08-22 13:59:31 +03001125 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001126 pm_ier = I915_READ(GEN6_PMIER);
1127 pm_imr = I915_READ(GEN6_PMIMR);
1128 pm_isr = I915_READ(GEN6_PMISR);
1129 pm_iir = I915_READ(GEN6_PMIIR);
1130 pm_mask = I915_READ(GEN6_PMINTRMSK);
1131 } else {
1132 pm_ier = I915_READ(GEN8_GT_IER(2));
1133 pm_imr = I915_READ(GEN8_GT_IMR(2));
1134 pm_isr = I915_READ(GEN8_GT_ISR(2));
1135 pm_iir = I915_READ(GEN8_GT_IIR(2));
1136 pm_mask = I915_READ(GEN6_PMINTRMSK);
1137 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001138 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 -03001139 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05301140 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
1141 dev_priv->rps.pm_intrmsk_mbz);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001142 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143 seq_printf(m, "Render p-state ratio: %d\n",
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001144 (gt_perf_status & (INTEL_GEN(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001145 seq_printf(m, "Render p-state VID: %d\n",
1146 gt_perf_status & 0xff);
1147 seq_printf(m, "Render p-state limit: %d\n",
1148 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001149 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1150 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1151 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1152 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001153 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001154 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301155 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1156 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1157 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1158 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1159 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1160 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001161 seq_printf(m, "Up threshold: %d%%\n",
1162 dev_priv->rps.up_threshold);
1163
Akash Goeld6cda9c2016-04-23 00:05:46 +05301164 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1165 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1166 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1167 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1168 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1169 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001170 seq_printf(m, "Down threshold: %d%%\n",
1171 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001172
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001173 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001174 rp_state_cap >> 16) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001175 max_freq *= (IS_GEN9_BC(dev_priv) ||
1176 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001177 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001178 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001179
1180 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001181 max_freq *= (IS_GEN9_BC(dev_priv) ||
1182 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001183 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001184 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001185
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001186 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001187 rp_state_cap >> 0) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001188 max_freq *= (IS_GEN9_BC(dev_priv) ||
1189 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001190 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001191 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001192 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001193 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001194
Chris Wilsond86ed342015-04-27 13:41:19 +01001195 seq_printf(m, "Current freq: %d MHz\n",
1196 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1197 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001198 seq_printf(m, "Idle freq: %d MHz\n",
1199 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001200 seq_printf(m, "Min freq: %d MHz\n",
1201 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001202 seq_printf(m, "Boost freq: %d MHz\n",
1203 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001204 seq_printf(m, "Max freq: %d MHz\n",
1205 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1206 seq_printf(m,
1207 "efficient (RPe) frequency: %d MHz\n",
1208 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001209 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001210 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001211 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001212
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001213 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001214 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1215 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1216
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001217 intel_runtime_pm_put(dev_priv);
1218 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001219}
1220
Ben Widawskyd6369512016-09-20 16:54:32 +03001221static void i915_instdone_info(struct drm_i915_private *dev_priv,
1222 struct seq_file *m,
1223 struct intel_instdone *instdone)
1224{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001225 int slice;
1226 int subslice;
1227
Ben Widawskyd6369512016-09-20 16:54:32 +03001228 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1229 instdone->instdone);
1230
1231 if (INTEL_GEN(dev_priv) <= 3)
1232 return;
1233
1234 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1235 instdone->slice_common);
1236
1237 if (INTEL_GEN(dev_priv) <= 6)
1238 return;
1239
Ben Widawskyf9e61372016-09-20 16:54:33 +03001240 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1241 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1242 slice, subslice, instdone->sampler[slice][subslice]);
1243
1244 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1245 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1246 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001247}
1248
Chris Wilsonf6544492015-01-26 18:03:04 +02001249static int i915_hangcheck_info(struct seq_file *m, void *unused)
1250{
David Weinehall36cdd012016-08-22 13:59:31 +03001251 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001252 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001253 u64 acthd[I915_NUM_ENGINES];
1254 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001255 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001256 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001257
Chris Wilson8af29b02016-09-09 14:11:47 +01001258 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001259 seq_puts(m, "Wedged\n");
1260 if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
1261 seq_puts(m, "Reset in progress: struct_mutex backoff\n");
1262 if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
1263 seq_puts(m, "Reset in progress: reset handoff to waiter\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001264 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001265 seq_puts(m, "Waiter holding struct mutex\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001266 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001267 seq_puts(m, "struct_mutex blocked for reset\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001268
Chris Wilsonf6544492015-01-26 18:03:04 +02001269 if (!i915.enable_hangcheck) {
Chris Wilson8c185ec2017-03-16 17:13:02 +00001270 seq_puts(m, "Hangcheck disabled\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001271 return 0;
1272 }
1273
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001274 intel_runtime_pm_get(dev_priv);
1275
Akash Goel3b3f1652016-10-13 22:44:48 +05301276 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001277 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001278 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001279 }
1280
Akash Goel3b3f1652016-10-13 22:44:48 +05301281 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001282
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001283 intel_runtime_pm_put(dev_priv);
1284
Chris Wilson8352aea2017-03-03 09:00:56 +00001285 if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
1286 seq_printf(m, "Hangcheck active, timer fires in %dms\n",
Chris Wilsonf6544492015-01-26 18:03:04 +02001287 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1288 jiffies));
Chris Wilson8352aea2017-03-03 09:00:56 +00001289 else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
1290 seq_puts(m, "Hangcheck active, work pending\n");
1291 else
1292 seq_puts(m, "Hangcheck inactive\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001293
Chris Wilsonf73b5672017-03-02 15:03:56 +00001294 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1295
Akash Goel3b3f1652016-10-13 22:44:48 +05301296 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001297 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1298 struct rb_node *rb;
1299
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001300 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001301 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001302 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001303 intel_engine_last_submit(engine),
1304 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001305 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001306 yesno(intel_engine_has_waiter(engine)),
1307 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001308 &dev_priv->gpu_error.missed_irq_rings)),
1309 yesno(engine->hangcheck.stalled));
1310
Chris Wilson61d3dc72017-03-03 19:08:24 +00001311 spin_lock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001312 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001313 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001314
1315 seq_printf(m, "\t%s [%d] waiting for %x\n",
1316 w->tsk->comm, w->tsk->pid, w->seqno);
1317 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001318 spin_unlock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001319
Chris Wilsonf6544492015-01-26 18:03:04 +02001320 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001321 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001322 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001323 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1324 hangcheck_action_to_str(engine->hangcheck.action),
1325 engine->hangcheck.action,
1326 jiffies_to_msecs(jiffies -
1327 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001328
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001329 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001330 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001331
Ben Widawskyd6369512016-09-20 16:54:32 +03001332 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001333
Ben Widawskyd6369512016-09-20 16:54:32 +03001334 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001335
Ben Widawskyd6369512016-09-20 16:54:32 +03001336 i915_instdone_info(dev_priv, m,
1337 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001338 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001339 }
1340
1341 return 0;
1342}
1343
Michel Thierry061d06a2017-06-20 10:57:49 +01001344static int i915_reset_info(struct seq_file *m, void *unused)
1345{
1346 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1347 struct i915_gpu_error *error = &dev_priv->gpu_error;
1348 struct intel_engine_cs *engine;
1349 enum intel_engine_id id;
1350
1351 seq_printf(m, "full gpu reset = %u\n", i915_reset_count(error));
1352
1353 for_each_engine(engine, dev_priv, id) {
1354 seq_printf(m, "%s = %u\n", engine->name,
1355 i915_reset_engine_count(error, engine));
1356 }
1357
1358 return 0;
1359}
1360
Ben Widawsky4d855292011-12-12 19:34:16 -08001361static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001362{
David Weinehall36cdd012016-08-22 13:59:31 +03001363 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001364 u32 rgvmodectl, rstdbyctl;
1365 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001366
Ben Widawsky616fdb52011-10-05 11:44:54 -07001367 rgvmodectl = I915_READ(MEMMODECTL);
1368 rstdbyctl = I915_READ(RSTDBYCTL);
1369 crstandvid = I915_READ16(CRSTANDVID);
1370
Jani Nikula742f4912015-09-03 11:16:09 +03001371 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001372 seq_printf(m, "Boost freq: %d\n",
1373 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1374 MEMMODE_BOOST_FREQ_SHIFT);
1375 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001376 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001377 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001378 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001379 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001380 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001381 seq_printf(m, "Starting frequency: P%d\n",
1382 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001383 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001384 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001385 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1386 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1387 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1388 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001389 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001390 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001391 switch (rstdbyctl & RSX_STATUS_MASK) {
1392 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001393 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001394 break;
1395 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001396 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001397 break;
1398 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001399 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001400 break;
1401 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001402 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001403 break;
1404 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001405 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001406 break;
1407 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001408 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001409 break;
1410 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001411 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001412 break;
1413 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001414
1415 return 0;
1416}
1417
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001418static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001419{
Chris Wilson233ebf52017-03-23 10:19:44 +00001420 struct drm_i915_private *i915 = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001421 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsond2dc94b2017-03-23 10:19:41 +00001422 unsigned int tmp;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001423
Chris Wilson233ebf52017-03-23 10:19:44 +00001424 for_each_fw_domain(fw_domain, i915, tmp)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001425 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001426 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilson233ebf52017-03-23 10:19:44 +00001427 READ_ONCE(fw_domain->wake_count));
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001428
1429 return 0;
1430}
1431
Mika Kuoppala13628772017-03-15 17:43:02 +02001432static void print_rc6_res(struct seq_file *m,
1433 const char *title,
1434 const i915_reg_t reg)
1435{
1436 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1437
1438 seq_printf(m, "%s %u (%llu us)\n",
1439 title, I915_READ(reg),
1440 intel_rc6_residency_us(dev_priv, reg));
1441}
1442
Deepak S669ab5a2014-01-10 15:18:26 +05301443static int vlv_drpc_info(struct seq_file *m)
1444{
David Weinehall36cdd012016-08-22 13:59:31 +03001445 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001446 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301447
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001448 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301449 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1450 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1451
1452 seq_printf(m, "Video Turbo Mode: %s\n",
1453 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1454 seq_printf(m, "Turbo enabled: %s\n",
1455 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1456 seq_printf(m, "HW control enabled: %s\n",
1457 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1458 seq_printf(m, "SW control enabled: %s\n",
1459 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1460 GEN6_RP_MEDIA_SW_MODE));
1461 seq_printf(m, "RC6 Enabled: %s\n",
1462 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1463 GEN6_RC_CTL_EI_MODE(1))));
1464 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001465 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301466 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001467 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301468
Mika Kuoppala13628772017-03-15 17:43:02 +02001469 print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
1470 print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
Imre Deak9cc19be2014-04-14 20:24:24 +03001471
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001472 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301473}
1474
Ben Widawsky4d855292011-12-12 19:34:16 -08001475static int gen6_drpc_info(struct seq_file *m)
1476{
David Weinehall36cdd012016-08-22 13:59:31 +03001477 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001478 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301479 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001480 unsigned forcewake_count;
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001481 int count = 0;
Ben Widawsky4d855292011-12-12 19:34:16 -08001482
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001483 forcewake_count = READ_ONCE(dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001484 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001485 seq_puts(m, "RC information inaccurate because somebody "
1486 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001487 } else {
1488 /* NB: we cannot use forcewake, else we read the wrong values */
1489 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1490 udelay(10);
1491 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1492 }
1493
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001494 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001495 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001496
1497 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1498 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001499 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301500 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1501 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1502 }
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001503
Ben Widawsky44cbd332012-11-06 14:36:36 +00001504 mutex_lock(&dev_priv->rps.hw_lock);
1505 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1506 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001507
1508 seq_printf(m, "Video Turbo Mode: %s\n",
1509 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1510 seq_printf(m, "HW control enabled: %s\n",
1511 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1512 seq_printf(m, "SW control enabled: %s\n",
1513 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1514 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001515 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001516 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1517 seq_printf(m, "RC6 Enabled: %s\n",
1518 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001519 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301520 seq_printf(m, "Render Well Gating Enabled: %s\n",
1521 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1522 seq_printf(m, "Media Well Gating Enabled: %s\n",
1523 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1524 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001525 seq_printf(m, "Deep RC6 Enabled: %s\n",
1526 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1527 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1528 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001529 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001530 switch (gt_core_status & GEN6_RCn_MASK) {
1531 case GEN6_RC0:
1532 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001533 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001534 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001535 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001536 break;
1537 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001538 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001539 break;
1540 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001541 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001542 break;
1543 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001544 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001545 break;
1546 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001547 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001548 break;
1549 }
1550
1551 seq_printf(m, "Core Power Down: %s\n",
1552 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001553 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301554 seq_printf(m, "Render Power Well: %s\n",
1555 (gen9_powergate_status &
1556 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1557 seq_printf(m, "Media Power Well: %s\n",
1558 (gen9_powergate_status &
1559 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1560 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001561
1562 /* Not exactly sure what this is */
Mika Kuoppala13628772017-03-15 17:43:02 +02001563 print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
1564 GEN6_GT_GFX_RC6_LOCKED);
1565 print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
1566 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
1567 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
Ben Widawskycce66a22012-03-27 18:59:38 -07001568
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001569 seq_printf(m, "RC6 voltage: %dmV\n",
1570 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1571 seq_printf(m, "RC6+ voltage: %dmV\n",
1572 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1573 seq_printf(m, "RC6++ voltage: %dmV\n",
1574 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301575 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001576}
1577
1578static int i915_drpc_info(struct seq_file *m, void *unused)
1579{
David Weinehall36cdd012016-08-22 13:59:31 +03001580 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001581 int err;
1582
1583 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001584
David Weinehall36cdd012016-08-22 13:59:31 +03001585 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001586 err = vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001587 else if (INTEL_GEN(dev_priv) >= 6)
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001588 err = gen6_drpc_info(m);
Ben Widawsky4d855292011-12-12 19:34:16 -08001589 else
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001590 err = ironlake_drpc_info(m);
1591
1592 intel_runtime_pm_put(dev_priv);
1593
1594 return err;
Ben Widawsky4d855292011-12-12 19:34:16 -08001595}
1596
Daniel Vetter9a851782015-06-18 10:30:22 +02001597static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1598{
David Weinehall36cdd012016-08-22 13:59:31 +03001599 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001600
1601 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1602 dev_priv->fb_tracking.busy_bits);
1603
1604 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1605 dev_priv->fb_tracking.flip_bits);
1606
1607 return 0;
1608}
1609
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001610static int i915_fbc_status(struct seq_file *m, void *unused)
1611{
David Weinehall36cdd012016-08-22 13:59:31 +03001612 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001613
David Weinehall36cdd012016-08-22 13:59:31 +03001614 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001615 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001616 return 0;
1617 }
1618
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001619 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001620 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001621
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001622 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001623 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001624 else
1625 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001626 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001627
Ville Syrjälä3fd5d1e2017-06-06 15:43:18 +03001628 if (intel_fbc_is_active(dev_priv)) {
1629 u32 mask;
1630
1631 if (INTEL_GEN(dev_priv) >= 8)
1632 mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
1633 else if (INTEL_GEN(dev_priv) >= 7)
1634 mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
1635 else if (INTEL_GEN(dev_priv) >= 5)
1636 mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
1637 else if (IS_G4X(dev_priv))
1638 mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
1639 else
1640 mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
1641 FBC_STAT_COMPRESSED);
1642
1643 seq_printf(m, "Compressing: %s\n", yesno(mask));
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001644 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001645
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001646 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001647 intel_runtime_pm_put(dev_priv);
1648
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001649 return 0;
1650}
1651
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001652static int i915_fbc_false_color_get(void *data, u64 *val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001653{
David Weinehall36cdd012016-08-22 13:59:31 +03001654 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001655
David Weinehall36cdd012016-08-22 13:59:31 +03001656 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001657 return -ENODEV;
1658
Rodrigo Vivida46f932014-08-01 02:04:45 -07001659 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001660
1661 return 0;
1662}
1663
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001664static int i915_fbc_false_color_set(void *data, u64 val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001665{
David Weinehall36cdd012016-08-22 13:59:31 +03001666 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001667 u32 reg;
1668
David Weinehall36cdd012016-08-22 13:59:31 +03001669 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001670 return -ENODEV;
1671
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001672 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001673
1674 reg = I915_READ(ILK_DPFC_CONTROL);
1675 dev_priv->fbc.false_color = val;
1676
1677 I915_WRITE(ILK_DPFC_CONTROL, val ?
1678 (reg | FBC_CTL_FALSE_COLOR) :
1679 (reg & ~FBC_CTL_FALSE_COLOR));
1680
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001681 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001682 return 0;
1683}
1684
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001685DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_false_color_fops,
1686 i915_fbc_false_color_get, i915_fbc_false_color_set,
Rodrigo Vivida46f932014-08-01 02:04:45 -07001687 "%llu\n");
1688
Paulo Zanoni92d44622013-05-31 16:33:24 -03001689static int i915_ips_status(struct seq_file *m, void *unused)
1690{
David Weinehall36cdd012016-08-22 13:59:31 +03001691 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001692
David Weinehall36cdd012016-08-22 13:59:31 +03001693 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001694 seq_puts(m, "not supported\n");
1695 return 0;
1696 }
1697
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001698 intel_runtime_pm_get(dev_priv);
1699
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001700 seq_printf(m, "Enabled by kernel parameter: %s\n",
1701 yesno(i915.enable_ips));
1702
David Weinehall36cdd012016-08-22 13:59:31 +03001703 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001704 seq_puts(m, "Currently: unknown\n");
1705 } else {
1706 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1707 seq_puts(m, "Currently: enabled\n");
1708 else
1709 seq_puts(m, "Currently: disabled\n");
1710 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001711
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001712 intel_runtime_pm_put(dev_priv);
1713
Paulo Zanoni92d44622013-05-31 16:33:24 -03001714 return 0;
1715}
1716
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001717static int i915_sr_status(struct seq_file *m, void *unused)
1718{
David Weinehall36cdd012016-08-22 13:59:31 +03001719 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001720 bool sr_enabled = false;
1721
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001722 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001723 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001724
Chris Wilson7342a722017-03-09 14:20:49 +00001725 if (INTEL_GEN(dev_priv) >= 9)
1726 /* no global SR status; inspect per-plane WM */;
1727 else if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001728 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001729 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001730 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001731 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001732 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001733 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001734 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001735 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001736 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001737 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001738
Chris Wilson9c870d02016-10-24 13:42:15 +01001739 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001740 intel_runtime_pm_put(dev_priv);
1741
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001742 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001743
1744 return 0;
1745}
1746
Jesse Barnes7648fa92010-05-20 14:28:11 -07001747static int i915_emon_status(struct seq_file *m, void *unused)
1748{
David Weinehall36cdd012016-08-22 13:59:31 +03001749 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1750 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001751 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001752 int ret;
1753
David Weinehall36cdd012016-08-22 13:59:31 +03001754 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001755 return -ENODEV;
1756
Chris Wilsonde227ef2010-07-03 07:58:38 +01001757 ret = mutex_lock_interruptible(&dev->struct_mutex);
1758 if (ret)
1759 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001760
1761 temp = i915_mch_val(dev_priv);
1762 chipset = i915_chipset_val(dev_priv);
1763 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001764 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001765
1766 seq_printf(m, "GMCH temp: %ld\n", temp);
1767 seq_printf(m, "Chipset power: %ld\n", chipset);
1768 seq_printf(m, "GFX power: %ld\n", gfx);
1769 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1770
1771 return 0;
1772}
1773
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001774static int i915_ring_freq_table(struct seq_file *m, void *unused)
1775{
David Weinehall36cdd012016-08-22 13:59:31 +03001776 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001777 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001778 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301779 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001780
Carlos Santa26310342016-08-17 12:30:41 -07001781 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001782 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001783 return 0;
1784 }
1785
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001786 intel_runtime_pm_get(dev_priv);
1787
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001788 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001790 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001791
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001792 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301793 /* Convert GT frequency to 50 HZ units */
1794 min_gpu_freq =
1795 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1796 max_gpu_freq =
1797 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1798 } else {
1799 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1800 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1801 }
1802
Damien Lespiau267f0c92013-06-24 22:59:48 +01001803 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001804
Akash Goelf936ec32015-06-29 14:50:22 +05301805 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001806 ia_freq = gpu_freq;
1807 sandybridge_pcode_read(dev_priv,
1808 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1809 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001810 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301811 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001812 (IS_GEN9_BC(dev_priv) ||
1813 IS_CANNONLAKE(dev_priv) ?
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001814 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001815 ((ia_freq >> 0) & 0xff) * 100,
1816 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001817 }
1818
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001819 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001820
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001821out:
1822 intel_runtime_pm_put(dev_priv);
1823 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001824}
1825
Chris Wilson44834a62010-08-19 16:09:23 +01001826static int i915_opregion(struct seq_file *m, void *unused)
1827{
David Weinehall36cdd012016-08-22 13:59:31 +03001828 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1829 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001830 struct intel_opregion *opregion = &dev_priv->opregion;
1831 int ret;
1832
1833 ret = mutex_lock_interruptible(&dev->struct_mutex);
1834 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001835 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001836
Jani Nikula2455a8e2015-12-14 12:50:53 +02001837 if (opregion->header)
1838 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001839
1840 mutex_unlock(&dev->struct_mutex);
1841
Daniel Vetter0d38f002012-04-21 22:49:10 +02001842out:
Chris Wilson44834a62010-08-19 16:09:23 +01001843 return 0;
1844}
1845
Jani Nikulaada8f952015-12-15 13:17:12 +02001846static int i915_vbt(struct seq_file *m, void *unused)
1847{
David Weinehall36cdd012016-08-22 13:59:31 +03001848 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001849
1850 if (opregion->vbt)
1851 seq_write(m, opregion->vbt, opregion->vbt_size);
1852
1853 return 0;
1854}
1855
Chris Wilson37811fc2010-08-25 22:45:57 +01001856static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1857{
David Weinehall36cdd012016-08-22 13:59:31 +03001858 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1859 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301860 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001861 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001862 int ret;
1863
1864 ret = mutex_lock_interruptible(&dev->struct_mutex);
1865 if (ret)
1866 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001867
Daniel Vetter06957262015-08-10 13:34:08 +02001868#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter346fb4e2017-07-06 15:00:20 +02001869 if (dev_priv->fbdev && dev_priv->fbdev->helper.fb) {
David Weinehall36cdd012016-08-22 13:59:31 +03001870 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001871
Chris Wilson25bcce92016-07-02 15:36:00 +01001872 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1873 fbdev_fb->base.width,
1874 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001875 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001876 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001877 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001878 drm_framebuffer_read_refcount(&fbdev_fb->base));
1879 describe_obj(m, fbdev_fb->obj);
1880 seq_putc(m, '\n');
1881 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001882#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001883
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001884 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001885 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301886 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1887 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001888 continue;
1889
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001890 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 +01001891 fb->base.width,
1892 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001893 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001894 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001895 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001896 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001897 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001898 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001899 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001900 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001901 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001902
1903 return 0;
1904}
1905
Chris Wilson7e37f882016-08-02 22:50:21 +01001906static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001907{
Chris Wilsonfe085f12017-03-21 10:25:52 +00001908 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u)",
1909 ring->space, ring->head, ring->tail);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001910}
1911
Ben Widawskye76d3632011-03-19 18:14:29 -07001912static int i915_context_status(struct seq_file *m, void *unused)
1913{
David Weinehall36cdd012016-08-22 13:59:31 +03001914 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1915 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001916 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001917 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301918 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001919 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001920
Daniel Vetterf3d28872014-05-29 23:23:08 +02001921 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001922 if (ret)
1923 return ret;
1924
Chris Wilson829a0af2017-06-20 12:05:45 +01001925 list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001926 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001927 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001928 struct task_struct *task;
1929
Chris Wilsonc84455b2016-08-15 10:49:08 +01001930 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001931 if (task) {
1932 seq_printf(m, "(%s [%d]) ",
1933 task->comm, task->pid);
1934 put_task_struct(task);
1935 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001936 } else if (IS_ERR(ctx->file_priv)) {
1937 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001938 } else {
1939 seq_puts(m, "(kernel) ");
1940 }
1941
Chris Wilsonbca44d82016-05-24 14:53:41 +01001942 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1943 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001944
Akash Goel3b3f1652016-10-13 22:44:48 +05301945 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001946 struct intel_context *ce = &ctx->engine[engine->id];
1947
1948 seq_printf(m, "%s: ", engine->name);
1949 seq_putc(m, ce->initialised ? 'I' : 'i');
1950 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001951 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001952 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001953 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001954 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001955 }
1956
Chris Wilson4ff4b442017-06-16 15:05:16 +01001957 seq_printf(m,
1958 "\tvma hashtable size=%u (actual %lu), count=%u\n",
1959 ctx->vma_lut.ht_size,
1960 BIT(ctx->vma_lut.ht_bits),
1961 ctx->vma_lut.ht_count);
1962
Ben Widawskya33afea2013-09-17 21:12:45 -07001963 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001964 }
1965
Daniel Vetterf3d28872014-05-29 23:23:08 +02001966 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001967
1968 return 0;
1969}
1970
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001971static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001972 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001973 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001974{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001975 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001976 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001977 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001978
Chris Wilson7069b142016-04-28 09:56:52 +01001979 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1980
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001981 if (!vma) {
1982 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001983 return;
1984 }
1985
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001986 if (vma->flags & I915_VMA_GLOBAL_BIND)
1987 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01001988 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001989
Chris Wilsona4f5ea62016-10-28 13:58:35 +01001990 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001991 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001992 return;
1993 }
1994
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001995 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
1996 if (page) {
1997 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001998
1999 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002000 seq_printf(m,
2001 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2002 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002003 reg_state[j], reg_state[j + 1],
2004 reg_state[j + 2], reg_state[j + 3]);
2005 }
2006 kunmap_atomic(reg_state);
2007 }
2008
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002009 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002010 seq_putc(m, '\n');
2011}
2012
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002013static int i915_dump_lrc(struct seq_file *m, void *unused)
2014{
David Weinehall36cdd012016-08-22 13:59:31 +03002015 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2016 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002017 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002018 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302019 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002020 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002021
2022 if (!i915.enable_execlists) {
2023 seq_printf(m, "Logical Ring Contexts are disabled\n");
2024 return 0;
2025 }
2026
2027 ret = mutex_lock_interruptible(&dev->struct_mutex);
2028 if (ret)
2029 return ret;
2030
Chris Wilson829a0af2017-06-20 12:05:45 +01002031 list_for_each_entry(ctx, &dev_priv->contexts.list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302032 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002033 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002034
2035 mutex_unlock(&dev->struct_mutex);
2036
2037 return 0;
2038}
2039
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002040static const char *swizzle_string(unsigned swizzle)
2041{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002042 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002043 case I915_BIT_6_SWIZZLE_NONE:
2044 return "none";
2045 case I915_BIT_6_SWIZZLE_9:
2046 return "bit9";
2047 case I915_BIT_6_SWIZZLE_9_10:
2048 return "bit9/bit10";
2049 case I915_BIT_6_SWIZZLE_9_11:
2050 return "bit9/bit11";
2051 case I915_BIT_6_SWIZZLE_9_10_11:
2052 return "bit9/bit10/bit11";
2053 case I915_BIT_6_SWIZZLE_9_17:
2054 return "bit9/bit17";
2055 case I915_BIT_6_SWIZZLE_9_10_17:
2056 return "bit9/bit10/bit17";
2057 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002058 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002059 }
2060
2061 return "bug";
2062}
2063
2064static int i915_swizzle_info(struct seq_file *m, void *data)
2065{
David Weinehall36cdd012016-08-22 13:59:31 +03002066 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002067
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002068 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002069
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002070 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2071 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2072 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2073 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2074
David Weinehall36cdd012016-08-22 13:59:31 +03002075 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002076 seq_printf(m, "DDC = 0x%08x\n",
2077 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002078 seq_printf(m, "DDC2 = 0x%08x\n",
2079 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002080 seq_printf(m, "C0DRB3 = 0x%04x\n",
2081 I915_READ16(C0DRB3));
2082 seq_printf(m, "C1DRB3 = 0x%04x\n",
2083 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002084 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002085 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2086 I915_READ(MAD_DIMM_C0));
2087 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2088 I915_READ(MAD_DIMM_C1));
2089 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2090 I915_READ(MAD_DIMM_C2));
2091 seq_printf(m, "TILECTL = 0x%08x\n",
2092 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002093 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002094 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2095 I915_READ(GAMTARBMODE));
2096 else
2097 seq_printf(m, "ARB_MODE = 0x%08x\n",
2098 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002099 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2100 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002101 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002102
2103 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2104 seq_puts(m, "L-shaped memory detected\n");
2105
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002106 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002107
2108 return 0;
2109}
2110
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002111static int per_file_ctx(int id, void *ptr, void *data)
2112{
Chris Wilsone2efd132016-05-24 14:53:34 +01002113 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002114 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002115 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2116
2117 if (!ppgtt) {
2118 seq_printf(m, " no ppgtt for context %d\n",
2119 ctx->user_handle);
2120 return 0;
2121 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002122
Oscar Mateof83d6512014-05-22 14:13:38 +01002123 if (i915_gem_context_is_default(ctx))
2124 seq_puts(m, " default context:\n");
2125 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002126 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002127 ppgtt->debug_dump(ppgtt, m);
2128
2129 return 0;
2130}
2131
David Weinehall36cdd012016-08-22 13:59:31 +03002132static void gen8_ppgtt_info(struct seq_file *m,
2133 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002134{
Ben Widawsky77df6772013-11-02 21:07:30 -07002135 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302136 struct intel_engine_cs *engine;
2137 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002138 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002139
Ben Widawsky77df6772013-11-02 21:07:30 -07002140 if (!ppgtt)
2141 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002142
Akash Goel3b3f1652016-10-13 22:44:48 +05302143 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002144 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002145 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002146 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002147 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002148 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002149 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002150 }
2151 }
2152}
2153
David Weinehall36cdd012016-08-22 13:59:31 +03002154static void gen6_ppgtt_info(struct seq_file *m,
2155 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002156{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002157 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302158 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002159
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002160 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002161 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2162
Akash Goel3b3f1652016-10-13 22:44:48 +05302163 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002164 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002165 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002166 seq_printf(m, "GFX_MODE: 0x%08x\n",
2167 I915_READ(RING_MODE_GEN7(engine)));
2168 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2169 I915_READ(RING_PP_DIR_BASE(engine)));
2170 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2171 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2172 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2173 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002174 }
2175 if (dev_priv->mm.aliasing_ppgtt) {
2176 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2177
Damien Lespiau267f0c92013-06-24 22:59:48 +01002178 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002179 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002180
Ben Widawsky87d60b62013-12-06 14:11:29 -08002181 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002182 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002183
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002184 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002185}
2186
2187static int i915_ppgtt_info(struct seq_file *m, void *data)
2188{
David Weinehall36cdd012016-08-22 13:59:31 +03002189 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2190 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002191 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002192 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002193
Chris Wilson637ee292016-08-22 14:28:20 +01002194 mutex_lock(&dev->filelist_mutex);
2195 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002196 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002197 goto out_unlock;
2198
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002199 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002200
David Weinehall36cdd012016-08-22 13:59:31 +03002201 if (INTEL_GEN(dev_priv) >= 8)
2202 gen8_ppgtt_info(m, dev_priv);
2203 else if (INTEL_GEN(dev_priv) >= 6)
2204 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002205
Michel Thierryea91e402015-07-29 17:23:57 +01002206 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2207 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002208 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002209
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002210 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002211 if (!task) {
2212 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002213 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002214 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002215 seq_printf(m, "\nproc: %s\n", task->comm);
2216 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002217 idr_for_each(&file_priv->context_idr, per_file_ctx,
2218 (void *)(unsigned long)m);
2219 }
2220
Chris Wilson637ee292016-08-22 14:28:20 +01002221out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002222 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002223 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002224out_unlock:
2225 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002226 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002227}
2228
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002229static int count_irq_waiters(struct drm_i915_private *i915)
2230{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002231 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302232 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002233 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002234
Akash Goel3b3f1652016-10-13 22:44:48 +05302235 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002236 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002237
2238 return count;
2239}
2240
Chris Wilson7466c292016-08-15 09:49:33 +01002241static const char *rps_power_to_str(unsigned int power)
2242{
2243 static const char * const strings[] = {
2244 [LOW_POWER] = "low power",
2245 [BETWEEN] = "mixed",
2246 [HIGH_POWER] = "high power",
2247 };
2248
2249 if (power >= ARRAY_SIZE(strings) || !strings[power])
2250 return "unknown";
2251
2252 return strings[power];
2253}
2254
Chris Wilson1854d5c2015-04-07 16:20:32 +01002255static int i915_rps_boost_info(struct seq_file *m, void *data)
2256{
David Weinehall36cdd012016-08-22 13:59:31 +03002257 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2258 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002259 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002260
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002261 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002262 seq_printf(m, "GPU busy? %s [%d requests]\n",
2263 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002264 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002265 seq_printf(m, "Boosts outstanding? %d\n",
2266 atomic_read(&dev_priv->rps.num_waiters));
Chris Wilson7466c292016-08-15 09:49:33 +01002267 seq_printf(m, "Frequency requested %d\n",
2268 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2269 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002270 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2271 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2272 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2273 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002274 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2275 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2276 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2277 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002278
2279 mutex_lock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002280 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2281 struct drm_i915_file_private *file_priv = file->driver_priv;
2282 struct task_struct *task;
2283
2284 rcu_read_lock();
2285 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002286 seq_printf(m, "%s [%d]: %d boosts\n",
Chris Wilson1854d5c2015-04-07 16:20:32 +01002287 task ? task->comm : "<unknown>",
2288 task ? task->pid : -1,
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002289 atomic_read(&file_priv->rps.boosts));
Chris Wilson1854d5c2015-04-07 16:20:32 +01002290 rcu_read_unlock();
2291 }
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002292 seq_printf(m, "Kernel (anonymous) boosts: %d\n",
2293 atomic_read(&dev_priv->rps.boosts));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002294 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002295
Chris Wilson7466c292016-08-15 09:49:33 +01002296 if (INTEL_GEN(dev_priv) >= 6 &&
2297 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002298 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002299 u32 rpup, rpupei;
2300 u32 rpdown, rpdownei;
2301
2302 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2303 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2304 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2305 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2306 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2307 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2308
2309 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2310 rps_power_to_str(dev_priv->rps.power));
2311 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002312 rpup && rpupei ? 100 * rpup / rpupei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002313 dev_priv->rps.up_threshold);
2314 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002315 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002316 dev_priv->rps.down_threshold);
2317 } else {
2318 seq_puts(m, "\nRPS Autotuning inactive\n");
2319 }
2320
Chris Wilson8d3afd72015-05-21 21:01:47 +01002321 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002322}
2323
Ben Widawsky63573eb2013-07-04 11:02:07 -07002324static int i915_llc(struct seq_file *m, void *data)
2325{
David Weinehall36cdd012016-08-22 13:59:31 +03002326 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002327 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002328
David Weinehall36cdd012016-08-22 13:59:31 +03002329 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002330 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2331 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002332
2333 return 0;
2334}
2335
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002336static int i915_huc_load_status_info(struct seq_file *m, void *data)
2337{
2338 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2339 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2340
2341 if (!HAS_HUC_UCODE(dev_priv))
2342 return 0;
2343
2344 seq_puts(m, "HuC firmware status:\n");
2345 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2346 seq_printf(m, "\tfetch: %s\n",
2347 intel_uc_fw_status_repr(huc_fw->fetch_status));
2348 seq_printf(m, "\tload: %s\n",
2349 intel_uc_fw_status_repr(huc_fw->load_status));
2350 seq_printf(m, "\tversion wanted: %d.%d\n",
2351 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2352 seq_printf(m, "\tversion found: %d.%d\n",
2353 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2354 seq_printf(m, "\theader: offset is %d; size = %d\n",
2355 huc_fw->header_offset, huc_fw->header_size);
2356 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2357 huc_fw->ucode_offset, huc_fw->ucode_size);
2358 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2359 huc_fw->rsa_offset, huc_fw->rsa_size);
2360
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302361 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002362 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302363 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002364
2365 return 0;
2366}
2367
Alex Daifdf5d352015-08-12 15:43:37 +01002368static int i915_guc_load_status_info(struct seq_file *m, void *data)
2369{
David Weinehall36cdd012016-08-22 13:59:31 +03002370 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002371 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Daifdf5d352015-08-12 15:43:37 +01002372 u32 tmp, i;
2373
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002374 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002375 return 0;
2376
2377 seq_printf(m, "GuC firmware status:\n");
2378 seq_printf(m, "\tpath: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002379 guc_fw->path);
Alex Daifdf5d352015-08-12 15:43:37 +01002380 seq_printf(m, "\tfetch: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002381 intel_uc_fw_status_repr(guc_fw->fetch_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002382 seq_printf(m, "\tload: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002383 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002384 seq_printf(m, "\tversion wanted: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002385 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
Alex Daifdf5d352015-08-12 15:43:37 +01002386 seq_printf(m, "\tversion found: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002387 guc_fw->major_ver_found, guc_fw->minor_ver_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002388 seq_printf(m, "\theader: offset is %d; size = %d\n",
2389 guc_fw->header_offset, guc_fw->header_size);
2390 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2391 guc_fw->ucode_offset, guc_fw->ucode_size);
2392 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2393 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002394
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302395 intel_runtime_pm_get(dev_priv);
2396
Alex Daifdf5d352015-08-12 15:43:37 +01002397 tmp = I915_READ(GUC_STATUS);
2398
2399 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2400 seq_printf(m, "\tBootrom status = 0x%x\n",
2401 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2402 seq_printf(m, "\tuKernel status = 0x%x\n",
2403 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2404 seq_printf(m, "\tMIA Core status = 0x%x\n",
2405 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2406 seq_puts(m, "\nScratch registers:\n");
2407 for (i = 0; i < 16; i++)
2408 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2409
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302410 intel_runtime_pm_put(dev_priv);
2411
Alex Daifdf5d352015-08-12 15:43:37 +01002412 return 0;
2413}
2414
Akash Goel5aa1ee42016-10-12 21:54:36 +05302415static void i915_guc_log_info(struct seq_file *m,
2416 struct drm_i915_private *dev_priv)
2417{
2418 struct intel_guc *guc = &dev_priv->guc;
2419
2420 seq_puts(m, "\nGuC logging stats:\n");
2421
2422 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2423 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2424 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2425
2426 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2427 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2428 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2429
2430 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2431 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2432 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2433
2434 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2435 guc->log.flush_interrupt_count);
2436
2437 seq_printf(m, "\tCapture miss count: %u\n",
2438 guc->log.capture_miss_count);
2439}
2440
Dave Gordon8b417c22015-08-12 15:43:44 +01002441static void i915_guc_client_info(struct seq_file *m,
2442 struct drm_i915_private *dev_priv,
2443 struct i915_guc_client *client)
2444{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002445 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002446 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002447 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002448
Oscar Mateob09935a2017-03-22 10:39:53 -07002449 seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
2450 client->priority, client->stage_id, client->proc_desc_offset);
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002451 seq_printf(m, "\tDoorbell id %d, offset: 0x%lx, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002452 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002453 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2454 client->wq_size, client->wq_offset, client->wq_tail);
2455
Dave Gordon551aaec2016-05-13 15:36:33 +01002456 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002457
Akash Goel3b3f1652016-10-13 22:44:48 +05302458 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002459 u64 submissions = client->submissions[id];
2460 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002461 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002462 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002463 }
2464 seq_printf(m, "\tTotal: %llu\n", tot);
2465}
2466
Oscar Mateoa8b93702017-05-10 15:04:51 +00002467static bool check_guc_submission(struct seq_file *m)
Dave Gordon8b417c22015-08-12 15:43:44 +01002468{
David Weinehall36cdd012016-08-22 13:59:31 +03002469 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002470 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002471
Chris Wilson334636c2016-11-29 12:10:20 +00002472 if (!guc->execbuf_client) {
2473 seq_printf(m, "GuC submission %s\n",
2474 HAS_GUC_SCHED(dev_priv) ?
2475 "disabled" :
2476 "not supported");
Oscar Mateoa8b93702017-05-10 15:04:51 +00002477 return false;
Chris Wilson334636c2016-11-29 12:10:20 +00002478 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002479
Oscar Mateoa8b93702017-05-10 15:04:51 +00002480 return true;
2481}
2482
Dave Gordon8b417c22015-08-12 15:43:44 +01002483static int i915_guc_info(struct seq_file *m, void *data)
2484{
2485 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2486 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002487
Oscar Mateoa8b93702017-05-10 15:04:51 +00002488 if (!check_guc_submission(m))
Dave Gordon8b417c22015-08-12 15:43:44 +01002489 return 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002490
Dave Gordon9636f6d2016-06-13 17:57:28 +01002491 seq_printf(m, "Doorbell map:\n");
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002492 seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
Chris Wilson334636c2016-11-29 12:10:20 +00002493 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002494
Chris Wilson334636c2016-11-29 12:10:20 +00002495 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2496 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002497
Akash Goel5aa1ee42016-10-12 21:54:36 +05302498 i915_guc_log_info(m, dev_priv);
2499
Dave Gordon8b417c22015-08-12 15:43:44 +01002500 /* Add more as required ... */
2501
2502 return 0;
2503}
2504
Oscar Mateoa8b93702017-05-10 15:04:51 +00002505static int i915_guc_stage_pool(struct seq_file *m, void *data)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002506{
David Weinehall36cdd012016-08-22 13:59:31 +03002507 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Oscar Mateoa8b93702017-05-10 15:04:51 +00002508 const struct intel_guc *guc = &dev_priv->guc;
2509 struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
2510 struct i915_guc_client *client = guc->execbuf_client;
2511 unsigned int tmp;
2512 int index;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002513
Oscar Mateoa8b93702017-05-10 15:04:51 +00002514 if (!check_guc_submission(m))
Alex Dai4c7e77f2015-08-12 15:43:40 +01002515 return 0;
2516
Oscar Mateoa8b93702017-05-10 15:04:51 +00002517 for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
2518 struct intel_engine_cs *engine;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002519
Oscar Mateoa8b93702017-05-10 15:04:51 +00002520 if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
2521 continue;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002522
Oscar Mateoa8b93702017-05-10 15:04:51 +00002523 seq_printf(m, "GuC stage descriptor %u:\n", index);
2524 seq_printf(m, "\tIndex: %u\n", desc->stage_id);
2525 seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
2526 seq_printf(m, "\tPriority: %d\n", desc->priority);
2527 seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
2528 seq_printf(m, "\tEngines used: 0x%x\n",
2529 desc->engines_used);
2530 seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
2531 desc->db_trigger_phy,
2532 desc->db_trigger_cpu,
2533 desc->db_trigger_uk);
2534 seq_printf(m, "\tProcess descriptor: 0x%x\n",
2535 desc->process_desc);
Colin Ian King9a094852017-05-16 10:22:35 +01002536 seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
Oscar Mateoa8b93702017-05-10 15:04:51 +00002537 desc->wq_addr, desc->wq_size);
2538 seq_putc(m, '\n');
2539
2540 for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
2541 u32 guc_engine_id = engine->guc_id;
2542 struct guc_execlist_context *lrc =
2543 &desc->lrc[guc_engine_id];
2544
2545 seq_printf(m, "\t%s LRC:\n", engine->name);
2546 seq_printf(m, "\t\tContext desc: 0x%x\n",
2547 lrc->context_desc);
2548 seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
2549 seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
2550 seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
2551 seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
2552 seq_putc(m, '\n');
2553 }
Alex Dai4c7e77f2015-08-12 15:43:40 +01002554 }
2555
Oscar Mateoa8b93702017-05-10 15:04:51 +00002556 return 0;
2557}
2558
Alex Dai4c7e77f2015-08-12 15:43:40 +01002559static int i915_guc_log_dump(struct seq_file *m, void *data)
2560{
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002561 struct drm_info_node *node = m->private;
2562 struct drm_i915_private *dev_priv = node_to_i915(node);
2563 bool dump_load_err = !!node->info_ent->data;
2564 struct drm_i915_gem_object *obj = NULL;
2565 u32 *log;
2566 int i = 0;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002567
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002568 if (dump_load_err)
2569 obj = dev_priv->guc.load_err_log;
2570 else if (dev_priv->guc.log.vma)
2571 obj = dev_priv->guc.log.vma->obj;
2572
2573 if (!obj)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002574 return 0;
2575
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002576 log = i915_gem_object_pin_map(obj, I915_MAP_WC);
2577 if (IS_ERR(log)) {
2578 DRM_DEBUG("Failed to pin object\n");
2579 seq_puts(m, "(log data unaccessible)\n");
2580 return PTR_ERR(log);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002581 }
2582
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002583 for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
2584 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2585 *(log + i), *(log + i + 1),
2586 *(log + i + 2), *(log + i + 3));
2587
Alex Dai4c7e77f2015-08-12 15:43:40 +01002588 seq_putc(m, '\n');
2589
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002590 i915_gem_object_unpin_map(obj);
2591
Alex Dai4c7e77f2015-08-12 15:43:40 +01002592 return 0;
2593}
2594
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302595static int i915_guc_log_control_get(void *data, u64 *val)
2596{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002597 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302598
2599 if (!dev_priv->guc.log.vma)
2600 return -EINVAL;
2601
2602 *val = i915.guc_log_level;
2603
2604 return 0;
2605}
2606
2607static int i915_guc_log_control_set(void *data, u64 val)
2608{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002609 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302610 int ret;
2611
2612 if (!dev_priv->guc.log.vma)
2613 return -EINVAL;
2614
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002615 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302616 if (ret)
2617 return ret;
2618
2619 intel_runtime_pm_get(dev_priv);
2620 ret = i915_guc_log_control(dev_priv, val);
2621 intel_runtime_pm_put(dev_priv);
2622
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002623 mutex_unlock(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302624 return ret;
2625}
2626
2627DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2628 i915_guc_log_control_get, i915_guc_log_control_set,
2629 "%lld\n");
2630
Chris Wilsonb86bef202017-01-16 13:06:21 +00002631static const char *psr2_live_status(u32 val)
2632{
2633 static const char * const live_status[] = {
2634 "IDLE",
2635 "CAPTURE",
2636 "CAPTURE_FS",
2637 "SLEEP",
2638 "BUFON_FW",
2639 "ML_UP",
2640 "SU_STANDBY",
2641 "FAST_SLEEP",
2642 "DEEP_SLEEP",
2643 "BUF_ON",
2644 "TG_ON"
2645 };
2646
2647 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2648 if (val < ARRAY_SIZE(live_status))
2649 return live_status[val];
2650
2651 return "unknown";
2652}
2653
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002654static int i915_edp_psr_status(struct seq_file *m, void *data)
2655{
David Weinehall36cdd012016-08-22 13:59:31 +03002656 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002657 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002658 u32 stat[3];
2659 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002660 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002661
David Weinehall36cdd012016-08-22 13:59:31 +03002662 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002663 seq_puts(m, "PSR not supported\n");
2664 return 0;
2665 }
2666
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002667 intel_runtime_pm_get(dev_priv);
2668
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002669 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002670 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2671 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002672 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002673 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002674 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2675 dev_priv->psr.busy_frontbuffer_bits);
2676 seq_printf(m, "Re-enable work scheduled: %s\n",
2677 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002678
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302679 if (HAS_DDI(dev_priv)) {
2680 if (dev_priv->psr.psr2_support)
2681 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2682 else
2683 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2684 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002685 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002686 enum transcoder cpu_transcoder =
2687 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2688 enum intel_display_power_domain power_domain;
2689
2690 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2691 if (!intel_display_power_get_if_enabled(dev_priv,
2692 power_domain))
2693 continue;
2694
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002695 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2696 VLV_EDP_PSR_CURR_STATE_MASK;
2697 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2698 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2699 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002700
2701 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002702 }
2703 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002704
2705 seq_printf(m, "Main link in standby mode: %s\n",
2706 yesno(dev_priv->psr.link_standby));
2707
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002708 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002709
David Weinehall36cdd012016-08-22 13:59:31 +03002710 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002711 for_each_pipe(dev_priv, pipe) {
2712 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2713 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2714 seq_printf(m, " pipe %c", pipe_name(pipe));
2715 }
2716 seq_puts(m, "\n");
2717
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002718 /*
2719 * VLV/CHV PSR has no kind of performance counter
2720 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2721 */
David Weinehall36cdd012016-08-22 13:59:31 +03002722 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002723 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002724 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002725
2726 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2727 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302728 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002729 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302730
Chris Wilsonb86bef202017-01-16 13:06:21 +00002731 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2732 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302733 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002734 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002735
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002736 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002737 return 0;
2738}
2739
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002740static int i915_sink_crc(struct seq_file *m, void *data)
2741{
David Weinehall36cdd012016-08-22 13:59:31 +03002742 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2743 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002744 struct intel_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002745 struct drm_connector_list_iter conn_iter;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002746 struct intel_dp *intel_dp = NULL;
2747 int ret;
2748 u8 crc[6];
2749
2750 drm_modeset_lock_all(dev);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002751 drm_connector_list_iter_begin(dev, &conn_iter);
2752 for_each_intel_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002753 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002754
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002755 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002756 continue;
2757
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002758 crtc = connector->base.state->crtc;
2759 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002760 continue;
2761
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002762 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002763 continue;
2764
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002765 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002766
2767 ret = intel_dp_sink_crc(intel_dp, crc);
2768 if (ret)
2769 goto out;
2770
2771 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2772 crc[0], crc[1], crc[2],
2773 crc[3], crc[4], crc[5]);
2774 goto out;
2775 }
2776 ret = -ENODEV;
2777out:
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002778 drm_connector_list_iter_end(&conn_iter);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002779 drm_modeset_unlock_all(dev);
2780 return ret;
2781}
2782
Jesse Barnesec013e72013-08-20 10:29:23 +01002783static int i915_energy_uJ(struct seq_file *m, void *data)
2784{
David Weinehall36cdd012016-08-22 13:59:31 +03002785 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002786 unsigned long long power;
Jesse Barnesec013e72013-08-20 10:29:23 +01002787 u32 units;
2788
David Weinehall36cdd012016-08-22 13:59:31 +03002789 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002790 return -ENODEV;
2791
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002792 intel_runtime_pm_get(dev_priv);
2793
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002794 if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) {
2795 intel_runtime_pm_put(dev_priv);
2796 return -ENODEV;
2797 }
2798
2799 units = (power & 0x1f00) >> 8;
Jesse Barnesec013e72013-08-20 10:29:23 +01002800 power = I915_READ(MCH_SECP_NRG_STTS);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002801 power = (1000000 * power) >> units; /* convert to uJ */
Jesse Barnesec013e72013-08-20 10:29:23 +01002802
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002803 intel_runtime_pm_put(dev_priv);
2804
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002805 seq_printf(m, "%llu", power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002806
2807 return 0;
2808}
2809
Damien Lespiau6455c872015-06-04 18:23:57 +01002810static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002811{
David Weinehall36cdd012016-08-22 13:59:31 +03002812 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002813 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002814
Chris Wilsona156e642016-04-03 14:14:21 +01002815 if (!HAS_RUNTIME_PM(dev_priv))
2816 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002817
Chris Wilson67d97da2016-07-04 08:08:31 +01002818 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002819 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002820 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002821#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002822 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002823 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002824#else
2825 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2826#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002827 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002828 pci_power_name(pdev->current_state),
2829 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002830
Jesse Barnesec013e72013-08-20 10:29:23 +01002831 return 0;
2832}
2833
Imre Deak1da51582013-11-25 17:15:35 +02002834static int i915_power_domain_info(struct seq_file *m, void *unused)
2835{
David Weinehall36cdd012016-08-22 13:59:31 +03002836 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002837 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2838 int i;
2839
2840 mutex_lock(&power_domains->lock);
2841
2842 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2843 for (i = 0; i < power_domains->power_well_count; i++) {
2844 struct i915_power_well *power_well;
2845 enum intel_display_power_domain power_domain;
2846
2847 power_well = &power_domains->power_wells[i];
2848 seq_printf(m, "%-25s %d\n", power_well->name,
2849 power_well->count);
2850
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002851 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002852 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002853 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002854 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002855 }
2856
2857 mutex_unlock(&power_domains->lock);
2858
2859 return 0;
2860}
2861
Damien Lespiaub7cec662015-10-27 14:47:01 +02002862static int i915_dmc_info(struct seq_file *m, void *unused)
2863{
David Weinehall36cdd012016-08-22 13:59:31 +03002864 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002865 struct intel_csr *csr;
2866
David Weinehall36cdd012016-08-22 13:59:31 +03002867 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002868 seq_puts(m, "not supported\n");
2869 return 0;
2870 }
2871
2872 csr = &dev_priv->csr;
2873
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002874 intel_runtime_pm_get(dev_priv);
2875
Damien Lespiaub7cec662015-10-27 14:47:01 +02002876 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2877 seq_printf(m, "path: %s\n", csr->fw_path);
2878
2879 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002880 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002881
2882 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2883 CSR_VERSION_MINOR(csr->version));
2884
Mika Kuoppala48de5682017-05-09 13:05:22 +03002885 if (IS_KABYLAKE(dev_priv) ||
2886 (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6))) {
Damien Lespiau83372062015-10-30 17:53:32 +02002887 seq_printf(m, "DC3 -> DC5 count: %d\n",
2888 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2889 seq_printf(m, "DC5 -> DC6 count: %d\n",
2890 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002891 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002892 seq_printf(m, "DC3 -> DC5 count: %d\n",
2893 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002894 }
2895
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002896out:
2897 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2898 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2899 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2900
Damien Lespiau83372062015-10-30 17:53:32 +02002901 intel_runtime_pm_put(dev_priv);
2902
Damien Lespiaub7cec662015-10-27 14:47:01 +02002903 return 0;
2904}
2905
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002906static void intel_seq_print_mode(struct seq_file *m, int tabs,
2907 struct drm_display_mode *mode)
2908{
2909 int i;
2910
2911 for (i = 0; i < tabs; i++)
2912 seq_putc(m, '\t');
2913
2914 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",
2915 mode->base.id, mode->name,
2916 mode->vrefresh, mode->clock,
2917 mode->hdisplay, mode->hsync_start,
2918 mode->hsync_end, mode->htotal,
2919 mode->vdisplay, mode->vsync_start,
2920 mode->vsync_end, mode->vtotal,
2921 mode->type, mode->flags);
2922}
2923
2924static void intel_encoder_info(struct seq_file *m,
2925 struct intel_crtc *intel_crtc,
2926 struct intel_encoder *intel_encoder)
2927{
David Weinehall36cdd012016-08-22 13:59:31 +03002928 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2929 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002930 struct drm_crtc *crtc = &intel_crtc->base;
2931 struct intel_connector *intel_connector;
2932 struct drm_encoder *encoder;
2933
2934 encoder = &intel_encoder->base;
2935 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002936 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002937 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2938 struct drm_connector *connector = &intel_connector->base;
2939 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2940 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002941 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002942 drm_get_connector_status_name(connector->status));
2943 if (connector->status == connector_status_connected) {
2944 struct drm_display_mode *mode = &crtc->mode;
2945 seq_printf(m, ", mode:\n");
2946 intel_seq_print_mode(m, 2, mode);
2947 } else {
2948 seq_putc(m, '\n');
2949 }
2950 }
2951}
2952
2953static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2954{
David Weinehall36cdd012016-08-22 13:59:31 +03002955 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2956 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002957 struct drm_crtc *crtc = &intel_crtc->base;
2958 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002959 struct drm_plane_state *plane_state = crtc->primary->state;
2960 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002961
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002962 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002963 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002964 fb->base.id, plane_state->src_x >> 16,
2965 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002966 else
2967 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002968 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2969 intel_encoder_info(m, intel_crtc, intel_encoder);
2970}
2971
2972static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2973{
2974 struct drm_display_mode *mode = panel->fixed_mode;
2975
2976 seq_printf(m, "\tfixed mode:\n");
2977 intel_seq_print_mode(m, 2, mode);
2978}
2979
2980static void intel_dp_info(struct seq_file *m,
2981 struct intel_connector *intel_connector)
2982{
2983 struct intel_encoder *intel_encoder = intel_connector->encoder;
2984 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2985
2986 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002987 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002988 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002989 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002990
2991 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2992 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002993}
2994
Libin Yang9a148a92016-11-28 20:07:05 +08002995static void intel_dp_mst_info(struct seq_file *m,
2996 struct intel_connector *intel_connector)
2997{
2998 struct intel_encoder *intel_encoder = intel_connector->encoder;
2999 struct intel_dp_mst_encoder *intel_mst =
3000 enc_to_mst(&intel_encoder->base);
3001 struct intel_digital_port *intel_dig_port = intel_mst->primary;
3002 struct intel_dp *intel_dp = &intel_dig_port->dp;
3003 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
3004 intel_connector->port);
3005
3006 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
3007}
3008
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003009static void intel_hdmi_info(struct seq_file *m,
3010 struct intel_connector *intel_connector)
3011{
3012 struct intel_encoder *intel_encoder = intel_connector->encoder;
3013 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
3014
Jani Nikula742f4912015-09-03 11:16:09 +03003015 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003016}
3017
3018static void intel_lvds_info(struct seq_file *m,
3019 struct intel_connector *intel_connector)
3020{
3021 intel_panel_info(m, &intel_connector->panel);
3022}
3023
3024static void intel_connector_info(struct seq_file *m,
3025 struct drm_connector *connector)
3026{
3027 struct intel_connector *intel_connector = to_intel_connector(connector);
3028 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08003029 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003030
3031 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03003032 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003033 drm_get_connector_status_name(connector->status));
3034 if (connector->status == connector_status_connected) {
3035 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3036 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3037 connector->display_info.width_mm,
3038 connector->display_info.height_mm);
3039 seq_printf(m, "\tsubpixel order: %s\n",
3040 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3041 seq_printf(m, "\tCEA rev: %d\n",
3042 connector->display_info.cea_rev);
3043 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003044
Maarten Lankhorst77d1f612017-06-26 10:33:49 +02003045 if (!intel_encoder)
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003046 return;
3047
3048 switch (connector->connector_type) {
3049 case DRM_MODE_CONNECTOR_DisplayPort:
3050 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003051 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3052 intel_dp_mst_info(m, intel_connector);
3053 else
3054 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003055 break;
3056 case DRM_MODE_CONNECTOR_LVDS:
3057 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003058 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003059 break;
3060 case DRM_MODE_CONNECTOR_HDMIA:
3061 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3062 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3063 intel_hdmi_info(m, intel_connector);
3064 break;
3065 default:
3066 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003067 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003068
Jesse Barnesf103fc72014-02-20 12:39:57 -08003069 seq_printf(m, "\tmodes:\n");
3070 list_for_each_entry(mode, &connector->modes, head)
3071 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003072}
3073
Robert Fekete3abc4e02015-10-27 16:58:32 +01003074static const char *plane_type(enum drm_plane_type type)
3075{
3076 switch (type) {
3077 case DRM_PLANE_TYPE_OVERLAY:
3078 return "OVL";
3079 case DRM_PLANE_TYPE_PRIMARY:
3080 return "PRI";
3081 case DRM_PLANE_TYPE_CURSOR:
3082 return "CUR";
3083 /*
3084 * Deliberately omitting default: to generate compiler warnings
3085 * when a new drm_plane_type gets added.
3086 */
3087 }
3088
3089 return "unknown";
3090}
3091
3092static const char *plane_rotation(unsigned int rotation)
3093{
3094 static char buf[48];
3095 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003096 * According to doc only one DRM_MODE_ROTATE_ is allowed but this
Robert Fekete3abc4e02015-10-27 16:58:32 +01003097 * will print them all to visualize if the values are misused
3098 */
3099 snprintf(buf, sizeof(buf),
3100 "%s%s%s%s%s%s(0x%08x)",
Robert Fossc2c446a2017-05-19 16:50:17 -04003101 (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
3102 (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
3103 (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
3104 (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
3105 (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
3106 (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003107 rotation);
3108
3109 return buf;
3110}
3111
3112static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3113{
David Weinehall36cdd012016-08-22 13:59:31 +03003114 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3115 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003116 struct intel_plane *intel_plane;
3117
3118 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3119 struct drm_plane_state *state;
3120 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003121 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003122
3123 if (!plane->state) {
3124 seq_puts(m, "plane->state is NULL!\n");
3125 continue;
3126 }
3127
3128 state = plane->state;
3129
Eric Engestrom90844f02016-08-15 01:02:38 +01003130 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003131 drm_get_format_name(state->fb->format->format,
3132 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003133 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003134 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003135 }
3136
Robert Fekete3abc4e02015-10-27 16:58:32 +01003137 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",
3138 plane->base.id,
3139 plane_type(intel_plane->base.type),
3140 state->crtc_x, state->crtc_y,
3141 state->crtc_w, state->crtc_h,
3142 (state->src_x >> 16),
3143 ((state->src_x & 0xffff) * 15625) >> 10,
3144 (state->src_y >> 16),
3145 ((state->src_y & 0xffff) * 15625) >> 10,
3146 (state->src_w >> 16),
3147 ((state->src_w & 0xffff) * 15625) >> 10,
3148 (state->src_h >> 16),
3149 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003150 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003151 plane_rotation(state->rotation));
3152 }
3153}
3154
3155static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3156{
3157 struct intel_crtc_state *pipe_config;
3158 int num_scalers = intel_crtc->num_scalers;
3159 int i;
3160
3161 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3162
3163 /* Not all platformas have a scaler */
3164 if (num_scalers) {
3165 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3166 num_scalers,
3167 pipe_config->scaler_state.scaler_users,
3168 pipe_config->scaler_state.scaler_id);
3169
A.Sunil Kamath58415912016-11-20 23:20:26 +05303170 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003171 struct intel_scaler *sc =
3172 &pipe_config->scaler_state.scalers[i];
3173
3174 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3175 i, yesno(sc->in_use), sc->mode);
3176 }
3177 seq_puts(m, "\n");
3178 } else {
3179 seq_puts(m, "\tNo scalers available on this platform\n");
3180 }
3181}
3182
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003183static int i915_display_info(struct seq_file *m, void *unused)
3184{
David Weinehall36cdd012016-08-22 13:59:31 +03003185 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3186 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003187 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003188 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003189 struct drm_connector_list_iter conn_iter;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003190
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003191 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003192 seq_printf(m, "CRTC info\n");
3193 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003194 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003195 struct intel_crtc_state *pipe_config;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003196
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003197 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003198 pipe_config = to_intel_crtc_state(crtc->base.state);
3199
Robert Fekete3abc4e02015-10-27 16:58:32 +01003200 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003201 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003202 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003203 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3204 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3205
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003206 if (pipe_config->base.active) {
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003207 struct intel_plane *cursor =
3208 to_intel_plane(crtc->base.cursor);
3209
Chris Wilson065f2ec2014-03-12 09:13:13 +00003210 intel_crtc_info(m, crtc);
3211
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003212 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x\n",
3213 yesno(cursor->base.state->visible),
3214 cursor->base.state->crtc_x,
3215 cursor->base.state->crtc_y,
3216 cursor->base.state->crtc_w,
3217 cursor->base.state->crtc_h,
3218 cursor->cursor.base);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003219 intel_scaler_info(m, crtc);
3220 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003221 }
Daniel Vettercace8412014-05-22 17:56:31 +02003222
3223 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3224 yesno(!crtc->cpu_fifo_underrun_disabled),
3225 yesno(!crtc->pch_fifo_underrun_disabled));
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003226 drm_modeset_unlock(&crtc->base.mutex);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003227 }
3228
3229 seq_printf(m, "\n");
3230 seq_printf(m, "Connector info\n");
3231 seq_printf(m, "--------------\n");
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003232 mutex_lock(&dev->mode_config.mutex);
3233 drm_connector_list_iter_begin(dev, &conn_iter);
3234 drm_for_each_connector_iter(connector, &conn_iter)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003235 intel_connector_info(m, connector);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003236 drm_connector_list_iter_end(&conn_iter);
3237 mutex_unlock(&dev->mode_config.mutex);
3238
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003239 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003240
3241 return 0;
3242}
3243
Chris Wilson1b365952016-10-04 21:11:31 +01003244static int i915_engine_info(struct seq_file *m, void *unused)
3245{
3246 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michel Thierry061d06a2017-06-20 10:57:49 +01003247 struct i915_gpu_error *error = &dev_priv->gpu_error;
Chris Wilson1b365952016-10-04 21:11:31 +01003248 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303249 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003250
Chris Wilson9c870d02016-10-24 13:42:15 +01003251 intel_runtime_pm_get(dev_priv);
3252
Chris Wilsonf73b5672017-03-02 15:03:56 +00003253 seq_printf(m, "GT awake? %s\n",
3254 yesno(dev_priv->gt.awake));
3255 seq_printf(m, "Global active requests: %d\n",
3256 dev_priv->gt.active_requests);
3257
Akash Goel3b3f1652016-10-13 22:44:48 +05303258 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003259 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3260 struct drm_i915_gem_request *rq;
3261 struct rb_node *rb;
3262 u64 addr;
3263
3264 seq_printf(m, "%s\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003265 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003266 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003267 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003268 engine->hangcheck.seqno,
Chris Wilsonf73b5672017-03-02 15:03:56 +00003269 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp),
3270 engine->timeline->inflight_seqnos);
Michel Thierry061d06a2017-06-20 10:57:49 +01003271 seq_printf(m, "\tReset count: %d\n",
3272 i915_reset_engine_count(error, engine));
Chris Wilson1b365952016-10-04 21:11:31 +01003273
3274 rcu_read_lock();
3275
3276 seq_printf(m, "\tRequests:\n");
3277
Chris Wilson73cb9702016-10-28 13:58:46 +01003278 rq = list_first_entry(&engine->timeline->requests,
3279 struct drm_i915_gem_request, link);
3280 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003281 print_request(m, rq, "\t\tfirst ");
3282
Chris Wilson73cb9702016-10-28 13:58:46 +01003283 rq = list_last_entry(&engine->timeline->requests,
3284 struct drm_i915_gem_request, link);
3285 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003286 print_request(m, rq, "\t\tlast ");
3287
3288 rq = i915_gem_find_active_request(engine);
3289 if (rq) {
3290 print_request(m, rq, "\t\tactive ");
3291 seq_printf(m,
3292 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3293 rq->head, rq->postfix, rq->tail,
3294 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3295 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3296 }
3297
3298 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3299 I915_READ(RING_START(engine->mmio_base)),
3300 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3301 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3302 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3303 rq ? rq->ring->head : 0);
3304 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3305 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3306 rq ? rq->ring->tail : 0);
3307 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3308 I915_READ(RING_CTL(engine->mmio_base)),
3309 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3310
3311 rcu_read_unlock();
3312
3313 addr = intel_engine_get_active_head(engine);
3314 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3315 upper_32_bits(addr), lower_32_bits(addr));
3316 addr = intel_engine_get_last_batch_head(engine);
3317 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3318 upper_32_bits(addr), lower_32_bits(addr));
3319
3320 if (i915.enable_execlists) {
3321 u32 ptr, read, write;
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003322 unsigned int idx;
Chris Wilson1b365952016-10-04 21:11:31 +01003323
3324 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3325 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3326 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3327
3328 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3329 read = GEN8_CSB_READ_PTR(ptr);
3330 write = GEN8_CSB_WRITE_PTR(ptr);
Chris Wilson4d73da92017-07-21 13:32:19 +01003331 seq_printf(m, "\tExeclist CSB read %d, write %d, interrupt posted? %s\n",
3332 read, write,
3333 yesno(test_bit(ENGINE_IRQ_EXECLIST,
3334 &engine->irq_posted)));
Chris Wilson1b365952016-10-04 21:11:31 +01003335 if (read >= GEN8_CSB_ENTRIES)
3336 read = 0;
3337 if (write >= GEN8_CSB_ENTRIES)
3338 write = 0;
3339 if (read > write)
3340 write += GEN8_CSB_ENTRIES;
3341 while (read < write) {
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003342 idx = ++read % GEN8_CSB_ENTRIES;
Chris Wilson1b365952016-10-04 21:11:31 +01003343 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3344 idx,
3345 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3346 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3347 }
3348
3349 rcu_read_lock();
Chris Wilson77f0d0e2017-05-17 13:10:00 +01003350 for (idx = 0; idx < ARRAY_SIZE(engine->execlist_port); idx++) {
3351 unsigned int count;
3352
3353 rq = port_unpack(&engine->execlist_port[idx],
3354 &count);
3355 if (rq) {
3356 seq_printf(m, "\t\tELSP[%d] count=%d, ",
3357 idx, count);
3358 print_request(m, rq, "rq: ");
3359 } else {
3360 seq_printf(m, "\t\tELSP[%d] idle\n",
3361 idx);
3362 }
Chris Wilson816ee792017-01-24 11:00:03 +00003363 }
Chris Wilson1b365952016-10-04 21:11:31 +01003364 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003365
Chris Wilson663f71e2016-11-14 20:41:00 +00003366 spin_lock_irq(&engine->timeline->lock);
Chris Wilson6c067572017-05-17 13:10:03 +01003367 for (rb = engine->execlist_first; rb; rb = rb_next(rb)){
3368 struct i915_priolist *p =
3369 rb_entry(rb, typeof(*p), node);
3370
3371 list_for_each_entry(rq, &p->requests,
3372 priotree.link)
3373 print_request(m, rq, "\t\tQ ");
Chris Wilsonc8247c02016-10-27 01:03:43 +01003374 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003375 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003376 } else if (INTEL_GEN(dev_priv) > 6) {
3377 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3378 I915_READ(RING_PP_DIR_BASE(engine)));
3379 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3380 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3381 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3382 I915_READ(RING_PP_DIR_DCLV(engine)));
3383 }
3384
Chris Wilson61d3dc72017-03-03 19:08:24 +00003385 spin_lock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003386 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08003387 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson1b365952016-10-04 21:11:31 +01003388
3389 seq_printf(m, "\t%s [%d] waiting for %x\n",
3390 w->tsk->comm, w->tsk->pid, w->seqno);
3391 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00003392 spin_unlock_irq(&b->rb_lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003393
3394 seq_puts(m, "\n");
3395 }
3396
Chris Wilson9c870d02016-10-24 13:42:15 +01003397 intel_runtime_pm_put(dev_priv);
3398
Chris Wilson1b365952016-10-04 21:11:31 +01003399 return 0;
3400}
3401
Ben Widawskye04934c2014-06-30 09:53:42 -07003402static int i915_semaphore_status(struct seq_file *m, void *unused)
3403{
David Weinehall36cdd012016-08-22 13:59:31 +03003404 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3405 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003406 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003407 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003408 enum intel_engine_id id;
3409 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003410
Chris Wilson39df9192016-07-20 13:31:57 +01003411 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003412 seq_puts(m, "Semaphores are disabled\n");
3413 return 0;
3414 }
3415
3416 ret = mutex_lock_interruptible(&dev->struct_mutex);
3417 if (ret)
3418 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003419 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003420
David Weinehall36cdd012016-08-22 13:59:31 +03003421 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003422 struct page *page;
3423 uint64_t *seqno;
3424
Chris Wilson51d545d2016-08-15 10:49:02 +01003425 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003426
3427 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303428 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003429 uint64_t offset;
3430
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003431 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003432
3433 seq_puts(m, " Last signal:");
3434 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003435 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003436 seq_printf(m, "0x%08llx (0x%02llx) ",
3437 seqno[offset], offset * 8);
3438 }
3439 seq_putc(m, '\n');
3440
3441 seq_puts(m, " Last wait: ");
3442 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003443 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003444 seq_printf(m, "0x%08llx (0x%02llx) ",
3445 seqno[offset], offset * 8);
3446 }
3447 seq_putc(m, '\n');
3448
3449 }
3450 kunmap_atomic(seqno);
3451 } else {
3452 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303453 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003454 for (j = 0; j < num_rings; j++)
3455 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003456 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003457 seq_putc(m, '\n');
3458 }
3459
Paulo Zanoni03872062014-07-09 14:31:57 -03003460 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003461 mutex_unlock(&dev->struct_mutex);
3462 return 0;
3463}
3464
Daniel Vetter728e29d2014-06-25 22:01:53 +03003465static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3466{
David Weinehall36cdd012016-08-22 13:59:31 +03003467 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3468 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003469 int i;
3470
3471 drm_modeset_lock_all(dev);
3472 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3473 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3474
3475 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003476 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003477 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003478 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003479 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003480 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003481 pll->state.hw_state.dpll_md);
3482 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3483 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3484 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003485 }
3486 drm_modeset_unlock_all(dev);
3487
3488 return 0;
3489}
3490
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003491static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003492{
3493 int i;
3494 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003495 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003496 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3497 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003498 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003499 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003500
Arun Siluvery888b5992014-08-26 14:44:51 +01003501 ret = mutex_lock_interruptible(&dev->struct_mutex);
3502 if (ret)
3503 return ret;
3504
3505 intel_runtime_pm_get(dev_priv);
3506
Arun Siluvery33136b02016-01-21 21:43:47 +00003507 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303508 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003509 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003510 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003511 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003512 i915_reg_t addr;
3513 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003514 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003515
Arun Siluvery33136b02016-01-21 21:43:47 +00003516 addr = workarounds->reg[i].addr;
3517 mask = workarounds->reg[i].mask;
3518 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003519 read = I915_READ(addr);
3520 ok = (value & mask) == (read & mask);
3521 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 +02003522 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003523 }
3524
3525 intel_runtime_pm_put(dev_priv);
3526 mutex_unlock(&dev->struct_mutex);
3527
3528 return 0;
3529}
3530
Damien Lespiauc5511e42014-11-04 17:06:51 +00003531static int i915_ddb_info(struct seq_file *m, void *unused)
3532{
David Weinehall36cdd012016-08-22 13:59:31 +03003533 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3534 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003535 struct skl_ddb_allocation *ddb;
3536 struct skl_ddb_entry *entry;
3537 enum pipe pipe;
3538 int plane;
3539
David Weinehall36cdd012016-08-22 13:59:31 +03003540 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003541 return 0;
3542
Damien Lespiauc5511e42014-11-04 17:06:51 +00003543 drm_modeset_lock_all(dev);
3544
3545 ddb = &dev_priv->wm.skl_hw.ddb;
3546
3547 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3548
3549 for_each_pipe(dev_priv, pipe) {
3550 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3551
Matt Roper8b364b42016-10-26 15:51:28 -07003552 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003553 entry = &ddb->plane[pipe][plane];
3554 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3555 entry->start, entry->end,
3556 skl_ddb_entry_size(entry));
3557 }
3558
Matt Roper4969d332015-09-24 15:53:10 -07003559 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003560 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3561 entry->end, skl_ddb_entry_size(entry));
3562 }
3563
3564 drm_modeset_unlock_all(dev);
3565
3566 return 0;
3567}
3568
Vandana Kannana54746e2015-03-03 20:53:10 +05303569static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003570 struct drm_device *dev,
3571 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303572{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003573 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303574 struct i915_drrs *drrs = &dev_priv->drrs;
3575 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003576 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003577 struct drm_connector_list_iter conn_iter;
Vandana Kannana54746e2015-03-03 20:53:10 +05303578
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003579 drm_connector_list_iter_begin(dev, &conn_iter);
3580 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003581 if (connector->state->crtc != &intel_crtc->base)
3582 continue;
3583
3584 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303585 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003586 drm_connector_list_iter_end(&conn_iter);
Vandana Kannana54746e2015-03-03 20:53:10 +05303587
3588 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3589 seq_puts(m, "\tVBT: DRRS_type: Static");
3590 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3591 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3592 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3593 seq_puts(m, "\tVBT: DRRS_type: None");
3594 else
3595 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3596
3597 seq_puts(m, "\n\n");
3598
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003599 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303600 struct intel_panel *panel;
3601
3602 mutex_lock(&drrs->mutex);
3603 /* DRRS Supported */
3604 seq_puts(m, "\tDRRS Supported: Yes\n");
3605
3606 /* disable_drrs() will make drrs->dp NULL */
3607 if (!drrs->dp) {
3608 seq_puts(m, "Idleness DRRS: Disabled");
3609 mutex_unlock(&drrs->mutex);
3610 return;
3611 }
3612
3613 panel = &drrs->dp->attached_connector->panel;
3614 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3615 drrs->busy_frontbuffer_bits);
3616
3617 seq_puts(m, "\n\t\t");
3618 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3619 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3620 vrefresh = panel->fixed_mode->vrefresh;
3621 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3622 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3623 vrefresh = panel->downclock_mode->vrefresh;
3624 } else {
3625 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3626 drrs->refresh_rate_type);
3627 mutex_unlock(&drrs->mutex);
3628 return;
3629 }
3630 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3631
3632 seq_puts(m, "\n\t\t");
3633 mutex_unlock(&drrs->mutex);
3634 } else {
3635 /* DRRS not supported. Print the VBT parameter*/
3636 seq_puts(m, "\tDRRS Supported : No");
3637 }
3638 seq_puts(m, "\n");
3639}
3640
3641static int i915_drrs_status(struct seq_file *m, void *unused)
3642{
David Weinehall36cdd012016-08-22 13:59:31 +03003643 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3644 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303645 struct intel_crtc *intel_crtc;
3646 int active_crtc_cnt = 0;
3647
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003648 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303649 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003650 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303651 active_crtc_cnt++;
3652 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3653
3654 drrs_status_per_crtc(m, dev, intel_crtc);
3655 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303656 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003657 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303658
3659 if (!active_crtc_cnt)
3660 seq_puts(m, "No active crtc found\n");
3661
3662 return 0;
3663}
3664
Dave Airlie11bed952014-05-12 15:22:27 +10003665static int i915_dp_mst_info(struct seq_file *m, void *unused)
3666{
David Weinehall36cdd012016-08-22 13:59:31 +03003667 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3668 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003669 struct intel_encoder *intel_encoder;
3670 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003671 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003672 struct drm_connector_list_iter conn_iter;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003673
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003674 drm_connector_list_iter_begin(dev, &conn_iter);
3675 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003676 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003677 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003678
3679 intel_encoder = intel_attached_encoder(connector);
3680 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3681 continue;
3682
3683 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003684 if (!intel_dig_port->dp.can_mst)
3685 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003686
Jim Bride40ae80c2016-04-14 10:18:37 -07003687 seq_printf(m, "MST Source Port %c\n",
3688 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003689 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3690 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003691 drm_connector_list_iter_end(&conn_iter);
3692
Dave Airlie11bed952014-05-12 15:22:27 +10003693 return 0;
3694}
3695
Todd Previteeb3394fa2015-04-18 00:04:19 -07003696static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003697 const char __user *ubuf,
3698 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003699{
3700 char *input_buffer;
3701 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003702 struct drm_device *dev;
3703 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003704 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003705 struct intel_dp *intel_dp;
3706 int val = 0;
3707
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303708 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003709
Todd Previteeb3394fa2015-04-18 00:04:19 -07003710 if (len == 0)
3711 return 0;
3712
Geliang Tang261aeba2017-05-06 23:40:17 +08003713 input_buffer = memdup_user_nul(ubuf, len);
3714 if (IS_ERR(input_buffer))
3715 return PTR_ERR(input_buffer);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003716
Todd Previteeb3394fa2015-04-18 00:04:19 -07003717 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3718
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003719 drm_connector_list_iter_begin(dev, &conn_iter);
3720 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003721 struct intel_encoder *encoder;
3722
Todd Previteeb3394fa2015-04-18 00:04:19 -07003723 if (connector->connector_type !=
3724 DRM_MODE_CONNECTOR_DisplayPort)
3725 continue;
3726
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003727 encoder = to_intel_encoder(connector->encoder);
3728 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3729 continue;
3730
3731 if (encoder && connector->status == connector_status_connected) {
3732 intel_dp = enc_to_intel_dp(&encoder->base);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003733 status = kstrtoint(input_buffer, 10, &val);
3734 if (status < 0)
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003735 break;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003736 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3737 /* To prevent erroneous activation of the compliance
3738 * testing code, only accept an actual value of 1 here
3739 */
3740 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003741 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003742 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003743 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003744 }
3745 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003746 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003747 kfree(input_buffer);
3748 if (status < 0)
3749 return status;
3750
3751 *offp += len;
3752 return len;
3753}
3754
3755static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3756{
3757 struct drm_device *dev = m->private;
3758 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003759 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003760 struct intel_dp *intel_dp;
3761
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003762 drm_connector_list_iter_begin(dev, &conn_iter);
3763 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003764 struct intel_encoder *encoder;
3765
Todd Previteeb3394fa2015-04-18 00:04:19 -07003766 if (connector->connector_type !=
3767 DRM_MODE_CONNECTOR_DisplayPort)
3768 continue;
3769
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003770 encoder = to_intel_encoder(connector->encoder);
3771 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3772 continue;
3773
3774 if (encoder && connector->status == connector_status_connected) {
3775 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003776 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003777 seq_puts(m, "1");
3778 else
3779 seq_puts(m, "0");
3780 } else
3781 seq_puts(m, "0");
3782 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003783 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003784
3785 return 0;
3786}
3787
3788static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003789 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003790{
David Weinehall36cdd012016-08-22 13:59:31 +03003791 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003792
David Weinehall36cdd012016-08-22 13:59:31 +03003793 return single_open(file, i915_displayport_test_active_show,
3794 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003795}
3796
3797static const struct file_operations i915_displayport_test_active_fops = {
3798 .owner = THIS_MODULE,
3799 .open = i915_displayport_test_active_open,
3800 .read = seq_read,
3801 .llseek = seq_lseek,
3802 .release = single_release,
3803 .write = i915_displayport_test_active_write
3804};
3805
3806static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3807{
3808 struct drm_device *dev = m->private;
3809 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003810 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003811 struct intel_dp *intel_dp;
3812
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003813 drm_connector_list_iter_begin(dev, &conn_iter);
3814 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003815 struct intel_encoder *encoder;
3816
Todd Previteeb3394fa2015-04-18 00:04:19 -07003817 if (connector->connector_type !=
3818 DRM_MODE_CONNECTOR_DisplayPort)
3819 continue;
3820
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003821 encoder = to_intel_encoder(connector->encoder);
3822 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3823 continue;
3824
3825 if (encoder && connector->status == connector_status_connected) {
3826 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003827 if (intel_dp->compliance.test_type ==
3828 DP_TEST_LINK_EDID_READ)
3829 seq_printf(m, "%lx",
3830 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003831 else if (intel_dp->compliance.test_type ==
3832 DP_TEST_LINK_VIDEO_PATTERN) {
3833 seq_printf(m, "hdisplay: %d\n",
3834 intel_dp->compliance.test_data.hdisplay);
3835 seq_printf(m, "vdisplay: %d\n",
3836 intel_dp->compliance.test_data.vdisplay);
3837 seq_printf(m, "bpc: %u\n",
3838 intel_dp->compliance.test_data.bpc);
3839 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003840 } else
3841 seq_puts(m, "0");
3842 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003843 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003844
3845 return 0;
3846}
3847static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003848 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003849{
David Weinehall36cdd012016-08-22 13:59:31 +03003850 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003851
David Weinehall36cdd012016-08-22 13:59:31 +03003852 return single_open(file, i915_displayport_test_data_show,
3853 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003854}
3855
3856static const struct file_operations i915_displayport_test_data_fops = {
3857 .owner = THIS_MODULE,
3858 .open = i915_displayport_test_data_open,
3859 .read = seq_read,
3860 .llseek = seq_lseek,
3861 .release = single_release
3862};
3863
3864static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3865{
3866 struct drm_device *dev = m->private;
3867 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003868 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003869 struct intel_dp *intel_dp;
3870
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003871 drm_connector_list_iter_begin(dev, &conn_iter);
3872 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003873 struct intel_encoder *encoder;
3874
Todd Previteeb3394fa2015-04-18 00:04:19 -07003875 if (connector->connector_type !=
3876 DRM_MODE_CONNECTOR_DisplayPort)
3877 continue;
3878
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003879 encoder = to_intel_encoder(connector->encoder);
3880 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3881 continue;
3882
3883 if (encoder && connector->status == connector_status_connected) {
3884 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003885 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003886 } else
3887 seq_puts(m, "0");
3888 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003889 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003890
3891 return 0;
3892}
3893
3894static int i915_displayport_test_type_open(struct inode *inode,
3895 struct file *file)
3896{
David Weinehall36cdd012016-08-22 13:59:31 +03003897 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003898
David Weinehall36cdd012016-08-22 13:59:31 +03003899 return single_open(file, i915_displayport_test_type_show,
3900 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003901}
3902
3903static const struct file_operations i915_displayport_test_type_fops = {
3904 .owner = THIS_MODULE,
3905 .open = i915_displayport_test_type_open,
3906 .read = seq_read,
3907 .llseek = seq_lseek,
3908 .release = single_release
3909};
3910
Damien Lespiau97e94b22014-11-04 17:06:50 +00003911static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003912{
David Weinehall36cdd012016-08-22 13:59:31 +03003913 struct drm_i915_private *dev_priv = m->private;
3914 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003915 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003916 int num_levels;
3917
David Weinehall36cdd012016-08-22 13:59:31 +03003918 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003919 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003920 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003921 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003922 else if (IS_G4X(dev_priv))
3923 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003924 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003925 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003926
3927 drm_modeset_lock_all(dev);
3928
3929 for (level = 0; level < num_levels; level++) {
3930 unsigned int latency = wm[level];
3931
Damien Lespiau97e94b22014-11-04 17:06:50 +00003932 /*
3933 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003934 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003935 */
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003936 if (INTEL_GEN(dev_priv) >= 9 ||
3937 IS_VALLEYVIEW(dev_priv) ||
3938 IS_CHERRYVIEW(dev_priv) ||
3939 IS_G4X(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003940 latency *= 10;
3941 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003942 latency *= 5;
3943
3944 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003945 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003946 }
3947
3948 drm_modeset_unlock_all(dev);
3949}
3950
3951static int pri_wm_latency_show(struct seq_file *m, void *data)
3952{
David Weinehall36cdd012016-08-22 13:59:31 +03003953 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003954 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003955
David Weinehall36cdd012016-08-22 13:59:31 +03003956 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003957 latencies = dev_priv->wm.skl_latency;
3958 else
David Weinehall36cdd012016-08-22 13:59:31 +03003959 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003960
3961 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003962
3963 return 0;
3964}
3965
3966static int spr_wm_latency_show(struct seq_file *m, void *data)
3967{
David Weinehall36cdd012016-08-22 13:59:31 +03003968 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003969 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003970
David Weinehall36cdd012016-08-22 13:59:31 +03003971 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003972 latencies = dev_priv->wm.skl_latency;
3973 else
David Weinehall36cdd012016-08-22 13:59:31 +03003974 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003975
3976 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003977
3978 return 0;
3979}
3980
3981static int cur_wm_latency_show(struct seq_file *m, void *data)
3982{
David Weinehall36cdd012016-08-22 13:59:31 +03003983 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003984 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003985
David Weinehall36cdd012016-08-22 13:59:31 +03003986 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003987 latencies = dev_priv->wm.skl_latency;
3988 else
David Weinehall36cdd012016-08-22 13:59:31 +03003989 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003990
3991 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003992
3993 return 0;
3994}
3995
3996static int pri_wm_latency_open(struct inode *inode, struct file *file)
3997{
David Weinehall36cdd012016-08-22 13:59:31 +03003998 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003999
Ville Syrjälä04548cb2017-04-21 21:14:29 +03004000 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004001 return -ENODEV;
4002
David Weinehall36cdd012016-08-22 13:59:31 +03004003 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004004}
4005
4006static int spr_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
David Weinehall36cdd012016-08-22 13:59:31 +03004010 if (HAS_GMCH_DISPLAY(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, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004014}
4015
4016static int cur_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, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004024}
4025
4026static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004027 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004028{
4029 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004030 struct drm_i915_private *dev_priv = m->private;
4031 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004032 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004033 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004034 int level;
4035 int ret;
4036 char tmp[32];
4037
David Weinehall36cdd012016-08-22 13:59:31 +03004038 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004039 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004040 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004041 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03004042 else if (IS_G4X(dev_priv))
4043 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004044 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004045 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004046
Ville Syrjälä369a1342014-01-22 14:36:08 +02004047 if (len >= sizeof(tmp))
4048 return -EINVAL;
4049
4050 if (copy_from_user(tmp, ubuf, len))
4051 return -EFAULT;
4052
4053 tmp[len] = '\0';
4054
Damien Lespiau97e94b22014-11-04 17:06:50 +00004055 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4056 &new[0], &new[1], &new[2], &new[3],
4057 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004058 if (ret != num_levels)
4059 return -EINVAL;
4060
4061 drm_modeset_lock_all(dev);
4062
4063 for (level = 0; level < num_levels; level++)
4064 wm[level] = new[level];
4065
4066 drm_modeset_unlock_all(dev);
4067
4068 return len;
4069}
4070
4071
4072static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4073 size_t len, loff_t *offp)
4074{
4075 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004076 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004077 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004078
David Weinehall36cdd012016-08-22 13:59:31 +03004079 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004080 latencies = dev_priv->wm.skl_latency;
4081 else
David Weinehall36cdd012016-08-22 13:59:31 +03004082 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004083
4084 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004085}
4086
4087static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4088 size_t len, loff_t *offp)
4089{
4090 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004091 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004092 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004093
David Weinehall36cdd012016-08-22 13:59:31 +03004094 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004095 latencies = dev_priv->wm.skl_latency;
4096 else
David Weinehall36cdd012016-08-22 13:59:31 +03004097 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004098
4099 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004100}
4101
4102static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4103 size_t len, loff_t *offp)
4104{
4105 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004106 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004107 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004108
David Weinehall36cdd012016-08-22 13:59:31 +03004109 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004110 latencies = dev_priv->wm.skl_latency;
4111 else
David Weinehall36cdd012016-08-22 13:59:31 +03004112 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004113
4114 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004115}
4116
4117static const struct file_operations i915_pri_wm_latency_fops = {
4118 .owner = THIS_MODULE,
4119 .open = pri_wm_latency_open,
4120 .read = seq_read,
4121 .llseek = seq_lseek,
4122 .release = single_release,
4123 .write = pri_wm_latency_write
4124};
4125
4126static const struct file_operations i915_spr_wm_latency_fops = {
4127 .owner = THIS_MODULE,
4128 .open = spr_wm_latency_open,
4129 .read = seq_read,
4130 .llseek = seq_lseek,
4131 .release = single_release,
4132 .write = spr_wm_latency_write
4133};
4134
4135static const struct file_operations i915_cur_wm_latency_fops = {
4136 .owner = THIS_MODULE,
4137 .open = cur_wm_latency_open,
4138 .read = seq_read,
4139 .llseek = seq_lseek,
4140 .release = single_release,
4141 .write = cur_wm_latency_write
4142};
4143
Kees Cook647416f2013-03-10 14:10:06 -07004144static int
4145i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004146{
David Weinehall36cdd012016-08-22 13:59:31 +03004147 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004148
Chris Wilsond98c52c2016-04-13 17:35:05 +01004149 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004150
Kees Cook647416f2013-03-10 14:10:06 -07004151 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004152}
4153
Kees Cook647416f2013-03-10 14:10:06 -07004154static int
4155i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004156{
Chris Wilson598b6b52017-03-25 13:47:35 +00004157 struct drm_i915_private *i915 = data;
4158 struct intel_engine_cs *engine;
4159 unsigned int tmp;
Imre Deakd46c0512014-04-14 20:24:27 +03004160
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004161 /*
4162 * There is no safeguard against this debugfs entry colliding
4163 * with the hangcheck calling same i915_handle_error() in
4164 * parallel, causing an explosion. For now we assume that the
4165 * test harness is responsible enough not to inject gpu hangs
4166 * while it is writing to 'i915_wedged'
4167 */
4168
Chris Wilson598b6b52017-03-25 13:47:35 +00004169 if (i915_reset_backoff(&i915->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004170 return -EAGAIN;
4171
Chris Wilson598b6b52017-03-25 13:47:35 +00004172 for_each_engine_masked(engine, i915, val, tmp) {
4173 engine->hangcheck.seqno = intel_engine_get_seqno(engine);
4174 engine->hangcheck.stalled = true;
4175 }
Imre Deakd46c0512014-04-14 20:24:27 +03004176
Chris Wilson598b6b52017-03-25 13:47:35 +00004177 i915_handle_error(i915, val, "Manually setting wedged to %llu", val);
4178
4179 wait_on_bit(&i915->gpu_error.flags,
Chris Wilsond3df42b2017-03-16 17:13:05 +00004180 I915_RESET_HANDOFF,
4181 TASK_UNINTERRUPTIBLE);
4182
Kees Cook647416f2013-03-10 14:10:06 -07004183 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004184}
4185
Kees Cook647416f2013-03-10 14:10:06 -07004186DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4187 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004188 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004189
Kees Cook647416f2013-03-10 14:10:06 -07004190static int
Chris Wilson64486ae2017-03-07 15:59:08 +00004191fault_irq_set(struct drm_i915_private *i915,
4192 unsigned long *irq,
4193 unsigned long val)
4194{
4195 int err;
4196
4197 err = mutex_lock_interruptible(&i915->drm.struct_mutex);
4198 if (err)
4199 return err;
4200
4201 err = i915_gem_wait_for_idle(i915,
4202 I915_WAIT_LOCKED |
4203 I915_WAIT_INTERRUPTIBLE);
4204 if (err)
4205 goto err_unlock;
4206
Chris Wilson64486ae2017-03-07 15:59:08 +00004207 *irq = val;
4208 mutex_unlock(&i915->drm.struct_mutex);
4209
4210 /* Flush idle worker to disarm irq */
4211 while (flush_delayed_work(&i915->gt.idle_work))
4212 ;
4213
4214 return 0;
4215
4216err_unlock:
4217 mutex_unlock(&i915->drm.struct_mutex);
4218 return err;
4219}
4220
4221static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004222i915_ring_missed_irq_get(void *data, u64 *val)
4223{
David Weinehall36cdd012016-08-22 13:59:31 +03004224 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004225
4226 *val = dev_priv->gpu_error.missed_irq_rings;
4227 return 0;
4228}
4229
4230static int
4231i915_ring_missed_irq_set(void *data, u64 val)
4232{
Chris Wilson64486ae2017-03-07 15:59:08 +00004233 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004234
Chris Wilson64486ae2017-03-07 15:59:08 +00004235 return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004236}
4237
4238DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4239 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4240 "0x%08llx\n");
4241
4242static int
4243i915_ring_test_irq_get(void *data, u64 *val)
4244{
David Weinehall36cdd012016-08-22 13:59:31 +03004245 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004246
4247 *val = dev_priv->gpu_error.test_irq_rings;
4248
4249 return 0;
4250}
4251
4252static int
4253i915_ring_test_irq_set(void *data, u64 val)
4254{
Chris Wilson64486ae2017-03-07 15:59:08 +00004255 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004256
Chris Wilson64486ae2017-03-07 15:59:08 +00004257 val &= INTEL_INFO(i915)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004258 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004259
Chris Wilson64486ae2017-03-07 15:59:08 +00004260 return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004261}
4262
4263DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4264 i915_ring_test_irq_get, i915_ring_test_irq_set,
4265 "0x%08llx\n");
4266
Chris Wilsondd624af2013-01-15 12:39:35 +00004267#define DROP_UNBOUND 0x1
4268#define DROP_BOUND 0x2
4269#define DROP_RETIRE 0x4
4270#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004271#define DROP_FREED 0x10
Chris Wilson8eadc192017-03-08 14:46:22 +00004272#define DROP_SHRINK_ALL 0x20
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004273#define DROP_ALL (DROP_UNBOUND | \
4274 DROP_BOUND | \
4275 DROP_RETIRE | \
4276 DROP_ACTIVE | \
Chris Wilson8eadc192017-03-08 14:46:22 +00004277 DROP_FREED | \
4278 DROP_SHRINK_ALL)
Kees Cook647416f2013-03-10 14:10:06 -07004279static int
4280i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004281{
Kees Cook647416f2013-03-10 14:10:06 -07004282 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004283
Kees Cook647416f2013-03-10 14:10:06 -07004284 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004285}
4286
Kees Cook647416f2013-03-10 14:10:06 -07004287static int
4288i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004289{
David Weinehall36cdd012016-08-22 13:59:31 +03004290 struct drm_i915_private *dev_priv = data;
4291 struct drm_device *dev = &dev_priv->drm;
Chris Wilson00c26cf2017-05-24 17:26:53 +01004292 int ret = 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004293
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004294 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004295
4296 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4297 * on ioctls on -EAGAIN. */
Chris Wilson00c26cf2017-05-24 17:26:53 +01004298 if (val & (DROP_ACTIVE | DROP_RETIRE)) {
4299 ret = mutex_lock_interruptible(&dev->struct_mutex);
Chris Wilsondd624af2013-01-15 12:39:35 +00004300 if (ret)
Chris Wilson00c26cf2017-05-24 17:26:53 +01004301 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004302
Chris Wilson00c26cf2017-05-24 17:26:53 +01004303 if (val & DROP_ACTIVE)
4304 ret = i915_gem_wait_for_idle(dev_priv,
4305 I915_WAIT_INTERRUPTIBLE |
4306 I915_WAIT_LOCKED);
4307
4308 if (val & DROP_RETIRE)
4309 i915_gem_retire_requests(dev_priv);
4310
4311 mutex_unlock(&dev->struct_mutex);
4312 }
Chris Wilsondd624af2013-01-15 12:39:35 +00004313
Daniel Vetter05df49e2017-03-12 21:53:40 +01004314 lockdep_set_current_reclaim_state(GFP_KERNEL);
Chris Wilson21ab4e72014-09-09 11:16:08 +01004315 if (val & DROP_BOUND)
4316 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004317
Chris Wilson21ab4e72014-09-09 11:16:08 +01004318 if (val & DROP_UNBOUND)
4319 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004320
Chris Wilson8eadc192017-03-08 14:46:22 +00004321 if (val & DROP_SHRINK_ALL)
4322 i915_gem_shrink_all(dev_priv);
Daniel Vetter05df49e2017-03-12 21:53:40 +01004323 lockdep_clear_current_reclaim_state();
Chris Wilson8eadc192017-03-08 14:46:22 +00004324
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004325 if (val & DROP_FREED) {
4326 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004327 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004328 }
4329
Kees Cook647416f2013-03-10 14:10:06 -07004330 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004331}
4332
Kees Cook647416f2013-03-10 14:10:06 -07004333DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4334 i915_drop_caches_get, i915_drop_caches_set,
4335 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004336
Kees Cook647416f2013-03-10 14:10:06 -07004337static int
4338i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004339{
David Weinehall36cdd012016-08-22 13:59:31 +03004340 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004341
David Weinehall36cdd012016-08-22 13:59:31 +03004342 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004343 return -ENODEV;
4344
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004345 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004346 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004347}
4348
Kees Cook647416f2013-03-10 14:10:06 -07004349static int
4350i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004351{
David Weinehall36cdd012016-08-22 13:59:31 +03004352 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304353 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004354 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004355
David Weinehall36cdd012016-08-22 13:59:31 +03004356 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004357 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004358
Kees Cook647416f2013-03-10 14:10:06 -07004359 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004360
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004361 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004362 if (ret)
4363 return ret;
4364
Jesse Barnes358733e2011-07-27 11:53:01 -07004365 /*
4366 * Turbo will still be enabled, but won't go above the set value.
4367 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304368 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004369
Akash Goelbc4d91f2015-02-26 16:09:47 +05304370 hw_max = dev_priv->rps.max_freq;
4371 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004372
Ben Widawskyb39fb292014-03-19 18:31:11 -07004373 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004374 mutex_unlock(&dev_priv->rps.hw_lock);
4375 return -EINVAL;
4376 }
4377
Ben Widawskyb39fb292014-03-19 18:31:11 -07004378 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004379
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004380 if (intel_set_rps(dev_priv, val))
4381 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004382
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004383 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004384
Kees Cook647416f2013-03-10 14:10:06 -07004385 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004386}
4387
Kees Cook647416f2013-03-10 14:10:06 -07004388DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4389 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004390 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004391
Kees Cook647416f2013-03-10 14:10:06 -07004392static int
4393i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004394{
David Weinehall36cdd012016-08-22 13:59:31 +03004395 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004396
Chris Wilson62e1baa2016-07-13 09:10:36 +01004397 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004398 return -ENODEV;
4399
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004400 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004401 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004402}
4403
Kees Cook647416f2013-03-10 14:10:06 -07004404static int
4405i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004406{
David Weinehall36cdd012016-08-22 13:59:31 +03004407 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304408 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004409 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004410
Chris Wilson62e1baa2016-07-13 09:10:36 +01004411 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004412 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004413
Kees Cook647416f2013-03-10 14:10:06 -07004414 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004415
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004416 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004417 if (ret)
4418 return ret;
4419
Jesse Barnes1523c312012-05-25 12:34:54 -07004420 /*
4421 * Turbo will still be enabled, but won't go below the set value.
4422 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304423 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004424
Akash Goelbc4d91f2015-02-26 16:09:47 +05304425 hw_max = dev_priv->rps.max_freq;
4426 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004427
David Weinehall36cdd012016-08-22 13:59:31 +03004428 if (val < hw_min ||
4429 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004430 mutex_unlock(&dev_priv->rps.hw_lock);
4431 return -EINVAL;
4432 }
4433
Ben Widawskyb39fb292014-03-19 18:31:11 -07004434 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004435
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004436 if (intel_set_rps(dev_priv, val))
4437 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004438
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004439 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004440
Kees Cook647416f2013-03-10 14:10:06 -07004441 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004442}
4443
Kees Cook647416f2013-03-10 14:10:06 -07004444DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4445 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004446 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004447
Kees Cook647416f2013-03-10 14:10:06 -07004448static int
4449i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004450{
David Weinehall36cdd012016-08-22 13:59:31 +03004451 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004452 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004453
David Weinehall36cdd012016-08-22 13:59:31 +03004454 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004455 return -ENODEV;
4456
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004457 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004458
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004459 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004460
4461 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004462
Kees Cook647416f2013-03-10 14:10:06 -07004463 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004464
Kees Cook647416f2013-03-10 14:10:06 -07004465 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004466}
4467
Kees Cook647416f2013-03-10 14:10:06 -07004468static int
4469i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004470{
David Weinehall36cdd012016-08-22 13:59:31 +03004471 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004472 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004473
David Weinehall36cdd012016-08-22 13:59:31 +03004474 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004475 return -ENODEV;
4476
Kees Cook647416f2013-03-10 14:10:06 -07004477 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004478 return -EINVAL;
4479
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004480 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004481 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004482
4483 /* Update the cache sharing policy here as well */
4484 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4485 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4486 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4487 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4488
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004489 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004490 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004491}
4492
Kees Cook647416f2013-03-10 14:10:06 -07004493DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4494 i915_cache_sharing_get, i915_cache_sharing_set,
4495 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004496
David Weinehall36cdd012016-08-22 13:59:31 +03004497static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004498 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004499{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004500 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004501 int ss;
4502 u32 sig1[ss_max], sig2[ss_max];
4503
4504 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4505 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4506 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4507 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4508
4509 for (ss = 0; ss < ss_max; ss++) {
4510 unsigned int eu_cnt;
4511
4512 if (sig1[ss] & CHV_SS_PG_ENABLE)
4513 /* skip disabled subslice */
4514 continue;
4515
Imre Deakf08a0c92016-08-31 19:13:04 +03004516 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004517 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004518 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4519 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4520 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4521 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004522 sseu->eu_total += eu_cnt;
4523 sseu->eu_per_subslice = max_t(unsigned int,
4524 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004525 }
Jeff McGee5d395252015-04-03 18:13:17 -07004526}
4527
David Weinehall36cdd012016-08-22 13:59:31 +03004528static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004529 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004530{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004531 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004532 int s, ss;
4533 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4534
Jeff McGee1c046bc2015-04-03 18:13:18 -07004535 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004536 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004537 s_max = 1;
4538 ss_max = 3;
4539 }
4540
4541 for (s = 0; s < s_max; s++) {
4542 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4543 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4544 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4545 }
4546
Jeff McGee5d395252015-04-03 18:13:17 -07004547 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4548 GEN9_PGCTL_SSA_EU19_ACK |
4549 GEN9_PGCTL_SSA_EU210_ACK |
4550 GEN9_PGCTL_SSA_EU311_ACK;
4551 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4552 GEN9_PGCTL_SSB_EU19_ACK |
4553 GEN9_PGCTL_SSB_EU210_ACK |
4554 GEN9_PGCTL_SSB_EU311_ACK;
4555
4556 for (s = 0; s < s_max; s++) {
4557 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4558 /* skip disabled slice */
4559 continue;
4560
Imre Deakf08a0c92016-08-31 19:13:04 +03004561 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004562
Rodrigo Vivi7ea1adf2017-08-09 13:07:02 -07004563 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004564 sseu->subslice_mask =
4565 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004566
Jeff McGee5d395252015-04-03 18:13:17 -07004567 for (ss = 0; ss < ss_max; ss++) {
4568 unsigned int eu_cnt;
4569
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004570 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004571 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4572 /* skip disabled subslice */
4573 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004574
Imre Deak57ec1712016-08-31 19:13:05 +03004575 sseu->subslice_mask |= BIT(ss);
4576 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004577
Jeff McGee5d395252015-04-03 18:13:17 -07004578 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4579 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004580 sseu->eu_total += eu_cnt;
4581 sseu->eu_per_subslice = max_t(unsigned int,
4582 sseu->eu_per_subslice,
4583 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004584 }
4585 }
4586}
4587
David Weinehall36cdd012016-08-22 13:59:31 +03004588static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004589 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004590{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004591 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004592 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004593
Imre Deakf08a0c92016-08-31 19:13:04 +03004594 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004595
Imre Deakf08a0c92016-08-31 19:13:04 +03004596 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004597 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004598 sseu->eu_per_subslice =
4599 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004600 sseu->eu_total = sseu->eu_per_subslice *
4601 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004602
4603 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004604 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004605 u8 subslice_7eu =
4606 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004607
Imre Deak915490d2016-08-31 19:13:01 +03004608 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004609 }
4610 }
4611}
4612
Imre Deak615d8902016-08-31 19:13:03 +03004613static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4614 const struct sseu_dev_info *sseu)
4615{
4616 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4617 const char *type = is_available_info ? "Available" : "Enabled";
4618
Imre Deakc67ba532016-08-31 19:13:06 +03004619 seq_printf(m, " %s Slice Mask: %04x\n", type,
4620 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004621 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004622 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004623 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004624 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004625 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4626 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004627 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004628 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004629 seq_printf(m, " %s EU Total: %u\n", type,
4630 sseu->eu_total);
4631 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4632 sseu->eu_per_subslice);
4633
4634 if (!is_available_info)
4635 return;
4636
4637 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4638 if (HAS_POOLED_EU(dev_priv))
4639 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4640
4641 seq_printf(m, " Has Slice Power Gating: %s\n",
4642 yesno(sseu->has_slice_pg));
4643 seq_printf(m, " Has Subslice Power Gating: %s\n",
4644 yesno(sseu->has_subslice_pg));
4645 seq_printf(m, " Has EU Power Gating: %s\n",
4646 yesno(sseu->has_eu_pg));
4647}
4648
Jeff McGee38732182015-02-13 10:27:54 -06004649static int i915_sseu_status(struct seq_file *m, void *unused)
4650{
David Weinehall36cdd012016-08-22 13:59:31 +03004651 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004652 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004653
David Weinehall36cdd012016-08-22 13:59:31 +03004654 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004655 return -ENODEV;
4656
4657 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004658 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004659
Jeff McGee7f992ab2015-02-13 10:27:55 -06004660 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004661 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004662
4663 intel_runtime_pm_get(dev_priv);
4664
David Weinehall36cdd012016-08-22 13:59:31 +03004665 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004666 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004667 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004668 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004669 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004670 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004671 }
David Weinehall238010e2016-08-01 17:33:27 +03004672
4673 intel_runtime_pm_put(dev_priv);
4674
Imre Deak615d8902016-08-31 19:13:03 +03004675 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004676
Jeff McGee38732182015-02-13 10:27:54 -06004677 return 0;
4678}
4679
Ben Widawsky6d794d42011-04-25 11:25:56 -07004680static int i915_forcewake_open(struct inode *inode, struct file *file)
4681{
David Weinehall36cdd012016-08-22 13:59:31 +03004682 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004683
David Weinehall36cdd012016-08-22 13:59:31 +03004684 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004685 return 0;
4686
Chris Wilson6daccb02015-01-16 11:34:35 +02004687 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004688 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004689
4690 return 0;
4691}
4692
Ben Widawskyc43b5632012-04-16 14:07:40 -07004693static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004694{
David Weinehall36cdd012016-08-22 13:59:31 +03004695 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004696
David Weinehall36cdd012016-08-22 13:59:31 +03004697 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004698 return 0;
4699
Mika Kuoppala59bad942015-01-16 11:34:40 +02004700 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004701 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004702
4703 return 0;
4704}
4705
4706static const struct file_operations i915_forcewake_fops = {
4707 .owner = THIS_MODULE,
4708 .open = i915_forcewake_open,
4709 .release = i915_forcewake_release,
4710};
4711
Lyude317eaa92017-02-03 21:18:25 -05004712static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4713{
4714 struct drm_i915_private *dev_priv = m->private;
4715 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4716
4717 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4718 seq_printf(m, "Detected: %s\n",
4719 yesno(delayed_work_pending(&hotplug->reenable_work)));
4720
4721 return 0;
4722}
4723
4724static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4725 const char __user *ubuf, size_t len,
4726 loff_t *offp)
4727{
4728 struct seq_file *m = file->private_data;
4729 struct drm_i915_private *dev_priv = m->private;
4730 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4731 unsigned int new_threshold;
4732 int i;
4733 char *newline;
4734 char tmp[16];
4735
4736 if (len >= sizeof(tmp))
4737 return -EINVAL;
4738
4739 if (copy_from_user(tmp, ubuf, len))
4740 return -EFAULT;
4741
4742 tmp[len] = '\0';
4743
4744 /* Strip newline, if any */
4745 newline = strchr(tmp, '\n');
4746 if (newline)
4747 *newline = '\0';
4748
4749 if (strcmp(tmp, "reset") == 0)
4750 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4751 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4752 return -EINVAL;
4753
4754 if (new_threshold > 0)
4755 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4756 new_threshold);
4757 else
4758 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4759
4760 spin_lock_irq(&dev_priv->irq_lock);
4761 hotplug->hpd_storm_threshold = new_threshold;
4762 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4763 for_each_hpd_pin(i)
4764 hotplug->stats[i].count = 0;
4765 spin_unlock_irq(&dev_priv->irq_lock);
4766
4767 /* Re-enable hpd immediately if we were in an irq storm */
4768 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4769
4770 return len;
4771}
4772
4773static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4774{
4775 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4776}
4777
4778static const struct file_operations i915_hpd_storm_ctl_fops = {
4779 .owner = THIS_MODULE,
4780 .open = i915_hpd_storm_ctl_open,
4781 .read = seq_read,
4782 .llseek = seq_lseek,
4783 .release = single_release,
4784 .write = i915_hpd_storm_ctl_write
4785};
4786
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004787static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004788 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004789 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004790 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01004791 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004792 {"i915_gem_stolen", i915_gem_stolen_list_info },
Ben Gamari20172632009-02-17 20:08:50 -05004793 {"i915_gem_request", i915_gem_request_info, 0},
4794 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004795 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004796 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004797 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004798 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004799 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004800 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07004801 {"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
Oscar Mateoa8b93702017-05-10 15:04:51 +00004802 {"i915_guc_stage_pool", i915_guc_stage_pool, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004803 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304804 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004805 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Michel Thierry061d06a2017-06-20 10:57:49 +01004806 {"i915_reset_info", i915_reset_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004807 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004808 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004809 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004810 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004811 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004812 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004813 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004814 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004815 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004816 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004817 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01004818 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004819 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004820 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004821 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004822 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004823 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004824 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004825 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004826 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004827 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004828 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004829 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004830 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004831 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004832 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004833 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004834 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004835 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004836 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304837 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004838 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004839};
Ben Gamari27c202a2009-07-01 22:26:52 -04004840#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004841
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004842static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004843 const char *name;
4844 const struct file_operations *fops;
4845} i915_debugfs_files[] = {
4846 {"i915_wedged", &i915_wedged_fops},
4847 {"i915_max_freq", &i915_max_freq_fops},
4848 {"i915_min_freq", &i915_min_freq_fops},
4849 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004850 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4851 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004852 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004853#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004854 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004855 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004856#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004857 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004858 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004859 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4860 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4861 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Ville Syrjälä4127dc42017-06-06 15:44:12 +03004862 {"i915_fbc_false_color", &i915_fbc_false_color_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004863 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4864 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304865 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004866 {"i915_guc_log_control", &i915_guc_log_control_fops},
4867 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004868};
4869
Chris Wilson1dac8912016-06-24 14:00:17 +01004870int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004871{
Chris Wilson91c8a322016-07-05 10:40:23 +01004872 struct drm_minor *minor = dev_priv->drm.primary;
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004873 struct dentry *ent;
Daniel Vetter34b96742013-07-04 20:49:44 +02004874 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004875
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004876 ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
4877 minor->debugfs_root, to_i915(minor->dev),
4878 &i915_forcewake_fops);
4879 if (!ent)
4880 return -ENOMEM;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004881
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004882 ret = intel_pipe_crc_create(minor);
4883 if (ret)
4884 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004885
Daniel Vetter34b96742013-07-04 20:49:44 +02004886 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004887 ent = debugfs_create_file(i915_debugfs_files[i].name,
4888 S_IRUGO | S_IWUSR,
4889 minor->debugfs_root,
4890 to_i915(minor->dev),
Daniel Vetter34b96742013-07-04 20:49:44 +02004891 i915_debugfs_files[i].fops);
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004892 if (!ent)
4893 return -ENOMEM;
Daniel Vetter34b96742013-07-04 20:49:44 +02004894 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004895
Ben Gamari27c202a2009-07-01 22:26:52 -04004896 return drm_debugfs_create_files(i915_debugfs_list,
4897 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004898 minor->debugfs_root, minor);
4899}
4900
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004901struct dpcd_block {
4902 /* DPCD dump start address. */
4903 unsigned int offset;
4904 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4905 unsigned int end;
4906 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4907 size_t size;
4908 /* Only valid for eDP. */
4909 bool edp;
4910};
4911
4912static const struct dpcd_block i915_dpcd_debug[] = {
4913 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4914 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4915 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4916 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4917 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4918 { .offset = DP_SET_POWER },
4919 { .offset = DP_EDP_DPCD_REV },
4920 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4921 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4922 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4923};
4924
4925static int i915_dpcd_show(struct seq_file *m, void *data)
4926{
4927 struct drm_connector *connector = m->private;
4928 struct intel_dp *intel_dp =
4929 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4930 uint8_t buf[16];
4931 ssize_t err;
4932 int i;
4933
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004934 if (connector->status != connector_status_connected)
4935 return -ENODEV;
4936
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004937 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4938 const struct dpcd_block *b = &i915_dpcd_debug[i];
4939 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4940
4941 if (b->edp &&
4942 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4943 continue;
4944
4945 /* low tech for now */
4946 if (WARN_ON(size > sizeof(buf)))
4947 continue;
4948
4949 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4950 if (err <= 0) {
4951 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4952 size, b->offset, err);
4953 continue;
4954 }
4955
4956 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004957 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004958
4959 return 0;
4960}
4961
4962static int i915_dpcd_open(struct inode *inode, struct file *file)
4963{
4964 return single_open(file, i915_dpcd_show, inode->i_private);
4965}
4966
4967static const struct file_operations i915_dpcd_fops = {
4968 .owner = THIS_MODULE,
4969 .open = i915_dpcd_open,
4970 .read = seq_read,
4971 .llseek = seq_lseek,
4972 .release = single_release,
4973};
4974
David Weinehallecbd6782016-08-23 12:23:56 +03004975static int i915_panel_show(struct seq_file *m, void *data)
4976{
4977 struct drm_connector *connector = m->private;
4978 struct intel_dp *intel_dp =
4979 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4980
4981 if (connector->status != connector_status_connected)
4982 return -ENODEV;
4983
4984 seq_printf(m, "Panel power up delay: %d\n",
4985 intel_dp->panel_power_up_delay);
4986 seq_printf(m, "Panel power down delay: %d\n",
4987 intel_dp->panel_power_down_delay);
4988 seq_printf(m, "Backlight on delay: %d\n",
4989 intel_dp->backlight_on_delay);
4990 seq_printf(m, "Backlight off delay: %d\n",
4991 intel_dp->backlight_off_delay);
4992
4993 return 0;
4994}
4995
4996static int i915_panel_open(struct inode *inode, struct file *file)
4997{
4998 return single_open(file, i915_panel_show, inode->i_private);
4999}
5000
5001static const struct file_operations i915_panel_fops = {
5002 .owner = THIS_MODULE,
5003 .open = i915_panel_open,
5004 .read = seq_read,
5005 .llseek = seq_lseek,
5006 .release = single_release,
5007};
5008
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005009/**
5010 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5011 * @connector: pointer to a registered drm_connector
5012 *
5013 * Cleanup will be done by drm_connector_unregister() through a call to
5014 * drm_debugfs_connector_remove().
5015 *
5016 * Returns 0 on success, negative error codes on error.
5017 */
5018int i915_debugfs_connector_add(struct drm_connector *connector)
5019{
5020 struct dentry *root = connector->debugfs_entry;
5021
5022 /* The connector must have been registered beforehands. */
5023 if (!root)
5024 return -ENODEV;
5025
5026 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5027 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005028 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5029 connector, &i915_dpcd_fops);
5030
5031 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5032 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5033 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005034
5035 return 0;
5036}