blob: a746130c8e324de9cca02250a77ebcdb47bbcfd0 [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
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
David Weinehall36cdd012016-08-22 13:59:31 +030043static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
44{
45 return to_i915(node->minor->dev);
46}
47
Damien Lespiau497666d2013-10-15 18:55:39 +010048/* As the drm_debugfs_init() routines are called before dev->dev_private is
49 * allocated we need to hook into the minor for release. */
50static int
51drm_add_fake_info_node(struct drm_minor *minor,
52 struct dentry *ent,
53 const void *key)
54{
55 struct drm_info_node *node;
56
57 node = kmalloc(sizeof(*node), GFP_KERNEL);
58 if (node == NULL) {
59 debugfs_remove(ent);
60 return -ENOMEM;
61 }
62
63 node->minor = minor;
64 node->dent = ent;
David Weinehall36cdd012016-08-22 13:59:31 +030065 node->info_ent = (void *)key;
Damien Lespiau497666d2013-10-15 18:55:39 +010066
67 mutex_lock(&minor->debugfs_lock);
68 list_add(&node->list, &minor->debugfs_list);
69 mutex_unlock(&minor->debugfs_lock);
70
71 return 0;
72}
73
Chris Wilson70d39fe2010-08-25 16:03:34 +010074static int i915_capabilities(struct seq_file *m, void *data)
75{
David Weinehall36cdd012016-08-22 13:59:31 +030076 struct drm_i915_private *dev_priv = node_to_i915(m->private);
77 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010078
David Weinehall36cdd012016-08-22 13:59:31 +030079 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
Jani Nikula2e0d26f2016-12-01 14:49:55 +020080 seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
David Weinehall36cdd012016-08-22 13:59:31 +030081 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010082#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030083 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010084#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010085
86 return 0;
87}
Ben Gamari433e12f2009-02-17 20:08:51 -050088
Imre Deaka7363de2016-05-12 16:18:52 +030089static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000090{
Chris Wilson573adb32016-08-04 16:32:39 +010091 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000092}
93
Imre Deaka7363de2016-05-12 16:18:52 +030094static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010095{
96 return obj->pin_display ? 'p' : ' ';
97}
98
Imre Deaka7363de2016-05-12 16:18:52 +030099static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000100{
Chris Wilson3e510a82016-08-05 10:14:23 +0100101 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -0400102 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100103 case I915_TILING_NONE: return ' ';
104 case I915_TILING_X: return 'X';
105 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400106 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000107}
108
Imre Deaka7363de2016-05-12 16:18:52 +0300109static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700110{
Chris Wilson275f0392016-10-24 13:42:14 +0100111 return !list_empty(&obj->userfault_link) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100112}
113
Imre Deaka7363de2016-05-12 16:18:52 +0300114static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100115{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100116 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700117}
118
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100119static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
120{
121 u64 size = 0;
122 struct i915_vma *vma;
123
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000124 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100125 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100126 size += vma->node.size;
127 }
128
129 return size;
130}
131
Chris Wilson37811fc2010-08-25 22:45:57 +0100132static void
133describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
134{
Chris Wilsonb4716182015-04-27 13:41:17 +0100135 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000136 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700137 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100138 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800139 int pin_count = 0;
140
Chris Wilson188c1ab2016-04-03 14:14:20 +0100141 lockdep_assert_held(&obj->base.dev->struct_mutex);
142
Chris Wilsond07f0e52016-10-28 13:58:44 +0100143 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100144 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100145 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 get_pin_flag(obj),
147 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700148 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100149 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800150 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100151 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100152 obj->base.write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300153 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100154 obj->mm.dirty ? " dirty" : "",
155 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100156 if (obj->base.name)
157 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000158 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100159 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800160 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300161 }
162 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100163 if (obj->pin_display)
164 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000165 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100166 if (!drm_mm_node_allocated(&vma->node))
167 continue;
168
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100169 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100170 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100171 vma->node.start, vma->node.size);
Chris Wilson3272db52016-08-04 16:32:32 +0100172 if (i915_vma_is_ggtt(vma))
Chris Wilson596c5922016-02-26 11:03:20 +0000173 seq_printf(m, ", type: %u", vma->ggtt_view.type);
Chris Wilson49ef5292016-08-18 17:17:00 +0100174 if (vma->fence)
175 seq_printf(m, " , fence: %d%s",
176 vma->fence->id,
177 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000178 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700179 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000180 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100181 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100182
Chris Wilsond07f0e52016-10-28 13:58:44 +0100183 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100184 if (engine)
185 seq_printf(m, " (%s)", engine->name);
186
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100187 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
188 if (frontbuffer_bits)
189 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100190}
191
Chris Wilson6d2b88852013-08-07 18:30:54 +0100192static int obj_rank_by_stolen(void *priv,
193 struct list_head *A, struct list_head *B)
194{
195 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200196 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100197 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200198 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100199
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200200 if (a->stolen->start < b->stolen->start)
201 return -1;
202 if (a->stolen->start > b->stolen->start)
203 return 1;
204 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100205}
206
207static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
208{
David Weinehall36cdd012016-08-22 13:59:31 +0300209 struct drm_i915_private *dev_priv = node_to_i915(m->private);
210 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100211 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300212 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100213 LIST_HEAD(stolen);
214 int count, ret;
215
216 ret = mutex_lock_interruptible(&dev->struct_mutex);
217 if (ret)
218 return ret;
219
220 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200221 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100222 if (obj->stolen == NULL)
223 continue;
224
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200225 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100226
227 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100228 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100229 count++;
230 }
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200231 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson6d2b88852013-08-07 18:30:54 +0100232 if (obj->stolen == NULL)
233 continue;
234
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100236
237 total_obj_size += obj->base.size;
238 count++;
239 }
240 list_sort(NULL, &stolen, obj_rank_by_stolen);
241 seq_puts(m, "Stolen:\n");
242 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200243 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100244 seq_puts(m, " ");
245 describe_obj(m, obj);
246 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200247 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100248 }
249 mutex_unlock(&dev->struct_mutex);
250
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300251 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252 count, total_obj_size, total_gtt_size);
253 return 0;
254}
255
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100256struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000257 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300258 unsigned long count;
259 u64 total, unbound;
260 u64 global, shared;
261 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100262};
263
264static int per_file_stats(int id, void *ptr, void *data)
265{
266 struct drm_i915_gem_object *obj = ptr;
267 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000268 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100269
270 stats->count++;
271 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100272 if (!obj->bind_count)
273 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000274 if (obj->base.name || obj->base.dma_buf)
275 stats->shared += obj->base.size;
276
Chris Wilson894eeec2016-08-04 07:52:20 +0100277 list_for_each_entry(vma, &obj->vma_list, obj_link) {
278 if (!drm_mm_node_allocated(&vma->node))
279 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000280
Chris Wilson3272db52016-08-04 16:32:32 +0100281 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100282 stats->global += vma->node.size;
283 } else {
284 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000285
Chris Wilson2bfa9962016-08-04 07:52:25 +0100286 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000287 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000288 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100289
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100290 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100291 stats->active += vma->node.size;
292 else
293 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100294 }
295
296 return 0;
297}
298
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100299#define print_file_stats(m, name, stats) do { \
300 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300301 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 +0100302 name, \
303 stats.count, \
304 stats.total, \
305 stats.active, \
306 stats.inactive, \
307 stats.global, \
308 stats.shared, \
309 stats.unbound); \
310} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800311
312static void print_batch_pool_stats(struct seq_file *m,
313 struct drm_i915_private *dev_priv)
314{
315 struct drm_i915_gem_object *obj;
316 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000317 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530318 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000319 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800320
321 memset(&stats, 0, sizeof(stats));
322
Akash Goel3b3f1652016-10-13 22:44:48 +0530323 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000324 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100325 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000326 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100327 batch_pool_link)
328 per_file_stats(0, obj, &stats);
329 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100330 }
Brad Volkin493018d2014-12-11 12:13:08 -0800331
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100332 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800333}
334
Chris Wilson15da9562016-05-24 14:53:43 +0100335static int per_file_ctx_stats(int id, void *ptr, void *data)
336{
337 struct i915_gem_context *ctx = ptr;
338 int n;
339
340 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
341 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100342 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100343 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100344 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100345 }
346
347 return 0;
348}
349
350static void print_context_stats(struct seq_file *m,
351 struct drm_i915_private *dev_priv)
352{
David Weinehall36cdd012016-08-22 13:59:31 +0300353 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100354 struct file_stats stats;
355 struct drm_file *file;
356
357 memset(&stats, 0, sizeof(stats));
358
David Weinehall36cdd012016-08-22 13:59:31 +0300359 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100360 if (dev_priv->kernel_context)
361 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
362
David Weinehall36cdd012016-08-22 13:59:31 +0300363 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100364 struct drm_i915_file_private *fpriv = file->driver_priv;
365 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
366 }
David Weinehall36cdd012016-08-22 13:59:31 +0300367 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100368
369 print_file_stats(m, "[k]contexts", stats);
370}
371
David Weinehall36cdd012016-08-22 13:59:31 +0300372static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100373{
David Weinehall36cdd012016-08-22 13:59:31 +0300374 struct drm_i915_private *dev_priv = node_to_i915(m->private);
375 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300376 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100377 u32 count, mapped_count, purgeable_count, dpy_count;
378 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000379 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100380 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100381 int ret;
382
383 ret = mutex_lock_interruptible(&dev->struct_mutex);
384 if (ret)
385 return ret;
386
Chris Wilson3ef7f222016-10-18 13:02:48 +0100387 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000388 dev_priv->mm.object_count,
389 dev_priv->mm.object_memory);
390
Chris Wilson1544c422016-08-15 13:18:16 +0100391 size = count = 0;
392 mapped_size = mapped_count = 0;
393 purgeable_size = purgeable_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200394 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100395 size += obj->base.size;
396 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200397
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100398 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200399 purgeable_size += obj->base.size;
400 ++purgeable_count;
401 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100402
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100403 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100404 mapped_count++;
405 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100406 }
Chris Wilson6299f992010-11-24 12:23:44 +0000407 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100408 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
409
410 size = count = dpy_size = dpy_count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200411 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100412 size += obj->base.size;
413 ++count;
414
415 if (obj->pin_display) {
416 dpy_size += obj->base.size;
417 ++dpy_count;
418 }
419
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100420 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100421 purgeable_size += obj->base.size;
422 ++purgeable_count;
423 }
424
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100425 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100426 mapped_count++;
427 mapped_size += obj->base.size;
428 }
429 }
430 seq_printf(m, "%u bound objects, %llu bytes\n",
431 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300432 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200433 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100434 seq_printf(m, "%u mapped objects, %llu bytes\n",
435 mapped_count, mapped_size);
436 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
437 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000438
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300439 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300440 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100441
Damien Lespiau267f0c92013-06-24 22:59:48 +0100442 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800443 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200444 mutex_unlock(&dev->struct_mutex);
445
446 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100447 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100448 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
449 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100450 struct drm_i915_file_private *file_priv = file->driver_priv;
451 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900452 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100453
454 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000455 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100456 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100457 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100458 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900459 /*
460 * Although we have a valid reference on file->pid, that does
461 * not guarantee that the task_struct who called get_pid() is
462 * still alive (e.g. get_pid(current) => fork() => exit()).
463 * Therefore, we need to protect this ->comm access using RCU.
464 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100465 mutex_lock(&dev->struct_mutex);
466 request = list_first_entry_or_null(&file_priv->mm.request_list,
467 struct drm_i915_gem_request,
468 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900469 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100470 task = pid_task(request && request->ctx->pid ?
471 request->ctx->pid : file->pid,
472 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800473 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900474 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100475 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100476 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200477 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100478
479 return 0;
480}
481
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100482static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000483{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100484 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300485 struct drm_i915_private *dev_priv = node_to_i915(node);
486 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100487 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000488 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300489 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000490 int count, ret;
491
492 ret = mutex_lock_interruptible(&dev->struct_mutex);
493 if (ret)
494 return ret;
495
496 total_obj_size = total_gtt_size = count = 0;
Joonas Lahtinen56cea322016-11-02 12:16:04 +0200497 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
Chris Wilson6da84822016-08-15 10:48:44 +0100498 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100499 continue;
500
Damien Lespiau267f0c92013-06-24 22:59:48 +0100501 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000502 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100503 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000504 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100505 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000506 count++;
507 }
508
509 mutex_unlock(&dev->struct_mutex);
510
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300511 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000512 count, total_obj_size, total_gtt_size);
513
514 return 0;
515}
516
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100517static int i915_gem_pageflip_info(struct seq_file *m, void *data)
518{
David Weinehall36cdd012016-08-22 13:59:31 +0300519 struct drm_i915_private *dev_priv = node_to_i915(m->private);
520 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100521 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200522 int ret;
523
524 ret = mutex_lock_interruptible(&dev->struct_mutex);
525 if (ret)
526 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100527
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100528 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800529 const char pipe = pipe_name(crtc->pipe);
530 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200531 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100532
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200533 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200534 work = crtc->flip_work;
535 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800536 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100537 pipe, plane);
538 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200539 u32 pending;
540 u32 addr;
541
542 pending = atomic_read(&work->pending);
543 if (pending) {
544 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
545 pipe, plane);
546 } else {
547 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
548 pipe, plane);
549 }
550 if (work->flip_queued_req) {
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200551 struct intel_engine_cs *engine = work->flip_queued_req->engine;
Daniel Vetter5a21b662016-05-24 17:13:53 +0200552
Chris Wilson312c3c42016-11-24 14:47:50 +0000553 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 +0200554 engine->name,
Joonas Lahtinen24327f82016-11-08 09:11:48 +0200555 work->flip_queued_req->global_seqno,
Chris Wilson312c3c42016-11-24 14:47:50 +0000556 intel_engine_last_submit(engine),
Chris Wilson1b7744e2016-07-01 17:23:17 +0100557 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100558 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200559 } else
560 seq_printf(m, "Flip not associated with any ring\n");
561 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
562 work->flip_queued_vblank,
563 work->flip_ready_vblank,
564 intel_crtc_get_vblank_counter(crtc));
565 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
566
David Weinehall36cdd012016-08-22 13:59:31 +0300567 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200568 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
569 else
570 addr = I915_READ(DSPADDR(crtc->plane));
571 seq_printf(m, "Current scanout address 0x%08x\n", addr);
572
573 if (work->pending_flip_obj) {
574 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
575 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100576 }
577 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200578 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100579 }
580
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200581 mutex_unlock(&dev->struct_mutex);
582
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100583 return 0;
584}
585
Brad Volkin493018d2014-12-11 12:13:08 -0800586static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
587{
David Weinehall36cdd012016-08-22 13:59:31 +0300588 struct drm_i915_private *dev_priv = node_to_i915(m->private);
589 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800590 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000591 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530592 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100593 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000594 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800595
596 ret = mutex_lock_interruptible(&dev->struct_mutex);
597 if (ret)
598 return ret;
599
Akash Goel3b3f1652016-10-13 22:44:48 +0530600 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000601 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100602 int count;
603
604 count = 0;
605 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000606 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100607 batch_pool_link)
608 count++;
609 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000610 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100611
612 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000613 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100614 batch_pool_link) {
615 seq_puts(m, " ");
616 describe_obj(m, obj);
617 seq_putc(m, '\n');
618 }
619
620 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100621 }
Brad Volkin493018d2014-12-11 12:13:08 -0800622 }
623
Chris Wilson8d9d5742015-04-07 16:20:38 +0100624 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800625
626 mutex_unlock(&dev->struct_mutex);
627
628 return 0;
629}
630
Chris Wilson1b365952016-10-04 21:11:31 +0100631static void print_request(struct seq_file *m,
632 struct drm_i915_gem_request *rq,
633 const char *prefix)
634{
Chris Wilson20311bd2016-11-14 20:41:03 +0000635 seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilson65e47602016-10-28 13:58:49 +0100636 rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
Chris Wilson20311bd2016-11-14 20:41:03 +0000637 rq->priotree.priority,
Chris Wilson1b365952016-10-04 21:11:31 +0100638 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilson562f5d42016-10-28 13:58:54 +0100639 rq->timeline->common->name);
Chris Wilson1b365952016-10-04 21:11:31 +0100640}
641
Ben Gamari20172632009-02-17 20:08:50 -0500642static int i915_gem_request_info(struct seq_file *m, void *data)
643{
David Weinehall36cdd012016-08-22 13:59:31 +0300644 struct drm_i915_private *dev_priv = node_to_i915(m->private);
645 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200646 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530647 struct intel_engine_cs *engine;
648 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000649 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100650
651 ret = mutex_lock_interruptible(&dev->struct_mutex);
652 if (ret)
653 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500654
Chris Wilson2d1070b2015-04-01 10:36:56 +0100655 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530656 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100657 int count;
658
659 count = 0;
Chris Wilson73cb9702016-10-28 13:58:46 +0100660 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100661 count++;
662 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100663 continue;
664
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000665 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson73cb9702016-10-28 13:58:46 +0100666 list_for_each_entry(req, &engine->timeline->requests, link)
Chris Wilson1b365952016-10-04 21:11:31 +0100667 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100668
669 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500670 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100671 mutex_unlock(&dev->struct_mutex);
672
Chris Wilson2d1070b2015-04-01 10:36:56 +0100673 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100674 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100675
Ben Gamari20172632009-02-17 20:08:50 -0500676 return 0;
677}
678
Chris Wilsonb2223492010-10-27 15:27:33 +0100679static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000680 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100681{
Chris Wilson688e6c72016-07-01 17:23:15 +0100682 struct intel_breadcrumbs *b = &engine->breadcrumbs;
683 struct rb_node *rb;
684
Chris Wilson12471ba2016-04-09 10:57:55 +0100685 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100686 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100687
Chris Wilsonf6168e32016-10-28 13:58:55 +0100688 spin_lock_irq(&b->lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100689 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
690 struct intel_wait *w = container_of(rb, typeof(*w), node);
691
692 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
693 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
694 }
Chris Wilsonf6168e32016-10-28 13:58:55 +0100695 spin_unlock_irq(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100696}
697
Ben Gamari20172632009-02-17 20:08:50 -0500698static int i915_gem_seqno_info(struct seq_file *m, void *data)
699{
David Weinehall36cdd012016-08-22 13:59:31 +0300700 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000701 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530702 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500703
Akash Goel3b3f1652016-10-13 22:44:48 +0530704 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000705 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100706
Ben Gamari20172632009-02-17 20:08:50 -0500707 return 0;
708}
709
710
711static int i915_interrupt_info(struct seq_file *m, void *data)
712{
David Weinehall36cdd012016-08-22 13:59:31 +0300713 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000714 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530715 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100716 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100717
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200718 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500719
David Weinehall36cdd012016-08-22 13:59:31 +0300720 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300721 seq_printf(m, "Master Interrupt Control:\t%08x\n",
722 I915_READ(GEN8_MASTER_IRQ));
723
724 seq_printf(m, "Display IER:\t%08x\n",
725 I915_READ(VLV_IER));
726 seq_printf(m, "Display IIR:\t%08x\n",
727 I915_READ(VLV_IIR));
728 seq_printf(m, "Display IIR_RW:\t%08x\n",
729 I915_READ(VLV_IIR_RW));
730 seq_printf(m, "Display IMR:\t%08x\n",
731 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100732 for_each_pipe(dev_priv, pipe) {
733 enum intel_display_power_domain power_domain;
734
735 power_domain = POWER_DOMAIN_PIPE(pipe);
736 if (!intel_display_power_get_if_enabled(dev_priv,
737 power_domain)) {
738 seq_printf(m, "Pipe %c power disabled\n",
739 pipe_name(pipe));
740 continue;
741 }
742
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300743 seq_printf(m, "Pipe %c stat:\t%08x\n",
744 pipe_name(pipe),
745 I915_READ(PIPESTAT(pipe)));
746
Chris Wilson9c870d02016-10-24 13:42:15 +0100747 intel_display_power_put(dev_priv, power_domain);
748 }
749
750 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300751 seq_printf(m, "Port hotplug:\t%08x\n",
752 I915_READ(PORT_HOTPLUG_EN));
753 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
754 I915_READ(VLV_DPFLIPSTAT));
755 seq_printf(m, "DPINVGTT:\t%08x\n",
756 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100757 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300758
759 for (i = 0; i < 4; i++) {
760 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
761 i, I915_READ(GEN8_GT_IMR(i)));
762 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
763 i, I915_READ(GEN8_GT_IIR(i)));
764 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
765 i, I915_READ(GEN8_GT_IER(i)));
766 }
767
768 seq_printf(m, "PCU interrupt mask:\t%08x\n",
769 I915_READ(GEN8_PCU_IMR));
770 seq_printf(m, "PCU interrupt identity:\t%08x\n",
771 I915_READ(GEN8_PCU_IIR));
772 seq_printf(m, "PCU interrupt enable:\t%08x\n",
773 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300774 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700775 seq_printf(m, "Master Interrupt Control:\t%08x\n",
776 I915_READ(GEN8_MASTER_IRQ));
777
778 for (i = 0; i < 4; i++) {
779 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
780 i, I915_READ(GEN8_GT_IMR(i)));
781 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
782 i, I915_READ(GEN8_GT_IIR(i)));
783 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
784 i, I915_READ(GEN8_GT_IER(i)));
785 }
786
Damien Lespiau055e3932014-08-18 13:49:10 +0100787 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200788 enum intel_display_power_domain power_domain;
789
790 power_domain = POWER_DOMAIN_PIPE(pipe);
791 if (!intel_display_power_get_if_enabled(dev_priv,
792 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300793 seq_printf(m, "Pipe %c power disabled\n",
794 pipe_name(pipe));
795 continue;
796 }
Ben Widawskya123f152013-11-02 21:07:10 -0700797 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000798 pipe_name(pipe),
799 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700800 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000801 pipe_name(pipe),
802 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700803 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000804 pipe_name(pipe),
805 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200806
807 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700808 }
809
810 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
811 I915_READ(GEN8_DE_PORT_IMR));
812 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
813 I915_READ(GEN8_DE_PORT_IIR));
814 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
815 I915_READ(GEN8_DE_PORT_IER));
816
817 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
818 I915_READ(GEN8_DE_MISC_IMR));
819 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
820 I915_READ(GEN8_DE_MISC_IIR));
821 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
822 I915_READ(GEN8_DE_MISC_IER));
823
824 seq_printf(m, "PCU interrupt mask:\t%08x\n",
825 I915_READ(GEN8_PCU_IMR));
826 seq_printf(m, "PCU interrupt identity:\t%08x\n",
827 I915_READ(GEN8_PCU_IIR));
828 seq_printf(m, "PCU interrupt enable:\t%08x\n",
829 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300830 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700831 seq_printf(m, "Display IER:\t%08x\n",
832 I915_READ(VLV_IER));
833 seq_printf(m, "Display IIR:\t%08x\n",
834 I915_READ(VLV_IIR));
835 seq_printf(m, "Display IIR_RW:\t%08x\n",
836 I915_READ(VLV_IIR_RW));
837 seq_printf(m, "Display IMR:\t%08x\n",
838 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100839 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700840 seq_printf(m, "Pipe %c stat:\t%08x\n",
841 pipe_name(pipe),
842 I915_READ(PIPESTAT(pipe)));
843
844 seq_printf(m, "Master IER:\t%08x\n",
845 I915_READ(VLV_MASTER_IER));
846
847 seq_printf(m, "Render IER:\t%08x\n",
848 I915_READ(GTIER));
849 seq_printf(m, "Render IIR:\t%08x\n",
850 I915_READ(GTIIR));
851 seq_printf(m, "Render IMR:\t%08x\n",
852 I915_READ(GTIMR));
853
854 seq_printf(m, "PM IER:\t\t%08x\n",
855 I915_READ(GEN6_PMIER));
856 seq_printf(m, "PM IIR:\t\t%08x\n",
857 I915_READ(GEN6_PMIIR));
858 seq_printf(m, "PM IMR:\t\t%08x\n",
859 I915_READ(GEN6_PMIMR));
860
861 seq_printf(m, "Port hotplug:\t%08x\n",
862 I915_READ(PORT_HOTPLUG_EN));
863 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
864 I915_READ(VLV_DPFLIPSTAT));
865 seq_printf(m, "DPINVGTT:\t%08x\n",
866 I915_READ(DPINVGTT));
867
David Weinehall36cdd012016-08-22 13:59:31 +0300868 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800869 seq_printf(m, "Interrupt enable: %08x\n",
870 I915_READ(IER));
871 seq_printf(m, "Interrupt identity: %08x\n",
872 I915_READ(IIR));
873 seq_printf(m, "Interrupt mask: %08x\n",
874 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100875 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800876 seq_printf(m, "Pipe %c stat: %08x\n",
877 pipe_name(pipe),
878 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800879 } else {
880 seq_printf(m, "North Display Interrupt enable: %08x\n",
881 I915_READ(DEIER));
882 seq_printf(m, "North Display Interrupt identity: %08x\n",
883 I915_READ(DEIIR));
884 seq_printf(m, "North Display Interrupt mask: %08x\n",
885 I915_READ(DEIMR));
886 seq_printf(m, "South Display Interrupt enable: %08x\n",
887 I915_READ(SDEIER));
888 seq_printf(m, "South Display Interrupt identity: %08x\n",
889 I915_READ(SDEIIR));
890 seq_printf(m, "South Display Interrupt mask: %08x\n",
891 I915_READ(SDEIMR));
892 seq_printf(m, "Graphics Interrupt enable: %08x\n",
893 I915_READ(GTIER));
894 seq_printf(m, "Graphics Interrupt identity: %08x\n",
895 I915_READ(GTIIR));
896 seq_printf(m, "Graphics Interrupt mask: %08x\n",
897 I915_READ(GTIMR));
898 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530899 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300900 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100901 seq_printf(m,
902 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000903 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000904 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000905 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000906 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200907 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100908
Ben Gamari20172632009-02-17 20:08:50 -0500909 return 0;
910}
911
Chris Wilsona6172a82009-02-11 14:26:38 +0000912static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
913{
David Weinehall36cdd012016-08-22 13:59:31 +0300914 struct drm_i915_private *dev_priv = node_to_i915(m->private);
915 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100916 int i, ret;
917
918 ret = mutex_lock_interruptible(&dev->struct_mutex);
919 if (ret)
920 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000921
Chris Wilsona6172a82009-02-11 14:26:38 +0000922 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
923 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100924 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000925
Chris Wilson6c085a72012-08-20 11:40:46 +0200926 seq_printf(m, "Fence %d, pin count = %d, object = ",
927 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100928 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100929 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100930 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100931 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100932 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000933 }
934
Chris Wilson05394f32010-11-08 19:18:58 +0000935 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000936 return 0;
937}
938
Chris Wilson98a2f412016-10-12 10:05:18 +0100939#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
940
Daniel Vetterd5442302012-04-27 15:17:40 +0200941static ssize_t
942i915_error_state_write(struct file *filp,
943 const char __user *ubuf,
944 size_t cnt,
945 loff_t *ppos)
946{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300947 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200948
949 DRM_DEBUG_DRIVER("Resetting error state\n");
Tvrtko Ursulin12ff05e2016-12-01 14:16:43 +0000950 i915_destroy_error_state(error_priv->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +0200951
952 return cnt;
953}
954
955static int i915_error_state_open(struct inode *inode, struct file *file)
956{
David Weinehall36cdd012016-08-22 13:59:31 +0300957 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200958 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200959
960 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
961 if (!error_priv)
962 return -ENOMEM;
963
Tvrtko Ursulin12ff05e2016-12-01 14:16:43 +0000964 error_priv->i915 = dev_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200965
David Weinehall36cdd012016-08-22 13:59:31 +0300966 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200967
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300968 file->private_data = error_priv;
969
970 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200971}
972
973static int i915_error_state_release(struct inode *inode, struct file *file)
974{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300975 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200976
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300977 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200978 kfree(error_priv);
979
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300980 return 0;
981}
982
983static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
984 size_t count, loff_t *pos)
985{
986 struct i915_error_state_file_priv *error_priv = file->private_data;
987 struct drm_i915_error_state_buf error_str;
988 loff_t tmp_pos = 0;
989 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300990 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300991
Tvrtko Ursulin12ff05e2016-12-01 14:16:43 +0000992 ret = i915_error_state_buf_init(&error_str, error_priv->i915,
993 count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300994 if (ret)
995 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300996
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300997 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300998 if (ret)
999 goto out;
1000
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001001 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1002 error_str.buf,
1003 error_str.bytes);
1004
1005 if (ret_count < 0)
1006 ret = ret_count;
1007 else
1008 *pos = error_str.start + ret_count;
1009out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001010 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001011 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001012}
1013
1014static const struct file_operations i915_error_state_fops = {
1015 .owner = THIS_MODULE,
1016 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001017 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001018 .write = i915_error_state_write,
1019 .llseek = default_llseek,
1020 .release = i915_error_state_release,
1021};
1022
Chris Wilson98a2f412016-10-12 10:05:18 +01001023#endif
1024
Kees Cook647416f2013-03-10 14:10:06 -07001025static int
1026i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001027{
David Weinehall36cdd012016-08-22 13:59:31 +03001028 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001029
Joonas Lahtinen4c266ed2016-11-24 14:47:49 +00001030 *val = 1 + atomic_read(&dev_priv->gt.global_timeline.seqno);
Kees Cook647416f2013-03-10 14:10:06 -07001031 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001032}
1033
Kees Cook647416f2013-03-10 14:10:06 -07001034static int
1035i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001036{
David Weinehall36cdd012016-08-22 13:59:31 +03001037 struct drm_i915_private *dev_priv = data;
1038 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001039 int ret;
1040
Mika Kuoppala40633212012-12-04 15:12:00 +02001041 ret = mutex_lock_interruptible(&dev->struct_mutex);
1042 if (ret)
1043 return ret;
1044
Chris Wilson73cb9702016-10-28 13:58:46 +01001045 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001046 mutex_unlock(&dev->struct_mutex);
1047
Kees Cook647416f2013-03-10 14:10:06 -07001048 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001049}
1050
Kees Cook647416f2013-03-10 14:10:06 -07001051DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1052 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001053 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001054
Deepak Sadb4bd12014-03-31 11:30:02 +05301055static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001056{
David Weinehall36cdd012016-08-22 13:59:31 +03001057 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1058 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001059 int ret = 0;
1060
1061 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001062
David Weinehall36cdd012016-08-22 13:59:31 +03001063 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001064 u16 rgvswctl = I915_READ16(MEMSWCTL);
1065 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1066
1067 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1068 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1069 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1070 MEMSTAT_VID_SHIFT);
1071 seq_printf(m, "Current P-state: %d\n",
1072 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001073 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001074 u32 freq_sts;
1075
1076 mutex_lock(&dev_priv->rps.hw_lock);
1077 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1078 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1079 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1080
1081 seq_printf(m, "actual GPU freq: %d MHz\n",
1082 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1083
1084 seq_printf(m, "current GPU freq: %d MHz\n",
1085 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1086
1087 seq_printf(m, "max GPU freq: %d MHz\n",
1088 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1089
1090 seq_printf(m, "min GPU freq: %d MHz\n",
1091 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1092
1093 seq_printf(m, "idle GPU freq: %d MHz\n",
1094 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1095
1096 seq_printf(m,
1097 "efficient (RPe) frequency: %d MHz\n",
1098 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1099 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001100 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001101 u32 rp_state_limits;
1102 u32 gt_perf_status;
1103 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001104 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001105 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001106 u32 rpupei, rpcurup, rpprevup;
1107 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001108 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001109 int max_freq;
1110
Bob Paauwe35040562015-06-25 14:54:07 -07001111 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001112 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001113 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1114 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1115 } else {
1116 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1117 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1118 }
1119
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001120 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001121 ret = mutex_lock_interruptible(&dev->struct_mutex);
1122 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001123 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001124
Mika Kuoppala59bad942015-01-16 11:34:40 +02001125 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001126
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001127 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001128 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301129 reqf >>= 23;
1130 else {
1131 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001132 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301133 reqf >>= 24;
1134 else
1135 reqf >>= 25;
1136 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001137 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001138
Chris Wilson0d8f9492014-03-27 09:06:14 +00001139 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1140 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1141 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1142
Jesse Barnesccab5c82011-01-18 15:49:25 -08001143 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301144 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1145 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1146 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1147 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1148 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1149 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001150 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301151 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001152 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001153 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1154 else
1155 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001156 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001157
Mika Kuoppala59bad942015-01-16 11:34:40 +02001158 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001159 mutex_unlock(&dev->struct_mutex);
1160
David Weinehall36cdd012016-08-22 13:59:31 +03001161 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001162 pm_ier = I915_READ(GEN6_PMIER);
1163 pm_imr = I915_READ(GEN6_PMIMR);
1164 pm_isr = I915_READ(GEN6_PMISR);
1165 pm_iir = I915_READ(GEN6_PMIIR);
1166 pm_mask = I915_READ(GEN6_PMINTRMSK);
1167 } else {
1168 pm_ier = I915_READ(GEN8_GT_IER(2));
1169 pm_imr = I915_READ(GEN8_GT_IMR(2));
1170 pm_isr = I915_READ(GEN8_GT_ISR(2));
1171 pm_iir = I915_READ(GEN8_GT_IIR(2));
1172 pm_mask = I915_READ(GEN6_PMINTRMSK);
1173 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001174 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 -03001175 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301176 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001177 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001178 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001179 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001180 seq_printf(m, "Render p-state VID: %d\n",
1181 gt_perf_status & 0xff);
1182 seq_printf(m, "Render p-state limit: %d\n",
1183 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001184 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1185 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1186 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1187 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001188 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001189 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301190 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1191 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1192 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1193 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1194 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1195 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001196 seq_printf(m, "Up threshold: %d%%\n",
1197 dev_priv->rps.up_threshold);
1198
Akash Goeld6cda9c2016-04-23 00:05:46 +05301199 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1200 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1201 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1202 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1203 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1204 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001205 seq_printf(m, "Down threshold: %d%%\n",
1206 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001207
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001208 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001209 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001210 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001211 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001212 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001213 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001214
1215 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001216 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001217 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001218 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001219 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001220
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001221 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001222 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001223 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001224 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001225 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001226 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001227 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001228 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001229
Chris Wilsond86ed342015-04-27 13:41:19 +01001230 seq_printf(m, "Current freq: %d MHz\n",
1231 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1232 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001233 seq_printf(m, "Idle freq: %d MHz\n",
1234 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001235 seq_printf(m, "Min freq: %d MHz\n",
1236 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001237 seq_printf(m, "Boost freq: %d MHz\n",
1238 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001239 seq_printf(m, "Max freq: %d MHz\n",
1240 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1241 seq_printf(m,
1242 "efficient (RPe) frequency: %d MHz\n",
1243 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001244 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001245 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001246 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001247
Mika Kahola1170f282015-09-25 14:00:32 +03001248 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1249 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1250 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1251
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001252out:
1253 intel_runtime_pm_put(dev_priv);
1254 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001255}
1256
Ben Widawskyd6369512016-09-20 16:54:32 +03001257static void i915_instdone_info(struct drm_i915_private *dev_priv,
1258 struct seq_file *m,
1259 struct intel_instdone *instdone)
1260{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001261 int slice;
1262 int subslice;
1263
Ben Widawskyd6369512016-09-20 16:54:32 +03001264 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1265 instdone->instdone);
1266
1267 if (INTEL_GEN(dev_priv) <= 3)
1268 return;
1269
1270 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1271 instdone->slice_common);
1272
1273 if (INTEL_GEN(dev_priv) <= 6)
1274 return;
1275
Ben Widawskyf9e61372016-09-20 16:54:33 +03001276 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1277 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1278 slice, subslice, instdone->sampler[slice][subslice]);
1279
1280 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1281 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1282 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001283}
1284
Chris Wilsonf6544492015-01-26 18:03:04 +02001285static int i915_hangcheck_info(struct seq_file *m, void *unused)
1286{
David Weinehall36cdd012016-08-22 13:59:31 +03001287 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001288 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001289 u64 acthd[I915_NUM_ENGINES];
1290 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001291 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001292 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001293
Chris Wilson8af29b02016-09-09 14:11:47 +01001294 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1295 seq_printf(m, "Wedged\n");
1296 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1297 seq_printf(m, "Reset in progress\n");
1298 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1299 seq_printf(m, "Waiter holding struct mutex\n");
1300 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1301 seq_printf(m, "struct_mutex blocked for reset\n");
1302
Chris Wilsonf6544492015-01-26 18:03:04 +02001303 if (!i915.enable_hangcheck) {
1304 seq_printf(m, "Hangcheck disabled\n");
1305 return 0;
1306 }
1307
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001308 intel_runtime_pm_get(dev_priv);
1309
Akash Goel3b3f1652016-10-13 22:44:48 +05301310 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001311 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001312 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001313 }
1314
Akash Goel3b3f1652016-10-13 22:44:48 +05301315 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001316
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001317 intel_runtime_pm_put(dev_priv);
1318
Chris Wilsonf6544492015-01-26 18:03:04 +02001319 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1320 seq_printf(m, "Hangcheck active, fires in %dms\n",
1321 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1322 jiffies));
1323 } else
1324 seq_printf(m, "Hangcheck inactive\n");
1325
Akash Goel3b3f1652016-10-13 22:44:48 +05301326 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001327 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1328 struct rb_node *rb;
1329
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001330 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001331 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001332 engine->hangcheck.seqno, seqno[id],
1333 intel_engine_last_submit(engine));
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001334 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001335 yesno(intel_engine_has_waiter(engine)),
1336 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001337 &dev_priv->gpu_error.missed_irq_rings)),
1338 yesno(engine->hangcheck.stalled));
1339
Chris Wilsonf6168e32016-10-28 13:58:55 +01001340 spin_lock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001341 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1342 struct intel_wait *w = container_of(rb, typeof(*w), node);
1343
1344 seq_printf(m, "\t%s [%d] waiting for %x\n",
1345 w->tsk->comm, w->tsk->pid, w->seqno);
1346 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01001347 spin_unlock_irq(&b->lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001348
Chris Wilsonf6544492015-01-26 18:03:04 +02001349 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001350 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001351 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001352 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1353 hangcheck_action_to_str(engine->hangcheck.action),
1354 engine->hangcheck.action,
1355 jiffies_to_msecs(jiffies -
1356 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001357
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001358 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001359 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001360
Ben Widawskyd6369512016-09-20 16:54:32 +03001361 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001362
Ben Widawskyd6369512016-09-20 16:54:32 +03001363 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001364
Ben Widawskyd6369512016-09-20 16:54:32 +03001365 i915_instdone_info(dev_priv, m,
1366 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001367 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001368 }
1369
1370 return 0;
1371}
1372
Ben Widawsky4d855292011-12-12 19:34:16 -08001373static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001374{
David Weinehall36cdd012016-08-22 13:59:31 +03001375 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001376 u32 rgvmodectl, rstdbyctl;
1377 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001378
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001379 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001380
1381 rgvmodectl = I915_READ(MEMMODECTL);
1382 rstdbyctl = I915_READ(RSTDBYCTL);
1383 crstandvid = I915_READ16(CRSTANDVID);
1384
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001385 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001386
Jani Nikula742f4912015-09-03 11:16:09 +03001387 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001388 seq_printf(m, "Boost freq: %d\n",
1389 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1390 MEMMODE_BOOST_FREQ_SHIFT);
1391 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001392 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001393 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001394 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001395 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001396 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001397 seq_printf(m, "Starting frequency: P%d\n",
1398 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001399 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001400 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001401 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1402 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1403 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1404 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001405 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001406 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001407 switch (rstdbyctl & RSX_STATUS_MASK) {
1408 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001409 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001410 break;
1411 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001412 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001413 break;
1414 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001415 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001416 break;
1417 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001418 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001419 break;
1420 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001421 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001422 break;
1423 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001424 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001425 break;
1426 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001427 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001428 break;
1429 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001430
1431 return 0;
1432}
1433
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001434static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001435{
David Weinehall36cdd012016-08-22 13:59:31 +03001436 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001437 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001438
1439 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001440 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001441 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001442 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001443 fw_domain->wake_count);
1444 }
1445 spin_unlock_irq(&dev_priv->uncore.lock);
1446
1447 return 0;
1448}
1449
Deepak S669ab5a2014-01-10 15:18:26 +05301450static int vlv_drpc_info(struct seq_file *m)
1451{
David Weinehall36cdd012016-08-22 13:59:31 +03001452 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001453 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301454
Imre Deakd46c0512014-04-14 20:24:27 +03001455 intel_runtime_pm_get(dev_priv);
1456
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001457 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301458 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1459 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1460
Imre Deakd46c0512014-04-14 20:24:27 +03001461 intel_runtime_pm_put(dev_priv);
1462
Deepak S669ab5a2014-01-10 15:18:26 +05301463 seq_printf(m, "Video Turbo Mode: %s\n",
1464 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1465 seq_printf(m, "Turbo enabled: %s\n",
1466 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1467 seq_printf(m, "HW control enabled: %s\n",
1468 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1469 seq_printf(m, "SW control enabled: %s\n",
1470 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1471 GEN6_RP_MEDIA_SW_MODE));
1472 seq_printf(m, "RC6 Enabled: %s\n",
1473 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1474 GEN6_RC_CTL_EI_MODE(1))));
1475 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001476 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301477 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001478 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301479
Imre Deak9cc19be2014-04-14 20:24:24 +03001480 seq_printf(m, "Render RC6 residency since boot: %u\n",
1481 I915_READ(VLV_GT_RENDER_RC6));
1482 seq_printf(m, "Media RC6 residency since boot: %u\n",
1483 I915_READ(VLV_GT_MEDIA_RC6));
1484
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001485 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301486}
1487
Ben Widawsky4d855292011-12-12 19:34:16 -08001488static int gen6_drpc_info(struct seq_file *m)
1489{
David Weinehall36cdd012016-08-22 13:59:31 +03001490 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1491 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001492 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301493 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001494 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001495 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001496
1497 ret = mutex_lock_interruptible(&dev->struct_mutex);
1498 if (ret)
1499 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001500 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001501
Chris Wilson907b28c2013-07-19 20:36:52 +01001502 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001503 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001504 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001505
1506 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001507 seq_puts(m, "RC information inaccurate because somebody "
1508 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001509 } else {
1510 /* NB: we cannot use forcewake, else we read the wrong values */
1511 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1512 udelay(10);
1513 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1514 }
1515
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001516 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001517 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001518
1519 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1520 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001521 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301522 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1523 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1524 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001525 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001526 mutex_lock(&dev_priv->rps.hw_lock);
1527 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1528 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001529
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001530 intel_runtime_pm_put(dev_priv);
1531
Ben Widawsky4d855292011-12-12 19:34:16 -08001532 seq_printf(m, "Video Turbo Mode: %s\n",
1533 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1534 seq_printf(m, "HW control enabled: %s\n",
1535 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1536 seq_printf(m, "SW control enabled: %s\n",
1537 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1538 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001539 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001540 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1541 seq_printf(m, "RC6 Enabled: %s\n",
1542 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001543 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301544 seq_printf(m, "Render Well Gating Enabled: %s\n",
1545 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1546 seq_printf(m, "Media Well Gating Enabled: %s\n",
1547 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1548 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001549 seq_printf(m, "Deep RC6 Enabled: %s\n",
1550 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1551 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1552 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001553 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 switch (gt_core_status & GEN6_RCn_MASK) {
1555 case GEN6_RC0:
1556 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001557 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001558 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001559 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001560 break;
1561 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001562 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 break;
1564 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001565 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001566 break;
1567 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001568 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001569 break;
1570 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001571 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001572 break;
1573 }
1574
1575 seq_printf(m, "Core Power Down: %s\n",
1576 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001577 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301578 seq_printf(m, "Render Power Well: %s\n",
1579 (gen9_powergate_status &
1580 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1581 seq_printf(m, "Media Power Well: %s\n",
1582 (gen9_powergate_status &
1583 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1584 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001585
1586 /* Not exactly sure what this is */
1587 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1588 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1589 seq_printf(m, "RC6 residency since boot: %u\n",
1590 I915_READ(GEN6_GT_GFX_RC6));
1591 seq_printf(m, "RC6+ residency since boot: %u\n",
1592 I915_READ(GEN6_GT_GFX_RC6p));
1593 seq_printf(m, "RC6++ residency since boot: %u\n",
1594 I915_READ(GEN6_GT_GFX_RC6pp));
1595
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001596 seq_printf(m, "RC6 voltage: %dmV\n",
1597 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1598 seq_printf(m, "RC6+ voltage: %dmV\n",
1599 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1600 seq_printf(m, "RC6++ voltage: %dmV\n",
1601 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301602 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001603}
1604
1605static int i915_drpc_info(struct seq_file *m, void *unused)
1606{
David Weinehall36cdd012016-08-22 13:59:31 +03001607 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001608
David Weinehall36cdd012016-08-22 13:59:31 +03001609 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301610 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001611 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001612 return gen6_drpc_info(m);
1613 else
1614 return ironlake_drpc_info(m);
1615}
1616
Daniel Vetter9a851782015-06-18 10:30:22 +02001617static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1618{
David Weinehall36cdd012016-08-22 13:59:31 +03001619 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001620
1621 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1622 dev_priv->fb_tracking.busy_bits);
1623
1624 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1625 dev_priv->fb_tracking.flip_bits);
1626
1627 return 0;
1628}
1629
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001630static int i915_fbc_status(struct seq_file *m, void *unused)
1631{
David Weinehall36cdd012016-08-22 13:59:31 +03001632 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001633
David Weinehall36cdd012016-08-22 13:59:31 +03001634 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001635 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001636 return 0;
1637 }
1638
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001639 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001640 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001641
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001642 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001643 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001644 else
1645 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001646 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001647
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001648 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1649 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1650 BDW_FBC_COMPRESSION_MASK :
1651 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001652 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001653 yesno(I915_READ(FBC_STATUS2) & mask));
1654 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001655
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001656 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001657 intel_runtime_pm_put(dev_priv);
1658
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001659 return 0;
1660}
1661
Rodrigo Vivida46f932014-08-01 02:04:45 -07001662static int i915_fbc_fc_get(void *data, u64 *val)
1663{
David Weinehall36cdd012016-08-22 13:59:31 +03001664 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001665
David Weinehall36cdd012016-08-22 13:59:31 +03001666 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001667 return -ENODEV;
1668
Rodrigo Vivida46f932014-08-01 02:04:45 -07001669 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001670
1671 return 0;
1672}
1673
1674static int i915_fbc_fc_set(void *data, u64 val)
1675{
David Weinehall36cdd012016-08-22 13:59:31 +03001676 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001677 u32 reg;
1678
David Weinehall36cdd012016-08-22 13:59:31 +03001679 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001680 return -ENODEV;
1681
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001682 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001683
1684 reg = I915_READ(ILK_DPFC_CONTROL);
1685 dev_priv->fbc.false_color = val;
1686
1687 I915_WRITE(ILK_DPFC_CONTROL, val ?
1688 (reg | FBC_CTL_FALSE_COLOR) :
1689 (reg & ~FBC_CTL_FALSE_COLOR));
1690
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001691 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001692 return 0;
1693}
1694
1695DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1696 i915_fbc_fc_get, i915_fbc_fc_set,
1697 "%llu\n");
1698
Paulo Zanoni92d44622013-05-31 16:33:24 -03001699static int i915_ips_status(struct seq_file *m, void *unused)
1700{
David Weinehall36cdd012016-08-22 13:59:31 +03001701 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001702
David Weinehall36cdd012016-08-22 13:59:31 +03001703 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001704 seq_puts(m, "not supported\n");
1705 return 0;
1706 }
1707
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001708 intel_runtime_pm_get(dev_priv);
1709
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001710 seq_printf(m, "Enabled by kernel parameter: %s\n",
1711 yesno(i915.enable_ips));
1712
David Weinehall36cdd012016-08-22 13:59:31 +03001713 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001714 seq_puts(m, "Currently: unknown\n");
1715 } else {
1716 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1717 seq_puts(m, "Currently: enabled\n");
1718 else
1719 seq_puts(m, "Currently: disabled\n");
1720 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001721
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001722 intel_runtime_pm_put(dev_priv);
1723
Paulo Zanoni92d44622013-05-31 16:33:24 -03001724 return 0;
1725}
1726
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001727static int i915_sr_status(struct seq_file *m, void *unused)
1728{
David Weinehall36cdd012016-08-22 13:59:31 +03001729 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001730 bool sr_enabled = false;
1731
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001732 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001733 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001734
David Weinehall36cdd012016-08-22 13:59:31 +03001735 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001736 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001737 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001738 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001739 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001740 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001741 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001742 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001743 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001744 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001745 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001746
Chris Wilson9c870d02016-10-24 13:42:15 +01001747 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001748 intel_runtime_pm_put(dev_priv);
1749
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001750 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001751
1752 return 0;
1753}
1754
Jesse Barnes7648fa92010-05-20 14:28:11 -07001755static int i915_emon_status(struct seq_file *m, void *unused)
1756{
David Weinehall36cdd012016-08-22 13:59:31 +03001757 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1758 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001759 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001760 int ret;
1761
David Weinehall36cdd012016-08-22 13:59:31 +03001762 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001763 return -ENODEV;
1764
Chris Wilsonde227ef2010-07-03 07:58:38 +01001765 ret = mutex_lock_interruptible(&dev->struct_mutex);
1766 if (ret)
1767 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001768
1769 temp = i915_mch_val(dev_priv);
1770 chipset = i915_chipset_val(dev_priv);
1771 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001772 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001773
1774 seq_printf(m, "GMCH temp: %ld\n", temp);
1775 seq_printf(m, "Chipset power: %ld\n", chipset);
1776 seq_printf(m, "GFX power: %ld\n", gfx);
1777 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1778
1779 return 0;
1780}
1781
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001782static int i915_ring_freq_table(struct seq_file *m, void *unused)
1783{
David Weinehall36cdd012016-08-22 13:59:31 +03001784 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001785 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001786 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301787 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001788
Carlos Santa26310342016-08-17 12:30:41 -07001789 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001790 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001791 return 0;
1792 }
1793
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001794 intel_runtime_pm_get(dev_priv);
1795
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001796 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001797 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001798 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001799
David Weinehall36cdd012016-08-22 13:59:31 +03001800 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301801 /* Convert GT frequency to 50 HZ units */
1802 min_gpu_freq =
1803 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1804 max_gpu_freq =
1805 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1806 } else {
1807 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1808 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1809 }
1810
Damien Lespiau267f0c92013-06-24 22:59:48 +01001811 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001812
Akash Goelf936ec32015-06-29 14:50:22 +05301813 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001814 ia_freq = gpu_freq;
1815 sandybridge_pcode_read(dev_priv,
1816 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1817 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001818 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301819 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001820 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001821 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001822 ((ia_freq >> 0) & 0xff) * 100,
1823 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001824 }
1825
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001826 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001828out:
1829 intel_runtime_pm_put(dev_priv);
1830 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001831}
1832
Chris Wilson44834a62010-08-19 16:09:23 +01001833static int i915_opregion(struct seq_file *m, void *unused)
1834{
David Weinehall36cdd012016-08-22 13:59:31 +03001835 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1836 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001837 struct intel_opregion *opregion = &dev_priv->opregion;
1838 int ret;
1839
1840 ret = mutex_lock_interruptible(&dev->struct_mutex);
1841 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001842 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001843
Jani Nikula2455a8e2015-12-14 12:50:53 +02001844 if (opregion->header)
1845 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001846
1847 mutex_unlock(&dev->struct_mutex);
1848
Daniel Vetter0d38f002012-04-21 22:49:10 +02001849out:
Chris Wilson44834a62010-08-19 16:09:23 +01001850 return 0;
1851}
1852
Jani Nikulaada8f952015-12-15 13:17:12 +02001853static int i915_vbt(struct seq_file *m, void *unused)
1854{
David Weinehall36cdd012016-08-22 13:59:31 +03001855 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001856
1857 if (opregion->vbt)
1858 seq_write(m, opregion->vbt, opregion->vbt_size);
1859
1860 return 0;
1861}
1862
Chris Wilson37811fc2010-08-25 22:45:57 +01001863static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1864{
David Weinehall36cdd012016-08-22 13:59:31 +03001865 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1866 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301867 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001868 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001869 int ret;
1870
1871 ret = mutex_lock_interruptible(&dev->struct_mutex);
1872 if (ret)
1873 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001874
Daniel Vetter06957262015-08-10 13:34:08 +02001875#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001876 if (dev_priv->fbdev) {
1877 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001878
Chris Wilson25bcce92016-07-02 15:36:00 +01001879 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1880 fbdev_fb->base.width,
1881 fbdev_fb->base.height,
1882 fbdev_fb->base.depth,
1883 fbdev_fb->base.bits_per_pixel,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001884 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001885 drm_framebuffer_read_refcount(&fbdev_fb->base));
1886 describe_obj(m, fbdev_fb->obj);
1887 seq_putc(m, '\n');
1888 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001889#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001890
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001891 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001892 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301893 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1894 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001895 continue;
1896
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001897 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 +01001898 fb->base.width,
1899 fb->base.height,
1900 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001901 fb->base.bits_per_pixel,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001902 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001903 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001904 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001905 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001906 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001907 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001908 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001909
1910 return 0;
1911}
1912
Chris Wilson7e37f882016-08-02 22:50:21 +01001913static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001914{
1915 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001916 ring->space, ring->head, ring->tail,
1917 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001918}
1919
Ben Widawskye76d3632011-03-19 18:14:29 -07001920static int i915_context_status(struct seq_file *m, void *unused)
1921{
David Weinehall36cdd012016-08-22 13:59:31 +03001922 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1923 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001924 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001925 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301926 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001927 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001928
Daniel Vetterf3d28872014-05-29 23:23:08 +02001929 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001930 if (ret)
1931 return ret;
1932
Ben Widawskya33afea2013-09-17 21:12:45 -07001933 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001934 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001935 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001936 struct task_struct *task;
1937
Chris Wilsonc84455b2016-08-15 10:49:08 +01001938 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001939 if (task) {
1940 seq_printf(m, "(%s [%d]) ",
1941 task->comm, task->pid);
1942 put_task_struct(task);
1943 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001944 } else if (IS_ERR(ctx->file_priv)) {
1945 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001946 } else {
1947 seq_puts(m, "(kernel) ");
1948 }
1949
Chris Wilsonbca44d82016-05-24 14:53:41 +01001950 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1951 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001952
Akash Goel3b3f1652016-10-13 22:44:48 +05301953 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001954 struct intel_context *ce = &ctx->engine[engine->id];
1955
1956 seq_printf(m, "%s: ", engine->name);
1957 seq_putc(m, ce->initialised ? 'I' : 'i');
1958 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001959 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001960 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001961 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001962 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001963 }
1964
Ben Widawskya33afea2013-09-17 21:12:45 -07001965 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001966 }
1967
Daniel Vetterf3d28872014-05-29 23:23:08 +02001968 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001969
1970 return 0;
1971}
1972
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001973static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001974 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001975 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001976{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001977 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001978 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001979 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001980
Chris Wilson7069b142016-04-28 09:56:52 +01001981 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1982
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001983 if (!vma) {
1984 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001985 return;
1986 }
1987
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001988 if (vma->flags & I915_VMA_GLOBAL_BIND)
1989 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01001990 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001991
Chris Wilsona4f5ea62016-10-28 13:58:35 +01001992 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001993 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001994 return;
1995 }
1996
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001997 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
1998 if (page) {
1999 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002000
2001 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002002 seq_printf(m,
2003 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2004 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002005 reg_state[j], reg_state[j + 1],
2006 reg_state[j + 2], reg_state[j + 3]);
2007 }
2008 kunmap_atomic(reg_state);
2009 }
2010
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002011 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002012 seq_putc(m, '\n');
2013}
2014
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002015static int i915_dump_lrc(struct seq_file *m, void *unused)
2016{
David Weinehall36cdd012016-08-22 13:59:31 +03002017 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2018 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002019 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002020 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302021 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002022 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002023
2024 if (!i915.enable_execlists) {
2025 seq_printf(m, "Logical Ring Contexts are disabled\n");
2026 return 0;
2027 }
2028
2029 ret = mutex_lock_interruptible(&dev->struct_mutex);
2030 if (ret)
2031 return ret;
2032
Dave Gordone28e4042016-01-19 19:02:55 +00002033 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302034 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002035 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002036
2037 mutex_unlock(&dev->struct_mutex);
2038
2039 return 0;
2040}
2041
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002042static const char *swizzle_string(unsigned swizzle)
2043{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002044 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002045 case I915_BIT_6_SWIZZLE_NONE:
2046 return "none";
2047 case I915_BIT_6_SWIZZLE_9:
2048 return "bit9";
2049 case I915_BIT_6_SWIZZLE_9_10:
2050 return "bit9/bit10";
2051 case I915_BIT_6_SWIZZLE_9_11:
2052 return "bit9/bit11";
2053 case I915_BIT_6_SWIZZLE_9_10_11:
2054 return "bit9/bit10/bit11";
2055 case I915_BIT_6_SWIZZLE_9_17:
2056 return "bit9/bit17";
2057 case I915_BIT_6_SWIZZLE_9_10_17:
2058 return "bit9/bit10/bit17";
2059 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002060 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002061 }
2062
2063 return "bug";
2064}
2065
2066static int i915_swizzle_info(struct seq_file *m, void *data)
2067{
David Weinehall36cdd012016-08-22 13:59:31 +03002068 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002069
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002070 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002071
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002072 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2073 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2074 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2075 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2076
David Weinehall36cdd012016-08-22 13:59:31 +03002077 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002078 seq_printf(m, "DDC = 0x%08x\n",
2079 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002080 seq_printf(m, "DDC2 = 0x%08x\n",
2081 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002082 seq_printf(m, "C0DRB3 = 0x%04x\n",
2083 I915_READ16(C0DRB3));
2084 seq_printf(m, "C1DRB3 = 0x%04x\n",
2085 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002086 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002087 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2088 I915_READ(MAD_DIMM_C0));
2089 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2090 I915_READ(MAD_DIMM_C1));
2091 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2092 I915_READ(MAD_DIMM_C2));
2093 seq_printf(m, "TILECTL = 0x%08x\n",
2094 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002095 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002096 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2097 I915_READ(GAMTARBMODE));
2098 else
2099 seq_printf(m, "ARB_MODE = 0x%08x\n",
2100 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002101 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2102 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002103 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002104
2105 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2106 seq_puts(m, "L-shaped memory detected\n");
2107
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002108 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002109
2110 return 0;
2111}
2112
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002113static int per_file_ctx(int id, void *ptr, void *data)
2114{
Chris Wilsone2efd132016-05-24 14:53:34 +01002115 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002116 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002117 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2118
2119 if (!ppgtt) {
2120 seq_printf(m, " no ppgtt for context %d\n",
2121 ctx->user_handle);
2122 return 0;
2123 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002124
Oscar Mateof83d6512014-05-22 14:13:38 +01002125 if (i915_gem_context_is_default(ctx))
2126 seq_puts(m, " default context:\n");
2127 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002128 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002129 ppgtt->debug_dump(ppgtt, m);
2130
2131 return 0;
2132}
2133
David Weinehall36cdd012016-08-22 13:59:31 +03002134static void gen8_ppgtt_info(struct seq_file *m,
2135 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002136{
Ben Widawsky77df6772013-11-02 21:07:30 -07002137 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302138 struct intel_engine_cs *engine;
2139 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002140 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002141
Ben Widawsky77df6772013-11-02 21:07:30 -07002142 if (!ppgtt)
2143 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002144
Akash Goel3b3f1652016-10-13 22:44:48 +05302145 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002146 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002147 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002148 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002149 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002150 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002151 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002152 }
2153 }
2154}
2155
David Weinehall36cdd012016-08-22 13:59:31 +03002156static void gen6_ppgtt_info(struct seq_file *m,
2157 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002158{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002159 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302160 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002161
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002162 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002163 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2164
Akash Goel3b3f1652016-10-13 22:44:48 +05302165 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002166 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002167 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002168 seq_printf(m, "GFX_MODE: 0x%08x\n",
2169 I915_READ(RING_MODE_GEN7(engine)));
2170 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2171 I915_READ(RING_PP_DIR_BASE(engine)));
2172 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2173 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2174 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2175 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002176 }
2177 if (dev_priv->mm.aliasing_ppgtt) {
2178 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2179
Damien Lespiau267f0c92013-06-24 22:59:48 +01002180 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002181 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002182
Ben Widawsky87d60b62013-12-06 14:11:29 -08002183 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002184 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002185
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002186 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002187}
2188
2189static int i915_ppgtt_info(struct seq_file *m, void *data)
2190{
David Weinehall36cdd012016-08-22 13:59:31 +03002191 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2192 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002193 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002194 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002195
Chris Wilson637ee292016-08-22 14:28:20 +01002196 mutex_lock(&dev->filelist_mutex);
2197 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002198 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002199 goto out_unlock;
2200
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002201 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002202
David Weinehall36cdd012016-08-22 13:59:31 +03002203 if (INTEL_GEN(dev_priv) >= 8)
2204 gen8_ppgtt_info(m, dev_priv);
2205 else if (INTEL_GEN(dev_priv) >= 6)
2206 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002207
Michel Thierryea91e402015-07-29 17:23:57 +01002208 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2209 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002210 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002211
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002212 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002213 if (!task) {
2214 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002215 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002216 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002217 seq_printf(m, "\nproc: %s\n", task->comm);
2218 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002219 idr_for_each(&file_priv->context_idr, per_file_ctx,
2220 (void *)(unsigned long)m);
2221 }
2222
Chris Wilson637ee292016-08-22 14:28:20 +01002223out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002224 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002225 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002226out_unlock:
2227 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002228 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002229}
2230
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002231static int count_irq_waiters(struct drm_i915_private *i915)
2232{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002233 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302234 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002235 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002236
Akash Goel3b3f1652016-10-13 22:44:48 +05302237 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002238 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002239
2240 return count;
2241}
2242
Chris Wilson7466c292016-08-15 09:49:33 +01002243static const char *rps_power_to_str(unsigned int power)
2244{
2245 static const char * const strings[] = {
2246 [LOW_POWER] = "low power",
2247 [BETWEEN] = "mixed",
2248 [HIGH_POWER] = "high power",
2249 };
2250
2251 if (power >= ARRAY_SIZE(strings) || !strings[power])
2252 return "unknown";
2253
2254 return strings[power];
2255}
2256
Chris Wilson1854d5c2015-04-07 16:20:32 +01002257static int i915_rps_boost_info(struct seq_file *m, void *data)
2258{
David Weinehall36cdd012016-08-22 13:59:31 +03002259 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2260 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002261 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002262
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002263 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002264 seq_printf(m, "GPU busy? %s [%d requests]\n",
2265 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002266 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002267 seq_printf(m, "Frequency requested %d\n",
2268 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2269 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002270 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2271 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2272 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2273 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002274 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2275 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2276 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2277 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002278
2279 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002280 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002281 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2282 struct drm_i915_file_private *file_priv = file->driver_priv;
2283 struct task_struct *task;
2284
2285 rcu_read_lock();
2286 task = pid_task(file->pid, PIDTYPE_PID);
2287 seq_printf(m, "%s [%d]: %d boosts%s\n",
2288 task ? task->comm : "<unknown>",
2289 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002290 file_priv->rps.boosts,
2291 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002292 rcu_read_unlock();
2293 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002294 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002295 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002296 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002297
Chris Wilson7466c292016-08-15 09:49:33 +01002298 if (INTEL_GEN(dev_priv) >= 6 &&
2299 dev_priv->rps.enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002300 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002301 u32 rpup, rpupei;
2302 u32 rpdown, rpdownei;
2303
2304 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2305 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2306 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2307 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2308 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2309 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2310
2311 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2312 rps_power_to_str(dev_priv->rps.power));
2313 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2314 100 * rpup / rpupei,
2315 dev_priv->rps.up_threshold);
2316 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2317 100 * rpdown / rpdownei,
2318 dev_priv->rps.down_threshold);
2319 } else {
2320 seq_puts(m, "\nRPS Autotuning inactive\n");
2321 }
2322
Chris Wilson8d3afd72015-05-21 21:01:47 +01002323 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002324}
2325
Ben Widawsky63573eb2013-07-04 11:02:07 -07002326static int i915_llc(struct seq_file *m, void *data)
2327{
David Weinehall36cdd012016-08-22 13:59:31 +03002328 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002329 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002330
David Weinehall36cdd012016-08-22 13:59:31 +03002331 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002332 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2333 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002334
2335 return 0;
2336}
2337
Alex Daifdf5d352015-08-12 15:43:37 +01002338static int i915_guc_load_status_info(struct seq_file *m, void *data)
2339{
David Weinehall36cdd012016-08-22 13:59:31 +03002340 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002341 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2342 u32 tmp, i;
2343
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002344 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002345 return 0;
2346
2347 seq_printf(m, "GuC firmware status:\n");
2348 seq_printf(m, "\tpath: %s\n",
2349 guc_fw->guc_fw_path);
2350 seq_printf(m, "\tfetch: %s\n",
2351 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2352 seq_printf(m, "\tload: %s\n",
2353 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2354 seq_printf(m, "\tversion wanted: %d.%d\n",
2355 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2356 seq_printf(m, "\tversion found: %d.%d\n",
2357 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002358 seq_printf(m, "\theader: offset is %d; size = %d\n",
2359 guc_fw->header_offset, guc_fw->header_size);
2360 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2361 guc_fw->ucode_offset, guc_fw->ucode_size);
2362 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2363 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002364
2365 tmp = I915_READ(GUC_STATUS);
2366
2367 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2368 seq_printf(m, "\tBootrom status = 0x%x\n",
2369 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2370 seq_printf(m, "\tuKernel status = 0x%x\n",
2371 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2372 seq_printf(m, "\tMIA Core status = 0x%x\n",
2373 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2374 seq_puts(m, "\nScratch registers:\n");
2375 for (i = 0; i < 16; i++)
2376 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2377
2378 return 0;
2379}
2380
Akash Goel5aa1ee42016-10-12 21:54:36 +05302381static void i915_guc_log_info(struct seq_file *m,
2382 struct drm_i915_private *dev_priv)
2383{
2384 struct intel_guc *guc = &dev_priv->guc;
2385
2386 seq_puts(m, "\nGuC logging stats:\n");
2387
2388 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2389 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2390 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2391
2392 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2393 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2394 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2395
2396 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2397 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2398 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2399
2400 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2401 guc->log.flush_interrupt_count);
2402
2403 seq_printf(m, "\tCapture miss count: %u\n",
2404 guc->log.capture_miss_count);
2405}
2406
Dave Gordon8b417c22015-08-12 15:43:44 +01002407static void i915_guc_client_info(struct seq_file *m,
2408 struct drm_i915_private *dev_priv,
2409 struct i915_guc_client *client)
2410{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002411 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002412 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002413 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002414
2415 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2416 client->priority, client->ctx_index, client->proc_desc_offset);
2417 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
Chris Wilson357248b2016-11-29 12:10:21 +00002418 client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
Dave Gordon8b417c22015-08-12 15:43:44 +01002419 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2420 client->wq_size, client->wq_offset, client->wq_tail);
2421
Dave Gordon551aaec2016-05-13 15:36:33 +01002422 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002423 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2424 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2425
Akash Goel3b3f1652016-10-13 22:44:48 +05302426 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002427 u64 submissions = client->submissions[id];
2428 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002429 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002430 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002431 }
2432 seq_printf(m, "\tTotal: %llu\n", tot);
2433}
2434
2435static int i915_guc_info(struct seq_file *m, void *data)
2436{
David Weinehall36cdd012016-08-22 13:59:31 +03002437 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002438 const struct intel_guc *guc = &dev_priv->guc;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002439 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002440 enum intel_engine_id id;
Chris Wilson334636c2016-11-29 12:10:20 +00002441 u64 total;
Dave Gordon8b417c22015-08-12 15:43:44 +01002442
Chris Wilson334636c2016-11-29 12:10:20 +00002443 if (!guc->execbuf_client) {
2444 seq_printf(m, "GuC submission %s\n",
2445 HAS_GUC_SCHED(dev_priv) ?
2446 "disabled" :
2447 "not supported");
Dave Gordon8b417c22015-08-12 15:43:44 +01002448 return 0;
Chris Wilson334636c2016-11-29 12:10:20 +00002449 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002450
Dave Gordon9636f6d2016-06-13 17:57:28 +01002451 seq_printf(m, "Doorbell map:\n");
Chris Wilson334636c2016-11-29 12:10:20 +00002452 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc->doorbell_bitmap);
2453 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002454
Chris Wilson334636c2016-11-29 12:10:20 +00002455 seq_printf(m, "GuC total action count: %llu\n", guc->action_count);
2456 seq_printf(m, "GuC action failure count: %u\n", guc->action_fail);
2457 seq_printf(m, "GuC last action command: 0x%x\n", guc->action_cmd);
2458 seq_printf(m, "GuC last action status: 0x%x\n", guc->action_status);
2459 seq_printf(m, "GuC last action error code: %d\n", guc->action_err);
Dave Gordon8b417c22015-08-12 15:43:44 +01002460
Chris Wilson334636c2016-11-29 12:10:20 +00002461 total = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002462 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302463 for_each_engine(engine, dev_priv, id) {
Chris Wilson334636c2016-11-29 12:10:20 +00002464 u64 submissions = guc->submissions[id];
Dave Gordonc18468c2016-08-09 15:19:22 +01002465 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002466 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Chris Wilson334636c2016-11-29 12:10:20 +00002467 engine->name, submissions, guc->last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002468 }
2469 seq_printf(m, "\t%s: %llu\n", "Total", total);
2470
Chris Wilson334636c2016-11-29 12:10:20 +00002471 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2472 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002473
Akash Goel5aa1ee42016-10-12 21:54:36 +05302474 i915_guc_log_info(m, dev_priv);
2475
Dave Gordon8b417c22015-08-12 15:43:44 +01002476 /* Add more as required ... */
2477
2478 return 0;
2479}
2480
Alex Dai4c7e77f2015-08-12 15:43:40 +01002481static int i915_guc_log_dump(struct seq_file *m, void *data)
2482{
David Weinehall36cdd012016-08-22 13:59:31 +03002483 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002484 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002485 int i = 0, pg;
2486
Akash Goeld6b40b42016-10-12 21:54:29 +05302487 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002488 return 0;
2489
Akash Goeld6b40b42016-10-12 21:54:29 +05302490 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002491 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2492 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002493
2494 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2495 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2496 *(log + i), *(log + i + 1),
2497 *(log + i + 2), *(log + i + 3));
2498
2499 kunmap_atomic(log);
2500 }
2501
2502 seq_putc(m, '\n');
2503
2504 return 0;
2505}
2506
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302507static int i915_guc_log_control_get(void *data, u64 *val)
2508{
2509 struct drm_device *dev = data;
2510 struct drm_i915_private *dev_priv = to_i915(dev);
2511
2512 if (!dev_priv->guc.log.vma)
2513 return -EINVAL;
2514
2515 *val = i915.guc_log_level;
2516
2517 return 0;
2518}
2519
2520static int i915_guc_log_control_set(void *data, u64 val)
2521{
2522 struct drm_device *dev = data;
2523 struct drm_i915_private *dev_priv = to_i915(dev);
2524 int ret;
2525
2526 if (!dev_priv->guc.log.vma)
2527 return -EINVAL;
2528
2529 ret = mutex_lock_interruptible(&dev->struct_mutex);
2530 if (ret)
2531 return ret;
2532
2533 intel_runtime_pm_get(dev_priv);
2534 ret = i915_guc_log_control(dev_priv, val);
2535 intel_runtime_pm_put(dev_priv);
2536
2537 mutex_unlock(&dev->struct_mutex);
2538 return ret;
2539}
2540
2541DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2542 i915_guc_log_control_get, i915_guc_log_control_set,
2543 "%lld\n");
2544
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002545static int i915_edp_psr_status(struct seq_file *m, void *data)
2546{
David Weinehall36cdd012016-08-22 13:59:31 +03002547 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002548 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002549 u32 stat[3];
2550 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002551 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002552
David Weinehall36cdd012016-08-22 13:59:31 +03002553 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002554 seq_puts(m, "PSR not supported\n");
2555 return 0;
2556 }
2557
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002558 intel_runtime_pm_get(dev_priv);
2559
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002560 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002561 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2562 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002563 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002564 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002565 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2566 dev_priv->psr.busy_frontbuffer_bits);
2567 seq_printf(m, "Re-enable work scheduled: %s\n",
2568 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002569
David Weinehall36cdd012016-08-22 13:59:31 +03002570 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002571 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002572 else {
2573 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002574 enum transcoder cpu_transcoder =
2575 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2576 enum intel_display_power_domain power_domain;
2577
2578 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2579 if (!intel_display_power_get_if_enabled(dev_priv,
2580 power_domain))
2581 continue;
2582
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002583 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2584 VLV_EDP_PSR_CURR_STATE_MASK;
2585 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2586 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2587 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002588
2589 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002590 }
2591 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002592
2593 seq_printf(m, "Main link in standby mode: %s\n",
2594 yesno(dev_priv->psr.link_standby));
2595
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002596 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002597
David Weinehall36cdd012016-08-22 13:59:31 +03002598 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002599 for_each_pipe(dev_priv, pipe) {
2600 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2601 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2602 seq_printf(m, " pipe %c", pipe_name(pipe));
2603 }
2604 seq_puts(m, "\n");
2605
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002606 /*
2607 * VLV/CHV PSR has no kind of performance counter
2608 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2609 */
David Weinehall36cdd012016-08-22 13:59:31 +03002610 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002611 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002612 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002613
2614 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2615 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002616 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002617
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002618 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002619 return 0;
2620}
2621
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002622static int i915_sink_crc(struct seq_file *m, void *data)
2623{
David Weinehall36cdd012016-08-22 13:59:31 +03002624 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2625 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002626 struct intel_connector *connector;
2627 struct intel_dp *intel_dp = NULL;
2628 int ret;
2629 u8 crc[6];
2630
2631 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002632 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002633 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002634
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002635 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002636 continue;
2637
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002638 crtc = connector->base.state->crtc;
2639 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002640 continue;
2641
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002642 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002643 continue;
2644
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002645 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002646
2647 ret = intel_dp_sink_crc(intel_dp, crc);
2648 if (ret)
2649 goto out;
2650
2651 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2652 crc[0], crc[1], crc[2],
2653 crc[3], crc[4], crc[5]);
2654 goto out;
2655 }
2656 ret = -ENODEV;
2657out:
2658 drm_modeset_unlock_all(dev);
2659 return ret;
2660}
2661
Jesse Barnesec013e72013-08-20 10:29:23 +01002662static int i915_energy_uJ(struct seq_file *m, void *data)
2663{
David Weinehall36cdd012016-08-22 13:59:31 +03002664 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002665 u64 power;
2666 u32 units;
2667
David Weinehall36cdd012016-08-22 13:59:31 +03002668 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002669 return -ENODEV;
2670
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002671 intel_runtime_pm_get(dev_priv);
2672
Jesse Barnesec013e72013-08-20 10:29:23 +01002673 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2674 power = (power & 0x1f00) >> 8;
2675 units = 1000000 / (1 << power); /* convert to uJ */
2676 power = I915_READ(MCH_SECP_NRG_STTS);
2677 power *= units;
2678
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002679 intel_runtime_pm_put(dev_priv);
2680
Jesse Barnesec013e72013-08-20 10:29:23 +01002681 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002682
2683 return 0;
2684}
2685
Damien Lespiau6455c872015-06-04 18:23:57 +01002686static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002687{
David Weinehall36cdd012016-08-22 13:59:31 +03002688 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002689 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002690
Chris Wilsona156e642016-04-03 14:14:21 +01002691 if (!HAS_RUNTIME_PM(dev_priv))
2692 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002693
Chris Wilson67d97da2016-07-04 08:08:31 +01002694 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002695 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002696 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002697#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002698 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002699 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002700#else
2701 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2702#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002703 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002704 pci_power_name(pdev->current_state),
2705 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002706
Jesse Barnesec013e72013-08-20 10:29:23 +01002707 return 0;
2708}
2709
Imre Deak1da51582013-11-25 17:15:35 +02002710static int i915_power_domain_info(struct seq_file *m, void *unused)
2711{
David Weinehall36cdd012016-08-22 13:59:31 +03002712 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002713 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2714 int i;
2715
2716 mutex_lock(&power_domains->lock);
2717
2718 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2719 for (i = 0; i < power_domains->power_well_count; i++) {
2720 struct i915_power_well *power_well;
2721 enum intel_display_power_domain power_domain;
2722
2723 power_well = &power_domains->power_wells[i];
2724 seq_printf(m, "%-25s %d\n", power_well->name,
2725 power_well->count);
2726
2727 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2728 power_domain++) {
2729 if (!(BIT(power_domain) & power_well->domains))
2730 continue;
2731
2732 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002733 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002734 power_domains->domain_use_count[power_domain]);
2735 }
2736 }
2737
2738 mutex_unlock(&power_domains->lock);
2739
2740 return 0;
2741}
2742
Damien Lespiaub7cec662015-10-27 14:47:01 +02002743static int i915_dmc_info(struct seq_file *m, void *unused)
2744{
David Weinehall36cdd012016-08-22 13:59:31 +03002745 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002746 struct intel_csr *csr;
2747
David Weinehall36cdd012016-08-22 13:59:31 +03002748 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002749 seq_puts(m, "not supported\n");
2750 return 0;
2751 }
2752
2753 csr = &dev_priv->csr;
2754
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002755 intel_runtime_pm_get(dev_priv);
2756
Damien Lespiaub7cec662015-10-27 14:47:01 +02002757 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2758 seq_printf(m, "path: %s\n", csr->fw_path);
2759
2760 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002761 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002762
2763 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2764 CSR_VERSION_MINOR(csr->version));
2765
David Weinehall36cdd012016-08-22 13:59:31 +03002766 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002767 seq_printf(m, "DC3 -> DC5 count: %d\n",
2768 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2769 seq_printf(m, "DC5 -> DC6 count: %d\n",
2770 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002771 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002772 seq_printf(m, "DC3 -> DC5 count: %d\n",
2773 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002774 }
2775
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002776out:
2777 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2778 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2779 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2780
Damien Lespiau83372062015-10-30 17:53:32 +02002781 intel_runtime_pm_put(dev_priv);
2782
Damien Lespiaub7cec662015-10-27 14:47:01 +02002783 return 0;
2784}
2785
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002786static void intel_seq_print_mode(struct seq_file *m, int tabs,
2787 struct drm_display_mode *mode)
2788{
2789 int i;
2790
2791 for (i = 0; i < tabs; i++)
2792 seq_putc(m, '\t');
2793
2794 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",
2795 mode->base.id, mode->name,
2796 mode->vrefresh, mode->clock,
2797 mode->hdisplay, mode->hsync_start,
2798 mode->hsync_end, mode->htotal,
2799 mode->vdisplay, mode->vsync_start,
2800 mode->vsync_end, mode->vtotal,
2801 mode->type, mode->flags);
2802}
2803
2804static void intel_encoder_info(struct seq_file *m,
2805 struct intel_crtc *intel_crtc,
2806 struct intel_encoder *intel_encoder)
2807{
David Weinehall36cdd012016-08-22 13:59:31 +03002808 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2809 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002810 struct drm_crtc *crtc = &intel_crtc->base;
2811 struct intel_connector *intel_connector;
2812 struct drm_encoder *encoder;
2813
2814 encoder = &intel_encoder->base;
2815 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002816 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002817 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2818 struct drm_connector *connector = &intel_connector->base;
2819 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2820 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002821 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002822 drm_get_connector_status_name(connector->status));
2823 if (connector->status == connector_status_connected) {
2824 struct drm_display_mode *mode = &crtc->mode;
2825 seq_printf(m, ", mode:\n");
2826 intel_seq_print_mode(m, 2, mode);
2827 } else {
2828 seq_putc(m, '\n');
2829 }
2830 }
2831}
2832
2833static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2834{
David Weinehall36cdd012016-08-22 13:59:31 +03002835 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2836 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002837 struct drm_crtc *crtc = &intel_crtc->base;
2838 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002839 struct drm_plane_state *plane_state = crtc->primary->state;
2840 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002841
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002842 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002843 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002844 fb->base.id, plane_state->src_x >> 16,
2845 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002846 else
2847 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002848 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2849 intel_encoder_info(m, intel_crtc, intel_encoder);
2850}
2851
2852static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2853{
2854 struct drm_display_mode *mode = panel->fixed_mode;
2855
2856 seq_printf(m, "\tfixed mode:\n");
2857 intel_seq_print_mode(m, 2, mode);
2858}
2859
2860static void intel_dp_info(struct seq_file *m,
2861 struct intel_connector *intel_connector)
2862{
2863 struct intel_encoder *intel_encoder = intel_connector->encoder;
2864 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2865
2866 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002867 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002868 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002869 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002870
2871 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2872 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002873}
2874
Libin Yang9a148a92016-11-28 20:07:05 +08002875static void intel_dp_mst_info(struct seq_file *m,
2876 struct intel_connector *intel_connector)
2877{
2878 struct intel_encoder *intel_encoder = intel_connector->encoder;
2879 struct intel_dp_mst_encoder *intel_mst =
2880 enc_to_mst(&intel_encoder->base);
2881 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2882 struct intel_dp *intel_dp = &intel_dig_port->dp;
2883 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2884 intel_connector->port);
2885
2886 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2887}
2888
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002889static void intel_hdmi_info(struct seq_file *m,
2890 struct intel_connector *intel_connector)
2891{
2892 struct intel_encoder *intel_encoder = intel_connector->encoder;
2893 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2894
Jani Nikula742f4912015-09-03 11:16:09 +03002895 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002896}
2897
2898static void intel_lvds_info(struct seq_file *m,
2899 struct intel_connector *intel_connector)
2900{
2901 intel_panel_info(m, &intel_connector->panel);
2902}
2903
2904static void intel_connector_info(struct seq_file *m,
2905 struct drm_connector *connector)
2906{
2907 struct intel_connector *intel_connector = to_intel_connector(connector);
2908 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002909 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002910
2911 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002912 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002913 drm_get_connector_status_name(connector->status));
2914 if (connector->status == connector_status_connected) {
2915 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2916 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2917 connector->display_info.width_mm,
2918 connector->display_info.height_mm);
2919 seq_printf(m, "\tsubpixel order: %s\n",
2920 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2921 seq_printf(m, "\tCEA rev: %d\n",
2922 connector->display_info.cea_rev);
2923 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002924
2925 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2926 return;
2927
2928 switch (connector->connector_type) {
2929 case DRM_MODE_CONNECTOR_DisplayPort:
2930 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08002931 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
2932 intel_dp_mst_info(m, intel_connector);
2933 else
2934 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002935 break;
2936 case DRM_MODE_CONNECTOR_LVDS:
2937 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002938 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002939 break;
2940 case DRM_MODE_CONNECTOR_HDMIA:
2941 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2942 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2943 intel_hdmi_info(m, intel_connector);
2944 break;
2945 default:
2946 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002947 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002948
Jesse Barnesf103fc72014-02-20 12:39:57 -08002949 seq_printf(m, "\tmodes:\n");
2950 list_for_each_entry(mode, &connector->modes, head)
2951 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002952}
2953
David Weinehall36cdd012016-08-22 13:59:31 +03002954static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002955{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002956 u32 state;
2957
Jani Nikula2a307c22016-11-30 17:43:04 +02002958 if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002959 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002960 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002961 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002962
2963 return state;
2964}
2965
David Weinehall36cdd012016-08-22 13:59:31 +03002966static bool cursor_position(struct drm_i915_private *dev_priv,
2967 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002968{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002969 u32 pos;
2970
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002971 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002972
2973 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2974 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2975 *x = -*x;
2976
2977 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2978 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2979 *y = -*y;
2980
David Weinehall36cdd012016-08-22 13:59:31 +03002981 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002982}
2983
Robert Fekete3abc4e02015-10-27 16:58:32 +01002984static const char *plane_type(enum drm_plane_type type)
2985{
2986 switch (type) {
2987 case DRM_PLANE_TYPE_OVERLAY:
2988 return "OVL";
2989 case DRM_PLANE_TYPE_PRIMARY:
2990 return "PRI";
2991 case DRM_PLANE_TYPE_CURSOR:
2992 return "CUR";
2993 /*
2994 * Deliberately omitting default: to generate compiler warnings
2995 * when a new drm_plane_type gets added.
2996 */
2997 }
2998
2999 return "unknown";
3000}
3001
3002static const char *plane_rotation(unsigned int rotation)
3003{
3004 static char buf[48];
3005 /*
3006 * According to doc only one DRM_ROTATE_ is allowed but this
3007 * will print them all to visualize if the values are misused
3008 */
3009 snprintf(buf, sizeof(buf),
3010 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003011 (rotation & DRM_ROTATE_0) ? "0 " : "",
3012 (rotation & DRM_ROTATE_90) ? "90 " : "",
3013 (rotation & DRM_ROTATE_180) ? "180 " : "",
3014 (rotation & DRM_ROTATE_270) ? "270 " : "",
3015 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3016 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003017 rotation);
3018
3019 return buf;
3020}
3021
3022static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3023{
David Weinehall36cdd012016-08-22 13:59:31 +03003024 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3025 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003026 struct intel_plane *intel_plane;
3027
3028 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3029 struct drm_plane_state *state;
3030 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003031 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003032
3033 if (!plane->state) {
3034 seq_puts(m, "plane->state is NULL!\n");
3035 continue;
3036 }
3037
3038 state = plane->state;
3039
Eric Engestrom90844f02016-08-15 01:02:38 +01003040 if (state->fb) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003041 drm_get_format_name(state->fb->pixel_format, &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003042 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003043 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003044 }
3045
Robert Fekete3abc4e02015-10-27 16:58:32 +01003046 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",
3047 plane->base.id,
3048 plane_type(intel_plane->base.type),
3049 state->crtc_x, state->crtc_y,
3050 state->crtc_w, state->crtc_h,
3051 (state->src_x >> 16),
3052 ((state->src_x & 0xffff) * 15625) >> 10,
3053 (state->src_y >> 16),
3054 ((state->src_y & 0xffff) * 15625) >> 10,
3055 (state->src_w >> 16),
3056 ((state->src_w & 0xffff) * 15625) >> 10,
3057 (state->src_h >> 16),
3058 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003059 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003060 plane_rotation(state->rotation));
3061 }
3062}
3063
3064static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3065{
3066 struct intel_crtc_state *pipe_config;
3067 int num_scalers = intel_crtc->num_scalers;
3068 int i;
3069
3070 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3071
3072 /* Not all platformas have a scaler */
3073 if (num_scalers) {
3074 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3075 num_scalers,
3076 pipe_config->scaler_state.scaler_users,
3077 pipe_config->scaler_state.scaler_id);
3078
A.Sunil Kamath58415912016-11-20 23:20:26 +05303079 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003080 struct intel_scaler *sc =
3081 &pipe_config->scaler_state.scalers[i];
3082
3083 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3084 i, yesno(sc->in_use), sc->mode);
3085 }
3086 seq_puts(m, "\n");
3087 } else {
3088 seq_puts(m, "\tNo scalers available on this platform\n");
3089 }
3090}
3091
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003092static int i915_display_info(struct seq_file *m, void *unused)
3093{
David Weinehall36cdd012016-08-22 13:59:31 +03003094 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3095 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003096 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003097 struct drm_connector *connector;
3098
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003099 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003100 drm_modeset_lock_all(dev);
3101 seq_printf(m, "CRTC info\n");
3102 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003103 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003104 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003105 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003106 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003107
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003108 pipe_config = to_intel_crtc_state(crtc->base.state);
3109
Robert Fekete3abc4e02015-10-27 16:58:32 +01003110 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003111 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003112 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003113 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3114 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3115
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003116 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003117 intel_crtc_info(m, crtc);
3118
David Weinehall36cdd012016-08-22 13:59:31 +03003119 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003120 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 +03003121 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003122 x, y, crtc->base.cursor->state->crtc_w,
3123 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003124 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003125 intel_scaler_info(m, crtc);
3126 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003127 }
Daniel Vettercace8412014-05-22 17:56:31 +02003128
3129 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3130 yesno(!crtc->cpu_fifo_underrun_disabled),
3131 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003132 }
3133
3134 seq_printf(m, "\n");
3135 seq_printf(m, "Connector info\n");
3136 seq_printf(m, "--------------\n");
3137 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3138 intel_connector_info(m, connector);
3139 }
3140 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003141 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003142
3143 return 0;
3144}
3145
Chris Wilson1b365952016-10-04 21:11:31 +01003146static int i915_engine_info(struct seq_file *m, void *unused)
3147{
3148 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3149 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303150 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003151
Chris Wilson9c870d02016-10-24 13:42:15 +01003152 intel_runtime_pm_get(dev_priv);
3153
Akash Goel3b3f1652016-10-13 22:44:48 +05303154 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003155 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3156 struct drm_i915_gem_request *rq;
3157 struct rb_node *rb;
3158 u64 addr;
3159
3160 seq_printf(m, "%s\n", engine->name);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02003161 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms]\n",
Chris Wilson1b365952016-10-04 21:11:31 +01003162 intel_engine_get_seqno(engine),
Chris Wilsoncb399ea2016-11-01 10:03:16 +00003163 intel_engine_last_submit(engine),
Chris Wilson1b365952016-10-04 21:11:31 +01003164 engine->hangcheck.seqno,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02003165 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
Chris Wilson1b365952016-10-04 21:11:31 +01003166
3167 rcu_read_lock();
3168
3169 seq_printf(m, "\tRequests:\n");
3170
Chris Wilson73cb9702016-10-28 13:58:46 +01003171 rq = list_first_entry(&engine->timeline->requests,
3172 struct drm_i915_gem_request, link);
3173 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003174 print_request(m, rq, "\t\tfirst ");
3175
Chris Wilson73cb9702016-10-28 13:58:46 +01003176 rq = list_last_entry(&engine->timeline->requests,
3177 struct drm_i915_gem_request, link);
3178 if (&rq->link != &engine->timeline->requests)
Chris Wilson1b365952016-10-04 21:11:31 +01003179 print_request(m, rq, "\t\tlast ");
3180
3181 rq = i915_gem_find_active_request(engine);
3182 if (rq) {
3183 print_request(m, rq, "\t\tactive ");
3184 seq_printf(m,
3185 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3186 rq->head, rq->postfix, rq->tail,
3187 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3188 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3189 }
3190
3191 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3192 I915_READ(RING_START(engine->mmio_base)),
3193 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3194 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3195 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3196 rq ? rq->ring->head : 0);
3197 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3198 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3199 rq ? rq->ring->tail : 0);
3200 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3201 I915_READ(RING_CTL(engine->mmio_base)),
3202 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3203
3204 rcu_read_unlock();
3205
3206 addr = intel_engine_get_active_head(engine);
3207 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3208 upper_32_bits(addr), lower_32_bits(addr));
3209 addr = intel_engine_get_last_batch_head(engine);
3210 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3211 upper_32_bits(addr), lower_32_bits(addr));
3212
3213 if (i915.enable_execlists) {
3214 u32 ptr, read, write;
Chris Wilson20311bd2016-11-14 20:41:03 +00003215 struct rb_node *rb;
Chris Wilson1b365952016-10-04 21:11:31 +01003216
3217 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3218 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3219 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3220
3221 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3222 read = GEN8_CSB_READ_PTR(ptr);
3223 write = GEN8_CSB_WRITE_PTR(ptr);
3224 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3225 read, write);
3226 if (read >= GEN8_CSB_ENTRIES)
3227 read = 0;
3228 if (write >= GEN8_CSB_ENTRIES)
3229 write = 0;
3230 if (read > write)
3231 write += GEN8_CSB_ENTRIES;
3232 while (read < write) {
3233 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3234
3235 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3236 idx,
3237 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3238 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3239 }
3240
3241 rcu_read_lock();
3242 rq = READ_ONCE(engine->execlist_port[0].request);
3243 if (rq)
3244 print_request(m, rq, "\t\tELSP[0] ");
3245 else
3246 seq_printf(m, "\t\tELSP[0] idle\n");
3247 rq = READ_ONCE(engine->execlist_port[1].request);
3248 if (rq)
3249 print_request(m, rq, "\t\tELSP[1] ");
3250 else
3251 seq_printf(m, "\t\tELSP[1] idle\n");
3252 rcu_read_unlock();
Chris Wilsonc8247c02016-10-27 01:03:43 +01003253
Chris Wilson663f71e2016-11-14 20:41:00 +00003254 spin_lock_irq(&engine->timeline->lock);
Chris Wilson20311bd2016-11-14 20:41:03 +00003255 for (rb = engine->execlist_first; rb; rb = rb_next(rb)) {
3256 rq = rb_entry(rb, typeof(*rq), priotree.node);
Chris Wilsonc8247c02016-10-27 01:03:43 +01003257 print_request(m, rq, "\t\tQ ");
3258 }
Chris Wilson663f71e2016-11-14 20:41:00 +00003259 spin_unlock_irq(&engine->timeline->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003260 } else if (INTEL_GEN(dev_priv) > 6) {
3261 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3262 I915_READ(RING_PP_DIR_BASE(engine)));
3263 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3264 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3265 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3266 I915_READ(RING_PP_DIR_DCLV(engine)));
3267 }
3268
Chris Wilsonf6168e32016-10-28 13:58:55 +01003269 spin_lock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003270 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3271 struct intel_wait *w = container_of(rb, typeof(*w), node);
3272
3273 seq_printf(m, "\t%s [%d] waiting for %x\n",
3274 w->tsk->comm, w->tsk->pid, w->seqno);
3275 }
Chris Wilsonf6168e32016-10-28 13:58:55 +01003276 spin_unlock_irq(&b->lock);
Chris Wilson1b365952016-10-04 21:11:31 +01003277
3278 seq_puts(m, "\n");
3279 }
3280
Chris Wilson9c870d02016-10-24 13:42:15 +01003281 intel_runtime_pm_put(dev_priv);
3282
Chris Wilson1b365952016-10-04 21:11:31 +01003283 return 0;
3284}
3285
Ben Widawskye04934c2014-06-30 09:53:42 -07003286static int i915_semaphore_status(struct seq_file *m, void *unused)
3287{
David Weinehall36cdd012016-08-22 13:59:31 +03003288 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3289 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003290 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003291 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003292 enum intel_engine_id id;
3293 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003294
Chris Wilson39df9192016-07-20 13:31:57 +01003295 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003296 seq_puts(m, "Semaphores are disabled\n");
3297 return 0;
3298 }
3299
3300 ret = mutex_lock_interruptible(&dev->struct_mutex);
3301 if (ret)
3302 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003303 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003304
David Weinehall36cdd012016-08-22 13:59:31 +03003305 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003306 struct page *page;
3307 uint64_t *seqno;
3308
Chris Wilson51d545d2016-08-15 10:49:02 +01003309 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003310
3311 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303312 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003313 uint64_t offset;
3314
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003315 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003316
3317 seq_puts(m, " Last signal:");
3318 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003319 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003320 seq_printf(m, "0x%08llx (0x%02llx) ",
3321 seqno[offset], offset * 8);
3322 }
3323 seq_putc(m, '\n');
3324
3325 seq_puts(m, " Last wait: ");
3326 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003327 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003328 seq_printf(m, "0x%08llx (0x%02llx) ",
3329 seqno[offset], offset * 8);
3330 }
3331 seq_putc(m, '\n');
3332
3333 }
3334 kunmap_atomic(seqno);
3335 } else {
3336 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303337 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003338 for (j = 0; j < num_rings; j++)
3339 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003340 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003341 seq_putc(m, '\n');
3342 }
3343
Paulo Zanoni03872062014-07-09 14:31:57 -03003344 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003345 mutex_unlock(&dev->struct_mutex);
3346 return 0;
3347}
3348
Daniel Vetter728e29d2014-06-25 22:01:53 +03003349static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3350{
David Weinehall36cdd012016-08-22 13:59:31 +03003351 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3352 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003353 int i;
3354
3355 drm_modeset_lock_all(dev);
3356 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3357 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3358
3359 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003360 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3361 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003362 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003363 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3364 seq_printf(m, " dpll_md: 0x%08x\n",
3365 pll->config.hw_state.dpll_md);
3366 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3367 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3368 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003369 }
3370 drm_modeset_unlock_all(dev);
3371
3372 return 0;
3373}
3374
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003375static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003376{
3377 int i;
3378 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003379 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003380 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3381 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003382 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003383 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003384
Arun Siluvery888b5992014-08-26 14:44:51 +01003385 ret = mutex_lock_interruptible(&dev->struct_mutex);
3386 if (ret)
3387 return ret;
3388
3389 intel_runtime_pm_get(dev_priv);
3390
Arun Siluvery33136b02016-01-21 21:43:47 +00003391 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303392 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003393 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003394 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003395 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003396 i915_reg_t addr;
3397 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003398 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003399
Arun Siluvery33136b02016-01-21 21:43:47 +00003400 addr = workarounds->reg[i].addr;
3401 mask = workarounds->reg[i].mask;
3402 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003403 read = I915_READ(addr);
3404 ok = (value & mask) == (read & mask);
3405 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 +02003406 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003407 }
3408
3409 intel_runtime_pm_put(dev_priv);
3410 mutex_unlock(&dev->struct_mutex);
3411
3412 return 0;
3413}
3414
Damien Lespiauc5511e42014-11-04 17:06:51 +00003415static int i915_ddb_info(struct seq_file *m, void *unused)
3416{
David Weinehall36cdd012016-08-22 13:59:31 +03003417 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3418 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003419 struct skl_ddb_allocation *ddb;
3420 struct skl_ddb_entry *entry;
3421 enum pipe pipe;
3422 int plane;
3423
David Weinehall36cdd012016-08-22 13:59:31 +03003424 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003425 return 0;
3426
Damien Lespiauc5511e42014-11-04 17:06:51 +00003427 drm_modeset_lock_all(dev);
3428
3429 ddb = &dev_priv->wm.skl_hw.ddb;
3430
3431 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3432
3433 for_each_pipe(dev_priv, pipe) {
3434 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3435
Matt Roper8b364b42016-10-26 15:51:28 -07003436 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003437 entry = &ddb->plane[pipe][plane];
3438 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3439 entry->start, entry->end,
3440 skl_ddb_entry_size(entry));
3441 }
3442
Matt Roper4969d332015-09-24 15:53:10 -07003443 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003444 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3445 entry->end, skl_ddb_entry_size(entry));
3446 }
3447
3448 drm_modeset_unlock_all(dev);
3449
3450 return 0;
3451}
3452
Vandana Kannana54746e2015-03-03 20:53:10 +05303453static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003454 struct drm_device *dev,
3455 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303456{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003457 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303458 struct i915_drrs *drrs = &dev_priv->drrs;
3459 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003460 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303461
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003462 drm_for_each_connector(connector, dev) {
3463 if (connector->state->crtc != &intel_crtc->base)
3464 continue;
3465
3466 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303467 }
3468
3469 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3470 seq_puts(m, "\tVBT: DRRS_type: Static");
3471 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3472 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3473 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3474 seq_puts(m, "\tVBT: DRRS_type: None");
3475 else
3476 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3477
3478 seq_puts(m, "\n\n");
3479
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003480 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303481 struct intel_panel *panel;
3482
3483 mutex_lock(&drrs->mutex);
3484 /* DRRS Supported */
3485 seq_puts(m, "\tDRRS Supported: Yes\n");
3486
3487 /* disable_drrs() will make drrs->dp NULL */
3488 if (!drrs->dp) {
3489 seq_puts(m, "Idleness DRRS: Disabled");
3490 mutex_unlock(&drrs->mutex);
3491 return;
3492 }
3493
3494 panel = &drrs->dp->attached_connector->panel;
3495 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3496 drrs->busy_frontbuffer_bits);
3497
3498 seq_puts(m, "\n\t\t");
3499 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3500 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3501 vrefresh = panel->fixed_mode->vrefresh;
3502 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3503 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3504 vrefresh = panel->downclock_mode->vrefresh;
3505 } else {
3506 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3507 drrs->refresh_rate_type);
3508 mutex_unlock(&drrs->mutex);
3509 return;
3510 }
3511 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3512
3513 seq_puts(m, "\n\t\t");
3514 mutex_unlock(&drrs->mutex);
3515 } else {
3516 /* DRRS not supported. Print the VBT parameter*/
3517 seq_puts(m, "\tDRRS Supported : No");
3518 }
3519 seq_puts(m, "\n");
3520}
3521
3522static int i915_drrs_status(struct seq_file *m, void *unused)
3523{
David Weinehall36cdd012016-08-22 13:59:31 +03003524 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3525 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303526 struct intel_crtc *intel_crtc;
3527 int active_crtc_cnt = 0;
3528
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003529 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303530 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003531 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303532 active_crtc_cnt++;
3533 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3534
3535 drrs_status_per_crtc(m, dev, intel_crtc);
3536 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303537 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003538 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303539
3540 if (!active_crtc_cnt)
3541 seq_puts(m, "No active crtc found\n");
3542
3543 return 0;
3544}
3545
Damien Lespiau07144422013-10-15 18:55:40 +01003546struct pipe_crc_info {
3547 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003548 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003549 enum pipe pipe;
3550};
3551
Dave Airlie11bed952014-05-12 15:22:27 +10003552static int i915_dp_mst_info(struct seq_file *m, void *unused)
3553{
David Weinehall36cdd012016-08-22 13:59:31 +03003554 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3555 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003556 struct intel_encoder *intel_encoder;
3557 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003558 struct drm_connector *connector;
3559
Dave Airlie11bed952014-05-12 15:22:27 +10003560 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003561 drm_for_each_connector(connector, dev) {
3562 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003563 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003564
3565 intel_encoder = intel_attached_encoder(connector);
3566 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3567 continue;
3568
3569 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003570 if (!intel_dig_port->dp.can_mst)
3571 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003572
Jim Bride40ae80c2016-04-14 10:18:37 -07003573 seq_printf(m, "MST Source Port %c\n",
3574 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003575 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3576 }
3577 drm_modeset_unlock_all(dev);
3578 return 0;
3579}
3580
Damien Lespiau07144422013-10-15 18:55:40 +01003581static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003582{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003583 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003584 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003585 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3586
David Weinehall36cdd012016-08-22 13:59:31 +03003587 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003588 return -ENODEV;
3589
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003590 spin_lock_irq(&pipe_crc->lock);
3591
3592 if (pipe_crc->opened) {
3593 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003594 return -EBUSY; /* already open */
3595 }
3596
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003597 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003598 filep->private_data = inode->i_private;
3599
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003600 spin_unlock_irq(&pipe_crc->lock);
3601
Damien Lespiau07144422013-10-15 18:55:40 +01003602 return 0;
3603}
3604
3605static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3606{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003607 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003608 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003609 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3610
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003611 spin_lock_irq(&pipe_crc->lock);
3612 pipe_crc->opened = false;
3613 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003614
Damien Lespiau07144422013-10-15 18:55:40 +01003615 return 0;
3616}
3617
3618/* (6 fields, 8 chars each, space separated (5) + '\n') */
3619#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3620/* account for \'0' */
3621#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3622
3623static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3624{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003625 assert_spin_locked(&pipe_crc->lock);
3626 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3627 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003628}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003629
Damien Lespiau07144422013-10-15 18:55:40 +01003630static ssize_t
3631i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3632 loff_t *pos)
3633{
3634 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003635 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003636 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3637 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003638 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003639 ssize_t bytes_read;
3640
3641 /*
3642 * Don't allow user space to provide buffers not big enough to hold
3643 * a line of data.
3644 */
3645 if (count < PIPE_CRC_LINE_LEN)
3646 return -EINVAL;
3647
3648 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3649 return 0;
3650
3651 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003652 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003653 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003654 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003655
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003656 if (filep->f_flags & O_NONBLOCK) {
3657 spin_unlock_irq(&pipe_crc->lock);
3658 return -EAGAIN;
3659 }
3660
3661 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3662 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3663 if (ret) {
3664 spin_unlock_irq(&pipe_crc->lock);
3665 return ret;
3666 }
Damien Lespiau07144422013-10-15 18:55:40 +01003667 }
3668
3669 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003670 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003671
Damien Lespiau07144422013-10-15 18:55:40 +01003672 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003673 while (n_entries > 0) {
3674 struct intel_pipe_crc_entry *entry =
3675 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003676
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003677 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3678 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3679 break;
3680
3681 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3682 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3683
Damien Lespiau07144422013-10-15 18:55:40 +01003684 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3685 "%8u %8x %8x %8x %8x %8x\n",
3686 entry->frame, entry->crc[0],
3687 entry->crc[1], entry->crc[2],
3688 entry->crc[3], entry->crc[4]);
3689
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003690 spin_unlock_irq(&pipe_crc->lock);
3691
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003692 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003693 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003694
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003695 user_buf += PIPE_CRC_LINE_LEN;
3696 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003697
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003698 spin_lock_irq(&pipe_crc->lock);
3699 }
3700
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003701 spin_unlock_irq(&pipe_crc->lock);
3702
Damien Lespiau07144422013-10-15 18:55:40 +01003703 return bytes_read;
3704}
3705
3706static const struct file_operations i915_pipe_crc_fops = {
3707 .owner = THIS_MODULE,
3708 .open = i915_pipe_crc_open,
3709 .read = i915_pipe_crc_read,
3710 .release = i915_pipe_crc_release,
3711};
3712
3713static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3714 {
3715 .name = "i915_pipe_A_crc",
3716 .pipe = PIPE_A,
3717 },
3718 {
3719 .name = "i915_pipe_B_crc",
3720 .pipe = PIPE_B,
3721 },
3722 {
3723 .name = "i915_pipe_C_crc",
3724 .pipe = PIPE_C,
3725 },
3726};
3727
3728static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3729 enum pipe pipe)
3730{
David Weinehall36cdd012016-08-22 13:59:31 +03003731 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003732 struct dentry *ent;
3733 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3734
David Weinehall36cdd012016-08-22 13:59:31 +03003735 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003736 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3737 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003738 if (!ent)
3739 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003740
3741 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003742}
3743
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003744static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003745 "none",
3746 "plane1",
3747 "plane2",
3748 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003749 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003750 "TV",
3751 "DP-B",
3752 "DP-C",
3753 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003754 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003755};
3756
3757static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3758{
3759 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3760 return pipe_crc_sources[source];
3761}
3762
Damien Lespiaubd9db022013-10-15 18:55:36 +01003763static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003764{
David Weinehall36cdd012016-08-22 13:59:31 +03003765 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003766 int i;
3767
3768 for (i = 0; i < I915_MAX_PIPES; i++)
3769 seq_printf(m, "%c %s\n", pipe_name(i),
3770 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3771
3772 return 0;
3773}
3774
Damien Lespiaubd9db022013-10-15 18:55:36 +01003775static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003776{
David Weinehall36cdd012016-08-22 13:59:31 +03003777 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003778}
3779
Daniel Vetter46a19182013-11-01 10:50:20 +01003780static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003781 uint32_t *val)
3782{
Daniel Vetter46a19182013-11-01 10:50:20 +01003783 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3784 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3785
3786 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003787 case INTEL_PIPE_CRC_SOURCE_PIPE:
3788 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3789 break;
3790 case INTEL_PIPE_CRC_SOURCE_NONE:
3791 *val = 0;
3792 break;
3793 default:
3794 return -EINVAL;
3795 }
3796
3797 return 0;
3798}
3799
David Weinehall36cdd012016-08-22 13:59:31 +03003800static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3801 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003802 enum intel_pipe_crc_source *source)
3803{
David Weinehall36cdd012016-08-22 13:59:31 +03003804 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003805 struct intel_encoder *encoder;
3806 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003807 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003808 int ret = 0;
3809
3810 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3811
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003812 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003813 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003814 if (!encoder->base.crtc)
3815 continue;
3816
3817 crtc = to_intel_crtc(encoder->base.crtc);
3818
3819 if (crtc->pipe != pipe)
3820 continue;
3821
3822 switch (encoder->type) {
3823 case INTEL_OUTPUT_TVOUT:
3824 *source = INTEL_PIPE_CRC_SOURCE_TV;
3825 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003826 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003827 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003828 dig_port = enc_to_dig_port(&encoder->base);
3829 switch (dig_port->port) {
3830 case PORT_B:
3831 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3832 break;
3833 case PORT_C:
3834 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3835 break;
3836 case PORT_D:
3837 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3838 break;
3839 default:
3840 WARN(1, "nonexisting DP port %c\n",
3841 port_name(dig_port->port));
3842 break;
3843 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003844 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003845 default:
3846 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003847 }
3848 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003849 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003850
3851 return ret;
3852}
3853
David Weinehall36cdd012016-08-22 13:59:31 +03003854static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003855 enum pipe pipe,
3856 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003857 uint32_t *val)
3858{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003859 bool need_stable_symbols = false;
3860
Daniel Vetter46a19182013-11-01 10:50:20 +01003861 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003862 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003863 if (ret)
3864 return ret;
3865 }
3866
3867 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003868 case INTEL_PIPE_CRC_SOURCE_PIPE:
3869 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3870 break;
3871 case INTEL_PIPE_CRC_SOURCE_DP_B:
3872 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003873 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003874 break;
3875 case INTEL_PIPE_CRC_SOURCE_DP_C:
3876 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003877 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003878 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003879 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003880 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003881 return -EINVAL;
3882 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3883 need_stable_symbols = true;
3884 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003885 case INTEL_PIPE_CRC_SOURCE_NONE:
3886 *val = 0;
3887 break;
3888 default:
3889 return -EINVAL;
3890 }
3891
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003892 /*
3893 * When the pipe CRC tap point is after the transcoders we need
3894 * to tweak symbol-level features to produce a deterministic series of
3895 * symbols for a given frame. We need to reset those features only once
3896 * a frame (instead of every nth symbol):
3897 * - DC-balance: used to ensure a better clock recovery from the data
3898 * link (SDVO)
3899 * - DisplayPort scrambling: used for EMI reduction
3900 */
3901 if (need_stable_symbols) {
3902 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3903
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003904 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003905 switch (pipe) {
3906 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003907 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003908 break;
3909 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003910 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003911 break;
3912 case PIPE_C:
3913 tmp |= PIPE_C_SCRAMBLE_RESET;
3914 break;
3915 default:
3916 return -EINVAL;
3917 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003918 I915_WRITE(PORT_DFT2_G4X, tmp);
3919 }
3920
Daniel Vetter7ac01292013-10-18 16:37:06 +02003921 return 0;
3922}
3923
David Weinehall36cdd012016-08-22 13:59:31 +03003924static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003925 enum pipe pipe,
3926 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003927 uint32_t *val)
3928{
Daniel Vetter84093602013-11-01 10:50:21 +01003929 bool need_stable_symbols = false;
3930
Daniel Vetter46a19182013-11-01 10:50:20 +01003931 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003932 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003933 if (ret)
3934 return ret;
3935 }
3936
3937 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003938 case INTEL_PIPE_CRC_SOURCE_PIPE:
3939 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3940 break;
3941 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003942 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003943 return -EINVAL;
3944 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3945 break;
3946 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003947 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003948 return -EINVAL;
3949 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003950 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003951 break;
3952 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003953 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003954 return -EINVAL;
3955 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003956 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003957 break;
3958 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003959 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003960 return -EINVAL;
3961 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003962 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003963 break;
3964 case INTEL_PIPE_CRC_SOURCE_NONE:
3965 *val = 0;
3966 break;
3967 default:
3968 return -EINVAL;
3969 }
3970
Daniel Vetter84093602013-11-01 10:50:21 +01003971 /*
3972 * When the pipe CRC tap point is after the transcoders we need
3973 * to tweak symbol-level features to produce a deterministic series of
3974 * symbols for a given frame. We need to reset those features only once
3975 * a frame (instead of every nth symbol):
3976 * - DC-balance: used to ensure a better clock recovery from the data
3977 * link (SDVO)
3978 * - DisplayPort scrambling: used for EMI reduction
3979 */
3980 if (need_stable_symbols) {
3981 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3982
David Weinehall36cdd012016-08-22 13:59:31 +03003983 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003984
3985 I915_WRITE(PORT_DFT_I9XX,
3986 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3987
3988 if (pipe == PIPE_A)
3989 tmp |= PIPE_A_SCRAMBLE_RESET;
3990 else
3991 tmp |= PIPE_B_SCRAMBLE_RESET;
3992
3993 I915_WRITE(PORT_DFT2_G4X, tmp);
3994 }
3995
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003996 return 0;
3997}
3998
David Weinehall36cdd012016-08-22 13:59:31 +03003999static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004000 enum pipe pipe)
4001{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004002 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4003
Ville Syrjäläeb736672014-12-09 21:28:28 +02004004 switch (pipe) {
4005 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004006 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004007 break;
4008 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004009 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004010 break;
4011 case PIPE_C:
4012 tmp &= ~PIPE_C_SCRAMBLE_RESET;
4013 break;
4014 default:
4015 return;
4016 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004017 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
4018 tmp &= ~DC_BALANCE_RESET_VLV;
4019 I915_WRITE(PORT_DFT2_G4X, tmp);
4020
4021}
4022
David Weinehall36cdd012016-08-22 13:59:31 +03004023static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01004024 enum pipe pipe)
4025{
Daniel Vetter84093602013-11-01 10:50:21 +01004026 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4027
4028 if (pipe == PIPE_A)
4029 tmp &= ~PIPE_A_SCRAMBLE_RESET;
4030 else
4031 tmp &= ~PIPE_B_SCRAMBLE_RESET;
4032 I915_WRITE(PORT_DFT2_G4X, tmp);
4033
4034 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
4035 I915_WRITE(PORT_DFT_I9XX,
4036 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
4037 }
4038}
4039
Daniel Vetter46a19182013-11-01 10:50:20 +01004040static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004041 uint32_t *val)
4042{
Daniel Vetter46a19182013-11-01 10:50:20 +01004043 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4044 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4045
4046 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004047 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4048 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4049 break;
4050 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4051 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4052 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004053 case INTEL_PIPE_CRC_SOURCE_PIPE:
4054 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4055 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004056 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004057 *val = 0;
4058 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004059 default:
4060 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004061 }
4062
4063 return 0;
4064}
4065
David Weinehall36cdd012016-08-22 13:59:31 +03004066static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4067 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004068{
David Weinehall36cdd012016-08-22 13:59:31 +03004069 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä98187832016-10-31 22:37:10 +02004070 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004071 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004072 struct drm_atomic_state *state;
4073 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004074
4075 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004076 state = drm_atomic_state_alloc(dev);
4077 if (!state) {
4078 ret = -ENOMEM;
4079 goto out;
4080 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004081
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004082 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4083 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4084 if (IS_ERR(pipe_config)) {
4085 ret = PTR_ERR(pipe_config);
4086 goto out;
4087 }
4088
4089 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004090 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004091 pipe_config->pch_pfit.enabled != enable)
4092 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004093
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004094 ret = drm_atomic_commit(state);
4095out:
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004096 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
Chris Wilson08536952016-10-14 13:18:18 +01004097 drm_modeset_unlock_all(dev);
4098 drm_atomic_state_put(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004099}
4100
David Weinehall36cdd012016-08-22 13:59:31 +03004101static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004102 enum pipe pipe,
4103 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004104 uint32_t *val)
4105{
Daniel Vetter46a19182013-11-01 10:50:20 +01004106 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4107 *source = INTEL_PIPE_CRC_SOURCE_PF;
4108
4109 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004110 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4111 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4112 break;
4113 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4114 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4115 break;
4116 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004117 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4118 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004119
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004120 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4121 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004122 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004123 *val = 0;
4124 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004125 default:
4126 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004127 }
4128
4129 return 0;
4130}
4131
David Weinehall36cdd012016-08-22 13:59:31 +03004132static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4133 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004134 enum intel_pipe_crc_source source)
4135{
Damien Lespiaucc3da172013-10-15 18:55:31 +01004136 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02004137 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Imre Deake1296492016-02-12 18:55:17 +02004138 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004139 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004140 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004141
Damien Lespiaucc3da172013-10-15 18:55:31 +01004142 if (pipe_crc->source == source)
4143 return 0;
4144
Damien Lespiauae676fc2013-10-15 18:55:32 +01004145 /* forbid changing the source without going back to 'none' */
4146 if (pipe_crc->source && source)
4147 return -EINVAL;
4148
Imre Deake1296492016-02-12 18:55:17 +02004149 power_domain = POWER_DOMAIN_PIPE(pipe);
4150 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004151 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4152 return -EIO;
4153 }
4154
David Weinehall36cdd012016-08-22 13:59:31 +03004155 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004156 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004157 else if (INTEL_GEN(dev_priv) < 5)
4158 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4159 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4160 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4161 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004162 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004163 else
David Weinehall36cdd012016-08-22 13:59:31 +03004164 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004165
4166 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004167 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004168
Damien Lespiau4b584362013-10-15 18:55:33 +01004169 /* none -> real source transition */
4170 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004171 struct intel_pipe_crc_entry *entries;
4172
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004173 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4174 pipe_name(pipe), pipe_crc_source_name(source));
4175
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004176 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4177 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004178 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004179 if (!entries) {
4180 ret = -ENOMEM;
4181 goto out;
4182 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004183
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004184 /*
4185 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4186 * enabled and disabled dynamically based on package C states,
4187 * user space can't make reliable use of the CRCs, so let's just
4188 * completely disable it.
4189 */
4190 hsw_disable_ips(crtc);
4191
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004192 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004193 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004194 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004195 pipe_crc->head = 0;
4196 pipe_crc->tail = 0;
4197 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004198 }
4199
Damien Lespiaucc3da172013-10-15 18:55:31 +01004200 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004201
Daniel Vetter926321d2013-10-16 13:30:34 +02004202 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4203 POSTING_READ(PIPE_CRC_CTL(pipe));
4204
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004205 /* real source -> none transition */
4206 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004207 struct intel_pipe_crc_entry *entries;
Ville Syrjälä98187832016-10-31 22:37:10 +02004208 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
4209 pipe);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004210
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004211 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4212 pipe_name(pipe));
4213
Daniel Vettera33d7102014-06-06 08:22:08 +02004214 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004215 if (crtc->base.state->active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004216 intel_wait_for_vblank(dev_priv, pipe);
Daniel Vettera33d7102014-06-06 08:22:08 +02004217 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004218
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004219 spin_lock_irq(&pipe_crc->lock);
4220 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004221 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004222 pipe_crc->head = 0;
4223 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004224 spin_unlock_irq(&pipe_crc->lock);
4225
4226 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004227
David Weinehall36cdd012016-08-22 13:59:31 +03004228 if (IS_G4X(dev_priv))
4229 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4230 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4231 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4232 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4233 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004234
4235 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004236 }
4237
Imre Deake1296492016-02-12 18:55:17 +02004238 ret = 0;
4239
4240out:
4241 intel_display_power_put(dev_priv, power_domain);
4242
4243 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004244}
4245
4246/*
4247 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004248 * command: wsp* object wsp+ name wsp+ source wsp*
4249 * object: 'pipe'
4250 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004251 * source: (none | plane1 | plane2 | pf)
4252 * wsp: (#0x20 | #0x9 | #0xA)+
4253 *
4254 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004255 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4256 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004257 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004258static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004259{
4260 int n_words = 0;
4261
4262 while (*buf) {
4263 char *end;
4264
4265 /* skip leading white space */
4266 buf = skip_spaces(buf);
4267 if (!*buf)
4268 break; /* end of buffer */
4269
4270 /* find end of word */
4271 for (end = buf; *end && !isspace(*end); end++)
4272 ;
4273
4274 if (n_words == max_words) {
4275 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4276 max_words);
4277 return -EINVAL; /* ran out of words[] before bytes */
4278 }
4279
4280 if (*end)
4281 *end++ = '\0';
4282 words[n_words++] = buf;
4283 buf = end;
4284 }
4285
4286 return n_words;
4287}
4288
Damien Lespiaub94dec82013-10-15 18:55:35 +01004289enum intel_pipe_crc_object {
4290 PIPE_CRC_OBJECT_PIPE,
4291};
4292
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004293static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004294 "pipe",
4295};
4296
4297static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004298display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004299{
4300 int i;
4301
4302 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4303 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004304 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004305 return 0;
4306 }
4307
4308 return -EINVAL;
4309}
4310
Damien Lespiaubd9db022013-10-15 18:55:36 +01004311static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004312{
4313 const char name = buf[0];
4314
4315 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4316 return -EINVAL;
4317
4318 *pipe = name - 'A';
4319
4320 return 0;
4321}
4322
4323static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004324display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004325{
4326 int i;
4327
4328 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4329 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004330 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004331 return 0;
4332 }
4333
4334 return -EINVAL;
4335}
4336
David Weinehall36cdd012016-08-22 13:59:31 +03004337static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4338 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004339{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004340#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004341 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004342 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004343 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004344 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004345 enum intel_pipe_crc_source source;
4346
Damien Lespiaubd9db022013-10-15 18:55:36 +01004347 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004348 if (n_words != N_WORDS) {
4349 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4350 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004351 return -EINVAL;
4352 }
4353
Damien Lespiaubd9db022013-10-15 18:55:36 +01004354 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004355 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004356 return -EINVAL;
4357 }
4358
Damien Lespiaubd9db022013-10-15 18:55:36 +01004359 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004360 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4361 return -EINVAL;
4362 }
4363
Damien Lespiaubd9db022013-10-15 18:55:36 +01004364 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004365 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004366 return -EINVAL;
4367 }
4368
David Weinehall36cdd012016-08-22 13:59:31 +03004369 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004370}
4371
Damien Lespiaubd9db022013-10-15 18:55:36 +01004372static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4373 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004374{
4375 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004376 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004377 char *tmpbuf;
4378 int ret;
4379
4380 if (len == 0)
4381 return 0;
4382
4383 if (len > PAGE_SIZE - 1) {
4384 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4385 PAGE_SIZE);
4386 return -E2BIG;
4387 }
4388
4389 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4390 if (!tmpbuf)
4391 return -ENOMEM;
4392
4393 if (copy_from_user(tmpbuf, ubuf, len)) {
4394 ret = -EFAULT;
4395 goto out;
4396 }
4397 tmpbuf[len] = '\0';
4398
David Weinehall36cdd012016-08-22 13:59:31 +03004399 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004400
4401out:
4402 kfree(tmpbuf);
4403 if (ret < 0)
4404 return ret;
4405
4406 *offp += len;
4407 return len;
4408}
4409
Damien Lespiaubd9db022013-10-15 18:55:36 +01004410static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004411 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004412 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004413 .read = seq_read,
4414 .llseek = seq_lseek,
4415 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004416 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004417};
4418
Todd Previteeb3394fa2015-04-18 00:04:19 -07004419static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004420 const char __user *ubuf,
4421 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004422{
4423 char *input_buffer;
4424 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004425 struct drm_device *dev;
4426 struct drm_connector *connector;
4427 struct list_head *connector_list;
4428 struct intel_dp *intel_dp;
4429 int val = 0;
4430
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304431 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004432
Todd Previteeb3394fa2015-04-18 00:04:19 -07004433 connector_list = &dev->mode_config.connector_list;
4434
4435 if (len == 0)
4436 return 0;
4437
4438 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4439 if (!input_buffer)
4440 return -ENOMEM;
4441
4442 if (copy_from_user(input_buffer, ubuf, len)) {
4443 status = -EFAULT;
4444 goto out;
4445 }
4446
4447 input_buffer[len] = '\0';
4448 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4449
4450 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004451 if (connector->connector_type !=
4452 DRM_MODE_CONNECTOR_DisplayPort)
4453 continue;
4454
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304455 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004456 connector->encoder != NULL) {
4457 intel_dp = enc_to_intel_dp(connector->encoder);
4458 status = kstrtoint(input_buffer, 10, &val);
4459 if (status < 0)
4460 goto out;
4461 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4462 /* To prevent erroneous activation of the compliance
4463 * testing code, only accept an actual value of 1 here
4464 */
4465 if (val == 1)
4466 intel_dp->compliance_test_active = 1;
4467 else
4468 intel_dp->compliance_test_active = 0;
4469 }
4470 }
4471out:
4472 kfree(input_buffer);
4473 if (status < 0)
4474 return status;
4475
4476 *offp += len;
4477 return len;
4478}
4479
4480static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4481{
4482 struct drm_device *dev = m->private;
4483 struct drm_connector *connector;
4484 struct list_head *connector_list = &dev->mode_config.connector_list;
4485 struct intel_dp *intel_dp;
4486
Todd Previteeb3394fa2015-04-18 00:04:19 -07004487 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004488 if (connector->connector_type !=
4489 DRM_MODE_CONNECTOR_DisplayPort)
4490 continue;
4491
4492 if (connector->status == connector_status_connected &&
4493 connector->encoder != NULL) {
4494 intel_dp = enc_to_intel_dp(connector->encoder);
4495 if (intel_dp->compliance_test_active)
4496 seq_puts(m, "1");
4497 else
4498 seq_puts(m, "0");
4499 } else
4500 seq_puts(m, "0");
4501 }
4502
4503 return 0;
4504}
4505
4506static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004507 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004508{
David Weinehall36cdd012016-08-22 13:59:31 +03004509 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004510
David Weinehall36cdd012016-08-22 13:59:31 +03004511 return single_open(file, i915_displayport_test_active_show,
4512 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004513}
4514
4515static const struct file_operations i915_displayport_test_active_fops = {
4516 .owner = THIS_MODULE,
4517 .open = i915_displayport_test_active_open,
4518 .read = seq_read,
4519 .llseek = seq_lseek,
4520 .release = single_release,
4521 .write = i915_displayport_test_active_write
4522};
4523
4524static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4525{
4526 struct drm_device *dev = m->private;
4527 struct drm_connector *connector;
4528 struct list_head *connector_list = &dev->mode_config.connector_list;
4529 struct intel_dp *intel_dp;
4530
Todd Previteeb3394fa2015-04-18 00:04:19 -07004531 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004532 if (connector->connector_type !=
4533 DRM_MODE_CONNECTOR_DisplayPort)
4534 continue;
4535
4536 if (connector->status == connector_status_connected &&
4537 connector->encoder != NULL) {
4538 intel_dp = enc_to_intel_dp(connector->encoder);
4539 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4540 } else
4541 seq_puts(m, "0");
4542 }
4543
4544 return 0;
4545}
4546static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004547 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004548{
David Weinehall36cdd012016-08-22 13:59:31 +03004549 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004550
David Weinehall36cdd012016-08-22 13:59:31 +03004551 return single_open(file, i915_displayport_test_data_show,
4552 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004553}
4554
4555static const struct file_operations i915_displayport_test_data_fops = {
4556 .owner = THIS_MODULE,
4557 .open = i915_displayport_test_data_open,
4558 .read = seq_read,
4559 .llseek = seq_lseek,
4560 .release = single_release
4561};
4562
4563static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4564{
4565 struct drm_device *dev = m->private;
4566 struct drm_connector *connector;
4567 struct list_head *connector_list = &dev->mode_config.connector_list;
4568 struct intel_dp *intel_dp;
4569
Todd Previteeb3394fa2015-04-18 00:04:19 -07004570 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004571 if (connector->connector_type !=
4572 DRM_MODE_CONNECTOR_DisplayPort)
4573 continue;
4574
4575 if (connector->status == connector_status_connected &&
4576 connector->encoder != NULL) {
4577 intel_dp = enc_to_intel_dp(connector->encoder);
4578 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4579 } else
4580 seq_puts(m, "0");
4581 }
4582
4583 return 0;
4584}
4585
4586static int i915_displayport_test_type_open(struct inode *inode,
4587 struct file *file)
4588{
David Weinehall36cdd012016-08-22 13:59:31 +03004589 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004590
David Weinehall36cdd012016-08-22 13:59:31 +03004591 return single_open(file, i915_displayport_test_type_show,
4592 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004593}
4594
4595static const struct file_operations i915_displayport_test_type_fops = {
4596 .owner = THIS_MODULE,
4597 .open = i915_displayport_test_type_open,
4598 .read = seq_read,
4599 .llseek = seq_lseek,
4600 .release = single_release
4601};
4602
Damien Lespiau97e94b22014-11-04 17:06:50 +00004603static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004604{
David Weinehall36cdd012016-08-22 13:59:31 +03004605 struct drm_i915_private *dev_priv = m->private;
4606 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004607 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004608 int num_levels;
4609
David Weinehall36cdd012016-08-22 13:59:31 +03004610 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004611 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004612 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004613 num_levels = 1;
4614 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004615 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004616
4617 drm_modeset_lock_all(dev);
4618
4619 for (level = 0; level < num_levels; level++) {
4620 unsigned int latency = wm[level];
4621
Damien Lespiau97e94b22014-11-04 17:06:50 +00004622 /*
4623 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004624 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004625 */
David Weinehall36cdd012016-08-22 13:59:31 +03004626 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4627 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004628 latency *= 10;
4629 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004630 latency *= 5;
4631
4632 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004633 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004634 }
4635
4636 drm_modeset_unlock_all(dev);
4637}
4638
4639static int pri_wm_latency_show(struct seq_file *m, void *data)
4640{
David Weinehall36cdd012016-08-22 13:59:31 +03004641 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004642 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004643
David Weinehall36cdd012016-08-22 13:59:31 +03004644 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004645 latencies = dev_priv->wm.skl_latency;
4646 else
David Weinehall36cdd012016-08-22 13:59:31 +03004647 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004648
4649 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004650
4651 return 0;
4652}
4653
4654static int spr_wm_latency_show(struct seq_file *m, void *data)
4655{
David Weinehall36cdd012016-08-22 13:59:31 +03004656 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004657 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004658
David Weinehall36cdd012016-08-22 13:59:31 +03004659 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004660 latencies = dev_priv->wm.skl_latency;
4661 else
David Weinehall36cdd012016-08-22 13:59:31 +03004662 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004663
4664 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004665
4666 return 0;
4667}
4668
4669static int cur_wm_latency_show(struct seq_file *m, void *data)
4670{
David Weinehall36cdd012016-08-22 13:59:31 +03004671 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004672 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004673
David Weinehall36cdd012016-08-22 13:59:31 +03004674 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004675 latencies = dev_priv->wm.skl_latency;
4676 else
David Weinehall36cdd012016-08-22 13:59:31 +03004677 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004678
4679 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004680
4681 return 0;
4682}
4683
4684static int pri_wm_latency_open(struct inode *inode, struct file *file)
4685{
David Weinehall36cdd012016-08-22 13:59:31 +03004686 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004687
David Weinehall36cdd012016-08-22 13:59:31 +03004688 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004689 return -ENODEV;
4690
David Weinehall36cdd012016-08-22 13:59:31 +03004691 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004692}
4693
4694static int spr_wm_latency_open(struct inode *inode, struct file *file)
4695{
David Weinehall36cdd012016-08-22 13:59:31 +03004696 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004697
David Weinehall36cdd012016-08-22 13:59:31 +03004698 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004699 return -ENODEV;
4700
David Weinehall36cdd012016-08-22 13:59:31 +03004701 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004702}
4703
4704static int cur_wm_latency_open(struct inode *inode, struct file *file)
4705{
David Weinehall36cdd012016-08-22 13:59:31 +03004706 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004707
David Weinehall36cdd012016-08-22 13:59:31 +03004708 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004709 return -ENODEV;
4710
David Weinehall36cdd012016-08-22 13:59:31 +03004711 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004712}
4713
4714static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004715 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004716{
4717 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004718 struct drm_i915_private *dev_priv = m->private;
4719 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004720 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004721 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004722 int level;
4723 int ret;
4724 char tmp[32];
4725
David Weinehall36cdd012016-08-22 13:59:31 +03004726 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004727 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004728 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004729 num_levels = 1;
4730 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004731 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004732
Ville Syrjälä369a1342014-01-22 14:36:08 +02004733 if (len >= sizeof(tmp))
4734 return -EINVAL;
4735
4736 if (copy_from_user(tmp, ubuf, len))
4737 return -EFAULT;
4738
4739 tmp[len] = '\0';
4740
Damien Lespiau97e94b22014-11-04 17:06:50 +00004741 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4742 &new[0], &new[1], &new[2], &new[3],
4743 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004744 if (ret != num_levels)
4745 return -EINVAL;
4746
4747 drm_modeset_lock_all(dev);
4748
4749 for (level = 0; level < num_levels; level++)
4750 wm[level] = new[level];
4751
4752 drm_modeset_unlock_all(dev);
4753
4754 return len;
4755}
4756
4757
4758static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4759 size_t len, loff_t *offp)
4760{
4761 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004762 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004763 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004764
David Weinehall36cdd012016-08-22 13:59:31 +03004765 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004766 latencies = dev_priv->wm.skl_latency;
4767 else
David Weinehall36cdd012016-08-22 13:59:31 +03004768 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004769
4770 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004771}
4772
4773static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4774 size_t len, loff_t *offp)
4775{
4776 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004777 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004778 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004779
David Weinehall36cdd012016-08-22 13:59:31 +03004780 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004781 latencies = dev_priv->wm.skl_latency;
4782 else
David Weinehall36cdd012016-08-22 13:59:31 +03004783 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004784
4785 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004786}
4787
4788static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4789 size_t len, loff_t *offp)
4790{
4791 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004792 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004793 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004794
David Weinehall36cdd012016-08-22 13:59:31 +03004795 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004796 latencies = dev_priv->wm.skl_latency;
4797 else
David Weinehall36cdd012016-08-22 13:59:31 +03004798 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004799
4800 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004801}
4802
4803static const struct file_operations i915_pri_wm_latency_fops = {
4804 .owner = THIS_MODULE,
4805 .open = pri_wm_latency_open,
4806 .read = seq_read,
4807 .llseek = seq_lseek,
4808 .release = single_release,
4809 .write = pri_wm_latency_write
4810};
4811
4812static const struct file_operations i915_spr_wm_latency_fops = {
4813 .owner = THIS_MODULE,
4814 .open = spr_wm_latency_open,
4815 .read = seq_read,
4816 .llseek = seq_lseek,
4817 .release = single_release,
4818 .write = spr_wm_latency_write
4819};
4820
4821static const struct file_operations i915_cur_wm_latency_fops = {
4822 .owner = THIS_MODULE,
4823 .open = cur_wm_latency_open,
4824 .read = seq_read,
4825 .llseek = seq_lseek,
4826 .release = single_release,
4827 .write = cur_wm_latency_write
4828};
4829
Kees Cook647416f2013-03-10 14:10:06 -07004830static int
4831i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004832{
David Weinehall36cdd012016-08-22 13:59:31 +03004833 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004834
Chris Wilsond98c52c2016-04-13 17:35:05 +01004835 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004836
Kees Cook647416f2013-03-10 14:10:06 -07004837 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004838}
4839
Kees Cook647416f2013-03-10 14:10:06 -07004840static int
4841i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004842{
David Weinehall36cdd012016-08-22 13:59:31 +03004843 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004844
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004845 /*
4846 * There is no safeguard against this debugfs entry colliding
4847 * with the hangcheck calling same i915_handle_error() in
4848 * parallel, causing an explosion. For now we assume that the
4849 * test harness is responsible enough not to inject gpu hangs
4850 * while it is writing to 'i915_wedged'
4851 */
4852
Chris Wilsond98c52c2016-04-13 17:35:05 +01004853 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004854 return -EAGAIN;
4855
Chris Wilsonc0336662016-05-06 15:40:21 +01004856 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004857 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004858
Kees Cook647416f2013-03-10 14:10:06 -07004859 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004860}
4861
Kees Cook647416f2013-03-10 14:10:06 -07004862DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4863 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004864 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004865
Kees Cook647416f2013-03-10 14:10:06 -07004866static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004867i915_ring_missed_irq_get(void *data, u64 *val)
4868{
David Weinehall36cdd012016-08-22 13:59:31 +03004869 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004870
4871 *val = dev_priv->gpu_error.missed_irq_rings;
4872 return 0;
4873}
4874
4875static int
4876i915_ring_missed_irq_set(void *data, u64 val)
4877{
David Weinehall36cdd012016-08-22 13:59:31 +03004878 struct drm_i915_private *dev_priv = data;
4879 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004880 int ret;
4881
4882 /* Lock against concurrent debugfs callers */
4883 ret = mutex_lock_interruptible(&dev->struct_mutex);
4884 if (ret)
4885 return ret;
4886 dev_priv->gpu_error.missed_irq_rings = val;
4887 mutex_unlock(&dev->struct_mutex);
4888
4889 return 0;
4890}
4891
4892DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4893 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4894 "0x%08llx\n");
4895
4896static int
4897i915_ring_test_irq_get(void *data, u64 *val)
4898{
David Weinehall36cdd012016-08-22 13:59:31 +03004899 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004900
4901 *val = dev_priv->gpu_error.test_irq_rings;
4902
4903 return 0;
4904}
4905
4906static int
4907i915_ring_test_irq_set(void *data, u64 val)
4908{
David Weinehall36cdd012016-08-22 13:59:31 +03004909 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004910
Chris Wilson3a122c22016-06-17 14:35:05 +01004911 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004912 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004913 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004914
4915 return 0;
4916}
4917
4918DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4919 i915_ring_test_irq_get, i915_ring_test_irq_set,
4920 "0x%08llx\n");
4921
Chris Wilsondd624af2013-01-15 12:39:35 +00004922#define DROP_UNBOUND 0x1
4923#define DROP_BOUND 0x2
4924#define DROP_RETIRE 0x4
4925#define DROP_ACTIVE 0x8
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004926#define DROP_FREED 0x10
4927#define DROP_ALL (DROP_UNBOUND | \
4928 DROP_BOUND | \
4929 DROP_RETIRE | \
4930 DROP_ACTIVE | \
4931 DROP_FREED)
Kees Cook647416f2013-03-10 14:10:06 -07004932static int
4933i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004934{
Kees Cook647416f2013-03-10 14:10:06 -07004935 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004936
Kees Cook647416f2013-03-10 14:10:06 -07004937 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004938}
4939
Kees Cook647416f2013-03-10 14:10:06 -07004940static int
4941i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004942{
David Weinehall36cdd012016-08-22 13:59:31 +03004943 struct drm_i915_private *dev_priv = data;
4944 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004945 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004946
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004947 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004948
4949 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4950 * on ioctls on -EAGAIN. */
4951 ret = mutex_lock_interruptible(&dev->struct_mutex);
4952 if (ret)
4953 return ret;
4954
4955 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004956 ret = i915_gem_wait_for_idle(dev_priv,
4957 I915_WAIT_INTERRUPTIBLE |
4958 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004959 if (ret)
4960 goto unlock;
4961 }
4962
4963 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004964 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004965
Chris Wilson21ab4e72014-09-09 11:16:08 +01004966 if (val & DROP_BOUND)
4967 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004968
Chris Wilson21ab4e72014-09-09 11:16:08 +01004969 if (val & DROP_UNBOUND)
4970 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004971
4972unlock:
4973 mutex_unlock(&dev->struct_mutex);
4974
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004975 if (val & DROP_FREED) {
4976 synchronize_rcu();
4977 flush_work(&dev_priv->mm.free_work);
4978 }
4979
Kees Cook647416f2013-03-10 14:10:06 -07004980 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004981}
4982
Kees Cook647416f2013-03-10 14:10:06 -07004983DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4984 i915_drop_caches_get, i915_drop_caches_set,
4985 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004986
Kees Cook647416f2013-03-10 14:10:06 -07004987static int
4988i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004989{
David Weinehall36cdd012016-08-22 13:59:31 +03004990 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004991
David Weinehall36cdd012016-08-22 13:59:31 +03004992 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004993 return -ENODEV;
4994
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004995 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004996 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004997}
4998
Kees Cook647416f2013-03-10 14:10:06 -07004999static int
5000i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005001{
David Weinehall36cdd012016-08-22 13:59:31 +03005002 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305003 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005004 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005005
David Weinehall36cdd012016-08-22 13:59:31 +03005006 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005007 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005008
Kees Cook647416f2013-03-10 14:10:06 -07005009 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005010
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005011 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005012 if (ret)
5013 return ret;
5014
Jesse Barnes358733e2011-07-27 11:53:01 -07005015 /*
5016 * Turbo will still be enabled, but won't go above the set value.
5017 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305018 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005019
Akash Goelbc4d91f2015-02-26 16:09:47 +05305020 hw_max = dev_priv->rps.max_freq;
5021 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005022
Ben Widawskyb39fb292014-03-19 18:31:11 -07005023 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005024 mutex_unlock(&dev_priv->rps.hw_lock);
5025 return -EINVAL;
5026 }
5027
Ben Widawskyb39fb292014-03-19 18:31:11 -07005028 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005029
Chris Wilsondc979972016-05-10 14:10:04 +01005030 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005031
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005032 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005033
Kees Cook647416f2013-03-10 14:10:06 -07005034 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005035}
5036
Kees Cook647416f2013-03-10 14:10:06 -07005037DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5038 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005039 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005040
Kees Cook647416f2013-03-10 14:10:06 -07005041static int
5042i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005043{
David Weinehall36cdd012016-08-22 13:59:31 +03005044 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005045
Chris Wilson62e1baa2016-07-13 09:10:36 +01005046 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005047 return -ENODEV;
5048
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005049 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005050 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005051}
5052
Kees Cook647416f2013-03-10 14:10:06 -07005053static int
5054i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005055{
David Weinehall36cdd012016-08-22 13:59:31 +03005056 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305057 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005058 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005059
Chris Wilson62e1baa2016-07-13 09:10:36 +01005060 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005061 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005062
Kees Cook647416f2013-03-10 14:10:06 -07005063 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005064
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005065 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005066 if (ret)
5067 return ret;
5068
Jesse Barnes1523c312012-05-25 12:34:54 -07005069 /*
5070 * Turbo will still be enabled, but won't go below the set value.
5071 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305072 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005073
Akash Goelbc4d91f2015-02-26 16:09:47 +05305074 hw_max = dev_priv->rps.max_freq;
5075 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005076
David Weinehall36cdd012016-08-22 13:59:31 +03005077 if (val < hw_min ||
5078 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005079 mutex_unlock(&dev_priv->rps.hw_lock);
5080 return -EINVAL;
5081 }
5082
Ben Widawskyb39fb292014-03-19 18:31:11 -07005083 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005084
Chris Wilsondc979972016-05-10 14:10:04 +01005085 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005086
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005087 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005088
Kees Cook647416f2013-03-10 14:10:06 -07005089 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005090}
5091
Kees Cook647416f2013-03-10 14:10:06 -07005092DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5093 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005094 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005095
Kees Cook647416f2013-03-10 14:10:06 -07005096static int
5097i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005098{
David Weinehall36cdd012016-08-22 13:59:31 +03005099 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005100 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005101
David Weinehall36cdd012016-08-22 13:59:31 +03005102 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005103 return -ENODEV;
5104
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005105 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005106
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005107 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005108
5109 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005110
Kees Cook647416f2013-03-10 14:10:06 -07005111 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005112
Kees Cook647416f2013-03-10 14:10:06 -07005113 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005114}
5115
Kees Cook647416f2013-03-10 14:10:06 -07005116static int
5117i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005118{
David Weinehall36cdd012016-08-22 13:59:31 +03005119 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005120 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005121
David Weinehall36cdd012016-08-22 13:59:31 +03005122 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005123 return -ENODEV;
5124
Kees Cook647416f2013-03-10 14:10:06 -07005125 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005126 return -EINVAL;
5127
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005128 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005129 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005130
5131 /* Update the cache sharing policy here as well */
5132 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5133 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5134 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5135 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5136
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005137 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005138 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005139}
5140
Kees Cook647416f2013-03-10 14:10:06 -07005141DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5142 i915_cache_sharing_get, i915_cache_sharing_set,
5143 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005144
David Weinehall36cdd012016-08-22 13:59:31 +03005145static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005146 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005147{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005148 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005149 int ss;
5150 u32 sig1[ss_max], sig2[ss_max];
5151
5152 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5153 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5154 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5155 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5156
5157 for (ss = 0; ss < ss_max; ss++) {
5158 unsigned int eu_cnt;
5159
5160 if (sig1[ss] & CHV_SS_PG_ENABLE)
5161 /* skip disabled subslice */
5162 continue;
5163
Imre Deakf08a0c92016-08-31 19:13:04 +03005164 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005165 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005166 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5167 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5168 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5169 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005170 sseu->eu_total += eu_cnt;
5171 sseu->eu_per_subslice = max_t(unsigned int,
5172 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005173 }
Jeff McGee5d395252015-04-03 18:13:17 -07005174}
5175
David Weinehall36cdd012016-08-22 13:59:31 +03005176static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005177 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005178{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005179 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005180 int s, ss;
5181 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5182
Jeff McGee1c046bc2015-04-03 18:13:18 -07005183 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005184 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005185 s_max = 1;
5186 ss_max = 3;
5187 }
5188
5189 for (s = 0; s < s_max; s++) {
5190 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5191 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5192 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5193 }
5194
Jeff McGee5d395252015-04-03 18:13:17 -07005195 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5196 GEN9_PGCTL_SSA_EU19_ACK |
5197 GEN9_PGCTL_SSA_EU210_ACK |
5198 GEN9_PGCTL_SSA_EU311_ACK;
5199 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5200 GEN9_PGCTL_SSB_EU19_ACK |
5201 GEN9_PGCTL_SSB_EU210_ACK |
5202 GEN9_PGCTL_SSB_EU311_ACK;
5203
5204 for (s = 0; s < s_max; s++) {
5205 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5206 /* skip disabled slice */
5207 continue;
5208
Imre Deakf08a0c92016-08-31 19:13:04 +03005209 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005210
David Weinehall36cdd012016-08-22 13:59:31 +03005211 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005212 sseu->subslice_mask =
5213 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005214
Jeff McGee5d395252015-04-03 18:13:17 -07005215 for (ss = 0; ss < ss_max; ss++) {
5216 unsigned int eu_cnt;
5217
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005218 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03005219 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5220 /* skip disabled subslice */
5221 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005222
Imre Deak57ec1712016-08-31 19:13:05 +03005223 sseu->subslice_mask |= BIT(ss);
5224 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005225
Jeff McGee5d395252015-04-03 18:13:17 -07005226 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5227 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005228 sseu->eu_total += eu_cnt;
5229 sseu->eu_per_subslice = max_t(unsigned int,
5230 sseu->eu_per_subslice,
5231 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005232 }
5233 }
5234}
5235
David Weinehall36cdd012016-08-22 13:59:31 +03005236static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005237 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005238{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005239 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005240 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005241
Imre Deakf08a0c92016-08-31 19:13:04 +03005242 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005243
Imre Deakf08a0c92016-08-31 19:13:04 +03005244 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005245 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005246 sseu->eu_per_subslice =
5247 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005248 sseu->eu_total = sseu->eu_per_subslice *
5249 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005250
5251 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005252 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005253 u8 subslice_7eu =
5254 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005255
Imre Deak915490d2016-08-31 19:13:01 +03005256 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005257 }
5258 }
5259}
5260
Imre Deak615d8902016-08-31 19:13:03 +03005261static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5262 const struct sseu_dev_info *sseu)
5263{
5264 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5265 const char *type = is_available_info ? "Available" : "Enabled";
5266
Imre Deakc67ba532016-08-31 19:13:06 +03005267 seq_printf(m, " %s Slice Mask: %04x\n", type,
5268 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005269 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005270 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005271 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005272 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005273 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5274 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005275 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005276 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005277 seq_printf(m, " %s EU Total: %u\n", type,
5278 sseu->eu_total);
5279 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5280 sseu->eu_per_subslice);
5281
5282 if (!is_available_info)
5283 return;
5284
5285 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5286 if (HAS_POOLED_EU(dev_priv))
5287 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5288
5289 seq_printf(m, " Has Slice Power Gating: %s\n",
5290 yesno(sseu->has_slice_pg));
5291 seq_printf(m, " Has Subslice Power Gating: %s\n",
5292 yesno(sseu->has_subslice_pg));
5293 seq_printf(m, " Has EU Power Gating: %s\n",
5294 yesno(sseu->has_eu_pg));
5295}
5296
Jeff McGee38732182015-02-13 10:27:54 -06005297static int i915_sseu_status(struct seq_file *m, void *unused)
5298{
David Weinehall36cdd012016-08-22 13:59:31 +03005299 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005300 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005301
David Weinehall36cdd012016-08-22 13:59:31 +03005302 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005303 return -ENODEV;
5304
5305 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005306 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005307
Jeff McGee7f992ab2015-02-13 10:27:55 -06005308 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005309 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005310
5311 intel_runtime_pm_get(dev_priv);
5312
David Weinehall36cdd012016-08-22 13:59:31 +03005313 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005314 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005315 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005316 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005317 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005318 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005319 }
David Weinehall238010e2016-08-01 17:33:27 +03005320
5321 intel_runtime_pm_put(dev_priv);
5322
Imre Deak615d8902016-08-31 19:13:03 +03005323 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005324
Jeff McGee38732182015-02-13 10:27:54 -06005325 return 0;
5326}
5327
Ben Widawsky6d794d42011-04-25 11:25:56 -07005328static int i915_forcewake_open(struct inode *inode, struct file *file)
5329{
David Weinehall36cdd012016-08-22 13:59:31 +03005330 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005331
David Weinehall36cdd012016-08-22 13:59:31 +03005332 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005333 return 0;
5334
Chris Wilson6daccb02015-01-16 11:34:35 +02005335 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005336 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005337
5338 return 0;
5339}
5340
Ben Widawskyc43b5632012-04-16 14:07:40 -07005341static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005342{
David Weinehall36cdd012016-08-22 13:59:31 +03005343 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005344
David Weinehall36cdd012016-08-22 13:59:31 +03005345 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005346 return 0;
5347
Mika Kuoppala59bad942015-01-16 11:34:40 +02005348 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005349 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005350
5351 return 0;
5352}
5353
5354static const struct file_operations i915_forcewake_fops = {
5355 .owner = THIS_MODULE,
5356 .open = i915_forcewake_open,
5357 .release = i915_forcewake_release,
5358};
5359
5360static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5361{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005362 struct dentry *ent;
5363
5364 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005365 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005366 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005367 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005368 if (!ent)
5369 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005370
Ben Widawsky8eb57292011-05-11 15:10:58 -07005371 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005372}
5373
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005374static int i915_debugfs_create(struct dentry *root,
5375 struct drm_minor *minor,
5376 const char *name,
5377 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005378{
Jesse Barnes358733e2011-07-27 11:53:01 -07005379 struct dentry *ent;
5380
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005381 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005382 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005383 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005384 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005385 if (!ent)
5386 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005387
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005388 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005389}
5390
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005391static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005392 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005393 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005394 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005395 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005396 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005397 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005398 {"i915_gem_request", i915_gem_request_info, 0},
5399 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005400 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005401 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08005402 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005403 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005404 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005405 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305406 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005407 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005408 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005409 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005410 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005411 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005412 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005413 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005414 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005415 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005416 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005417 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005418 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005419 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005420 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005421 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005422 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005423 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005424 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005425 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005426 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005427 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005428 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005429 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005430 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005431 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005432 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005433 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005434 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005435 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005436 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005437 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305438 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005439 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005440};
Ben Gamari27c202a2009-07-01 22:26:52 -04005441#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005442
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005443static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005444 const char *name;
5445 const struct file_operations *fops;
5446} i915_debugfs_files[] = {
5447 {"i915_wedged", &i915_wedged_fops},
5448 {"i915_max_freq", &i915_max_freq_fops},
5449 {"i915_min_freq", &i915_min_freq_fops},
5450 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005451 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5452 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005453 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005454#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005455 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005456#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005457 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005458 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005459 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5460 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5461 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005462 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005463 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5464 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05305465 {"i915_dp_test_active", &i915_displayport_test_active_fops},
5466 {"i915_guc_log_control", &i915_guc_log_control_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005467};
5468
David Weinehall36cdd012016-08-22 13:59:31 +03005469void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005470{
Daniel Vetterb3783602013-11-14 11:30:42 +01005471 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005472
Damien Lespiau055e3932014-08-18 13:49:10 +01005473 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005474 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005475
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005476 pipe_crc->opened = false;
5477 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005478 init_waitqueue_head(&pipe_crc->wq);
5479 }
5480}
5481
Chris Wilson1dac8912016-06-24 14:00:17 +01005482int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005483{
Chris Wilson91c8a322016-07-05 10:40:23 +01005484 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005485 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005486
Ben Widawsky6d794d42011-04-25 11:25:56 -07005487 ret = i915_forcewake_create(minor->debugfs_root, minor);
5488 if (ret)
5489 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005490
Damien Lespiau07144422013-10-15 18:55:40 +01005491 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5492 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5493 if (ret)
5494 return ret;
5495 }
5496
Daniel Vetter34b96742013-07-04 20:49:44 +02005497 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5498 ret = i915_debugfs_create(minor->debugfs_root, minor,
5499 i915_debugfs_files[i].name,
5500 i915_debugfs_files[i].fops);
5501 if (ret)
5502 return ret;
5503 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005504
Ben Gamari27c202a2009-07-01 22:26:52 -04005505 return drm_debugfs_create_files(i915_debugfs_list,
5506 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005507 minor->debugfs_root, minor);
5508}
5509
Chris Wilson1dac8912016-06-24 14:00:17 +01005510void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005511{
Chris Wilson91c8a322016-07-05 10:40:23 +01005512 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005513 int i;
5514
Ben Gamari27c202a2009-07-01 22:26:52 -04005515 drm_debugfs_remove_files(i915_debugfs_list,
5516 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005517
David Weinehall36cdd012016-08-22 13:59:31 +03005518 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005519 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005520
Daniel Vettere309a992013-10-16 22:55:51 +02005521 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005522 struct drm_info_list *info_list =
5523 (struct drm_info_list *)&i915_pipe_crc_data[i];
5524
5525 drm_debugfs_remove_files(info_list, 1, minor);
5526 }
5527
Daniel Vetter34b96742013-07-04 20:49:44 +02005528 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5529 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005530 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005531
5532 drm_debugfs_remove_files(info_list, 1, minor);
5533 }
Ben Gamari20172632009-02-17 20:08:50 -05005534}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005535
5536struct dpcd_block {
5537 /* DPCD dump start address. */
5538 unsigned int offset;
5539 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5540 unsigned int end;
5541 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5542 size_t size;
5543 /* Only valid for eDP. */
5544 bool edp;
5545};
5546
5547static const struct dpcd_block i915_dpcd_debug[] = {
5548 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5549 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5550 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5551 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5552 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5553 { .offset = DP_SET_POWER },
5554 { .offset = DP_EDP_DPCD_REV },
5555 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5556 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5557 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5558};
5559
5560static int i915_dpcd_show(struct seq_file *m, void *data)
5561{
5562 struct drm_connector *connector = m->private;
5563 struct intel_dp *intel_dp =
5564 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5565 uint8_t buf[16];
5566 ssize_t err;
5567 int i;
5568
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005569 if (connector->status != connector_status_connected)
5570 return -ENODEV;
5571
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005572 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5573 const struct dpcd_block *b = &i915_dpcd_debug[i];
5574 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5575
5576 if (b->edp &&
5577 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5578 continue;
5579
5580 /* low tech for now */
5581 if (WARN_ON(size > sizeof(buf)))
5582 continue;
5583
5584 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5585 if (err <= 0) {
5586 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5587 size, b->offset, err);
5588 continue;
5589 }
5590
5591 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005592 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005593
5594 return 0;
5595}
5596
5597static int i915_dpcd_open(struct inode *inode, struct file *file)
5598{
5599 return single_open(file, i915_dpcd_show, inode->i_private);
5600}
5601
5602static const struct file_operations i915_dpcd_fops = {
5603 .owner = THIS_MODULE,
5604 .open = i915_dpcd_open,
5605 .read = seq_read,
5606 .llseek = seq_lseek,
5607 .release = single_release,
5608};
5609
David Weinehallecbd6782016-08-23 12:23:56 +03005610static int i915_panel_show(struct seq_file *m, void *data)
5611{
5612 struct drm_connector *connector = m->private;
5613 struct intel_dp *intel_dp =
5614 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5615
5616 if (connector->status != connector_status_connected)
5617 return -ENODEV;
5618
5619 seq_printf(m, "Panel power up delay: %d\n",
5620 intel_dp->panel_power_up_delay);
5621 seq_printf(m, "Panel power down delay: %d\n",
5622 intel_dp->panel_power_down_delay);
5623 seq_printf(m, "Backlight on delay: %d\n",
5624 intel_dp->backlight_on_delay);
5625 seq_printf(m, "Backlight off delay: %d\n",
5626 intel_dp->backlight_off_delay);
5627
5628 return 0;
5629}
5630
5631static int i915_panel_open(struct inode *inode, struct file *file)
5632{
5633 return single_open(file, i915_panel_show, inode->i_private);
5634}
5635
5636static const struct file_operations i915_panel_fops = {
5637 .owner = THIS_MODULE,
5638 .open = i915_panel_open,
5639 .read = seq_read,
5640 .llseek = seq_lseek,
5641 .release = single_release,
5642};
5643
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005644/**
5645 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5646 * @connector: pointer to a registered drm_connector
5647 *
5648 * Cleanup will be done by drm_connector_unregister() through a call to
5649 * drm_debugfs_connector_remove().
5650 *
5651 * Returns 0 on success, negative error codes on error.
5652 */
5653int i915_debugfs_connector_add(struct drm_connector *connector)
5654{
5655 struct dentry *root = connector->debugfs_entry;
5656
5657 /* The connector must have been registered beforehands. */
5658 if (!root)
5659 return -ENODEV;
5660
5661 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5662 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005663 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5664 connector, &i915_dpcd_fops);
5665
5666 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5667 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5668 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005669
5670 return 0;
5671}