blob: fa69d72fdcb9ff45e6590402bb59b9b325d65c38 [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 Wilson70d39fe2010-08-25 16:03:34 +010064static int i915_capabilities(struct seq_file *m, void *data)
65{
David Weinehall36cdd012016-08-22 13:59:31 +030066 struct drm_i915_private *dev_priv = node_to_i915(m->private);
67 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010068
David Weinehall36cdd012016-08-22 13:59:31 +030069 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
Jani Nikula2e0d26f2016-12-01 14:49:55 +020070 seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
David Weinehall36cdd012016-08-22 13:59:31 +030071 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010072#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030073 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010074#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010075
76 return 0;
77}
Ben Gamari433e12f2009-02-17 20:08:51 -050078
Imre Deaka7363de2016-05-12 16:18:52 +030079static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000080{
Chris Wilson573adb32016-08-04 16:32:39 +010081 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000082}
83
Imre Deaka7363de2016-05-12 16:18:52 +030084static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010085{
86 return obj->pin_display ? 'p' : ' ';
87}
88
Imre Deaka7363de2016-05-12 16:18:52 +030089static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000090{
Chris Wilson3e510a82016-08-05 10:14:23 +010091 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -040092 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010093 case I915_TILING_NONE: return ' ';
94 case I915_TILING_X: return 'X';
95 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -040096 }
Chris Wilsona6172a82009-02-11 14:26:38 +000097}
98
Imre Deaka7363de2016-05-12 16:18:52 +030099static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700100{
Chris Wilson275f0392016-10-24 13:42:14 +0100101 return !list_empty(&obj->userfault_link) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100102}
103
Imre Deaka7363de2016-05-12 16:18:52 +0300104static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100105{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100106 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700107}
108
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100109static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
110{
111 u64 size = 0;
112 struct i915_vma *vma;
113
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000114 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100115 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100116 size += vma->node.size;
117 }
118
119 return size;
120}
121
Chris Wilson37811fc2010-08-25 22:45:57 +0100122static void
123describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
124{
Chris Wilsonb4716182015-04-27 13:41:17 +0100125 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000126 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700127 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100128 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800129 int pin_count = 0;
130
Chris Wilson188c1ab2016-04-03 14:14:20 +0100131 lockdep_assert_held(&obj->base.dev->struct_mutex);
132
Chris Wilsond07f0e52016-10-28 13:58:44 +0100133 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100134 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100135 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100136 get_pin_flag(obj),
137 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700138 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100139 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800140 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100141 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100142 obj->base.write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300143 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100144 obj->mm.dirty ? " dirty" : "",
145 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 if (obj->base.name)
147 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000148 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100149 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800150 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300151 }
152 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100153 if (obj->pin_display)
154 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000155 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100156 if (!drm_mm_node_allocated(&vma->node))
157 continue;
158
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100159 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100160 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100161 vma->node.start, vma->node.size);
Chris Wilson21976852017-01-12 11:21:08 +0000162 if (i915_vma_is_ggtt(vma)) {
163 switch (vma->ggtt_view.type) {
164 case I915_GGTT_VIEW_NORMAL:
165 seq_puts(m, ", normal");
166 break;
167
168 case I915_GGTT_VIEW_PARTIAL:
169 seq_printf(m, ", partial [%08llx+%x]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000170 vma->ggtt_view.partial.offset << PAGE_SHIFT,
171 vma->ggtt_view.partial.size << PAGE_SHIFT);
Chris Wilson21976852017-01-12 11:21:08 +0000172 break;
173
174 case I915_GGTT_VIEW_ROTATED:
175 seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000176 vma->ggtt_view.rotated.plane[0].width,
177 vma->ggtt_view.rotated.plane[0].height,
178 vma->ggtt_view.rotated.plane[0].stride,
179 vma->ggtt_view.rotated.plane[0].offset,
180 vma->ggtt_view.rotated.plane[1].width,
181 vma->ggtt_view.rotated.plane[1].height,
182 vma->ggtt_view.rotated.plane[1].stride,
183 vma->ggtt_view.rotated.plane[1].offset);
Chris Wilson21976852017-01-12 11:21:08 +0000184 break;
185
186 default:
187 MISSING_CASE(vma->ggtt_view.type);
188 break;
189 }
190 }
Chris Wilson49ef5292016-08-18 17:17:00 +0100191 if (vma->fence)
192 seq_printf(m, " , fence: %d%s",
193 vma->fence->id,
194 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000195 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700196 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000197 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100198 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100199
Chris Wilsond07f0e52016-10-28 13:58:44 +0100200 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100201 if (engine)
202 seq_printf(m, " (%s)", engine->name);
203
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100204 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
205 if (frontbuffer_bits)
206 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100207}
208
Chris Wilson6d2b88852013-08-07 18:30:54 +0100209static int obj_rank_by_stolen(void *priv,
210 struct list_head *A, struct list_head *B)
211{
212 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200213 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100214 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200215 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100216
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200217 if (a->stolen->start < b->stolen->start)
218 return -1;
219 if (a->stolen->start > b->stolen->start)
220 return 1;
221 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100222}
223
224static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
225{
David Weinehall36cdd012016-08-22 13:59:31 +0300226 struct drm_i915_private *dev_priv = node_to_i915(m->private);
227 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100228 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300229 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100230 LIST_HEAD(stolen);
231 int count, ret;
232
233 ret = mutex_lock_interruptible(&dev->struct_mutex);
234 if (ret)
235 return ret;
236
237 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200238 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100239 if (obj->stolen == NULL)
240 continue;
241
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200242 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100243
244 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100245 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100246 count++;
247 }
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200248 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100249 if (obj->stolen == NULL)
250 continue;
251
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200252 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100253
254 total_obj_size += obj->base.size;
255 count++;
256 }
257 list_sort(NULL, &stolen, obj_rank_by_stolen);
258 seq_puts(m, "Stolen:\n");
259 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200260 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261 seq_puts(m, " ");
262 describe_obj(m, obj);
263 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200264 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100265 }
266 mutex_unlock(&dev->struct_mutex);
267
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300268 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100269 count, total_obj_size, total_gtt_size);
270 return 0;
271}
272
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100273struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000274 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300275 unsigned long count;
276 u64 total, unbound;
277 u64 global, shared;
278 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100279};
280
281static int per_file_stats(int id, void *ptr, void *data)
282{
283 struct drm_i915_gem_object *obj = ptr;
284 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000285 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100286
287 stats->count++;
288 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100289 if (!obj->bind_count)
290 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000291 if (obj->base.name || obj->base.dma_buf)
292 stats->shared += obj->base.size;
293
Chris Wilson894eeec2016-08-04 07:52:20 +0100294 list_for_each_entry(vma, &obj->vma_list, obj_link) {
295 if (!drm_mm_node_allocated(&vma->node))
296 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000297
Chris Wilson3272db52016-08-04 16:32:32 +0100298 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100299 stats->global += vma->node.size;
300 } else {
301 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000302
Chris Wilson2bfa9962016-08-04 07:52:25 +0100303 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000304 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000305 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100306
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100307 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100308 stats->active += vma->node.size;
309 else
310 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100311 }
312
313 return 0;
314}
315
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100316#define print_file_stats(m, name, stats) do { \
317 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300318 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 +0100319 name, \
320 stats.count, \
321 stats.total, \
322 stats.active, \
323 stats.inactive, \
324 stats.global, \
325 stats.shared, \
326 stats.unbound); \
327} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800328
329static void print_batch_pool_stats(struct seq_file *m,
330 struct drm_i915_private *dev_priv)
331{
332 struct drm_i915_gem_object *obj;
333 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000334 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530335 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000336 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800337
338 memset(&stats, 0, sizeof(stats));
339
Akash Goel3b3f1652016-10-13 22:44:48 +0530340 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000341 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100342 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000343 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100344 batch_pool_link)
345 per_file_stats(0, obj, &stats);
346 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100347 }
Brad Volkin493018d2014-12-11 12:13:08 -0800348
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100349 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800350}
351
Chris Wilson15da9562016-05-24 14:53:43 +0100352static int per_file_ctx_stats(int id, void *ptr, void *data)
353{
354 struct i915_gem_context *ctx = ptr;
355 int n;
356
357 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
358 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100359 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100360 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100361 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100362 }
363
364 return 0;
365}
366
367static void print_context_stats(struct seq_file *m,
368 struct drm_i915_private *dev_priv)
369{
David Weinehall36cdd012016-08-22 13:59:31 +0300370 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100371 struct file_stats stats;
372 struct drm_file *file;
373
374 memset(&stats, 0, sizeof(stats));
375
David Weinehall36cdd012016-08-22 13:59:31 +0300376 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100377 if (dev_priv->kernel_context)
378 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
379
David Weinehall36cdd012016-08-22 13:59:31 +0300380 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100381 struct drm_i915_file_private *fpriv = file->driver_priv;
382 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
383 }
David Weinehall36cdd012016-08-22 13:59:31 +0300384 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100385
386 print_file_stats(m, "[k]contexts", stats);
387}
388
David Weinehall36cdd012016-08-22 13:59:31 +0300389static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100390{
David Weinehall36cdd012016-08-22 13:59:31 +0300391 struct drm_i915_private *dev_priv = node_to_i915(m->private);
392 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300393 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100394 u32 count, mapped_count, purgeable_count, dpy_count;
395 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000396 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100397 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100398 int ret;
399
400 ret = mutex_lock_interruptible(&dev->struct_mutex);
401 if (ret)
402 return ret;
403
Chris Wilson3ef7f222016-10-18 13:02:48 +0100404 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000405 dev_priv->mm.object_count,
406 dev_priv->mm.object_memory);
407
Chris Wilson1544c422016-08-15 13:18:16 +0100408 size = count = 0;
409 mapped_size = mapped_count = 0;
410 purgeable_size = purgeable_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200411 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100412 size += obj->base.size;
413 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200414
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100415 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200416 purgeable_size += obj->base.size;
417 ++purgeable_count;
418 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100419
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100420 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100421 mapped_count++;
422 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100423 }
Chris Wilson6299f992010-11-24 12:23:44 +0000424 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100425 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
426
427 size = count = dpy_size = dpy_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200428 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100429 size += obj->base.size;
430 ++count;
431
432 if (obj->pin_display) {
433 dpy_size += obj->base.size;
434 ++dpy_count;
435 }
436
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100437 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100438 purgeable_size += obj->base.size;
439 ++purgeable_count;
440 }
441
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100442 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100443 mapped_count++;
444 mapped_size += obj->base.size;
445 }
446 }
447 seq_printf(m, "%u bound objects, %llu bytes\n",
448 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300449 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200450 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100451 seq_printf(m, "%u mapped objects, %llu bytes\n",
452 mapped_count, mapped_size);
453 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
454 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000455
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300456 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300457 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100458
Damien Lespiau267f0c92013-06-24 22:59:48 +0100459 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800460 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200461 mutex_unlock(&dev->struct_mutex);
462
463 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100464 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100465 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
466 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100467 struct drm_i915_file_private *file_priv = file->driver_priv;
468 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900469 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100470
471 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000472 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100473 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100474 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100475 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900476 /*
477 * Although we have a valid reference on file->pid, that does
478 * not guarantee that the task_struct who called get_pid() is
479 * still alive (e.g. get_pid(current) => fork() => exit()).
480 * Therefore, we need to protect this ->comm access using RCU.
481 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100482 mutex_lock(&dev->struct_mutex);
483 request = list_first_entry_or_null(&file_priv->mm.request_list,
484 struct drm_i915_gem_request,
485 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900486 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100487 task = pid_task(request && request->ctx->pid ?
488 request->ctx->pid : file->pid,
489 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800490 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900491 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100492 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100493 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200494 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100495
496 return 0;
497}
498
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100499static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000500{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100501 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300502 struct drm_i915_private *dev_priv = node_to_i915(node);
503 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100504 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000505 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300506 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000507 int count, ret;
508
509 ret = mutex_lock_interruptible(&dev->struct_mutex);
510 if (ret)
511 return ret;
512
513 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200514 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6da84822016-08-15 10:48:44 +0100515 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100516 continue;
517
Damien Lespiau267f0c92013-06-24 22:59:48 +0100518 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000519 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100520 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000521 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100522 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000523 count++;
524 }
525
526 mutex_unlock(&dev->struct_mutex);
527
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300528 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000529 count, total_obj_size, total_gtt_size);
530
531 return 0;
532}
533
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100534static int i915_gem_pageflip_info(struct seq_file *m, void *data)
535{
David Weinehall36cdd012016-08-22 13:59:31 +0300536 struct drm_i915_private *dev_priv = node_to_i915(m->private);
537 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100538 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200539 int ret;
540
541 ret = mutex_lock_interruptible(&dev->struct_mutex);
542 if (ret)
543 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100544
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100545 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800546 const char pipe = pipe_name(crtc->pipe);
547 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200548 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100549
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200550 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200551 work = crtc->flip_work;
552 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800553 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100554 pipe, plane);
555 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200556 u32 pending;
557 u32 addr;
558
559 pending = atomic_read(&work->pending);
560 if (pending) {
561 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
562 pipe, plane);
563 } else {
564 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
565 pipe, plane);
566 }
567 if (work->flip_queued_req) {
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200568 struct intel_engine_cs *engine = work->flip_queued_req->engine;
Daniel Vetter5a21b662016-05-24 17:13:53 +0200569
Chris Wilson312c3c42016-11-24 14:47:50 +0000570 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 +0200571 engine->name,
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200572 work->flip_queued_req->global_seqno,
Chris Wilson312c3c42016-11-24 14:47:50 +0000573 intel_engine_last_submit(engine),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100574 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100575 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200576 } else
577 seq_printf(m, "Flip not associated with any ring\n");
578 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
579 work->flip_queued_vblank,
580 work->flip_ready_vblank,
581 intel_crtc_get_vblank_counter(crtc));
582 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
583
David Weinehall36cdd012016-08-22 13:59:31 +0300584 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200585 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
586 else
587 addr = I915_READ(DSPADDR(crtc->plane));
588 seq_printf(m, "Current scanout address 0x%08x\n", addr);
589
590 if (work->pending_flip_obj) {
591 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
592 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100593 }
594 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200595 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100596 }
597
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200598 mutex_unlock(&dev->struct_mutex);
599
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100600 return 0;
601}
602
Brad Volkin493018d2014-12-11 12:13:08 -0800603static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
604{
David Weinehall36cdd012016-08-22 13:59:31 +0300605 struct drm_i915_private *dev_priv = node_to_i915(m->private);
606 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800607 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000608 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530609 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100610 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000611 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800612
613 ret = mutex_lock_interruptible(&dev->struct_mutex);
614 if (ret)
615 return ret;
616
Akash Goel3b3f1652016-10-13 22:44:48 +0530617 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000618 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100619 int count;
620
621 count = 0;
622 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000623 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100624 batch_pool_link)
625 count++;
626 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000627 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100628
629 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000630 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100631 batch_pool_link) {
632 seq_puts(m, " ");
633 describe_obj(m, obj);
634 seq_putc(m, '\n');
635 }
636
637 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100638 }
Brad Volkin493018d2014-12-11 12:13:08 -0800639 }
640
Chris Wilson8d9d5742015-04-07 16:20:38 +0100641 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800642
643 mutex_unlock(&dev->struct_mutex);
644
645 return 0;
646}
647
Chris Wilson1b365952016-10-04 21:11:31 +0100648static void print_request(struct seq_file *m,
649 struct drm_i915_gem_request *rq,
650 const char *prefix)
651{
Chris Wilson20311bd2016-11-14 20:41:03 +0000652 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100653 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000654 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100655 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100656 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100657}
658
Ben Gamari20172632009-02-17 20:08:50 -0500659static int i915_gem_request_info(struct seq_file *m, void *data)
660{
David Weinehall36cdd012016-08-22 13:59:31 +0300661 struct drm_i915_private *dev_priv = node_to_i915(m->private);
662 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200663 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530664 struct intel_engine_cs *engine;
665 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000666 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100667
668 ret = mutex_lock_interruptible(&dev->struct_mutex);
669 if (ret)
670 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500671
Chris Wilson2d1070b2015-04-01 10:36:56 +0100672 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530673 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100674 int count;
675
676 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100677 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100678 count++;
679 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100680 continue;
681
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000682 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100683 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100684 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100685
686 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500687 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100688 mutex_unlock(&dev->struct_mutex);
689
Chris Wilson2d1070b2015-04-01 10:36:56 +0100690 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100691 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100692
Ben Gamari20172632009-02-17 20:08:50 -0500693 return 0;
694}
695
Chris Wilsonb2223492010-10-27 15:27:33 +0100696static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000697 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100698{
Chris Wilson688e6c72016-07-01 17:23:15 +0100699 struct intel_breadcrumbs *b = &engine->breadcrumbs;
700 struct rb_node *rb;
701
Chris Wilson12471ba2016-04-09 10:57:55 +0100702 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100703 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100704
Chris Wilsonf6168e32016-10-28 13:58:55 +0100705 spin_lock_irq(&b->lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100706 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +0800707 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson688e6c72016-07-01 17:23:15 +0100708
709 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
710 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
711 }
Chris Wilsonf6168e32016-10-28 13:58:55 +0100712 spin_unlock_irq(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100713}
714
Ben Gamari20172632009-02-17 20:08:50 -0500715static int i915_gem_seqno_info(struct seq_file *m, void *data)
716{
David Weinehall36cdd012016-08-22 13:59:31 +0300717 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000718 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530719 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500720
Akash Goel3b3f1652016-10-13 22:44:48 +0530721 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000722 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100723
Ben Gamari20172632009-02-17 20:08:50 -0500724 return 0;
725}
726
727
728static int i915_interrupt_info(struct seq_file *m, void *data)
729{
David Weinehall36cdd012016-08-22 13:59:31 +0300730 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000731 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530732 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100733 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100734
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200735 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500736
David Weinehall36cdd012016-08-22 13:59:31 +0300737 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300738 seq_printf(m, "Master Interrupt Control:\t%08x\n",
739 I915_READ(GEN8_MASTER_IRQ));
740
741 seq_printf(m, "Display IER:\t%08x\n",
742 I915_READ(VLV_IER));
743 seq_printf(m, "Display IIR:\t%08x\n",
744 I915_READ(VLV_IIR));
745 seq_printf(m, "Display IIR_RW:\t%08x\n",
746 I915_READ(VLV_IIR_RW));
747 seq_printf(m, "Display IMR:\t%08x\n",
748 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100749 for_each_pipe(dev_priv, pipe) {
750 enum intel_display_power_domain power_domain;
751
752 power_domain = POWER_DOMAIN_PIPE(pipe);
753 if (!intel_display_power_get_if_enabled(dev_priv,
754 power_domain)) {
755 seq_printf(m, "Pipe %c power disabled\n",
756 pipe_name(pipe));
757 continue;
758 }
759
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300760 seq_printf(m, "Pipe %c stat:\t%08x\n",
761 pipe_name(pipe),
762 I915_READ(PIPESTAT(pipe)));
763
Chris Wilson9c870d02016-10-24 13:42:15 +0100764 intel_display_power_put(dev_priv, power_domain);
765 }
766
767 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300768 seq_printf(m, "Port hotplug:\t%08x\n",
769 I915_READ(PORT_HOTPLUG_EN));
770 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
771 I915_READ(VLV_DPFLIPSTAT));
772 seq_printf(m, "DPINVGTT:\t%08x\n",
773 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100774 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300775
776 for (i = 0; i < 4; i++) {
777 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
778 i, I915_READ(GEN8_GT_IMR(i)));
779 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
780 i, I915_READ(GEN8_GT_IIR(i)));
781 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
782 i, I915_READ(GEN8_GT_IER(i)));
783 }
784
785 seq_printf(m, "PCU interrupt mask:\t%08x\n",
786 I915_READ(GEN8_PCU_IMR));
787 seq_printf(m, "PCU interrupt identity:\t%08x\n",
788 I915_READ(GEN8_PCU_IIR));
789 seq_printf(m, "PCU interrupt enable:\t%08x\n",
790 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300791 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700792 seq_printf(m, "Master Interrupt Control:\t%08x\n",
793 I915_READ(GEN8_MASTER_IRQ));
794
795 for (i = 0; i < 4; i++) {
796 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
797 i, I915_READ(GEN8_GT_IMR(i)));
798 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
799 i, I915_READ(GEN8_GT_IIR(i)));
800 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
801 i, I915_READ(GEN8_GT_IER(i)));
802 }
803
Damien Lespiau055e3932014-08-18 13:49:10 +0100804 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200805 enum intel_display_power_domain power_domain;
806
807 power_domain = POWER_DOMAIN_PIPE(pipe);
808 if (!intel_display_power_get_if_enabled(dev_priv,
809 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300810 seq_printf(m, "Pipe %c power disabled\n",
811 pipe_name(pipe));
812 continue;
813 }
Ben Widawskya123f152013-11-02 21:07:10 -0700814 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000815 pipe_name(pipe),
816 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700817 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000818 pipe_name(pipe),
819 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700820 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000821 pipe_name(pipe),
822 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200823
824 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700825 }
826
827 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
828 I915_READ(GEN8_DE_PORT_IMR));
829 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
830 I915_READ(GEN8_DE_PORT_IIR));
831 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
832 I915_READ(GEN8_DE_PORT_IER));
833
834 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
835 I915_READ(GEN8_DE_MISC_IMR));
836 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
837 I915_READ(GEN8_DE_MISC_IIR));
838 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
839 I915_READ(GEN8_DE_MISC_IER));
840
841 seq_printf(m, "PCU interrupt mask:\t%08x\n",
842 I915_READ(GEN8_PCU_IMR));
843 seq_printf(m, "PCU interrupt identity:\t%08x\n",
844 I915_READ(GEN8_PCU_IIR));
845 seq_printf(m, "PCU interrupt enable:\t%08x\n",
846 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300847 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700848 seq_printf(m, "Display IER:\t%08x\n",
849 I915_READ(VLV_IER));
850 seq_printf(m, "Display IIR:\t%08x\n",
851 I915_READ(VLV_IIR));
852 seq_printf(m, "Display IIR_RW:\t%08x\n",
853 I915_READ(VLV_IIR_RW));
854 seq_printf(m, "Display IMR:\t%08x\n",
855 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100856 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700857 seq_printf(m, "Pipe %c stat:\t%08x\n",
858 pipe_name(pipe),
859 I915_READ(PIPESTAT(pipe)));
860
861 seq_printf(m, "Master IER:\t%08x\n",
862 I915_READ(VLV_MASTER_IER));
863
864 seq_printf(m, "Render IER:\t%08x\n",
865 I915_READ(GTIER));
866 seq_printf(m, "Render IIR:\t%08x\n",
867 I915_READ(GTIIR));
868 seq_printf(m, "Render IMR:\t%08x\n",
869 I915_READ(GTIMR));
870
871 seq_printf(m, "PM IER:\t\t%08x\n",
872 I915_READ(GEN6_PMIER));
873 seq_printf(m, "PM IIR:\t\t%08x\n",
874 I915_READ(GEN6_PMIIR));
875 seq_printf(m, "PM IMR:\t\t%08x\n",
876 I915_READ(GEN6_PMIMR));
877
878 seq_printf(m, "Port hotplug:\t%08x\n",
879 I915_READ(PORT_HOTPLUG_EN));
880 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
881 I915_READ(VLV_DPFLIPSTAT));
882 seq_printf(m, "DPINVGTT:\t%08x\n",
883 I915_READ(DPINVGTT));
884
David Weinehall36cdd012016-08-22 13:59:31 +0300885 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800886 seq_printf(m, "Interrupt enable: %08x\n",
887 I915_READ(IER));
888 seq_printf(m, "Interrupt identity: %08x\n",
889 I915_READ(IIR));
890 seq_printf(m, "Interrupt mask: %08x\n",
891 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100892 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800893 seq_printf(m, "Pipe %c stat: %08x\n",
894 pipe_name(pipe),
895 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800896 } else {
897 seq_printf(m, "North Display Interrupt enable: %08x\n",
898 I915_READ(DEIER));
899 seq_printf(m, "North Display Interrupt identity: %08x\n",
900 I915_READ(DEIIR));
901 seq_printf(m, "North Display Interrupt mask: %08x\n",
902 I915_READ(DEIMR));
903 seq_printf(m, "South Display Interrupt enable: %08x\n",
904 I915_READ(SDEIER));
905 seq_printf(m, "South Display Interrupt identity: %08x\n",
906 I915_READ(SDEIIR));
907 seq_printf(m, "South Display Interrupt mask: %08x\n",
908 I915_READ(SDEIMR));
909 seq_printf(m, "Graphics Interrupt enable: %08x\n",
910 I915_READ(GTIER));
911 seq_printf(m, "Graphics Interrupt identity: %08x\n",
912 I915_READ(GTIIR));
913 seq_printf(m, "Graphics Interrupt mask: %08x\n",
914 I915_READ(GTIMR));
915 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530916 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300917 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100918 seq_printf(m,
919 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000920 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000921 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000922 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000923 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200924 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100925
Ben Gamari20172632009-02-17 20:08:50 -0500926 return 0;
927}
928
Chris Wilsona6172a82009-02-11 14:26:38 +0000929static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
930{
David Weinehall36cdd012016-08-22 13:59:31 +0300931 struct drm_i915_private *dev_priv = node_to_i915(m->private);
932 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100933 int i, ret;
934
935 ret = mutex_lock_interruptible(&dev->struct_mutex);
936 if (ret)
937 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000938
Chris Wilsona6172a82009-02-11 14:26:38 +0000939 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
940 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100941 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000942
Chris Wilson6c085a72012-08-20 11:40:46 +0200943 seq_printf(m, "Fence %d, pin count = %d, object = ",
944 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100945 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100946 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100947 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100948 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100949 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000950 }
951
Chris Wilson05394f32010-11-08 19:18:58 +0000952 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000953 return 0;
954}
955
Chris Wilson98a2f412016-10-12 10:05:18 +0100956#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
957
Daniel Vetterd5442302012-04-27 15:17:40 +0200958static ssize_t
959i915_error_state_write(struct file *filp,
960 const char __user *ubuf,
961 size_t cnt,
962 loff_t *ppos)
963{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300964 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200965
966 DRM_DEBUG_DRIVER("Resetting error state\n");
Tvrtko Ursulin12ff05e2016-12-01 14:16:43 +0000967 i915_destroy_error_state(error_priv->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +0200968
969 return cnt;
970}
971
972static int i915_error_state_open(struct inode *inode, struct file *file)
973{
David Weinehall36cdd012016-08-22 13:59:31 +0300974 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200975 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200976
977 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
978 if (!error_priv)
979 return -ENOMEM;
980
Tvrtko Ursulin12ff05e2016-12-01 14:16:43 +0000981 error_priv->i915 = dev_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200982
David Weinehall36cdd012016-08-22 13:59:31 +0300983 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200984
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300985 file->private_data = error_priv;
986
987 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200988}
989
990static int i915_error_state_release(struct inode *inode, struct file *file)
991{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300992 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200993
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300994 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200995 kfree(error_priv);
996
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300997 return 0;
998}
999
1000static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1001 size_t count, loff_t *pos)
1002{
1003 struct i915_error_state_file_priv *error_priv = file->private_data;
1004 struct drm_i915_error_state_buf error_str;
1005 loff_t tmp_pos = 0;
1006 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001007 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001008
Tvrtko Ursulin12ff05e2016-12-01 14:16:43 +00001009 ret = i915_error_state_buf_init(&error_str, error_priv->i915,
1010 count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001011 if (ret)
1012 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001013
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001014 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001015 if (ret)
1016 goto out;
1017
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001018 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1019 error_str.buf,
1020 error_str.bytes);
1021
1022 if (ret_count < 0)
1023 ret = ret_count;
1024 else
1025 *pos = error_str.start + ret_count;
1026out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001027 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001028 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001029}
1030
1031static const struct file_operations i915_error_state_fops = {
1032 .owner = THIS_MODULE,
1033 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001034 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001035 .write = i915_error_state_write,
1036 .llseek = default_llseek,
1037 .release = i915_error_state_release,
1038};
1039
Chris Wilson98a2f412016-10-12 10:05:18 +01001040#endif
1041
Kees Cook647416f2013-03-10 14:10:06 -07001042static int
1043i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001044{
David Weinehall36cdd012016-08-22 13:59:31 +03001045 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001046
Joonas Lahtinen4c266ed2016-11-24 14:47:49 +00001047 *val = 1 + atomic_read(&dev_priv->gt.global_timeline.seqno);
Kees Cook647416f2013-03-10 14:10:06 -07001048 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001049}
1050
Kees Cook647416f2013-03-10 14:10:06 -07001051static int
1052i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001053{
David Weinehall36cdd012016-08-22 13:59:31 +03001054 struct drm_i915_private *dev_priv = data;
1055 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001056 int ret;
1057
Mika Kuoppala40633212012-12-04 15:12:00 +02001058 ret = mutex_lock_interruptible(&dev->struct_mutex);
1059 if (ret)
1060 return ret;
1061
Chris Wilson73cb9702016-10-28 13:58:46 +01001062 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001063 mutex_unlock(&dev->struct_mutex);
1064
Kees Cook647416f2013-03-10 14:10:06 -07001065 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001066}
1067
Kees Cook647416f2013-03-10 14:10:06 -07001068DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1069 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001070 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001071
Deepak Sadb4bd12014-03-31 11:30:02 +05301072static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001073{
David Weinehall36cdd012016-08-22 13:59:31 +03001074 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1075 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001076 int ret = 0;
1077
1078 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001079
David Weinehall36cdd012016-08-22 13:59:31 +03001080 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001081 u16 rgvswctl = I915_READ16(MEMSWCTL);
1082 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1083
1084 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1085 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1086 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1087 MEMSTAT_VID_SHIFT);
1088 seq_printf(m, "Current P-state: %d\n",
1089 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001090 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001091 u32 freq_sts;
1092
1093 mutex_lock(&dev_priv->rps.hw_lock);
1094 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1095 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1096 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1097
1098 seq_printf(m, "actual GPU freq: %d MHz\n",
1099 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1100
1101 seq_printf(m, "current GPU freq: %d MHz\n",
1102 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1103
1104 seq_printf(m, "max GPU freq: %d MHz\n",
1105 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1106
1107 seq_printf(m, "min GPU freq: %d MHz\n",
1108 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1109
1110 seq_printf(m, "idle GPU freq: %d MHz\n",
1111 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1112
1113 seq_printf(m,
1114 "efficient (RPe) frequency: %d MHz\n",
1115 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1116 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001117 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001118 u32 rp_state_limits;
1119 u32 gt_perf_status;
1120 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001121 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001122 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001123 u32 rpupei, rpcurup, rpprevup;
1124 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001125 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001126 int max_freq;
1127
Bob Paauwe35040562015-06-25 14:54:07 -07001128 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001129 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001130 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1131 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1132 } else {
1133 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1134 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1135 }
1136
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001137 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001138 ret = mutex_lock_interruptible(&dev->struct_mutex);
1139 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001140 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001141
Mika Kuoppala59bad942015-01-16 11:34:40 +02001142 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001144 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001145 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301146 reqf >>= 23;
1147 else {
1148 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001149 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301150 reqf >>= 24;
1151 else
1152 reqf >>= 25;
1153 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001154 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001155
Chris Wilson0d8f9492014-03-27 09:06:14 +00001156 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1157 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1158 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1159
Jesse Barnesccab5c82011-01-18 15:49:25 -08001160 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301161 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1162 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1163 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1164 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1165 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1166 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001167 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301168 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001169 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001170 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1171 else
1172 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001173 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001174
Mika Kuoppala59bad942015-01-16 11:34:40 +02001175 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001176 mutex_unlock(&dev->struct_mutex);
1177
David Weinehall36cdd012016-08-22 13:59:31 +03001178 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001179 pm_ier = I915_READ(GEN6_PMIER);
1180 pm_imr = I915_READ(GEN6_PMIMR);
1181 pm_isr = I915_READ(GEN6_PMISR);
1182 pm_iir = I915_READ(GEN6_PMIIR);
1183 pm_mask = I915_READ(GEN6_PMINTRMSK);
1184 } else {
1185 pm_ier = I915_READ(GEN8_GT_IER(2));
1186 pm_imr = I915_READ(GEN8_GT_IMR(2));
1187 pm_isr = I915_READ(GEN8_GT_ISR(2));
1188 pm_iir = I915_READ(GEN8_GT_IIR(2));
1189 pm_mask = I915_READ(GEN6_PMINTRMSK);
1190 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001191 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 -03001192 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301193 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001194 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001195 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001196 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001197 seq_printf(m, "Render p-state VID: %d\n",
1198 gt_perf_status & 0xff);
1199 seq_printf(m, "Render p-state limit: %d\n",
1200 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001201 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1202 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1203 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1204 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001205 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001206 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301207 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1208 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1209 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1210 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1211 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1212 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001213 seq_printf(m, "Up threshold: %d%%\n",
1214 dev_priv->rps.up_threshold);
1215
Akash Goeld6cda9c2016-04-23 00:05:46 +05301216 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1217 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1218 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1219 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1220 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1221 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001222 seq_printf(m, "Down threshold: %d%%\n",
1223 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001224
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001225 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001226 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001227 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001228 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001229 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001230 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001231
1232 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001233 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001234 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001235 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001236 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001237
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001238 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001239 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001240 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001241 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001242 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001243 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001244 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001245 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001246
Chris Wilsond86ed342015-04-27 13:41:19 +01001247 seq_printf(m, "Current freq: %d MHz\n",
1248 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1249 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001250 seq_printf(m, "Idle freq: %d MHz\n",
1251 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001252 seq_printf(m, "Min freq: %d MHz\n",
1253 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001254 seq_printf(m, "Boost freq: %d MHz\n",
1255 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001256 seq_printf(m, "Max freq: %d MHz\n",
1257 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1258 seq_printf(m,
1259 "efficient (RPe) frequency: %d MHz\n",
1260 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001261 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001262 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001264
Mika Kahola1170f282015-09-25 14:00:32 +03001265 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1266 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1267 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1268
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001269out:
1270 intel_runtime_pm_put(dev_priv);
1271 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001272}
1273
Ben Widawskyd6369512016-09-20 16:54:32 +03001274static void i915_instdone_info(struct drm_i915_private *dev_priv,
1275 struct seq_file *m,
1276 struct intel_instdone *instdone)
1277{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001278 int slice;
1279 int subslice;
1280
Ben Widawskyd6369512016-09-20 16:54:32 +03001281 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1282 instdone->instdone);
1283
1284 if (INTEL_GEN(dev_priv) <= 3)
1285 return;
1286
1287 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1288 instdone->slice_common);
1289
1290 if (INTEL_GEN(dev_priv) <= 6)
1291 return;
1292
Ben Widawskyf9e61372016-09-20 16:54:33 +03001293 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1294 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1295 slice, subslice, instdone->sampler[slice][subslice]);
1296
1297 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1298 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1299 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001300}
1301
Chris Wilsonf6544492015-01-26 18:03:04 +02001302static int i915_hangcheck_info(struct seq_file *m, void *unused)
1303{
David Weinehall36cdd012016-08-22 13:59:31 +03001304 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001305 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001306 u64 acthd[I915_NUM_ENGINES];
1307 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001308 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001309 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001310
Chris Wilson8af29b02016-09-09 14:11:47 +01001311 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1312 seq_printf(m, "Wedged\n");
1313 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1314 seq_printf(m, "Reset in progress\n");
1315 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1316 seq_printf(m, "Waiter holding struct mutex\n");
1317 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1318 seq_printf(m, "struct_mutex blocked for reset\n");
1319
Chris Wilsonf6544492015-01-26 18:03:04 +02001320 if (!i915.enable_hangcheck) {
1321 seq_printf(m, "Hangcheck disabled\n");
1322 return 0;
1323 }
1324
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001325 intel_runtime_pm_get(dev_priv);
1326
Akash Goel3b3f1652016-10-13 22:44:48 +05301327 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001328 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001329 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001330 }
1331
Akash Goel3b3f1652016-10-13 22:44:48 +05301332 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001333
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001334 intel_runtime_pm_put(dev_priv);
1335
Chris Wilsonf6544492015-01-26 18:03:04 +02001336 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1337 seq_printf(m, "Hangcheck active, fires in %dms\n",
1338 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1339 jiffies));
1340 } else
1341 seq_printf(m, "Hangcheck inactive\n");
1342
Akash Goel3b3f1652016-10-13 22:44:48 +05301343 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001344 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1345 struct rb_node *rb;
1346
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001347 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001348 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001349 engine->hangcheck.seqno, seqno[id],
1350 intel_engine_last_submit(engine));
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001351 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001352 yesno(intel_engine_has_waiter(engine)),
1353 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001354 &dev_priv->gpu_error.missed_irq_rings)),
1355 yesno(engine->hangcheck.stalled));
1356
Chris Wilsonf6168e32016-10-28 13:58:55 +01001357 spin_lock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001358 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001359 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001360
1361 seq_printf(m, "\t%s [%d] waiting for %x\n",
1362 w->tsk->comm, w->tsk->pid, w->seqno);
1363 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01001364 spin_unlock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001365
Chris Wilsonf6544492015-01-26 18:03:04 +02001366 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001367 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001368 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001369 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1370 hangcheck_action_to_str(engine->hangcheck.action),
1371 engine->hangcheck.action,
1372 jiffies_to_msecs(jiffies -
1373 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001374
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001375 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001376 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001377
Ben Widawskyd6369512016-09-20 16:54:32 +03001378 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001379
Ben Widawskyd6369512016-09-20 16:54:32 +03001380 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001381
Ben Widawskyd6369512016-09-20 16:54:32 +03001382 i915_instdone_info(dev_priv, m,
1383 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001384 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001385 }
1386
1387 return 0;
1388}
1389
Ben Widawsky4d855292011-12-12 19:34:16 -08001390static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001391{
David Weinehall36cdd012016-08-22 13:59:31 +03001392 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001393 u32 rgvmodectl, rstdbyctl;
1394 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001395
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001396 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001397
1398 rgvmodectl = I915_READ(MEMMODECTL);
1399 rstdbyctl = I915_READ(RSTDBYCTL);
1400 crstandvid = I915_READ16(CRSTANDVID);
1401
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001402 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001403
Jani Nikula742f4912015-09-03 11:16:09 +03001404 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001405 seq_printf(m, "Boost freq: %d\n",
1406 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1407 MEMMODE_BOOST_FREQ_SHIFT);
1408 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001409 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001410 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001411 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001412 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001413 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001414 seq_printf(m, "Starting frequency: P%d\n",
1415 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001416 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001417 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001418 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1419 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1420 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1421 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001422 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001423 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001424 switch (rstdbyctl & RSX_STATUS_MASK) {
1425 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001426 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001427 break;
1428 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001429 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001430 break;
1431 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001432 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001433 break;
1434 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001435 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001436 break;
1437 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001438 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001439 break;
1440 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001442 break;
1443 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 break;
1446 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001447
1448 return 0;
1449}
1450
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001451static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001452{
David Weinehall36cdd012016-08-22 13:59:31 +03001453 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001454 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001455
1456 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001457 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001458 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001459 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001460 fw_domain->wake_count);
1461 }
1462 spin_unlock_irq(&dev_priv->uncore.lock);
1463
1464 return 0;
1465}
1466
Deepak S669ab5a2014-01-10 15:18:26 +05301467static int vlv_drpc_info(struct seq_file *m)
1468{
David Weinehall36cdd012016-08-22 13:59:31 +03001469 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001470 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301471
Imre Deakd46c0512014-04-14 20:24:27 +03001472 intel_runtime_pm_get(dev_priv);
1473
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001474 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301475 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1476 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1477
Imre Deakd46c0512014-04-14 20:24:27 +03001478 intel_runtime_pm_put(dev_priv);
1479
Deepak S669ab5a2014-01-10 15:18:26 +05301480 seq_printf(m, "Video Turbo Mode: %s\n",
1481 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1482 seq_printf(m, "Turbo enabled: %s\n",
1483 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1484 seq_printf(m, "HW control enabled: %s\n",
1485 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1486 seq_printf(m, "SW control enabled: %s\n",
1487 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1488 GEN6_RP_MEDIA_SW_MODE));
1489 seq_printf(m, "RC6 Enabled: %s\n",
1490 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1491 GEN6_RC_CTL_EI_MODE(1))));
1492 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001493 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301494 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001495 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301496
Imre Deak9cc19be2014-04-14 20:24:24 +03001497 seq_printf(m, "Render RC6 residency since boot: %u\n",
1498 I915_READ(VLV_GT_RENDER_RC6));
1499 seq_printf(m, "Media RC6 residency since boot: %u\n",
1500 I915_READ(VLV_GT_MEDIA_RC6));
1501
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001502 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301503}
1504
Ben Widawsky4d855292011-12-12 19:34:16 -08001505static int gen6_drpc_info(struct seq_file *m)
1506{
David Weinehall36cdd012016-08-22 13:59:31 +03001507 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1508 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001509 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301510 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001511 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001512 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001513
1514 ret = mutex_lock_interruptible(&dev->struct_mutex);
1515 if (ret)
1516 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001517 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001518
Chris Wilson907b28c2013-07-19 20:36:52 +01001519 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001520 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001521 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001522
1523 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001524 seq_puts(m, "RC information inaccurate because somebody "
1525 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001526 } else {
1527 /* NB: we cannot use forcewake, else we read the wrong values */
1528 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1529 udelay(10);
1530 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1531 }
1532
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001533 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001534 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001535
1536 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1537 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001538 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301539 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1540 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1541 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001542 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001543 mutex_lock(&dev_priv->rps.hw_lock);
1544 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1545 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001546
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001547 intel_runtime_pm_put(dev_priv);
1548
Ben Widawsky4d855292011-12-12 19:34:16 -08001549 seq_printf(m, "Video Turbo Mode: %s\n",
1550 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1551 seq_printf(m, "HW control enabled: %s\n",
1552 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1553 seq_printf(m, "SW control enabled: %s\n",
1554 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1555 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001556 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001557 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1558 seq_printf(m, "RC6 Enabled: %s\n",
1559 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001560 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301561 seq_printf(m, "Render Well Gating Enabled: %s\n",
1562 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1563 seq_printf(m, "Media Well Gating Enabled: %s\n",
1564 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1565 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001566 seq_printf(m, "Deep RC6 Enabled: %s\n",
1567 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1568 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1569 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001570 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001571 switch (gt_core_status & GEN6_RCn_MASK) {
1572 case GEN6_RC0:
1573 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001574 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001575 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001576 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001577 break;
1578 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001579 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001580 break;
1581 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001582 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001583 break;
1584 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001585 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001586 break;
1587 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001588 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001589 break;
1590 }
1591
1592 seq_printf(m, "Core Power Down: %s\n",
1593 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001594 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301595 seq_printf(m, "Render Power Well: %s\n",
1596 (gen9_powergate_status &
1597 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1598 seq_printf(m, "Media Power Well: %s\n",
1599 (gen9_powergate_status &
1600 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1601 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001602
1603 /* Not exactly sure what this is */
1604 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1605 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1606 seq_printf(m, "RC6 residency since boot: %u\n",
1607 I915_READ(GEN6_GT_GFX_RC6));
1608 seq_printf(m, "RC6+ residency since boot: %u\n",
1609 I915_READ(GEN6_GT_GFX_RC6p));
1610 seq_printf(m, "RC6++ residency since boot: %u\n",
1611 I915_READ(GEN6_GT_GFX_RC6pp));
1612
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001613 seq_printf(m, "RC6 voltage: %dmV\n",
1614 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1615 seq_printf(m, "RC6+ voltage: %dmV\n",
1616 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1617 seq_printf(m, "RC6++ voltage: %dmV\n",
1618 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301619 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001620}
1621
1622static int i915_drpc_info(struct seq_file *m, void *unused)
1623{
David Weinehall36cdd012016-08-22 13:59:31 +03001624 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001625
David Weinehall36cdd012016-08-22 13:59:31 +03001626 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301627 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001628 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001629 return gen6_drpc_info(m);
1630 else
1631 return ironlake_drpc_info(m);
1632}
1633
Daniel Vetter9a851782015-06-18 10:30:22 +02001634static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1635{
David Weinehall36cdd012016-08-22 13:59:31 +03001636 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001637
1638 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1639 dev_priv->fb_tracking.busy_bits);
1640
1641 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1642 dev_priv->fb_tracking.flip_bits);
1643
1644 return 0;
1645}
1646
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001647static int i915_fbc_status(struct seq_file *m, void *unused)
1648{
David Weinehall36cdd012016-08-22 13:59:31 +03001649 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001650
David Weinehall36cdd012016-08-22 13:59:31 +03001651 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001652 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001653 return 0;
1654 }
1655
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001656 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001657 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001658
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001659 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001660 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001661 else
1662 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001663 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001664
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001665 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1666 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1667 BDW_FBC_COMPRESSION_MASK :
1668 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001669 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001670 yesno(I915_READ(FBC_STATUS2) & mask));
1671 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001672
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001673 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001674 intel_runtime_pm_put(dev_priv);
1675
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001676 return 0;
1677}
1678
Rodrigo Vivida46f932014-08-01 02:04:45 -07001679static int i915_fbc_fc_get(void *data, u64 *val)
1680{
David Weinehall36cdd012016-08-22 13:59:31 +03001681 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001682
David Weinehall36cdd012016-08-22 13:59:31 +03001683 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001684 return -ENODEV;
1685
Rodrigo Vivida46f932014-08-01 02:04:45 -07001686 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001687
1688 return 0;
1689}
1690
1691static int i915_fbc_fc_set(void *data, u64 val)
1692{
David Weinehall36cdd012016-08-22 13:59:31 +03001693 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001694 u32 reg;
1695
David Weinehall36cdd012016-08-22 13:59:31 +03001696 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001697 return -ENODEV;
1698
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001699 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001700
1701 reg = I915_READ(ILK_DPFC_CONTROL);
1702 dev_priv->fbc.false_color = val;
1703
1704 I915_WRITE(ILK_DPFC_CONTROL, val ?
1705 (reg | FBC_CTL_FALSE_COLOR) :
1706 (reg & ~FBC_CTL_FALSE_COLOR));
1707
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001708 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001709 return 0;
1710}
1711
1712DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1713 i915_fbc_fc_get, i915_fbc_fc_set,
1714 "%llu\n");
1715
Paulo Zanoni92d44622013-05-31 16:33:24 -03001716static int i915_ips_status(struct seq_file *m, void *unused)
1717{
David Weinehall36cdd012016-08-22 13:59:31 +03001718 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001719
David Weinehall36cdd012016-08-22 13:59:31 +03001720 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001721 seq_puts(m, "not supported\n");
1722 return 0;
1723 }
1724
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001725 intel_runtime_pm_get(dev_priv);
1726
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001727 seq_printf(m, "Enabled by kernel parameter: %s\n",
1728 yesno(i915.enable_ips));
1729
David Weinehall36cdd012016-08-22 13:59:31 +03001730 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001731 seq_puts(m, "Currently: unknown\n");
1732 } else {
1733 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1734 seq_puts(m, "Currently: enabled\n");
1735 else
1736 seq_puts(m, "Currently: disabled\n");
1737 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001738
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001739 intel_runtime_pm_put(dev_priv);
1740
Paulo Zanoni92d44622013-05-31 16:33:24 -03001741 return 0;
1742}
1743
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001744static int i915_sr_status(struct seq_file *m, void *unused)
1745{
David Weinehall36cdd012016-08-22 13:59:31 +03001746 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001747 bool sr_enabled = false;
1748
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001749 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001750 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001751
David Weinehall36cdd012016-08-22 13:59:31 +03001752 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001753 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001754 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001755 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001756 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001757 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001758 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001759 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001760 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001761 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001762 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001763
Chris Wilson9c870d02016-10-24 13:42:15 +01001764 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001765 intel_runtime_pm_put(dev_priv);
1766
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001767 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001768
1769 return 0;
1770}
1771
Jesse Barnes7648fa92010-05-20 14:28:11 -07001772static int i915_emon_status(struct seq_file *m, void *unused)
1773{
David Weinehall36cdd012016-08-22 13:59:31 +03001774 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1775 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001776 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001777 int ret;
1778
David Weinehall36cdd012016-08-22 13:59:31 +03001779 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001780 return -ENODEV;
1781
Chris Wilsonde227ef2010-07-03 07:58:38 +01001782 ret = mutex_lock_interruptible(&dev->struct_mutex);
1783 if (ret)
1784 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001785
1786 temp = i915_mch_val(dev_priv);
1787 chipset = i915_chipset_val(dev_priv);
1788 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001789 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001790
1791 seq_printf(m, "GMCH temp: %ld\n", temp);
1792 seq_printf(m, "Chipset power: %ld\n", chipset);
1793 seq_printf(m, "GFX power: %ld\n", gfx);
1794 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1795
1796 return 0;
1797}
1798
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001799static int i915_ring_freq_table(struct seq_file *m, void *unused)
1800{
David Weinehall36cdd012016-08-22 13:59:31 +03001801 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001802 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001803 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301804 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001805
Carlos Santa26310342016-08-17 12:30:41 -07001806 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001807 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001808 return 0;
1809 }
1810
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001811 intel_runtime_pm_get(dev_priv);
1812
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001813 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001814 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001815 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001816
David Weinehall36cdd012016-08-22 13:59:31 +03001817 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301818 /* Convert GT frequency to 50 HZ units */
1819 min_gpu_freq =
1820 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1821 max_gpu_freq =
1822 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1823 } else {
1824 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1825 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1826 }
1827
Damien Lespiau267f0c92013-06-24 22:59:48 +01001828 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001829
Akash Goelf936ec32015-06-29 14:50:22 +05301830 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001831 ia_freq = gpu_freq;
1832 sandybridge_pcode_read(dev_priv,
1833 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1834 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001835 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301836 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001837 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001838 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001839 ((ia_freq >> 0) & 0xff) * 100,
1840 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001841 }
1842
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001843 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001844
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001845out:
1846 intel_runtime_pm_put(dev_priv);
1847 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001848}
1849
Chris Wilson44834a62010-08-19 16:09:23 +01001850static int i915_opregion(struct seq_file *m, void *unused)
1851{
David Weinehall36cdd012016-08-22 13:59:31 +03001852 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1853 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001854 struct intel_opregion *opregion = &dev_priv->opregion;
1855 int ret;
1856
1857 ret = mutex_lock_interruptible(&dev->struct_mutex);
1858 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001859 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001860
Jani Nikula2455a8e2015-12-14 12:50:53 +02001861 if (opregion->header)
1862 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001863
1864 mutex_unlock(&dev->struct_mutex);
1865
Daniel Vetter0d38f002012-04-21 22:49:10 +02001866out:
Chris Wilson44834a62010-08-19 16:09:23 +01001867 return 0;
1868}
1869
Jani Nikulaada8f952015-12-15 13:17:12 +02001870static int i915_vbt(struct seq_file *m, void *unused)
1871{
David Weinehall36cdd012016-08-22 13:59:31 +03001872 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001873
1874 if (opregion->vbt)
1875 seq_write(m, opregion->vbt, opregion->vbt_size);
1876
1877 return 0;
1878}
1879
Chris Wilson37811fc2010-08-25 22:45:57 +01001880static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1881{
David Weinehall36cdd012016-08-22 13:59:31 +03001882 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1883 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301884 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001885 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001886 int ret;
1887
1888 ret = mutex_lock_interruptible(&dev->struct_mutex);
1889 if (ret)
1890 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001891
Daniel Vetter06957262015-08-10 13:34:08 +02001892#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001893 if (dev_priv->fbdev) {
1894 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001895
Chris Wilson25bcce92016-07-02 15:36:00 +01001896 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1897 fbdev_fb->base.width,
1898 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001899 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001900 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001901 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001902 drm_framebuffer_read_refcount(&fbdev_fb->base));
1903 describe_obj(m, fbdev_fb->obj);
1904 seq_putc(m, '\n');
1905 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001906#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001907
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001908 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001909 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301910 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1911 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001912 continue;
1913
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001914 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 +01001915 fb->base.width,
1916 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001917 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001918 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001919 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001920 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001921 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001922 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001923 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001924 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001925 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001926
1927 return 0;
1928}
1929
Chris Wilson7e37f882016-08-02 22:50:21 +01001930static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001931{
1932 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001933 ring->space, ring->head, ring->tail,
1934 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001935}
1936
Ben Widawskye76d3632011-03-19 18:14:29 -07001937static int i915_context_status(struct seq_file *m, void *unused)
1938{
David Weinehall36cdd012016-08-22 13:59:31 +03001939 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1940 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001941 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001942 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301943 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001944 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001945
Daniel Vetterf3d28872014-05-29 23:23:08 +02001946 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001947 if (ret)
1948 return ret;
1949
Ben Widawskya33afea2013-09-17 21:12:45 -07001950 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001951 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001952 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001953 struct task_struct *task;
1954
Chris Wilsonc84455b2016-08-15 10:49:08 +01001955 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001956 if (task) {
1957 seq_printf(m, "(%s [%d]) ",
1958 task->comm, task->pid);
1959 put_task_struct(task);
1960 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001961 } else if (IS_ERR(ctx->file_priv)) {
1962 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001963 } else {
1964 seq_puts(m, "(kernel) ");
1965 }
1966
Chris Wilsonbca44d82016-05-24 14:53:41 +01001967 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1968 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001969
Akash Goel3b3f1652016-10-13 22:44:48 +05301970 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001971 struct intel_context *ce = &ctx->engine[engine->id];
1972
1973 seq_printf(m, "%s: ", engine->name);
1974 seq_putc(m, ce->initialised ? 'I' : 'i');
1975 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001976 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001977 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001978 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001979 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001980 }
1981
Ben Widawskya33afea2013-09-17 21:12:45 -07001982 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001983 }
1984
Daniel Vetterf3d28872014-05-29 23:23:08 +02001985 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001986
1987 return 0;
1988}
1989
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001990static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001991 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001992 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001993{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001994 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001995 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001996 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001997
Chris Wilson7069b142016-04-28 09:56:52 +01001998 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1999
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002000 if (!vma) {
2001 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002002 return;
2003 }
2004
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002005 if (vma->flags & I915_VMA_GLOBAL_BIND)
2006 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002007 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002008
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002009 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002010 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002011 return;
2012 }
2013
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002014 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2015 if (page) {
2016 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002017
2018 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002019 seq_printf(m,
2020 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2021 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002022 reg_state[j], reg_state[j + 1],
2023 reg_state[j + 2], reg_state[j + 3]);
2024 }
2025 kunmap_atomic(reg_state);
2026 }
2027
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002028 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002029 seq_putc(m, '\n');
2030}
2031
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002032static int i915_dump_lrc(struct seq_file *m, void *unused)
2033{
David Weinehall36cdd012016-08-22 13:59:31 +03002034 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2035 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002036 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002037 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302038 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002039 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002040
2041 if (!i915.enable_execlists) {
2042 seq_printf(m, "Logical Ring Contexts are disabled\n");
2043 return 0;
2044 }
2045
2046 ret = mutex_lock_interruptible(&dev->struct_mutex);
2047 if (ret)
2048 return ret;
2049
Dave Gordone28e4042016-01-19 19:02:55 +00002050 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302051 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002052 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002053
2054 mutex_unlock(&dev->struct_mutex);
2055
2056 return 0;
2057}
2058
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002059static const char *swizzle_string(unsigned swizzle)
2060{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002061 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002062 case I915_BIT_6_SWIZZLE_NONE:
2063 return "none";
2064 case I915_BIT_6_SWIZZLE_9:
2065 return "bit9";
2066 case I915_BIT_6_SWIZZLE_9_10:
2067 return "bit9/bit10";
2068 case I915_BIT_6_SWIZZLE_9_11:
2069 return "bit9/bit11";
2070 case I915_BIT_6_SWIZZLE_9_10_11:
2071 return "bit9/bit10/bit11";
2072 case I915_BIT_6_SWIZZLE_9_17:
2073 return "bit9/bit17";
2074 case I915_BIT_6_SWIZZLE_9_10_17:
2075 return "bit9/bit10/bit17";
2076 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002077 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002078 }
2079
2080 return "bug";
2081}
2082
2083static int i915_swizzle_info(struct seq_file *m, void *data)
2084{
David Weinehall36cdd012016-08-22 13:59:31 +03002085 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002086
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002087 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002088
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002089 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2090 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2091 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2092 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2093
David Weinehall36cdd012016-08-22 13:59:31 +03002094 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002095 seq_printf(m, "DDC = 0x%08x\n",
2096 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002097 seq_printf(m, "DDC2 = 0x%08x\n",
2098 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002099 seq_printf(m, "C0DRB3 = 0x%04x\n",
2100 I915_READ16(C0DRB3));
2101 seq_printf(m, "C1DRB3 = 0x%04x\n",
2102 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002103 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002104 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2105 I915_READ(MAD_DIMM_C0));
2106 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2107 I915_READ(MAD_DIMM_C1));
2108 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2109 I915_READ(MAD_DIMM_C2));
2110 seq_printf(m, "TILECTL = 0x%08x\n",
2111 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002112 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002113 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2114 I915_READ(GAMTARBMODE));
2115 else
2116 seq_printf(m, "ARB_MODE = 0x%08x\n",
2117 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002118 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2119 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002120 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002121
2122 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2123 seq_puts(m, "L-shaped memory detected\n");
2124
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002125 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002126
2127 return 0;
2128}
2129
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002130static int per_file_ctx(int id, void *ptr, void *data)
2131{
Chris Wilsone2efd132016-05-24 14:53:34 +01002132 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002133 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002134 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2135
2136 if (!ppgtt) {
2137 seq_printf(m, " no ppgtt for context %d\n",
2138 ctx->user_handle);
2139 return 0;
2140 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002141
Oscar Mateof83d6512014-05-22 14:13:38 +01002142 if (i915_gem_context_is_default(ctx))
2143 seq_puts(m, " default context:\n");
2144 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002145 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002146 ppgtt->debug_dump(ppgtt, m);
2147
2148 return 0;
2149}
2150
David Weinehall36cdd012016-08-22 13:59:31 +03002151static void gen8_ppgtt_info(struct seq_file *m,
2152 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002153{
Ben Widawsky77df6772013-11-02 21:07:30 -07002154 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302155 struct intel_engine_cs *engine;
2156 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002157 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002158
Ben Widawsky77df6772013-11-02 21:07:30 -07002159 if (!ppgtt)
2160 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002161
Akash Goel3b3f1652016-10-13 22:44:48 +05302162 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002163 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002164 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002165 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002166 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002167 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002168 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002169 }
2170 }
2171}
2172
David Weinehall36cdd012016-08-22 13:59:31 +03002173static void gen6_ppgtt_info(struct seq_file *m,
2174 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002175{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002176 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302177 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002178
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002179 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002180 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2181
Akash Goel3b3f1652016-10-13 22:44:48 +05302182 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002183 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002184 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002185 seq_printf(m, "GFX_MODE: 0x%08x\n",
2186 I915_READ(RING_MODE_GEN7(engine)));
2187 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2188 I915_READ(RING_PP_DIR_BASE(engine)));
2189 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2190 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2191 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2192 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002193 }
2194 if (dev_priv->mm.aliasing_ppgtt) {
2195 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2196
Damien Lespiau267f0c92013-06-24 22:59:48 +01002197 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002198 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002199
Ben Widawsky87d60b62013-12-06 14:11:29 -08002200 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002201 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002202
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002203 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002204}
2205
2206static int i915_ppgtt_info(struct seq_file *m, void *data)
2207{
David Weinehall36cdd012016-08-22 13:59:31 +03002208 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2209 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002210 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002211 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002212
Chris Wilson637ee292016-08-22 14:28:20 +01002213 mutex_lock(&dev->filelist_mutex);
2214 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002215 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002216 goto out_unlock;
2217
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002218 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002219
David Weinehall36cdd012016-08-22 13:59:31 +03002220 if (INTEL_GEN(dev_priv) >= 8)
2221 gen8_ppgtt_info(m, dev_priv);
2222 else if (INTEL_GEN(dev_priv) >= 6)
2223 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002224
Michel Thierryea91e402015-07-29 17:23:57 +01002225 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2226 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002227 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002228
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002229 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002230 if (!task) {
2231 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002232 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002233 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002234 seq_printf(m, "\nproc: %s\n", task->comm);
2235 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002236 idr_for_each(&file_priv->context_idr, per_file_ctx,
2237 (void *)(unsigned long)m);
2238 }
2239
Chris Wilson637ee292016-08-22 14:28:20 +01002240out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002241 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002242 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002243out_unlock:
2244 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002245 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002246}
2247
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002248static int count_irq_waiters(struct drm_i915_private *i915)
2249{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002250 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302251 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002252 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002253
Akash Goel3b3f1652016-10-13 22:44:48 +05302254 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002255 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002256
2257 return count;
2258}
2259
Chris Wilson7466c292016-08-15 09:49:33 +01002260static const char *rps_power_to_str(unsigned int power)
2261{
2262 static const char * const strings[] = {
2263 [LOW_POWER] = "low power",
2264 [BETWEEN] = "mixed",
2265 [HIGH_POWER] = "high power",
2266 };
2267
2268 if (power >= ARRAY_SIZE(strings) || !strings[power])
2269 return "unknown";
2270
2271 return strings[power];
2272}
2273
Chris Wilson1854d5c2015-04-07 16:20:32 +01002274static int i915_rps_boost_info(struct seq_file *m, void *data)
2275{
David Weinehall36cdd012016-08-22 13:59:31 +03002276 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2277 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002278 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002279
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002280 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002281 seq_printf(m, "GPU busy? %s [%d requests]\n",
2282 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002283 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002284 seq_printf(m, "Frequency requested %d\n",
2285 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2286 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002287 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2288 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2289 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2290 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002291 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2292 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2293 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2294 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002295
2296 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002297 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002298 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2299 struct drm_i915_file_private *file_priv = file->driver_priv;
2300 struct task_struct *task;
2301
2302 rcu_read_lock();
2303 task = pid_task(file->pid, PIDTYPE_PID);
2304 seq_printf(m, "%s [%d]: %d boosts%s\n",
2305 task ? task->comm : "<unknown>",
2306 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002307 file_priv->rps.boosts,
2308 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002309 rcu_read_unlock();
2310 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002311 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002312 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002313 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002314
Chris Wilson7466c292016-08-15 09:49:33 +01002315 if (INTEL_GEN(dev_priv) >= 6 &&
2316 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002317 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002318 u32 rpup, rpupei;
2319 u32 rpdown, rpdownei;
2320
2321 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2322 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2323 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2324 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2325 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2326 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2327
2328 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2329 rps_power_to_str(dev_priv->rps.power));
2330 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2331 100 * rpup / rpupei,
2332 dev_priv->rps.up_threshold);
2333 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2334 100 * rpdown / rpdownei,
2335 dev_priv->rps.down_threshold);
2336 } else {
2337 seq_puts(m, "\nRPS Autotuning inactive\n");
2338 }
2339
Chris Wilson8d3afd72015-05-21 21:01:47 +01002340 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002341}
2342
Ben Widawsky63573eb2013-07-04 11:02:07 -07002343static int i915_llc(struct seq_file *m, void *data)
2344{
David Weinehall36cdd012016-08-22 13:59:31 +03002345 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002346 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002347
David Weinehall36cdd012016-08-22 13:59:31 +03002348 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002349 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2350 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002351
2352 return 0;
2353}
2354
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002355static int i915_huc_load_status_info(struct seq_file *m, void *data)
2356{
2357 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2358 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2359
2360 if (!HAS_HUC_UCODE(dev_priv))
2361 return 0;
2362
2363 seq_puts(m, "HuC firmware status:\n");
2364 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2365 seq_printf(m, "\tfetch: %s\n",
2366 intel_uc_fw_status_repr(huc_fw->fetch_status));
2367 seq_printf(m, "\tload: %s\n",
2368 intel_uc_fw_status_repr(huc_fw->load_status));
2369 seq_printf(m, "\tversion wanted: %d.%d\n",
2370 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2371 seq_printf(m, "\tversion found: %d.%d\n",
2372 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2373 seq_printf(m, "\theader: offset is %d; size = %d\n",
2374 huc_fw->header_offset, huc_fw->header_size);
2375 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2376 huc_fw->ucode_offset, huc_fw->ucode_size);
2377 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2378 huc_fw->rsa_offset, huc_fw->rsa_size);
2379
2380 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
2381
2382 return 0;
2383}
2384
Alex Daifdf5d352015-08-12 15:43:37 +01002385static int i915_guc_load_status_info(struct seq_file *m, void *data)
2386{
David Weinehall36cdd012016-08-22 13:59:31 +03002387 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002388 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
Alex Daifdf5d352015-08-12 15:43:37 +01002389 u32 tmp, i;
2390
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002391 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002392 return 0;
2393
2394 seq_printf(m, "GuC firmware status:\n");
2395 seq_printf(m, "\tpath: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002396 guc_fw->path);
Alex Daifdf5d352015-08-12 15:43:37 +01002397 seq_printf(m, "\tfetch: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002398 intel_uc_fw_status_repr(guc_fw->fetch_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002399 seq_printf(m, "\tload: %s\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002400 intel_uc_fw_status_repr(guc_fw->load_status));
Alex Daifdf5d352015-08-12 15:43:37 +01002401 seq_printf(m, "\tversion wanted: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002402 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
Alex Daifdf5d352015-08-12 15:43:37 +01002403 seq_printf(m, "\tversion found: %d.%d\n",
Anusha Srivatsadb0a0912017-01-13 17:17:04 -08002404 guc_fw->major_ver_found, guc_fw->minor_ver_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002405 seq_printf(m, "\theader: offset is %d; size = %d\n",
2406 guc_fw->header_offset, guc_fw->header_size);
2407 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2408 guc_fw->ucode_offset, guc_fw->ucode_size);
2409 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2410 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002411
2412 tmp = I915_READ(GUC_STATUS);
2413
2414 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2415 seq_printf(m, "\tBootrom status = 0x%x\n",
2416 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2417 seq_printf(m, "\tuKernel status = 0x%x\n",
2418 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2419 seq_printf(m, "\tMIA Core status = 0x%x\n",
2420 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2421 seq_puts(m, "\nScratch registers:\n");
2422 for (i = 0; i < 16; i++)
2423 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2424
2425 return 0;
2426}
2427
Akash Goel5aa1ee42016-10-12 21:54:36 +05302428static void i915_guc_log_info(struct seq_file *m,
2429 struct drm_i915_private *dev_priv)
2430{
2431 struct intel_guc *guc = &dev_priv->guc;
2432
2433 seq_puts(m, "\nGuC logging stats:\n");
2434
2435 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2436 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2437 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2438
2439 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2440 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2441 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2442
2443 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2444 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2445 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2446
2447 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2448 guc->log.flush_interrupt_count);
2449
2450 seq_printf(m, "\tCapture miss count: %u\n",
2451 guc->log.capture_miss_count);
2452}
2453
Dave Gordon8b417c22015-08-12 15:43:44 +01002454static void i915_guc_client_info(struct seq_file *m,
2455 struct drm_i915_private *dev_priv,
2456 struct i915_guc_client *client)
2457{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002458 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002459 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002460 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002461
2462 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2463 client->priority, client->ctx_index, client->proc_desc_offset);
2464 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002465 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002466 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2467 client->wq_size, client->wq_offset, client->wq_tail);
2468
Dave Gordon551aaec2016-05-13 15:36:33 +01002469 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002470 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2471 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2472
Akash Goel3b3f1652016-10-13 22:44:48 +05302473 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002474 u64 submissions = client->submissions[id];
2475 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002476 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002477 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002478 }
2479 seq_printf(m, "\tTotal: %llu\n", tot);
2480}
2481
2482static int i915_guc_info(struct seq_file *m, void *data)
2483{
David Weinehall36cdd012016-08-22 13:59:31 +03002484 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002485 const struct intel_guc *guc = &dev_priv->guc;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002486 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002487 enum intel_engine_id id;
Chris Wilson334636c2016-11-29 12:10:20 +00002488 u64 total;
Dave Gordon8b417c22015-08-12 15:43:44 +01002489
Chris Wilson334636c2016-11-29 12:10:20 +00002490 if (!guc->execbuf_client) {
2491 seq_printf(m, "GuC submission %s\n",
2492 HAS_GUC_SCHED(dev_priv) ?
2493 "disabled" :
2494 "not supported");
Dave Gordon8b417c22015-08-12 15:43:44 +01002495 return 0;
Chris Wilson334636c2016-11-29 12:10:20 +00002496 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002497
Dave Gordon9636f6d2016-06-13 17:57:28 +01002498 seq_printf(m, "Doorbell map:\n");
Chris Wilson334636c2016-11-29 12:10:20 +00002499 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc->doorbell_bitmap);
2500 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002501
Chris Wilson334636c2016-11-29 12:10:20 +00002502 seq_printf(m, "GuC total action count: %llu\n", guc->action_count);
2503 seq_printf(m, "GuC action failure count: %u\n", guc->action_fail);
2504 seq_printf(m, "GuC last action command: 0x%x\n", guc->action_cmd);
2505 seq_printf(m, "GuC last action status: 0x%x\n", guc->action_status);
2506 seq_printf(m, "GuC last action error code: %d\n", guc->action_err);
Dave Gordon8b417c22015-08-12 15:43:44 +01002507
Chris Wilson334636c2016-11-29 12:10:20 +00002508 total = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002509 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302510 for_each_engine(engine, dev_priv, id) {
Chris Wilson334636c2016-11-29 12:10:20 +00002511 u64 submissions = guc->submissions[id];
Dave Gordonc18468c2016-08-09 15:19:22 +01002512 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002513 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Chris Wilson334636c2016-11-29 12:10:20 +00002514 engine->name, submissions, guc->last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002515 }
2516 seq_printf(m, "\t%s: %llu\n", "Total", total);
2517
Chris Wilson334636c2016-11-29 12:10:20 +00002518 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2519 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002520
Akash Goel5aa1ee42016-10-12 21:54:36 +05302521 i915_guc_log_info(m, dev_priv);
2522
Dave Gordon8b417c22015-08-12 15:43:44 +01002523 /* Add more as required ... */
2524
2525 return 0;
2526}
2527
Alex Dai4c7e77f2015-08-12 15:43:40 +01002528static int i915_guc_log_dump(struct seq_file *m, void *data)
2529{
David Weinehall36cdd012016-08-22 13:59:31 +03002530 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002531 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002532 int i = 0, pg;
2533
Akash Goeld6b40b42016-10-12 21:54:29 +05302534 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002535 return 0;
2536
Akash Goeld6b40b42016-10-12 21:54:29 +05302537 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002538 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2539 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002540
2541 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2542 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2543 *(log + i), *(log + i + 1),
2544 *(log + i + 2), *(log + i + 3));
2545
2546 kunmap_atomic(log);
2547 }
2548
2549 seq_putc(m, '\n');
2550
2551 return 0;
2552}
2553
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302554static int i915_guc_log_control_get(void *data, u64 *val)
2555{
2556 struct drm_device *dev = data;
2557 struct drm_i915_private *dev_priv = to_i915(dev);
2558
2559 if (!dev_priv->guc.log.vma)
2560 return -EINVAL;
2561
2562 *val = i915.guc_log_level;
2563
2564 return 0;
2565}
2566
2567static int i915_guc_log_control_set(void *data, u64 val)
2568{
2569 struct drm_device *dev = data;
2570 struct drm_i915_private *dev_priv = to_i915(dev);
2571 int ret;
2572
2573 if (!dev_priv->guc.log.vma)
2574 return -EINVAL;
2575
2576 ret = mutex_lock_interruptible(&dev->struct_mutex);
2577 if (ret)
2578 return ret;
2579
2580 intel_runtime_pm_get(dev_priv);
2581 ret = i915_guc_log_control(dev_priv, val);
2582 intel_runtime_pm_put(dev_priv);
2583
2584 mutex_unlock(&dev->struct_mutex);
2585 return ret;
2586}
2587
2588DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2589 i915_guc_log_control_get, i915_guc_log_control_set,
2590 "%lld\n");
2591
Chris Wilsonb86bef202017-01-16 13:06:21 +00002592static const char *psr2_live_status(u32 val)
2593{
2594 static const char * const live_status[] = {
2595 "IDLE",
2596 "CAPTURE",
2597 "CAPTURE_FS",
2598 "SLEEP",
2599 "BUFON_FW",
2600 "ML_UP",
2601 "SU_STANDBY",
2602 "FAST_SLEEP",
2603 "DEEP_SLEEP",
2604 "BUF_ON",
2605 "TG_ON"
2606 };
2607
2608 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2609 if (val < ARRAY_SIZE(live_status))
2610 return live_status[val];
2611
2612 return "unknown";
2613}
2614
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002615static int i915_edp_psr_status(struct seq_file *m, void *data)
2616{
David Weinehall36cdd012016-08-22 13:59:31 +03002617 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002618 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002619 u32 stat[3];
2620 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002621 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002622
David Weinehall36cdd012016-08-22 13:59:31 +03002623 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002624 seq_puts(m, "PSR not supported\n");
2625 return 0;
2626 }
2627
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002628 intel_runtime_pm_get(dev_priv);
2629
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002630 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002631 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2632 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002633 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002634 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002635 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2636 dev_priv->psr.busy_frontbuffer_bits);
2637 seq_printf(m, "Re-enable work scheduled: %s\n",
2638 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002639
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302640 if (HAS_DDI(dev_priv)) {
2641 if (dev_priv->psr.psr2_support)
2642 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2643 else
2644 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2645 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002646 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002647 enum transcoder cpu_transcoder =
2648 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2649 enum intel_display_power_domain power_domain;
2650
2651 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2652 if (!intel_display_power_get_if_enabled(dev_priv,
2653 power_domain))
2654 continue;
2655
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002656 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2657 VLV_EDP_PSR_CURR_STATE_MASK;
2658 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2659 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2660 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002661
2662 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002663 }
2664 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002665
2666 seq_printf(m, "Main link in standby mode: %s\n",
2667 yesno(dev_priv->psr.link_standby));
2668
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002669 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002670
David Weinehall36cdd012016-08-22 13:59:31 +03002671 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002672 for_each_pipe(dev_priv, pipe) {
2673 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2674 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2675 seq_printf(m, " pipe %c", pipe_name(pipe));
2676 }
2677 seq_puts(m, "\n");
2678
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002679 /*
2680 * VLV/CHV PSR has no kind of performance counter
2681 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2682 */
David Weinehall36cdd012016-08-22 13:59:31 +03002683 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002684 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002685 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002686
2687 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2688 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302689 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002690 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302691
Chris Wilsonb86bef202017-01-16 13:06:21 +00002692 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2693 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302694 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002695 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002696
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002697 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002698 return 0;
2699}
2700
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002701static int i915_sink_crc(struct seq_file *m, void *data)
2702{
David Weinehall36cdd012016-08-22 13:59:31 +03002703 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2704 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002705 struct intel_connector *connector;
2706 struct intel_dp *intel_dp = NULL;
2707 int ret;
2708 u8 crc[6];
2709
2710 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002711 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002712 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002713
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002714 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002715 continue;
2716
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002717 crtc = connector->base.state->crtc;
2718 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002719 continue;
2720
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002721 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002722 continue;
2723
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002724 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002725
2726 ret = intel_dp_sink_crc(intel_dp, crc);
2727 if (ret)
2728 goto out;
2729
2730 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2731 crc[0], crc[1], crc[2],
2732 crc[3], crc[4], crc[5]);
2733 goto out;
2734 }
2735 ret = -ENODEV;
2736out:
2737 drm_modeset_unlock_all(dev);
2738 return ret;
2739}
2740
Jesse Barnesec013e72013-08-20 10:29:23 +01002741static int i915_energy_uJ(struct seq_file *m, void *data)
2742{
David Weinehall36cdd012016-08-22 13:59:31 +03002743 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002744 u64 power;
2745 u32 units;
2746
David Weinehall36cdd012016-08-22 13:59:31 +03002747 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002748 return -ENODEV;
2749
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002750 intel_runtime_pm_get(dev_priv);
2751
Jesse Barnesec013e72013-08-20 10:29:23 +01002752 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2753 power = (power & 0x1f00) >> 8;
2754 units = 1000000 / (1 << power); /* convert to uJ */
2755 power = I915_READ(MCH_SECP_NRG_STTS);
2756 power *= units;
2757
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002758 intel_runtime_pm_put(dev_priv);
2759
Jesse Barnesec013e72013-08-20 10:29:23 +01002760 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002761
2762 return 0;
2763}
2764
Damien Lespiau6455c872015-06-04 18:23:57 +01002765static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002766{
David Weinehall36cdd012016-08-22 13:59:31 +03002767 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002768 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002769
Chris Wilsona156e642016-04-03 14:14:21 +01002770 if (!HAS_RUNTIME_PM(dev_priv))
2771 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002772
Chris Wilson67d97da2016-07-04 08:08:31 +01002773 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002774 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002775 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002776#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002777 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002778 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002779#else
2780 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2781#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002782 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002783 pci_power_name(pdev->current_state),
2784 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002785
Jesse Barnesec013e72013-08-20 10:29:23 +01002786 return 0;
2787}
2788
Imre Deak1da51582013-11-25 17:15:35 +02002789static int i915_power_domain_info(struct seq_file *m, void *unused)
2790{
David Weinehall36cdd012016-08-22 13:59:31 +03002791 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002792 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2793 int i;
2794
2795 mutex_lock(&power_domains->lock);
2796
2797 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2798 for (i = 0; i < power_domains->power_well_count; i++) {
2799 struct i915_power_well *power_well;
2800 enum intel_display_power_domain power_domain;
2801
2802 power_well = &power_domains->power_wells[i];
2803 seq_printf(m, "%-25s %d\n", power_well->name,
2804 power_well->count);
2805
2806 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2807 power_domain++) {
2808 if (!(BIT(power_domain) & power_well->domains))
2809 continue;
2810
2811 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002812 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002813 power_domains->domain_use_count[power_domain]);
2814 }
2815 }
2816
2817 mutex_unlock(&power_domains->lock);
2818
2819 return 0;
2820}
2821
Damien Lespiaub7cec662015-10-27 14:47:01 +02002822static int i915_dmc_info(struct seq_file *m, void *unused)
2823{
David Weinehall36cdd012016-08-22 13:59:31 +03002824 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002825 struct intel_csr *csr;
2826
David Weinehall36cdd012016-08-22 13:59:31 +03002827 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002828 seq_puts(m, "not supported\n");
2829 return 0;
2830 }
2831
2832 csr = &dev_priv->csr;
2833
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002834 intel_runtime_pm_get(dev_priv);
2835
Damien Lespiaub7cec662015-10-27 14:47:01 +02002836 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2837 seq_printf(m, "path: %s\n", csr->fw_path);
2838
2839 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002840 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002841
2842 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2843 CSR_VERSION_MINOR(csr->version));
2844
David Weinehall36cdd012016-08-22 13:59:31 +03002845 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002846 seq_printf(m, "DC3 -> DC5 count: %d\n",
2847 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2848 seq_printf(m, "DC5 -> DC6 count: %d\n",
2849 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002850 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002851 seq_printf(m, "DC3 -> DC5 count: %d\n",
2852 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002853 }
2854
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002855out:
2856 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2857 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2858 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2859
Damien Lespiau83372062015-10-30 17:53:32 +02002860 intel_runtime_pm_put(dev_priv);
2861
Damien Lespiaub7cec662015-10-27 14:47:01 +02002862 return 0;
2863}
2864
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002865static void intel_seq_print_mode(struct seq_file *m, int tabs,
2866 struct drm_display_mode *mode)
2867{
2868 int i;
2869
2870 for (i = 0; i < tabs; i++)
2871 seq_putc(m, '\t');
2872
2873 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",
2874 mode->base.id, mode->name,
2875 mode->vrefresh, mode->clock,
2876 mode->hdisplay, mode->hsync_start,
2877 mode->hsync_end, mode->htotal,
2878 mode->vdisplay, mode->vsync_start,
2879 mode->vsync_end, mode->vtotal,
2880 mode->type, mode->flags);
2881}
2882
2883static void intel_encoder_info(struct seq_file *m,
2884 struct intel_crtc *intel_crtc,
2885 struct intel_encoder *intel_encoder)
2886{
David Weinehall36cdd012016-08-22 13:59:31 +03002887 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2888 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002889 struct drm_crtc *crtc = &intel_crtc->base;
2890 struct intel_connector *intel_connector;
2891 struct drm_encoder *encoder;
2892
2893 encoder = &intel_encoder->base;
2894 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002895 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002896 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2897 struct drm_connector *connector = &intel_connector->base;
2898 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2899 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002900 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002901 drm_get_connector_status_name(connector->status));
2902 if (connector->status == connector_status_connected) {
2903 struct drm_display_mode *mode = &crtc->mode;
2904 seq_printf(m, ", mode:\n");
2905 intel_seq_print_mode(m, 2, mode);
2906 } else {
2907 seq_putc(m, '\n');
2908 }
2909 }
2910}
2911
2912static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2913{
David Weinehall36cdd012016-08-22 13:59:31 +03002914 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2915 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002916 struct drm_crtc *crtc = &intel_crtc->base;
2917 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002918 struct drm_plane_state *plane_state = crtc->primary->state;
2919 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002920
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002921 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002922 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002923 fb->base.id, plane_state->src_x >> 16,
2924 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002925 else
2926 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002927 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2928 intel_encoder_info(m, intel_crtc, intel_encoder);
2929}
2930
2931static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2932{
2933 struct drm_display_mode *mode = panel->fixed_mode;
2934
2935 seq_printf(m, "\tfixed mode:\n");
2936 intel_seq_print_mode(m, 2, mode);
2937}
2938
2939static void intel_dp_info(struct seq_file *m,
2940 struct intel_connector *intel_connector)
2941{
2942 struct intel_encoder *intel_encoder = intel_connector->encoder;
2943 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2944
2945 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002946 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002947 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002948 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002949
2950 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2951 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002952}
2953
Libin Yang9a148a92016-11-28 20:07:05 +08002954static void intel_dp_mst_info(struct seq_file *m,
2955 struct intel_connector *intel_connector)
2956{
2957 struct intel_encoder *intel_encoder = intel_connector->encoder;
2958 struct intel_dp_mst_encoder *intel_mst =
2959 enc_to_mst(&intel_encoder->base);
2960 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2961 struct intel_dp *intel_dp = &intel_dig_port->dp;
2962 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2963 intel_connector->port);
2964
2965 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2966}
2967
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002968static void intel_hdmi_info(struct seq_file *m,
2969 struct intel_connector *intel_connector)
2970{
2971 struct intel_encoder *intel_encoder = intel_connector->encoder;
2972 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2973
Jani Nikula742f4912015-09-03 11:16:09 +03002974 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002975}
2976
2977static void intel_lvds_info(struct seq_file *m,
2978 struct intel_connector *intel_connector)
2979{
2980 intel_panel_info(m, &intel_connector->panel);
2981}
2982
2983static void intel_connector_info(struct seq_file *m,
2984 struct drm_connector *connector)
2985{
2986 struct intel_connector *intel_connector = to_intel_connector(connector);
2987 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002988 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002989
2990 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002991 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002992 drm_get_connector_status_name(connector->status));
2993 if (connector->status == connector_status_connected) {
2994 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2995 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2996 connector->display_info.width_mm,
2997 connector->display_info.height_mm);
2998 seq_printf(m, "\tsubpixel order: %s\n",
2999 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3000 seq_printf(m, "\tCEA rev: %d\n",
3001 connector->display_info.cea_rev);
3002 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003003
3004 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3005 return;
3006
3007 switch (connector->connector_type) {
3008 case DRM_MODE_CONNECTOR_DisplayPort:
3009 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003010 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3011 intel_dp_mst_info(m, intel_connector);
3012 else
3013 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003014 break;
3015 case DRM_MODE_CONNECTOR_LVDS:
3016 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003017 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003018 break;
3019 case DRM_MODE_CONNECTOR_HDMIA:
3020 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3021 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3022 intel_hdmi_info(m, intel_connector);
3023 break;
3024 default:
3025 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003026 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003027
Jesse Barnesf103fc72014-02-20 12:39:57 -08003028 seq_printf(m, "\tmodes:\n");
3029 list_for_each_entry(mode, &connector->modes, head)
3030 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003031}
3032
David Weinehall36cdd012016-08-22 13:59:31 +03003033static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00003034{
Chris Wilson065f2ec2014-03-12 09:13:13 +00003035 u32 state;
3036
Jani Nikula2a307c22016-11-30 17:43:04 +02003037 if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003038 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003039 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003040 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003041
3042 return state;
3043}
3044
David Weinehall36cdd012016-08-22 13:59:31 +03003045static bool cursor_position(struct drm_i915_private *dev_priv,
3046 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00003047{
Chris Wilson065f2ec2014-03-12 09:13:13 +00003048 u32 pos;
3049
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003050 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003051
3052 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3053 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3054 *x = -*x;
3055
3056 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3057 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3058 *y = -*y;
3059
David Weinehall36cdd012016-08-22 13:59:31 +03003060 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003061}
3062
Robert Fekete3abc4e02015-10-27 16:58:32 +01003063static const char *plane_type(enum drm_plane_type type)
3064{
3065 switch (type) {
3066 case DRM_PLANE_TYPE_OVERLAY:
3067 return "OVL";
3068 case DRM_PLANE_TYPE_PRIMARY:
3069 return "PRI";
3070 case DRM_PLANE_TYPE_CURSOR:
3071 return "CUR";
3072 /*
3073 * Deliberately omitting default: to generate compiler warnings
3074 * when a new drm_plane_type gets added.
3075 */
3076 }
3077
3078 return "unknown";
3079}
3080
3081static const char *plane_rotation(unsigned int rotation)
3082{
3083 static char buf[48];
3084 /*
3085 * According to doc only one DRM_ROTATE_ is allowed but this
3086 * will print them all to visualize if the values are misused
3087 */
3088 snprintf(buf, sizeof(buf),
3089 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003090 (rotation & DRM_ROTATE_0) ? "0 " : "",
3091 (rotation & DRM_ROTATE_90) ? "90 " : "",
3092 (rotation & DRM_ROTATE_180) ? "180 " : "",
3093 (rotation & DRM_ROTATE_270) ? "270 " : "",
3094 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3095 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003096 rotation);
3097
3098 return buf;
3099}
3100
3101static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3102{
David Weinehall36cdd012016-08-22 13:59:31 +03003103 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3104 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003105 struct intel_plane *intel_plane;
3106
3107 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3108 struct drm_plane_state *state;
3109 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003110 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003111
3112 if (!plane->state) {
3113 seq_puts(m, "plane->state is NULL!\n");
3114 continue;
3115 }
3116
3117 state = plane->state;
3118
Eric Engestrom90844f02016-08-15 01:02:38 +01003119 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003120 drm_get_format_name(state->fb->format->format,
3121 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003122 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003123 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003124 }
3125
Robert Fekete3abc4e02015-10-27 16:58:32 +01003126 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",
3127 plane->base.id,
3128 plane_type(intel_plane->base.type),
3129 state->crtc_x, state->crtc_y,
3130 state->crtc_w, state->crtc_h,
3131 (state->src_x >> 16),
3132 ((state->src_x & 0xffff) * 15625) >> 10,
3133 (state->src_y >> 16),
3134 ((state->src_y & 0xffff) * 15625) >> 10,
3135 (state->src_w >> 16),
3136 ((state->src_w & 0xffff) * 15625) >> 10,
3137 (state->src_h >> 16),
3138 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003139 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003140 plane_rotation(state->rotation));
3141 }
3142}
3143
3144static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3145{
3146 struct intel_crtc_state *pipe_config;
3147 int num_scalers = intel_crtc->num_scalers;
3148 int i;
3149
3150 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3151
3152 /* Not all platformas have a scaler */
3153 if (num_scalers) {
3154 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3155 num_scalers,
3156 pipe_config->scaler_state.scaler_users,
3157 pipe_config->scaler_state.scaler_id);
3158
A.Sunil Kamath58415912016-11-20 23:20:26 +05303159 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003160 struct intel_scaler *sc =
3161 &pipe_config->scaler_state.scalers[i];
3162
3163 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3164 i, yesno(sc->in_use), sc->mode);
3165 }
3166 seq_puts(m, "\n");
3167 } else {
3168 seq_puts(m, "\tNo scalers available on this platform\n");
3169 }
3170}
3171
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003172static int i915_display_info(struct seq_file *m, void *unused)
3173{
David Weinehall36cdd012016-08-22 13:59:31 +03003174 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3175 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003176 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003177 struct drm_connector *connector;
3178
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003179 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003180 drm_modeset_lock_all(dev);
3181 seq_printf(m, "CRTC info\n");
3182 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003183 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003184 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003185 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003186 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003187
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003188 pipe_config = to_intel_crtc_state(crtc->base.state);
3189
Robert Fekete3abc4e02015-10-27 16:58:32 +01003190 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003191 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003192 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003193 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3194 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3195
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003196 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003197 intel_crtc_info(m, crtc);
3198
David Weinehall36cdd012016-08-22 13:59:31 +03003199 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003200 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 +03003201 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003202 x, y, crtc->base.cursor->state->crtc_w,
3203 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003204 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003205 intel_scaler_info(m, crtc);
3206 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003207 }
Daniel Vettercace8412014-05-22 17:56:31 +02003208
3209 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3210 yesno(!crtc->cpu_fifo_underrun_disabled),
3211 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003212 }
3213
3214 seq_printf(m, "\n");
3215 seq_printf(m, "Connector info\n");
3216 seq_printf(m, "--------------\n");
3217 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3218 intel_connector_info(m, connector);
3219 }
3220 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003221 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003222
3223 return 0;
3224}
3225
Chris Wilson1b365952016-10-04 21:11:31 +01003226static int i915_engine_info(struct seq_file *m, void *unused)
3227{
3228 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3229 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303230 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003231
Chris Wilson9c870d02016-10-24 13:42:15 +01003232 intel_runtime_pm_get(dev_priv);
3233
Akash Goel3b3f1652016-10-13 22:44:48 +05303234 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003235 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3236 struct drm_i915_gem_request *rq;
3237 struct rb_node *rb;
3238 u64 addr;
3239
3240 seq_printf(m, "%s\n", engine->name);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02003241 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms]\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003242 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003243 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003244 engine->hangcheck.seqno,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02003245 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
Chris Wilson1b365952016-10-04 21:11:31 +01003246
3247 rcu_read_lock();
3248
3249 seq_printf(m, "\tRequests:\n");
3250
Chris Wilson73cb9702016-10-28 13:58:46 +01003251 rq = list_first_entry(&engine->timeline->requests,
3252 struct drm_i915_gem_request, link);
3253 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003254 print_request(m, rq, "\t\tfirst ");
3255
Chris Wilson73cb9702016-10-28 13:58:46 +01003256 rq = list_last_entry(&engine->timeline->requests,
3257 struct drm_i915_gem_request, link);
3258 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003259 print_request(m, rq, "\t\tlast ");
3260
3261 rq = i915_gem_find_active_request(engine);
3262 if (rq) {
3263 print_request(m, rq, "\t\tactive ");
3264 seq_printf(m,
3265 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3266 rq->head, rq->postfix, rq->tail,
3267 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3268 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3269 }
3270
3271 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3272 I915_READ(RING_START(engine->mmio_base)),
3273 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3274 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3275 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3276 rq ? rq->ring->head : 0);
3277 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3278 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3279 rq ? rq->ring->tail : 0);
3280 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3281 I915_READ(RING_CTL(engine->mmio_base)),
3282 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3283
3284 rcu_read_unlock();
3285
3286 addr = intel_engine_get_active_head(engine);
3287 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3288 upper_32_bits(addr), lower_32_bits(addr));
3289 addr = intel_engine_get_last_batch_head(engine);
3290 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3291 upper_32_bits(addr), lower_32_bits(addr));
3292
3293 if (i915.enable_execlists) {
3294 u32 ptr, read, write;
Chris Wilson20311bd2016-11-14 20:41:03 +00003295 struct rb_node *rb;
Chris Wilson1b365952016-10-04 21:11:31 +01003296
3297 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3298 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3299 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3300
3301 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3302 read = GEN8_CSB_READ_PTR(ptr);
3303 write = GEN8_CSB_WRITE_PTR(ptr);
3304 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3305 read, write);
3306 if (read >= GEN8_CSB_ENTRIES)
3307 read = 0;
3308 if (write >= GEN8_CSB_ENTRIES)
3309 write = 0;
3310 if (read > write)
3311 write += GEN8_CSB_ENTRIES;
3312 while (read < write) {
3313 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3314
3315 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3316 idx,
3317 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3318 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3319 }
3320
3321 rcu_read_lock();
3322 rq = READ_ONCE(engine->execlist_port[0].request);
3323 if (rq)
3324 print_request(m, rq, "\t\tELSP[0] ");
3325 else
3326 seq_printf(m, "\t\tELSP[0] idle\n");
3327 rq = READ_ONCE(engine->execlist_port[1].request);
3328 if (rq)
3329 print_request(m, rq, "\t\tELSP[1] ");
3330 else
3331 seq_printf(m, "\t\tELSP[1] idle\n");
3332 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003333
Chris Wilson663f71e2016-11-14 20:41:00 +00003334 spin_lock_irq(&engine->timeline->lock);
Chris Wilson20311bd2016-11-14 20:41:03 +00003335 for (rb = engine->execlist_first; rb; rb = rb_next(rb)) {
3336 rq = rb_entry(rb, typeof(*rq), priotree.node);
Chris Wilsonc8247c02016-10-27 01:03:43 +01003337 print_request(m, rq, "\t\tQ ");
3338 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003339 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003340 } else if (INTEL_GEN(dev_priv) > 6) {
3341 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3342 I915_READ(RING_PP_DIR_BASE(engine)));
3343 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3344 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3345 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3346 I915_READ(RING_PP_DIR_DCLV(engine)));
3347 }
3348
Chris Wilsonf6168e32016-10-28 13:58:55 +01003349 spin_lock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003350 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08003351 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson1b365952016-10-04 21:11:31 +01003352
3353 seq_printf(m, "\t%s [%d] waiting for %x\n",
3354 w->tsk->comm, w->tsk->pid, w->seqno);
3355 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01003356 spin_unlock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003357
3358 seq_puts(m, "\n");
3359 }
3360
Chris Wilson9c870d02016-10-24 13:42:15 +01003361 intel_runtime_pm_put(dev_priv);
3362
Chris Wilson1b365952016-10-04 21:11:31 +01003363 return 0;
3364}
3365
Ben Widawskye04934c2014-06-30 09:53:42 -07003366static int i915_semaphore_status(struct seq_file *m, void *unused)
3367{
David Weinehall36cdd012016-08-22 13:59:31 +03003368 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3369 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003370 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003371 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003372 enum intel_engine_id id;
3373 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003374
Chris Wilson39df9192016-07-20 13:31:57 +01003375 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003376 seq_puts(m, "Semaphores are disabled\n");
3377 return 0;
3378 }
3379
3380 ret = mutex_lock_interruptible(&dev->struct_mutex);
3381 if (ret)
3382 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003383 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003384
David Weinehall36cdd012016-08-22 13:59:31 +03003385 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003386 struct page *page;
3387 uint64_t *seqno;
3388
Chris Wilson51d545d2016-08-15 10:49:02 +01003389 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003390
3391 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303392 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003393 uint64_t offset;
3394
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003395 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003396
3397 seq_puts(m, " Last signal:");
3398 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003399 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003400 seq_printf(m, "0x%08llx (0x%02llx) ",
3401 seqno[offset], offset * 8);
3402 }
3403 seq_putc(m, '\n');
3404
3405 seq_puts(m, " Last wait: ");
3406 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003407 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003408 seq_printf(m, "0x%08llx (0x%02llx) ",
3409 seqno[offset], offset * 8);
3410 }
3411 seq_putc(m, '\n');
3412
3413 }
3414 kunmap_atomic(seqno);
3415 } else {
3416 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303417 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003418 for (j = 0; j < num_rings; j++)
3419 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003420 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003421 seq_putc(m, '\n');
3422 }
3423
Paulo Zanoni03872062014-07-09 14:31:57 -03003424 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003425 mutex_unlock(&dev->struct_mutex);
3426 return 0;
3427}
3428
Daniel Vetter728e29d2014-06-25 22:01:53 +03003429static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3430{
David Weinehall36cdd012016-08-22 13:59:31 +03003431 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3432 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003433 int i;
3434
3435 drm_modeset_lock_all(dev);
3436 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3437 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3438
3439 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003440 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003441 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003442 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003443 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003444 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003445 pll->state.hw_state.dpll_md);
3446 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3447 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3448 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003449 }
3450 drm_modeset_unlock_all(dev);
3451
3452 return 0;
3453}
3454
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003455static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003456{
3457 int i;
3458 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003459 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003460 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3461 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003462 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003463 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003464
Arun Siluvery888b5992014-08-26 14:44:51 +01003465 ret = mutex_lock_interruptible(&dev->struct_mutex);
3466 if (ret)
3467 return ret;
3468
3469 intel_runtime_pm_get(dev_priv);
3470
Arun Siluvery33136b02016-01-21 21:43:47 +00003471 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303472 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003473 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003474 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003475 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003476 i915_reg_t addr;
3477 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003478 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003479
Arun Siluvery33136b02016-01-21 21:43:47 +00003480 addr = workarounds->reg[i].addr;
3481 mask = workarounds->reg[i].mask;
3482 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003483 read = I915_READ(addr);
3484 ok = (value & mask) == (read & mask);
3485 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 +02003486 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003487 }
3488
3489 intel_runtime_pm_put(dev_priv);
3490 mutex_unlock(&dev->struct_mutex);
3491
3492 return 0;
3493}
3494
Damien Lespiauc5511e42014-11-04 17:06:51 +00003495static int i915_ddb_info(struct seq_file *m, void *unused)
3496{
David Weinehall36cdd012016-08-22 13:59:31 +03003497 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3498 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003499 struct skl_ddb_allocation *ddb;
3500 struct skl_ddb_entry *entry;
3501 enum pipe pipe;
3502 int plane;
3503
David Weinehall36cdd012016-08-22 13:59:31 +03003504 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003505 return 0;
3506
Damien Lespiauc5511e42014-11-04 17:06:51 +00003507 drm_modeset_lock_all(dev);
3508
3509 ddb = &dev_priv->wm.skl_hw.ddb;
3510
3511 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3512
3513 for_each_pipe(dev_priv, pipe) {
3514 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3515
Matt Roper8b364b42016-10-26 15:51:28 -07003516 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003517 entry = &ddb->plane[pipe][plane];
3518 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3519 entry->start, entry->end,
3520 skl_ddb_entry_size(entry));
3521 }
3522
Matt Roper4969d332015-09-24 15:53:10 -07003523 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003524 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3525 entry->end, skl_ddb_entry_size(entry));
3526 }
3527
3528 drm_modeset_unlock_all(dev);
3529
3530 return 0;
3531}
3532
Vandana Kannana54746e2015-03-03 20:53:10 +05303533static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003534 struct drm_device *dev,
3535 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303536{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003537 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303538 struct i915_drrs *drrs = &dev_priv->drrs;
3539 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003540 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303541
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003542 drm_for_each_connector(connector, dev) {
3543 if (connector->state->crtc != &intel_crtc->base)
3544 continue;
3545
3546 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303547 }
3548
3549 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3550 seq_puts(m, "\tVBT: DRRS_type: Static");
3551 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3552 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3553 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3554 seq_puts(m, "\tVBT: DRRS_type: None");
3555 else
3556 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3557
3558 seq_puts(m, "\n\n");
3559
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003560 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303561 struct intel_panel *panel;
3562
3563 mutex_lock(&drrs->mutex);
3564 /* DRRS Supported */
3565 seq_puts(m, "\tDRRS Supported: Yes\n");
3566
3567 /* disable_drrs() will make drrs->dp NULL */
3568 if (!drrs->dp) {
3569 seq_puts(m, "Idleness DRRS: Disabled");
3570 mutex_unlock(&drrs->mutex);
3571 return;
3572 }
3573
3574 panel = &drrs->dp->attached_connector->panel;
3575 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3576 drrs->busy_frontbuffer_bits);
3577
3578 seq_puts(m, "\n\t\t");
3579 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3580 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3581 vrefresh = panel->fixed_mode->vrefresh;
3582 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3583 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3584 vrefresh = panel->downclock_mode->vrefresh;
3585 } else {
3586 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3587 drrs->refresh_rate_type);
3588 mutex_unlock(&drrs->mutex);
3589 return;
3590 }
3591 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3592
3593 seq_puts(m, "\n\t\t");
3594 mutex_unlock(&drrs->mutex);
3595 } else {
3596 /* DRRS not supported. Print the VBT parameter*/
3597 seq_puts(m, "\tDRRS Supported : No");
3598 }
3599 seq_puts(m, "\n");
3600}
3601
3602static int i915_drrs_status(struct seq_file *m, void *unused)
3603{
David Weinehall36cdd012016-08-22 13:59:31 +03003604 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3605 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303606 struct intel_crtc *intel_crtc;
3607 int active_crtc_cnt = 0;
3608
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003609 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303610 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003611 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303612 active_crtc_cnt++;
3613 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3614
3615 drrs_status_per_crtc(m, dev, intel_crtc);
3616 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303617 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003618 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303619
3620 if (!active_crtc_cnt)
3621 seq_puts(m, "No active crtc found\n");
3622
3623 return 0;
3624}
3625
Dave Airlie11bed952014-05-12 15:22:27 +10003626static int i915_dp_mst_info(struct seq_file *m, void *unused)
3627{
David Weinehall36cdd012016-08-22 13:59:31 +03003628 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3629 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003630 struct intel_encoder *intel_encoder;
3631 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003632 struct drm_connector *connector;
3633
Dave Airlie11bed952014-05-12 15:22:27 +10003634 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003635 drm_for_each_connector(connector, dev) {
3636 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003637 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003638
3639 intel_encoder = intel_attached_encoder(connector);
3640 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3641 continue;
3642
3643 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003644 if (!intel_dig_port->dp.can_mst)
3645 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003646
Jim Bride40ae80c2016-04-14 10:18:37 -07003647 seq_printf(m, "MST Source Port %c\n",
3648 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003649 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3650 }
3651 drm_modeset_unlock_all(dev);
3652 return 0;
3653}
3654
Todd Previteeb3394fa2015-04-18 00:04:19 -07003655static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003656 const char __user *ubuf,
3657 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003658{
3659 char *input_buffer;
3660 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003661 struct drm_device *dev;
3662 struct drm_connector *connector;
3663 struct list_head *connector_list;
3664 struct intel_dp *intel_dp;
3665 int val = 0;
3666
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303667 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003668
Todd Previteeb3394fa2015-04-18 00:04:19 -07003669 connector_list = &dev->mode_config.connector_list;
3670
3671 if (len == 0)
3672 return 0;
3673
3674 input_buffer = kmalloc(len + 1, GFP_KERNEL);
3675 if (!input_buffer)
3676 return -ENOMEM;
3677
3678 if (copy_from_user(input_buffer, ubuf, len)) {
3679 status = -EFAULT;
3680 goto out;
3681 }
3682
3683 input_buffer[len] = '\0';
3684 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3685
3686 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003687 if (connector->connector_type !=
3688 DRM_MODE_CONNECTOR_DisplayPort)
3689 continue;
3690
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05303691 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07003692 connector->encoder != NULL) {
3693 intel_dp = enc_to_intel_dp(connector->encoder);
3694 status = kstrtoint(input_buffer, 10, &val);
3695 if (status < 0)
3696 goto out;
3697 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3698 /* To prevent erroneous activation of the compliance
3699 * testing code, only accept an actual value of 1 here
3700 */
3701 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003702 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003703 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003704 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003705 }
3706 }
3707out:
3708 kfree(input_buffer);
3709 if (status < 0)
3710 return status;
3711
3712 *offp += len;
3713 return len;
3714}
3715
3716static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3717{
3718 struct drm_device *dev = m->private;
3719 struct drm_connector *connector;
3720 struct list_head *connector_list = &dev->mode_config.connector_list;
3721 struct intel_dp *intel_dp;
3722
Todd Previteeb3394fa2015-04-18 00:04:19 -07003723 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003724 if (connector->connector_type !=
3725 DRM_MODE_CONNECTOR_DisplayPort)
3726 continue;
3727
3728 if (connector->status == connector_status_connected &&
3729 connector->encoder != NULL) {
3730 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003731 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003732 seq_puts(m, "1");
3733 else
3734 seq_puts(m, "0");
3735 } else
3736 seq_puts(m, "0");
3737 }
3738
3739 return 0;
3740}
3741
3742static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003743 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003744{
David Weinehall36cdd012016-08-22 13:59:31 +03003745 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003746
David Weinehall36cdd012016-08-22 13:59:31 +03003747 return single_open(file, i915_displayport_test_active_show,
3748 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003749}
3750
3751static const struct file_operations i915_displayport_test_active_fops = {
3752 .owner = THIS_MODULE,
3753 .open = i915_displayport_test_active_open,
3754 .read = seq_read,
3755 .llseek = seq_lseek,
3756 .release = single_release,
3757 .write = i915_displayport_test_active_write
3758};
3759
3760static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3761{
3762 struct drm_device *dev = m->private;
3763 struct drm_connector *connector;
3764 struct list_head *connector_list = &dev->mode_config.connector_list;
3765 struct intel_dp *intel_dp;
3766
Todd Previteeb3394fa2015-04-18 00:04:19 -07003767 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003768 if (connector->connector_type !=
3769 DRM_MODE_CONNECTOR_DisplayPort)
3770 continue;
3771
3772 if (connector->status == connector_status_connected &&
3773 connector->encoder != NULL) {
3774 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003775 seq_printf(m, "%lx", intel_dp->compliance.test_data.edid);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003776 } else
3777 seq_puts(m, "0");
3778 }
3779
3780 return 0;
3781}
3782static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003783 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003784{
David Weinehall36cdd012016-08-22 13:59:31 +03003785 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003786
David Weinehall36cdd012016-08-22 13:59:31 +03003787 return single_open(file, i915_displayport_test_data_show,
3788 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003789}
3790
3791static const struct file_operations i915_displayport_test_data_fops = {
3792 .owner = THIS_MODULE,
3793 .open = i915_displayport_test_data_open,
3794 .read = seq_read,
3795 .llseek = seq_lseek,
3796 .release = single_release
3797};
3798
3799static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3800{
3801 struct drm_device *dev = m->private;
3802 struct drm_connector *connector;
3803 struct list_head *connector_list = &dev->mode_config.connector_list;
3804 struct intel_dp *intel_dp;
3805
Todd Previteeb3394fa2015-04-18 00:04:19 -07003806 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07003807 if (connector->connector_type !=
3808 DRM_MODE_CONNECTOR_DisplayPort)
3809 continue;
3810
3811 if (connector->status == connector_status_connected &&
3812 connector->encoder != NULL) {
3813 intel_dp = enc_to_intel_dp(connector->encoder);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003814 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003815 } else
3816 seq_puts(m, "0");
3817 }
3818
3819 return 0;
3820}
3821
3822static int i915_displayport_test_type_open(struct inode *inode,
3823 struct file *file)
3824{
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_type_show,
3828 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003829}
3830
3831static const struct file_operations i915_displayport_test_type_fops = {
3832 .owner = THIS_MODULE,
3833 .open = i915_displayport_test_type_open,
3834 .read = seq_read,
3835 .llseek = seq_lseek,
3836 .release = single_release
3837};
3838
Damien Lespiau97e94b22014-11-04 17:06:50 +00003839static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003840{
David Weinehall36cdd012016-08-22 13:59:31 +03003841 struct drm_i915_private *dev_priv = m->private;
3842 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003843 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003844 int num_levels;
3845
David Weinehall36cdd012016-08-22 13:59:31 +03003846 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003847 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003848 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003849 num_levels = 1;
3850 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003851 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003852
3853 drm_modeset_lock_all(dev);
3854
3855 for (level = 0; level < num_levels; level++) {
3856 unsigned int latency = wm[level];
3857
Damien Lespiau97e94b22014-11-04 17:06:50 +00003858 /*
3859 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003860 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003861 */
David Weinehall36cdd012016-08-22 13:59:31 +03003862 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
3863 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003864 latency *= 10;
3865 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003866 latency *= 5;
3867
3868 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003869 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003870 }
3871
3872 drm_modeset_unlock_all(dev);
3873}
3874
3875static int pri_wm_latency_show(struct seq_file *m, void *data)
3876{
David Weinehall36cdd012016-08-22 13:59:31 +03003877 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003878 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003879
David Weinehall36cdd012016-08-22 13:59:31 +03003880 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003881 latencies = dev_priv->wm.skl_latency;
3882 else
David Weinehall36cdd012016-08-22 13:59:31 +03003883 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003884
3885 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003886
3887 return 0;
3888}
3889
3890static int spr_wm_latency_show(struct seq_file *m, void *data)
3891{
David Weinehall36cdd012016-08-22 13:59:31 +03003892 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003893 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003894
David Weinehall36cdd012016-08-22 13:59:31 +03003895 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003896 latencies = dev_priv->wm.skl_latency;
3897 else
David Weinehall36cdd012016-08-22 13:59:31 +03003898 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003899
3900 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003901
3902 return 0;
3903}
3904
3905static int cur_wm_latency_show(struct seq_file *m, void *data)
3906{
David Weinehall36cdd012016-08-22 13:59:31 +03003907 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003908 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003909
David Weinehall36cdd012016-08-22 13:59:31 +03003910 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003911 latencies = dev_priv->wm.skl_latency;
3912 else
David Weinehall36cdd012016-08-22 13:59:31 +03003913 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003914
3915 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003916
3917 return 0;
3918}
3919
3920static int pri_wm_latency_open(struct inode *inode, struct file *file)
3921{
David Weinehall36cdd012016-08-22 13:59:31 +03003922 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003923
David Weinehall36cdd012016-08-22 13:59:31 +03003924 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003925 return -ENODEV;
3926
David Weinehall36cdd012016-08-22 13:59:31 +03003927 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003928}
3929
3930static int spr_wm_latency_open(struct inode *inode, struct file *file)
3931{
David Weinehall36cdd012016-08-22 13:59:31 +03003932 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003933
David Weinehall36cdd012016-08-22 13:59:31 +03003934 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003935 return -ENODEV;
3936
David Weinehall36cdd012016-08-22 13:59:31 +03003937 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003938}
3939
3940static int cur_wm_latency_open(struct inode *inode, struct file *file)
3941{
David Weinehall36cdd012016-08-22 13:59:31 +03003942 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003943
David Weinehall36cdd012016-08-22 13:59:31 +03003944 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003945 return -ENODEV;
3946
David Weinehall36cdd012016-08-22 13:59:31 +03003947 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003948}
3949
3950static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003951 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003952{
3953 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003954 struct drm_i915_private *dev_priv = m->private;
3955 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003956 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03003957 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003958 int level;
3959 int ret;
3960 char tmp[32];
3961
David Weinehall36cdd012016-08-22 13:59:31 +03003962 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003963 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003964 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003965 num_levels = 1;
3966 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003967 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003968
Ville Syrjälä369a1342014-01-22 14:36:08 +02003969 if (len >= sizeof(tmp))
3970 return -EINVAL;
3971
3972 if (copy_from_user(tmp, ubuf, len))
3973 return -EFAULT;
3974
3975 tmp[len] = '\0';
3976
Damien Lespiau97e94b22014-11-04 17:06:50 +00003977 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3978 &new[0], &new[1], &new[2], &new[3],
3979 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003980 if (ret != num_levels)
3981 return -EINVAL;
3982
3983 drm_modeset_lock_all(dev);
3984
3985 for (level = 0; level < num_levels; level++)
3986 wm[level] = new[level];
3987
3988 drm_modeset_unlock_all(dev);
3989
3990 return len;
3991}
3992
3993
3994static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3995 size_t len, loff_t *offp)
3996{
3997 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003998 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003999 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004000
David Weinehall36cdd012016-08-22 13:59:31 +03004001 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004002 latencies = dev_priv->wm.skl_latency;
4003 else
David Weinehall36cdd012016-08-22 13:59:31 +03004004 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004005
4006 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004007}
4008
4009static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4010 size_t len, loff_t *offp)
4011{
4012 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004013 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004014 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004015
David Weinehall36cdd012016-08-22 13:59:31 +03004016 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004017 latencies = dev_priv->wm.skl_latency;
4018 else
David Weinehall36cdd012016-08-22 13:59:31 +03004019 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004020
4021 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004022}
4023
4024static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4025 size_t len, loff_t *offp)
4026{
4027 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004028 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004029 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004030
David Weinehall36cdd012016-08-22 13:59:31 +03004031 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004032 latencies = dev_priv->wm.skl_latency;
4033 else
David Weinehall36cdd012016-08-22 13:59:31 +03004034 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004035
4036 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004037}
4038
4039static const struct file_operations i915_pri_wm_latency_fops = {
4040 .owner = THIS_MODULE,
4041 .open = pri_wm_latency_open,
4042 .read = seq_read,
4043 .llseek = seq_lseek,
4044 .release = single_release,
4045 .write = pri_wm_latency_write
4046};
4047
4048static const struct file_operations i915_spr_wm_latency_fops = {
4049 .owner = THIS_MODULE,
4050 .open = spr_wm_latency_open,
4051 .read = seq_read,
4052 .llseek = seq_lseek,
4053 .release = single_release,
4054 .write = spr_wm_latency_write
4055};
4056
4057static const struct file_operations i915_cur_wm_latency_fops = {
4058 .owner = THIS_MODULE,
4059 .open = cur_wm_latency_open,
4060 .read = seq_read,
4061 .llseek = seq_lseek,
4062 .release = single_release,
4063 .write = cur_wm_latency_write
4064};
4065
Kees Cook647416f2013-03-10 14:10:06 -07004066static int
4067i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004068{
David Weinehall36cdd012016-08-22 13:59:31 +03004069 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004070
Chris Wilsond98c52c2016-04-13 17:35:05 +01004071 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004072
Kees Cook647416f2013-03-10 14:10:06 -07004073 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004074}
4075
Kees Cook647416f2013-03-10 14:10:06 -07004076static int
4077i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004078{
David Weinehall36cdd012016-08-22 13:59:31 +03004079 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004080
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004081 /*
4082 * There is no safeguard against this debugfs entry colliding
4083 * with the hangcheck calling same i915_handle_error() in
4084 * parallel, causing an explosion. For now we assume that the
4085 * test harness is responsible enough not to inject gpu hangs
4086 * while it is writing to 'i915_wedged'
4087 */
4088
Chris Wilsond98c52c2016-04-13 17:35:05 +01004089 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004090 return -EAGAIN;
4091
Chris Wilsonc0336662016-05-06 15:40:21 +01004092 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004093 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004094
Kees Cook647416f2013-03-10 14:10:06 -07004095 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004096}
4097
Kees Cook647416f2013-03-10 14:10:06 -07004098DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4099 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004100 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004101
Kees Cook647416f2013-03-10 14:10:06 -07004102static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004103i915_ring_missed_irq_get(void *data, u64 *val)
4104{
David Weinehall36cdd012016-08-22 13:59:31 +03004105 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004106
4107 *val = dev_priv->gpu_error.missed_irq_rings;
4108 return 0;
4109}
4110
4111static int
4112i915_ring_missed_irq_set(void *data, u64 val)
4113{
David Weinehall36cdd012016-08-22 13:59:31 +03004114 struct drm_i915_private *dev_priv = data;
4115 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004116 int ret;
4117
4118 /* Lock against concurrent debugfs callers */
4119 ret = mutex_lock_interruptible(&dev->struct_mutex);
4120 if (ret)
4121 return ret;
4122 dev_priv->gpu_error.missed_irq_rings = val;
4123 mutex_unlock(&dev->struct_mutex);
4124
4125 return 0;
4126}
4127
4128DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4129 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4130 "0x%08llx\n");
4131
4132static int
4133i915_ring_test_irq_get(void *data, u64 *val)
4134{
David Weinehall36cdd012016-08-22 13:59:31 +03004135 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004136
4137 *val = dev_priv->gpu_error.test_irq_rings;
4138
4139 return 0;
4140}
4141
4142static int
4143i915_ring_test_irq_set(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
Chris Wilson3a122c22016-06-17 14:35:05 +01004147 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004148 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004149 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004150
4151 return 0;
4152}
4153
4154DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4155 i915_ring_test_irq_get, i915_ring_test_irq_set,
4156 "0x%08llx\n");
4157
Chris Wilsondd624af2013-01-15 12:39:35 +00004158#define DROP_UNBOUND 0x1
4159#define DROP_BOUND 0x2
4160#define DROP_RETIRE 0x4
4161#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004162#define DROP_FREED 0x10
4163#define DROP_ALL (DROP_UNBOUND | \
4164 DROP_BOUND | \
4165 DROP_RETIRE | \
4166 DROP_ACTIVE | \
4167 DROP_FREED)
Kees Cook647416f2013-03-10 14:10:06 -07004168static int
4169i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004170{
Kees Cook647416f2013-03-10 14:10:06 -07004171 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004172
Kees Cook647416f2013-03-10 14:10:06 -07004173 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004174}
4175
Kees Cook647416f2013-03-10 14:10:06 -07004176static int
4177i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004178{
David Weinehall36cdd012016-08-22 13:59:31 +03004179 struct drm_i915_private *dev_priv = data;
4180 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004181 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004182
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004183 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004184
4185 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4186 * on ioctls on -EAGAIN. */
4187 ret = mutex_lock_interruptible(&dev->struct_mutex);
4188 if (ret)
4189 return ret;
4190
4191 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004192 ret = i915_gem_wait_for_idle(dev_priv,
4193 I915_WAIT_INTERRUPTIBLE |
4194 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004195 if (ret)
4196 goto unlock;
4197 }
4198
4199 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004200 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004201
Chris Wilson21ab4e72014-09-09 11:16:08 +01004202 if (val & DROP_BOUND)
4203 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004204
Chris Wilson21ab4e72014-09-09 11:16:08 +01004205 if (val & DROP_UNBOUND)
4206 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004207
4208unlock:
4209 mutex_unlock(&dev->struct_mutex);
4210
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004211 if (val & DROP_FREED) {
4212 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004213 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004214 }
4215
Kees Cook647416f2013-03-10 14:10:06 -07004216 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004217}
4218
Kees Cook647416f2013-03-10 14:10:06 -07004219DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4220 i915_drop_caches_get, i915_drop_caches_set,
4221 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004222
Kees Cook647416f2013-03-10 14:10:06 -07004223static int
4224i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004225{
David Weinehall36cdd012016-08-22 13:59:31 +03004226 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004227
David Weinehall36cdd012016-08-22 13:59:31 +03004228 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004229 return -ENODEV;
4230
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004231 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004232 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004233}
4234
Kees Cook647416f2013-03-10 14:10:06 -07004235static int
4236i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004237{
David Weinehall36cdd012016-08-22 13:59:31 +03004238 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304239 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004240 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004241
David Weinehall36cdd012016-08-22 13:59:31 +03004242 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004243 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004244
Kees Cook647416f2013-03-10 14:10:06 -07004245 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004246
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004247 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004248 if (ret)
4249 return ret;
4250
Jesse Barnes358733e2011-07-27 11:53:01 -07004251 /*
4252 * Turbo will still be enabled, but won't go above the set value.
4253 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304254 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004255
Akash Goelbc4d91f2015-02-26 16:09:47 +05304256 hw_max = dev_priv->rps.max_freq;
4257 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004258
Ben Widawskyb39fb292014-03-19 18:31:11 -07004259 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004260 mutex_unlock(&dev_priv->rps.hw_lock);
4261 return -EINVAL;
4262 }
4263
Ben Widawskyb39fb292014-03-19 18:31:11 -07004264 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004265
Chris Wilsondc979972016-05-10 14:10:04 +01004266 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004267
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004268 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004269
Kees Cook647416f2013-03-10 14:10:06 -07004270 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004271}
4272
Kees Cook647416f2013-03-10 14:10:06 -07004273DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4274 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004275 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004276
Kees Cook647416f2013-03-10 14:10:06 -07004277static int
4278i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004279{
David Weinehall36cdd012016-08-22 13:59:31 +03004280 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004281
Chris Wilson62e1baa2016-07-13 09:10:36 +01004282 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004283 return -ENODEV;
4284
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004285 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004286 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004287}
4288
Kees Cook647416f2013-03-10 14:10:06 -07004289static int
4290i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004291{
David Weinehall36cdd012016-08-22 13:59:31 +03004292 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304293 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004294 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004295
Chris Wilson62e1baa2016-07-13 09:10:36 +01004296 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004297 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004298
Kees Cook647416f2013-03-10 14:10:06 -07004299 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004300
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004301 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004302 if (ret)
4303 return ret;
4304
Jesse Barnes1523c312012-05-25 12:34:54 -07004305 /*
4306 * Turbo will still be enabled, but won't go below the set value.
4307 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304308 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004309
Akash Goelbc4d91f2015-02-26 16:09:47 +05304310 hw_max = dev_priv->rps.max_freq;
4311 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004312
David Weinehall36cdd012016-08-22 13:59:31 +03004313 if (val < hw_min ||
4314 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004315 mutex_unlock(&dev_priv->rps.hw_lock);
4316 return -EINVAL;
4317 }
4318
Ben Widawskyb39fb292014-03-19 18:31:11 -07004319 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004320
Chris Wilsondc979972016-05-10 14:10:04 +01004321 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004322
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004323 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004324
Kees Cook647416f2013-03-10 14:10:06 -07004325 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004326}
4327
Kees Cook647416f2013-03-10 14:10:06 -07004328DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4329 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004330 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004331
Kees Cook647416f2013-03-10 14:10:06 -07004332static int
4333i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004334{
David Weinehall36cdd012016-08-22 13:59:31 +03004335 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004336 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004337
David Weinehall36cdd012016-08-22 13:59:31 +03004338 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004339 return -ENODEV;
4340
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004341 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004342
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004343 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004344
4345 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004346
Kees Cook647416f2013-03-10 14:10:06 -07004347 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004348
Kees Cook647416f2013-03-10 14:10:06 -07004349 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004350}
4351
Kees Cook647416f2013-03-10 14:10:06 -07004352static int
4353i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004354{
David Weinehall36cdd012016-08-22 13:59:31 +03004355 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004356 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004357
David Weinehall36cdd012016-08-22 13:59:31 +03004358 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004359 return -ENODEV;
4360
Kees Cook647416f2013-03-10 14:10:06 -07004361 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004362 return -EINVAL;
4363
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004364 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004365 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004366
4367 /* Update the cache sharing policy here as well */
4368 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4369 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4370 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4371 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4372
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004373 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004374 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004375}
4376
Kees Cook647416f2013-03-10 14:10:06 -07004377DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4378 i915_cache_sharing_get, i915_cache_sharing_set,
4379 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004380
David Weinehall36cdd012016-08-22 13:59:31 +03004381static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004382 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004383{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004384 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004385 int ss;
4386 u32 sig1[ss_max], sig2[ss_max];
4387
4388 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4389 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4390 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4391 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4392
4393 for (ss = 0; ss < ss_max; ss++) {
4394 unsigned int eu_cnt;
4395
4396 if (sig1[ss] & CHV_SS_PG_ENABLE)
4397 /* skip disabled subslice */
4398 continue;
4399
Imre Deakf08a0c92016-08-31 19:13:04 +03004400 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004401 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004402 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4403 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4404 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4405 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004406 sseu->eu_total += eu_cnt;
4407 sseu->eu_per_subslice = max_t(unsigned int,
4408 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004409 }
Jeff McGee5d395252015-04-03 18:13:17 -07004410}
4411
David Weinehall36cdd012016-08-22 13:59:31 +03004412static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004413 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004414{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004415 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004416 int s, ss;
4417 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4418
Jeff McGee1c046bc2015-04-03 18:13:18 -07004419 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004420 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004421 s_max = 1;
4422 ss_max = 3;
4423 }
4424
4425 for (s = 0; s < s_max; s++) {
4426 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4427 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4428 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4429 }
4430
Jeff McGee5d395252015-04-03 18:13:17 -07004431 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4432 GEN9_PGCTL_SSA_EU19_ACK |
4433 GEN9_PGCTL_SSA_EU210_ACK |
4434 GEN9_PGCTL_SSA_EU311_ACK;
4435 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4436 GEN9_PGCTL_SSB_EU19_ACK |
4437 GEN9_PGCTL_SSB_EU210_ACK |
4438 GEN9_PGCTL_SSB_EU311_ACK;
4439
4440 for (s = 0; s < s_max; s++) {
4441 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4442 /* skip disabled slice */
4443 continue;
4444
Imre Deakf08a0c92016-08-31 19:13:04 +03004445 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004446
David Weinehall36cdd012016-08-22 13:59:31 +03004447 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004448 sseu->subslice_mask =
4449 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004450
Jeff McGee5d395252015-04-03 18:13:17 -07004451 for (ss = 0; ss < ss_max; ss++) {
4452 unsigned int eu_cnt;
4453
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004454 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004455 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4456 /* skip disabled subslice */
4457 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004458
Imre Deak57ec1712016-08-31 19:13:05 +03004459 sseu->subslice_mask |= BIT(ss);
4460 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004461
Jeff McGee5d395252015-04-03 18:13:17 -07004462 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4463 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004464 sseu->eu_total += eu_cnt;
4465 sseu->eu_per_subslice = max_t(unsigned int,
4466 sseu->eu_per_subslice,
4467 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004468 }
4469 }
4470}
4471
David Weinehall36cdd012016-08-22 13:59:31 +03004472static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004473 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004474{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004475 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004476 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004477
Imre Deakf08a0c92016-08-31 19:13:04 +03004478 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004479
Imre Deakf08a0c92016-08-31 19:13:04 +03004480 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004481 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004482 sseu->eu_per_subslice =
4483 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004484 sseu->eu_total = sseu->eu_per_subslice *
4485 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004486
4487 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004488 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004489 u8 subslice_7eu =
4490 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004491
Imre Deak915490d2016-08-31 19:13:01 +03004492 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004493 }
4494 }
4495}
4496
Imre Deak615d8902016-08-31 19:13:03 +03004497static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4498 const struct sseu_dev_info *sseu)
4499{
4500 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4501 const char *type = is_available_info ? "Available" : "Enabled";
4502
Imre Deakc67ba532016-08-31 19:13:06 +03004503 seq_printf(m, " %s Slice Mask: %04x\n", type,
4504 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004505 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004506 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004507 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004508 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004509 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4510 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004511 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004512 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004513 seq_printf(m, " %s EU Total: %u\n", type,
4514 sseu->eu_total);
4515 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4516 sseu->eu_per_subslice);
4517
4518 if (!is_available_info)
4519 return;
4520
4521 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4522 if (HAS_POOLED_EU(dev_priv))
4523 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4524
4525 seq_printf(m, " Has Slice Power Gating: %s\n",
4526 yesno(sseu->has_slice_pg));
4527 seq_printf(m, " Has Subslice Power Gating: %s\n",
4528 yesno(sseu->has_subslice_pg));
4529 seq_printf(m, " Has EU Power Gating: %s\n",
4530 yesno(sseu->has_eu_pg));
4531}
4532
Jeff McGee38732182015-02-13 10:27:54 -06004533static int i915_sseu_status(struct seq_file *m, void *unused)
4534{
David Weinehall36cdd012016-08-22 13:59:31 +03004535 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004536 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004537
David Weinehall36cdd012016-08-22 13:59:31 +03004538 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004539 return -ENODEV;
4540
4541 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004542 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004543
Jeff McGee7f992ab2015-02-13 10:27:55 -06004544 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004545 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004546
4547 intel_runtime_pm_get(dev_priv);
4548
David Weinehall36cdd012016-08-22 13:59:31 +03004549 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004550 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004551 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004552 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004553 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004554 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004555 }
David Weinehall238010e2016-08-01 17:33:27 +03004556
4557 intel_runtime_pm_put(dev_priv);
4558
Imre Deak615d8902016-08-31 19:13:03 +03004559 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004560
Jeff McGee38732182015-02-13 10:27:54 -06004561 return 0;
4562}
4563
Ben Widawsky6d794d42011-04-25 11:25:56 -07004564static int i915_forcewake_open(struct inode *inode, struct file *file)
4565{
David Weinehall36cdd012016-08-22 13:59:31 +03004566 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004567
David Weinehall36cdd012016-08-22 13:59:31 +03004568 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004569 return 0;
4570
Chris Wilson6daccb02015-01-16 11:34:35 +02004571 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004572 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004573
4574 return 0;
4575}
4576
Ben Widawskyc43b5632012-04-16 14:07:40 -07004577static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004578{
David Weinehall36cdd012016-08-22 13:59:31 +03004579 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004580
David Weinehall36cdd012016-08-22 13:59:31 +03004581 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004582 return 0;
4583
Mika Kuoppala59bad942015-01-16 11:34:40 +02004584 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004585 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004586
4587 return 0;
4588}
4589
4590static const struct file_operations i915_forcewake_fops = {
4591 .owner = THIS_MODULE,
4592 .open = i915_forcewake_open,
4593 .release = i915_forcewake_release,
4594};
4595
4596static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4597{
Ben Widawsky6d794d42011-04-25 11:25:56 -07004598 struct dentry *ent;
4599
4600 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004601 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03004602 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07004603 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004604 if (!ent)
4605 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004606
Ben Widawsky8eb57292011-05-11 15:10:58 -07004607 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004608}
4609
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004610static int i915_debugfs_create(struct dentry *root,
4611 struct drm_minor *minor,
4612 const char *name,
4613 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004614{
Jesse Barnes358733e2011-07-27 11:53:01 -07004615 struct dentry *ent;
4616
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004617 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004618 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03004619 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004620 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004621 if (!ent)
4622 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004623
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004624 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004625}
4626
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004627static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004628 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004629 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004630 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01004631 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004632 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004633 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004634 {"i915_gem_request", i915_gem_request_info, 0},
4635 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004636 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004637 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004638 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004639 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004640 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004641 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004642 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304643 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004644 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004645 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004646 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004647 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004648 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004649 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004650 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004651 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004652 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004653 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004654 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004655 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004656 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004657 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004658 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004659 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004660 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004661 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004662 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004663 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004664 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004665 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004666 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004667 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004668 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004669 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004670 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004671 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004672 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004673 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004674 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304675 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004676 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004677};
Ben Gamari27c202a2009-07-01 22:26:52 -04004678#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004679
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004680static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004681 const char *name;
4682 const struct file_operations *fops;
4683} i915_debugfs_files[] = {
4684 {"i915_wedged", &i915_wedged_fops},
4685 {"i915_max_freq", &i915_max_freq_fops},
4686 {"i915_min_freq", &i915_min_freq_fops},
4687 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004688 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4689 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004690 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004691#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004692 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004693#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004694 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004695 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004696 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4697 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4698 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004699 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004700 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4701 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304702 {"i915_dp_test_active", &i915_displayport_test_active_fops},
4703 {"i915_guc_log_control", &i915_guc_log_control_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004704};
4705
Chris Wilson1dac8912016-06-24 14:00:17 +01004706int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004707{
Chris Wilson91c8a322016-07-05 10:40:23 +01004708 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02004709 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004710
Ben Widawsky6d794d42011-04-25 11:25:56 -07004711 ret = i915_forcewake_create(minor->debugfs_root, minor);
4712 if (ret)
4713 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004714
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004715 ret = intel_pipe_crc_create(minor);
4716 if (ret)
4717 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004718
Daniel Vetter34b96742013-07-04 20:49:44 +02004719 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4720 ret = i915_debugfs_create(minor->debugfs_root, minor,
4721 i915_debugfs_files[i].name,
4722 i915_debugfs_files[i].fops);
4723 if (ret)
4724 return ret;
4725 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004726
Ben Gamari27c202a2009-07-01 22:26:52 -04004727 return drm_debugfs_create_files(i915_debugfs_list,
4728 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004729 minor->debugfs_root, minor);
4730}
4731
Chris Wilson1dac8912016-06-24 14:00:17 +01004732void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004733{
Chris Wilson91c8a322016-07-05 10:40:23 +01004734 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02004735 int i;
4736
Ben Gamari27c202a2009-07-01 22:26:52 -04004737 drm_debugfs_remove_files(i915_debugfs_list,
4738 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004739
David Weinehall36cdd012016-08-22 13:59:31 +03004740 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004741 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004742
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004743 intel_pipe_crc_cleanup(minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004744
Daniel Vetter34b96742013-07-04 20:49:44 +02004745 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4746 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03004747 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02004748
4749 drm_debugfs_remove_files(info_list, 1, minor);
4750 }
Ben Gamari20172632009-02-17 20:08:50 -05004751}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004752
4753struct dpcd_block {
4754 /* DPCD dump start address. */
4755 unsigned int offset;
4756 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4757 unsigned int end;
4758 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4759 size_t size;
4760 /* Only valid for eDP. */
4761 bool edp;
4762};
4763
4764static const struct dpcd_block i915_dpcd_debug[] = {
4765 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4766 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4767 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4768 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4769 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4770 { .offset = DP_SET_POWER },
4771 { .offset = DP_EDP_DPCD_REV },
4772 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4773 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4774 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4775};
4776
4777static int i915_dpcd_show(struct seq_file *m, void *data)
4778{
4779 struct drm_connector *connector = m->private;
4780 struct intel_dp *intel_dp =
4781 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4782 uint8_t buf[16];
4783 ssize_t err;
4784 int i;
4785
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004786 if (connector->status != connector_status_connected)
4787 return -ENODEV;
4788
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004789 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4790 const struct dpcd_block *b = &i915_dpcd_debug[i];
4791 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4792
4793 if (b->edp &&
4794 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4795 continue;
4796
4797 /* low tech for now */
4798 if (WARN_ON(size > sizeof(buf)))
4799 continue;
4800
4801 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4802 if (err <= 0) {
4803 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4804 size, b->offset, err);
4805 continue;
4806 }
4807
4808 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004809 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004810
4811 return 0;
4812}
4813
4814static int i915_dpcd_open(struct inode *inode, struct file *file)
4815{
4816 return single_open(file, i915_dpcd_show, inode->i_private);
4817}
4818
4819static const struct file_operations i915_dpcd_fops = {
4820 .owner = THIS_MODULE,
4821 .open = i915_dpcd_open,
4822 .read = seq_read,
4823 .llseek = seq_lseek,
4824 .release = single_release,
4825};
4826
David Weinehallecbd6782016-08-23 12:23:56 +03004827static int i915_panel_show(struct seq_file *m, void *data)
4828{
4829 struct drm_connector *connector = m->private;
4830 struct intel_dp *intel_dp =
4831 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4832
4833 if (connector->status != connector_status_connected)
4834 return -ENODEV;
4835
4836 seq_printf(m, "Panel power up delay: %d\n",
4837 intel_dp->panel_power_up_delay);
4838 seq_printf(m, "Panel power down delay: %d\n",
4839 intel_dp->panel_power_down_delay);
4840 seq_printf(m, "Backlight on delay: %d\n",
4841 intel_dp->backlight_on_delay);
4842 seq_printf(m, "Backlight off delay: %d\n",
4843 intel_dp->backlight_off_delay);
4844
4845 return 0;
4846}
4847
4848static int i915_panel_open(struct inode *inode, struct file *file)
4849{
4850 return single_open(file, i915_panel_show, inode->i_private);
4851}
4852
4853static const struct file_operations i915_panel_fops = {
4854 .owner = THIS_MODULE,
4855 .open = i915_panel_open,
4856 .read = seq_read,
4857 .llseek = seq_lseek,
4858 .release = single_release,
4859};
4860
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004861/**
4862 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4863 * @connector: pointer to a registered drm_connector
4864 *
4865 * Cleanup will be done by drm_connector_unregister() through a call to
4866 * drm_debugfs_connector_remove().
4867 *
4868 * Returns 0 on success, negative error codes on error.
4869 */
4870int i915_debugfs_connector_add(struct drm_connector *connector)
4871{
4872 struct dentry *root = connector->debugfs_entry;
4873
4874 /* The connector must have been registered beforehands. */
4875 if (!root)
4876 return -ENODEV;
4877
4878 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4879 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03004880 debugfs_create_file("i915_dpcd", S_IRUGO, root,
4881 connector, &i915_dpcd_fops);
4882
4883 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4884 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
4885 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004886
4887 return 0;
4888}