blob: 1a28b5279bec6cf220bd1ea1bfeb3e13d5facf6b [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
Akash Goel3b3f1652016-10-13 22:44:48 +05301364 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001365 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1366 struct rb_node *rb;
1367
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001368 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001369 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001370 engine->hangcheck.seqno, seqno[id],
1371 intel_engine_last_submit(engine));
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001372 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001373 yesno(intel_engine_has_waiter(engine)),
1374 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001375 &dev_priv->gpu_error.missed_irq_rings)),
1376 yesno(engine->hangcheck.stalled));
1377
Chris Wilsonf6168e32016-10-28 13:58:55 +01001378 spin_lock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001379 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001380 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001381
1382 seq_printf(m, "\t%s [%d] waiting for %x\n",
1383 w->tsk->comm, w->tsk->pid, w->seqno);
1384 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01001385 spin_unlock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001386
Chris Wilsonf6544492015-01-26 18:03:04 +02001387 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001388 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001389 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001390 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1391 hangcheck_action_to_str(engine->hangcheck.action),
1392 engine->hangcheck.action,
1393 jiffies_to_msecs(jiffies -
1394 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001395
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001396 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001397 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001398
Ben Widawskyd6369512016-09-20 16:54:32 +03001399 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001400
Ben Widawskyd6369512016-09-20 16:54:32 +03001401 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001402
Ben Widawskyd6369512016-09-20 16:54:32 +03001403 i915_instdone_info(dev_priv, m,
1404 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001405 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001406 }
1407
1408 return 0;
1409}
1410
Ben Widawsky4d855292011-12-12 19:34:16 -08001411static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001412{
David Weinehall36cdd012016-08-22 13:59:31 +03001413 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001414 u32 rgvmodectl, rstdbyctl;
1415 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001416
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001417 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001418
1419 rgvmodectl = I915_READ(MEMMODECTL);
1420 rstdbyctl = I915_READ(RSTDBYCTL);
1421 crstandvid = I915_READ16(CRSTANDVID);
1422
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001423 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001424
Jani Nikula742f4912015-09-03 11:16:09 +03001425 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426 seq_printf(m, "Boost freq: %d\n",
1427 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1428 MEMMODE_BOOST_FREQ_SHIFT);
1429 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001430 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001431 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001432 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001433 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001434 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001435 seq_printf(m, "Starting frequency: P%d\n",
1436 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001437 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001438 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001439 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1440 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1441 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1442 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001443 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 switch (rstdbyctl & RSX_STATUS_MASK) {
1446 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 break;
1449 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001457 break;
1458 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001459 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001460 break;
1461 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001462 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001463 break;
1464 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001465 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001466 break;
1467 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001468
1469 return 0;
1470}
1471
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001472static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001473{
David Weinehall36cdd012016-08-22 13:59:31 +03001474 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001475 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001476
1477 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001478 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001479 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001480 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001481 fw_domain->wake_count);
1482 }
1483 spin_unlock_irq(&dev_priv->uncore.lock);
1484
1485 return 0;
1486}
1487
Deepak S669ab5a2014-01-10 15:18:26 +05301488static int vlv_drpc_info(struct seq_file *m)
1489{
David Weinehall36cdd012016-08-22 13:59:31 +03001490 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001491 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301492
Imre Deakd46c0512014-04-14 20:24:27 +03001493 intel_runtime_pm_get(dev_priv);
1494
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001495 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301496 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1497 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1498
Imre Deakd46c0512014-04-14 20:24:27 +03001499 intel_runtime_pm_put(dev_priv);
1500
Deepak S669ab5a2014-01-10 15:18:26 +05301501 seq_printf(m, "Video Turbo Mode: %s\n",
1502 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1503 seq_printf(m, "Turbo enabled: %s\n",
1504 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1505 seq_printf(m, "HW control enabled: %s\n",
1506 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1507 seq_printf(m, "SW control enabled: %s\n",
1508 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1509 GEN6_RP_MEDIA_SW_MODE));
1510 seq_printf(m, "RC6 Enabled: %s\n",
1511 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1512 GEN6_RC_CTL_EI_MODE(1))));
1513 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001514 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301515 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001516 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301517
Imre Deak9cc19be2014-04-14 20:24:24 +03001518 seq_printf(m, "Render RC6 residency since boot: %u\n",
1519 I915_READ(VLV_GT_RENDER_RC6));
1520 seq_printf(m, "Media RC6 residency since boot: %u\n",
1521 I915_READ(VLV_GT_MEDIA_RC6));
1522
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001523 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301524}
1525
Ben Widawsky4d855292011-12-12 19:34:16 -08001526static int gen6_drpc_info(struct seq_file *m)
1527{
David Weinehall36cdd012016-08-22 13:59:31 +03001528 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1529 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001530 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301531 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001532 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001533 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001534
1535 ret = mutex_lock_interruptible(&dev->struct_mutex);
1536 if (ret)
1537 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001538 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001539
Chris Wilson907b28c2013-07-19 20:36:52 +01001540 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001541 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001542 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001543
1544 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "RC information inaccurate because somebody "
1546 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 } else {
1548 /* NB: we cannot use forcewake, else we read the wrong values */
1549 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1550 udelay(10);
1551 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1552 }
1553
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001554 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001555 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001556
1557 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1558 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001559 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301560 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1561 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1562 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001564 mutex_lock(&dev_priv->rps.hw_lock);
1565 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1566 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001567
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001568 intel_runtime_pm_put(dev_priv);
1569
Ben Widawsky4d855292011-12-12 19:34:16 -08001570 seq_printf(m, "Video Turbo Mode: %s\n",
1571 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1572 seq_printf(m, "HW control enabled: %s\n",
1573 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1574 seq_printf(m, "SW control enabled: %s\n",
1575 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1576 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001577 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001578 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1579 seq_printf(m, "RC6 Enabled: %s\n",
1580 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001581 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301582 seq_printf(m, "Render Well Gating Enabled: %s\n",
1583 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1584 seq_printf(m, "Media Well Gating Enabled: %s\n",
1585 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1586 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 seq_printf(m, "Deep RC6 Enabled: %s\n",
1588 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1589 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1590 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001591 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001592 switch (gt_core_status & GEN6_RCn_MASK) {
1593 case GEN6_RC0:
1594 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001596 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001597 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001598 break;
1599 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001600 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001601 break;
1602 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001603 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001604 break;
1605 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001606 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001607 break;
1608 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001609 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001610 break;
1611 }
1612
1613 seq_printf(m, "Core Power Down: %s\n",
1614 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001615 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301616 seq_printf(m, "Render Power Well: %s\n",
1617 (gen9_powergate_status &
1618 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1619 seq_printf(m, "Media Power Well: %s\n",
1620 (gen9_powergate_status &
1621 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1622 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001623
1624 /* Not exactly sure what this is */
1625 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1626 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1627 seq_printf(m, "RC6 residency since boot: %u\n",
1628 I915_READ(GEN6_GT_GFX_RC6));
1629 seq_printf(m, "RC6+ residency since boot: %u\n",
1630 I915_READ(GEN6_GT_GFX_RC6p));
1631 seq_printf(m, "RC6++ residency since boot: %u\n",
1632 I915_READ(GEN6_GT_GFX_RC6pp));
1633
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001634 seq_printf(m, "RC6 voltage: %dmV\n",
1635 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1636 seq_printf(m, "RC6+ voltage: %dmV\n",
1637 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1638 seq_printf(m, "RC6++ voltage: %dmV\n",
1639 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301640 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001641}
1642
1643static int i915_drpc_info(struct seq_file *m, void *unused)
1644{
David Weinehall36cdd012016-08-22 13:59:31 +03001645 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001646
David Weinehall36cdd012016-08-22 13:59:31 +03001647 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301648 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001649 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001650 return gen6_drpc_info(m);
1651 else
1652 return ironlake_drpc_info(m);
1653}
1654
Daniel Vetter9a851782015-06-18 10:30:22 +02001655static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1656{
David Weinehall36cdd012016-08-22 13:59:31 +03001657 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001658
1659 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1660 dev_priv->fb_tracking.busy_bits);
1661
1662 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1663 dev_priv->fb_tracking.flip_bits);
1664
1665 return 0;
1666}
1667
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001668static int i915_fbc_status(struct seq_file *m, void *unused)
1669{
David Weinehall36cdd012016-08-22 13:59:31 +03001670 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001671
David Weinehall36cdd012016-08-22 13:59:31 +03001672 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001673 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001674 return 0;
1675 }
1676
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001677 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001678 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001679
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001680 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001681 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001682 else
1683 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001684 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001685
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001686 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1687 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1688 BDW_FBC_COMPRESSION_MASK :
1689 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001690 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001691 yesno(I915_READ(FBC_STATUS2) & mask));
1692 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001693
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001694 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001695 intel_runtime_pm_put(dev_priv);
1696
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001697 return 0;
1698}
1699
Rodrigo Vivida46f932014-08-01 02:04:45 -07001700static int i915_fbc_fc_get(void *data, u64 *val)
1701{
David Weinehall36cdd012016-08-22 13:59:31 +03001702 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001703
David Weinehall36cdd012016-08-22 13:59:31 +03001704 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001705 return -ENODEV;
1706
Rodrigo Vivida46f932014-08-01 02:04:45 -07001707 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001708
1709 return 0;
1710}
1711
1712static int i915_fbc_fc_set(void *data, u64 val)
1713{
David Weinehall36cdd012016-08-22 13:59:31 +03001714 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001715 u32 reg;
1716
David Weinehall36cdd012016-08-22 13:59:31 +03001717 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001718 return -ENODEV;
1719
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001720 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001721
1722 reg = I915_READ(ILK_DPFC_CONTROL);
1723 dev_priv->fbc.false_color = val;
1724
1725 I915_WRITE(ILK_DPFC_CONTROL, val ?
1726 (reg | FBC_CTL_FALSE_COLOR) :
1727 (reg & ~FBC_CTL_FALSE_COLOR));
1728
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001729 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001730 return 0;
1731}
1732
1733DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1734 i915_fbc_fc_get, i915_fbc_fc_set,
1735 "%llu\n");
1736
Paulo Zanoni92d44622013-05-31 16:33:24 -03001737static int i915_ips_status(struct seq_file *m, void *unused)
1738{
David Weinehall36cdd012016-08-22 13:59:31 +03001739 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001740
David Weinehall36cdd012016-08-22 13:59:31 +03001741 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001742 seq_puts(m, "not supported\n");
1743 return 0;
1744 }
1745
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001746 intel_runtime_pm_get(dev_priv);
1747
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001748 seq_printf(m, "Enabled by kernel parameter: %s\n",
1749 yesno(i915.enable_ips));
1750
David Weinehall36cdd012016-08-22 13:59:31 +03001751 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001752 seq_puts(m, "Currently: unknown\n");
1753 } else {
1754 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1755 seq_puts(m, "Currently: enabled\n");
1756 else
1757 seq_puts(m, "Currently: disabled\n");
1758 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001759
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001760 intel_runtime_pm_put(dev_priv);
1761
Paulo Zanoni92d44622013-05-31 16:33:24 -03001762 return 0;
1763}
1764
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001765static int i915_sr_status(struct seq_file *m, void *unused)
1766{
David Weinehall36cdd012016-08-22 13:59:31 +03001767 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001768 bool sr_enabled = false;
1769
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001770 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001771 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001772
David Weinehall36cdd012016-08-22 13:59:31 +03001773 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001774 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001775 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001776 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001777 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001778 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001779 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001780 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001781 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001782 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001783 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001784
Chris Wilson9c870d02016-10-24 13:42:15 +01001785 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001786 intel_runtime_pm_put(dev_priv);
1787
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001788 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001789
1790 return 0;
1791}
1792
Jesse Barnes7648fa92010-05-20 14:28:11 -07001793static int i915_emon_status(struct seq_file *m, void *unused)
1794{
David Weinehall36cdd012016-08-22 13:59:31 +03001795 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1796 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001797 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001798 int ret;
1799
David Weinehall36cdd012016-08-22 13:59:31 +03001800 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001801 return -ENODEV;
1802
Chris Wilsonde227ef2010-07-03 07:58:38 +01001803 ret = mutex_lock_interruptible(&dev->struct_mutex);
1804 if (ret)
1805 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001806
1807 temp = i915_mch_val(dev_priv);
1808 chipset = i915_chipset_val(dev_priv);
1809 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001810 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001811
1812 seq_printf(m, "GMCH temp: %ld\n", temp);
1813 seq_printf(m, "Chipset power: %ld\n", chipset);
1814 seq_printf(m, "GFX power: %ld\n", gfx);
1815 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1816
1817 return 0;
1818}
1819
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001820static int i915_ring_freq_table(struct seq_file *m, void *unused)
1821{
David Weinehall36cdd012016-08-22 13:59:31 +03001822 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001823 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001824 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301825 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001826
Carlos Santa26310342016-08-17 12:30:41 -07001827 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001828 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001829 return 0;
1830 }
1831
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001832 intel_runtime_pm_get(dev_priv);
1833
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001834 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001835 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001836 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001837
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001838 if (IS_GEN9_BC(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301839 /* Convert GT frequency to 50 HZ units */
1840 min_gpu_freq =
1841 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1842 max_gpu_freq =
1843 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1844 } else {
1845 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1846 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1847 }
1848
Damien Lespiau267f0c92013-06-24 22:59:48 +01001849 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001850
Akash Goelf936ec32015-06-29 14:50:22 +05301851 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001852 ia_freq = gpu_freq;
1853 sandybridge_pcode_read(dev_priv,
1854 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1855 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001856 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301857 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001858 (IS_GEN9_BC(dev_priv) ?
1859 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001860 ((ia_freq >> 0) & 0xff) * 100,
1861 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001862 }
1863
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001864 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001865
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001866out:
1867 intel_runtime_pm_put(dev_priv);
1868 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001869}
1870
Chris Wilson44834a62010-08-19 16:09:23 +01001871static int i915_opregion(struct seq_file *m, void *unused)
1872{
David Weinehall36cdd012016-08-22 13:59:31 +03001873 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1874 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001875 struct intel_opregion *opregion = &dev_priv->opregion;
1876 int ret;
1877
1878 ret = mutex_lock_interruptible(&dev->struct_mutex);
1879 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001880 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001881
Jani Nikula2455a8e2015-12-14 12:50:53 +02001882 if (opregion->header)
1883 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001884
1885 mutex_unlock(&dev->struct_mutex);
1886
Daniel Vetter0d38f002012-04-21 22:49:10 +02001887out:
Chris Wilson44834a62010-08-19 16:09:23 +01001888 return 0;
1889}
1890
Jani Nikulaada8f952015-12-15 13:17:12 +02001891static int i915_vbt(struct seq_file *m, void *unused)
1892{
David Weinehall36cdd012016-08-22 13:59:31 +03001893 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001894
1895 if (opregion->vbt)
1896 seq_write(m, opregion->vbt, opregion->vbt_size);
1897
1898 return 0;
1899}
1900
Chris Wilson37811fc2010-08-25 22:45:57 +01001901static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1902{
David Weinehall36cdd012016-08-22 13:59:31 +03001903 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1904 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301905 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001906 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001907 int ret;
1908
1909 ret = mutex_lock_interruptible(&dev->struct_mutex);
1910 if (ret)
1911 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001912
Daniel Vetter06957262015-08-10 13:34:08 +02001913#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001914 if (dev_priv->fbdev) {
1915 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001916
Chris Wilson25bcce92016-07-02 15:36:00 +01001917 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1918 fbdev_fb->base.width,
1919 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001920 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001921 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001922 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001923 drm_framebuffer_read_refcount(&fbdev_fb->base));
1924 describe_obj(m, fbdev_fb->obj);
1925 seq_putc(m, '\n');
1926 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001927#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001928
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001929 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001930 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301931 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1932 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001933 continue;
1934
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001935 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 +01001936 fb->base.width,
1937 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001938 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001939 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001940 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001941 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001942 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001943 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001944 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001945 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001946 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001947
1948 return 0;
1949}
1950
Chris Wilson7e37f882016-08-02 22:50:21 +01001951static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001952{
1953 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001954 ring->space, ring->head, ring->tail,
1955 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001956}
1957
Ben Widawskye76d3632011-03-19 18:14:29 -07001958static int i915_context_status(struct seq_file *m, void *unused)
1959{
David Weinehall36cdd012016-08-22 13:59:31 +03001960 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1961 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001962 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001963 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301964 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001965 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001966
Daniel Vetterf3d28872014-05-29 23:23:08 +02001967 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001968 if (ret)
1969 return ret;
1970
Ben Widawskya33afea2013-09-17 21:12:45 -07001971 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001972 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001973 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001974 struct task_struct *task;
1975
Chris Wilsonc84455b2016-08-15 10:49:08 +01001976 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001977 if (task) {
1978 seq_printf(m, "(%s [%d]) ",
1979 task->comm, task->pid);
1980 put_task_struct(task);
1981 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001982 } else if (IS_ERR(ctx->file_priv)) {
1983 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001984 } else {
1985 seq_puts(m, "(kernel) ");
1986 }
1987
Chris Wilsonbca44d82016-05-24 14:53:41 +01001988 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1989 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001990
Akash Goel3b3f1652016-10-13 22:44:48 +05301991 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001992 struct intel_context *ce = &ctx->engine[engine->id];
1993
1994 seq_printf(m, "%s: ", engine->name);
1995 seq_putc(m, ce->initialised ? 'I' : 'i');
1996 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001997 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001998 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001999 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002000 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002001 }
2002
Ben Widawskya33afea2013-09-17 21:12:45 -07002003 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002004 }
2005
Daniel Vetterf3d28872014-05-29 23:23:08 +02002006 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002007
2008 return 0;
2009}
2010
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002011static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002012 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002013 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002014{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002015 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002016 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002017 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002018
Chris Wilson7069b142016-04-28 09:56:52 +01002019 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2020
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002021 if (!vma) {
2022 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002023 return;
2024 }
2025
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002026 if (vma->flags & I915_VMA_GLOBAL_BIND)
2027 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002028 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002029
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002030 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002031 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002032 return;
2033 }
2034
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002035 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2036 if (page) {
2037 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002038
2039 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002040 seq_printf(m,
2041 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2042 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002043 reg_state[j], reg_state[j + 1],
2044 reg_state[j + 2], reg_state[j + 3]);
2045 }
2046 kunmap_atomic(reg_state);
2047 }
2048
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002049 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002050 seq_putc(m, '\n');
2051}
2052
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002053static int i915_dump_lrc(struct seq_file *m, void *unused)
2054{
David Weinehall36cdd012016-08-22 13:59:31 +03002055 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2056 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002057 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002058 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302059 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002060 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002061
2062 if (!i915.enable_execlists) {
2063 seq_printf(m, "Logical Ring Contexts are disabled\n");
2064 return 0;
2065 }
2066
2067 ret = mutex_lock_interruptible(&dev->struct_mutex);
2068 if (ret)
2069 return ret;
2070
Dave Gordone28e4042016-01-19 19:02:55 +00002071 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302072 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002073 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002074
2075 mutex_unlock(&dev->struct_mutex);
2076
2077 return 0;
2078}
2079
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002080static const char *swizzle_string(unsigned swizzle)
2081{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002082 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002083 case I915_BIT_6_SWIZZLE_NONE:
2084 return "none";
2085 case I915_BIT_6_SWIZZLE_9:
2086 return "bit9";
2087 case I915_BIT_6_SWIZZLE_9_10:
2088 return "bit9/bit10";
2089 case I915_BIT_6_SWIZZLE_9_11:
2090 return "bit9/bit11";
2091 case I915_BIT_6_SWIZZLE_9_10_11:
2092 return "bit9/bit10/bit11";
2093 case I915_BIT_6_SWIZZLE_9_17:
2094 return "bit9/bit17";
2095 case I915_BIT_6_SWIZZLE_9_10_17:
2096 return "bit9/bit10/bit17";
2097 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002098 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002099 }
2100
2101 return "bug";
2102}
2103
2104static int i915_swizzle_info(struct seq_file *m, void *data)
2105{
David Weinehall36cdd012016-08-22 13:59:31 +03002106 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002107
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002108 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002109
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002110 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2111 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2112 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2113 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2114
David Weinehall36cdd012016-08-22 13:59:31 +03002115 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002116 seq_printf(m, "DDC = 0x%08x\n",
2117 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002118 seq_printf(m, "DDC2 = 0x%08x\n",
2119 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002120 seq_printf(m, "C0DRB3 = 0x%04x\n",
2121 I915_READ16(C0DRB3));
2122 seq_printf(m, "C1DRB3 = 0x%04x\n",
2123 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002124 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002125 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2126 I915_READ(MAD_DIMM_C0));
2127 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2128 I915_READ(MAD_DIMM_C1));
2129 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2130 I915_READ(MAD_DIMM_C2));
2131 seq_printf(m, "TILECTL = 0x%08x\n",
2132 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002133 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002134 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2135 I915_READ(GAMTARBMODE));
2136 else
2137 seq_printf(m, "ARB_MODE = 0x%08x\n",
2138 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002139 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2140 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002141 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002142
2143 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2144 seq_puts(m, "L-shaped memory detected\n");
2145
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002146 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002147
2148 return 0;
2149}
2150
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002151static int per_file_ctx(int id, void *ptr, void *data)
2152{
Chris Wilsone2efd132016-05-24 14:53:34 +01002153 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002154 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002155 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2156
2157 if (!ppgtt) {
2158 seq_printf(m, " no ppgtt for context %d\n",
2159 ctx->user_handle);
2160 return 0;
2161 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002162
Oscar Mateof83d6512014-05-22 14:13:38 +01002163 if (i915_gem_context_is_default(ctx))
2164 seq_puts(m, " default context:\n");
2165 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002166 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002167 ppgtt->debug_dump(ppgtt, m);
2168
2169 return 0;
2170}
2171
David Weinehall36cdd012016-08-22 13:59:31 +03002172static void gen8_ppgtt_info(struct seq_file *m,
2173 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002174{
Ben Widawsky77df6772013-11-02 21:07:30 -07002175 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302176 struct intel_engine_cs *engine;
2177 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002178 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002179
Ben Widawsky77df6772013-11-02 21:07:30 -07002180 if (!ppgtt)
2181 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002182
Akash Goel3b3f1652016-10-13 22:44:48 +05302183 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002184 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002185 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002186 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002187 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002188 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002189 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002190 }
2191 }
2192}
2193
David Weinehall36cdd012016-08-22 13:59:31 +03002194static void gen6_ppgtt_info(struct seq_file *m,
2195 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002196{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002197 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302198 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002199
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002200 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002201 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2202
Akash Goel3b3f1652016-10-13 22:44:48 +05302203 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002204 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002205 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002206 seq_printf(m, "GFX_MODE: 0x%08x\n",
2207 I915_READ(RING_MODE_GEN7(engine)));
2208 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2209 I915_READ(RING_PP_DIR_BASE(engine)));
2210 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2211 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2212 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2213 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002214 }
2215 if (dev_priv->mm.aliasing_ppgtt) {
2216 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2217
Damien Lespiau267f0c92013-06-24 22:59:48 +01002218 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002219 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002220
Ben Widawsky87d60b62013-12-06 14:11:29 -08002221 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002222 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002223
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002224 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002225}
2226
2227static int i915_ppgtt_info(struct seq_file *m, void *data)
2228{
David Weinehall36cdd012016-08-22 13:59:31 +03002229 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2230 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002231 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002232 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002233
Chris Wilson637ee292016-08-22 14:28:20 +01002234 mutex_lock(&dev->filelist_mutex);
2235 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002236 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002237 goto out_unlock;
2238
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002239 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002240
David Weinehall36cdd012016-08-22 13:59:31 +03002241 if (INTEL_GEN(dev_priv) >= 8)
2242 gen8_ppgtt_info(m, dev_priv);
2243 else if (INTEL_GEN(dev_priv) >= 6)
2244 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002245
Michel Thierryea91e402015-07-29 17:23:57 +01002246 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2247 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002248 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002249
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002250 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002251 if (!task) {
2252 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002253 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002254 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002255 seq_printf(m, "\nproc: %s\n", task->comm);
2256 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002257 idr_for_each(&file_priv->context_idr, per_file_ctx,
2258 (void *)(unsigned long)m);
2259 }
2260
Chris Wilson637ee292016-08-22 14:28:20 +01002261out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002262 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002263 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002264out_unlock:
2265 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002266 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002267}
2268
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002269static int count_irq_waiters(struct drm_i915_private *i915)
2270{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002271 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302272 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002273 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002274
Akash Goel3b3f1652016-10-13 22:44:48 +05302275 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002276 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002277
2278 return count;
2279}
2280
Chris Wilson7466c292016-08-15 09:49:33 +01002281static const char *rps_power_to_str(unsigned int power)
2282{
2283 static const char * const strings[] = {
2284 [LOW_POWER] = "low power",
2285 [BETWEEN] = "mixed",
2286 [HIGH_POWER] = "high power",
2287 };
2288
2289 if (power >= ARRAY_SIZE(strings) || !strings[power])
2290 return "unknown";
2291
2292 return strings[power];
2293}
2294
Chris Wilson1854d5c2015-04-07 16:20:32 +01002295static int i915_rps_boost_info(struct seq_file *m, void *data)
2296{
David Weinehall36cdd012016-08-22 13:59:31 +03002297 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2298 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002299 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002300
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002301 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002302 seq_printf(m, "GPU busy? %s [%d requests]\n",
2303 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002304 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002305 seq_printf(m, "Frequency requested %d\n",
2306 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2307 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002308 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2309 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2310 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2311 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002312 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2313 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2314 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2315 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002316
2317 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002318 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002319 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2320 struct drm_i915_file_private *file_priv = file->driver_priv;
2321 struct task_struct *task;
2322
2323 rcu_read_lock();
2324 task = pid_task(file->pid, PIDTYPE_PID);
2325 seq_printf(m, "%s [%d]: %d boosts%s\n",
2326 task ? task->comm : "<unknown>",
2327 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002328 file_priv->rps.boosts,
2329 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002330 rcu_read_unlock();
2331 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002332 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002333 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002334 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002335
Chris Wilson7466c292016-08-15 09:49:33 +01002336 if (INTEL_GEN(dev_priv) >= 6 &&
2337 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002338 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002339 u32 rpup, rpupei;
2340 u32 rpdown, rpdownei;
2341
2342 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2343 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2344 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2345 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2346 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2347 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2348
2349 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2350 rps_power_to_str(dev_priv->rps.power));
2351 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002352 rpup && rpupei ? 100 * rpup / rpupei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002353 dev_priv->rps.up_threshold);
2354 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002355 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Chris Wilson7466c292016-08-15 09:49:33 +01002356 dev_priv->rps.down_threshold);
2357 } else {
2358 seq_puts(m, "\nRPS Autotuning inactive\n");
2359 }
2360
Chris Wilson8d3afd72015-05-21 21:01:47 +01002361 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002362}
2363
Ben Widawsky63573eb2013-07-04 11:02:07 -07002364static int i915_llc(struct seq_file *m, void *data)
2365{
David Weinehall36cdd012016-08-22 13:59:31 +03002366 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002367 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002368
David Weinehall36cdd012016-08-22 13:59:31 +03002369 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002370 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2371 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002372
2373 return 0;
2374}
2375
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002376static int i915_huc_load_status_info(struct seq_file *m, void *data)
2377{
2378 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2379 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2380
2381 if (!HAS_HUC_UCODE(dev_priv))
2382 return 0;
2383
2384 seq_puts(m, "HuC firmware status:\n");
2385 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2386 seq_printf(m, "\tfetch: %s\n",
2387 intel_uc_fw_status_repr(huc_fw->fetch_status));
2388 seq_printf(m, "\tload: %s\n",
2389 intel_uc_fw_status_repr(huc_fw->load_status));
2390 seq_printf(m, "\tversion wanted: %d.%d\n",
2391 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2392 seq_printf(m, "\tversion found: %d.%d\n",
2393 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2394 seq_printf(m, "\theader: offset is %d; size = %d\n",
2395 huc_fw->header_offset, huc_fw->header_size);
2396 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2397 huc_fw->ucode_offset, huc_fw->ucode_size);
2398 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2399 huc_fw->rsa_offset, huc_fw->rsa_size);
2400
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302401 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002402 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302403 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002404
2405 return 0;
2406}
2407
Alex Daifdf5d352015-08-12 15:43:37 +01002408static int i915_guc_load_status_info(struct seq_file *m, void *data)
2409{
David Weinehall36cdd012016-08-22 13:59:31 +03002410 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002411 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Daifdf5d352015-08-12 15:43:37 +01002412 u32 tmp, i;
2413
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002414 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002415 return 0;
2416
2417 seq_printf(m, "GuC firmware status:\n");
2418 seq_printf(m, "\tpath: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002419 guc_fw->path);
Alex Daifdf5d352015-08-12 15:43:37 +01002420 seq_printf(m, "\tfetch: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002421 intel_uc_fw_status_repr(guc_fw->fetch_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002422 seq_printf(m, "\tload: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002423 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002424 seq_printf(m, "\tversion wanted: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002425 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
Alex Daifdf5d352015-08-12 15:43:37 +01002426 seq_printf(m, "\tversion found: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002427 guc_fw->major_ver_found, guc_fw->minor_ver_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002428 seq_printf(m, "\theader: offset is %d; size = %d\n",
2429 guc_fw->header_offset, guc_fw->header_size);
2430 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2431 guc_fw->ucode_offset, guc_fw->ucode_size);
2432 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2433 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002434
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302435 intel_runtime_pm_get(dev_priv);
2436
Alex Daifdf5d352015-08-12 15:43:37 +01002437 tmp = I915_READ(GUC_STATUS);
2438
2439 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2440 seq_printf(m, "\tBootrom status = 0x%x\n",
2441 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2442 seq_printf(m, "\tuKernel status = 0x%x\n",
2443 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2444 seq_printf(m, "\tMIA Core status = 0x%x\n",
2445 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2446 seq_puts(m, "\nScratch registers:\n");
2447 for (i = 0; i < 16; i++)
2448 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2449
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302450 intel_runtime_pm_put(dev_priv);
2451
Alex Daifdf5d352015-08-12 15:43:37 +01002452 return 0;
2453}
2454
Akash Goel5aa1ee42016-10-12 21:54:36 +05302455static void i915_guc_log_info(struct seq_file *m,
2456 struct drm_i915_private *dev_priv)
2457{
2458 struct intel_guc *guc = &dev_priv->guc;
2459
2460 seq_puts(m, "\nGuC logging stats:\n");
2461
2462 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2463 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2464 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2465
2466 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2467 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2468 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2469
2470 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2471 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2472 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2473
2474 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2475 guc->log.flush_interrupt_count);
2476
2477 seq_printf(m, "\tCapture miss count: %u\n",
2478 guc->log.capture_miss_count);
2479}
2480
Dave Gordon8b417c22015-08-12 15:43:44 +01002481static void i915_guc_client_info(struct seq_file *m,
2482 struct drm_i915_private *dev_priv,
2483 struct i915_guc_client *client)
2484{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002485 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002486 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002487 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002488
2489 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2490 client->priority, client->ctx_index, client->proc_desc_offset);
2491 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002492 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002493 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2494 client->wq_size, client->wq_offset, client->wq_tail);
2495
Dave Gordon551aaec2016-05-13 15:36:33 +01002496 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002497 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2498 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2499
Akash Goel3b3f1652016-10-13 22:44:48 +05302500 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002501 u64 submissions = client->submissions[id];
2502 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002503 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002504 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002505 }
2506 seq_printf(m, "\tTotal: %llu\n", tot);
2507}
2508
2509static int i915_guc_info(struct seq_file *m, void *data)
2510{
David Weinehall36cdd012016-08-22 13:59:31 +03002511 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002512 const struct intel_guc *guc = &dev_priv->guc;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002513 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002514 enum intel_engine_id id;
Chris Wilson334636c2016-11-29 12:10:20 +00002515 u64 total;
Dave Gordon8b417c22015-08-12 15:43:44 +01002516
Chris Wilson334636c2016-11-29 12:10:20 +00002517 if (!guc->execbuf_client) {
2518 seq_printf(m, "GuC submission %s\n",
2519 HAS_GUC_SCHED(dev_priv) ?
2520 "disabled" :
2521 "not supported");
Dave Gordon8b417c22015-08-12 15:43:44 +01002522 return 0;
Chris Wilson334636c2016-11-29 12:10:20 +00002523 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002524
Dave Gordon9636f6d2016-06-13 17:57:28 +01002525 seq_printf(m, "Doorbell map:\n");
Chris Wilson334636c2016-11-29 12:10:20 +00002526 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc->doorbell_bitmap);
2527 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002528
Chris Wilson334636c2016-11-29 12:10:20 +00002529 seq_printf(m, "GuC total action count: %llu\n", guc->action_count);
2530 seq_printf(m, "GuC action failure count: %u\n", guc->action_fail);
2531 seq_printf(m, "GuC last action command: 0x%x\n", guc->action_cmd);
2532 seq_printf(m, "GuC last action status: 0x%x\n", guc->action_status);
2533 seq_printf(m, "GuC last action error code: %d\n", guc->action_err);
Dave Gordon8b417c22015-08-12 15:43:44 +01002534
Chris Wilson334636c2016-11-29 12:10:20 +00002535 total = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002536 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302537 for_each_engine(engine, dev_priv, id) {
Chris Wilson334636c2016-11-29 12:10:20 +00002538 u64 submissions = guc->submissions[id];
Dave Gordonc18468c2016-08-09 15:19:22 +01002539 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002540 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Chris Wilson334636c2016-11-29 12:10:20 +00002541 engine->name, submissions, guc->last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002542 }
2543 seq_printf(m, "\t%s: %llu\n", "Total", total);
2544
Chris Wilson334636c2016-11-29 12:10:20 +00002545 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2546 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002547
Akash Goel5aa1ee42016-10-12 21:54:36 +05302548 i915_guc_log_info(m, dev_priv);
2549
Dave Gordon8b417c22015-08-12 15:43:44 +01002550 /* Add more as required ... */
2551
2552 return 0;
2553}
2554
Alex Dai4c7e77f2015-08-12 15:43:40 +01002555static int i915_guc_log_dump(struct seq_file *m, void *data)
2556{
David Weinehall36cdd012016-08-22 13:59:31 +03002557 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002558 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002559 int i = 0, pg;
2560
Akash Goeld6b40b42016-10-12 21:54:29 +05302561 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002562 return 0;
2563
Akash Goeld6b40b42016-10-12 21:54:29 +05302564 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002565 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2566 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002567
2568 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2569 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2570 *(log + i), *(log + i + 1),
2571 *(log + i + 2), *(log + i + 3));
2572
2573 kunmap_atomic(log);
2574 }
2575
2576 seq_putc(m, '\n');
2577
2578 return 0;
2579}
2580
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302581static int i915_guc_log_control_get(void *data, u64 *val)
2582{
2583 struct drm_device *dev = data;
2584 struct drm_i915_private *dev_priv = to_i915(dev);
2585
2586 if (!dev_priv->guc.log.vma)
2587 return -EINVAL;
2588
2589 *val = i915.guc_log_level;
2590
2591 return 0;
2592}
2593
2594static int i915_guc_log_control_set(void *data, u64 val)
2595{
2596 struct drm_device *dev = data;
2597 struct drm_i915_private *dev_priv = to_i915(dev);
2598 int ret;
2599
2600 if (!dev_priv->guc.log.vma)
2601 return -EINVAL;
2602
2603 ret = mutex_lock_interruptible(&dev->struct_mutex);
2604 if (ret)
2605 return ret;
2606
2607 intel_runtime_pm_get(dev_priv);
2608 ret = i915_guc_log_control(dev_priv, val);
2609 intel_runtime_pm_put(dev_priv);
2610
2611 mutex_unlock(&dev->struct_mutex);
2612 return ret;
2613}
2614
2615DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2616 i915_guc_log_control_get, i915_guc_log_control_set,
2617 "%lld\n");
2618
Chris Wilsonb86bef202017-01-16 13:06:21 +00002619static const char *psr2_live_status(u32 val)
2620{
2621 static const char * const live_status[] = {
2622 "IDLE",
2623 "CAPTURE",
2624 "CAPTURE_FS",
2625 "SLEEP",
2626 "BUFON_FW",
2627 "ML_UP",
2628 "SU_STANDBY",
2629 "FAST_SLEEP",
2630 "DEEP_SLEEP",
2631 "BUF_ON",
2632 "TG_ON"
2633 };
2634
2635 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2636 if (val < ARRAY_SIZE(live_status))
2637 return live_status[val];
2638
2639 return "unknown";
2640}
2641
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002642static int i915_edp_psr_status(struct seq_file *m, void *data)
2643{
David Weinehall36cdd012016-08-22 13:59:31 +03002644 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002645 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002646 u32 stat[3];
2647 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002648 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002649
David Weinehall36cdd012016-08-22 13:59:31 +03002650 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002651 seq_puts(m, "PSR not supported\n");
2652 return 0;
2653 }
2654
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002655 intel_runtime_pm_get(dev_priv);
2656
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002657 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002658 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2659 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002660 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002661 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002662 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2663 dev_priv->psr.busy_frontbuffer_bits);
2664 seq_printf(m, "Re-enable work scheduled: %s\n",
2665 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002666
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302667 if (HAS_DDI(dev_priv)) {
2668 if (dev_priv->psr.psr2_support)
2669 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2670 else
2671 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2672 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002673 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002674 enum transcoder cpu_transcoder =
2675 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2676 enum intel_display_power_domain power_domain;
2677
2678 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2679 if (!intel_display_power_get_if_enabled(dev_priv,
2680 power_domain))
2681 continue;
2682
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002683 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2684 VLV_EDP_PSR_CURR_STATE_MASK;
2685 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2686 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2687 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002688
2689 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002690 }
2691 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002692
2693 seq_printf(m, "Main link in standby mode: %s\n",
2694 yesno(dev_priv->psr.link_standby));
2695
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002696 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002697
David Weinehall36cdd012016-08-22 13:59:31 +03002698 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002699 for_each_pipe(dev_priv, pipe) {
2700 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2701 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2702 seq_printf(m, " pipe %c", pipe_name(pipe));
2703 }
2704 seq_puts(m, "\n");
2705
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002706 /*
2707 * VLV/CHV PSR has no kind of performance counter
2708 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2709 */
David Weinehall36cdd012016-08-22 13:59:31 +03002710 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002711 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002712 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002713
2714 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2715 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302716 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002717 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302718
Chris Wilsonb86bef202017-01-16 13:06:21 +00002719 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2720 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302721 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002722 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002723
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002724 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002725 return 0;
2726}
2727
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002728static int i915_sink_crc(struct seq_file *m, void *data)
2729{
David Weinehall36cdd012016-08-22 13:59:31 +03002730 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2731 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002732 struct intel_connector *connector;
2733 struct intel_dp *intel_dp = NULL;
2734 int ret;
2735 u8 crc[6];
2736
2737 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002738 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002739 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002740
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002741 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002742 continue;
2743
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002744 crtc = connector->base.state->crtc;
2745 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002746 continue;
2747
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002748 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002749 continue;
2750
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002751 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002752
2753 ret = intel_dp_sink_crc(intel_dp, crc);
2754 if (ret)
2755 goto out;
2756
2757 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2758 crc[0], crc[1], crc[2],
2759 crc[3], crc[4], crc[5]);
2760 goto out;
2761 }
2762 ret = -ENODEV;
2763out:
2764 drm_modeset_unlock_all(dev);
2765 return ret;
2766}
2767
Jesse Barnesec013e72013-08-20 10:29:23 +01002768static int i915_energy_uJ(struct seq_file *m, void *data)
2769{
David Weinehall36cdd012016-08-22 13:59:31 +03002770 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002771 u64 power;
2772 u32 units;
2773
David Weinehall36cdd012016-08-22 13:59:31 +03002774 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002775 return -ENODEV;
2776
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002777 intel_runtime_pm_get(dev_priv);
2778
Jesse Barnesec013e72013-08-20 10:29:23 +01002779 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2780 power = (power & 0x1f00) >> 8;
2781 units = 1000000 / (1 << power); /* convert to uJ */
2782 power = I915_READ(MCH_SECP_NRG_STTS);
2783 power *= units;
2784
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002785 intel_runtime_pm_put(dev_priv);
2786
Jesse Barnesec013e72013-08-20 10:29:23 +01002787 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002788
2789 return 0;
2790}
2791
Damien Lespiau6455c872015-06-04 18:23:57 +01002792static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002793{
David Weinehall36cdd012016-08-22 13:59:31 +03002794 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002795 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002796
Chris Wilsona156e642016-04-03 14:14:21 +01002797 if (!HAS_RUNTIME_PM(dev_priv))
2798 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002799
Chris Wilson67d97da2016-07-04 08:08:31 +01002800 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002801 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002802 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002803#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002804 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002805 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002806#else
2807 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2808#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002809 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002810 pci_power_name(pdev->current_state),
2811 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002812
Jesse Barnesec013e72013-08-20 10:29:23 +01002813 return 0;
2814}
2815
Imre Deak1da51582013-11-25 17:15:35 +02002816static int i915_power_domain_info(struct seq_file *m, void *unused)
2817{
David Weinehall36cdd012016-08-22 13:59:31 +03002818 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002819 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2820 int i;
2821
2822 mutex_lock(&power_domains->lock);
2823
2824 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2825 for (i = 0; i < power_domains->power_well_count; i++) {
2826 struct i915_power_well *power_well;
2827 enum intel_display_power_domain power_domain;
2828
2829 power_well = &power_domains->power_wells[i];
2830 seq_printf(m, "%-25s %d\n", power_well->name,
2831 power_well->count);
2832
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002833 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002834 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002835 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002836 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002837 }
2838
2839 mutex_unlock(&power_domains->lock);
2840
2841 return 0;
2842}
2843
Damien Lespiaub7cec662015-10-27 14:47:01 +02002844static int i915_dmc_info(struct seq_file *m, void *unused)
2845{
David Weinehall36cdd012016-08-22 13:59:31 +03002846 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002847 struct intel_csr *csr;
2848
David Weinehall36cdd012016-08-22 13:59:31 +03002849 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002850 seq_puts(m, "not supported\n");
2851 return 0;
2852 }
2853
2854 csr = &dev_priv->csr;
2855
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002856 intel_runtime_pm_get(dev_priv);
2857
Damien Lespiaub7cec662015-10-27 14:47:01 +02002858 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2859 seq_printf(m, "path: %s\n", csr->fw_path);
2860
2861 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002862 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002863
2864 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2865 CSR_VERSION_MINOR(csr->version));
2866
David Weinehall36cdd012016-08-22 13:59:31 +03002867 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002868 seq_printf(m, "DC3 -> DC5 count: %d\n",
2869 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2870 seq_printf(m, "DC5 -> DC6 count: %d\n",
2871 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002872 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002873 seq_printf(m, "DC3 -> DC5 count: %d\n",
2874 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002875 }
2876
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002877out:
2878 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2879 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2880 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2881
Damien Lespiau83372062015-10-30 17:53:32 +02002882 intel_runtime_pm_put(dev_priv);
2883
Damien Lespiaub7cec662015-10-27 14:47:01 +02002884 return 0;
2885}
2886
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002887static void intel_seq_print_mode(struct seq_file *m, int tabs,
2888 struct drm_display_mode *mode)
2889{
2890 int i;
2891
2892 for (i = 0; i < tabs; i++)
2893 seq_putc(m, '\t');
2894
2895 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",
2896 mode->base.id, mode->name,
2897 mode->vrefresh, mode->clock,
2898 mode->hdisplay, mode->hsync_start,
2899 mode->hsync_end, mode->htotal,
2900 mode->vdisplay, mode->vsync_start,
2901 mode->vsync_end, mode->vtotal,
2902 mode->type, mode->flags);
2903}
2904
2905static void intel_encoder_info(struct seq_file *m,
2906 struct intel_crtc *intel_crtc,
2907 struct intel_encoder *intel_encoder)
2908{
David Weinehall36cdd012016-08-22 13:59:31 +03002909 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2910 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002911 struct drm_crtc *crtc = &intel_crtc->base;
2912 struct intel_connector *intel_connector;
2913 struct drm_encoder *encoder;
2914
2915 encoder = &intel_encoder->base;
2916 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002917 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002918 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2919 struct drm_connector *connector = &intel_connector->base;
2920 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2921 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002922 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002923 drm_get_connector_status_name(connector->status));
2924 if (connector->status == connector_status_connected) {
2925 struct drm_display_mode *mode = &crtc->mode;
2926 seq_printf(m, ", mode:\n");
2927 intel_seq_print_mode(m, 2, mode);
2928 } else {
2929 seq_putc(m, '\n');
2930 }
2931 }
2932}
2933
2934static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2935{
David Weinehall36cdd012016-08-22 13:59:31 +03002936 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2937 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002938 struct drm_crtc *crtc = &intel_crtc->base;
2939 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002940 struct drm_plane_state *plane_state = crtc->primary->state;
2941 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002942
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002943 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002944 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002945 fb->base.id, plane_state->src_x >> 16,
2946 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002947 else
2948 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002949 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2950 intel_encoder_info(m, intel_crtc, intel_encoder);
2951}
2952
2953static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2954{
2955 struct drm_display_mode *mode = panel->fixed_mode;
2956
2957 seq_printf(m, "\tfixed mode:\n");
2958 intel_seq_print_mode(m, 2, mode);
2959}
2960
2961static void intel_dp_info(struct seq_file *m,
2962 struct intel_connector *intel_connector)
2963{
2964 struct intel_encoder *intel_encoder = intel_connector->encoder;
2965 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2966
2967 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002968 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002969 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002970 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002971
2972 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2973 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002974}
2975
Libin Yang9a148a92016-11-28 20:07:05 +08002976static void intel_dp_mst_info(struct seq_file *m,
2977 struct intel_connector *intel_connector)
2978{
2979 struct intel_encoder *intel_encoder = intel_connector->encoder;
2980 struct intel_dp_mst_encoder *intel_mst =
2981 enc_to_mst(&intel_encoder->base);
2982 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2983 struct intel_dp *intel_dp = &intel_dig_port->dp;
2984 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2985 intel_connector->port);
2986
2987 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2988}
2989
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002990static void intel_hdmi_info(struct seq_file *m,
2991 struct intel_connector *intel_connector)
2992{
2993 struct intel_encoder *intel_encoder = intel_connector->encoder;
2994 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2995
Jani Nikula742f4912015-09-03 11:16:09 +03002996 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002997}
2998
2999static void intel_lvds_info(struct seq_file *m,
3000 struct intel_connector *intel_connector)
3001{
3002 intel_panel_info(m, &intel_connector->panel);
3003}
3004
3005static void intel_connector_info(struct seq_file *m,
3006 struct drm_connector *connector)
3007{
3008 struct intel_connector *intel_connector = to_intel_connector(connector);
3009 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08003010 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003011
3012 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03003013 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003014 drm_get_connector_status_name(connector->status));
3015 if (connector->status == connector_status_connected) {
3016 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3017 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3018 connector->display_info.width_mm,
3019 connector->display_info.height_mm);
3020 seq_printf(m, "\tsubpixel order: %s\n",
3021 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3022 seq_printf(m, "\tCEA rev: %d\n",
3023 connector->display_info.cea_rev);
3024 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003025
3026 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3027 return;
3028
3029 switch (connector->connector_type) {
3030 case DRM_MODE_CONNECTOR_DisplayPort:
3031 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003032 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3033 intel_dp_mst_info(m, intel_connector);
3034 else
3035 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003036 break;
3037 case DRM_MODE_CONNECTOR_LVDS:
3038 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003039 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003040 break;
3041 case DRM_MODE_CONNECTOR_HDMIA:
3042 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3043 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3044 intel_hdmi_info(m, intel_connector);
3045 break;
3046 default:
3047 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003048 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003049
Jesse Barnesf103fc72014-02-20 12:39:57 -08003050 seq_printf(m, "\tmodes:\n");
3051 list_for_each_entry(mode, &connector->modes, head)
3052 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003053}
3054
David Weinehall36cdd012016-08-22 13:59:31 +03003055static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec22014-03-12 09:13:13 +00003056{
Chris Wilson065f2ec22014-03-12 09:13:13 +00003057 u32 state;
3058
Jani Nikula2a307c22016-11-30 17:43:04 +02003059 if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003060 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003061 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003062 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003063
3064 return state;
3065}
3066
David Weinehall36cdd012016-08-22 13:59:31 +03003067static bool cursor_position(struct drm_i915_private *dev_priv,
3068 int pipe, int *x, int *y)
Chris Wilson065f2ec22014-03-12 09:13:13 +00003069{
Chris Wilson065f2ec22014-03-12 09:13:13 +00003070 u32 pos;
3071
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003072 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00003073
3074 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3075 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3076 *x = -*x;
3077
3078 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3079 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3080 *y = -*y;
3081
David Weinehall36cdd012016-08-22 13:59:31 +03003082 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec22014-03-12 09:13:13 +00003083}
3084
Robert Fekete3abc4e02015-10-27 16:58:32 +01003085static const char *plane_type(enum drm_plane_type type)
3086{
3087 switch (type) {
3088 case DRM_PLANE_TYPE_OVERLAY:
3089 return "OVL";
3090 case DRM_PLANE_TYPE_PRIMARY:
3091 return "PRI";
3092 case DRM_PLANE_TYPE_CURSOR:
3093 return "CUR";
3094 /*
3095 * Deliberately omitting default: to generate compiler warnings
3096 * when a new drm_plane_type gets added.
3097 */
3098 }
3099
3100 return "unknown";
3101}
3102
3103static const char *plane_rotation(unsigned int rotation)
3104{
3105 static char buf[48];
3106 /*
3107 * According to doc only one DRM_ROTATE_ is allowed but this
3108 * will print them all to visualize if the values are misused
3109 */
3110 snprintf(buf, sizeof(buf),
3111 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003112 (rotation & DRM_ROTATE_0) ? "0 " : "",
3113 (rotation & DRM_ROTATE_90) ? "90 " : "",
3114 (rotation & DRM_ROTATE_180) ? "180 " : "",
3115 (rotation & DRM_ROTATE_270) ? "270 " : "",
3116 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3117 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003118 rotation);
3119
3120 return buf;
3121}
3122
3123static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3124{
David Weinehall36cdd012016-08-22 13:59:31 +03003125 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3126 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003127 struct intel_plane *intel_plane;
3128
3129 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3130 struct drm_plane_state *state;
3131 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003132 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003133
3134 if (!plane->state) {
3135 seq_puts(m, "plane->state is NULL!\n");
3136 continue;
3137 }
3138
3139 state = plane->state;
3140
Eric Engestrom90844f02016-08-15 01:02:38 +01003141 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003142 drm_get_format_name(state->fb->format->format,
3143 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003144 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003145 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003146 }
3147
Robert Fekete3abc4e02015-10-27 16:58:32 +01003148 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",
3149 plane->base.id,
3150 plane_type(intel_plane->base.type),
3151 state->crtc_x, state->crtc_y,
3152 state->crtc_w, state->crtc_h,
3153 (state->src_x >> 16),
3154 ((state->src_x & 0xffff) * 15625) >> 10,
3155 (state->src_y >> 16),
3156 ((state->src_y & 0xffff) * 15625) >> 10,
3157 (state->src_w >> 16),
3158 ((state->src_w & 0xffff) * 15625) >> 10,
3159 (state->src_h >> 16),
3160 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003161 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003162 plane_rotation(state->rotation));
3163 }
3164}
3165
3166static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3167{
3168 struct intel_crtc_state *pipe_config;
3169 int num_scalers = intel_crtc->num_scalers;
3170 int i;
3171
3172 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3173
3174 /* Not all platformas have a scaler */
3175 if (num_scalers) {
3176 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3177 num_scalers,
3178 pipe_config->scaler_state.scaler_users,
3179 pipe_config->scaler_state.scaler_id);
3180
A.Sunil Kamath58415912016-11-20 23:20:26 +05303181 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003182 struct intel_scaler *sc =
3183 &pipe_config->scaler_state.scalers[i];
3184
3185 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3186 i, yesno(sc->in_use), sc->mode);
3187 }
3188 seq_puts(m, "\n");
3189 } else {
3190 seq_puts(m, "\tNo scalers available on this platform\n");
3191 }
3192}
3193
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003194static int i915_display_info(struct seq_file *m, void *unused)
3195{
David Weinehall36cdd012016-08-22 13:59:31 +03003196 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3197 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003198 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003199 struct drm_connector *connector;
3200
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003201 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003202 drm_modeset_lock_all(dev);
3203 seq_printf(m, "CRTC info\n");
3204 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003205 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003206 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003207 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003208 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003209
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003210 pipe_config = to_intel_crtc_state(crtc->base.state);
3211
Robert Fekete3abc4e02015-10-27 16:58:32 +01003212 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003213 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003214 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003215 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3216 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3217
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003218 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003219 intel_crtc_info(m, crtc);
3220
David Weinehall36cdd012016-08-22 13:59:31 +03003221 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003222 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 +03003223 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003224 x, y, crtc->base.cursor->state->crtc_w,
3225 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003226 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003227 intel_scaler_info(m, crtc);
3228 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003229 }
Daniel Vettercace8412014-05-22 17:56:31 +02003230
3231 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3232 yesno(!crtc->cpu_fifo_underrun_disabled),
3233 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003234 }
3235
3236 seq_printf(m, "\n");
3237 seq_printf(m, "Connector info\n");
3238 seq_printf(m, "--------------\n");
3239 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3240 intel_connector_info(m, connector);
3241 }
3242 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003243 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003244
3245 return 0;
3246}
3247
Chris Wilson1b365952016-10-04 21:11:31 +01003248static int i915_engine_info(struct seq_file *m, void *unused)
3249{
3250 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3251 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303252 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003253
Chris Wilson9c870d02016-10-24 13:42:15 +01003254 intel_runtime_pm_get(dev_priv);
3255
Akash Goel3b3f1652016-10-13 22:44:48 +05303256 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003257 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3258 struct drm_i915_gem_request *rq;
3259 struct rb_node *rb;
3260 u64 addr;
3261
3262 seq_printf(m, "%s\n", engine->name);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02003263 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms]\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003264 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003265 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003266 engine->hangcheck.seqno,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02003267 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
Chris Wilson1b365952016-10-04 21:11:31 +01003268
3269 rcu_read_lock();
3270
3271 seq_printf(m, "\tRequests:\n");
3272
Chris Wilson73cb9702016-10-28 13:58:46 +01003273 rq = list_first_entry(&engine->timeline->requests,
3274 struct drm_i915_gem_request, link);
3275 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003276 print_request(m, rq, "\t\tfirst ");
3277
Chris Wilson73cb9702016-10-28 13:58:46 +01003278 rq = list_last_entry(&engine->timeline->requests,
3279 struct drm_i915_gem_request, link);
3280 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003281 print_request(m, rq, "\t\tlast ");
3282
3283 rq = i915_gem_find_active_request(engine);
3284 if (rq) {
3285 print_request(m, rq, "\t\tactive ");
3286 seq_printf(m,
3287 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3288 rq->head, rq->postfix, rq->tail,
3289 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3290 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3291 }
3292
3293 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3294 I915_READ(RING_START(engine->mmio_base)),
3295 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3296 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3297 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3298 rq ? rq->ring->head : 0);
3299 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3300 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3301 rq ? rq->ring->tail : 0);
3302 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3303 I915_READ(RING_CTL(engine->mmio_base)),
3304 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3305
3306 rcu_read_unlock();
3307
3308 addr = intel_engine_get_active_head(engine);
3309 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3310 upper_32_bits(addr), lower_32_bits(addr));
3311 addr = intel_engine_get_last_batch_head(engine);
3312 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3313 upper_32_bits(addr), lower_32_bits(addr));
3314
3315 if (i915.enable_execlists) {
3316 u32 ptr, read, write;
Chris Wilson20311bd2016-11-14 20:41:03 +00003317 struct rb_node *rb;
Chris Wilson1b365952016-10-04 21:11:31 +01003318
3319 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3320 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3321 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3322
3323 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3324 read = GEN8_CSB_READ_PTR(ptr);
3325 write = GEN8_CSB_WRITE_PTR(ptr);
3326 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3327 read, write);
3328 if (read >= GEN8_CSB_ENTRIES)
3329 read = 0;
3330 if (write >= GEN8_CSB_ENTRIES)
3331 write = 0;
3332 if (read > write)
3333 write += GEN8_CSB_ENTRIES;
3334 while (read < write) {
3335 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3336
3337 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3338 idx,
3339 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3340 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3341 }
3342
3343 rcu_read_lock();
3344 rq = READ_ONCE(engine->execlist_port[0].request);
Chris Wilson816ee792017-01-24 11:00:03 +00003345 if (rq) {
3346 seq_printf(m, "\t\tELSP[0] count=%d, ",
3347 engine->execlist_port[0].count);
3348 print_request(m, rq, "rq: ");
3349 } else {
Chris Wilson1b365952016-10-04 21:11:31 +01003350 seq_printf(m, "\t\tELSP[0] idle\n");
Chris Wilson816ee792017-01-24 11:00:03 +00003351 }
Chris Wilson1b365952016-10-04 21:11:31 +01003352 rq = READ_ONCE(engine->execlist_port[1].request);
Chris Wilson816ee792017-01-24 11:00:03 +00003353 if (rq) {
3354 seq_printf(m, "\t\tELSP[1] count=%d, ",
3355 engine->execlist_port[1].count);
3356 print_request(m, rq, "rq: ");
3357 } else {
Chris Wilson1b365952016-10-04 21:11:31 +01003358 seq_printf(m, "\t\tELSP[1] idle\n");
Chris Wilson816ee792017-01-24 11:00:03 +00003359 }
Chris Wilson1b365952016-10-04 21:11:31 +01003360 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003361
Chris Wilson663f71e2016-11-14 20:41:00 +00003362 spin_lock_irq(&engine->timeline->lock);
Chris Wilson20311bd2016-11-14 20:41:03 +00003363 for (rb = engine->execlist_first; rb; rb = rb_next(rb)) {
3364 rq = rb_entry(rb, typeof(*rq), priotree.node);
Chris Wilsonc8247c02016-10-27 01:03:43 +01003365 print_request(m, rq, "\t\tQ ");
3366 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003367 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003368 } else if (INTEL_GEN(dev_priv) > 6) {
3369 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3370 I915_READ(RING_PP_DIR_BASE(engine)));
3371 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3372 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3373 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3374 I915_READ(RING_PP_DIR_DCLV(engine)));
3375 }
3376
Chris Wilsonf6168e32016-10-28 13:58:55 +01003377 spin_lock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003378 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08003379 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson1b365952016-10-04 21:11:31 +01003380
3381 seq_printf(m, "\t%s [%d] waiting for %x\n",
3382 w->tsk->comm, w->tsk->pid, w->seqno);
3383 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01003384 spin_unlock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003385
3386 seq_puts(m, "\n");
3387 }
3388
Chris Wilson9c870d02016-10-24 13:42:15 +01003389 intel_runtime_pm_put(dev_priv);
3390
Chris Wilson1b365952016-10-04 21:11:31 +01003391 return 0;
3392}
3393
Ben Widawskye04934c2014-06-30 09:53:42 -07003394static int i915_semaphore_status(struct seq_file *m, void *unused)
3395{
David Weinehall36cdd012016-08-22 13:59:31 +03003396 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3397 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003398 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003399 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003400 enum intel_engine_id id;
3401 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003402
Chris Wilson39df9192016-07-20 13:31:57 +01003403 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003404 seq_puts(m, "Semaphores are disabled\n");
3405 return 0;
3406 }
3407
3408 ret = mutex_lock_interruptible(&dev->struct_mutex);
3409 if (ret)
3410 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003411 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003412
David Weinehall36cdd012016-08-22 13:59:31 +03003413 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003414 struct page *page;
3415 uint64_t *seqno;
3416
Chris Wilson51d545d2016-08-15 10:49:02 +01003417 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003418
3419 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303420 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003421 uint64_t offset;
3422
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003423 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003424
3425 seq_puts(m, " Last signal:");
3426 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003427 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003428 seq_printf(m, "0x%08llx (0x%02llx) ",
3429 seqno[offset], offset * 8);
3430 }
3431 seq_putc(m, '\n');
3432
3433 seq_puts(m, " Last wait: ");
3434 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003435 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003436 seq_printf(m, "0x%08llx (0x%02llx) ",
3437 seqno[offset], offset * 8);
3438 }
3439 seq_putc(m, '\n');
3440
3441 }
3442 kunmap_atomic(seqno);
3443 } else {
3444 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303445 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003446 for (j = 0; j < num_rings; j++)
3447 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003448 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003449 seq_putc(m, '\n');
3450 }
3451
Paulo Zanoni03872062014-07-09 14:31:57 -03003452 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003453 mutex_unlock(&dev->struct_mutex);
3454 return 0;
3455}
3456
Daniel Vetter728e29d2014-06-25 22:01:53 +03003457static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3458{
David Weinehall36cdd012016-08-22 13:59:31 +03003459 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3460 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003461 int i;
3462
3463 drm_modeset_lock_all(dev);
3464 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3465 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3466
3467 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003468 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003469 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003470 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003471 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003472 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003473 pll->state.hw_state.dpll_md);
3474 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3475 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3476 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003477 }
3478 drm_modeset_unlock_all(dev);
3479
3480 return 0;
3481}
3482
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003483static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003484{
3485 int i;
3486 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003487 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003488 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3489 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003490 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003491 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003492
Arun Siluvery888b5992014-08-26 14:44:51 +01003493 ret = mutex_lock_interruptible(&dev->struct_mutex);
3494 if (ret)
3495 return ret;
3496
3497 intel_runtime_pm_get(dev_priv);
3498
Arun Siluvery33136b02016-01-21 21:43:47 +00003499 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303500 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003501 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003502 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003503 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003504 i915_reg_t addr;
3505 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003506 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003507
Arun Siluvery33136b02016-01-21 21:43:47 +00003508 addr = workarounds->reg[i].addr;
3509 mask = workarounds->reg[i].mask;
3510 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003511 read = I915_READ(addr);
3512 ok = (value & mask) == (read & mask);
3513 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 +02003514 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003515 }
3516
3517 intel_runtime_pm_put(dev_priv);
3518 mutex_unlock(&dev->struct_mutex);
3519
3520 return 0;
3521}
3522
Damien Lespiauc5511e42014-11-04 17:06:51 +00003523static int i915_ddb_info(struct seq_file *m, void *unused)
3524{
David Weinehall36cdd012016-08-22 13:59:31 +03003525 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3526 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003527 struct skl_ddb_allocation *ddb;
3528 struct skl_ddb_entry *entry;
3529 enum pipe pipe;
3530 int plane;
3531
David Weinehall36cdd012016-08-22 13:59:31 +03003532 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003533 return 0;
3534
Damien Lespiauc5511e42014-11-04 17:06:51 +00003535 drm_modeset_lock_all(dev);
3536
3537 ddb = &dev_priv->wm.skl_hw.ddb;
3538
3539 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3540
3541 for_each_pipe(dev_priv, pipe) {
3542 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3543
Matt Roper8b364b42016-10-26 15:51:28 -07003544 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003545 entry = &ddb->plane[pipe][plane];
3546 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3547 entry->start, entry->end,
3548 skl_ddb_entry_size(entry));
3549 }
3550
Matt Roper4969d332015-09-24 15:53:10 -07003551 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003552 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3553 entry->end, skl_ddb_entry_size(entry));
3554 }
3555
3556 drm_modeset_unlock_all(dev);
3557
3558 return 0;
3559}
3560
Vandana Kannana54746e2015-03-03 20:53:10 +05303561static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003562 struct drm_device *dev,
3563 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303564{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003565 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303566 struct i915_drrs *drrs = &dev_priv->drrs;
3567 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003568 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303569
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003570 drm_for_each_connector(connector, dev) {
3571 if (connector->state->crtc != &intel_crtc->base)
3572 continue;
3573
3574 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303575 }
3576
3577 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3578 seq_puts(m, "\tVBT: DRRS_type: Static");
3579 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3580 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3581 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3582 seq_puts(m, "\tVBT: DRRS_type: None");
3583 else
3584 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3585
3586 seq_puts(m, "\n\n");
3587
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003588 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303589 struct intel_panel *panel;
3590
3591 mutex_lock(&drrs->mutex);
3592 /* DRRS Supported */
3593 seq_puts(m, "\tDRRS Supported: Yes\n");
3594
3595 /* disable_drrs() will make drrs->dp NULL */
3596 if (!drrs->dp) {
3597 seq_puts(m, "Idleness DRRS: Disabled");
3598 mutex_unlock(&drrs->mutex);
3599 return;
3600 }
3601
3602 panel = &drrs->dp->attached_connector->panel;
3603 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3604 drrs->busy_frontbuffer_bits);
3605
3606 seq_puts(m, "\n\t\t");
3607 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3608 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3609 vrefresh = panel->fixed_mode->vrefresh;
3610 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3611 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3612 vrefresh = panel->downclock_mode->vrefresh;
3613 } else {
3614 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3615 drrs->refresh_rate_type);
3616 mutex_unlock(&drrs->mutex);
3617 return;
3618 }
3619 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3620
3621 seq_puts(m, "\n\t\t");
3622 mutex_unlock(&drrs->mutex);
3623 } else {
3624 /* DRRS not supported. Print the VBT parameter*/
3625 seq_puts(m, "\tDRRS Supported : No");
3626 }
3627 seq_puts(m, "\n");
3628}
3629
3630static int i915_drrs_status(struct seq_file *m, void *unused)
3631{
David Weinehall36cdd012016-08-22 13:59:31 +03003632 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3633 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303634 struct intel_crtc *intel_crtc;
3635 int active_crtc_cnt = 0;
3636
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003637 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303638 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003639 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303640 active_crtc_cnt++;
3641 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3642
3643 drrs_status_per_crtc(m, dev, intel_crtc);
3644 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303645 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003646 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303647
3648 if (!active_crtc_cnt)
3649 seq_puts(m, "No active crtc found\n");
3650
3651 return 0;
3652}
3653
Dave Airlie11bed952014-05-12 15:22:27 +10003654static int i915_dp_mst_info(struct seq_file *m, void *unused)
3655{
David Weinehall36cdd012016-08-22 13:59:31 +03003656 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3657 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003658 struct intel_encoder *intel_encoder;
3659 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003660 struct drm_connector *connector;
3661
Dave Airlie11bed952014-05-12 15:22:27 +10003662 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003663 drm_for_each_connector(connector, dev) {
3664 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003665 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003666
3667 intel_encoder = intel_attached_encoder(connector);
3668 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3669 continue;
3670
3671 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003672 if (!intel_dig_port->dp.can_mst)
3673 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003674
Jim Bride40ae80c2016-04-14 10:18:37 -07003675 seq_printf(m, "MST Source Port %c\n",
3676 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003677 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3678 }
3679 drm_modeset_unlock_all(dev);
3680 return 0;
3681}
3682
Todd Previteeb3394fa2015-04-18 00:04:19 -07003683static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003684 const char __user *ubuf,
3685 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003686{
3687 char *input_buffer;
3688 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003689 struct drm_device *dev;
3690 struct drm_connector *connector;
3691 struct list_head *connector_list;
3692 struct intel_dp *intel_dp;
3693 int val = 0;
3694
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303695 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003696
Todd Previteeb3394fa2015-04-18 00:04:19 -07003697 connector_list = &dev->mode_config.connector_list;
3698
3699 if (len == 0)
3700 return 0;
3701
3702 input_buffer = kmalloc(len + 1, GFP_KERNEL);
3703 if (!input_buffer)
3704 return -ENOMEM;
3705
3706 if (copy_from_user(input_buffer, ubuf, len)) {
3707 status = -EFAULT;
3708 goto out;
3709 }
3710
3711 input_buffer[len] = '\0';
3712 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3713
3714 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003715 if (connector->connector_type !=
3716 DRM_MODE_CONNECTOR_DisplayPort)
3717 continue;
3718
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05303719 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07003720 connector->encoder != NULL) {
3721 intel_dp = enc_to_intel_dp(connector->encoder);
3722 status = kstrtoint(input_buffer, 10, &val);
3723 if (status < 0)
3724 goto out;
3725 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3726 /* To prevent erroneous activation of the compliance
3727 * testing code, only accept an actual value of 1 here
3728 */
3729 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003730 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003731 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003732 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003733 }
3734 }
3735out:
3736 kfree(input_buffer);
3737 if (status < 0)
3738 return status;
3739
3740 *offp += len;
3741 return len;
3742}
3743
3744static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3745{
3746 struct drm_device *dev = m->private;
3747 struct drm_connector *connector;
3748 struct list_head *connector_list = &dev->mode_config.connector_list;
3749 struct intel_dp *intel_dp;
3750
Todd Previteeb3394fa2015-04-18 00:04:19 -07003751 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003752 if (connector->connector_type !=
3753 DRM_MODE_CONNECTOR_DisplayPort)
3754 continue;
3755
3756 if (connector->status == connector_status_connected &&
3757 connector->encoder != NULL) {
3758 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003759 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003760 seq_puts(m, "1");
3761 else
3762 seq_puts(m, "0");
3763 } else
3764 seq_puts(m, "0");
3765 }
3766
3767 return 0;
3768}
3769
3770static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003771 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003772{
David Weinehall36cdd012016-08-22 13:59:31 +03003773 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003774
David Weinehall36cdd012016-08-22 13:59:31 +03003775 return single_open(file, i915_displayport_test_active_show,
3776 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003777}
3778
3779static const struct file_operations i915_displayport_test_active_fops = {
3780 .owner = THIS_MODULE,
3781 .open = i915_displayport_test_active_open,
3782 .read = seq_read,
3783 .llseek = seq_lseek,
3784 .release = single_release,
3785 .write = i915_displayport_test_active_write
3786};
3787
3788static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3789{
3790 struct drm_device *dev = m->private;
3791 struct drm_connector *connector;
3792 struct list_head *connector_list = &dev->mode_config.connector_list;
3793 struct intel_dp *intel_dp;
3794
Todd Previteeb3394fa2015-04-18 00:04:19 -07003795 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003796 if (connector->connector_type !=
3797 DRM_MODE_CONNECTOR_DisplayPort)
3798 continue;
3799
3800 if (connector->status == connector_status_connected &&
3801 connector->encoder != NULL) {
3802 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003803 if (intel_dp->compliance.test_type ==
3804 DP_TEST_LINK_EDID_READ)
3805 seq_printf(m, "%lx",
3806 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003807 else if (intel_dp->compliance.test_type ==
3808 DP_TEST_LINK_VIDEO_PATTERN) {
3809 seq_printf(m, "hdisplay: %d\n",
3810 intel_dp->compliance.test_data.hdisplay);
3811 seq_printf(m, "vdisplay: %d\n",
3812 intel_dp->compliance.test_data.vdisplay);
3813 seq_printf(m, "bpc: %u\n",
3814 intel_dp->compliance.test_data.bpc);
3815 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003816 } else
3817 seq_puts(m, "0");
3818 }
3819
3820 return 0;
3821}
3822static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003823 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003824{
David Weinehall36cdd012016-08-22 13:59:31 +03003825 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003826
David Weinehall36cdd012016-08-22 13:59:31 +03003827 return single_open(file, i915_displayport_test_data_show,
3828 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003829}
3830
3831static const struct file_operations i915_displayport_test_data_fops = {
3832 .owner = THIS_MODULE,
3833 .open = i915_displayport_test_data_open,
3834 .read = seq_read,
3835 .llseek = seq_lseek,
3836 .release = single_release
3837};
3838
3839static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3840{
3841 struct drm_device *dev = m->private;
3842 struct drm_connector *connector;
3843 struct list_head *connector_list = &dev->mode_config.connector_list;
3844 struct intel_dp *intel_dp;
3845
Todd Previteeb3394fa2015-04-18 00:04:19 -07003846 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003847 if (connector->connector_type !=
3848 DRM_MODE_CONNECTOR_DisplayPort)
3849 continue;
3850
3851 if (connector->status == connector_status_connected &&
3852 connector->encoder != NULL) {
3853 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003854 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003855 } else
3856 seq_puts(m, "0");
3857 }
3858
3859 return 0;
3860}
3861
3862static int i915_displayport_test_type_open(struct inode *inode,
3863 struct file *file)
3864{
David Weinehall36cdd012016-08-22 13:59:31 +03003865 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003866
David Weinehall36cdd012016-08-22 13:59:31 +03003867 return single_open(file, i915_displayport_test_type_show,
3868 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003869}
3870
3871static const struct file_operations i915_displayport_test_type_fops = {
3872 .owner = THIS_MODULE,
3873 .open = i915_displayport_test_type_open,
3874 .read = seq_read,
3875 .llseek = seq_lseek,
3876 .release = single_release
3877};
3878
Damien Lespiau97e94b22014-11-04 17:06:50 +00003879static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003880{
David Weinehall36cdd012016-08-22 13:59:31 +03003881 struct drm_i915_private *dev_priv = m->private;
3882 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003883 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003884 int num_levels;
3885
David Weinehall36cdd012016-08-22 13:59:31 +03003886 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003887 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003888 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003889 num_levels = 1;
3890 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003891 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003892
3893 drm_modeset_lock_all(dev);
3894
3895 for (level = 0; level < num_levels; level++) {
3896 unsigned int latency = wm[level];
3897
Damien Lespiau97e94b22014-11-04 17:06:50 +00003898 /*
3899 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003900 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003901 */
David Weinehall36cdd012016-08-22 13:59:31 +03003902 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
3903 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003904 latency *= 10;
3905 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003906 latency *= 5;
3907
3908 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003909 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003910 }
3911
3912 drm_modeset_unlock_all(dev);
3913}
3914
3915static int pri_wm_latency_show(struct seq_file *m, void *data)
3916{
David Weinehall36cdd012016-08-22 13:59:31 +03003917 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003918 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003919
David Weinehall36cdd012016-08-22 13:59:31 +03003920 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003921 latencies = dev_priv->wm.skl_latency;
3922 else
David Weinehall36cdd012016-08-22 13:59:31 +03003923 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003924
3925 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003926
3927 return 0;
3928}
3929
3930static int spr_wm_latency_show(struct seq_file *m, void *data)
3931{
David Weinehall36cdd012016-08-22 13:59:31 +03003932 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003933 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003934
David Weinehall36cdd012016-08-22 13:59:31 +03003935 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003936 latencies = dev_priv->wm.skl_latency;
3937 else
David Weinehall36cdd012016-08-22 13:59:31 +03003938 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003939
3940 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003941
3942 return 0;
3943}
3944
3945static int cur_wm_latency_show(struct seq_file *m, void *data)
3946{
David Weinehall36cdd012016-08-22 13:59:31 +03003947 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003948 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003949
David Weinehall36cdd012016-08-22 13:59:31 +03003950 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003951 latencies = dev_priv->wm.skl_latency;
3952 else
David Weinehall36cdd012016-08-22 13:59:31 +03003953 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003954
3955 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003956
3957 return 0;
3958}
3959
3960static int pri_wm_latency_open(struct inode *inode, struct file *file)
3961{
David Weinehall36cdd012016-08-22 13:59:31 +03003962 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003963
David Weinehall36cdd012016-08-22 13:59:31 +03003964 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003965 return -ENODEV;
3966
David Weinehall36cdd012016-08-22 13:59:31 +03003967 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003968}
3969
3970static int spr_wm_latency_open(struct inode *inode, struct file *file)
3971{
David Weinehall36cdd012016-08-22 13:59:31 +03003972 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003973
David Weinehall36cdd012016-08-22 13:59:31 +03003974 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003975 return -ENODEV;
3976
David Weinehall36cdd012016-08-22 13:59:31 +03003977 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003978}
3979
3980static int cur_wm_latency_open(struct inode *inode, struct file *file)
3981{
David Weinehall36cdd012016-08-22 13:59:31 +03003982 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003983
David Weinehall36cdd012016-08-22 13:59:31 +03003984 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003985 return -ENODEV;
3986
David Weinehall36cdd012016-08-22 13:59:31 +03003987 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003988}
3989
3990static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003991 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003992{
3993 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003994 struct drm_i915_private *dev_priv = m->private;
3995 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003996 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03003997 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003998 int level;
3999 int ret;
4000 char tmp[32];
4001
David Weinehall36cdd012016-08-22 13:59:31 +03004002 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004003 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004004 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004005 num_levels = 1;
4006 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004007 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004008
Ville Syrjälä369a1342014-01-22 14:36:08 +02004009 if (len >= sizeof(tmp))
4010 return -EINVAL;
4011
4012 if (copy_from_user(tmp, ubuf, len))
4013 return -EFAULT;
4014
4015 tmp[len] = '\0';
4016
Damien Lespiau97e94b22014-11-04 17:06:50 +00004017 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4018 &new[0], &new[1], &new[2], &new[3],
4019 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004020 if (ret != num_levels)
4021 return -EINVAL;
4022
4023 drm_modeset_lock_all(dev);
4024
4025 for (level = 0; level < num_levels; level++)
4026 wm[level] = new[level];
4027
4028 drm_modeset_unlock_all(dev);
4029
4030 return len;
4031}
4032
4033
4034static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4035 size_t len, loff_t *offp)
4036{
4037 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004038 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004039 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004040
David Weinehall36cdd012016-08-22 13:59:31 +03004041 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004042 latencies = dev_priv->wm.skl_latency;
4043 else
David Weinehall36cdd012016-08-22 13:59:31 +03004044 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004045
4046 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004047}
4048
4049static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4050 size_t len, loff_t *offp)
4051{
4052 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004053 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004054 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004055
David Weinehall36cdd012016-08-22 13:59:31 +03004056 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004057 latencies = dev_priv->wm.skl_latency;
4058 else
David Weinehall36cdd012016-08-22 13:59:31 +03004059 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004060
4061 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004062}
4063
4064static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4065 size_t len, loff_t *offp)
4066{
4067 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004068 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004069 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004070
David Weinehall36cdd012016-08-22 13:59:31 +03004071 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004072 latencies = dev_priv->wm.skl_latency;
4073 else
David Weinehall36cdd012016-08-22 13:59:31 +03004074 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004075
4076 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004077}
4078
4079static const struct file_operations i915_pri_wm_latency_fops = {
4080 .owner = THIS_MODULE,
4081 .open = pri_wm_latency_open,
4082 .read = seq_read,
4083 .llseek = seq_lseek,
4084 .release = single_release,
4085 .write = pri_wm_latency_write
4086};
4087
4088static const struct file_operations i915_spr_wm_latency_fops = {
4089 .owner = THIS_MODULE,
4090 .open = spr_wm_latency_open,
4091 .read = seq_read,
4092 .llseek = seq_lseek,
4093 .release = single_release,
4094 .write = spr_wm_latency_write
4095};
4096
4097static const struct file_operations i915_cur_wm_latency_fops = {
4098 .owner = THIS_MODULE,
4099 .open = cur_wm_latency_open,
4100 .read = seq_read,
4101 .llseek = seq_lseek,
4102 .release = single_release,
4103 .write = cur_wm_latency_write
4104};
4105
Kees Cook647416f2013-03-10 14:10:06 -07004106static int
4107i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004108{
David Weinehall36cdd012016-08-22 13:59:31 +03004109 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004110
Chris Wilsond98c52c2016-04-13 17:35:05 +01004111 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004112
Kees Cook647416f2013-03-10 14:10:06 -07004113 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004114}
4115
Kees Cook647416f2013-03-10 14:10:06 -07004116static int
4117i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004118{
David Weinehall36cdd012016-08-22 13:59:31 +03004119 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004120
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004121 /*
4122 * There is no safeguard against this debugfs entry colliding
4123 * with the hangcheck calling same i915_handle_error() in
4124 * parallel, causing an explosion. For now we assume that the
4125 * test harness is responsible enough not to inject gpu hangs
4126 * while it is writing to 'i915_wedged'
4127 */
4128
Chris Wilsond98c52c2016-04-13 17:35:05 +01004129 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004130 return -EAGAIN;
4131
Chris Wilsonc0336662016-05-06 15:40:21 +01004132 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004133 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004134
Kees Cook647416f2013-03-10 14:10:06 -07004135 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004136}
4137
Kees Cook647416f2013-03-10 14:10:06 -07004138DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4139 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004140 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004141
Kees Cook647416f2013-03-10 14:10:06 -07004142static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004143i915_ring_missed_irq_get(void *data, u64 *val)
4144{
David Weinehall36cdd012016-08-22 13:59:31 +03004145 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004146
4147 *val = dev_priv->gpu_error.missed_irq_rings;
4148 return 0;
4149}
4150
4151static int
4152i915_ring_missed_irq_set(void *data, u64 val)
4153{
David Weinehall36cdd012016-08-22 13:59:31 +03004154 struct drm_i915_private *dev_priv = data;
4155 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004156 int ret;
4157
4158 /* Lock against concurrent debugfs callers */
4159 ret = mutex_lock_interruptible(&dev->struct_mutex);
4160 if (ret)
4161 return ret;
4162 dev_priv->gpu_error.missed_irq_rings = val;
4163 mutex_unlock(&dev->struct_mutex);
4164
4165 return 0;
4166}
4167
4168DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4169 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4170 "0x%08llx\n");
4171
4172static int
4173i915_ring_test_irq_get(void *data, u64 *val)
4174{
David Weinehall36cdd012016-08-22 13:59:31 +03004175 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004176
4177 *val = dev_priv->gpu_error.test_irq_rings;
4178
4179 return 0;
4180}
4181
4182static int
4183i915_ring_test_irq_set(void *data, u64 val)
4184{
David Weinehall36cdd012016-08-22 13:59:31 +03004185 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004186
Chris Wilson3a122c22016-06-17 14:35:05 +01004187 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004188 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004189 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004190
4191 return 0;
4192}
4193
4194DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4195 i915_ring_test_irq_get, i915_ring_test_irq_set,
4196 "0x%08llx\n");
4197
Chris Wilsondd624af2013-01-15 12:39:35 +00004198#define DROP_UNBOUND 0x1
4199#define DROP_BOUND 0x2
4200#define DROP_RETIRE 0x4
4201#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004202#define DROP_FREED 0x10
4203#define DROP_ALL (DROP_UNBOUND | \
4204 DROP_BOUND | \
4205 DROP_RETIRE | \
4206 DROP_ACTIVE | \
4207 DROP_FREED)
Kees Cook647416f2013-03-10 14:10:06 -07004208static int
4209i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004210{
Kees Cook647416f2013-03-10 14:10:06 -07004211 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004212
Kees Cook647416f2013-03-10 14:10:06 -07004213 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004214}
4215
Kees Cook647416f2013-03-10 14:10:06 -07004216static int
4217i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004218{
David Weinehall36cdd012016-08-22 13:59:31 +03004219 struct drm_i915_private *dev_priv = data;
4220 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004221 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004222
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004223 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004224
4225 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4226 * on ioctls on -EAGAIN. */
4227 ret = mutex_lock_interruptible(&dev->struct_mutex);
4228 if (ret)
4229 return ret;
4230
4231 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004232 ret = i915_gem_wait_for_idle(dev_priv,
4233 I915_WAIT_INTERRUPTIBLE |
4234 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004235 if (ret)
4236 goto unlock;
4237 }
4238
4239 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004240 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004241
Chris Wilson21ab4e72014-09-09 11:16:08 +01004242 if (val & DROP_BOUND)
4243 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004244
Chris Wilson21ab4e72014-09-09 11:16:08 +01004245 if (val & DROP_UNBOUND)
4246 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004247
4248unlock:
4249 mutex_unlock(&dev->struct_mutex);
4250
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004251 if (val & DROP_FREED) {
4252 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004253 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004254 }
4255
Kees Cook647416f2013-03-10 14:10:06 -07004256 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004257}
4258
Kees Cook647416f2013-03-10 14:10:06 -07004259DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4260 i915_drop_caches_get, i915_drop_caches_set,
4261 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004262
Kees Cook647416f2013-03-10 14:10:06 -07004263static int
4264i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004265{
David Weinehall36cdd012016-08-22 13:59:31 +03004266 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004267
David Weinehall36cdd012016-08-22 13:59:31 +03004268 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004269 return -ENODEV;
4270
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004271 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004272 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004273}
4274
Kees Cook647416f2013-03-10 14:10:06 -07004275static int
4276i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004277{
David Weinehall36cdd012016-08-22 13:59:31 +03004278 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304279 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004280 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004281
David Weinehall36cdd012016-08-22 13:59:31 +03004282 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004283 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004284
Kees Cook647416f2013-03-10 14:10:06 -07004285 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004286
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004287 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004288 if (ret)
4289 return ret;
4290
Jesse Barnes358733e2011-07-27 11:53:01 -07004291 /*
4292 * Turbo will still be enabled, but won't go above the set value.
4293 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304294 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004295
Akash Goelbc4d91f2015-02-26 16:09:47 +05304296 hw_max = dev_priv->rps.max_freq;
4297 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004298
Ben Widawskyb39fb292014-03-19 18:31:11 -07004299 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004300 mutex_unlock(&dev_priv->rps.hw_lock);
4301 return -EINVAL;
4302 }
4303
Ben Widawskyb39fb292014-03-19 18:31:11 -07004304 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004305
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004306 if (intel_set_rps(dev_priv, val))
4307 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004308
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004309 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004310
Kees Cook647416f2013-03-10 14:10:06 -07004311 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004312}
4313
Kees Cook647416f2013-03-10 14:10:06 -07004314DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4315 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004316 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004317
Kees Cook647416f2013-03-10 14:10:06 -07004318static int
4319i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004320{
David Weinehall36cdd012016-08-22 13:59:31 +03004321 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004322
Chris Wilson62e1baa2016-07-13 09:10:36 +01004323 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004324 return -ENODEV;
4325
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004326 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004327 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004328}
4329
Kees Cook647416f2013-03-10 14:10:06 -07004330static int
4331i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004332{
David Weinehall36cdd012016-08-22 13:59:31 +03004333 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304334 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004335 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004336
Chris Wilson62e1baa2016-07-13 09:10:36 +01004337 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004338 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004339
Kees Cook647416f2013-03-10 14:10:06 -07004340 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004341
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004342 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004343 if (ret)
4344 return ret;
4345
Jesse Barnes1523c312012-05-25 12:34:54 -07004346 /*
4347 * Turbo will still be enabled, but won't go below the set value.
4348 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304349 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004350
Akash Goelbc4d91f2015-02-26 16:09:47 +05304351 hw_max = dev_priv->rps.max_freq;
4352 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004353
David Weinehall36cdd012016-08-22 13:59:31 +03004354 if (val < hw_min ||
4355 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004356 mutex_unlock(&dev_priv->rps.hw_lock);
4357 return -EINVAL;
4358 }
4359
Ben Widawskyb39fb292014-03-19 18:31:11 -07004360 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004361
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004362 if (intel_set_rps(dev_priv, val))
4363 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004364
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004365 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004366
Kees Cook647416f2013-03-10 14:10:06 -07004367 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004368}
4369
Kees Cook647416f2013-03-10 14:10:06 -07004370DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4371 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004372 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004373
Kees Cook647416f2013-03-10 14:10:06 -07004374static int
4375i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004376{
David Weinehall36cdd012016-08-22 13:59:31 +03004377 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004378 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004379
David Weinehall36cdd012016-08-22 13:59:31 +03004380 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004381 return -ENODEV;
4382
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004383 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004384
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004385 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004386
4387 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004388
Kees Cook647416f2013-03-10 14:10:06 -07004389 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004390
Kees Cook647416f2013-03-10 14:10:06 -07004391 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004392}
4393
Kees Cook647416f2013-03-10 14:10:06 -07004394static int
4395i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004396{
David Weinehall36cdd012016-08-22 13:59:31 +03004397 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004398 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004399
David Weinehall36cdd012016-08-22 13:59:31 +03004400 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004401 return -ENODEV;
4402
Kees Cook647416f2013-03-10 14:10:06 -07004403 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004404 return -EINVAL;
4405
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004406 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004407 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004408
4409 /* Update the cache sharing policy here as well */
4410 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4411 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4412 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4413 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4414
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004415 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004416 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004417}
4418
Kees Cook647416f2013-03-10 14:10:06 -07004419DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4420 i915_cache_sharing_get, i915_cache_sharing_set,
4421 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004422
David Weinehall36cdd012016-08-22 13:59:31 +03004423static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004424 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004425{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004426 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004427 int ss;
4428 u32 sig1[ss_max], sig2[ss_max];
4429
4430 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4431 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4432 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4433 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4434
4435 for (ss = 0; ss < ss_max; ss++) {
4436 unsigned int eu_cnt;
4437
4438 if (sig1[ss] & CHV_SS_PG_ENABLE)
4439 /* skip disabled subslice */
4440 continue;
4441
Imre Deakf08a0c92016-08-31 19:13:04 +03004442 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004443 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004444 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4445 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4446 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4447 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004448 sseu->eu_total += eu_cnt;
4449 sseu->eu_per_subslice = max_t(unsigned int,
4450 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004451 }
Jeff McGee5d395252015-04-03 18:13:17 -07004452}
4453
David Weinehall36cdd012016-08-22 13:59:31 +03004454static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004455 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004456{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004457 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004458 int s, ss;
4459 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4460
Jeff McGee1c046bc2015-04-03 18:13:18 -07004461 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004462 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004463 s_max = 1;
4464 ss_max = 3;
4465 }
4466
4467 for (s = 0; s < s_max; s++) {
4468 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4469 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4470 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4471 }
4472
Jeff McGee5d395252015-04-03 18:13:17 -07004473 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4474 GEN9_PGCTL_SSA_EU19_ACK |
4475 GEN9_PGCTL_SSA_EU210_ACK |
4476 GEN9_PGCTL_SSA_EU311_ACK;
4477 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4478 GEN9_PGCTL_SSB_EU19_ACK |
4479 GEN9_PGCTL_SSB_EU210_ACK |
4480 GEN9_PGCTL_SSB_EU311_ACK;
4481
4482 for (s = 0; s < s_max; s++) {
4483 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4484 /* skip disabled slice */
4485 continue;
4486
Imre Deakf08a0c92016-08-31 19:13:04 +03004487 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004488
Rodrigo Vivib976dc52017-01-23 10:32:37 -08004489 if (IS_GEN9_BC(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004490 sseu->subslice_mask =
4491 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004492
Jeff McGee5d395252015-04-03 18:13:17 -07004493 for (ss = 0; ss < ss_max; ss++) {
4494 unsigned int eu_cnt;
4495
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004496 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004497 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4498 /* skip disabled subslice */
4499 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004500
Imre Deak57ec1712016-08-31 19:13:05 +03004501 sseu->subslice_mask |= BIT(ss);
4502 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004503
Jeff McGee5d395252015-04-03 18:13:17 -07004504 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4505 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004506 sseu->eu_total += eu_cnt;
4507 sseu->eu_per_subslice = max_t(unsigned int,
4508 sseu->eu_per_subslice,
4509 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004510 }
4511 }
4512}
4513
David Weinehall36cdd012016-08-22 13:59:31 +03004514static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004515 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004516{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004517 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004518 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004519
Imre Deakf08a0c92016-08-31 19:13:04 +03004520 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004521
Imre Deakf08a0c92016-08-31 19:13:04 +03004522 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004523 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004524 sseu->eu_per_subslice =
4525 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004526 sseu->eu_total = sseu->eu_per_subslice *
4527 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004528
4529 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004530 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004531 u8 subslice_7eu =
4532 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004533
Imre Deak915490d2016-08-31 19:13:01 +03004534 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004535 }
4536 }
4537}
4538
Imre Deak615d8902016-08-31 19:13:03 +03004539static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4540 const struct sseu_dev_info *sseu)
4541{
4542 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4543 const char *type = is_available_info ? "Available" : "Enabled";
4544
Imre Deakc67ba532016-08-31 19:13:06 +03004545 seq_printf(m, " %s Slice Mask: %04x\n", type,
4546 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004547 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004548 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004549 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004550 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004551 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4552 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004553 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004554 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004555 seq_printf(m, " %s EU Total: %u\n", type,
4556 sseu->eu_total);
4557 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4558 sseu->eu_per_subslice);
4559
4560 if (!is_available_info)
4561 return;
4562
4563 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4564 if (HAS_POOLED_EU(dev_priv))
4565 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4566
4567 seq_printf(m, " Has Slice Power Gating: %s\n",
4568 yesno(sseu->has_slice_pg));
4569 seq_printf(m, " Has Subslice Power Gating: %s\n",
4570 yesno(sseu->has_subslice_pg));
4571 seq_printf(m, " Has EU Power Gating: %s\n",
4572 yesno(sseu->has_eu_pg));
4573}
4574
Jeff McGee38732182015-02-13 10:27:54 -06004575static int i915_sseu_status(struct seq_file *m, void *unused)
4576{
David Weinehall36cdd012016-08-22 13:59:31 +03004577 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004578 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004579
David Weinehall36cdd012016-08-22 13:59:31 +03004580 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004581 return -ENODEV;
4582
4583 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004584 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004585
Jeff McGee7f992ab2015-02-13 10:27:55 -06004586 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004587 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004588
4589 intel_runtime_pm_get(dev_priv);
4590
David Weinehall36cdd012016-08-22 13:59:31 +03004591 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004592 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004593 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004594 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004595 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004596 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004597 }
David Weinehall238010e2016-08-01 17:33:27 +03004598
4599 intel_runtime_pm_put(dev_priv);
4600
Imre Deak615d8902016-08-31 19:13:03 +03004601 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004602
Jeff McGee38732182015-02-13 10:27:54 -06004603 return 0;
4604}
4605
Ben Widawsky6d794d42011-04-25 11:25:56 -07004606static int i915_forcewake_open(struct inode *inode, struct file *file)
4607{
David Weinehall36cdd012016-08-22 13:59:31 +03004608 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004609
David Weinehall36cdd012016-08-22 13:59:31 +03004610 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004611 return 0;
4612
Chris Wilson6daccb02015-01-16 11:34:35 +02004613 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004614 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004615
4616 return 0;
4617}
4618
Ben Widawskyc43b5632012-04-16 14:07:40 -07004619static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004620{
David Weinehall36cdd012016-08-22 13:59:31 +03004621 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004622
David Weinehall36cdd012016-08-22 13:59:31 +03004623 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004624 return 0;
4625
Mika Kuoppala59bad942015-01-16 11:34:40 +02004626 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004627 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004628
4629 return 0;
4630}
4631
4632static const struct file_operations i915_forcewake_fops = {
4633 .owner = THIS_MODULE,
4634 .open = i915_forcewake_open,
4635 .release = i915_forcewake_release,
4636};
4637
4638static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4639{
Ben Widawsky6d794d42011-04-25 11:25:56 -07004640 struct dentry *ent;
4641
4642 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004643 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03004644 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07004645 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004646 if (!ent)
4647 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004648
Ben Widawsky8eb57292011-05-11 15:10:58 -07004649 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004650}
4651
Lyude317eaa92017-02-03 21:18:25 -05004652static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4653{
4654 struct drm_i915_private *dev_priv = m->private;
4655 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4656
4657 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4658 seq_printf(m, "Detected: %s\n",
4659 yesno(delayed_work_pending(&hotplug->reenable_work)));
4660
4661 return 0;
4662}
4663
4664static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4665 const char __user *ubuf, size_t len,
4666 loff_t *offp)
4667{
4668 struct seq_file *m = file->private_data;
4669 struct drm_i915_private *dev_priv = m->private;
4670 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4671 unsigned int new_threshold;
4672 int i;
4673 char *newline;
4674 char tmp[16];
4675
4676 if (len >= sizeof(tmp))
4677 return -EINVAL;
4678
4679 if (copy_from_user(tmp, ubuf, len))
4680 return -EFAULT;
4681
4682 tmp[len] = '\0';
4683
4684 /* Strip newline, if any */
4685 newline = strchr(tmp, '\n');
4686 if (newline)
4687 *newline = '\0';
4688
4689 if (strcmp(tmp, "reset") == 0)
4690 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4691 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4692 return -EINVAL;
4693
4694 if (new_threshold > 0)
4695 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4696 new_threshold);
4697 else
4698 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4699
4700 spin_lock_irq(&dev_priv->irq_lock);
4701 hotplug->hpd_storm_threshold = new_threshold;
4702 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4703 for_each_hpd_pin(i)
4704 hotplug->stats[i].count = 0;
4705 spin_unlock_irq(&dev_priv->irq_lock);
4706
4707 /* Re-enable hpd immediately if we were in an irq storm */
4708 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4709
4710 return len;
4711}
4712
4713static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4714{
4715 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4716}
4717
4718static const struct file_operations i915_hpd_storm_ctl_fops = {
4719 .owner = THIS_MODULE,
4720 .open = i915_hpd_storm_ctl_open,
4721 .read = seq_read,
4722 .llseek = seq_lseek,
4723 .release = single_release,
4724 .write = i915_hpd_storm_ctl_write
4725};
4726
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004727static int i915_debugfs_create(struct dentry *root,
4728 struct drm_minor *minor,
4729 const char *name,
4730 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004731{
Jesse Barnes358733e2011-07-27 11:53:01 -07004732 struct dentry *ent;
4733
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004734 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004735 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03004736 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004737 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004738 if (!ent)
4739 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004740
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004741 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004742}
4743
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004744static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004745 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004746 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004747 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01004748 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004749 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004750 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004751 {"i915_gem_request", i915_gem_request_info, 0},
4752 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004753 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004754 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004755 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004756 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004757 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004758 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004759 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304760 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004761 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004762 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004763 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004764 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004765 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004766 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004767 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004768 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004769 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004770 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004771 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004772 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004773 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004774 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004775 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004776 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004777 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004778 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004779 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004780 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004781 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004782 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004783 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004784 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004785 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004786 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004787 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004788 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004789 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004790 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004791 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304792 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004793 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004794};
Ben Gamari27c202a2009-07-01 22:26:52 -04004795#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004796
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004797static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004798 const char *name;
4799 const struct file_operations *fops;
4800} i915_debugfs_files[] = {
4801 {"i915_wedged", &i915_wedged_fops},
4802 {"i915_max_freq", &i915_max_freq_fops},
4803 {"i915_min_freq", &i915_min_freq_fops},
4804 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004805 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4806 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004807 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004808#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004809 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004810 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004811#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004812 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004813 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004814 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4815 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4816 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004817 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004818 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4819 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304820 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004821 {"i915_guc_log_control", &i915_guc_log_control_fops},
4822 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004823};
4824
Chris Wilson1dac8912016-06-24 14:00:17 +01004825int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004826{
Chris Wilson91c8a322016-07-05 10:40:23 +01004827 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02004828 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004829
Ben Widawsky6d794d42011-04-25 11:25:56 -07004830 ret = i915_forcewake_create(minor->debugfs_root, minor);
4831 if (ret)
4832 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004833
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004834 ret = intel_pipe_crc_create(minor);
4835 if (ret)
4836 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004837
Daniel Vetter34b96742013-07-04 20:49:44 +02004838 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4839 ret = i915_debugfs_create(minor->debugfs_root, minor,
4840 i915_debugfs_files[i].name,
4841 i915_debugfs_files[i].fops);
4842 if (ret)
4843 return ret;
4844 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004845
Ben Gamari27c202a2009-07-01 22:26:52 -04004846 return drm_debugfs_create_files(i915_debugfs_list,
4847 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004848 minor->debugfs_root, minor);
4849}
4850
Chris Wilson1dac8912016-06-24 14:00:17 +01004851void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004852{
Chris Wilson91c8a322016-07-05 10:40:23 +01004853 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02004854 int i;
4855
Ben Gamari27c202a2009-07-01 22:26:52 -04004856 drm_debugfs_remove_files(i915_debugfs_list,
4857 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004858
David Weinehall36cdd012016-08-22 13:59:31 +03004859 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004860 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004861
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004862 intel_pipe_crc_cleanup(minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004863
Daniel Vetter34b96742013-07-04 20:49:44 +02004864 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4865 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03004866 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02004867
4868 drm_debugfs_remove_files(info_list, 1, minor);
4869 }
Ben Gamari20172632009-02-17 20:08:50 -05004870}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004871
4872struct dpcd_block {
4873 /* DPCD dump start address. */
4874 unsigned int offset;
4875 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4876 unsigned int end;
4877 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4878 size_t size;
4879 /* Only valid for eDP. */
4880 bool edp;
4881};
4882
4883static const struct dpcd_block i915_dpcd_debug[] = {
4884 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4885 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4886 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4887 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4888 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4889 { .offset = DP_SET_POWER },
4890 { .offset = DP_EDP_DPCD_REV },
4891 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4892 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4893 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4894};
4895
4896static int i915_dpcd_show(struct seq_file *m, void *data)
4897{
4898 struct drm_connector *connector = m->private;
4899 struct intel_dp *intel_dp =
4900 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4901 uint8_t buf[16];
4902 ssize_t err;
4903 int i;
4904
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004905 if (connector->status != connector_status_connected)
4906 return -ENODEV;
4907
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004908 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4909 const struct dpcd_block *b = &i915_dpcd_debug[i];
4910 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4911
4912 if (b->edp &&
4913 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4914 continue;
4915
4916 /* low tech for now */
4917 if (WARN_ON(size > sizeof(buf)))
4918 continue;
4919
4920 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4921 if (err <= 0) {
4922 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4923 size, b->offset, err);
4924 continue;
4925 }
4926
4927 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004928 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004929
4930 return 0;
4931}
4932
4933static int i915_dpcd_open(struct inode *inode, struct file *file)
4934{
4935 return single_open(file, i915_dpcd_show, inode->i_private);
4936}
4937
4938static const struct file_operations i915_dpcd_fops = {
4939 .owner = THIS_MODULE,
4940 .open = i915_dpcd_open,
4941 .read = seq_read,
4942 .llseek = seq_lseek,
4943 .release = single_release,
4944};
4945
David Weinehallecbd6782016-08-23 12:23:56 +03004946static int i915_panel_show(struct seq_file *m, void *data)
4947{
4948 struct drm_connector *connector = m->private;
4949 struct intel_dp *intel_dp =
4950 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4951
4952 if (connector->status != connector_status_connected)
4953 return -ENODEV;
4954
4955 seq_printf(m, "Panel power up delay: %d\n",
4956 intel_dp->panel_power_up_delay);
4957 seq_printf(m, "Panel power down delay: %d\n",
4958 intel_dp->panel_power_down_delay);
4959 seq_printf(m, "Backlight on delay: %d\n",
4960 intel_dp->backlight_on_delay);
4961 seq_printf(m, "Backlight off delay: %d\n",
4962 intel_dp->backlight_off_delay);
4963
4964 return 0;
4965}
4966
4967static int i915_panel_open(struct inode *inode, struct file *file)
4968{
4969 return single_open(file, i915_panel_show, inode->i_private);
4970}
4971
4972static const struct file_operations i915_panel_fops = {
4973 .owner = THIS_MODULE,
4974 .open = i915_panel_open,
4975 .read = seq_read,
4976 .llseek = seq_lseek,
4977 .release = single_release,
4978};
4979
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004980/**
4981 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4982 * @connector: pointer to a registered drm_connector
4983 *
4984 * Cleanup will be done by drm_connector_unregister() through a call to
4985 * drm_debugfs_connector_remove().
4986 *
4987 * Returns 0 on success, negative error codes on error.
4988 */
4989int i915_debugfs_connector_add(struct drm_connector *connector)
4990{
4991 struct dentry *root = connector->debugfs_entry;
4992
4993 /* The connector must have been registered beforehands. */
4994 if (!root)
4995 return -ENODEV;
4996
4997 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4998 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03004999 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5000 connector, &i915_dpcd_fops);
5001
5002 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5003 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5004 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005005
5006 return 0;
5007}