blob: b84ee7a323d2faac511bab2d14c5a3b25a89c046 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
Chris Wilsonf3cd4742009-10-13 22:20:20 +010029#include <linux/debugfs.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010030#include <linux/list_sort.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010031#include "intel_drv.h"
Ben Gamari20172632009-02-17 20:08:50 -050032
David Weinehall36cdd012016-08-22 13:59:31 +030033static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
34{
35 return to_i915(node->minor->dev);
36}
37
Damien Lespiau497666d2013-10-15 18:55:39 +010038/* As the drm_debugfs_init() routines are called before dev->dev_private is
39 * allocated we need to hook into the minor for release. */
40static int
41drm_add_fake_info_node(struct drm_minor *minor,
42 struct dentry *ent,
43 const void *key)
44{
45 struct drm_info_node *node;
46
47 node = kmalloc(sizeof(*node), GFP_KERNEL);
48 if (node == NULL) {
49 debugfs_remove(ent);
50 return -ENOMEM;
51 }
52
53 node->minor = minor;
54 node->dent = ent;
David Weinehall36cdd012016-08-22 13:59:31 +030055 node->info_ent = (void *)key;
Damien Lespiau497666d2013-10-15 18:55:39 +010056
57 mutex_lock(&minor->debugfs_lock);
58 list_add(&node->list, &minor->debugfs_list);
59 mutex_unlock(&minor->debugfs_lock);
60
61 return 0;
62}
63
Chris Wilson418e3cd2017-02-06 21:36:08 +000064static __always_inline void seq_print_param(struct seq_file *m,
65 const char *name,
66 const char *type,
67 const void *x)
68{
69 if (!__builtin_strcmp(type, "bool"))
70 seq_printf(m, "i915.%s=%s\n", name, yesno(*(const bool *)x));
71 else if (!__builtin_strcmp(type, "int"))
72 seq_printf(m, "i915.%s=%d\n", name, *(const int *)x);
73 else if (!__builtin_strcmp(type, "unsigned int"))
74 seq_printf(m, "i915.%s=%u\n", name, *(const unsigned int *)x);
Chris Wilson1d6aa7a2017-02-21 16:26:19 +000075 else if (!__builtin_strcmp(type, "char *"))
76 seq_printf(m, "i915.%s=%s\n", name, *(const char **)x);
Chris Wilson418e3cd2017-02-06 21:36:08 +000077 else
78 BUILD_BUG();
79}
80
Chris Wilson70d39fe2010-08-25 16:03:34 +010081static int i915_capabilities(struct seq_file *m, void *data)
82{
David Weinehall36cdd012016-08-22 13:59:31 +030083 struct drm_i915_private *dev_priv = node_to_i915(m->private);
84 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010085
David Weinehall36cdd012016-08-22 13:59:31 +030086 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
Jani Nikula2e0d26f2016-12-01 14:49:55 +020087 seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
David Weinehall36cdd012016-08-22 13:59:31 +030088 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Chris Wilson418e3cd2017-02-06 21:36:08 +000089
Damien Lespiau79fc46d2013-04-23 16:37:17 +010090#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030091 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010092#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
Chris Wilson418e3cd2017-02-06 21:36:08 +000094 kernel_param_lock(THIS_MODULE);
95#define PRINT_PARAM(T, x) seq_print_param(m, #x, #T, &i915.x);
96 I915_PARAMS_FOR_EACH(PRINT_PARAM);
97#undef PRINT_PARAM
98 kernel_param_unlock(THIS_MODULE);
99
Chris Wilson70d39fe2010-08-25 16:03:34 +0100100 return 0;
101}
Ben Gamari433e12f2009-02-17 20:08:51 -0500102
Imre Deaka7363de2016-05-12 16:18:52 +0300103static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000104{
Chris Wilson573adb32016-08-04 16:32:39 +0100105 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +0000106}
107
Imre Deaka7363de2016-05-12 16:18:52 +0300108static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100109{
110 return obj->pin_display ? 'p' : ' ';
111}
112
Imre Deaka7363de2016-05-12 16:18:52 +0300113static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000114{
Chris Wilson3e510a82016-08-05 10:14:23 +0100115 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -0400116 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100117 case I915_TILING_NONE: return ' ';
118 case I915_TILING_X: return 'X';
119 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400120 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000121}
122
Imre Deaka7363de2016-05-12 16:18:52 +0300123static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700124{
Chris Wilson275f0392016-10-24 13:42:14 +0100125 return !list_empty(&obj->userfault_link) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100126}
127
Imre Deaka7363de2016-05-12 16:18:52 +0300128static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100129{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100130 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700131}
132
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100133static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
134{
135 u64 size = 0;
136 struct i915_vma *vma;
137
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000138 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100139 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100140 size += vma->node.size;
141 }
142
143 return size;
144}
145
Chris Wilson37811fc2010-08-25 22:45:57 +0100146static void
147describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
148{
Chris Wilsonb4716182015-04-27 13:41:17 +0100149 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000150 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700151 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100152 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800153 int pin_count = 0;
154
Chris Wilson188c1ab2016-04-03 14:14:20 +0100155 lockdep_assert_held(&obj->base.dev->struct_mutex);
156
Chris Wilsond07f0e52016-10-28 13:58:44 +0100157 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100158 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100159 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100160 get_pin_flag(obj),
161 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700162 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100163 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800164 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100165 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100166 obj->base.write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300167 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100168 obj->mm.dirty ? " dirty" : "",
169 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100170 if (obj->base.name)
171 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000172 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100173 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800174 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300175 }
176 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100177 if (obj->pin_display)
178 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000179 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100180 if (!drm_mm_node_allocated(&vma->node))
181 continue;
182
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100183 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100184 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100185 vma->node.start, vma->node.size);
Chris Wilson21976852017-01-12 11:21:08 +0000186 if (i915_vma_is_ggtt(vma)) {
187 switch (vma->ggtt_view.type) {
188 case I915_GGTT_VIEW_NORMAL:
189 seq_puts(m, ", normal");
190 break;
191
192 case I915_GGTT_VIEW_PARTIAL:
193 seq_printf(m, ", partial [%08llx+%x]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000194 vma->ggtt_view.partial.offset << PAGE_SHIFT,
195 vma->ggtt_view.partial.size << PAGE_SHIFT);
Chris Wilson21976852017-01-12 11:21:08 +0000196 break;
197
198 case I915_GGTT_VIEW_ROTATED:
199 seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000200 vma->ggtt_view.rotated.plane[0].width,
201 vma->ggtt_view.rotated.plane[0].height,
202 vma->ggtt_view.rotated.plane[0].stride,
203 vma->ggtt_view.rotated.plane[0].offset,
204 vma->ggtt_view.rotated.plane[1].width,
205 vma->ggtt_view.rotated.plane[1].height,
206 vma->ggtt_view.rotated.plane[1].stride,
207 vma->ggtt_view.rotated.plane[1].offset);
Chris Wilson21976852017-01-12 11:21:08 +0000208 break;
209
210 default:
211 MISSING_CASE(vma->ggtt_view.type);
212 break;
213 }
214 }
Chris Wilson49ef5292016-08-18 17:17:00 +0100215 if (vma->fence)
216 seq_printf(m, " , fence: %d%s",
217 vma->fence->id,
218 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000219 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700220 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000221 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100222 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100223
Chris Wilsond07f0e52016-10-28 13:58:44 +0100224 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100225 if (engine)
226 seq_printf(m, " (%s)", engine->name);
227
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100228 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
229 if (frontbuffer_bits)
230 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100231}
232
Chris Wilson6d2b88852013-08-07 18:30:54 +0100233static int obj_rank_by_stolen(void *priv,
234 struct list_head *A, struct list_head *B)
235{
236 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200237 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100238 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200239 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100240
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200241 if (a->stolen->start < b->stolen->start)
242 return -1;
243 if (a->stolen->start > b->stolen->start)
244 return 1;
245 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100246}
247
248static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
249{
David Weinehall36cdd012016-08-22 13:59:31 +0300250 struct drm_i915_private *dev_priv = node_to_i915(m->private);
251 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300253 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100254 LIST_HEAD(stolen);
255 int count, ret;
256
257 ret = mutex_lock_interruptible(&dev->struct_mutex);
258 if (ret)
259 return ret;
260
261 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200262 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263 if (obj->stolen == NULL)
264 continue;
265
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200266 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100267
268 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100269 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100270 count++;
271 }
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200272 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100273 if (obj->stolen == NULL)
274 continue;
275
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200276 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100277
278 total_obj_size += obj->base.size;
279 count++;
280 }
281 list_sort(NULL, &stolen, obj_rank_by_stolen);
282 seq_puts(m, "Stolen:\n");
283 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200284 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100285 seq_puts(m, " ");
286 describe_obj(m, obj);
287 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200288 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100289 }
290 mutex_unlock(&dev->struct_mutex);
291
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300292 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100293 count, total_obj_size, total_gtt_size);
294 return 0;
295}
296
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100297struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000298 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300299 unsigned long count;
300 u64 total, unbound;
301 u64 global, shared;
302 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303};
304
305static int per_file_stats(int id, void *ptr, void *data)
306{
307 struct drm_i915_gem_object *obj = ptr;
308 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000309 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100310
311 stats->count++;
312 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100313 if (!obj->bind_count)
314 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000315 if (obj->base.name || obj->base.dma_buf)
316 stats->shared += obj->base.size;
317
Chris Wilson894eeec2016-08-04 07:52:20 +0100318 list_for_each_entry(vma, &obj->vma_list, obj_link) {
319 if (!drm_mm_node_allocated(&vma->node))
320 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000321
Chris Wilson3272db52016-08-04 16:32:32 +0100322 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100323 stats->global += vma->node.size;
324 } else {
325 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000326
Chris Wilson2bfa9962016-08-04 07:52:25 +0100327 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000328 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000329 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100330
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100331 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100332 stats->active += vma->node.size;
333 else
334 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100335 }
336
337 return 0;
338}
339
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100340#define print_file_stats(m, name, stats) do { \
341 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300342 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 +0100343 name, \
344 stats.count, \
345 stats.total, \
346 stats.active, \
347 stats.inactive, \
348 stats.global, \
349 stats.shared, \
350 stats.unbound); \
351} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800352
353static void print_batch_pool_stats(struct seq_file *m,
354 struct drm_i915_private *dev_priv)
355{
356 struct drm_i915_gem_object *obj;
357 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000358 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530359 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000360 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800361
362 memset(&stats, 0, sizeof(stats));
363
Akash Goel3b3f1652016-10-13 22:44:48 +0530364 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000365 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100366 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000367 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100368 batch_pool_link)
369 per_file_stats(0, obj, &stats);
370 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100371 }
Brad Volkin493018d2014-12-11 12:13:08 -0800372
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100373 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800374}
375
Chris Wilson15da9562016-05-24 14:53:43 +0100376static int per_file_ctx_stats(int id, void *ptr, void *data)
377{
378 struct i915_gem_context *ctx = ptr;
379 int n;
380
381 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
382 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100383 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100384 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100385 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100386 }
387
388 return 0;
389}
390
391static void print_context_stats(struct seq_file *m,
392 struct drm_i915_private *dev_priv)
393{
David Weinehall36cdd012016-08-22 13:59:31 +0300394 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100395 struct file_stats stats;
396 struct drm_file *file;
397
398 memset(&stats, 0, sizeof(stats));
399
David Weinehall36cdd012016-08-22 13:59:31 +0300400 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100401 if (dev_priv->kernel_context)
402 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
403
David Weinehall36cdd012016-08-22 13:59:31 +0300404 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100405 struct drm_i915_file_private *fpriv = file->driver_priv;
406 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
407 }
David Weinehall36cdd012016-08-22 13:59:31 +0300408 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100409
410 print_file_stats(m, "[k]contexts", stats);
411}
412
David Weinehall36cdd012016-08-22 13:59:31 +0300413static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100414{
David Weinehall36cdd012016-08-22 13:59:31 +0300415 struct drm_i915_private *dev_priv = node_to_i915(m->private);
416 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300417 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100418 u32 count, mapped_count, purgeable_count, dpy_count;
419 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000420 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100421 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100422 int ret;
423
424 ret = mutex_lock_interruptible(&dev->struct_mutex);
425 if (ret)
426 return ret;
427
Chris Wilson3ef7f222016-10-18 13:02:48 +0100428 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000429 dev_priv->mm.object_count,
430 dev_priv->mm.object_memory);
431
Chris Wilson1544c422016-08-15 13:18:16 +0100432 size = count = 0;
433 mapped_size = mapped_count = 0;
434 purgeable_size = purgeable_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200435 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100436 size += obj->base.size;
437 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200438
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100439 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200440 purgeable_size += obj->base.size;
441 ++purgeable_count;
442 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100443
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100444 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100445 mapped_count++;
446 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100447 }
Chris Wilson6299f992010-11-24 12:23:44 +0000448 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100449 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
450
451 size = count = dpy_size = dpy_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200452 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100453 size += obj->base.size;
454 ++count;
455
456 if (obj->pin_display) {
457 dpy_size += obj->base.size;
458 ++dpy_count;
459 }
460
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100461 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100462 purgeable_size += obj->base.size;
463 ++purgeable_count;
464 }
465
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100466 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100467 mapped_count++;
468 mapped_size += obj->base.size;
469 }
470 }
471 seq_printf(m, "%u bound objects, %llu bytes\n",
472 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300473 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200474 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100475 seq_printf(m, "%u mapped objects, %llu bytes\n",
476 mapped_count, mapped_size);
477 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
478 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000479
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300480 seq_printf(m, "%llu [%llu] gtt total\n",
Chris Wilson381b9432017-02-15 08:43:54 +0000481 ggtt->base.total, ggtt->mappable_end);
Chris Wilson73aa8082010-09-30 11:46:12 +0100482
Damien Lespiau267f0c92013-06-24 22:59:48 +0100483 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800484 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200485 mutex_unlock(&dev->struct_mutex);
486
487 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100488 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100489 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
490 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100491 struct drm_i915_file_private *file_priv = file->driver_priv;
492 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900493 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100494
495 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000496 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100497 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100498 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100499 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900500 /*
501 * Although we have a valid reference on file->pid, that does
502 * not guarantee that the task_struct who called get_pid() is
503 * still alive (e.g. get_pid(current) => fork() => exit()).
504 * Therefore, we need to protect this ->comm access using RCU.
505 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100506 mutex_lock(&dev->struct_mutex);
507 request = list_first_entry_or_null(&file_priv->mm.request_list,
508 struct drm_i915_gem_request,
509 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900510 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100511 task = pid_task(request && request->ctx->pid ?
512 request->ctx->pid : file->pid,
513 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800514 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900515 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100516 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100517 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200518 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100519
520 return 0;
521}
522
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100523static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000524{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100525 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300526 struct drm_i915_private *dev_priv = node_to_i915(node);
527 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100528 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000529 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300530 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000531 int count, ret;
532
533 ret = mutex_lock_interruptible(&dev->struct_mutex);
534 if (ret)
535 return ret;
536
537 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200538 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6da84822016-08-15 10:48:44 +0100539 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100540 continue;
541
Damien Lespiau267f0c92013-06-24 22:59:48 +0100542 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000543 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100544 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000545 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100546 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000547 count++;
548 }
549
550 mutex_unlock(&dev->struct_mutex);
551
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300552 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000553 count, total_obj_size, total_gtt_size);
554
555 return 0;
556}
557
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100558static int i915_gem_pageflip_info(struct seq_file *m, void *data)
559{
David Weinehall36cdd012016-08-22 13:59:31 +0300560 struct drm_i915_private *dev_priv = node_to_i915(m->private);
561 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100562 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200563 int ret;
564
565 ret = mutex_lock_interruptible(&dev->struct_mutex);
566 if (ret)
567 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100568
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100569 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800570 const char pipe = pipe_name(crtc->pipe);
571 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200572 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100573
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200574 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200575 work = crtc->flip_work;
576 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800577 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100578 pipe, plane);
579 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200580 u32 pending;
581 u32 addr;
582
583 pending = atomic_read(&work->pending);
584 if (pending) {
585 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
586 pipe, plane);
587 } else {
588 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
589 pipe, plane);
590 }
591 if (work->flip_queued_req) {
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200592 struct intel_engine_cs *engine = work->flip_queued_req->engine;
Daniel Vetter5a21b662016-05-24 17:13:53 +0200593
Chris Wilson312c3c42016-11-24 14:47:50 +0000594 seq_printf(m, "Flip queued on %s at seqno %x, last submitted seqno %x [current breadcrumb %x], completed? %d\n",
Daniel Vetter5a21b662016-05-24 17:13:53 +0200595 engine->name,
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200596 work->flip_queued_req->global_seqno,
Chris Wilson312c3c42016-11-24 14:47:50 +0000597 intel_engine_last_submit(engine),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100598 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100599 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200600 } else
601 seq_printf(m, "Flip not associated with any ring\n");
602 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
603 work->flip_queued_vblank,
604 work->flip_ready_vblank,
605 intel_crtc_get_vblank_counter(crtc));
606 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
607
David Weinehall36cdd012016-08-22 13:59:31 +0300608 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200609 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
610 else
611 addr = I915_READ(DSPADDR(crtc->plane));
612 seq_printf(m, "Current scanout address 0x%08x\n", addr);
613
614 if (work->pending_flip_obj) {
615 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
616 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100617 }
618 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200619 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100620 }
621
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200622 mutex_unlock(&dev->struct_mutex);
623
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100624 return 0;
625}
626
Brad Volkin493018d2014-12-11 12:13:08 -0800627static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
628{
David Weinehall36cdd012016-08-22 13:59:31 +0300629 struct drm_i915_private *dev_priv = node_to_i915(m->private);
630 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800631 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000632 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530633 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100634 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000635 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800636
637 ret = mutex_lock_interruptible(&dev->struct_mutex);
638 if (ret)
639 return ret;
640
Akash Goel3b3f1652016-10-13 22:44:48 +0530641 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000642 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100643 int count;
644
645 count = 0;
646 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000647 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100648 batch_pool_link)
649 count++;
650 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000651 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100652
653 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000654 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100655 batch_pool_link) {
656 seq_puts(m, " ");
657 describe_obj(m, obj);
658 seq_putc(m, '\n');
659 }
660
661 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100662 }
Brad Volkin493018d2014-12-11 12:13:08 -0800663 }
664
Chris Wilson8d9d5742015-04-07 16:20:38 +0100665 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800666
667 mutex_unlock(&dev->struct_mutex);
668
669 return 0;
670}
671
Chris Wilson1b365952016-10-04 21:11:31 +0100672static void print_request(struct seq_file *m,
673 struct drm_i915_gem_request *rq,
674 const char *prefix)
675{
Chris Wilson20311bd2016-11-14 20:41:03 +0000676 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100677 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000678 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100679 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100680 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100681}
682
Ben Gamari20172632009-02-17 20:08:50 -0500683static int i915_gem_request_info(struct seq_file *m, void *data)
684{
David Weinehall36cdd012016-08-22 13:59:31 +0300685 struct drm_i915_private *dev_priv = node_to_i915(m->private);
686 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200687 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530688 struct intel_engine_cs *engine;
689 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000690 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100691
692 ret = mutex_lock_interruptible(&dev->struct_mutex);
693 if (ret)
694 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500695
Chris Wilson2d1070b2015-04-01 10:36:56 +0100696 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530697 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100698 int count;
699
700 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100701 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100702 count++;
703 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100704 continue;
705
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000706 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100707 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100708 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100709
710 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500711 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100712 mutex_unlock(&dev->struct_mutex);
713
Chris Wilson2d1070b2015-04-01 10:36:56 +0100714 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100715 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100716
Ben Gamari20172632009-02-17 20:08:50 -0500717 return 0;
718}
719
Chris Wilsonb2223492010-10-27 15:27:33 +0100720static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000721 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100722{
Chris Wilson688e6c72016-07-01 17:23:15 +0100723 struct intel_breadcrumbs *b = &engine->breadcrumbs;
724 struct rb_node *rb;
725
Chris Wilson12471ba2016-04-09 10:57:55 +0100726 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100727 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100728
Chris Wilsonf6168e32016-10-28 13:58:55 +0100729 spin_lock_irq(&b->lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100730 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +0800731 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson688e6c72016-07-01 17:23:15 +0100732
733 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
734 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
735 }
Chris Wilsonf6168e32016-10-28 13:58:55 +0100736 spin_unlock_irq(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100737}
738
Ben Gamari20172632009-02-17 20:08:50 -0500739static int i915_gem_seqno_info(struct seq_file *m, void *data)
740{
David Weinehall36cdd012016-08-22 13:59:31 +0300741 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000742 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530743 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500744
Akash Goel3b3f1652016-10-13 22:44:48 +0530745 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000746 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100747
Ben Gamari20172632009-02-17 20:08:50 -0500748 return 0;
749}
750
751
752static int i915_interrupt_info(struct seq_file *m, void *data)
753{
David Weinehall36cdd012016-08-22 13:59:31 +0300754 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000755 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530756 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100757 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100758
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200759 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500760
David Weinehall36cdd012016-08-22 13:59:31 +0300761 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300762 seq_printf(m, "Master Interrupt Control:\t%08x\n",
763 I915_READ(GEN8_MASTER_IRQ));
764
765 seq_printf(m, "Display IER:\t%08x\n",
766 I915_READ(VLV_IER));
767 seq_printf(m, "Display IIR:\t%08x\n",
768 I915_READ(VLV_IIR));
769 seq_printf(m, "Display IIR_RW:\t%08x\n",
770 I915_READ(VLV_IIR_RW));
771 seq_printf(m, "Display IMR:\t%08x\n",
772 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100773 for_each_pipe(dev_priv, pipe) {
774 enum intel_display_power_domain power_domain;
775
776 power_domain = POWER_DOMAIN_PIPE(pipe);
777 if (!intel_display_power_get_if_enabled(dev_priv,
778 power_domain)) {
779 seq_printf(m, "Pipe %c power disabled\n",
780 pipe_name(pipe));
781 continue;
782 }
783
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300784 seq_printf(m, "Pipe %c stat:\t%08x\n",
785 pipe_name(pipe),
786 I915_READ(PIPESTAT(pipe)));
787
Chris Wilson9c870d02016-10-24 13:42:15 +0100788 intel_display_power_put(dev_priv, power_domain);
789 }
790
791 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300792 seq_printf(m, "Port hotplug:\t%08x\n",
793 I915_READ(PORT_HOTPLUG_EN));
794 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
795 I915_READ(VLV_DPFLIPSTAT));
796 seq_printf(m, "DPINVGTT:\t%08x\n",
797 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100798 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300799
800 for (i = 0; i < 4; i++) {
801 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
802 i, I915_READ(GEN8_GT_IMR(i)));
803 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
804 i, I915_READ(GEN8_GT_IIR(i)));
805 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
806 i, I915_READ(GEN8_GT_IER(i)));
807 }
808
809 seq_printf(m, "PCU interrupt mask:\t%08x\n",
810 I915_READ(GEN8_PCU_IMR));
811 seq_printf(m, "PCU interrupt identity:\t%08x\n",
812 I915_READ(GEN8_PCU_IIR));
813 seq_printf(m, "PCU interrupt enable:\t%08x\n",
814 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300815 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700816 seq_printf(m, "Master Interrupt Control:\t%08x\n",
817 I915_READ(GEN8_MASTER_IRQ));
818
819 for (i = 0; i < 4; i++) {
820 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
821 i, I915_READ(GEN8_GT_IMR(i)));
822 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
823 i, I915_READ(GEN8_GT_IIR(i)));
824 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
825 i, I915_READ(GEN8_GT_IER(i)));
826 }
827
Damien Lespiau055e3932014-08-18 13:49:10 +0100828 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200829 enum intel_display_power_domain power_domain;
830
831 power_domain = POWER_DOMAIN_PIPE(pipe);
832 if (!intel_display_power_get_if_enabled(dev_priv,
833 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300834 seq_printf(m, "Pipe %c power disabled\n",
835 pipe_name(pipe));
836 continue;
837 }
Ben Widawskya123f152013-11-02 21:07:10 -0700838 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000839 pipe_name(pipe),
840 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700841 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000842 pipe_name(pipe),
843 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700844 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000845 pipe_name(pipe),
846 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200847
848 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700849 }
850
851 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
852 I915_READ(GEN8_DE_PORT_IMR));
853 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
854 I915_READ(GEN8_DE_PORT_IIR));
855 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
856 I915_READ(GEN8_DE_PORT_IER));
857
858 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
859 I915_READ(GEN8_DE_MISC_IMR));
860 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
861 I915_READ(GEN8_DE_MISC_IIR));
862 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
863 I915_READ(GEN8_DE_MISC_IER));
864
865 seq_printf(m, "PCU interrupt mask:\t%08x\n",
866 I915_READ(GEN8_PCU_IMR));
867 seq_printf(m, "PCU interrupt identity:\t%08x\n",
868 I915_READ(GEN8_PCU_IIR));
869 seq_printf(m, "PCU interrupt enable:\t%08x\n",
870 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300871 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700872 seq_printf(m, "Display IER:\t%08x\n",
873 I915_READ(VLV_IER));
874 seq_printf(m, "Display IIR:\t%08x\n",
875 I915_READ(VLV_IIR));
876 seq_printf(m, "Display IIR_RW:\t%08x\n",
877 I915_READ(VLV_IIR_RW));
878 seq_printf(m, "Display IMR:\t%08x\n",
879 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000880 for_each_pipe(dev_priv, pipe) {
881 enum intel_display_power_domain power_domain;
882
883 power_domain = POWER_DOMAIN_PIPE(pipe);
884 if (!intel_display_power_get_if_enabled(dev_priv,
885 power_domain)) {
886 seq_printf(m, "Pipe %c power disabled\n",
887 pipe_name(pipe));
888 continue;
889 }
890
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700891 seq_printf(m, "Pipe %c stat:\t%08x\n",
892 pipe_name(pipe),
893 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000894 intel_display_power_put(dev_priv, power_domain);
895 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700896
897 seq_printf(m, "Master IER:\t%08x\n",
898 I915_READ(VLV_MASTER_IER));
899
900 seq_printf(m, "Render IER:\t%08x\n",
901 I915_READ(GTIER));
902 seq_printf(m, "Render IIR:\t%08x\n",
903 I915_READ(GTIIR));
904 seq_printf(m, "Render IMR:\t%08x\n",
905 I915_READ(GTIMR));
906
907 seq_printf(m, "PM IER:\t\t%08x\n",
908 I915_READ(GEN6_PMIER));
909 seq_printf(m, "PM IIR:\t\t%08x\n",
910 I915_READ(GEN6_PMIIR));
911 seq_printf(m, "PM IMR:\t\t%08x\n",
912 I915_READ(GEN6_PMIMR));
913
914 seq_printf(m, "Port hotplug:\t%08x\n",
915 I915_READ(PORT_HOTPLUG_EN));
916 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
917 I915_READ(VLV_DPFLIPSTAT));
918 seq_printf(m, "DPINVGTT:\t%08x\n",
919 I915_READ(DPINVGTT));
920
David Weinehall36cdd012016-08-22 13:59:31 +0300921 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800922 seq_printf(m, "Interrupt enable: %08x\n",
923 I915_READ(IER));
924 seq_printf(m, "Interrupt identity: %08x\n",
925 I915_READ(IIR));
926 seq_printf(m, "Interrupt mask: %08x\n",
927 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100928 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800929 seq_printf(m, "Pipe %c stat: %08x\n",
930 pipe_name(pipe),
931 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800932 } else {
933 seq_printf(m, "North Display Interrupt enable: %08x\n",
934 I915_READ(DEIER));
935 seq_printf(m, "North Display Interrupt identity: %08x\n",
936 I915_READ(DEIIR));
937 seq_printf(m, "North Display Interrupt mask: %08x\n",
938 I915_READ(DEIMR));
939 seq_printf(m, "South Display Interrupt enable: %08x\n",
940 I915_READ(SDEIER));
941 seq_printf(m, "South Display Interrupt identity: %08x\n",
942 I915_READ(SDEIIR));
943 seq_printf(m, "South Display Interrupt mask: %08x\n",
944 I915_READ(SDEIMR));
945 seq_printf(m, "Graphics Interrupt enable: %08x\n",
946 I915_READ(GTIER));
947 seq_printf(m, "Graphics Interrupt identity: %08x\n",
948 I915_READ(GTIIR));
949 seq_printf(m, "Graphics Interrupt mask: %08x\n",
950 I915_READ(GTIMR));
951 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530952 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300953 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100954 seq_printf(m,
955 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000956 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000957 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000958 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000959 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200960 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100961
Ben Gamari20172632009-02-17 20:08:50 -0500962 return 0;
963}
964
Chris Wilsona6172a82009-02-11 14:26:38 +0000965static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
966{
David Weinehall36cdd012016-08-22 13:59:31 +0300967 struct drm_i915_private *dev_priv = node_to_i915(m->private);
968 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100969 int i, ret;
970
971 ret = mutex_lock_interruptible(&dev->struct_mutex);
972 if (ret)
973 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000974
Chris Wilsona6172a82009-02-11 14:26:38 +0000975 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
976 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100977 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000978
Chris Wilson6c085a72012-08-20 11:40:46 +0200979 seq_printf(m, "Fence %d, pin count = %d, object = ",
980 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100981 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100982 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100983 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100984 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100985 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000986 }
987
Chris Wilson05394f32010-11-08 19:18:58 +0000988 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000989 return 0;
990}
991
Chris Wilson98a2f412016-10-12 10:05:18 +0100992#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000993static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
994 size_t count, loff_t *pos)
995{
996 struct i915_gpu_state *error = file->private_data;
997 struct drm_i915_error_state_buf str;
998 ssize_t ret;
999 loff_t tmp;
1000
1001 if (!error)
1002 return 0;
1003
1004 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
1005 if (ret)
1006 return ret;
1007
1008 ret = i915_error_state_to_str(&str, error);
1009 if (ret)
1010 goto out;
1011
1012 tmp = 0;
1013 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
1014 if (ret < 0)
1015 goto out;
1016
1017 *pos = str.start + ret;
1018out:
1019 i915_error_state_buf_release(&str);
1020 return ret;
1021}
1022
1023static int gpu_state_release(struct inode *inode, struct file *file)
1024{
1025 i915_gpu_state_put(file->private_data);
1026 return 0;
1027}
1028
1029static int i915_gpu_info_open(struct inode *inode, struct file *file)
1030{
1031 struct i915_gpu_state *gpu;
1032
1033 gpu = i915_capture_gpu_state(inode->i_private);
1034 if (!gpu)
1035 return -ENOMEM;
1036
1037 file->private_data = gpu;
1038 return 0;
1039}
1040
1041static const struct file_operations i915_gpu_info_fops = {
1042 .owner = THIS_MODULE,
1043 .open = i915_gpu_info_open,
1044 .read = gpu_state_read,
1045 .llseek = default_llseek,
1046 .release = gpu_state_release,
1047};
Chris Wilson98a2f412016-10-12 10:05:18 +01001048
Daniel Vetterd5442302012-04-27 15:17:40 +02001049static ssize_t
1050i915_error_state_write(struct file *filp,
1051 const char __user *ubuf,
1052 size_t cnt,
1053 loff_t *ppos)
1054{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001055 struct i915_gpu_state *error = filp->private_data;
1056
1057 if (!error)
1058 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001059
1060 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001061 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +02001062
1063 return cnt;
1064}
1065
1066static int i915_error_state_open(struct inode *inode, struct file *file)
1067{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001068 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001069 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001070}
1071
Daniel Vetterd5442302012-04-27 15:17:40 +02001072static const struct file_operations i915_error_state_fops = {
1073 .owner = THIS_MODULE,
1074 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001075 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001076 .write = i915_error_state_write,
1077 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001078 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +02001079};
Chris Wilson98a2f412016-10-12 10:05:18 +01001080#endif
1081
Kees Cook647416f2013-03-10 14:10:06 -07001082static int
Kees Cook647416f2013-03-10 14:10:06 -07001083i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001084{
David Weinehall36cdd012016-08-22 13:59:31 +03001085 struct drm_i915_private *dev_priv = data;
1086 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001087 int ret;
1088
Mika Kuoppala40633212012-12-04 15:12:00 +02001089 ret = mutex_lock_interruptible(&dev->struct_mutex);
1090 if (ret)
1091 return ret;
1092
Chris Wilson73cb9702016-10-28 13:58:46 +01001093 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001094 mutex_unlock(&dev->struct_mutex);
1095
Kees Cook647416f2013-03-10 14:10:06 -07001096 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001097}
1098
Kees Cook647416f2013-03-10 14:10:06 -07001099DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001100 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001101 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001102
Deepak Sadb4bd12014-03-31 11:30:02 +05301103static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001104{
David Weinehall36cdd012016-08-22 13:59:31 +03001105 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001106 int ret = 0;
1107
1108 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001109
David Weinehall36cdd012016-08-22 13:59:31 +03001110 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001111 u16 rgvswctl = I915_READ16(MEMSWCTL);
1112 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1113
1114 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1115 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1116 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1117 MEMSTAT_VID_SHIFT);
1118 seq_printf(m, "Current P-state: %d\n",
1119 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001120 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001121 u32 freq_sts;
1122
1123 mutex_lock(&dev_priv->rps.hw_lock);
1124 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1125 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1126 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1127
1128 seq_printf(m, "actual GPU freq: %d MHz\n",
1129 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1130
1131 seq_printf(m, "current GPU freq: %d MHz\n",
1132 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1133
1134 seq_printf(m, "max GPU freq: %d MHz\n",
1135 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1136
1137 seq_printf(m, "min GPU freq: %d MHz\n",
1138 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1139
1140 seq_printf(m, "idle GPU freq: %d MHz\n",
1141 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1142
1143 seq_printf(m,
1144 "efficient (RPe) frequency: %d MHz\n",
1145 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1146 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001147 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001148 u32 rp_state_limits;
1149 u32 gt_perf_status;
1150 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001151 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001152 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001153 u32 rpupei, rpcurup, rpprevup;
1154 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001155 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001156 int max_freq;
1157
Bob Paauwe35040562015-06-25 14:54:07 -07001158 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001159 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001160 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1161 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1162 } else {
1163 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1164 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1165 }
1166
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001167 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001168 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001169
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001170 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001171 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301172 reqf >>= 23;
1173 else {
1174 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001175 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301176 reqf >>= 24;
1177 else
1178 reqf >>= 25;
1179 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001180 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001181
Chris Wilson0d8f9492014-03-27 09:06:14 +00001182 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1183 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1184 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1185
Jesse Barnesccab5c82011-01-18 15:49:25 -08001186 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301187 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1188 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1189 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1190 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1191 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1192 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001193 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301194 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001195 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001196 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1197 else
1198 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001199 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001200
Mika Kuoppala59bad942015-01-16 11:34:40 +02001201 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001202
David Weinehall36cdd012016-08-22 13:59:31 +03001203 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001204 pm_ier = I915_READ(GEN6_PMIER);
1205 pm_imr = I915_READ(GEN6_PMIMR);
1206 pm_isr = I915_READ(GEN6_PMISR);
1207 pm_iir = I915_READ(GEN6_PMIIR);
1208 pm_mask = I915_READ(GEN6_PMINTRMSK);
1209 } else {
1210 pm_ier = I915_READ(GEN8_GT_IER(2));
1211 pm_imr = I915_READ(GEN8_GT_IMR(2));
1212 pm_isr = I915_READ(GEN8_GT_ISR(2));
1213 pm_iir = I915_READ(GEN8_GT_IIR(2));
1214 pm_mask = I915_READ(GEN6_PMINTRMSK);
1215 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001216 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 -03001217 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301218 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001219 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001220 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001221 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001222 seq_printf(m, "Render p-state VID: %d\n",
1223 gt_perf_status & 0xff);
1224 seq_printf(m, "Render p-state limit: %d\n",
1225 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001226 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1227 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1228 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1229 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001230 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001231 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301232 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1233 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1234 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1235 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1236 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1237 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001238 seq_printf(m, "Up threshold: %d%%\n",
1239 dev_priv->rps.up_threshold);
1240
Akash Goeld6cda9c2016-04-23 00:05:46 +05301241 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1242 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1243 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1244 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1245 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1246 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001247 seq_printf(m, "Down threshold: %d%%\n",
1248 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001249
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001250 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001251 rp_state_cap >> 16) & 0xff;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001252 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001253 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001254 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001255
1256 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001257 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001259 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001261 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001262 rp_state_cap >> 0) & 0xff;
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001263 max_freq *= (IS_GEN9_BC(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001264 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001265 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001266 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001267 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001268
Chris Wilsond86ed342015-04-27 13:41:19 +01001269 seq_printf(m, "Current freq: %d MHz\n",
1270 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1271 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001272 seq_printf(m, "Idle freq: %d MHz\n",
1273 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001274 seq_printf(m, "Min freq: %d MHz\n",
1275 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001276 seq_printf(m, "Boost freq: %d MHz\n",
1277 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001278 seq_printf(m, "Max freq: %d MHz\n",
1279 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1280 seq_printf(m,
1281 "efficient (RPe) frequency: %d MHz\n",
1282 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001283 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001284 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001285 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001286
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001287 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001288 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1289 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1290
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001291 intel_runtime_pm_put(dev_priv);
1292 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001293}
1294
Ben Widawskyd6369512016-09-20 16:54:32 +03001295static void i915_instdone_info(struct drm_i915_private *dev_priv,
1296 struct seq_file *m,
1297 struct intel_instdone *instdone)
1298{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001299 int slice;
1300 int subslice;
1301
Ben Widawskyd6369512016-09-20 16:54:32 +03001302 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1303 instdone->instdone);
1304
1305 if (INTEL_GEN(dev_priv) <= 3)
1306 return;
1307
1308 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1309 instdone->slice_common);
1310
1311 if (INTEL_GEN(dev_priv) <= 6)
1312 return;
1313
Ben Widawskyf9e61372016-09-20 16:54:33 +03001314 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1315 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1316 slice, subslice, instdone->sampler[slice][subslice]);
1317
1318 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1319 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1320 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001321}
1322
Chris Wilsonf6544492015-01-26 18:03:04 +02001323static int i915_hangcheck_info(struct seq_file *m, void *unused)
1324{
David Weinehall36cdd012016-08-22 13:59:31 +03001325 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001326 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001327 u64 acthd[I915_NUM_ENGINES];
1328 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001329 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001330 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001331
Chris Wilson8af29b02016-09-09 14:11:47 +01001332 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1333 seq_printf(m, "Wedged\n");
1334 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1335 seq_printf(m, "Reset in progress\n");
1336 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1337 seq_printf(m, "Waiter holding struct mutex\n");
1338 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1339 seq_printf(m, "struct_mutex blocked for reset\n");
1340
Chris Wilsonf6544492015-01-26 18:03:04 +02001341 if (!i915.enable_hangcheck) {
1342 seq_printf(m, "Hangcheck disabled\n");
1343 return 0;
1344 }
1345
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001346 intel_runtime_pm_get(dev_priv);
1347
Akash Goel3b3f1652016-10-13 22:44:48 +05301348 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001349 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001350 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001351 }
1352
Akash Goel3b3f1652016-10-13 22:44:48 +05301353 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001354
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001355 intel_runtime_pm_put(dev_priv);
1356
Chris Wilsonf6544492015-01-26 18:03:04 +02001357 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1358 seq_printf(m, "Hangcheck active, fires in %dms\n",
1359 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1360 jiffies));
1361 } else
1362 seq_printf(m, "Hangcheck inactive\n");
1363
Chris Wilsonf73b5672017-03-02 15:03:56 +00001364 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1365
Akash Goel3b3f1652016-10-13 22:44:48 +05301366 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001367 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1368 struct rb_node *rb;
1369
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001370 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001371 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001372 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001373 intel_engine_last_submit(engine),
1374 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001375 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001376 yesno(intel_engine_has_waiter(engine)),
1377 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001378 &dev_priv->gpu_error.missed_irq_rings)),
1379 yesno(engine->hangcheck.stalled));
1380
Chris Wilsonf6168e32016-10-28 13:58:55 +01001381 spin_lock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001382 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001383 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001384
1385 seq_printf(m, "\t%s [%d] waiting for %x\n",
1386 w->tsk->comm, w->tsk->pid, w->seqno);
1387 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01001388 spin_unlock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001389
Chris Wilsonf6544492015-01-26 18:03:04 +02001390 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001391 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001392 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001393 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1394 hangcheck_action_to_str(engine->hangcheck.action),
1395 engine->hangcheck.action,
1396 jiffies_to_msecs(jiffies -
1397 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001398
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001399 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001400 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001401
Ben Widawskyd6369512016-09-20 16:54:32 +03001402 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001403
Ben Widawskyd6369512016-09-20 16:54:32 +03001404 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001405
Ben Widawskyd6369512016-09-20 16:54:32 +03001406 i915_instdone_info(dev_priv, m,
1407 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001408 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001409 }
1410
1411 return 0;
1412}
1413
Ben Widawsky4d855292011-12-12 19:34:16 -08001414static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001415{
David Weinehall36cdd012016-08-22 13:59:31 +03001416 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001417 u32 rgvmodectl, rstdbyctl;
1418 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001419
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001420 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001421
1422 rgvmodectl = I915_READ(MEMMODECTL);
1423 rstdbyctl = I915_READ(RSTDBYCTL);
1424 crstandvid = I915_READ16(CRSTANDVID);
1425
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001426 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001427
Jani Nikula742f4912015-09-03 11:16:09 +03001428 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001429 seq_printf(m, "Boost freq: %d\n",
1430 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1431 MEMMODE_BOOST_FREQ_SHIFT);
1432 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001433 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001434 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001435 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001436 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001437 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001438 seq_printf(m, "Starting frequency: P%d\n",
1439 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001440 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001441 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001442 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1443 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1444 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1445 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001446 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 switch (rstdbyctl & RSX_STATUS_MASK) {
1449 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001457 break;
1458 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001459 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001460 break;
1461 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001462 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001463 break;
1464 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001465 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001466 break;
1467 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001468 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001469 break;
1470 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001471
1472 return 0;
1473}
1474
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001475static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001476{
David Weinehall36cdd012016-08-22 13:59:31 +03001477 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001478 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001479
1480 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001481 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001482 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001483 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001484 fw_domain->wake_count);
1485 }
1486 spin_unlock_irq(&dev_priv->uncore.lock);
1487
1488 return 0;
1489}
1490
Deepak S669ab5a2014-01-10 15:18:26 +05301491static int vlv_drpc_info(struct seq_file *m)
1492{
David Weinehall36cdd012016-08-22 13:59:31 +03001493 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001494 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301495
Imre Deakd46c0512014-04-14 20:24:27 +03001496 intel_runtime_pm_get(dev_priv);
1497
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001498 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301499 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1500 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1501
Imre Deakd46c0512014-04-14 20:24:27 +03001502 intel_runtime_pm_put(dev_priv);
1503
Deepak S669ab5a2014-01-10 15:18:26 +05301504 seq_printf(m, "Video Turbo Mode: %s\n",
1505 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1506 seq_printf(m, "Turbo enabled: %s\n",
1507 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1508 seq_printf(m, "HW control enabled: %s\n",
1509 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1510 seq_printf(m, "SW control enabled: %s\n",
1511 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1512 GEN6_RP_MEDIA_SW_MODE));
1513 seq_printf(m, "RC6 Enabled: %s\n",
1514 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1515 GEN6_RC_CTL_EI_MODE(1))));
1516 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001517 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301518 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001519 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301520
Imre Deak9cc19be2014-04-14 20:24:24 +03001521 seq_printf(m, "Render RC6 residency since boot: %u\n",
1522 I915_READ(VLV_GT_RENDER_RC6));
1523 seq_printf(m, "Media RC6 residency since boot: %u\n",
1524 I915_READ(VLV_GT_MEDIA_RC6));
1525
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001526 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301527}
1528
Ben Widawsky4d855292011-12-12 19:34:16 -08001529static int gen6_drpc_info(struct seq_file *m)
1530{
David Weinehall36cdd012016-08-22 13:59:31 +03001531 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1532 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001533 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301534 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001535 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001536 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001537
1538 ret = mutex_lock_interruptible(&dev->struct_mutex);
1539 if (ret)
1540 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001541 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001542
Chris Wilson907b28c2013-07-19 20:36:52 +01001543 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001544 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001545 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001546
1547 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001548 seq_puts(m, "RC information inaccurate because somebody "
1549 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001550 } else {
1551 /* NB: we cannot use forcewake, else we read the wrong values */
1552 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1553 udelay(10);
1554 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1555 }
1556
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001557 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001558 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001559
1560 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1561 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001562 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301563 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1564 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1565 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001566 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001567 mutex_lock(&dev_priv->rps.hw_lock);
1568 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1569 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001570
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001571 intel_runtime_pm_put(dev_priv);
1572
Ben Widawsky4d855292011-12-12 19:34:16 -08001573 seq_printf(m, "Video Turbo Mode: %s\n",
1574 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1575 seq_printf(m, "HW control enabled: %s\n",
1576 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1577 seq_printf(m, "SW control enabled: %s\n",
1578 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1579 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001580 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001581 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1582 seq_printf(m, "RC6 Enabled: %s\n",
1583 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001584 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301585 seq_printf(m, "Render Well Gating Enabled: %s\n",
1586 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1587 seq_printf(m, "Media Well Gating Enabled: %s\n",
1588 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1589 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001590 seq_printf(m, "Deep RC6 Enabled: %s\n",
1591 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1592 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1593 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001594 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001595 switch (gt_core_status & GEN6_RCn_MASK) {
1596 case GEN6_RC0:
1597 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001598 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001599 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001600 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001601 break;
1602 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001603 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001604 break;
1605 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001606 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001607 break;
1608 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001609 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001610 break;
1611 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001612 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001613 break;
1614 }
1615
1616 seq_printf(m, "Core Power Down: %s\n",
1617 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001618 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301619 seq_printf(m, "Render Power Well: %s\n",
1620 (gen9_powergate_status &
1621 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1622 seq_printf(m, "Media Power Well: %s\n",
1623 (gen9_powergate_status &
1624 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1625 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001626
1627 /* Not exactly sure what this is */
1628 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1629 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1630 seq_printf(m, "RC6 residency since boot: %u\n",
1631 I915_READ(GEN6_GT_GFX_RC6));
1632 seq_printf(m, "RC6+ residency since boot: %u\n",
1633 I915_READ(GEN6_GT_GFX_RC6p));
1634 seq_printf(m, "RC6++ residency since boot: %u\n",
1635 I915_READ(GEN6_GT_GFX_RC6pp));
1636
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001637 seq_printf(m, "RC6 voltage: %dmV\n",
1638 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1639 seq_printf(m, "RC6+ voltage: %dmV\n",
1640 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1641 seq_printf(m, "RC6++ voltage: %dmV\n",
1642 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301643 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001644}
1645
1646static int i915_drpc_info(struct seq_file *m, void *unused)
1647{
David Weinehall36cdd012016-08-22 13:59:31 +03001648 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001649
David Weinehall36cdd012016-08-22 13:59:31 +03001650 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301651 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001652 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001653 return gen6_drpc_info(m);
1654 else
1655 return ironlake_drpc_info(m);
1656}
1657
Daniel Vetter9a851782015-06-18 10:30:22 +02001658static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1659{
David Weinehall36cdd012016-08-22 13:59:31 +03001660 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001661
1662 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1663 dev_priv->fb_tracking.busy_bits);
1664
1665 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1666 dev_priv->fb_tracking.flip_bits);
1667
1668 return 0;
1669}
1670
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001671static int i915_fbc_status(struct seq_file *m, void *unused)
1672{
David Weinehall36cdd012016-08-22 13:59:31 +03001673 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001674
David Weinehall36cdd012016-08-22 13:59:31 +03001675 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001676 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001677 return 0;
1678 }
1679
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001680 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001681 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001682
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001683 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001684 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001685 else
1686 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001687 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001688
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001689 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1690 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1691 BDW_FBC_COMPRESSION_MASK :
1692 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001693 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001694 yesno(I915_READ(FBC_STATUS2) & mask));
1695 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001696
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001697 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001698 intel_runtime_pm_put(dev_priv);
1699
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001700 return 0;
1701}
1702
Rodrigo Vivida46f932014-08-01 02:04:45 -07001703static int i915_fbc_fc_get(void *data, u64 *val)
1704{
David Weinehall36cdd012016-08-22 13:59:31 +03001705 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001706
David Weinehall36cdd012016-08-22 13:59:31 +03001707 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001708 return -ENODEV;
1709
Rodrigo Vivida46f932014-08-01 02:04:45 -07001710 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001711
1712 return 0;
1713}
1714
1715static int i915_fbc_fc_set(void *data, u64 val)
1716{
David Weinehall36cdd012016-08-22 13:59:31 +03001717 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001718 u32 reg;
1719
David Weinehall36cdd012016-08-22 13:59:31 +03001720 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001721 return -ENODEV;
1722
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001723 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001724
1725 reg = I915_READ(ILK_DPFC_CONTROL);
1726 dev_priv->fbc.false_color = val;
1727
1728 I915_WRITE(ILK_DPFC_CONTROL, val ?
1729 (reg | FBC_CTL_FALSE_COLOR) :
1730 (reg & ~FBC_CTL_FALSE_COLOR));
1731
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001732 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001733 return 0;
1734}
1735
1736DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1737 i915_fbc_fc_get, i915_fbc_fc_set,
1738 "%llu\n");
1739
Paulo Zanoni92d44622013-05-31 16:33:24 -03001740static int i915_ips_status(struct seq_file *m, void *unused)
1741{
David Weinehall36cdd012016-08-22 13:59:31 +03001742 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001743
David Weinehall36cdd012016-08-22 13:59:31 +03001744 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001745 seq_puts(m, "not supported\n");
1746 return 0;
1747 }
1748
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001749 intel_runtime_pm_get(dev_priv);
1750
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001751 seq_printf(m, "Enabled by kernel parameter: %s\n",
1752 yesno(i915.enable_ips));
1753
David Weinehall36cdd012016-08-22 13:59:31 +03001754 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001755 seq_puts(m, "Currently: unknown\n");
1756 } else {
1757 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1758 seq_puts(m, "Currently: enabled\n");
1759 else
1760 seq_puts(m, "Currently: disabled\n");
1761 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001762
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001763 intel_runtime_pm_put(dev_priv);
1764
Paulo Zanoni92d44622013-05-31 16:33:24 -03001765 return 0;
1766}
1767
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001768static int i915_sr_status(struct seq_file *m, void *unused)
1769{
David Weinehall36cdd012016-08-22 13:59:31 +03001770 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001771 bool sr_enabled = false;
1772
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001773 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001774 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001775
David Weinehall36cdd012016-08-22 13:59:31 +03001776 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001777 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001778 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001779 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001780 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001781 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001782 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001783 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001784 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001785 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001786 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001787
Chris Wilson9c870d02016-10-24 13:42:15 +01001788 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001789 intel_runtime_pm_put(dev_priv);
1790
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001791 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001792
1793 return 0;
1794}
1795
Jesse Barnes7648fa92010-05-20 14:28:11 -07001796static int i915_emon_status(struct seq_file *m, void *unused)
1797{
David Weinehall36cdd012016-08-22 13:59:31 +03001798 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1799 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001800 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001801 int ret;
1802
David Weinehall36cdd012016-08-22 13:59:31 +03001803 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001804 return -ENODEV;
1805
Chris Wilsonde227ef2010-07-03 07:58:38 +01001806 ret = mutex_lock_interruptible(&dev->struct_mutex);
1807 if (ret)
1808 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001809
1810 temp = i915_mch_val(dev_priv);
1811 chipset = i915_chipset_val(dev_priv);
1812 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001813 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001814
1815 seq_printf(m, "GMCH temp: %ld\n", temp);
1816 seq_printf(m, "Chipset power: %ld\n", chipset);
1817 seq_printf(m, "GFX power: %ld\n", gfx);
1818 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1819
1820 return 0;
1821}
1822
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001823static int i915_ring_freq_table(struct seq_file *m, void *unused)
1824{
David Weinehall36cdd012016-08-22 13:59:31 +03001825 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001826 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301828 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001829
Carlos Santa26310342016-08-17 12:30:41 -07001830 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001831 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001832 return 0;
1833 }
1834
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001835 intel_runtime_pm_get(dev_priv);
1836
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001837 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001838 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001839 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001840
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001841 if (IS_GEN9_BC(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301842 /* Convert GT frequency to 50 HZ units */
1843 min_gpu_freq =
1844 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1845 max_gpu_freq =
1846 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1847 } else {
1848 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1849 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1850 }
1851
Damien Lespiau267f0c92013-06-24 22:59:48 +01001852 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001853
Akash Goelf936ec32015-06-29 14:50:22 +05301854 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001855 ia_freq = gpu_freq;
1856 sandybridge_pcode_read(dev_priv,
1857 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1858 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001859 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301860 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001861 (IS_GEN9_BC(dev_priv) ?
1862 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001863 ((ia_freq >> 0) & 0xff) * 100,
1864 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001865 }
1866
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001867 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001868
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001869out:
1870 intel_runtime_pm_put(dev_priv);
1871 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001872}
1873
Chris Wilson44834a62010-08-19 16:09:23 +01001874static int i915_opregion(struct seq_file *m, void *unused)
1875{
David Weinehall36cdd012016-08-22 13:59:31 +03001876 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1877 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001878 struct intel_opregion *opregion = &dev_priv->opregion;
1879 int ret;
1880
1881 ret = mutex_lock_interruptible(&dev->struct_mutex);
1882 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001883 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001884
Jani Nikula2455a8e2015-12-14 12:50:53 +02001885 if (opregion->header)
1886 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001887
1888 mutex_unlock(&dev->struct_mutex);
1889
Daniel Vetter0d38f002012-04-21 22:49:10 +02001890out:
Chris Wilson44834a62010-08-19 16:09:23 +01001891 return 0;
1892}
1893
Jani Nikulaada8f952015-12-15 13:17:12 +02001894static int i915_vbt(struct seq_file *m, void *unused)
1895{
David Weinehall36cdd012016-08-22 13:59:31 +03001896 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001897
1898 if (opregion->vbt)
1899 seq_write(m, opregion->vbt, opregion->vbt_size);
1900
1901 return 0;
1902}
1903
Chris Wilson37811fc2010-08-25 22:45:57 +01001904static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1905{
David Weinehall36cdd012016-08-22 13:59:31 +03001906 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1907 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301908 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001909 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001910 int ret;
1911
1912 ret = mutex_lock_interruptible(&dev->struct_mutex);
1913 if (ret)
1914 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001915
Daniel Vetter06957262015-08-10 13:34:08 +02001916#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001917 if (dev_priv->fbdev) {
1918 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001919
Chris Wilson25bcce92016-07-02 15:36:00 +01001920 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1921 fbdev_fb->base.width,
1922 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001923 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001924 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001925 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001926 drm_framebuffer_read_refcount(&fbdev_fb->base));
1927 describe_obj(m, fbdev_fb->obj);
1928 seq_putc(m, '\n');
1929 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001930#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001931
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001932 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001933 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301934 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1935 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001936 continue;
1937
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001938 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 +01001939 fb->base.width,
1940 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001941 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001942 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001943 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001944 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001945 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001946 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001947 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001948 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001949 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001950
1951 return 0;
1952}
1953
Chris Wilson7e37f882016-08-02 22:50:21 +01001954static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001955{
1956 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001957 ring->space, ring->head, ring->tail,
1958 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001959}
1960
Ben Widawskye76d3632011-03-19 18:14:29 -07001961static int i915_context_status(struct seq_file *m, void *unused)
1962{
David Weinehall36cdd012016-08-22 13:59:31 +03001963 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1964 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001965 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001966 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301967 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001968 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001969
Daniel Vetterf3d28872014-05-29 23:23:08 +02001970 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001971 if (ret)
1972 return ret;
1973
Ben Widawskya33afea2013-09-17 21:12:45 -07001974 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001975 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001976 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001977 struct task_struct *task;
1978
Chris Wilsonc84455b2016-08-15 10:49:08 +01001979 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001980 if (task) {
1981 seq_printf(m, "(%s [%d]) ",
1982 task->comm, task->pid);
1983 put_task_struct(task);
1984 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001985 } else if (IS_ERR(ctx->file_priv)) {
1986 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001987 } else {
1988 seq_puts(m, "(kernel) ");
1989 }
1990
Chris Wilsonbca44d82016-05-24 14:53:41 +01001991 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1992 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001993
Akash Goel3b3f1652016-10-13 22:44:48 +05301994 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001995 struct intel_context *ce = &ctx->engine[engine->id];
1996
1997 seq_printf(m, "%s: ", engine->name);
1998 seq_putc(m, ce->initialised ? 'I' : 'i');
1999 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002000 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01002001 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01002002 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002003 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002004 }
2005
Ben Widawskya33afea2013-09-17 21:12:45 -07002006 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002007 }
2008
Daniel Vetterf3d28872014-05-29 23:23:08 +02002009 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002010
2011 return 0;
2012}
2013
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002014static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002015 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002016 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002017{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002018 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002019 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002020 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002021
Chris Wilson7069b142016-04-28 09:56:52 +01002022 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2023
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002024 if (!vma) {
2025 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002026 return;
2027 }
2028
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002029 if (vma->flags & I915_VMA_GLOBAL_BIND)
2030 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002031 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002032
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002033 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002034 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002035 return;
2036 }
2037
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002038 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2039 if (page) {
2040 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002041
2042 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002043 seq_printf(m,
2044 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2045 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002046 reg_state[j], reg_state[j + 1],
2047 reg_state[j + 2], reg_state[j + 3]);
2048 }
2049 kunmap_atomic(reg_state);
2050 }
2051
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002052 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002053 seq_putc(m, '\n');
2054}
2055
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002056static int i915_dump_lrc(struct seq_file *m, void *unused)
2057{
David Weinehall36cdd012016-08-22 13:59:31 +03002058 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2059 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002060 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002061 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302062 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002063 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002064
2065 if (!i915.enable_execlists) {
2066 seq_printf(m, "Logical Ring Contexts are disabled\n");
2067 return 0;
2068 }
2069
2070 ret = mutex_lock_interruptible(&dev->struct_mutex);
2071 if (ret)
2072 return ret;
2073
Dave Gordone28e4042016-01-19 19:02:55 +00002074 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302075 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002076 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002077
2078 mutex_unlock(&dev->struct_mutex);
2079
2080 return 0;
2081}
2082
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002083static const char *swizzle_string(unsigned swizzle)
2084{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002085 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002086 case I915_BIT_6_SWIZZLE_NONE:
2087 return "none";
2088 case I915_BIT_6_SWIZZLE_9:
2089 return "bit9";
2090 case I915_BIT_6_SWIZZLE_9_10:
2091 return "bit9/bit10";
2092 case I915_BIT_6_SWIZZLE_9_11:
2093 return "bit9/bit11";
2094 case I915_BIT_6_SWIZZLE_9_10_11:
2095 return "bit9/bit10/bit11";
2096 case I915_BIT_6_SWIZZLE_9_17:
2097 return "bit9/bit17";
2098 case I915_BIT_6_SWIZZLE_9_10_17:
2099 return "bit9/bit10/bit17";
2100 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002101 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002102 }
2103
2104 return "bug";
2105}
2106
2107static int i915_swizzle_info(struct seq_file *m, void *data)
2108{
David Weinehall36cdd012016-08-22 13:59:31 +03002109 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002110
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002111 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002112
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002113 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2114 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2115 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2116 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2117
David Weinehall36cdd012016-08-22 13:59:31 +03002118 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002119 seq_printf(m, "DDC = 0x%08x\n",
2120 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002121 seq_printf(m, "DDC2 = 0x%08x\n",
2122 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002123 seq_printf(m, "C0DRB3 = 0x%04x\n",
2124 I915_READ16(C0DRB3));
2125 seq_printf(m, "C1DRB3 = 0x%04x\n",
2126 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002127 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002128 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2129 I915_READ(MAD_DIMM_C0));
2130 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2131 I915_READ(MAD_DIMM_C1));
2132 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2133 I915_READ(MAD_DIMM_C2));
2134 seq_printf(m, "TILECTL = 0x%08x\n",
2135 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002136 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002137 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2138 I915_READ(GAMTARBMODE));
2139 else
2140 seq_printf(m, "ARB_MODE = 0x%08x\n",
2141 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002142 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2143 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002144 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002145
2146 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2147 seq_puts(m, "L-shaped memory detected\n");
2148
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002149 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002150
2151 return 0;
2152}
2153
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002154static int per_file_ctx(int id, void *ptr, void *data)
2155{
Chris Wilsone2efd132016-05-24 14:53:34 +01002156 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002157 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002158 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2159
2160 if (!ppgtt) {
2161 seq_printf(m, " no ppgtt for context %d\n",
2162 ctx->user_handle);
2163 return 0;
2164 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002165
Oscar Mateof83d6512014-05-22 14:13:38 +01002166 if (i915_gem_context_is_default(ctx))
2167 seq_puts(m, " default context:\n");
2168 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002169 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002170 ppgtt->debug_dump(ppgtt, m);
2171
2172 return 0;
2173}
2174
David Weinehall36cdd012016-08-22 13:59:31 +03002175static void gen8_ppgtt_info(struct seq_file *m,
2176 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002177{
Ben Widawsky77df6772013-11-02 21:07:30 -07002178 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302179 struct intel_engine_cs *engine;
2180 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002181 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002182
Ben Widawsky77df6772013-11-02 21:07:30 -07002183 if (!ppgtt)
2184 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002185
Akash Goel3b3f1652016-10-13 22:44:48 +05302186 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002187 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002188 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002189 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002190 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002191 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002192 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002193 }
2194 }
2195}
2196
David Weinehall36cdd012016-08-22 13:59:31 +03002197static void gen6_ppgtt_info(struct seq_file *m,
2198 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002199{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002200 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302201 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002202
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002203 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002204 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2205
Akash Goel3b3f1652016-10-13 22:44:48 +05302206 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002207 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002208 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002209 seq_printf(m, "GFX_MODE: 0x%08x\n",
2210 I915_READ(RING_MODE_GEN7(engine)));
2211 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2212 I915_READ(RING_PP_DIR_BASE(engine)));
2213 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2214 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2215 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2216 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002217 }
2218 if (dev_priv->mm.aliasing_ppgtt) {
2219 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2220
Damien Lespiau267f0c92013-06-24 22:59:48 +01002221 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002222 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002223
Ben Widawsky87d60b62013-12-06 14:11:29 -08002224 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002225 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002226
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002227 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002228}
2229
2230static int i915_ppgtt_info(struct seq_file *m, void *data)
2231{
David Weinehall36cdd012016-08-22 13:59:31 +03002232 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2233 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002234 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002235 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002236
Chris Wilson637ee292016-08-22 14:28:20 +01002237 mutex_lock(&dev->filelist_mutex);
2238 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002239 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002240 goto out_unlock;
2241
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002242 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002243
David Weinehall36cdd012016-08-22 13:59:31 +03002244 if (INTEL_GEN(dev_priv) >= 8)
2245 gen8_ppgtt_info(m, dev_priv);
2246 else if (INTEL_GEN(dev_priv) >= 6)
2247 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002248
Michel Thierryea91e402015-07-29 17:23:57 +01002249 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2250 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002251 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002252
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002253 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002254 if (!task) {
2255 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002256 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002257 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002258 seq_printf(m, "\nproc: %s\n", task->comm);
2259 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002260 idr_for_each(&file_priv->context_idr, per_file_ctx,
2261 (void *)(unsigned long)m);
2262 }
2263
Chris Wilson637ee292016-08-22 14:28:20 +01002264out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002265 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002266 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002267out_unlock:
2268 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002269 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002270}
2271
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002272static int count_irq_waiters(struct drm_i915_private *i915)
2273{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002274 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302275 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002276 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002277
Akash Goel3b3f1652016-10-13 22:44:48 +05302278 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002279 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002280
2281 return count;
2282}
2283
Chris Wilson7466c292016-08-15 09:49:33 +01002284static const char *rps_power_to_str(unsigned int power)
2285{
2286 static const char * const strings[] = {
2287 [LOW_POWER] = "low power",
2288 [BETWEEN] = "mixed",
2289 [HIGH_POWER] = "high power",
2290 };
2291
2292 if (power >= ARRAY_SIZE(strings) || !strings[power])
2293 return "unknown";
2294
2295 return strings[power];
2296}
2297
Chris Wilson1854d5c2015-04-07 16:20:32 +01002298static int i915_rps_boost_info(struct seq_file *m, void *data)
2299{
David Weinehall36cdd012016-08-22 13:59:31 +03002300 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2301 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002302 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002303
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002304 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002305 seq_printf(m, "GPU busy? %s [%d requests]\n",
2306 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002307 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002308 seq_printf(m, "Frequency requested %d\n",
2309 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2310 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002311 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2312 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2313 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2314 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002315 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2316 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2317 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2318 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002319
2320 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002321 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002322 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2323 struct drm_i915_file_private *file_priv = file->driver_priv;
2324 struct task_struct *task;
2325
2326 rcu_read_lock();
2327 task = pid_task(file->pid, PIDTYPE_PID);
2328 seq_printf(m, "%s [%d]: %d boosts%s\n",
2329 task ? task->comm : "<unknown>",
2330 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002331 file_priv->rps.boosts,
2332 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002333 rcu_read_unlock();
2334 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002335 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002336 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002337 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002338
Chris Wilson7466c292016-08-15 09:49:33 +01002339 if (INTEL_GEN(dev_priv) >= 6 &&
2340 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002341 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002342 u32 rpup, rpupei;
2343 u32 rpdown, rpdownei;
2344
2345 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2346 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2347 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2348 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2349 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2350 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2351
2352 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2353 rps_power_to_str(dev_priv->rps.power));
2354 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002355 rpup && rpupei ? 100 * rpup / rpupei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002356 dev_priv->rps.up_threshold);
2357 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002358 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002359 dev_priv->rps.down_threshold);
2360 } else {
2361 seq_puts(m, "\nRPS Autotuning inactive\n");
2362 }
2363
Chris Wilson8d3afd72015-05-21 21:01:47 +01002364 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002365}
2366
Ben Widawsky63573eb2013-07-04 11:02:07 -07002367static int i915_llc(struct seq_file *m, void *data)
2368{
David Weinehall36cdd012016-08-22 13:59:31 +03002369 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002370 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002371
David Weinehall36cdd012016-08-22 13:59:31 +03002372 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002373 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2374 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002375
2376 return 0;
2377}
2378
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002379static int i915_huc_load_status_info(struct seq_file *m, void *data)
2380{
2381 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2382 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2383
2384 if (!HAS_HUC_UCODE(dev_priv))
2385 return 0;
2386
2387 seq_puts(m, "HuC firmware status:\n");
2388 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2389 seq_printf(m, "\tfetch: %s\n",
2390 intel_uc_fw_status_repr(huc_fw->fetch_status));
2391 seq_printf(m, "\tload: %s\n",
2392 intel_uc_fw_status_repr(huc_fw->load_status));
2393 seq_printf(m, "\tversion wanted: %d.%d\n",
2394 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2395 seq_printf(m, "\tversion found: %d.%d\n",
2396 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2397 seq_printf(m, "\theader: offset is %d; size = %d\n",
2398 huc_fw->header_offset, huc_fw->header_size);
2399 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2400 huc_fw->ucode_offset, huc_fw->ucode_size);
2401 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2402 huc_fw->rsa_offset, huc_fw->rsa_size);
2403
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302404 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002405 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302406 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002407
2408 return 0;
2409}
2410
Alex Daifdf5d352015-08-12 15:43:37 +01002411static int i915_guc_load_status_info(struct seq_file *m, void *data)
2412{
David Weinehall36cdd012016-08-22 13:59:31 +03002413 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002414 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Daifdf5d352015-08-12 15:43:37 +01002415 u32 tmp, i;
2416
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002417 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002418 return 0;
2419
2420 seq_printf(m, "GuC firmware status:\n");
2421 seq_printf(m, "\tpath: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002422 guc_fw->path);
Alex Daifdf5d352015-08-12 15:43:37 +01002423 seq_printf(m, "\tfetch: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002424 intel_uc_fw_status_repr(guc_fw->fetch_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002425 seq_printf(m, "\tload: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002426 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002427 seq_printf(m, "\tversion wanted: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002428 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
Alex Daifdf5d352015-08-12 15:43:37 +01002429 seq_printf(m, "\tversion found: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002430 guc_fw->major_ver_found, guc_fw->minor_ver_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002431 seq_printf(m, "\theader: offset is %d; size = %d\n",
2432 guc_fw->header_offset, guc_fw->header_size);
2433 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2434 guc_fw->ucode_offset, guc_fw->ucode_size);
2435 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2436 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002437
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302438 intel_runtime_pm_get(dev_priv);
2439
Alex Daifdf5d352015-08-12 15:43:37 +01002440 tmp = I915_READ(GUC_STATUS);
2441
2442 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2443 seq_printf(m, "\tBootrom status = 0x%x\n",
2444 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2445 seq_printf(m, "\tuKernel status = 0x%x\n",
2446 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2447 seq_printf(m, "\tMIA Core status = 0x%x\n",
2448 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2449 seq_puts(m, "\nScratch registers:\n");
2450 for (i = 0; i < 16; i++)
2451 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2452
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302453 intel_runtime_pm_put(dev_priv);
2454
Alex Daifdf5d352015-08-12 15:43:37 +01002455 return 0;
2456}
2457
Akash Goel5aa1ee42016-10-12 21:54:36 +05302458static void i915_guc_log_info(struct seq_file *m,
2459 struct drm_i915_private *dev_priv)
2460{
2461 struct intel_guc *guc = &dev_priv->guc;
2462
2463 seq_puts(m, "\nGuC logging stats:\n");
2464
2465 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2466 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2467 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2468
2469 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2470 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2471 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2472
2473 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2474 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2475 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2476
2477 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2478 guc->log.flush_interrupt_count);
2479
2480 seq_printf(m, "\tCapture miss count: %u\n",
2481 guc->log.capture_miss_count);
2482}
2483
Dave Gordon8b417c22015-08-12 15:43:44 +01002484static void i915_guc_client_info(struct seq_file *m,
2485 struct drm_i915_private *dev_priv,
2486 struct i915_guc_client *client)
2487{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002488 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002489 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002490 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002491
2492 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2493 client->priority, client->ctx_index, client->proc_desc_offset);
2494 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002495 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002496 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2497 client->wq_size, client->wq_offset, client->wq_tail);
2498
Dave Gordon551aaec2016-05-13 15:36:33 +01002499 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002500 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2501 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2502
Akash Goel3b3f1652016-10-13 22:44:48 +05302503 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002504 u64 submissions = client->submissions[id];
2505 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002506 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002507 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002508 }
2509 seq_printf(m, "\tTotal: %llu\n", tot);
2510}
2511
2512static int i915_guc_info(struct seq_file *m, void *data)
2513{
David Weinehall36cdd012016-08-22 13:59:31 +03002514 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002515 const struct intel_guc *guc = &dev_priv->guc;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002516 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002517 enum intel_engine_id id;
Chris Wilson334636c2016-11-29 12:10:20 +00002518 u64 total;
Dave Gordon8b417c22015-08-12 15:43:44 +01002519
Chris Wilson334636c2016-11-29 12:10:20 +00002520 if (!guc->execbuf_client) {
2521 seq_printf(m, "GuC submission %s\n",
2522 HAS_GUC_SCHED(dev_priv) ?
2523 "disabled" :
2524 "not supported");
Dave Gordon8b417c22015-08-12 15:43:44 +01002525 return 0;
Chris Wilson334636c2016-11-29 12:10:20 +00002526 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002527
Dave Gordon9636f6d2016-06-13 17:57:28 +01002528 seq_printf(m, "Doorbell map:\n");
Chris Wilson334636c2016-11-29 12:10:20 +00002529 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc->doorbell_bitmap);
2530 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002531
Chris Wilson334636c2016-11-29 12:10:20 +00002532 seq_printf(m, "GuC total action count: %llu\n", guc->action_count);
2533 seq_printf(m, "GuC action failure count: %u\n", guc->action_fail);
2534 seq_printf(m, "GuC last action command: 0x%x\n", guc->action_cmd);
2535 seq_printf(m, "GuC last action status: 0x%x\n", guc->action_status);
2536 seq_printf(m, "GuC last action error code: %d\n", guc->action_err);
Dave Gordon8b417c22015-08-12 15:43:44 +01002537
Chris Wilson334636c2016-11-29 12:10:20 +00002538 total = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002539 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302540 for_each_engine(engine, dev_priv, id) {
Chris Wilson334636c2016-11-29 12:10:20 +00002541 u64 submissions = guc->submissions[id];
Dave Gordonc18468c2016-08-09 15:19:22 +01002542 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002543 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Chris Wilson334636c2016-11-29 12:10:20 +00002544 engine->name, submissions, guc->last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002545 }
2546 seq_printf(m, "\t%s: %llu\n", "Total", total);
2547
Chris Wilson334636c2016-11-29 12:10:20 +00002548 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2549 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002550
Akash Goel5aa1ee42016-10-12 21:54:36 +05302551 i915_guc_log_info(m, dev_priv);
2552
Dave Gordon8b417c22015-08-12 15:43:44 +01002553 /* Add more as required ... */
2554
2555 return 0;
2556}
2557
Alex Dai4c7e77f2015-08-12 15:43:40 +01002558static int i915_guc_log_dump(struct seq_file *m, void *data)
2559{
David Weinehall36cdd012016-08-22 13:59:31 +03002560 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002561 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002562 int i = 0, pg;
2563
Akash Goeld6b40b42016-10-12 21:54:29 +05302564 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002565 return 0;
2566
Akash Goeld6b40b42016-10-12 21:54:29 +05302567 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002568 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2569 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002570
2571 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2572 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2573 *(log + i), *(log + i + 1),
2574 *(log + i + 2), *(log + i + 3));
2575
2576 kunmap_atomic(log);
2577 }
2578
2579 seq_putc(m, '\n');
2580
2581 return 0;
2582}
2583
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302584static int i915_guc_log_control_get(void *data, u64 *val)
2585{
2586 struct drm_device *dev = data;
2587 struct drm_i915_private *dev_priv = to_i915(dev);
2588
2589 if (!dev_priv->guc.log.vma)
2590 return -EINVAL;
2591
2592 *val = i915.guc_log_level;
2593
2594 return 0;
2595}
2596
2597static int i915_guc_log_control_set(void *data, u64 val)
2598{
2599 struct drm_device *dev = data;
2600 struct drm_i915_private *dev_priv = to_i915(dev);
2601 int ret;
2602
2603 if (!dev_priv->guc.log.vma)
2604 return -EINVAL;
2605
2606 ret = mutex_lock_interruptible(&dev->struct_mutex);
2607 if (ret)
2608 return ret;
2609
2610 intel_runtime_pm_get(dev_priv);
2611 ret = i915_guc_log_control(dev_priv, val);
2612 intel_runtime_pm_put(dev_priv);
2613
2614 mutex_unlock(&dev->struct_mutex);
2615 return ret;
2616}
2617
2618DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2619 i915_guc_log_control_get, i915_guc_log_control_set,
2620 "%lld\n");
2621
Chris Wilsonb86bef202017-01-16 13:06:21 +00002622static const char *psr2_live_status(u32 val)
2623{
2624 static const char * const live_status[] = {
2625 "IDLE",
2626 "CAPTURE",
2627 "CAPTURE_FS",
2628 "SLEEP",
2629 "BUFON_FW",
2630 "ML_UP",
2631 "SU_STANDBY",
2632 "FAST_SLEEP",
2633 "DEEP_SLEEP",
2634 "BUF_ON",
2635 "TG_ON"
2636 };
2637
2638 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2639 if (val < ARRAY_SIZE(live_status))
2640 return live_status[val];
2641
2642 return "unknown";
2643}
2644
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002645static int i915_edp_psr_status(struct seq_file *m, void *data)
2646{
David Weinehall36cdd012016-08-22 13:59:31 +03002647 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002648 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002649 u32 stat[3];
2650 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002651 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002652
David Weinehall36cdd012016-08-22 13:59:31 +03002653 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002654 seq_puts(m, "PSR not supported\n");
2655 return 0;
2656 }
2657
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002658 intel_runtime_pm_get(dev_priv);
2659
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002660 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002661 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2662 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002663 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002664 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002665 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2666 dev_priv->psr.busy_frontbuffer_bits);
2667 seq_printf(m, "Re-enable work scheduled: %s\n",
2668 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002669
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302670 if (HAS_DDI(dev_priv)) {
2671 if (dev_priv->psr.psr2_support)
2672 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2673 else
2674 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2675 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002676 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002677 enum transcoder cpu_transcoder =
2678 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2679 enum intel_display_power_domain power_domain;
2680
2681 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2682 if (!intel_display_power_get_if_enabled(dev_priv,
2683 power_domain))
2684 continue;
2685
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002686 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2687 VLV_EDP_PSR_CURR_STATE_MASK;
2688 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2689 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2690 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002691
2692 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002693 }
2694 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002695
2696 seq_printf(m, "Main link in standby mode: %s\n",
2697 yesno(dev_priv->psr.link_standby));
2698
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002699 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002700
David Weinehall36cdd012016-08-22 13:59:31 +03002701 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002702 for_each_pipe(dev_priv, pipe) {
2703 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2704 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2705 seq_printf(m, " pipe %c", pipe_name(pipe));
2706 }
2707 seq_puts(m, "\n");
2708
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002709 /*
2710 * VLV/CHV PSR has no kind of performance counter
2711 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2712 */
David Weinehall36cdd012016-08-22 13:59:31 +03002713 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002714 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002715 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002716
2717 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2718 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302719 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002720 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302721
Chris Wilsonb86bef202017-01-16 13:06:21 +00002722 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2723 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302724 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002725 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002726
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002727 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002728 return 0;
2729}
2730
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002731static int i915_sink_crc(struct seq_file *m, void *data)
2732{
David Weinehall36cdd012016-08-22 13:59:31 +03002733 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2734 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002735 struct intel_connector *connector;
2736 struct intel_dp *intel_dp = NULL;
2737 int ret;
2738 u8 crc[6];
2739
2740 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002741 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002742 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002743
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002744 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002745 continue;
2746
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002747 crtc = connector->base.state->crtc;
2748 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002749 continue;
2750
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002751 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002752 continue;
2753
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002754 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002755
2756 ret = intel_dp_sink_crc(intel_dp, crc);
2757 if (ret)
2758 goto out;
2759
2760 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2761 crc[0], crc[1], crc[2],
2762 crc[3], crc[4], crc[5]);
2763 goto out;
2764 }
2765 ret = -ENODEV;
2766out:
2767 drm_modeset_unlock_all(dev);
2768 return ret;
2769}
2770
Jesse Barnesec013e72013-08-20 10:29:23 +01002771static int i915_energy_uJ(struct seq_file *m, void *data)
2772{
David Weinehall36cdd012016-08-22 13:59:31 +03002773 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002774 u64 power;
2775 u32 units;
2776
David Weinehall36cdd012016-08-22 13:59:31 +03002777 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002778 return -ENODEV;
2779
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002780 intel_runtime_pm_get(dev_priv);
2781
Jesse Barnesec013e72013-08-20 10:29:23 +01002782 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2783 power = (power & 0x1f00) >> 8;
2784 units = 1000000 / (1 << power); /* convert to uJ */
2785 power = I915_READ(MCH_SECP_NRG_STTS);
2786 power *= units;
2787
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002788 intel_runtime_pm_put(dev_priv);
2789
Jesse Barnesec013e72013-08-20 10:29:23 +01002790 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002791
2792 return 0;
2793}
2794
Damien Lespiau6455c872015-06-04 18:23:57 +01002795static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002796{
David Weinehall36cdd012016-08-22 13:59:31 +03002797 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002798 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002799
Chris Wilsona156e642016-04-03 14:14:21 +01002800 if (!HAS_RUNTIME_PM(dev_priv))
2801 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002802
Chris Wilson67d97da2016-07-04 08:08:31 +01002803 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002804 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002805 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002806#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002807 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002808 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002809#else
2810 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2811#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002812 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002813 pci_power_name(pdev->current_state),
2814 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002815
Jesse Barnesec013e72013-08-20 10:29:23 +01002816 return 0;
2817}
2818
Imre Deak1da51582013-11-25 17:15:35 +02002819static int i915_power_domain_info(struct seq_file *m, void *unused)
2820{
David Weinehall36cdd012016-08-22 13:59:31 +03002821 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002822 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2823 int i;
2824
2825 mutex_lock(&power_domains->lock);
2826
2827 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2828 for (i = 0; i < power_domains->power_well_count; i++) {
2829 struct i915_power_well *power_well;
2830 enum intel_display_power_domain power_domain;
2831
2832 power_well = &power_domains->power_wells[i];
2833 seq_printf(m, "%-25s %d\n", power_well->name,
2834 power_well->count);
2835
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002836 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002837 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002838 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002839 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002840 }
2841
2842 mutex_unlock(&power_domains->lock);
2843
2844 return 0;
2845}
2846
Damien Lespiaub7cec662015-10-27 14:47:01 +02002847static int i915_dmc_info(struct seq_file *m, void *unused)
2848{
David Weinehall36cdd012016-08-22 13:59:31 +03002849 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002850 struct intel_csr *csr;
2851
David Weinehall36cdd012016-08-22 13:59:31 +03002852 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002853 seq_puts(m, "not supported\n");
2854 return 0;
2855 }
2856
2857 csr = &dev_priv->csr;
2858
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002859 intel_runtime_pm_get(dev_priv);
2860
Damien Lespiaub7cec662015-10-27 14:47:01 +02002861 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2862 seq_printf(m, "path: %s\n", csr->fw_path);
2863
2864 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002865 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002866
2867 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2868 CSR_VERSION_MINOR(csr->version));
2869
David Weinehall36cdd012016-08-22 13:59:31 +03002870 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002871 seq_printf(m, "DC3 -> DC5 count: %d\n",
2872 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2873 seq_printf(m, "DC5 -> DC6 count: %d\n",
2874 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002875 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002876 seq_printf(m, "DC3 -> DC5 count: %d\n",
2877 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002878 }
2879
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002880out:
2881 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2882 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2883 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2884
Damien Lespiau83372062015-10-30 17:53:32 +02002885 intel_runtime_pm_put(dev_priv);
2886
Damien Lespiaub7cec662015-10-27 14:47:01 +02002887 return 0;
2888}
2889
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002890static void intel_seq_print_mode(struct seq_file *m, int tabs,
2891 struct drm_display_mode *mode)
2892{
2893 int i;
2894
2895 for (i = 0; i < tabs; i++)
2896 seq_putc(m, '\t');
2897
2898 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",
2899 mode->base.id, mode->name,
2900 mode->vrefresh, mode->clock,
2901 mode->hdisplay, mode->hsync_start,
2902 mode->hsync_end, mode->htotal,
2903 mode->vdisplay, mode->vsync_start,
2904 mode->vsync_end, mode->vtotal,
2905 mode->type, mode->flags);
2906}
2907
2908static void intel_encoder_info(struct seq_file *m,
2909 struct intel_crtc *intel_crtc,
2910 struct intel_encoder *intel_encoder)
2911{
David Weinehall36cdd012016-08-22 13:59:31 +03002912 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2913 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002914 struct drm_crtc *crtc = &intel_crtc->base;
2915 struct intel_connector *intel_connector;
2916 struct drm_encoder *encoder;
2917
2918 encoder = &intel_encoder->base;
2919 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002920 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002921 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2922 struct drm_connector *connector = &intel_connector->base;
2923 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2924 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002925 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002926 drm_get_connector_status_name(connector->status));
2927 if (connector->status == connector_status_connected) {
2928 struct drm_display_mode *mode = &crtc->mode;
2929 seq_printf(m, ", mode:\n");
2930 intel_seq_print_mode(m, 2, mode);
2931 } else {
2932 seq_putc(m, '\n');
2933 }
2934 }
2935}
2936
2937static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2938{
David Weinehall36cdd012016-08-22 13:59:31 +03002939 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2940 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002941 struct drm_crtc *crtc = &intel_crtc->base;
2942 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002943 struct drm_plane_state *plane_state = crtc->primary->state;
2944 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002945
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002946 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002947 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002948 fb->base.id, plane_state->src_x >> 16,
2949 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002950 else
2951 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002952 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2953 intel_encoder_info(m, intel_crtc, intel_encoder);
2954}
2955
2956static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2957{
2958 struct drm_display_mode *mode = panel->fixed_mode;
2959
2960 seq_printf(m, "\tfixed mode:\n");
2961 intel_seq_print_mode(m, 2, mode);
2962}
2963
2964static void intel_dp_info(struct seq_file *m,
2965 struct intel_connector *intel_connector)
2966{
2967 struct intel_encoder *intel_encoder = intel_connector->encoder;
2968 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2969
2970 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002971 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002972 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002973 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002974
2975 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2976 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002977}
2978
Libin Yang9a148a92016-11-28 20:07:05 +08002979static void intel_dp_mst_info(struct seq_file *m,
2980 struct intel_connector *intel_connector)
2981{
2982 struct intel_encoder *intel_encoder = intel_connector->encoder;
2983 struct intel_dp_mst_encoder *intel_mst =
2984 enc_to_mst(&intel_encoder->base);
2985 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2986 struct intel_dp *intel_dp = &intel_dig_port->dp;
2987 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2988 intel_connector->port);
2989
2990 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2991}
2992
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002993static void intel_hdmi_info(struct seq_file *m,
2994 struct intel_connector *intel_connector)
2995{
2996 struct intel_encoder *intel_encoder = intel_connector->encoder;
2997 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2998
Jani Nikula742f4912015-09-03 11:16:09 +03002999 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003000}
3001
3002static void intel_lvds_info(struct seq_file *m,
3003 struct intel_connector *intel_connector)
3004{
3005 intel_panel_info(m, &intel_connector->panel);
3006}
3007
3008static void intel_connector_info(struct seq_file *m,
3009 struct drm_connector *connector)
3010{
3011 struct intel_connector *intel_connector = to_intel_connector(connector);
3012 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08003013 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003014
3015 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03003016 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003017 drm_get_connector_status_name(connector->status));
3018 if (connector->status == connector_status_connected) {
3019 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3020 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3021 connector->display_info.width_mm,
3022 connector->display_info.height_mm);
3023 seq_printf(m, "\tsubpixel order: %s\n",
3024 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3025 seq_printf(m, "\tCEA rev: %d\n",
3026 connector->display_info.cea_rev);
3027 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003028
3029 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3030 return;
3031
3032 switch (connector->connector_type) {
3033 case DRM_MODE_CONNECTOR_DisplayPort:
3034 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003035 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3036 intel_dp_mst_info(m, intel_connector);
3037 else
3038 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003039 break;
3040 case DRM_MODE_CONNECTOR_LVDS:
3041 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003042 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003043 break;
3044 case DRM_MODE_CONNECTOR_HDMIA:
3045 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3046 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3047 intel_hdmi_info(m, intel_connector);
3048 break;
3049 default:
3050 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003051 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003052
Jesse Barnesf103fc72014-02-20 12:39:57 -08003053 seq_printf(m, "\tmodes:\n");
3054 list_for_each_entry(mode, &connector->modes, head)
3055 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003056}
3057
David Weinehall36cdd012016-08-22 13:59:31 +03003058static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec22014-03-12 09:13:13 +00003059{
Chris Wilson065f2ec22014-03-12 09:13:13 +00003060 u32 state;
3061
Jani Nikula2a307c22016-11-30 17:43:04 +02003062 if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003063 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003064 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003065 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003066
3067 return state;
3068}
3069
David Weinehall36cdd012016-08-22 13:59:31 +03003070static bool cursor_position(struct drm_i915_private *dev_priv,
3071 int pipe, int *x, int *y)
Chris Wilson065f2ec22014-03-12 09:13:13 +00003072{
Chris Wilson065f2ec22014-03-12 09:13:13 +00003073 u32 pos;
3074
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003075 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00003076
3077 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3078 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3079 *x = -*x;
3080
3081 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3082 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3083 *y = -*y;
3084
David Weinehall36cdd012016-08-22 13:59:31 +03003085 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec22014-03-12 09:13:13 +00003086}
3087
Robert Fekete3abc4e02015-10-27 16:58:32 +01003088static const char *plane_type(enum drm_plane_type type)
3089{
3090 switch (type) {
3091 case DRM_PLANE_TYPE_OVERLAY:
3092 return "OVL";
3093 case DRM_PLANE_TYPE_PRIMARY:
3094 return "PRI";
3095 case DRM_PLANE_TYPE_CURSOR:
3096 return "CUR";
3097 /*
3098 * Deliberately omitting default: to generate compiler warnings
3099 * when a new drm_plane_type gets added.
3100 */
3101 }
3102
3103 return "unknown";
3104}
3105
3106static const char *plane_rotation(unsigned int rotation)
3107{
3108 static char buf[48];
3109 /*
3110 * According to doc only one DRM_ROTATE_ is allowed but this
3111 * will print them all to visualize if the values are misused
3112 */
3113 snprintf(buf, sizeof(buf),
3114 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003115 (rotation & DRM_ROTATE_0) ? "0 " : "",
3116 (rotation & DRM_ROTATE_90) ? "90 " : "",
3117 (rotation & DRM_ROTATE_180) ? "180 " : "",
3118 (rotation & DRM_ROTATE_270) ? "270 " : "",
3119 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3120 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003121 rotation);
3122
3123 return buf;
3124}
3125
3126static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3127{
David Weinehall36cdd012016-08-22 13:59:31 +03003128 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3129 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003130 struct intel_plane *intel_plane;
3131
3132 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3133 struct drm_plane_state *state;
3134 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003135 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003136
3137 if (!plane->state) {
3138 seq_puts(m, "plane->state is NULL!\n");
3139 continue;
3140 }
3141
3142 state = plane->state;
3143
Eric Engestrom90844f02016-08-15 01:02:38 +01003144 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003145 drm_get_format_name(state->fb->format->format,
3146 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003147 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003148 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003149 }
3150
Robert Fekete3abc4e02015-10-27 16:58:32 +01003151 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",
3152 plane->base.id,
3153 plane_type(intel_plane->base.type),
3154 state->crtc_x, state->crtc_y,
3155 state->crtc_w, state->crtc_h,
3156 (state->src_x >> 16),
3157 ((state->src_x & 0xffff) * 15625) >> 10,
3158 (state->src_y >> 16),
3159 ((state->src_y & 0xffff) * 15625) >> 10,
3160 (state->src_w >> 16),
3161 ((state->src_w & 0xffff) * 15625) >> 10,
3162 (state->src_h >> 16),
3163 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003164 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003165 plane_rotation(state->rotation));
3166 }
3167}
3168
3169static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3170{
3171 struct intel_crtc_state *pipe_config;
3172 int num_scalers = intel_crtc->num_scalers;
3173 int i;
3174
3175 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3176
3177 /* Not all platformas have a scaler */
3178 if (num_scalers) {
3179 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3180 num_scalers,
3181 pipe_config->scaler_state.scaler_users,
3182 pipe_config->scaler_state.scaler_id);
3183
A.Sunil Kamath58415912016-11-20 23:20:26 +05303184 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003185 struct intel_scaler *sc =
3186 &pipe_config->scaler_state.scalers[i];
3187
3188 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3189 i, yesno(sc->in_use), sc->mode);
3190 }
3191 seq_puts(m, "\n");
3192 } else {
3193 seq_puts(m, "\tNo scalers available on this platform\n");
3194 }
3195}
3196
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003197static int i915_display_info(struct seq_file *m, void *unused)
3198{
David Weinehall36cdd012016-08-22 13:59:31 +03003199 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3200 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003201 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003202 struct drm_connector *connector;
3203
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003204 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003205 drm_modeset_lock_all(dev);
3206 seq_printf(m, "CRTC info\n");
3207 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003208 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003209 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003210 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003211 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003212
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003213 pipe_config = to_intel_crtc_state(crtc->base.state);
3214
Robert Fekete3abc4e02015-10-27 16:58:32 +01003215 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003216 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003217 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003218 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3219 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3220
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003221 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003222 intel_crtc_info(m, crtc);
3223
David Weinehall36cdd012016-08-22 13:59:31 +03003224 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003225 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x, active? %s\n",
Chris Wilson4b0e3332014-05-30 16:35:26 +03003226 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003227 x, y, crtc->base.cursor->state->crtc_w,
3228 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003229 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003230 intel_scaler_info(m, crtc);
3231 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003232 }
Daniel Vettercace8412014-05-22 17:56:31 +02003233
3234 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3235 yesno(!crtc->cpu_fifo_underrun_disabled),
3236 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003237 }
3238
3239 seq_printf(m, "\n");
3240 seq_printf(m, "Connector info\n");
3241 seq_printf(m, "--------------\n");
3242 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3243 intel_connector_info(m, connector);
3244 }
3245 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003246 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003247
3248 return 0;
3249}
3250
Chris Wilson1b365952016-10-04 21:11:31 +01003251static int i915_engine_info(struct seq_file *m, void *unused)
3252{
3253 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3254 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303255 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003256
Chris Wilson9c870d02016-10-24 13:42:15 +01003257 intel_runtime_pm_get(dev_priv);
3258
Chris Wilsonf73b5672017-03-02 15:03:56 +00003259 seq_printf(m, "GT awake? %s\n",
3260 yesno(dev_priv->gt.awake));
3261 seq_printf(m, "Global active requests: %d\n",
3262 dev_priv->gt.active_requests);
3263
Akash Goel3b3f1652016-10-13 22:44:48 +05303264 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003265 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3266 struct drm_i915_gem_request *rq;
3267 struct rb_node *rb;
3268 u64 addr;
3269
3270 seq_printf(m, "%s\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003271 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003272 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003273 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003274 engine->hangcheck.seqno,
Chris Wilsonf73b5672017-03-02 15:03:56 +00003275 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp),
3276 engine->timeline->inflight_seqnos);
Chris Wilson1b365952016-10-04 21:11:31 +01003277
3278 rcu_read_lock();
3279
3280 seq_printf(m, "\tRequests:\n");
3281
Chris Wilson73cb9702016-10-28 13:58:46 +01003282 rq = list_first_entry(&engine->timeline->requests,
3283 struct drm_i915_gem_request, link);
3284 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003285 print_request(m, rq, "\t\tfirst ");
3286
Chris Wilson73cb9702016-10-28 13:58:46 +01003287 rq = list_last_entry(&engine->timeline->requests,
3288 struct drm_i915_gem_request, link);
3289 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003290 print_request(m, rq, "\t\tlast ");
3291
3292 rq = i915_gem_find_active_request(engine);
3293 if (rq) {
3294 print_request(m, rq, "\t\tactive ");
3295 seq_printf(m,
3296 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3297 rq->head, rq->postfix, rq->tail,
3298 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3299 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3300 }
3301
3302 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3303 I915_READ(RING_START(engine->mmio_base)),
3304 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3305 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3306 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3307 rq ? rq->ring->head : 0);
3308 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3309 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3310 rq ? rq->ring->tail : 0);
3311 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3312 I915_READ(RING_CTL(engine->mmio_base)),
3313 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3314
3315 rcu_read_unlock();
3316
3317 addr = intel_engine_get_active_head(engine);
3318 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3319 upper_32_bits(addr), lower_32_bits(addr));
3320 addr = intel_engine_get_last_batch_head(engine);
3321 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3322 upper_32_bits(addr), lower_32_bits(addr));
3323
3324 if (i915.enable_execlists) {
3325 u32 ptr, read, write;
Chris Wilson20311bd2016-11-14 20:41:03 +00003326 struct rb_node *rb;
Chris Wilson1b365952016-10-04 21:11:31 +01003327
3328 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3329 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3330 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3331
3332 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3333 read = GEN8_CSB_READ_PTR(ptr);
3334 write = GEN8_CSB_WRITE_PTR(ptr);
3335 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3336 read, write);
3337 if (read >= GEN8_CSB_ENTRIES)
3338 read = 0;
3339 if (write >= GEN8_CSB_ENTRIES)
3340 write = 0;
3341 if (read > write)
3342 write += GEN8_CSB_ENTRIES;
3343 while (read < write) {
3344 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3345
3346 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3347 idx,
3348 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3349 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3350 }
3351
3352 rcu_read_lock();
3353 rq = READ_ONCE(engine->execlist_port[0].request);
Chris Wilson816ee792017-01-24 11:00:03 +00003354 if (rq) {
3355 seq_printf(m, "\t\tELSP[0] count=%d, ",
3356 engine->execlist_port[0].count);
3357 print_request(m, rq, "rq: ");
3358 } else {
Chris Wilson1b365952016-10-04 21:11:31 +01003359 seq_printf(m, "\t\tELSP[0] idle\n");
Chris Wilson816ee792017-01-24 11:00:03 +00003360 }
Chris Wilson1b365952016-10-04 21:11:31 +01003361 rq = READ_ONCE(engine->execlist_port[1].request);
Chris Wilson816ee792017-01-24 11:00:03 +00003362 if (rq) {
3363 seq_printf(m, "\t\tELSP[1] count=%d, ",
3364 engine->execlist_port[1].count);
3365 print_request(m, rq, "rq: ");
3366 } else {
Chris Wilson1b365952016-10-04 21:11:31 +01003367 seq_printf(m, "\t\tELSP[1] idle\n");
Chris Wilson816ee792017-01-24 11:00:03 +00003368 }
Chris Wilson1b365952016-10-04 21:11:31 +01003369 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003370
Chris Wilson663f71e2016-11-14 20:41:00 +00003371 spin_lock_irq(&engine->timeline->lock);
Chris Wilson20311bd2016-11-14 20:41:03 +00003372 for (rb = engine->execlist_first; rb; rb = rb_next(rb)) {
3373 rq = rb_entry(rb, typeof(*rq), priotree.node);
Chris Wilsonc8247c02016-10-27 01:03:43 +01003374 print_request(m, rq, "\t\tQ ");
3375 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003376 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003377 } else if (INTEL_GEN(dev_priv) > 6) {
3378 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3379 I915_READ(RING_PP_DIR_BASE(engine)));
3380 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3381 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3382 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3383 I915_READ(RING_PP_DIR_DCLV(engine)));
3384 }
3385
Chris Wilsonf6168e32016-10-28 13:58:55 +01003386 spin_lock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003387 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08003388 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson1b365952016-10-04 21:11:31 +01003389
3390 seq_printf(m, "\t%s [%d] waiting for %x\n",
3391 w->tsk->comm, w->tsk->pid, w->seqno);
3392 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01003393 spin_unlock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003394
3395 seq_puts(m, "\n");
3396 }
3397
Chris Wilson9c870d02016-10-24 13:42:15 +01003398 intel_runtime_pm_put(dev_priv);
3399
Chris Wilson1b365952016-10-04 21:11:31 +01003400 return 0;
3401}
3402
Ben Widawskye04934c2014-06-30 09:53:42 -07003403static int i915_semaphore_status(struct seq_file *m, void *unused)
3404{
David Weinehall36cdd012016-08-22 13:59:31 +03003405 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3406 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003407 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003408 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003409 enum intel_engine_id id;
3410 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003411
Chris Wilson39df9192016-07-20 13:31:57 +01003412 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003413 seq_puts(m, "Semaphores are disabled\n");
3414 return 0;
3415 }
3416
3417 ret = mutex_lock_interruptible(&dev->struct_mutex);
3418 if (ret)
3419 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003420 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003421
David Weinehall36cdd012016-08-22 13:59:31 +03003422 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003423 struct page *page;
3424 uint64_t *seqno;
3425
Chris Wilson51d545d2016-08-15 10:49:02 +01003426 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003427
3428 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303429 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003430 uint64_t offset;
3431
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003432 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003433
3434 seq_puts(m, " Last signal:");
3435 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003436 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003437 seq_printf(m, "0x%08llx (0x%02llx) ",
3438 seqno[offset], offset * 8);
3439 }
3440 seq_putc(m, '\n');
3441
3442 seq_puts(m, " Last wait: ");
3443 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003444 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003445 seq_printf(m, "0x%08llx (0x%02llx) ",
3446 seqno[offset], offset * 8);
3447 }
3448 seq_putc(m, '\n');
3449
3450 }
3451 kunmap_atomic(seqno);
3452 } else {
3453 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303454 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003455 for (j = 0; j < num_rings; j++)
3456 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003457 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003458 seq_putc(m, '\n');
3459 }
3460
Paulo Zanoni03872062014-07-09 14:31:57 -03003461 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003462 mutex_unlock(&dev->struct_mutex);
3463 return 0;
3464}
3465
Daniel Vetter728e29d2014-06-25 22:01:53 +03003466static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3467{
David Weinehall36cdd012016-08-22 13:59:31 +03003468 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3469 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003470 int i;
3471
3472 drm_modeset_lock_all(dev);
3473 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3474 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3475
3476 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003477 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003478 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003479 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003480 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003481 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003482 pll->state.hw_state.dpll_md);
3483 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3484 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3485 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003486 }
3487 drm_modeset_unlock_all(dev);
3488
3489 return 0;
3490}
3491
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003492static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003493{
3494 int i;
3495 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003496 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003497 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3498 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003499 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003500 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003501
Arun Siluvery888b5992014-08-26 14:44:51 +01003502 ret = mutex_lock_interruptible(&dev->struct_mutex);
3503 if (ret)
3504 return ret;
3505
3506 intel_runtime_pm_get(dev_priv);
3507
Arun Siluvery33136b02016-01-21 21:43:47 +00003508 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303509 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003510 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003511 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003512 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003513 i915_reg_t addr;
3514 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003515 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003516
Arun Siluvery33136b02016-01-21 21:43:47 +00003517 addr = workarounds->reg[i].addr;
3518 mask = workarounds->reg[i].mask;
3519 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003520 read = I915_READ(addr);
3521 ok = (value & mask) == (read & mask);
3522 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 +02003523 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003524 }
3525
3526 intel_runtime_pm_put(dev_priv);
3527 mutex_unlock(&dev->struct_mutex);
3528
3529 return 0;
3530}
3531
Damien Lespiauc5511e42014-11-04 17:06:51 +00003532static int i915_ddb_info(struct seq_file *m, void *unused)
3533{
David Weinehall36cdd012016-08-22 13:59:31 +03003534 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3535 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003536 struct skl_ddb_allocation *ddb;
3537 struct skl_ddb_entry *entry;
3538 enum pipe pipe;
3539 int plane;
3540
David Weinehall36cdd012016-08-22 13:59:31 +03003541 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003542 return 0;
3543
Damien Lespiauc5511e42014-11-04 17:06:51 +00003544 drm_modeset_lock_all(dev);
3545
3546 ddb = &dev_priv->wm.skl_hw.ddb;
3547
3548 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3549
3550 for_each_pipe(dev_priv, pipe) {
3551 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3552
Matt Roper8b364b42016-10-26 15:51:28 -07003553 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003554 entry = &ddb->plane[pipe][plane];
3555 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3556 entry->start, entry->end,
3557 skl_ddb_entry_size(entry));
3558 }
3559
Matt Roper4969d332015-09-24 15:53:10 -07003560 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003561 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3562 entry->end, skl_ddb_entry_size(entry));
3563 }
3564
3565 drm_modeset_unlock_all(dev);
3566
3567 return 0;
3568}
3569
Vandana Kannana54746e2015-03-03 20:53:10 +05303570static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003571 struct drm_device *dev,
3572 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303573{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003574 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303575 struct i915_drrs *drrs = &dev_priv->drrs;
3576 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003577 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303578
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003579 drm_for_each_connector(connector, dev) {
3580 if (connector->state->crtc != &intel_crtc->base)
3581 continue;
3582
3583 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303584 }
3585
3586 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3587 seq_puts(m, "\tVBT: DRRS_type: Static");
3588 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3589 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3590 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3591 seq_puts(m, "\tVBT: DRRS_type: None");
3592 else
3593 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3594
3595 seq_puts(m, "\n\n");
3596
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003597 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303598 struct intel_panel *panel;
3599
3600 mutex_lock(&drrs->mutex);
3601 /* DRRS Supported */
3602 seq_puts(m, "\tDRRS Supported: Yes\n");
3603
3604 /* disable_drrs() will make drrs->dp NULL */
3605 if (!drrs->dp) {
3606 seq_puts(m, "Idleness DRRS: Disabled");
3607 mutex_unlock(&drrs->mutex);
3608 return;
3609 }
3610
3611 panel = &drrs->dp->attached_connector->panel;
3612 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3613 drrs->busy_frontbuffer_bits);
3614
3615 seq_puts(m, "\n\t\t");
3616 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3617 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3618 vrefresh = panel->fixed_mode->vrefresh;
3619 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3620 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3621 vrefresh = panel->downclock_mode->vrefresh;
3622 } else {
3623 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3624 drrs->refresh_rate_type);
3625 mutex_unlock(&drrs->mutex);
3626 return;
3627 }
3628 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3629
3630 seq_puts(m, "\n\t\t");
3631 mutex_unlock(&drrs->mutex);
3632 } else {
3633 /* DRRS not supported. Print the VBT parameter*/
3634 seq_puts(m, "\tDRRS Supported : No");
3635 }
3636 seq_puts(m, "\n");
3637}
3638
3639static int i915_drrs_status(struct seq_file *m, void *unused)
3640{
David Weinehall36cdd012016-08-22 13:59:31 +03003641 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3642 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303643 struct intel_crtc *intel_crtc;
3644 int active_crtc_cnt = 0;
3645
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003646 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303647 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003648 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303649 active_crtc_cnt++;
3650 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3651
3652 drrs_status_per_crtc(m, dev, intel_crtc);
3653 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303654 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003655 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303656
3657 if (!active_crtc_cnt)
3658 seq_puts(m, "No active crtc found\n");
3659
3660 return 0;
3661}
3662
Dave Airlie11bed952014-05-12 15:22:27 +10003663static int i915_dp_mst_info(struct seq_file *m, void *unused)
3664{
David Weinehall36cdd012016-08-22 13:59:31 +03003665 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3666 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003667 struct intel_encoder *intel_encoder;
3668 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003669 struct drm_connector *connector;
3670
Dave Airlie11bed952014-05-12 15:22:27 +10003671 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003672 drm_for_each_connector(connector, dev) {
3673 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003674 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003675
3676 intel_encoder = intel_attached_encoder(connector);
3677 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3678 continue;
3679
3680 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003681 if (!intel_dig_port->dp.can_mst)
3682 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003683
Jim Bride40ae80c2016-04-14 10:18:37 -07003684 seq_printf(m, "MST Source Port %c\n",
3685 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003686 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3687 }
3688 drm_modeset_unlock_all(dev);
3689 return 0;
3690}
3691
Todd Previteeb3394fa2015-04-18 00:04:19 -07003692static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003693 const char __user *ubuf,
3694 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003695{
3696 char *input_buffer;
3697 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003698 struct drm_device *dev;
3699 struct drm_connector *connector;
3700 struct list_head *connector_list;
3701 struct intel_dp *intel_dp;
3702 int val = 0;
3703
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303704 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003705
Todd Previteeb3394fa2015-04-18 00:04:19 -07003706 connector_list = &dev->mode_config.connector_list;
3707
3708 if (len == 0)
3709 return 0;
3710
3711 input_buffer = kmalloc(len + 1, GFP_KERNEL);
3712 if (!input_buffer)
3713 return -ENOMEM;
3714
3715 if (copy_from_user(input_buffer, ubuf, len)) {
3716 status = -EFAULT;
3717 goto out;
3718 }
3719
3720 input_buffer[len] = '\0';
3721 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3722
3723 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003724 if (connector->connector_type !=
3725 DRM_MODE_CONNECTOR_DisplayPort)
3726 continue;
3727
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05303728 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07003729 connector->encoder != NULL) {
3730 intel_dp = enc_to_intel_dp(connector->encoder);
3731 status = kstrtoint(input_buffer, 10, &val);
3732 if (status < 0)
3733 goto out;
3734 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3735 /* To prevent erroneous activation of the compliance
3736 * testing code, only accept an actual value of 1 here
3737 */
3738 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003739 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003740 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003741 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003742 }
3743 }
3744out:
3745 kfree(input_buffer);
3746 if (status < 0)
3747 return status;
3748
3749 *offp += len;
3750 return len;
3751}
3752
3753static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3754{
3755 struct drm_device *dev = m->private;
3756 struct drm_connector *connector;
3757 struct list_head *connector_list = &dev->mode_config.connector_list;
3758 struct intel_dp *intel_dp;
3759
Todd Previteeb3394fa2015-04-18 00:04:19 -07003760 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003761 if (connector->connector_type !=
3762 DRM_MODE_CONNECTOR_DisplayPort)
3763 continue;
3764
3765 if (connector->status == connector_status_connected &&
3766 connector->encoder != NULL) {
3767 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003768 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003769 seq_puts(m, "1");
3770 else
3771 seq_puts(m, "0");
3772 } else
3773 seq_puts(m, "0");
3774 }
3775
3776 return 0;
3777}
3778
3779static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003780 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003781{
David Weinehall36cdd012016-08-22 13:59:31 +03003782 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003783
David Weinehall36cdd012016-08-22 13:59:31 +03003784 return single_open(file, i915_displayport_test_active_show,
3785 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003786}
3787
3788static const struct file_operations i915_displayport_test_active_fops = {
3789 .owner = THIS_MODULE,
3790 .open = i915_displayport_test_active_open,
3791 .read = seq_read,
3792 .llseek = seq_lseek,
3793 .release = single_release,
3794 .write = i915_displayport_test_active_write
3795};
3796
3797static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3798{
3799 struct drm_device *dev = m->private;
3800 struct drm_connector *connector;
3801 struct list_head *connector_list = &dev->mode_config.connector_list;
3802 struct intel_dp *intel_dp;
3803
Todd Previteeb3394fa2015-04-18 00:04:19 -07003804 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003805 if (connector->connector_type !=
3806 DRM_MODE_CONNECTOR_DisplayPort)
3807 continue;
3808
3809 if (connector->status == connector_status_connected &&
3810 connector->encoder != NULL) {
3811 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003812 if (intel_dp->compliance.test_type ==
3813 DP_TEST_LINK_EDID_READ)
3814 seq_printf(m, "%lx",
3815 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003816 else if (intel_dp->compliance.test_type ==
3817 DP_TEST_LINK_VIDEO_PATTERN) {
3818 seq_printf(m, "hdisplay: %d\n",
3819 intel_dp->compliance.test_data.hdisplay);
3820 seq_printf(m, "vdisplay: %d\n",
3821 intel_dp->compliance.test_data.vdisplay);
3822 seq_printf(m, "bpc: %u\n",
3823 intel_dp->compliance.test_data.bpc);
3824 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003825 } else
3826 seq_puts(m, "0");
3827 }
3828
3829 return 0;
3830}
3831static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003832 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003833{
David Weinehall36cdd012016-08-22 13:59:31 +03003834 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003835
David Weinehall36cdd012016-08-22 13:59:31 +03003836 return single_open(file, i915_displayport_test_data_show,
3837 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003838}
3839
3840static const struct file_operations i915_displayport_test_data_fops = {
3841 .owner = THIS_MODULE,
3842 .open = i915_displayport_test_data_open,
3843 .read = seq_read,
3844 .llseek = seq_lseek,
3845 .release = single_release
3846};
3847
3848static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3849{
3850 struct drm_device *dev = m->private;
3851 struct drm_connector *connector;
3852 struct list_head *connector_list = &dev->mode_config.connector_list;
3853 struct intel_dp *intel_dp;
3854
Todd Previteeb3394fa2015-04-18 00:04:19 -07003855 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003856 if (connector->connector_type !=
3857 DRM_MODE_CONNECTOR_DisplayPort)
3858 continue;
3859
3860 if (connector->status == connector_status_connected &&
3861 connector->encoder != NULL) {
3862 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003863 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003864 } else
3865 seq_puts(m, "0");
3866 }
3867
3868 return 0;
3869}
3870
3871static int i915_displayport_test_type_open(struct inode *inode,
3872 struct file *file)
3873{
David Weinehall36cdd012016-08-22 13:59:31 +03003874 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003875
David Weinehall36cdd012016-08-22 13:59:31 +03003876 return single_open(file, i915_displayport_test_type_show,
3877 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003878}
3879
3880static const struct file_operations i915_displayport_test_type_fops = {
3881 .owner = THIS_MODULE,
3882 .open = i915_displayport_test_type_open,
3883 .read = seq_read,
3884 .llseek = seq_lseek,
3885 .release = single_release
3886};
3887
Damien Lespiau97e94b22014-11-04 17:06:50 +00003888static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003889{
David Weinehall36cdd012016-08-22 13:59:31 +03003890 struct drm_i915_private *dev_priv = m->private;
3891 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003892 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003893 int num_levels;
3894
David Weinehall36cdd012016-08-22 13:59:31 +03003895 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003896 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003897 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003898 num_levels = 1;
3899 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003900 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003901
3902 drm_modeset_lock_all(dev);
3903
3904 for (level = 0; level < num_levels; level++) {
3905 unsigned int latency = wm[level];
3906
Damien Lespiau97e94b22014-11-04 17:06:50 +00003907 /*
3908 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003909 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003910 */
David Weinehall36cdd012016-08-22 13:59:31 +03003911 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
3912 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003913 latency *= 10;
3914 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003915 latency *= 5;
3916
3917 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003918 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003919 }
3920
3921 drm_modeset_unlock_all(dev);
3922}
3923
3924static int pri_wm_latency_show(struct seq_file *m, void *data)
3925{
David Weinehall36cdd012016-08-22 13:59:31 +03003926 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003927 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003928
David Weinehall36cdd012016-08-22 13:59:31 +03003929 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003930 latencies = dev_priv->wm.skl_latency;
3931 else
David Weinehall36cdd012016-08-22 13:59:31 +03003932 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003933
3934 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003935
3936 return 0;
3937}
3938
3939static int spr_wm_latency_show(struct seq_file *m, void *data)
3940{
David Weinehall36cdd012016-08-22 13:59:31 +03003941 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003942 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003943
David Weinehall36cdd012016-08-22 13:59:31 +03003944 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003945 latencies = dev_priv->wm.skl_latency;
3946 else
David Weinehall36cdd012016-08-22 13:59:31 +03003947 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003948
3949 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003950
3951 return 0;
3952}
3953
3954static int cur_wm_latency_show(struct seq_file *m, void *data)
3955{
David Weinehall36cdd012016-08-22 13:59:31 +03003956 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003957 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003958
David Weinehall36cdd012016-08-22 13:59:31 +03003959 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003960 latencies = dev_priv->wm.skl_latency;
3961 else
David Weinehall36cdd012016-08-22 13:59:31 +03003962 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003963
3964 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003965
3966 return 0;
3967}
3968
3969static int pri_wm_latency_open(struct inode *inode, struct file *file)
3970{
David Weinehall36cdd012016-08-22 13:59:31 +03003971 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003972
David Weinehall36cdd012016-08-22 13:59:31 +03003973 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003974 return -ENODEV;
3975
David Weinehall36cdd012016-08-22 13:59:31 +03003976 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003977}
3978
3979static int spr_wm_latency_open(struct inode *inode, struct file *file)
3980{
David Weinehall36cdd012016-08-22 13:59:31 +03003981 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003982
David Weinehall36cdd012016-08-22 13:59:31 +03003983 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003984 return -ENODEV;
3985
David Weinehall36cdd012016-08-22 13:59:31 +03003986 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003987}
3988
3989static int cur_wm_latency_open(struct inode *inode, struct file *file)
3990{
David Weinehall36cdd012016-08-22 13:59:31 +03003991 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003992
David Weinehall36cdd012016-08-22 13:59:31 +03003993 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003994 return -ENODEV;
3995
David Weinehall36cdd012016-08-22 13:59:31 +03003996 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003997}
3998
3999static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004000 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004001{
4002 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004003 struct drm_i915_private *dev_priv = m->private;
4004 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004005 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004006 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004007 int level;
4008 int ret;
4009 char tmp[32];
4010
David Weinehall36cdd012016-08-22 13:59:31 +03004011 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004012 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004013 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004014 num_levels = 1;
4015 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004016 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004017
Ville Syrjälä369a1342014-01-22 14:36:08 +02004018 if (len >= sizeof(tmp))
4019 return -EINVAL;
4020
4021 if (copy_from_user(tmp, ubuf, len))
4022 return -EFAULT;
4023
4024 tmp[len] = '\0';
4025
Damien Lespiau97e94b22014-11-04 17:06:50 +00004026 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4027 &new[0], &new[1], &new[2], &new[3],
4028 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004029 if (ret != num_levels)
4030 return -EINVAL;
4031
4032 drm_modeset_lock_all(dev);
4033
4034 for (level = 0; level < num_levels; level++)
4035 wm[level] = new[level];
4036
4037 drm_modeset_unlock_all(dev);
4038
4039 return len;
4040}
4041
4042
4043static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4044 size_t len, loff_t *offp)
4045{
4046 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004047 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004048 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004049
David Weinehall36cdd012016-08-22 13:59:31 +03004050 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004051 latencies = dev_priv->wm.skl_latency;
4052 else
David Weinehall36cdd012016-08-22 13:59:31 +03004053 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004054
4055 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004056}
4057
4058static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4059 size_t len, loff_t *offp)
4060{
4061 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004062 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004063 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004064
David Weinehall36cdd012016-08-22 13:59:31 +03004065 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004066 latencies = dev_priv->wm.skl_latency;
4067 else
David Weinehall36cdd012016-08-22 13:59:31 +03004068 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004069
4070 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004071}
4072
4073static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4074 size_t len, loff_t *offp)
4075{
4076 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004077 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004078 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004079
David Weinehall36cdd012016-08-22 13:59:31 +03004080 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004081 latencies = dev_priv->wm.skl_latency;
4082 else
David Weinehall36cdd012016-08-22 13:59:31 +03004083 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004084
4085 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004086}
4087
4088static const struct file_operations i915_pri_wm_latency_fops = {
4089 .owner = THIS_MODULE,
4090 .open = pri_wm_latency_open,
4091 .read = seq_read,
4092 .llseek = seq_lseek,
4093 .release = single_release,
4094 .write = pri_wm_latency_write
4095};
4096
4097static const struct file_operations i915_spr_wm_latency_fops = {
4098 .owner = THIS_MODULE,
4099 .open = spr_wm_latency_open,
4100 .read = seq_read,
4101 .llseek = seq_lseek,
4102 .release = single_release,
4103 .write = spr_wm_latency_write
4104};
4105
4106static const struct file_operations i915_cur_wm_latency_fops = {
4107 .owner = THIS_MODULE,
4108 .open = cur_wm_latency_open,
4109 .read = seq_read,
4110 .llseek = seq_lseek,
4111 .release = single_release,
4112 .write = cur_wm_latency_write
4113};
4114
Kees Cook647416f2013-03-10 14:10:06 -07004115static int
4116i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004117{
David Weinehall36cdd012016-08-22 13:59:31 +03004118 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004119
Chris Wilsond98c52c2016-04-13 17:35:05 +01004120 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004121
Kees Cook647416f2013-03-10 14:10:06 -07004122 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004123}
4124
Kees Cook647416f2013-03-10 14:10:06 -07004125static int
4126i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004127{
David Weinehall36cdd012016-08-22 13:59:31 +03004128 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004129
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004130 /*
4131 * There is no safeguard against this debugfs entry colliding
4132 * with the hangcheck calling same i915_handle_error() in
4133 * parallel, causing an explosion. For now we assume that the
4134 * test harness is responsible enough not to inject gpu hangs
4135 * while it is writing to 'i915_wedged'
4136 */
4137
Chris Wilsond98c52c2016-04-13 17:35:05 +01004138 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004139 return -EAGAIN;
4140
Chris Wilsonc0336662016-05-06 15:40:21 +01004141 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004142 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004143
Kees Cook647416f2013-03-10 14:10:06 -07004144 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004145}
4146
Kees Cook647416f2013-03-10 14:10:06 -07004147DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4148 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004149 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004150
Kees Cook647416f2013-03-10 14:10:06 -07004151static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004152i915_ring_missed_irq_get(void *data, u64 *val)
4153{
David Weinehall36cdd012016-08-22 13:59:31 +03004154 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004155
4156 *val = dev_priv->gpu_error.missed_irq_rings;
4157 return 0;
4158}
4159
4160static int
4161i915_ring_missed_irq_set(void *data, u64 val)
4162{
David Weinehall36cdd012016-08-22 13:59:31 +03004163 struct drm_i915_private *dev_priv = data;
4164 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004165 int ret;
4166
4167 /* Lock against concurrent debugfs callers */
4168 ret = mutex_lock_interruptible(&dev->struct_mutex);
4169 if (ret)
4170 return ret;
4171 dev_priv->gpu_error.missed_irq_rings = val;
4172 mutex_unlock(&dev->struct_mutex);
4173
4174 return 0;
4175}
4176
4177DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4178 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4179 "0x%08llx\n");
4180
4181static int
4182i915_ring_test_irq_get(void *data, u64 *val)
4183{
David Weinehall36cdd012016-08-22 13:59:31 +03004184 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004185
4186 *val = dev_priv->gpu_error.test_irq_rings;
4187
4188 return 0;
4189}
4190
4191static int
4192i915_ring_test_irq_set(void *data, u64 val)
4193{
David Weinehall36cdd012016-08-22 13:59:31 +03004194 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004195
Chris Wilson3a122c22016-06-17 14:35:05 +01004196 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004197 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004198 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004199
4200 return 0;
4201}
4202
4203DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4204 i915_ring_test_irq_get, i915_ring_test_irq_set,
4205 "0x%08llx\n");
4206
Chris Wilsondd624af2013-01-15 12:39:35 +00004207#define DROP_UNBOUND 0x1
4208#define DROP_BOUND 0x2
4209#define DROP_RETIRE 0x4
4210#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004211#define DROP_FREED 0x10
4212#define DROP_ALL (DROP_UNBOUND | \
4213 DROP_BOUND | \
4214 DROP_RETIRE | \
4215 DROP_ACTIVE | \
4216 DROP_FREED)
Kees Cook647416f2013-03-10 14:10:06 -07004217static int
4218i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004219{
Kees Cook647416f2013-03-10 14:10:06 -07004220 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004221
Kees Cook647416f2013-03-10 14:10:06 -07004222 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004223}
4224
Kees Cook647416f2013-03-10 14:10:06 -07004225static int
4226i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004227{
David Weinehall36cdd012016-08-22 13:59:31 +03004228 struct drm_i915_private *dev_priv = data;
4229 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004230 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004231
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004232 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004233
4234 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4235 * on ioctls on -EAGAIN. */
4236 ret = mutex_lock_interruptible(&dev->struct_mutex);
4237 if (ret)
4238 return ret;
4239
4240 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004241 ret = i915_gem_wait_for_idle(dev_priv,
4242 I915_WAIT_INTERRUPTIBLE |
4243 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004244 if (ret)
4245 goto unlock;
4246 }
4247
4248 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004249 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004250
Chris Wilson21ab4e72014-09-09 11:16:08 +01004251 if (val & DROP_BOUND)
4252 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004253
Chris Wilson21ab4e72014-09-09 11:16:08 +01004254 if (val & DROP_UNBOUND)
4255 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004256
4257unlock:
4258 mutex_unlock(&dev->struct_mutex);
4259
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004260 if (val & DROP_FREED) {
4261 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004262 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004263 }
4264
Kees Cook647416f2013-03-10 14:10:06 -07004265 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004266}
4267
Kees Cook647416f2013-03-10 14:10:06 -07004268DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4269 i915_drop_caches_get, i915_drop_caches_set,
4270 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004271
Kees Cook647416f2013-03-10 14:10:06 -07004272static int
4273i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004274{
David Weinehall36cdd012016-08-22 13:59:31 +03004275 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004276
David Weinehall36cdd012016-08-22 13:59:31 +03004277 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004278 return -ENODEV;
4279
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004280 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004281 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004282}
4283
Kees Cook647416f2013-03-10 14:10:06 -07004284static int
4285i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004286{
David Weinehall36cdd012016-08-22 13:59:31 +03004287 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304288 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004289 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004290
David Weinehall36cdd012016-08-22 13:59:31 +03004291 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004292 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004293
Kees Cook647416f2013-03-10 14:10:06 -07004294 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004295
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004296 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004297 if (ret)
4298 return ret;
4299
Jesse Barnes358733e2011-07-27 11:53:01 -07004300 /*
4301 * Turbo will still be enabled, but won't go above the set value.
4302 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304303 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004304
Akash Goelbc4d91f2015-02-26 16:09:47 +05304305 hw_max = dev_priv->rps.max_freq;
4306 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004307
Ben Widawskyb39fb292014-03-19 18:31:11 -07004308 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004309 mutex_unlock(&dev_priv->rps.hw_lock);
4310 return -EINVAL;
4311 }
4312
Ben Widawskyb39fb292014-03-19 18:31:11 -07004313 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004314
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004315 if (intel_set_rps(dev_priv, val))
4316 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004317
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004318 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004319
Kees Cook647416f2013-03-10 14:10:06 -07004320 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004321}
4322
Kees Cook647416f2013-03-10 14:10:06 -07004323DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4324 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004325 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004326
Kees Cook647416f2013-03-10 14:10:06 -07004327static int
4328i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004329{
David Weinehall36cdd012016-08-22 13:59:31 +03004330 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004331
Chris Wilson62e1baa2016-07-13 09:10:36 +01004332 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004333 return -ENODEV;
4334
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004335 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004336 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004337}
4338
Kees Cook647416f2013-03-10 14:10:06 -07004339static int
4340i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004341{
David Weinehall36cdd012016-08-22 13:59:31 +03004342 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304343 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004344 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004345
Chris Wilson62e1baa2016-07-13 09:10:36 +01004346 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004347 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004348
Kees Cook647416f2013-03-10 14:10:06 -07004349 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004350
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004351 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004352 if (ret)
4353 return ret;
4354
Jesse Barnes1523c312012-05-25 12:34:54 -07004355 /*
4356 * Turbo will still be enabled, but won't go below the set value.
4357 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304358 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004359
Akash Goelbc4d91f2015-02-26 16:09:47 +05304360 hw_max = dev_priv->rps.max_freq;
4361 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004362
David Weinehall36cdd012016-08-22 13:59:31 +03004363 if (val < hw_min ||
4364 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004365 mutex_unlock(&dev_priv->rps.hw_lock);
4366 return -EINVAL;
4367 }
4368
Ben Widawskyb39fb292014-03-19 18:31:11 -07004369 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004370
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004371 if (intel_set_rps(dev_priv, val))
4372 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004373
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004374 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004375
Kees Cook647416f2013-03-10 14:10:06 -07004376 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004377}
4378
Kees Cook647416f2013-03-10 14:10:06 -07004379DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4380 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004381 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004382
Kees Cook647416f2013-03-10 14:10:06 -07004383static int
4384i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004385{
David Weinehall36cdd012016-08-22 13:59:31 +03004386 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004387 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004388
David Weinehall36cdd012016-08-22 13:59:31 +03004389 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004390 return -ENODEV;
4391
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004392 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004393
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004394 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004395
4396 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004397
Kees Cook647416f2013-03-10 14:10:06 -07004398 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004399
Kees Cook647416f2013-03-10 14:10:06 -07004400 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004401}
4402
Kees Cook647416f2013-03-10 14:10:06 -07004403static int
4404i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004405{
David Weinehall36cdd012016-08-22 13:59:31 +03004406 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004407 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004408
David Weinehall36cdd012016-08-22 13:59:31 +03004409 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004410 return -ENODEV;
4411
Kees Cook647416f2013-03-10 14:10:06 -07004412 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004413 return -EINVAL;
4414
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004415 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004416 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004417
4418 /* Update the cache sharing policy here as well */
4419 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4420 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4421 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4422 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4423
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004424 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004425 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004426}
4427
Kees Cook647416f2013-03-10 14:10:06 -07004428DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4429 i915_cache_sharing_get, i915_cache_sharing_set,
4430 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004431
David Weinehall36cdd012016-08-22 13:59:31 +03004432static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004433 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004434{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004435 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004436 int ss;
4437 u32 sig1[ss_max], sig2[ss_max];
4438
4439 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4440 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4441 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4442 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4443
4444 for (ss = 0; ss < ss_max; ss++) {
4445 unsigned int eu_cnt;
4446
4447 if (sig1[ss] & CHV_SS_PG_ENABLE)
4448 /* skip disabled subslice */
4449 continue;
4450
Imre Deakf08a0c92016-08-31 19:13:04 +03004451 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004452 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004453 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4454 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4455 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4456 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004457 sseu->eu_total += eu_cnt;
4458 sseu->eu_per_subslice = max_t(unsigned int,
4459 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004460 }
Jeff McGee5d395252015-04-03 18:13:17 -07004461}
4462
David Weinehall36cdd012016-08-22 13:59:31 +03004463static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004464 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004465{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004466 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004467 int s, ss;
4468 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4469
Jeff McGee1c046bc2015-04-03 18:13:18 -07004470 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004471 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004472 s_max = 1;
4473 ss_max = 3;
4474 }
4475
4476 for (s = 0; s < s_max; s++) {
4477 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4478 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4479 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4480 }
4481
Jeff McGee5d395252015-04-03 18:13:17 -07004482 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4483 GEN9_PGCTL_SSA_EU19_ACK |
4484 GEN9_PGCTL_SSA_EU210_ACK |
4485 GEN9_PGCTL_SSA_EU311_ACK;
4486 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4487 GEN9_PGCTL_SSB_EU19_ACK |
4488 GEN9_PGCTL_SSB_EU210_ACK |
4489 GEN9_PGCTL_SSB_EU311_ACK;
4490
4491 for (s = 0; s < s_max; s++) {
4492 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4493 /* skip disabled slice */
4494 continue;
4495
Imre Deakf08a0c92016-08-31 19:13:04 +03004496 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004497
Rodrigo Vivib976dc52017-01-23 10:32:37 -08004498 if (IS_GEN9_BC(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004499 sseu->subslice_mask =
4500 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004501
Jeff McGee5d395252015-04-03 18:13:17 -07004502 for (ss = 0; ss < ss_max; ss++) {
4503 unsigned int eu_cnt;
4504
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004505 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004506 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4507 /* skip disabled subslice */
4508 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004509
Imre Deak57ec1712016-08-31 19:13:05 +03004510 sseu->subslice_mask |= BIT(ss);
4511 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004512
Jeff McGee5d395252015-04-03 18:13:17 -07004513 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4514 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004515 sseu->eu_total += eu_cnt;
4516 sseu->eu_per_subslice = max_t(unsigned int,
4517 sseu->eu_per_subslice,
4518 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004519 }
4520 }
4521}
4522
David Weinehall36cdd012016-08-22 13:59:31 +03004523static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004524 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004525{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004526 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004527 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004528
Imre Deakf08a0c92016-08-31 19:13:04 +03004529 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004530
Imre Deakf08a0c92016-08-31 19:13:04 +03004531 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004532 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004533 sseu->eu_per_subslice =
4534 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004535 sseu->eu_total = sseu->eu_per_subslice *
4536 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004537
4538 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004539 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004540 u8 subslice_7eu =
4541 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004542
Imre Deak915490d2016-08-31 19:13:01 +03004543 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004544 }
4545 }
4546}
4547
Imre Deak615d8902016-08-31 19:13:03 +03004548static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4549 const struct sseu_dev_info *sseu)
4550{
4551 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4552 const char *type = is_available_info ? "Available" : "Enabled";
4553
Imre Deakc67ba532016-08-31 19:13:06 +03004554 seq_printf(m, " %s Slice Mask: %04x\n", type,
4555 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004556 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004557 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004558 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004559 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004560 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4561 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004562 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004563 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004564 seq_printf(m, " %s EU Total: %u\n", type,
4565 sseu->eu_total);
4566 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4567 sseu->eu_per_subslice);
4568
4569 if (!is_available_info)
4570 return;
4571
4572 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4573 if (HAS_POOLED_EU(dev_priv))
4574 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4575
4576 seq_printf(m, " Has Slice Power Gating: %s\n",
4577 yesno(sseu->has_slice_pg));
4578 seq_printf(m, " Has Subslice Power Gating: %s\n",
4579 yesno(sseu->has_subslice_pg));
4580 seq_printf(m, " Has EU Power Gating: %s\n",
4581 yesno(sseu->has_eu_pg));
4582}
4583
Jeff McGee38732182015-02-13 10:27:54 -06004584static int i915_sseu_status(struct seq_file *m, void *unused)
4585{
David Weinehall36cdd012016-08-22 13:59:31 +03004586 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004587 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004588
David Weinehall36cdd012016-08-22 13:59:31 +03004589 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004590 return -ENODEV;
4591
4592 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004593 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004594
Jeff McGee7f992ab2015-02-13 10:27:55 -06004595 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004596 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004597
4598 intel_runtime_pm_get(dev_priv);
4599
David Weinehall36cdd012016-08-22 13:59:31 +03004600 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004601 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004602 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004603 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004604 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004605 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004606 }
David Weinehall238010e2016-08-01 17:33:27 +03004607
4608 intel_runtime_pm_put(dev_priv);
4609
Imre Deak615d8902016-08-31 19:13:03 +03004610 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004611
Jeff McGee38732182015-02-13 10:27:54 -06004612 return 0;
4613}
4614
Ben Widawsky6d794d42011-04-25 11:25:56 -07004615static int i915_forcewake_open(struct inode *inode, struct file *file)
4616{
David Weinehall36cdd012016-08-22 13:59:31 +03004617 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004618
David Weinehall36cdd012016-08-22 13:59:31 +03004619 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004620 return 0;
4621
Chris Wilson6daccb02015-01-16 11:34:35 +02004622 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004623 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004624
4625 return 0;
4626}
4627
Ben Widawskyc43b5632012-04-16 14:07:40 -07004628static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004629{
David Weinehall36cdd012016-08-22 13:59:31 +03004630 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004631
David Weinehall36cdd012016-08-22 13:59:31 +03004632 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004633 return 0;
4634
Mika Kuoppala59bad942015-01-16 11:34:40 +02004635 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004636 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004637
4638 return 0;
4639}
4640
4641static const struct file_operations i915_forcewake_fops = {
4642 .owner = THIS_MODULE,
4643 .open = i915_forcewake_open,
4644 .release = i915_forcewake_release,
4645};
4646
4647static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4648{
Ben Widawsky6d794d42011-04-25 11:25:56 -07004649 struct dentry *ent;
4650
4651 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004652 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03004653 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07004654 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004655 if (!ent)
4656 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004657
Ben Widawsky8eb57292011-05-11 15:10:58 -07004658 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004659}
4660
Lyude317eaa92017-02-03 21:18:25 -05004661static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4662{
4663 struct drm_i915_private *dev_priv = m->private;
4664 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4665
4666 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4667 seq_printf(m, "Detected: %s\n",
4668 yesno(delayed_work_pending(&hotplug->reenable_work)));
4669
4670 return 0;
4671}
4672
4673static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4674 const char __user *ubuf, size_t len,
4675 loff_t *offp)
4676{
4677 struct seq_file *m = file->private_data;
4678 struct drm_i915_private *dev_priv = m->private;
4679 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4680 unsigned int new_threshold;
4681 int i;
4682 char *newline;
4683 char tmp[16];
4684
4685 if (len >= sizeof(tmp))
4686 return -EINVAL;
4687
4688 if (copy_from_user(tmp, ubuf, len))
4689 return -EFAULT;
4690
4691 tmp[len] = '\0';
4692
4693 /* Strip newline, if any */
4694 newline = strchr(tmp, '\n');
4695 if (newline)
4696 *newline = '\0';
4697
4698 if (strcmp(tmp, "reset") == 0)
4699 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4700 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4701 return -EINVAL;
4702
4703 if (new_threshold > 0)
4704 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4705 new_threshold);
4706 else
4707 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4708
4709 spin_lock_irq(&dev_priv->irq_lock);
4710 hotplug->hpd_storm_threshold = new_threshold;
4711 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4712 for_each_hpd_pin(i)
4713 hotplug->stats[i].count = 0;
4714 spin_unlock_irq(&dev_priv->irq_lock);
4715
4716 /* Re-enable hpd immediately if we were in an irq storm */
4717 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4718
4719 return len;
4720}
4721
4722static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4723{
4724 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4725}
4726
4727static const struct file_operations i915_hpd_storm_ctl_fops = {
4728 .owner = THIS_MODULE,
4729 .open = i915_hpd_storm_ctl_open,
4730 .read = seq_read,
4731 .llseek = seq_lseek,
4732 .release = single_release,
4733 .write = i915_hpd_storm_ctl_write
4734};
4735
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004736static int i915_debugfs_create(struct dentry *root,
4737 struct drm_minor *minor,
4738 const char *name,
4739 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004740{
Jesse Barnes358733e2011-07-27 11:53:01 -07004741 struct dentry *ent;
4742
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004743 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004744 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03004745 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004746 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004747 if (!ent)
4748 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004749
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004750 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004751}
4752
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004753static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004754 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004755 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004756 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01004757 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004758 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004759 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004760 {"i915_gem_request", i915_gem_request_info, 0},
4761 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004762 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004763 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004764 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004765 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004766 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004767 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004768 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304769 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004770 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004771 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004772 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004773 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004774 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004775 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004776 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004777 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004778 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004779 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004780 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004781 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004782 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004783 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004784 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004785 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004786 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004787 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004788 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004789 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004790 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004791 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004792 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004793 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004794 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004795 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004796 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004797 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004798 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004799 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004800 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304801 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004802 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004803};
Ben Gamari27c202a2009-07-01 22:26:52 -04004804#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004805
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004806static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004807 const char *name;
4808 const struct file_operations *fops;
4809} i915_debugfs_files[] = {
4810 {"i915_wedged", &i915_wedged_fops},
4811 {"i915_max_freq", &i915_max_freq_fops},
4812 {"i915_min_freq", &i915_min_freq_fops},
4813 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004814 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4815 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004816 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004817#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004818 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004819 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004820#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004821 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004822 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004823 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4824 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4825 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004826 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004827 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4828 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304829 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004830 {"i915_guc_log_control", &i915_guc_log_control_fops},
4831 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004832};
4833
Chris Wilson1dac8912016-06-24 14:00:17 +01004834int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004835{
Chris Wilson91c8a322016-07-05 10:40:23 +01004836 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02004837 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004838
Ben Widawsky6d794d42011-04-25 11:25:56 -07004839 ret = i915_forcewake_create(minor->debugfs_root, minor);
4840 if (ret)
4841 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004842
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004843 ret = intel_pipe_crc_create(minor);
4844 if (ret)
4845 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004846
Daniel Vetter34b96742013-07-04 20:49:44 +02004847 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4848 ret = i915_debugfs_create(minor->debugfs_root, minor,
4849 i915_debugfs_files[i].name,
4850 i915_debugfs_files[i].fops);
4851 if (ret)
4852 return ret;
4853 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004854
Ben Gamari27c202a2009-07-01 22:26:52 -04004855 return drm_debugfs_create_files(i915_debugfs_list,
4856 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004857 minor->debugfs_root, minor);
4858}
4859
Chris Wilson1dac8912016-06-24 14:00:17 +01004860void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004861{
Chris Wilson91c8a322016-07-05 10:40:23 +01004862 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02004863 int i;
4864
Ben Gamari27c202a2009-07-01 22:26:52 -04004865 drm_debugfs_remove_files(i915_debugfs_list,
4866 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004867
David Weinehall36cdd012016-08-22 13:59:31 +03004868 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004869 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004870
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004871 intel_pipe_crc_cleanup(minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004872
Daniel Vetter34b96742013-07-04 20:49:44 +02004873 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4874 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03004875 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02004876
4877 drm_debugfs_remove_files(info_list, 1, minor);
4878 }
Ben Gamari20172632009-02-17 20:08:50 -05004879}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004880
4881struct dpcd_block {
4882 /* DPCD dump start address. */
4883 unsigned int offset;
4884 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4885 unsigned int end;
4886 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4887 size_t size;
4888 /* Only valid for eDP. */
4889 bool edp;
4890};
4891
4892static const struct dpcd_block i915_dpcd_debug[] = {
4893 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4894 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4895 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4896 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4897 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4898 { .offset = DP_SET_POWER },
4899 { .offset = DP_EDP_DPCD_REV },
4900 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4901 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4902 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4903};
4904
4905static int i915_dpcd_show(struct seq_file *m, void *data)
4906{
4907 struct drm_connector *connector = m->private;
4908 struct intel_dp *intel_dp =
4909 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4910 uint8_t buf[16];
4911 ssize_t err;
4912 int i;
4913
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004914 if (connector->status != connector_status_connected)
4915 return -ENODEV;
4916
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004917 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4918 const struct dpcd_block *b = &i915_dpcd_debug[i];
4919 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4920
4921 if (b->edp &&
4922 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4923 continue;
4924
4925 /* low tech for now */
4926 if (WARN_ON(size > sizeof(buf)))
4927 continue;
4928
4929 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4930 if (err <= 0) {
4931 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4932 size, b->offset, err);
4933 continue;
4934 }
4935
4936 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004937 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004938
4939 return 0;
4940}
4941
4942static int i915_dpcd_open(struct inode *inode, struct file *file)
4943{
4944 return single_open(file, i915_dpcd_show, inode->i_private);
4945}
4946
4947static const struct file_operations i915_dpcd_fops = {
4948 .owner = THIS_MODULE,
4949 .open = i915_dpcd_open,
4950 .read = seq_read,
4951 .llseek = seq_lseek,
4952 .release = single_release,
4953};
4954
David Weinehallecbd6782016-08-23 12:23:56 +03004955static int i915_panel_show(struct seq_file *m, void *data)
4956{
4957 struct drm_connector *connector = m->private;
4958 struct intel_dp *intel_dp =
4959 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4960
4961 if (connector->status != connector_status_connected)
4962 return -ENODEV;
4963
4964 seq_printf(m, "Panel power up delay: %d\n",
4965 intel_dp->panel_power_up_delay);
4966 seq_printf(m, "Panel power down delay: %d\n",
4967 intel_dp->panel_power_down_delay);
4968 seq_printf(m, "Backlight on delay: %d\n",
4969 intel_dp->backlight_on_delay);
4970 seq_printf(m, "Backlight off delay: %d\n",
4971 intel_dp->backlight_off_delay);
4972
4973 return 0;
4974}
4975
4976static int i915_panel_open(struct inode *inode, struct file *file)
4977{
4978 return single_open(file, i915_panel_show, inode->i_private);
4979}
4980
4981static const struct file_operations i915_panel_fops = {
4982 .owner = THIS_MODULE,
4983 .open = i915_panel_open,
4984 .read = seq_read,
4985 .llseek = seq_lseek,
4986 .release = single_release,
4987};
4988
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004989/**
4990 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4991 * @connector: pointer to a registered drm_connector
4992 *
4993 * Cleanup will be done by drm_connector_unregister() through a call to
4994 * drm_debugfs_connector_remove().
4995 *
4996 * Returns 0 on success, negative error codes on error.
4997 */
4998int i915_debugfs_connector_add(struct drm_connector *connector)
4999{
5000 struct dentry *root = connector->debugfs_entry;
5001
5002 /* The connector must have been registered beforehands. */
5003 if (!root)
5004 return -ENODEV;
5005
5006 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5007 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005008 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5009 connector, &i915_dpcd_fops);
5010
5011 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5012 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5013 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005014
5015 return 0;
5016}