blob: e97a16cb6b67eb081c6d1832030fc766b9898c58 [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));
80 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010081#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030082 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010083#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010084
85 return 0;
86}
Ben Gamari433e12f2009-02-17 20:08:51 -050087
Imre Deaka7363de2016-05-12 16:18:52 +030088static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000089{
Chris Wilson573adb32016-08-04 16:32:39 +010090 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000091}
92
Imre Deaka7363de2016-05-12 16:18:52 +030093static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010094{
95 return obj->pin_display ? 'p' : ' ';
96}
97
Imre Deaka7363de2016-05-12 16:18:52 +030098static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000099{
Chris Wilson3e510a82016-08-05 10:14:23 +0100100 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -0400101 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100102 case I915_TILING_NONE: return ' ';
103 case I915_TILING_X: return 'X';
104 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400105 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000106}
107
Imre Deaka7363de2016-05-12 16:18:52 +0300108static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700109{
Chris Wilson275f0392016-10-24 13:42:14 +0100110 return !list_empty(&obj->userfault_link) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100111}
112
Imre Deaka7363de2016-05-12 16:18:52 +0300113static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100114{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100115 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700116}
117
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100118static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
119{
120 u64 size = 0;
121 struct i915_vma *vma;
122
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000123 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100124 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100125 size += vma->node.size;
126 }
127
128 return size;
129}
130
Chris Wilson37811fc2010-08-25 22:45:57 +0100131static void
132describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
133{
Chris Wilsonb4716182015-04-27 13:41:17 +0100134 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000135 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700136 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100137 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800138 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000139 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800140
Chris Wilson188c1ab2016-04-03 14:14:20 +0100141 lockdep_assert_held(&obj->base.dev->struct_mutex);
142
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100143 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
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 Wilsonb4716182015-04-27 13:41:17 +0100152 obj->base.write_domain);
Akash Goel3b3f1652016-10-13 22:44:48 +0530153 for_each_engine(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100154 seq_printf(m, "%x ",
Chris Wilsond72d9082016-08-04 07:52:31 +0100155 i915_gem_active_get_seqno(&obj->last_read[id],
156 &obj->base.dev->struct_mutex));
Chris Wilson49ef5292016-08-18 17:17:00 +0100157 seq_printf(m, "] %x %s%s%s",
Chris Wilsond72d9082016-08-04 07:52:31 +0100158 i915_gem_active_get_seqno(&obj->last_write,
159 &obj->base.dev->struct_mutex),
David Weinehall36cdd012016-08-22 13:59:31 +0300160 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100161 obj->mm.dirty ? " dirty" : "",
162 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100163 if (obj->base.name)
164 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000165 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100166 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800167 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300168 }
169 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100170 if (obj->pin_display)
171 seq_printf(m, " (display)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000172 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100173 if (!drm_mm_node_allocated(&vma->node))
174 continue;
175
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100176 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100177 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100178 vma->node.start, vma->node.size);
Chris Wilson3272db52016-08-04 16:32:32 +0100179 if (i915_vma_is_ggtt(vma))
Chris Wilson596c5922016-02-26 11:03:20 +0000180 seq_printf(m, ", type: %u", vma->ggtt_view.type);
Chris Wilson49ef5292016-08-18 17:17:00 +0100181 if (vma->fence)
182 seq_printf(m, " , fence: %d%s",
183 vma->fence->id,
184 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000185 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700186 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000187 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100188 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100189
Chris Wilsond72d9082016-08-04 07:52:31 +0100190 engine = i915_gem_active_get_engine(&obj->last_write,
David Weinehall36cdd012016-08-22 13:59:31 +0300191 &dev_priv->drm.struct_mutex);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100192 if (engine)
193 seq_printf(m, " (%s)", engine->name);
194
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100195 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
196 if (frontbuffer_bits)
197 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100198}
199
Chris Wilson6d2b88852013-08-07 18:30:54 +0100200static int obj_rank_by_stolen(void *priv,
201 struct list_head *A, struct list_head *B)
202{
203 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200204 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100205 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200206 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100207
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200208 if (a->stolen->start < b->stolen->start)
209 return -1;
210 if (a->stolen->start > b->stolen->start)
211 return 1;
212 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100213}
214
215static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
216{
David Weinehall36cdd012016-08-22 13:59:31 +0300217 struct drm_i915_private *dev_priv = node_to_i915(m->private);
218 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100219 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300220 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100221 LIST_HEAD(stolen);
222 int count, ret;
223
224 ret = mutex_lock_interruptible(&dev->struct_mutex);
225 if (ret)
226 return ret;
227
228 total_obj_size = total_gtt_size = count = 0;
229 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
230 if (obj->stolen == NULL)
231 continue;
232
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200233 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100234
235 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100236 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100237 count++;
238 }
239 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
240 if (obj->stolen == NULL)
241 continue;
242
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200243 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100244
245 total_obj_size += obj->base.size;
246 count++;
247 }
248 list_sort(NULL, &stolen, obj_rank_by_stolen);
249 seq_puts(m, "Stolen:\n");
250 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200251 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252 seq_puts(m, " ");
253 describe_obj(m, obj);
254 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200255 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100256 }
257 mutex_unlock(&dev->struct_mutex);
258
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300259 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100260 count, total_obj_size, total_gtt_size);
261 return 0;
262}
263
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100264struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000265 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300266 unsigned long count;
267 u64 total, unbound;
268 u64 global, shared;
269 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100270};
271
272static int per_file_stats(int id, void *ptr, void *data)
273{
274 struct drm_i915_gem_object *obj = ptr;
275 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000276 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100277
278 stats->count++;
279 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100280 if (!obj->bind_count)
281 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000282 if (obj->base.name || obj->base.dma_buf)
283 stats->shared += obj->base.size;
284
Chris Wilson894eeec2016-08-04 07:52:20 +0100285 list_for_each_entry(vma, &obj->vma_list, obj_link) {
286 if (!drm_mm_node_allocated(&vma->node))
287 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000288
Chris Wilson3272db52016-08-04 16:32:32 +0100289 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100290 stats->global += vma->node.size;
291 } else {
292 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000293
Chris Wilson2bfa9962016-08-04 07:52:25 +0100294 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000295 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000296 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100297
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100298 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100299 stats->active += vma->node.size;
300 else
301 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100302 }
303
304 return 0;
305}
306
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100307#define print_file_stats(m, name, stats) do { \
308 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300309 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 +0100310 name, \
311 stats.count, \
312 stats.total, \
313 stats.active, \
314 stats.inactive, \
315 stats.global, \
316 stats.shared, \
317 stats.unbound); \
318} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800319
320static void print_batch_pool_stats(struct seq_file *m,
321 struct drm_i915_private *dev_priv)
322{
323 struct drm_i915_gem_object *obj;
324 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000325 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530326 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000327 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800328
329 memset(&stats, 0, sizeof(stats));
330
Akash Goel3b3f1652016-10-13 22:44:48 +0530331 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000332 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100333 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000334 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100335 batch_pool_link)
336 per_file_stats(0, obj, &stats);
337 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100338 }
Brad Volkin493018d2014-12-11 12:13:08 -0800339
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100340 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800341}
342
Chris Wilson15da9562016-05-24 14:53:43 +0100343static int per_file_ctx_stats(int id, void *ptr, void *data)
344{
345 struct i915_gem_context *ctx = ptr;
346 int n;
347
348 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
349 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100350 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100351 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100352 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100353 }
354
355 return 0;
356}
357
358static void print_context_stats(struct seq_file *m,
359 struct drm_i915_private *dev_priv)
360{
David Weinehall36cdd012016-08-22 13:59:31 +0300361 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100362 struct file_stats stats;
363 struct drm_file *file;
364
365 memset(&stats, 0, sizeof(stats));
366
David Weinehall36cdd012016-08-22 13:59:31 +0300367 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100368 if (dev_priv->kernel_context)
369 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
370
David Weinehall36cdd012016-08-22 13:59:31 +0300371 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100372 struct drm_i915_file_private *fpriv = file->driver_priv;
373 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
374 }
David Weinehall36cdd012016-08-22 13:59:31 +0300375 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100376
377 print_file_stats(m, "[k]contexts", stats);
378}
379
David Weinehall36cdd012016-08-22 13:59:31 +0300380static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100381{
David Weinehall36cdd012016-08-22 13:59:31 +0300382 struct drm_i915_private *dev_priv = node_to_i915(m->private);
383 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300384 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100385 u32 count, mapped_count, purgeable_count, dpy_count;
386 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000387 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100388 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100389 int ret;
390
391 ret = mutex_lock_interruptible(&dev->struct_mutex);
392 if (ret)
393 return ret;
394
Chris Wilson3ef7f222016-10-18 13:02:48 +0100395 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000396 dev_priv->mm.object_count,
397 dev_priv->mm.object_memory);
398
Chris Wilson1544c422016-08-15 13:18:16 +0100399 size = count = 0;
400 mapped_size = mapped_count = 0;
401 purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700402 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100403 size += obj->base.size;
404 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200405
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100406 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200407 purgeable_size += obj->base.size;
408 ++purgeable_count;
409 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100410
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100411 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100412 mapped_count++;
413 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100414 }
Chris Wilson6299f992010-11-24 12:23:44 +0000415 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100416 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
417
418 size = count = dpy_size = dpy_count = 0;
419 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
420 size += obj->base.size;
421 ++count;
422
423 if (obj->pin_display) {
424 dpy_size += obj->base.size;
425 ++dpy_count;
426 }
427
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100428 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100429 purgeable_size += obj->base.size;
430 ++purgeable_count;
431 }
432
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100433 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100434 mapped_count++;
435 mapped_size += obj->base.size;
436 }
437 }
438 seq_printf(m, "%u bound objects, %llu bytes\n",
439 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300440 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200441 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100442 seq_printf(m, "%u mapped objects, %llu bytes\n",
443 mapped_count, mapped_size);
444 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
445 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000446
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300447 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300448 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100449
Damien Lespiau267f0c92013-06-24 22:59:48 +0100450 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800451 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200452 mutex_unlock(&dev->struct_mutex);
453
454 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100455 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100456 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
457 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100458 struct drm_i915_file_private *file_priv = file->driver_priv;
459 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900460 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100461
462 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000463 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100464 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100465 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100466 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900467 /*
468 * Although we have a valid reference on file->pid, that does
469 * not guarantee that the task_struct who called get_pid() is
470 * still alive (e.g. get_pid(current) => fork() => exit()).
471 * Therefore, we need to protect this ->comm access using RCU.
472 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100473 mutex_lock(&dev->struct_mutex);
474 request = list_first_entry_or_null(&file_priv->mm.request_list,
475 struct drm_i915_gem_request,
476 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900477 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100478 task = pid_task(request && request->ctx->pid ?
479 request->ctx->pid : file->pid,
480 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800481 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900482 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100483 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100484 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200485 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100486
487 return 0;
488}
489
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100490static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000491{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100492 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300493 struct drm_i915_private *dev_priv = node_to_i915(node);
494 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100495 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000496 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300497 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000498 int count, ret;
499
500 ret = mutex_lock_interruptible(&dev->struct_mutex);
501 if (ret)
502 return ret;
503
504 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700505 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6da84822016-08-15 10:48:44 +0100506 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100507 continue;
508
Damien Lespiau267f0c92013-06-24 22:59:48 +0100509 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000510 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100511 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000512 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100513 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000514 count++;
515 }
516
517 mutex_unlock(&dev->struct_mutex);
518
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300519 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000520 count, total_obj_size, total_gtt_size);
521
522 return 0;
523}
524
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100525static int i915_gem_pageflip_info(struct seq_file *m, void *data)
526{
David Weinehall36cdd012016-08-22 13:59:31 +0300527 struct drm_i915_private *dev_priv = node_to_i915(m->private);
528 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100529 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200530 int ret;
531
532 ret = mutex_lock_interruptible(&dev->struct_mutex);
533 if (ret)
534 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100535
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100536 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800537 const char pipe = pipe_name(crtc->pipe);
538 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200539 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100540
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200541 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200542 work = crtc->flip_work;
543 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800544 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100545 pipe, plane);
546 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200547 u32 pending;
548 u32 addr;
549
550 pending = atomic_read(&work->pending);
551 if (pending) {
552 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
553 pipe, plane);
554 } else {
555 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
556 pipe, plane);
557 }
558 if (work->flip_queued_req) {
559 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
560
561 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
562 engine->name,
563 i915_gem_request_get_seqno(work->flip_queued_req),
564 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100565 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100566 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200567 } else
568 seq_printf(m, "Flip not associated with any ring\n");
569 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
570 work->flip_queued_vblank,
571 work->flip_ready_vblank,
572 intel_crtc_get_vblank_counter(crtc));
573 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
574
David Weinehall36cdd012016-08-22 13:59:31 +0300575 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200576 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
577 else
578 addr = I915_READ(DSPADDR(crtc->plane));
579 seq_printf(m, "Current scanout address 0x%08x\n", addr);
580
581 if (work->pending_flip_obj) {
582 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
583 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100584 }
585 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200586 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100587 }
588
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200589 mutex_unlock(&dev->struct_mutex);
590
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100591 return 0;
592}
593
Brad Volkin493018d2014-12-11 12:13:08 -0800594static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
595{
David Weinehall36cdd012016-08-22 13:59:31 +0300596 struct drm_i915_private *dev_priv = node_to_i915(m->private);
597 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800598 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000599 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530600 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100601 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000602 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800603
604 ret = mutex_lock_interruptible(&dev->struct_mutex);
605 if (ret)
606 return ret;
607
Akash Goel3b3f1652016-10-13 22:44:48 +0530608 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000609 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100610 int count;
611
612 count = 0;
613 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000614 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100615 batch_pool_link)
616 count++;
617 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000618 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100619
620 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000621 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100622 batch_pool_link) {
623 seq_puts(m, " ");
624 describe_obj(m, obj);
625 seq_putc(m, '\n');
626 }
627
628 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100629 }
Brad Volkin493018d2014-12-11 12:13:08 -0800630 }
631
Chris Wilson8d9d5742015-04-07 16:20:38 +0100632 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800633
634 mutex_unlock(&dev->struct_mutex);
635
636 return 0;
637}
638
Chris Wilson1b365952016-10-04 21:11:31 +0100639static void print_request(struct seq_file *m,
640 struct drm_i915_gem_request *rq,
641 const char *prefix)
642{
643 struct pid *pid = rq->ctx->pid;
644 struct task_struct *task;
645
646 rcu_read_lock();
647 task = pid ? pid_task(pid, PIDTYPE_PID) : NULL;
648 seq_printf(m, "%s%x [%x:%x] @ %d: %s [%d]\n", prefix,
649 rq->fence.seqno, rq->ctx->hw_id, rq->fence.seqno,
650 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
651 task ? task->comm : "<unknown>",
652 task ? task->pid : -1);
653 rcu_read_unlock();
654}
655
Ben Gamari20172632009-02-17 20:08:50 -0500656static int i915_gem_request_info(struct seq_file *m, void *data)
657{
David Weinehall36cdd012016-08-22 13:59:31 +0300658 struct drm_i915_private *dev_priv = node_to_i915(m->private);
659 struct drm_device *dev = &dev_priv->drm;
Daniel Vettereed29a52015-05-21 14:21:25 +0200660 struct drm_i915_gem_request *req;
Akash Goel3b3f1652016-10-13 22:44:48 +0530661 struct intel_engine_cs *engine;
662 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000663 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100664
665 ret = mutex_lock_interruptible(&dev->struct_mutex);
666 if (ret)
667 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500668
Chris Wilson2d1070b2015-04-01 10:36:56 +0100669 any = 0;
Akash Goel3b3f1652016-10-13 22:44:48 +0530670 for_each_engine(engine, dev_priv, id) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100671 int count;
672
673 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100674 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100675 count++;
676 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100677 continue;
678
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000679 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilson1b365952016-10-04 21:11:31 +0100680 list_for_each_entry(req, &engine->request_list, link)
681 print_request(m, req, " ");
Chris Wilson2d1070b2015-04-01 10:36:56 +0100682
683 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500684 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100685 mutex_unlock(&dev->struct_mutex);
686
Chris Wilson2d1070b2015-04-01 10:36:56 +0100687 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100688 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100689
Ben Gamari20172632009-02-17 20:08:50 -0500690 return 0;
691}
692
Chris Wilsonb2223492010-10-27 15:27:33 +0100693static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000694 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100695{
Chris Wilson688e6c72016-07-01 17:23:15 +0100696 struct intel_breadcrumbs *b = &engine->breadcrumbs;
697 struct rb_node *rb;
698
Chris Wilson12471ba2016-04-09 10:57:55 +0100699 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100700 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100701
702 spin_lock(&b->lock);
703 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
704 struct intel_wait *w = container_of(rb, typeof(*w), node);
705
706 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
707 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
708 }
709 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100710}
711
Ben Gamari20172632009-02-17 20:08:50 -0500712static int i915_gem_seqno_info(struct seq_file *m, void *data)
713{
David Weinehall36cdd012016-08-22 13:59:31 +0300714 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000715 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530716 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500717
Akash Goel3b3f1652016-10-13 22:44:48 +0530718 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000719 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100720
Ben Gamari20172632009-02-17 20:08:50 -0500721 return 0;
722}
723
724
725static int i915_interrupt_info(struct seq_file *m, void *data)
726{
David Weinehall36cdd012016-08-22 13:59:31 +0300727 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000728 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530729 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100730 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100731
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200732 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500733
David Weinehall36cdd012016-08-22 13:59:31 +0300734 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300735 seq_printf(m, "Master Interrupt Control:\t%08x\n",
736 I915_READ(GEN8_MASTER_IRQ));
737
738 seq_printf(m, "Display IER:\t%08x\n",
739 I915_READ(VLV_IER));
740 seq_printf(m, "Display IIR:\t%08x\n",
741 I915_READ(VLV_IIR));
742 seq_printf(m, "Display IIR_RW:\t%08x\n",
743 I915_READ(VLV_IIR_RW));
744 seq_printf(m, "Display IMR:\t%08x\n",
745 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100746 for_each_pipe(dev_priv, pipe) {
747 enum intel_display_power_domain power_domain;
748
749 power_domain = POWER_DOMAIN_PIPE(pipe);
750 if (!intel_display_power_get_if_enabled(dev_priv,
751 power_domain)) {
752 seq_printf(m, "Pipe %c power disabled\n",
753 pipe_name(pipe));
754 continue;
755 }
756
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300757 seq_printf(m, "Pipe %c stat:\t%08x\n",
758 pipe_name(pipe),
759 I915_READ(PIPESTAT(pipe)));
760
Chris Wilson9c870d02016-10-24 13:42:15 +0100761 intel_display_power_put(dev_priv, power_domain);
762 }
763
764 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300765 seq_printf(m, "Port hotplug:\t%08x\n",
766 I915_READ(PORT_HOTPLUG_EN));
767 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
768 I915_READ(VLV_DPFLIPSTAT));
769 seq_printf(m, "DPINVGTT:\t%08x\n",
770 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100771 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300772
773 for (i = 0; i < 4; i++) {
774 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
775 i, I915_READ(GEN8_GT_IMR(i)));
776 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
777 i, I915_READ(GEN8_GT_IIR(i)));
778 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
779 i, I915_READ(GEN8_GT_IER(i)));
780 }
781
782 seq_printf(m, "PCU interrupt mask:\t%08x\n",
783 I915_READ(GEN8_PCU_IMR));
784 seq_printf(m, "PCU interrupt identity:\t%08x\n",
785 I915_READ(GEN8_PCU_IIR));
786 seq_printf(m, "PCU interrupt enable:\t%08x\n",
787 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300788 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700789 seq_printf(m, "Master Interrupt Control:\t%08x\n",
790 I915_READ(GEN8_MASTER_IRQ));
791
792 for (i = 0; i < 4; i++) {
793 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
794 i, I915_READ(GEN8_GT_IMR(i)));
795 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
796 i, I915_READ(GEN8_GT_IIR(i)));
797 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
798 i, I915_READ(GEN8_GT_IER(i)));
799 }
800
Damien Lespiau055e3932014-08-18 13:49:10 +0100801 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200802 enum intel_display_power_domain power_domain;
803
804 power_domain = POWER_DOMAIN_PIPE(pipe);
805 if (!intel_display_power_get_if_enabled(dev_priv,
806 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300807 seq_printf(m, "Pipe %c power disabled\n",
808 pipe_name(pipe));
809 continue;
810 }
Ben Widawskya123f152013-11-02 21:07:10 -0700811 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000812 pipe_name(pipe),
813 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700814 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000815 pipe_name(pipe),
816 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700817 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000818 pipe_name(pipe),
819 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200820
821 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700822 }
823
824 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
825 I915_READ(GEN8_DE_PORT_IMR));
826 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
827 I915_READ(GEN8_DE_PORT_IIR));
828 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
829 I915_READ(GEN8_DE_PORT_IER));
830
831 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
832 I915_READ(GEN8_DE_MISC_IMR));
833 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
834 I915_READ(GEN8_DE_MISC_IIR));
835 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
836 I915_READ(GEN8_DE_MISC_IER));
837
838 seq_printf(m, "PCU interrupt mask:\t%08x\n",
839 I915_READ(GEN8_PCU_IMR));
840 seq_printf(m, "PCU interrupt identity:\t%08x\n",
841 I915_READ(GEN8_PCU_IIR));
842 seq_printf(m, "PCU interrupt enable:\t%08x\n",
843 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300844 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700845 seq_printf(m, "Display IER:\t%08x\n",
846 I915_READ(VLV_IER));
847 seq_printf(m, "Display IIR:\t%08x\n",
848 I915_READ(VLV_IIR));
849 seq_printf(m, "Display IIR_RW:\t%08x\n",
850 I915_READ(VLV_IIR_RW));
851 seq_printf(m, "Display IMR:\t%08x\n",
852 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100853 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700854 seq_printf(m, "Pipe %c stat:\t%08x\n",
855 pipe_name(pipe),
856 I915_READ(PIPESTAT(pipe)));
857
858 seq_printf(m, "Master IER:\t%08x\n",
859 I915_READ(VLV_MASTER_IER));
860
861 seq_printf(m, "Render IER:\t%08x\n",
862 I915_READ(GTIER));
863 seq_printf(m, "Render IIR:\t%08x\n",
864 I915_READ(GTIIR));
865 seq_printf(m, "Render IMR:\t%08x\n",
866 I915_READ(GTIMR));
867
868 seq_printf(m, "PM IER:\t\t%08x\n",
869 I915_READ(GEN6_PMIER));
870 seq_printf(m, "PM IIR:\t\t%08x\n",
871 I915_READ(GEN6_PMIIR));
872 seq_printf(m, "PM IMR:\t\t%08x\n",
873 I915_READ(GEN6_PMIMR));
874
875 seq_printf(m, "Port hotplug:\t%08x\n",
876 I915_READ(PORT_HOTPLUG_EN));
877 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
878 I915_READ(VLV_DPFLIPSTAT));
879 seq_printf(m, "DPINVGTT:\t%08x\n",
880 I915_READ(DPINVGTT));
881
David Weinehall36cdd012016-08-22 13:59:31 +0300882 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800883 seq_printf(m, "Interrupt enable: %08x\n",
884 I915_READ(IER));
885 seq_printf(m, "Interrupt identity: %08x\n",
886 I915_READ(IIR));
887 seq_printf(m, "Interrupt mask: %08x\n",
888 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100889 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800890 seq_printf(m, "Pipe %c stat: %08x\n",
891 pipe_name(pipe),
892 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800893 } else {
894 seq_printf(m, "North Display Interrupt enable: %08x\n",
895 I915_READ(DEIER));
896 seq_printf(m, "North Display Interrupt identity: %08x\n",
897 I915_READ(DEIIR));
898 seq_printf(m, "North Display Interrupt mask: %08x\n",
899 I915_READ(DEIMR));
900 seq_printf(m, "South Display Interrupt enable: %08x\n",
901 I915_READ(SDEIER));
902 seq_printf(m, "South Display Interrupt identity: %08x\n",
903 I915_READ(SDEIIR));
904 seq_printf(m, "South Display Interrupt mask: %08x\n",
905 I915_READ(SDEIMR));
906 seq_printf(m, "Graphics Interrupt enable: %08x\n",
907 I915_READ(GTIER));
908 seq_printf(m, "Graphics Interrupt identity: %08x\n",
909 I915_READ(GTIIR));
910 seq_printf(m, "Graphics Interrupt mask: %08x\n",
911 I915_READ(GTIMR));
912 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530913 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300914 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100915 seq_printf(m,
916 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000917 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000918 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000919 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000920 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200921 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100922
Ben Gamari20172632009-02-17 20:08:50 -0500923 return 0;
924}
925
Chris Wilsona6172a82009-02-11 14:26:38 +0000926static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
927{
David Weinehall36cdd012016-08-22 13:59:31 +0300928 struct drm_i915_private *dev_priv = node_to_i915(m->private);
929 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100930 int i, ret;
931
932 ret = mutex_lock_interruptible(&dev->struct_mutex);
933 if (ret)
934 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000935
Chris Wilsona6172a82009-02-11 14:26:38 +0000936 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
937 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100938 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000939
Chris Wilson6c085a72012-08-20 11:40:46 +0200940 seq_printf(m, "Fence %d, pin count = %d, object = ",
941 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100942 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100943 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100944 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100945 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100946 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000947 }
948
Chris Wilson05394f32010-11-08 19:18:58 +0000949 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000950 return 0;
951}
952
Ben Gamari20172632009-02-17 20:08:50 -0500953static int i915_hws_info(struct seq_file *m, void *data)
954{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100955 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300956 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000957 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100958 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100959 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500960
Akash Goel3b3f1652016-10-13 22:44:48 +0530961 engine = dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000962 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500963 if (hws == NULL)
964 return 0;
965
966 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
967 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
968 i * 4,
969 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
970 }
971 return 0;
972}
973
Chris Wilson98a2f412016-10-12 10:05:18 +0100974#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
975
Daniel Vetterd5442302012-04-27 15:17:40 +0200976static ssize_t
977i915_error_state_write(struct file *filp,
978 const char __user *ubuf,
979 size_t cnt,
980 loff_t *ppos)
981{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300982 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200983
984 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100985 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200986
987 return cnt;
988}
989
990static int i915_error_state_open(struct inode *inode, struct file *file)
991{
David Weinehall36cdd012016-08-22 13:59:31 +0300992 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200993 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200994
995 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
996 if (!error_priv)
997 return -ENOMEM;
998
David Weinehall36cdd012016-08-22 13:59:31 +0300999 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +02001000
David Weinehall36cdd012016-08-22 13:59:31 +03001001 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001002
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001003 file->private_data = error_priv;
1004
1005 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001006}
1007
1008static int i915_error_state_release(struct inode *inode, struct file *file)
1009{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001010 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001011
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001012 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001013 kfree(error_priv);
1014
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001015 return 0;
1016}
1017
1018static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1019 size_t count, loff_t *pos)
1020{
1021 struct i915_error_state_file_priv *error_priv = file->private_data;
1022 struct drm_i915_error_state_buf error_str;
1023 loff_t tmp_pos = 0;
1024 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001025 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001026
David Weinehall36cdd012016-08-22 13:59:31 +03001027 ret = i915_error_state_buf_init(&error_str,
1028 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001029 if (ret)
1030 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001031
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001032 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001033 if (ret)
1034 goto out;
1035
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001036 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1037 error_str.buf,
1038 error_str.bytes);
1039
1040 if (ret_count < 0)
1041 ret = ret_count;
1042 else
1043 *pos = error_str.start + ret_count;
1044out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001045 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001046 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001047}
1048
1049static const struct file_operations i915_error_state_fops = {
1050 .owner = THIS_MODULE,
1051 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001052 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001053 .write = i915_error_state_write,
1054 .llseek = default_llseek,
1055 .release = i915_error_state_release,
1056};
1057
Chris Wilson98a2f412016-10-12 10:05:18 +01001058#endif
1059
Kees Cook647416f2013-03-10 14:10:06 -07001060static int
1061i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001062{
David Weinehall36cdd012016-08-22 13:59:31 +03001063 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001064 int ret;
1065
David Weinehall36cdd012016-08-22 13:59:31 +03001066 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001067 if (ret)
1068 return ret;
1069
Kees Cook647416f2013-03-10 14:10:06 -07001070 *val = dev_priv->next_seqno;
David Weinehall36cdd012016-08-22 13:59:31 +03001071 mutex_unlock(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001072
Kees Cook647416f2013-03-10 14:10:06 -07001073 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001074}
1075
Kees Cook647416f2013-03-10 14:10:06 -07001076static int
1077i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001078{
David Weinehall36cdd012016-08-22 13:59:31 +03001079 struct drm_i915_private *dev_priv = data;
1080 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001081 int ret;
1082
Mika Kuoppala40633212012-12-04 15:12:00 +02001083 ret = mutex_lock_interruptible(&dev->struct_mutex);
1084 if (ret)
1085 return ret;
1086
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001087 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001088 mutex_unlock(&dev->struct_mutex);
1089
Kees Cook647416f2013-03-10 14:10:06 -07001090 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001091}
1092
Kees Cook647416f2013-03-10 14:10:06 -07001093DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1094 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001095 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001096
Deepak Sadb4bd12014-03-31 11:30:02 +05301097static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001098{
David Weinehall36cdd012016-08-22 13:59:31 +03001099 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1100 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001101 int ret = 0;
1102
1103 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001104
David Weinehall36cdd012016-08-22 13:59:31 +03001105 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001106 u16 rgvswctl = I915_READ16(MEMSWCTL);
1107 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1108
1109 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1110 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1111 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1112 MEMSTAT_VID_SHIFT);
1113 seq_printf(m, "Current P-state: %d\n",
1114 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001115 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001116 u32 freq_sts;
1117
1118 mutex_lock(&dev_priv->rps.hw_lock);
1119 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1120 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1121 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1122
1123 seq_printf(m, "actual GPU freq: %d MHz\n",
1124 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1125
1126 seq_printf(m, "current GPU freq: %d MHz\n",
1127 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1128
1129 seq_printf(m, "max GPU freq: %d MHz\n",
1130 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1131
1132 seq_printf(m, "min GPU freq: %d MHz\n",
1133 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1134
1135 seq_printf(m, "idle GPU freq: %d MHz\n",
1136 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1137
1138 seq_printf(m,
1139 "efficient (RPe) frequency: %d MHz\n",
1140 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1141 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001142 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001143 u32 rp_state_limits;
1144 u32 gt_perf_status;
1145 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001146 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001147 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001148 u32 rpupei, rpcurup, rpprevup;
1149 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001150 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001151 int max_freq;
1152
Bob Paauwe35040562015-06-25 14:54:07 -07001153 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001154 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001155 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1156 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1157 } else {
1158 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1159 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1160 }
1161
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001162 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001163 ret = mutex_lock_interruptible(&dev->struct_mutex);
1164 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001165 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001166
Mika Kuoppala59bad942015-01-16 11:34:40 +02001167 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001168
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001169 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001170 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301171 reqf >>= 23;
1172 else {
1173 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001174 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301175 reqf >>= 24;
1176 else
1177 reqf >>= 25;
1178 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001179 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001180
Chris Wilson0d8f9492014-03-27 09:06:14 +00001181 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1182 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1183 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1184
Jesse Barnesccab5c82011-01-18 15:49:25 -08001185 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301186 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1187 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1188 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1189 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1190 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1191 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001192 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301193 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001194 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001195 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1196 else
1197 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001198 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001199
Mika Kuoppala59bad942015-01-16 11:34:40 +02001200 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001201 mutex_unlock(&dev->struct_mutex);
1202
David Weinehall36cdd012016-08-22 13:59:31 +03001203 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001204 pm_ier = I915_READ(GEN6_PMIER);
1205 pm_imr = I915_READ(GEN6_PMIMR);
1206 pm_isr = I915_READ(GEN6_PMISR);
1207 pm_iir = I915_READ(GEN6_PMIIR);
1208 pm_mask = I915_READ(GEN6_PMINTRMSK);
1209 } else {
1210 pm_ier = I915_READ(GEN8_GT_IER(2));
1211 pm_imr = I915_READ(GEN8_GT_IMR(2));
1212 pm_isr = I915_READ(GEN8_GT_ISR(2));
1213 pm_iir = I915_READ(GEN8_GT_IIR(2));
1214 pm_mask = I915_READ(GEN6_PMINTRMSK);
1215 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001216 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001217 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301218 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001219 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001220 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001221 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001222 seq_printf(m, "Render p-state VID: %d\n",
1223 gt_perf_status & 0xff);
1224 seq_printf(m, "Render p-state limit: %d\n",
1225 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001226 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1227 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1228 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1229 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001230 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001231 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301232 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1233 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1234 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1235 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1236 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1237 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001238 seq_printf(m, "Up threshold: %d%%\n",
1239 dev_priv->rps.up_threshold);
1240
Akash Goeld6cda9c2016-04-23 00:05:46 +05301241 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1242 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1243 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1244 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1245 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1246 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001247 seq_printf(m, "Down threshold: %d%%\n",
1248 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001249
David Weinehall36cdd012016-08-22 13:59:31 +03001250 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001251 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001252 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001253 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001254 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001255 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001256
1257 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001258 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001259 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001261 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001262
David Weinehall36cdd012016-08-22 13:59:31 +03001263 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001264 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001265 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001266 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001267 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001268 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001269 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001270 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001271
Chris Wilsond86ed342015-04-27 13:41:19 +01001272 seq_printf(m, "Current freq: %d MHz\n",
1273 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1274 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001275 seq_printf(m, "Idle freq: %d MHz\n",
1276 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001277 seq_printf(m, "Min freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001279 seq_printf(m, "Boost freq: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001281 seq_printf(m, "Max freq: %d MHz\n",
1282 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1283 seq_printf(m,
1284 "efficient (RPe) frequency: %d MHz\n",
1285 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001286 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001287 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001288 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001289
Mika Kahola1170f282015-09-25 14:00:32 +03001290 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1291 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1292 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1293
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001294out:
1295 intel_runtime_pm_put(dev_priv);
1296 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001297}
1298
Ben Widawskyd6369512016-09-20 16:54:32 +03001299static void i915_instdone_info(struct drm_i915_private *dev_priv,
1300 struct seq_file *m,
1301 struct intel_instdone *instdone)
1302{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001303 int slice;
1304 int subslice;
1305
Ben Widawskyd6369512016-09-20 16:54:32 +03001306 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1307 instdone->instdone);
1308
1309 if (INTEL_GEN(dev_priv) <= 3)
1310 return;
1311
1312 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1313 instdone->slice_common);
1314
1315 if (INTEL_GEN(dev_priv) <= 6)
1316 return;
1317
Ben Widawskyf9e61372016-09-20 16:54:33 +03001318 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1319 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1320 slice, subslice, instdone->sampler[slice][subslice]);
1321
1322 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1323 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1324 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001325}
1326
Chris Wilsonf6544492015-01-26 18:03:04 +02001327static int i915_hangcheck_info(struct seq_file *m, void *unused)
1328{
David Weinehall36cdd012016-08-22 13:59:31 +03001329 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001330 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001331 u64 acthd[I915_NUM_ENGINES];
1332 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001333 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001334 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001335
Chris Wilson8af29b02016-09-09 14:11:47 +01001336 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1337 seq_printf(m, "Wedged\n");
1338 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1339 seq_printf(m, "Reset in progress\n");
1340 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1341 seq_printf(m, "Waiter holding struct mutex\n");
1342 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1343 seq_printf(m, "struct_mutex blocked for reset\n");
1344
Chris Wilsonf6544492015-01-26 18:03:04 +02001345 if (!i915.enable_hangcheck) {
1346 seq_printf(m, "Hangcheck disabled\n");
1347 return 0;
1348 }
1349
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001350 intel_runtime_pm_get(dev_priv);
1351
Akash Goel3b3f1652016-10-13 22:44:48 +05301352 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001353 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001354 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001355 }
1356
Akash Goel3b3f1652016-10-13 22:44:48 +05301357 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001358
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001359 intel_runtime_pm_put(dev_priv);
1360
Chris Wilsonf6544492015-01-26 18:03:04 +02001361 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1362 seq_printf(m, "Hangcheck active, fires in %dms\n",
1363 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1364 jiffies));
1365 } else
1366 seq_printf(m, "Hangcheck inactive\n");
1367
Akash Goel3b3f1652016-10-13 22:44:48 +05301368 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001369 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1370 struct rb_node *rb;
1371
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001372 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001373 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1374 engine->hangcheck.seqno,
1375 seqno[id],
1376 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001377 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1378 yesno(intel_engine_has_waiter(engine)),
1379 yesno(test_bit(engine->id,
1380 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilson33f53712016-10-04 21:11:32 +01001381 spin_lock(&b->lock);
1382 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1383 struct intel_wait *w = container_of(rb, typeof(*w), node);
1384
1385 seq_printf(m, "\t%s [%d] waiting for %x\n",
1386 w->tsk->comm, w->tsk->pid, w->seqno);
1387 }
1388 spin_unlock(&b->lock);
1389
Chris Wilsonf6544492015-01-26 18:03:04 +02001390 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001391 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001392 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001393 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1394 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001395
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001396 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001397 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001398
Ben Widawskyd6369512016-09-20 16:54:32 +03001399 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001400
Ben Widawskyd6369512016-09-20 16:54:32 +03001401 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001402
Ben Widawskyd6369512016-09-20 16:54:32 +03001403 i915_instdone_info(dev_priv, m,
1404 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001405 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001406 }
1407
1408 return 0;
1409}
1410
Ben Widawsky4d855292011-12-12 19:34:16 -08001411static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001412{
David Weinehall36cdd012016-08-22 13:59:31 +03001413 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001414 u32 rgvmodectl, rstdbyctl;
1415 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001416
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001417 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001418
1419 rgvmodectl = I915_READ(MEMMODECTL);
1420 rstdbyctl = I915_READ(RSTDBYCTL);
1421 crstandvid = I915_READ16(CRSTANDVID);
1422
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001423 intel_runtime_pm_put(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001424
Jani Nikula742f4912015-09-03 11:16:09 +03001425 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426 seq_printf(m, "Boost freq: %d\n",
1427 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1428 MEMMODE_BOOST_FREQ_SHIFT);
1429 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001430 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001431 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001432 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001433 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001434 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001435 seq_printf(m, "Starting frequency: P%d\n",
1436 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001437 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001438 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001439 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1440 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1441 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1442 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001443 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 switch (rstdbyctl & RSX_STATUS_MASK) {
1446 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 break;
1449 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001457 break;
1458 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001459 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001460 break;
1461 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001462 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001463 break;
1464 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001465 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001466 break;
1467 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001468
1469 return 0;
1470}
1471
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001472static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001473{
David Weinehall36cdd012016-08-22 13:59:31 +03001474 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001475 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001476
1477 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001478 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001479 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001480 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001481 fw_domain->wake_count);
1482 }
1483 spin_unlock_irq(&dev_priv->uncore.lock);
1484
1485 return 0;
1486}
1487
Deepak S669ab5a2014-01-10 15:18:26 +05301488static int vlv_drpc_info(struct seq_file *m)
1489{
David Weinehall36cdd012016-08-22 13:59:31 +03001490 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001491 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301492
Imre Deakd46c0512014-04-14 20:24:27 +03001493 intel_runtime_pm_get(dev_priv);
1494
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001495 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301496 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1497 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1498
Imre Deakd46c0512014-04-14 20:24:27 +03001499 intel_runtime_pm_put(dev_priv);
1500
Deepak S669ab5a2014-01-10 15:18:26 +05301501 seq_printf(m, "Video Turbo Mode: %s\n",
1502 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1503 seq_printf(m, "Turbo enabled: %s\n",
1504 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1505 seq_printf(m, "HW control enabled: %s\n",
1506 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1507 seq_printf(m, "SW control enabled: %s\n",
1508 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1509 GEN6_RP_MEDIA_SW_MODE));
1510 seq_printf(m, "RC6 Enabled: %s\n",
1511 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1512 GEN6_RC_CTL_EI_MODE(1))));
1513 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001514 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301515 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001516 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301517
Imre Deak9cc19be2014-04-14 20:24:24 +03001518 seq_printf(m, "Render RC6 residency since boot: %u\n",
1519 I915_READ(VLV_GT_RENDER_RC6));
1520 seq_printf(m, "Media RC6 residency since boot: %u\n",
1521 I915_READ(VLV_GT_MEDIA_RC6));
1522
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001523 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301524}
1525
Ben Widawsky4d855292011-12-12 19:34:16 -08001526static int gen6_drpc_info(struct seq_file *m)
1527{
David Weinehall36cdd012016-08-22 13:59:31 +03001528 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1529 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001530 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301531 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001532 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001533 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001534
1535 ret = mutex_lock_interruptible(&dev->struct_mutex);
1536 if (ret)
1537 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001538 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001539
Chris Wilson907b28c2013-07-19 20:36:52 +01001540 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001541 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001542 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001543
1544 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "RC information inaccurate because somebody "
1546 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 } else {
1548 /* NB: we cannot use forcewake, else we read the wrong values */
1549 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1550 udelay(10);
1551 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1552 }
1553
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001554 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001555 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001556
1557 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1558 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001559 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301560 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1561 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1562 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001564 mutex_lock(&dev_priv->rps.hw_lock);
1565 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1566 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001567
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001568 intel_runtime_pm_put(dev_priv);
1569
Ben Widawsky4d855292011-12-12 19:34:16 -08001570 seq_printf(m, "Video Turbo Mode: %s\n",
1571 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1572 seq_printf(m, "HW control enabled: %s\n",
1573 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1574 seq_printf(m, "SW control enabled: %s\n",
1575 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1576 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001577 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001578 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1579 seq_printf(m, "RC6 Enabled: %s\n",
1580 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001581 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301582 seq_printf(m, "Render Well Gating Enabled: %s\n",
1583 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1584 seq_printf(m, "Media Well Gating Enabled: %s\n",
1585 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1586 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 seq_printf(m, "Deep RC6 Enabled: %s\n",
1588 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1589 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1590 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001591 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001592 switch (gt_core_status & GEN6_RCn_MASK) {
1593 case GEN6_RC0:
1594 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001596 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001597 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001598 break;
1599 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001600 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001601 break;
1602 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001603 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001604 break;
1605 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001606 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001607 break;
1608 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001609 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001610 break;
1611 }
1612
1613 seq_printf(m, "Core Power Down: %s\n",
1614 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001615 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301616 seq_printf(m, "Render Power Well: %s\n",
1617 (gen9_powergate_status &
1618 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1619 seq_printf(m, "Media Power Well: %s\n",
1620 (gen9_powergate_status &
1621 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1622 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001623
1624 /* Not exactly sure what this is */
1625 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1626 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1627 seq_printf(m, "RC6 residency since boot: %u\n",
1628 I915_READ(GEN6_GT_GFX_RC6));
1629 seq_printf(m, "RC6+ residency since boot: %u\n",
1630 I915_READ(GEN6_GT_GFX_RC6p));
1631 seq_printf(m, "RC6++ residency since boot: %u\n",
1632 I915_READ(GEN6_GT_GFX_RC6pp));
1633
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001634 seq_printf(m, "RC6 voltage: %dmV\n",
1635 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1636 seq_printf(m, "RC6+ voltage: %dmV\n",
1637 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1638 seq_printf(m, "RC6++ voltage: %dmV\n",
1639 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301640 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001641}
1642
1643static int i915_drpc_info(struct seq_file *m, void *unused)
1644{
David Weinehall36cdd012016-08-22 13:59:31 +03001645 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001646
David Weinehall36cdd012016-08-22 13:59:31 +03001647 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301648 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001649 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001650 return gen6_drpc_info(m);
1651 else
1652 return ironlake_drpc_info(m);
1653}
1654
Daniel Vetter9a851782015-06-18 10:30:22 +02001655static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1656{
David Weinehall36cdd012016-08-22 13:59:31 +03001657 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001658
1659 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1660 dev_priv->fb_tracking.busy_bits);
1661
1662 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1663 dev_priv->fb_tracking.flip_bits);
1664
1665 return 0;
1666}
1667
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001668static int i915_fbc_status(struct seq_file *m, void *unused)
1669{
David Weinehall36cdd012016-08-22 13:59:31 +03001670 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001671
David Weinehall36cdd012016-08-22 13:59:31 +03001672 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001673 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001674 return 0;
1675 }
1676
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001677 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001678 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001679
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001680 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001681 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001682 else
1683 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001684 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001685
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001686 if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
1687 uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
1688 BDW_FBC_COMPRESSION_MASK :
1689 IVB_FBC_COMPRESSION_MASK;
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001690 seq_printf(m, "Compressing: %s\n",
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001691 yesno(I915_READ(FBC_STATUS2) & mask));
1692 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001693
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001694 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001695 intel_runtime_pm_put(dev_priv);
1696
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001697 return 0;
1698}
1699
Rodrigo Vivida46f932014-08-01 02:04:45 -07001700static int i915_fbc_fc_get(void *data, u64 *val)
1701{
David Weinehall36cdd012016-08-22 13:59:31 +03001702 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001703
David Weinehall36cdd012016-08-22 13:59:31 +03001704 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001705 return -ENODEV;
1706
Rodrigo Vivida46f932014-08-01 02:04:45 -07001707 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001708
1709 return 0;
1710}
1711
1712static int i915_fbc_fc_set(void *data, u64 val)
1713{
David Weinehall36cdd012016-08-22 13:59:31 +03001714 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001715 u32 reg;
1716
David Weinehall36cdd012016-08-22 13:59:31 +03001717 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001718 return -ENODEV;
1719
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001720 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001721
1722 reg = I915_READ(ILK_DPFC_CONTROL);
1723 dev_priv->fbc.false_color = val;
1724
1725 I915_WRITE(ILK_DPFC_CONTROL, val ?
1726 (reg | FBC_CTL_FALSE_COLOR) :
1727 (reg & ~FBC_CTL_FALSE_COLOR));
1728
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001729 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001730 return 0;
1731}
1732
1733DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1734 i915_fbc_fc_get, i915_fbc_fc_set,
1735 "%llu\n");
1736
Paulo Zanoni92d44622013-05-31 16:33:24 -03001737static int i915_ips_status(struct seq_file *m, void *unused)
1738{
David Weinehall36cdd012016-08-22 13:59:31 +03001739 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001740
David Weinehall36cdd012016-08-22 13:59:31 +03001741 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001742 seq_puts(m, "not supported\n");
1743 return 0;
1744 }
1745
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001746 intel_runtime_pm_get(dev_priv);
1747
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001748 seq_printf(m, "Enabled by kernel parameter: %s\n",
1749 yesno(i915.enable_ips));
1750
David Weinehall36cdd012016-08-22 13:59:31 +03001751 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001752 seq_puts(m, "Currently: unknown\n");
1753 } else {
1754 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1755 seq_puts(m, "Currently: enabled\n");
1756 else
1757 seq_puts(m, "Currently: disabled\n");
1758 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001759
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001760 intel_runtime_pm_put(dev_priv);
1761
Paulo Zanoni92d44622013-05-31 16:33:24 -03001762 return 0;
1763}
1764
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001765static int i915_sr_status(struct seq_file *m, void *unused)
1766{
David Weinehall36cdd012016-08-22 13:59:31 +03001767 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001768 bool sr_enabled = false;
1769
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001770 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001771 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001772
David Weinehall36cdd012016-08-22 13:59:31 +03001773 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001774 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001775 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1776 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001777 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001778 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001779 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001780 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001781 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001782 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001783 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001784
Chris Wilson9c870d02016-10-24 13:42:15 +01001785 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001786 intel_runtime_pm_put(dev_priv);
1787
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001788 seq_printf(m, "self-refresh: %s\n",
1789 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001790
1791 return 0;
1792}
1793
Jesse Barnes7648fa92010-05-20 14:28:11 -07001794static int i915_emon_status(struct seq_file *m, void *unused)
1795{
David Weinehall36cdd012016-08-22 13:59:31 +03001796 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1797 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001798 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001799 int ret;
1800
David Weinehall36cdd012016-08-22 13:59:31 +03001801 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001802 return -ENODEV;
1803
Chris Wilsonde227ef2010-07-03 07:58:38 +01001804 ret = mutex_lock_interruptible(&dev->struct_mutex);
1805 if (ret)
1806 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001807
1808 temp = i915_mch_val(dev_priv);
1809 chipset = i915_chipset_val(dev_priv);
1810 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001811 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001812
1813 seq_printf(m, "GMCH temp: %ld\n", temp);
1814 seq_printf(m, "Chipset power: %ld\n", chipset);
1815 seq_printf(m, "GFX power: %ld\n", gfx);
1816 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1817
1818 return 0;
1819}
1820
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001821static int i915_ring_freq_table(struct seq_file *m, void *unused)
1822{
David Weinehall36cdd012016-08-22 13:59:31 +03001823 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001824 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001825 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301826 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827
Carlos Santa26310342016-08-17 12:30:41 -07001828 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001829 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001830 return 0;
1831 }
1832
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001833 intel_runtime_pm_get(dev_priv);
1834
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001835 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001836 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001837 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001838
David Weinehall36cdd012016-08-22 13:59:31 +03001839 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301840 /* Convert GT frequency to 50 HZ units */
1841 min_gpu_freq =
1842 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1843 max_gpu_freq =
1844 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1845 } else {
1846 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1847 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1848 }
1849
Damien Lespiau267f0c92013-06-24 22:59:48 +01001850 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001851
Akash Goelf936ec32015-06-29 14:50:22 +05301852 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001853 ia_freq = gpu_freq;
1854 sandybridge_pcode_read(dev_priv,
1855 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1856 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001857 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301858 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001859 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001860 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001861 ((ia_freq >> 0) & 0xff) * 100,
1862 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001863 }
1864
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001865 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001866
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001867out:
1868 intel_runtime_pm_put(dev_priv);
1869 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001870}
1871
Chris Wilson44834a62010-08-19 16:09:23 +01001872static int i915_opregion(struct seq_file *m, void *unused)
1873{
David Weinehall36cdd012016-08-22 13:59:31 +03001874 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1875 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001876 struct intel_opregion *opregion = &dev_priv->opregion;
1877 int ret;
1878
1879 ret = mutex_lock_interruptible(&dev->struct_mutex);
1880 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001881 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001882
Jani Nikula2455a8e2015-12-14 12:50:53 +02001883 if (opregion->header)
1884 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001885
1886 mutex_unlock(&dev->struct_mutex);
1887
Daniel Vetter0d38f002012-04-21 22:49:10 +02001888out:
Chris Wilson44834a62010-08-19 16:09:23 +01001889 return 0;
1890}
1891
Jani Nikulaada8f952015-12-15 13:17:12 +02001892static int i915_vbt(struct seq_file *m, void *unused)
1893{
David Weinehall36cdd012016-08-22 13:59:31 +03001894 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001895
1896 if (opregion->vbt)
1897 seq_write(m, opregion->vbt, opregion->vbt_size);
1898
1899 return 0;
1900}
1901
Chris Wilson37811fc2010-08-25 22:45:57 +01001902static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1903{
David Weinehall36cdd012016-08-22 13:59:31 +03001904 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1905 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301906 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001907 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001908 int ret;
1909
1910 ret = mutex_lock_interruptible(&dev->struct_mutex);
1911 if (ret)
1912 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001913
Daniel Vetter06957262015-08-10 13:34:08 +02001914#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001915 if (dev_priv->fbdev) {
1916 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001917
Chris Wilson25bcce92016-07-02 15:36:00 +01001918 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1919 fbdev_fb->base.width,
1920 fbdev_fb->base.height,
1921 fbdev_fb->base.depth,
1922 fbdev_fb->base.bits_per_pixel,
1923 fbdev_fb->base.modifier[0],
1924 drm_framebuffer_read_refcount(&fbdev_fb->base));
1925 describe_obj(m, fbdev_fb->obj);
1926 seq_putc(m, '\n');
1927 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001928#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001929
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001930 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001931 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301932 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1933 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001934 continue;
1935
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001936 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 +01001937 fb->base.width,
1938 fb->base.height,
1939 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001940 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001941 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001942 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001943 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001944 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001945 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001946 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001947 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001948
1949 return 0;
1950}
1951
Chris Wilson7e37f882016-08-02 22:50:21 +01001952static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001953{
1954 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001955 ring->space, ring->head, ring->tail,
1956 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001957}
1958
Ben Widawskye76d3632011-03-19 18:14:29 -07001959static int i915_context_status(struct seq_file *m, void *unused)
1960{
David Weinehall36cdd012016-08-22 13:59:31 +03001961 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1962 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001963 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001964 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301965 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001966 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001967
Daniel Vetterf3d28872014-05-29 23:23:08 +02001968 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001969 if (ret)
1970 return ret;
1971
Ben Widawskya33afea2013-09-17 21:12:45 -07001972 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001973 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001974 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001975 struct task_struct *task;
1976
Chris Wilsonc84455b2016-08-15 10:49:08 +01001977 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001978 if (task) {
1979 seq_printf(m, "(%s [%d]) ",
1980 task->comm, task->pid);
1981 put_task_struct(task);
1982 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001983 } else if (IS_ERR(ctx->file_priv)) {
1984 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001985 } else {
1986 seq_puts(m, "(kernel) ");
1987 }
1988
Chris Wilsonbca44d82016-05-24 14:53:41 +01001989 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1990 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001991
Akash Goel3b3f1652016-10-13 22:44:48 +05301992 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001993 struct intel_context *ce = &ctx->engine[engine->id];
1994
1995 seq_printf(m, "%s: ", engine->name);
1996 seq_putc(m, ce->initialised ? 'I' : 'i');
1997 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001998 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001999 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01002000 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002001 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002002 }
2003
Ben Widawskya33afea2013-09-17 21:12:45 -07002004 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002005 }
2006
Daniel Vetterf3d28872014-05-29 23:23:08 +02002007 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002008
2009 return 0;
2010}
2011
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002012static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002013 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002014 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002015{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002016 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002017 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002018 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002019
Chris Wilson7069b142016-04-28 09:56:52 +01002020 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2021
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002022 if (!vma) {
2023 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002024 return;
2025 }
2026
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002027 if (vma->flags & I915_VMA_GLOBAL_BIND)
2028 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002029 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002030
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002031 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002032 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002033 return;
2034 }
2035
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002036 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2037 if (page) {
2038 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002039
2040 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002041 seq_printf(m,
2042 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2043 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002044 reg_state[j], reg_state[j + 1],
2045 reg_state[j + 2], reg_state[j + 3]);
2046 }
2047 kunmap_atomic(reg_state);
2048 }
2049
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002050 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002051 seq_putc(m, '\n');
2052}
2053
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002054static int i915_dump_lrc(struct seq_file *m, void *unused)
2055{
David Weinehall36cdd012016-08-22 13:59:31 +03002056 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2057 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002058 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002059 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302060 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002061 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002062
2063 if (!i915.enable_execlists) {
2064 seq_printf(m, "Logical Ring Contexts are disabled\n");
2065 return 0;
2066 }
2067
2068 ret = mutex_lock_interruptible(&dev->struct_mutex);
2069 if (ret)
2070 return ret;
2071
Dave Gordone28e4042016-01-19 19:02:55 +00002072 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302073 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002074 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002075
2076 mutex_unlock(&dev->struct_mutex);
2077
2078 return 0;
2079}
2080
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002081static const char *swizzle_string(unsigned swizzle)
2082{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002083 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002084 case I915_BIT_6_SWIZZLE_NONE:
2085 return "none";
2086 case I915_BIT_6_SWIZZLE_9:
2087 return "bit9";
2088 case I915_BIT_6_SWIZZLE_9_10:
2089 return "bit9/bit10";
2090 case I915_BIT_6_SWIZZLE_9_11:
2091 return "bit9/bit11";
2092 case I915_BIT_6_SWIZZLE_9_10_11:
2093 return "bit9/bit10/bit11";
2094 case I915_BIT_6_SWIZZLE_9_17:
2095 return "bit9/bit17";
2096 case I915_BIT_6_SWIZZLE_9_10_17:
2097 return "bit9/bit10/bit17";
2098 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002099 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002100 }
2101
2102 return "bug";
2103}
2104
2105static int i915_swizzle_info(struct seq_file *m, void *data)
2106{
David Weinehall36cdd012016-08-22 13:59:31 +03002107 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002108
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002109 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002110
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002111 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2112 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2113 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2114 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2115
David Weinehall36cdd012016-08-22 13:59:31 +03002116 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002117 seq_printf(m, "DDC = 0x%08x\n",
2118 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002119 seq_printf(m, "DDC2 = 0x%08x\n",
2120 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002121 seq_printf(m, "C0DRB3 = 0x%04x\n",
2122 I915_READ16(C0DRB3));
2123 seq_printf(m, "C1DRB3 = 0x%04x\n",
2124 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002125 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002126 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2127 I915_READ(MAD_DIMM_C0));
2128 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2129 I915_READ(MAD_DIMM_C1));
2130 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2131 I915_READ(MAD_DIMM_C2));
2132 seq_printf(m, "TILECTL = 0x%08x\n",
2133 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002134 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002135 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2136 I915_READ(GAMTARBMODE));
2137 else
2138 seq_printf(m, "ARB_MODE = 0x%08x\n",
2139 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002140 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2141 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002142 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002143
2144 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2145 seq_puts(m, "L-shaped memory detected\n");
2146
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002147 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002148
2149 return 0;
2150}
2151
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002152static int per_file_ctx(int id, void *ptr, void *data)
2153{
Chris Wilsone2efd132016-05-24 14:53:34 +01002154 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002155 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002156 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2157
2158 if (!ppgtt) {
2159 seq_printf(m, " no ppgtt for context %d\n",
2160 ctx->user_handle);
2161 return 0;
2162 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002163
Oscar Mateof83d6512014-05-22 14:13:38 +01002164 if (i915_gem_context_is_default(ctx))
2165 seq_puts(m, " default context:\n");
2166 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002167 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002168 ppgtt->debug_dump(ppgtt, m);
2169
2170 return 0;
2171}
2172
David Weinehall36cdd012016-08-22 13:59:31 +03002173static void gen8_ppgtt_info(struct seq_file *m,
2174 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002175{
Ben Widawsky77df6772013-11-02 21:07:30 -07002176 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302177 struct intel_engine_cs *engine;
2178 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002179 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002180
Ben Widawsky77df6772013-11-02 21:07:30 -07002181 if (!ppgtt)
2182 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002183
Akash Goel3b3f1652016-10-13 22:44:48 +05302184 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002185 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002186 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002187 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002188 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002189 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002190 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002191 }
2192 }
2193}
2194
David Weinehall36cdd012016-08-22 13:59:31 +03002195static void gen6_ppgtt_info(struct seq_file *m,
2196 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002197{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002198 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302199 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002200
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002201 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002202 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2203
Akash Goel3b3f1652016-10-13 22:44:48 +05302204 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002205 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002206 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002207 seq_printf(m, "GFX_MODE: 0x%08x\n",
2208 I915_READ(RING_MODE_GEN7(engine)));
2209 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2210 I915_READ(RING_PP_DIR_BASE(engine)));
2211 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2212 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2213 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2214 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002215 }
2216 if (dev_priv->mm.aliasing_ppgtt) {
2217 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2218
Damien Lespiau267f0c92013-06-24 22:59:48 +01002219 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002220 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002221
Ben Widawsky87d60b62013-12-06 14:11:29 -08002222 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002223 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002224
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002225 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002226}
2227
2228static int i915_ppgtt_info(struct seq_file *m, void *data)
2229{
David Weinehall36cdd012016-08-22 13:59:31 +03002230 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2231 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002232 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002233 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002234
Chris Wilson637ee292016-08-22 14:28:20 +01002235 mutex_lock(&dev->filelist_mutex);
2236 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002237 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002238 goto out_unlock;
2239
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002240 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002241
David Weinehall36cdd012016-08-22 13:59:31 +03002242 if (INTEL_GEN(dev_priv) >= 8)
2243 gen8_ppgtt_info(m, dev_priv);
2244 else if (INTEL_GEN(dev_priv) >= 6)
2245 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002246
Michel Thierryea91e402015-07-29 17:23:57 +01002247 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2248 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002249 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002250
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002251 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002252 if (!task) {
2253 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002254 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002255 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002256 seq_printf(m, "\nproc: %s\n", task->comm);
2257 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002258 idr_for_each(&file_priv->context_idr, per_file_ctx,
2259 (void *)(unsigned long)m);
2260 }
2261
Chris Wilson637ee292016-08-22 14:28:20 +01002262out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002263 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002264 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002265out_unlock:
2266 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002267 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002268}
2269
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002270static int count_irq_waiters(struct drm_i915_private *i915)
2271{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002272 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302273 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002274 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002275
Akash Goel3b3f1652016-10-13 22:44:48 +05302276 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002277 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002278
2279 return count;
2280}
2281
Chris Wilson7466c292016-08-15 09:49:33 +01002282static const char *rps_power_to_str(unsigned int power)
2283{
2284 static const char * const strings[] = {
2285 [LOW_POWER] = "low power",
2286 [BETWEEN] = "mixed",
2287 [HIGH_POWER] = "high power",
2288 };
2289
2290 if (power >= ARRAY_SIZE(strings) || !strings[power])
2291 return "unknown";
2292
2293 return strings[power];
2294}
2295
Chris Wilson1854d5c2015-04-07 16:20:32 +01002296static int i915_rps_boost_info(struct seq_file *m, void *data)
2297{
David Weinehall36cdd012016-08-22 13:59:31 +03002298 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2299 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002300 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002301
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002302 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002303 seq_printf(m, "GPU busy? %s [%x]\n",
2304 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002305 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002306 seq_printf(m, "Frequency requested %d\n",
2307 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2308 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002309 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2310 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2311 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2312 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002313 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2314 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2315 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2316 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002317
2318 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002319 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002320 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2321 struct drm_i915_file_private *file_priv = file->driver_priv;
2322 struct task_struct *task;
2323
2324 rcu_read_lock();
2325 task = pid_task(file->pid, PIDTYPE_PID);
2326 seq_printf(m, "%s [%d]: %d boosts%s\n",
2327 task ? task->comm : "<unknown>",
2328 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002329 file_priv->rps.boosts,
2330 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002331 rcu_read_unlock();
2332 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002333 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002334 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002335 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002336
Chris Wilson7466c292016-08-15 09:49:33 +01002337 if (INTEL_GEN(dev_priv) >= 6 &&
2338 dev_priv->rps.enabled &&
2339 dev_priv->gt.active_engines) {
2340 u32 rpup, rpupei;
2341 u32 rpdown, rpdownei;
2342
2343 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2344 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2345 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2346 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2347 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2348 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2349
2350 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2351 rps_power_to_str(dev_priv->rps.power));
2352 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2353 100 * rpup / rpupei,
2354 dev_priv->rps.up_threshold);
2355 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2356 100 * rpdown / rpdownei,
2357 dev_priv->rps.down_threshold);
2358 } else {
2359 seq_puts(m, "\nRPS Autotuning inactive\n");
2360 }
2361
Chris Wilson8d3afd72015-05-21 21:01:47 +01002362 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002363}
2364
Ben Widawsky63573eb2013-07-04 11:02:07 -07002365static int i915_llc(struct seq_file *m, void *data)
2366{
David Weinehall36cdd012016-08-22 13:59:31 +03002367 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002368 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002369
David Weinehall36cdd012016-08-22 13:59:31 +03002370 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002371 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2372 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002373
2374 return 0;
2375}
2376
Alex Daifdf5d352015-08-12 15:43:37 +01002377static int i915_guc_load_status_info(struct seq_file *m, void *data)
2378{
David Weinehall36cdd012016-08-22 13:59:31 +03002379 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002380 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2381 u32 tmp, i;
2382
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002383 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002384 return 0;
2385
2386 seq_printf(m, "GuC firmware status:\n");
2387 seq_printf(m, "\tpath: %s\n",
2388 guc_fw->guc_fw_path);
2389 seq_printf(m, "\tfetch: %s\n",
2390 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2391 seq_printf(m, "\tload: %s\n",
2392 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2393 seq_printf(m, "\tversion wanted: %d.%d\n",
2394 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2395 seq_printf(m, "\tversion found: %d.%d\n",
2396 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002397 seq_printf(m, "\theader: offset is %d; size = %d\n",
2398 guc_fw->header_offset, guc_fw->header_size);
2399 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2400 guc_fw->ucode_offset, guc_fw->ucode_size);
2401 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2402 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002403
2404 tmp = I915_READ(GUC_STATUS);
2405
2406 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2407 seq_printf(m, "\tBootrom status = 0x%x\n",
2408 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2409 seq_printf(m, "\tuKernel status = 0x%x\n",
2410 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2411 seq_printf(m, "\tMIA Core status = 0x%x\n",
2412 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2413 seq_puts(m, "\nScratch registers:\n");
2414 for (i = 0; i < 16; i++)
2415 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2416
2417 return 0;
2418}
2419
Akash Goel5aa1ee42016-10-12 21:54:36 +05302420static void i915_guc_log_info(struct seq_file *m,
2421 struct drm_i915_private *dev_priv)
2422{
2423 struct intel_guc *guc = &dev_priv->guc;
2424
2425 seq_puts(m, "\nGuC logging stats:\n");
2426
2427 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2428 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2429 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2430
2431 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2432 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2433 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2434
2435 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2436 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2437 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2438
2439 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2440 guc->log.flush_interrupt_count);
2441
2442 seq_printf(m, "\tCapture miss count: %u\n",
2443 guc->log.capture_miss_count);
2444}
2445
Dave Gordon8b417c22015-08-12 15:43:44 +01002446static void i915_guc_client_info(struct seq_file *m,
2447 struct drm_i915_private *dev_priv,
2448 struct i915_guc_client *client)
2449{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002450 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002451 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002452 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002453
2454 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2455 client->priority, client->ctx_index, client->proc_desc_offset);
2456 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2457 client->doorbell_id, client->doorbell_offset, client->cookie);
2458 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2459 client->wq_size, client->wq_offset, client->wq_tail);
2460
Dave Gordon551aaec2016-05-13 15:36:33 +01002461 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002462 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2463 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2464
Akash Goel3b3f1652016-10-13 22:44:48 +05302465 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002466 u64 submissions = client->submissions[id];
2467 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002468 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002469 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002470 }
2471 seq_printf(m, "\tTotal: %llu\n", tot);
2472}
2473
2474static int i915_guc_info(struct seq_file *m, void *data)
2475{
David Weinehall36cdd012016-08-22 13:59:31 +03002476 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2477 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002478 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002479 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002480 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002481 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002482 u64 total = 0;
2483
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002484 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002485 return 0;
2486
Alex Dai5a843302015-12-02 16:56:29 -08002487 if (mutex_lock_interruptible(&dev->struct_mutex))
2488 return 0;
2489
Dave Gordon8b417c22015-08-12 15:43:44 +01002490 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002491 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002492 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002493 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002494
2495 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002496
Dave Gordon9636f6d2016-06-13 17:57:28 +01002497 seq_printf(m, "Doorbell map:\n");
2498 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2499 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2500
Dave Gordon8b417c22015-08-12 15:43:44 +01002501 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2502 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2503 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2504 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2505 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2506
2507 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302508 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002509 u64 submissions = guc.submissions[id];
2510 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002511 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002512 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002513 }
2514 seq_printf(m, "\t%s: %llu\n", "Total", total);
2515
2516 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2517 i915_guc_client_info(m, dev_priv, &client);
2518
Akash Goel5aa1ee42016-10-12 21:54:36 +05302519 i915_guc_log_info(m, dev_priv);
2520
Dave Gordon8b417c22015-08-12 15:43:44 +01002521 /* Add more as required ... */
2522
2523 return 0;
2524}
2525
Alex Dai4c7e77f2015-08-12 15:43:40 +01002526static int i915_guc_log_dump(struct seq_file *m, void *data)
2527{
David Weinehall36cdd012016-08-22 13:59:31 +03002528 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002529 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002530 int i = 0, pg;
2531
Akash Goeld6b40b42016-10-12 21:54:29 +05302532 if (!dev_priv->guc.log.vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002533 return 0;
2534
Akash Goeld6b40b42016-10-12 21:54:29 +05302535 obj = dev_priv->guc.log.vma->obj;
Chris Wilson8b797af2016-08-15 10:48:51 +01002536 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2537 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002538
2539 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2540 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2541 *(log + i), *(log + i + 1),
2542 *(log + i + 2), *(log + i + 3));
2543
2544 kunmap_atomic(log);
2545 }
2546
2547 seq_putc(m, '\n');
2548
2549 return 0;
2550}
2551
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302552static int i915_guc_log_control_get(void *data, u64 *val)
2553{
2554 struct drm_device *dev = data;
2555 struct drm_i915_private *dev_priv = to_i915(dev);
2556
2557 if (!dev_priv->guc.log.vma)
2558 return -EINVAL;
2559
2560 *val = i915.guc_log_level;
2561
2562 return 0;
2563}
2564
2565static int i915_guc_log_control_set(void *data, u64 val)
2566{
2567 struct drm_device *dev = data;
2568 struct drm_i915_private *dev_priv = to_i915(dev);
2569 int ret;
2570
2571 if (!dev_priv->guc.log.vma)
2572 return -EINVAL;
2573
2574 ret = mutex_lock_interruptible(&dev->struct_mutex);
2575 if (ret)
2576 return ret;
2577
2578 intel_runtime_pm_get(dev_priv);
2579 ret = i915_guc_log_control(dev_priv, val);
2580 intel_runtime_pm_put(dev_priv);
2581
2582 mutex_unlock(&dev->struct_mutex);
2583 return ret;
2584}
2585
2586DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2587 i915_guc_log_control_get, i915_guc_log_control_set,
2588 "%lld\n");
2589
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002590static int i915_edp_psr_status(struct seq_file *m, void *data)
2591{
David Weinehall36cdd012016-08-22 13:59:31 +03002592 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002593 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002594 u32 stat[3];
2595 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002596 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002597
David Weinehall36cdd012016-08-22 13:59:31 +03002598 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002599 seq_puts(m, "PSR not supported\n");
2600 return 0;
2601 }
2602
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002603 intel_runtime_pm_get(dev_priv);
2604
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002605 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002606 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2607 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002608 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002609 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002610 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2611 dev_priv->psr.busy_frontbuffer_bits);
2612 seq_printf(m, "Re-enable work scheduled: %s\n",
2613 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002614
David Weinehall36cdd012016-08-22 13:59:31 +03002615 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002616 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002617 else {
2618 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002619 enum transcoder cpu_transcoder =
2620 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2621 enum intel_display_power_domain power_domain;
2622
2623 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2624 if (!intel_display_power_get_if_enabled(dev_priv,
2625 power_domain))
2626 continue;
2627
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002628 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2629 VLV_EDP_PSR_CURR_STATE_MASK;
2630 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2631 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2632 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002633
2634 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002635 }
2636 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002637
2638 seq_printf(m, "Main link in standby mode: %s\n",
2639 yesno(dev_priv->psr.link_standby));
2640
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002641 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002642
David Weinehall36cdd012016-08-22 13:59:31 +03002643 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002644 for_each_pipe(dev_priv, pipe) {
2645 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2646 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2647 seq_printf(m, " pipe %c", pipe_name(pipe));
2648 }
2649 seq_puts(m, "\n");
2650
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002651 /*
2652 * VLV/CHV PSR has no kind of performance counter
2653 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2654 */
David Weinehall36cdd012016-08-22 13:59:31 +03002655 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002656 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002657 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002658
2659 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2660 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002661 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002662
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002663 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002664 return 0;
2665}
2666
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002667static int i915_sink_crc(struct seq_file *m, void *data)
2668{
David Weinehall36cdd012016-08-22 13:59:31 +03002669 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2670 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002671 struct intel_connector *connector;
2672 struct intel_dp *intel_dp = NULL;
2673 int ret;
2674 u8 crc[6];
2675
2676 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002677 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002678 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002679
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002680 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002681 continue;
2682
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002683 crtc = connector->base.state->crtc;
2684 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002685 continue;
2686
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002687 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002688 continue;
2689
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002690 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002691
2692 ret = intel_dp_sink_crc(intel_dp, crc);
2693 if (ret)
2694 goto out;
2695
2696 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2697 crc[0], crc[1], crc[2],
2698 crc[3], crc[4], crc[5]);
2699 goto out;
2700 }
2701 ret = -ENODEV;
2702out:
2703 drm_modeset_unlock_all(dev);
2704 return ret;
2705}
2706
Jesse Barnesec013e72013-08-20 10:29:23 +01002707static int i915_energy_uJ(struct seq_file *m, void *data)
2708{
David Weinehall36cdd012016-08-22 13:59:31 +03002709 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002710 u64 power;
2711 u32 units;
2712
David Weinehall36cdd012016-08-22 13:59:31 +03002713 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002714 return -ENODEV;
2715
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002716 intel_runtime_pm_get(dev_priv);
2717
Jesse Barnesec013e72013-08-20 10:29:23 +01002718 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2719 power = (power & 0x1f00) >> 8;
2720 units = 1000000 / (1 << power); /* convert to uJ */
2721 power = I915_READ(MCH_SECP_NRG_STTS);
2722 power *= units;
2723
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002724 intel_runtime_pm_put(dev_priv);
2725
Jesse Barnesec013e72013-08-20 10:29:23 +01002726 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002727
2728 return 0;
2729}
2730
Damien Lespiau6455c872015-06-04 18:23:57 +01002731static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002732{
David Weinehall36cdd012016-08-22 13:59:31 +03002733 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002734 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002735
Chris Wilsona156e642016-04-03 14:14:21 +01002736 if (!HAS_RUNTIME_PM(dev_priv))
2737 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002738
Chris Wilson67d97da2016-07-04 08:08:31 +01002739 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002740 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002741 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002742#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002743 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002744 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002745#else
2746 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2747#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002748 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002749 pci_power_name(pdev->current_state),
2750 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002751
Jesse Barnesec013e72013-08-20 10:29:23 +01002752 return 0;
2753}
2754
Imre Deak1da51582013-11-25 17:15:35 +02002755static int i915_power_domain_info(struct seq_file *m, void *unused)
2756{
David Weinehall36cdd012016-08-22 13:59:31 +03002757 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002758 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2759 int i;
2760
2761 mutex_lock(&power_domains->lock);
2762
2763 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2764 for (i = 0; i < power_domains->power_well_count; i++) {
2765 struct i915_power_well *power_well;
2766 enum intel_display_power_domain power_domain;
2767
2768 power_well = &power_domains->power_wells[i];
2769 seq_printf(m, "%-25s %d\n", power_well->name,
2770 power_well->count);
2771
2772 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2773 power_domain++) {
2774 if (!(BIT(power_domain) & power_well->domains))
2775 continue;
2776
2777 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002778 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002779 power_domains->domain_use_count[power_domain]);
2780 }
2781 }
2782
2783 mutex_unlock(&power_domains->lock);
2784
2785 return 0;
2786}
2787
Damien Lespiaub7cec662015-10-27 14:47:01 +02002788static int i915_dmc_info(struct seq_file *m, void *unused)
2789{
David Weinehall36cdd012016-08-22 13:59:31 +03002790 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002791 struct intel_csr *csr;
2792
David Weinehall36cdd012016-08-22 13:59:31 +03002793 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002794 seq_puts(m, "not supported\n");
2795 return 0;
2796 }
2797
2798 csr = &dev_priv->csr;
2799
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002800 intel_runtime_pm_get(dev_priv);
2801
Damien Lespiaub7cec662015-10-27 14:47:01 +02002802 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2803 seq_printf(m, "path: %s\n", csr->fw_path);
2804
2805 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002806 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002807
2808 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2809 CSR_VERSION_MINOR(csr->version));
2810
David Weinehall36cdd012016-08-22 13:59:31 +03002811 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002812 seq_printf(m, "DC3 -> DC5 count: %d\n",
2813 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2814 seq_printf(m, "DC5 -> DC6 count: %d\n",
2815 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002816 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002817 seq_printf(m, "DC3 -> DC5 count: %d\n",
2818 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002819 }
2820
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002821out:
2822 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2823 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2824 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2825
Damien Lespiau83372062015-10-30 17:53:32 +02002826 intel_runtime_pm_put(dev_priv);
2827
Damien Lespiaub7cec662015-10-27 14:47:01 +02002828 return 0;
2829}
2830
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002831static void intel_seq_print_mode(struct seq_file *m, int tabs,
2832 struct drm_display_mode *mode)
2833{
2834 int i;
2835
2836 for (i = 0; i < tabs; i++)
2837 seq_putc(m, '\t');
2838
2839 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",
2840 mode->base.id, mode->name,
2841 mode->vrefresh, mode->clock,
2842 mode->hdisplay, mode->hsync_start,
2843 mode->hsync_end, mode->htotal,
2844 mode->vdisplay, mode->vsync_start,
2845 mode->vsync_end, mode->vtotal,
2846 mode->type, mode->flags);
2847}
2848
2849static void intel_encoder_info(struct seq_file *m,
2850 struct intel_crtc *intel_crtc,
2851 struct intel_encoder *intel_encoder)
2852{
David Weinehall36cdd012016-08-22 13:59:31 +03002853 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2854 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002855 struct drm_crtc *crtc = &intel_crtc->base;
2856 struct intel_connector *intel_connector;
2857 struct drm_encoder *encoder;
2858
2859 encoder = &intel_encoder->base;
2860 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002861 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002862 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2863 struct drm_connector *connector = &intel_connector->base;
2864 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2865 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002866 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002867 drm_get_connector_status_name(connector->status));
2868 if (connector->status == connector_status_connected) {
2869 struct drm_display_mode *mode = &crtc->mode;
2870 seq_printf(m, ", mode:\n");
2871 intel_seq_print_mode(m, 2, mode);
2872 } else {
2873 seq_putc(m, '\n');
2874 }
2875 }
2876}
2877
2878static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2879{
David Weinehall36cdd012016-08-22 13:59:31 +03002880 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2881 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002882 struct drm_crtc *crtc = &intel_crtc->base;
2883 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002884 struct drm_plane_state *plane_state = crtc->primary->state;
2885 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002886
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002887 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002888 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002889 fb->base.id, plane_state->src_x >> 16,
2890 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002891 else
2892 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002893 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2894 intel_encoder_info(m, intel_crtc, intel_encoder);
2895}
2896
2897static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2898{
2899 struct drm_display_mode *mode = panel->fixed_mode;
2900
2901 seq_printf(m, "\tfixed mode:\n");
2902 intel_seq_print_mode(m, 2, mode);
2903}
2904
2905static void intel_dp_info(struct seq_file *m,
2906 struct intel_connector *intel_connector)
2907{
2908 struct intel_encoder *intel_encoder = intel_connector->encoder;
2909 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2910
2911 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002912 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002913 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002914 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002915
2916 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2917 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002918}
2919
2920static void intel_hdmi_info(struct seq_file *m,
2921 struct intel_connector *intel_connector)
2922{
2923 struct intel_encoder *intel_encoder = intel_connector->encoder;
2924 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2925
Jani Nikula742f4912015-09-03 11:16:09 +03002926 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002927}
2928
2929static void intel_lvds_info(struct seq_file *m,
2930 struct intel_connector *intel_connector)
2931{
2932 intel_panel_info(m, &intel_connector->panel);
2933}
2934
2935static void intel_connector_info(struct seq_file *m,
2936 struct drm_connector *connector)
2937{
2938 struct intel_connector *intel_connector = to_intel_connector(connector);
2939 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002940 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002941
2942 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002943 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002944 drm_get_connector_status_name(connector->status));
2945 if (connector->status == connector_status_connected) {
2946 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2947 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2948 connector->display_info.width_mm,
2949 connector->display_info.height_mm);
2950 seq_printf(m, "\tsubpixel order: %s\n",
2951 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2952 seq_printf(m, "\tCEA rev: %d\n",
2953 connector->display_info.cea_rev);
2954 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002955
2956 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2957 return;
2958
2959 switch (connector->connector_type) {
2960 case DRM_MODE_CONNECTOR_DisplayPort:
2961 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002962 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002963 break;
2964 case DRM_MODE_CONNECTOR_LVDS:
2965 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002966 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002967 break;
2968 case DRM_MODE_CONNECTOR_HDMIA:
2969 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2970 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2971 intel_hdmi_info(m, intel_connector);
2972 break;
2973 default:
2974 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002975 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002976
Jesse Barnesf103fc72014-02-20 12:39:57 -08002977 seq_printf(m, "\tmodes:\n");
2978 list_for_each_entry(mode, &connector->modes, head)
2979 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002980}
2981
David Weinehall36cdd012016-08-22 13:59:31 +03002982static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002983{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002984 u32 state;
2985
David Weinehall36cdd012016-08-22 13:59:31 +03002986 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002987 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002988 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002989 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002990
2991 return state;
2992}
2993
David Weinehall36cdd012016-08-22 13:59:31 +03002994static bool cursor_position(struct drm_i915_private *dev_priv,
2995 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002996{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002997 u32 pos;
2998
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002999 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003000
3001 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3002 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3003 *x = -*x;
3004
3005 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3006 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3007 *y = -*y;
3008
David Weinehall36cdd012016-08-22 13:59:31 +03003009 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003010}
3011
Robert Fekete3abc4e02015-10-27 16:58:32 +01003012static const char *plane_type(enum drm_plane_type type)
3013{
3014 switch (type) {
3015 case DRM_PLANE_TYPE_OVERLAY:
3016 return "OVL";
3017 case DRM_PLANE_TYPE_PRIMARY:
3018 return "PRI";
3019 case DRM_PLANE_TYPE_CURSOR:
3020 return "CUR";
3021 /*
3022 * Deliberately omitting default: to generate compiler warnings
3023 * when a new drm_plane_type gets added.
3024 */
3025 }
3026
3027 return "unknown";
3028}
3029
3030static const char *plane_rotation(unsigned int rotation)
3031{
3032 static char buf[48];
3033 /*
3034 * According to doc only one DRM_ROTATE_ is allowed but this
3035 * will print them all to visualize if the values are misused
3036 */
3037 snprintf(buf, sizeof(buf),
3038 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003039 (rotation & DRM_ROTATE_0) ? "0 " : "",
3040 (rotation & DRM_ROTATE_90) ? "90 " : "",
3041 (rotation & DRM_ROTATE_180) ? "180 " : "",
3042 (rotation & DRM_ROTATE_270) ? "270 " : "",
3043 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3044 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003045 rotation);
3046
3047 return buf;
3048}
3049
3050static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3051{
David Weinehall36cdd012016-08-22 13:59:31 +03003052 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3053 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003054 struct intel_plane *intel_plane;
3055
3056 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3057 struct drm_plane_state *state;
3058 struct drm_plane *plane = &intel_plane->base;
Eric Engestromd3828142016-08-15 16:29:55 +01003059 char *format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003060
3061 if (!plane->state) {
3062 seq_puts(m, "plane->state is NULL!\n");
3063 continue;
3064 }
3065
3066 state = plane->state;
3067
Eric Engestrom90844f02016-08-15 01:02:38 +01003068 if (state->fb) {
3069 format_name = drm_get_format_name(state->fb->pixel_format);
3070 } else {
3071 format_name = kstrdup("N/A", GFP_KERNEL);
3072 }
3073
Robert Fekete3abc4e02015-10-27 16:58:32 +01003074 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",
3075 plane->base.id,
3076 plane_type(intel_plane->base.type),
3077 state->crtc_x, state->crtc_y,
3078 state->crtc_w, state->crtc_h,
3079 (state->src_x >> 16),
3080 ((state->src_x & 0xffff) * 15625) >> 10,
3081 (state->src_y >> 16),
3082 ((state->src_y & 0xffff) * 15625) >> 10,
3083 (state->src_w >> 16),
3084 ((state->src_w & 0xffff) * 15625) >> 10,
3085 (state->src_h >> 16),
3086 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestrom90844f02016-08-15 01:02:38 +01003087 format_name,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003088 plane_rotation(state->rotation));
Eric Engestrom90844f02016-08-15 01:02:38 +01003089
3090 kfree(format_name);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003091 }
3092}
3093
3094static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3095{
3096 struct intel_crtc_state *pipe_config;
3097 int num_scalers = intel_crtc->num_scalers;
3098 int i;
3099
3100 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3101
3102 /* Not all platformas have a scaler */
3103 if (num_scalers) {
3104 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3105 num_scalers,
3106 pipe_config->scaler_state.scaler_users,
3107 pipe_config->scaler_state.scaler_id);
3108
3109 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3110 struct intel_scaler *sc =
3111 &pipe_config->scaler_state.scalers[i];
3112
3113 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3114 i, yesno(sc->in_use), sc->mode);
3115 }
3116 seq_puts(m, "\n");
3117 } else {
3118 seq_puts(m, "\tNo scalers available on this platform\n");
3119 }
3120}
3121
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003122static int i915_display_info(struct seq_file *m, void *unused)
3123{
David Weinehall36cdd012016-08-22 13:59:31 +03003124 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3125 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003126 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003127 struct drm_connector *connector;
3128
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003129 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003130 drm_modeset_lock_all(dev);
3131 seq_printf(m, "CRTC info\n");
3132 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003133 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003134 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003135 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003136 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003137
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003138 pipe_config = to_intel_crtc_state(crtc->base.state);
3139
Robert Fekete3abc4e02015-10-27 16:58:32 +01003140 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003141 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003142 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003143 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3144 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3145
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003146 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003147 intel_crtc_info(m, crtc);
3148
David Weinehall36cdd012016-08-22 13:59:31 +03003149 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003150 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 +03003151 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003152 x, y, crtc->base.cursor->state->crtc_w,
3153 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003154 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003155 intel_scaler_info(m, crtc);
3156 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003157 }
Daniel Vettercace8412014-05-22 17:56:31 +02003158
3159 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3160 yesno(!crtc->cpu_fifo_underrun_disabled),
3161 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003162 }
3163
3164 seq_printf(m, "\n");
3165 seq_printf(m, "Connector info\n");
3166 seq_printf(m, "--------------\n");
3167 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3168 intel_connector_info(m, connector);
3169 }
3170 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003171 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003172
3173 return 0;
3174}
3175
Chris Wilson1b365952016-10-04 21:11:31 +01003176static int i915_engine_info(struct seq_file *m, void *unused)
3177{
3178 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3179 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303180 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003181
Chris Wilson9c870d02016-10-24 13:42:15 +01003182 intel_runtime_pm_get(dev_priv);
3183
Akash Goel3b3f1652016-10-13 22:44:48 +05303184 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003185 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3186 struct drm_i915_gem_request *rq;
3187 struct rb_node *rb;
3188 u64 addr;
3189
3190 seq_printf(m, "%s\n", engine->name);
3191 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3192 intel_engine_get_seqno(engine),
3193 engine->last_submitted_seqno,
3194 engine->hangcheck.seqno,
3195 engine->hangcheck.score);
3196
3197 rcu_read_lock();
3198
3199 seq_printf(m, "\tRequests:\n");
3200
3201 rq = list_first_entry(&engine->request_list,
3202 struct drm_i915_gem_request, link);
3203 if (&rq->link != &engine->request_list)
3204 print_request(m, rq, "\t\tfirst ");
3205
3206 rq = list_last_entry(&engine->request_list,
3207 struct drm_i915_gem_request, link);
3208 if (&rq->link != &engine->request_list)
3209 print_request(m, rq, "\t\tlast ");
3210
3211 rq = i915_gem_find_active_request(engine);
3212 if (rq) {
3213 print_request(m, rq, "\t\tactive ");
3214 seq_printf(m,
3215 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3216 rq->head, rq->postfix, rq->tail,
3217 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3218 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3219 }
3220
3221 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3222 I915_READ(RING_START(engine->mmio_base)),
3223 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3224 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3225 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3226 rq ? rq->ring->head : 0);
3227 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3228 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3229 rq ? rq->ring->tail : 0);
3230 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3231 I915_READ(RING_CTL(engine->mmio_base)),
3232 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3233
3234 rcu_read_unlock();
3235
3236 addr = intel_engine_get_active_head(engine);
3237 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3238 upper_32_bits(addr), lower_32_bits(addr));
3239 addr = intel_engine_get_last_batch_head(engine);
3240 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3241 upper_32_bits(addr), lower_32_bits(addr));
3242
3243 if (i915.enable_execlists) {
3244 u32 ptr, read, write;
3245
3246 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3247 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3248 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3249
3250 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3251 read = GEN8_CSB_READ_PTR(ptr);
3252 write = GEN8_CSB_WRITE_PTR(ptr);
3253 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3254 read, write);
3255 if (read >= GEN8_CSB_ENTRIES)
3256 read = 0;
3257 if (write >= GEN8_CSB_ENTRIES)
3258 write = 0;
3259 if (read > write)
3260 write += GEN8_CSB_ENTRIES;
3261 while (read < write) {
3262 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3263
3264 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3265 idx,
3266 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3267 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3268 }
3269
3270 rcu_read_lock();
3271 rq = READ_ONCE(engine->execlist_port[0].request);
3272 if (rq)
3273 print_request(m, rq, "\t\tELSP[0] ");
3274 else
3275 seq_printf(m, "\t\tELSP[0] idle\n");
3276 rq = READ_ONCE(engine->execlist_port[1].request);
3277 if (rq)
3278 print_request(m, rq, "\t\tELSP[1] ");
3279 else
3280 seq_printf(m, "\t\tELSP[1] idle\n");
3281 rcu_read_unlock();
3282 } else if (INTEL_GEN(dev_priv) > 6) {
3283 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3284 I915_READ(RING_PP_DIR_BASE(engine)));
3285 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3286 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3287 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3288 I915_READ(RING_PP_DIR_DCLV(engine)));
3289 }
3290
3291 spin_lock(&b->lock);
3292 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3293 struct intel_wait *w = container_of(rb, typeof(*w), node);
3294
3295 seq_printf(m, "\t%s [%d] waiting for %x\n",
3296 w->tsk->comm, w->tsk->pid, w->seqno);
3297 }
3298 spin_unlock(&b->lock);
3299
3300 seq_puts(m, "\n");
3301 }
3302
Chris Wilson9c870d02016-10-24 13:42:15 +01003303 intel_runtime_pm_put(dev_priv);
3304
Chris Wilson1b365952016-10-04 21:11:31 +01003305 return 0;
3306}
3307
Ben Widawskye04934c2014-06-30 09:53:42 -07003308static int i915_semaphore_status(struct seq_file *m, void *unused)
3309{
David Weinehall36cdd012016-08-22 13:59:31 +03003310 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3311 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003312 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003313 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003314 enum intel_engine_id id;
3315 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003316
Chris Wilson39df9192016-07-20 13:31:57 +01003317 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003318 seq_puts(m, "Semaphores are disabled\n");
3319 return 0;
3320 }
3321
3322 ret = mutex_lock_interruptible(&dev->struct_mutex);
3323 if (ret)
3324 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003325 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003326
David Weinehall36cdd012016-08-22 13:59:31 +03003327 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003328 struct page *page;
3329 uint64_t *seqno;
3330
Chris Wilson51d545d2016-08-15 10:49:02 +01003331 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003332
3333 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303334 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003335 uint64_t offset;
3336
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003337 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003338
3339 seq_puts(m, " Last signal:");
3340 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003341 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003342 seq_printf(m, "0x%08llx (0x%02llx) ",
3343 seqno[offset], offset * 8);
3344 }
3345 seq_putc(m, '\n');
3346
3347 seq_puts(m, " Last wait: ");
3348 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003349 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003350 seq_printf(m, "0x%08llx (0x%02llx) ",
3351 seqno[offset], offset * 8);
3352 }
3353 seq_putc(m, '\n');
3354
3355 }
3356 kunmap_atomic(seqno);
3357 } else {
3358 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303359 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003360 for (j = 0; j < num_rings; j++)
3361 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003362 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003363 seq_putc(m, '\n');
3364 }
3365
3366 seq_puts(m, "\nSync seqno:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05303367 for_each_engine(engine, dev_priv, id) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003368 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003369 seq_printf(m, " 0x%08x ",
3370 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003371 seq_putc(m, '\n');
3372 }
3373 seq_putc(m, '\n');
3374
Paulo Zanoni03872062014-07-09 14:31:57 -03003375 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003376 mutex_unlock(&dev->struct_mutex);
3377 return 0;
3378}
3379
Daniel Vetter728e29d2014-06-25 22:01:53 +03003380static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3381{
David Weinehall36cdd012016-08-22 13:59:31 +03003382 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3383 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003384 int i;
3385
3386 drm_modeset_lock_all(dev);
3387 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3388 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3389
3390 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003391 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3392 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003393 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003394 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3395 seq_printf(m, " dpll_md: 0x%08x\n",
3396 pll->config.hw_state.dpll_md);
3397 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3398 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3399 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003400 }
3401 drm_modeset_unlock_all(dev);
3402
3403 return 0;
3404}
3405
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003406static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003407{
3408 int i;
3409 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003410 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003411 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3412 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003413 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003414 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003415
Arun Siluvery888b5992014-08-26 14:44:51 +01003416 ret = mutex_lock_interruptible(&dev->struct_mutex);
3417 if (ret)
3418 return ret;
3419
3420 intel_runtime_pm_get(dev_priv);
3421
Arun Siluvery33136b02016-01-21 21:43:47 +00003422 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303423 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003424 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003425 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003426 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003427 i915_reg_t addr;
3428 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003429 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003430
Arun Siluvery33136b02016-01-21 21:43:47 +00003431 addr = workarounds->reg[i].addr;
3432 mask = workarounds->reg[i].mask;
3433 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003434 read = I915_READ(addr);
3435 ok = (value & mask) == (read & mask);
3436 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 +02003437 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003438 }
3439
3440 intel_runtime_pm_put(dev_priv);
3441 mutex_unlock(&dev->struct_mutex);
3442
3443 return 0;
3444}
3445
Damien Lespiauc5511e42014-11-04 17:06:51 +00003446static int i915_ddb_info(struct seq_file *m, void *unused)
3447{
David Weinehall36cdd012016-08-22 13:59:31 +03003448 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3449 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003450 struct skl_ddb_allocation *ddb;
3451 struct skl_ddb_entry *entry;
3452 enum pipe pipe;
3453 int plane;
3454
David Weinehall36cdd012016-08-22 13:59:31 +03003455 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003456 return 0;
3457
Damien Lespiauc5511e42014-11-04 17:06:51 +00003458 drm_modeset_lock_all(dev);
3459
3460 ddb = &dev_priv->wm.skl_hw.ddb;
3461
3462 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3463
3464 for_each_pipe(dev_priv, pipe) {
3465 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3466
Matt Roper8b364b42016-10-26 15:51:28 -07003467 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003468 entry = &ddb->plane[pipe][plane];
3469 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3470 entry->start, entry->end,
3471 skl_ddb_entry_size(entry));
3472 }
3473
Matt Roper4969d332015-09-24 15:53:10 -07003474 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003475 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3476 entry->end, skl_ddb_entry_size(entry));
3477 }
3478
3479 drm_modeset_unlock_all(dev);
3480
3481 return 0;
3482}
3483
Vandana Kannana54746e2015-03-03 20:53:10 +05303484static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003485 struct drm_device *dev,
3486 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303487{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003488 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303489 struct i915_drrs *drrs = &dev_priv->drrs;
3490 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003491 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303492
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003493 drm_for_each_connector(connector, dev) {
3494 if (connector->state->crtc != &intel_crtc->base)
3495 continue;
3496
3497 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303498 }
3499
3500 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3501 seq_puts(m, "\tVBT: DRRS_type: Static");
3502 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3503 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3504 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3505 seq_puts(m, "\tVBT: DRRS_type: None");
3506 else
3507 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3508
3509 seq_puts(m, "\n\n");
3510
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003511 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303512 struct intel_panel *panel;
3513
3514 mutex_lock(&drrs->mutex);
3515 /* DRRS Supported */
3516 seq_puts(m, "\tDRRS Supported: Yes\n");
3517
3518 /* disable_drrs() will make drrs->dp NULL */
3519 if (!drrs->dp) {
3520 seq_puts(m, "Idleness DRRS: Disabled");
3521 mutex_unlock(&drrs->mutex);
3522 return;
3523 }
3524
3525 panel = &drrs->dp->attached_connector->panel;
3526 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3527 drrs->busy_frontbuffer_bits);
3528
3529 seq_puts(m, "\n\t\t");
3530 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3531 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3532 vrefresh = panel->fixed_mode->vrefresh;
3533 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3534 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3535 vrefresh = panel->downclock_mode->vrefresh;
3536 } else {
3537 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3538 drrs->refresh_rate_type);
3539 mutex_unlock(&drrs->mutex);
3540 return;
3541 }
3542 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3543
3544 seq_puts(m, "\n\t\t");
3545 mutex_unlock(&drrs->mutex);
3546 } else {
3547 /* DRRS not supported. Print the VBT parameter*/
3548 seq_puts(m, "\tDRRS Supported : No");
3549 }
3550 seq_puts(m, "\n");
3551}
3552
3553static int i915_drrs_status(struct seq_file *m, void *unused)
3554{
David Weinehall36cdd012016-08-22 13:59:31 +03003555 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3556 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303557 struct intel_crtc *intel_crtc;
3558 int active_crtc_cnt = 0;
3559
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003560 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303561 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003562 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303563 active_crtc_cnt++;
3564 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3565
3566 drrs_status_per_crtc(m, dev, intel_crtc);
3567 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303568 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003569 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303570
3571 if (!active_crtc_cnt)
3572 seq_puts(m, "No active crtc found\n");
3573
3574 return 0;
3575}
3576
Damien Lespiau07144422013-10-15 18:55:40 +01003577struct pipe_crc_info {
3578 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003579 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003580 enum pipe pipe;
3581};
3582
Dave Airlie11bed952014-05-12 15:22:27 +10003583static int i915_dp_mst_info(struct seq_file *m, void *unused)
3584{
David Weinehall36cdd012016-08-22 13:59:31 +03003585 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3586 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003587 struct intel_encoder *intel_encoder;
3588 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003589 struct drm_connector *connector;
3590
Dave Airlie11bed952014-05-12 15:22:27 +10003591 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003592 drm_for_each_connector(connector, dev) {
3593 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003594 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003595
3596 intel_encoder = intel_attached_encoder(connector);
3597 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3598 continue;
3599
3600 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003601 if (!intel_dig_port->dp.can_mst)
3602 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003603
Jim Bride40ae80c2016-04-14 10:18:37 -07003604 seq_printf(m, "MST Source Port %c\n",
3605 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003606 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3607 }
3608 drm_modeset_unlock_all(dev);
3609 return 0;
3610}
3611
Damien Lespiau07144422013-10-15 18:55:40 +01003612static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003613{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003614 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003615 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003616 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3617
David Weinehall36cdd012016-08-22 13:59:31 +03003618 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003619 return -ENODEV;
3620
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003621 spin_lock_irq(&pipe_crc->lock);
3622
3623 if (pipe_crc->opened) {
3624 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003625 return -EBUSY; /* already open */
3626 }
3627
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003628 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003629 filep->private_data = inode->i_private;
3630
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003631 spin_unlock_irq(&pipe_crc->lock);
3632
Damien Lespiau07144422013-10-15 18:55:40 +01003633 return 0;
3634}
3635
3636static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3637{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003638 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003639 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003640 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3641
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003642 spin_lock_irq(&pipe_crc->lock);
3643 pipe_crc->opened = false;
3644 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003645
Damien Lespiau07144422013-10-15 18:55:40 +01003646 return 0;
3647}
3648
3649/* (6 fields, 8 chars each, space separated (5) + '\n') */
3650#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3651/* account for \'0' */
3652#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3653
3654static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3655{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003656 assert_spin_locked(&pipe_crc->lock);
3657 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3658 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003659}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003660
Damien Lespiau07144422013-10-15 18:55:40 +01003661static ssize_t
3662i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3663 loff_t *pos)
3664{
3665 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003666 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003667 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3668 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003669 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003670 ssize_t bytes_read;
3671
3672 /*
3673 * Don't allow user space to provide buffers not big enough to hold
3674 * a line of data.
3675 */
3676 if (count < PIPE_CRC_LINE_LEN)
3677 return -EINVAL;
3678
3679 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3680 return 0;
3681
3682 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003683 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003684 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003685 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003686
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003687 if (filep->f_flags & O_NONBLOCK) {
3688 spin_unlock_irq(&pipe_crc->lock);
3689 return -EAGAIN;
3690 }
3691
3692 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3693 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3694 if (ret) {
3695 spin_unlock_irq(&pipe_crc->lock);
3696 return ret;
3697 }
Damien Lespiau07144422013-10-15 18:55:40 +01003698 }
3699
3700 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003701 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003702
Damien Lespiau07144422013-10-15 18:55:40 +01003703 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003704 while (n_entries > 0) {
3705 struct intel_pipe_crc_entry *entry =
3706 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003707
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003708 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3709 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3710 break;
3711
3712 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3713 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3714
Damien Lespiau07144422013-10-15 18:55:40 +01003715 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3716 "%8u %8x %8x %8x %8x %8x\n",
3717 entry->frame, entry->crc[0],
3718 entry->crc[1], entry->crc[2],
3719 entry->crc[3], entry->crc[4]);
3720
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003721 spin_unlock_irq(&pipe_crc->lock);
3722
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003723 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003724 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003725
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003726 user_buf += PIPE_CRC_LINE_LEN;
3727 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003728
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003729 spin_lock_irq(&pipe_crc->lock);
3730 }
3731
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003732 spin_unlock_irq(&pipe_crc->lock);
3733
Damien Lespiau07144422013-10-15 18:55:40 +01003734 return bytes_read;
3735}
3736
3737static const struct file_operations i915_pipe_crc_fops = {
3738 .owner = THIS_MODULE,
3739 .open = i915_pipe_crc_open,
3740 .read = i915_pipe_crc_read,
3741 .release = i915_pipe_crc_release,
3742};
3743
3744static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3745 {
3746 .name = "i915_pipe_A_crc",
3747 .pipe = PIPE_A,
3748 },
3749 {
3750 .name = "i915_pipe_B_crc",
3751 .pipe = PIPE_B,
3752 },
3753 {
3754 .name = "i915_pipe_C_crc",
3755 .pipe = PIPE_C,
3756 },
3757};
3758
3759static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3760 enum pipe pipe)
3761{
David Weinehall36cdd012016-08-22 13:59:31 +03003762 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003763 struct dentry *ent;
3764 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3765
David Weinehall36cdd012016-08-22 13:59:31 +03003766 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003767 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3768 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003769 if (!ent)
3770 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003771
3772 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003773}
3774
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003775static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003776 "none",
3777 "plane1",
3778 "plane2",
3779 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003780 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003781 "TV",
3782 "DP-B",
3783 "DP-C",
3784 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003785 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003786};
3787
3788static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3789{
3790 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3791 return pipe_crc_sources[source];
3792}
3793
Damien Lespiaubd9db022013-10-15 18:55:36 +01003794static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003795{
David Weinehall36cdd012016-08-22 13:59:31 +03003796 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003797 int i;
3798
3799 for (i = 0; i < I915_MAX_PIPES; i++)
3800 seq_printf(m, "%c %s\n", pipe_name(i),
3801 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3802
3803 return 0;
3804}
3805
Damien Lespiaubd9db022013-10-15 18:55:36 +01003806static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003807{
David Weinehall36cdd012016-08-22 13:59:31 +03003808 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003809}
3810
Daniel Vetter46a19182013-11-01 10:50:20 +01003811static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003812 uint32_t *val)
3813{
Daniel Vetter46a19182013-11-01 10:50:20 +01003814 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3815 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3816
3817 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003818 case INTEL_PIPE_CRC_SOURCE_PIPE:
3819 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3820 break;
3821 case INTEL_PIPE_CRC_SOURCE_NONE:
3822 *val = 0;
3823 break;
3824 default:
3825 return -EINVAL;
3826 }
3827
3828 return 0;
3829}
3830
David Weinehall36cdd012016-08-22 13:59:31 +03003831static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3832 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003833 enum intel_pipe_crc_source *source)
3834{
David Weinehall36cdd012016-08-22 13:59:31 +03003835 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003836 struct intel_encoder *encoder;
3837 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003838 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003839 int ret = 0;
3840
3841 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3842
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003843 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003844 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003845 if (!encoder->base.crtc)
3846 continue;
3847
3848 crtc = to_intel_crtc(encoder->base.crtc);
3849
3850 if (crtc->pipe != pipe)
3851 continue;
3852
3853 switch (encoder->type) {
3854 case INTEL_OUTPUT_TVOUT:
3855 *source = INTEL_PIPE_CRC_SOURCE_TV;
3856 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003857 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003858 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003859 dig_port = enc_to_dig_port(&encoder->base);
3860 switch (dig_port->port) {
3861 case PORT_B:
3862 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3863 break;
3864 case PORT_C:
3865 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3866 break;
3867 case PORT_D:
3868 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3869 break;
3870 default:
3871 WARN(1, "nonexisting DP port %c\n",
3872 port_name(dig_port->port));
3873 break;
3874 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003875 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003876 default:
3877 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003878 }
3879 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003880 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003881
3882 return ret;
3883}
3884
David Weinehall36cdd012016-08-22 13:59:31 +03003885static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003886 enum pipe pipe,
3887 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003888 uint32_t *val)
3889{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003890 bool need_stable_symbols = false;
3891
Daniel Vetter46a19182013-11-01 10:50:20 +01003892 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003893 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003894 if (ret)
3895 return ret;
3896 }
3897
3898 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003899 case INTEL_PIPE_CRC_SOURCE_PIPE:
3900 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3901 break;
3902 case INTEL_PIPE_CRC_SOURCE_DP_B:
3903 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003904 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003905 break;
3906 case INTEL_PIPE_CRC_SOURCE_DP_C:
3907 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003908 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003909 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003910 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003911 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003912 return -EINVAL;
3913 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3914 need_stable_symbols = true;
3915 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003916 case INTEL_PIPE_CRC_SOURCE_NONE:
3917 *val = 0;
3918 break;
3919 default:
3920 return -EINVAL;
3921 }
3922
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003923 /*
3924 * When the pipe CRC tap point is after the transcoders we need
3925 * to tweak symbol-level features to produce a deterministic series of
3926 * symbols for a given frame. We need to reset those features only once
3927 * a frame (instead of every nth symbol):
3928 * - DC-balance: used to ensure a better clock recovery from the data
3929 * link (SDVO)
3930 * - DisplayPort scrambling: used for EMI reduction
3931 */
3932 if (need_stable_symbols) {
3933 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3934
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003935 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003936 switch (pipe) {
3937 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003938 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003939 break;
3940 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003941 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003942 break;
3943 case PIPE_C:
3944 tmp |= PIPE_C_SCRAMBLE_RESET;
3945 break;
3946 default:
3947 return -EINVAL;
3948 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003949 I915_WRITE(PORT_DFT2_G4X, tmp);
3950 }
3951
Daniel Vetter7ac01292013-10-18 16:37:06 +02003952 return 0;
3953}
3954
David Weinehall36cdd012016-08-22 13:59:31 +03003955static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003956 enum pipe pipe,
3957 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003958 uint32_t *val)
3959{
Daniel Vetter84093602013-11-01 10:50:21 +01003960 bool need_stable_symbols = false;
3961
Daniel Vetter46a19182013-11-01 10:50:20 +01003962 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003963 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003964 if (ret)
3965 return ret;
3966 }
3967
3968 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003969 case INTEL_PIPE_CRC_SOURCE_PIPE:
3970 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3971 break;
3972 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003973 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003974 return -EINVAL;
3975 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3976 break;
3977 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003978 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003979 return -EINVAL;
3980 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003981 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003982 break;
3983 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003984 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003985 return -EINVAL;
3986 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003987 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003988 break;
3989 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003990 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003991 return -EINVAL;
3992 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003993 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003994 break;
3995 case INTEL_PIPE_CRC_SOURCE_NONE:
3996 *val = 0;
3997 break;
3998 default:
3999 return -EINVAL;
4000 }
4001
Daniel Vetter84093602013-11-01 10:50:21 +01004002 /*
4003 * When the pipe CRC tap point is after the transcoders we need
4004 * to tweak symbol-level features to produce a deterministic series of
4005 * symbols for a given frame. We need to reset those features only once
4006 * a frame (instead of every nth symbol):
4007 * - DC-balance: used to ensure a better clock recovery from the data
4008 * link (SDVO)
4009 * - DisplayPort scrambling: used for EMI reduction
4010 */
4011 if (need_stable_symbols) {
4012 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4013
David Weinehall36cdd012016-08-22 13:59:31 +03004014 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01004015
4016 I915_WRITE(PORT_DFT_I9XX,
4017 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
4018
4019 if (pipe == PIPE_A)
4020 tmp |= PIPE_A_SCRAMBLE_RESET;
4021 else
4022 tmp |= PIPE_B_SCRAMBLE_RESET;
4023
4024 I915_WRITE(PORT_DFT2_G4X, tmp);
4025 }
4026
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004027 return 0;
4028}
4029
David Weinehall36cdd012016-08-22 13:59:31 +03004030static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004031 enum pipe pipe)
4032{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004033 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4034
Ville Syrjäläeb736672014-12-09 21:28:28 +02004035 switch (pipe) {
4036 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004037 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004038 break;
4039 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004040 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02004041 break;
4042 case PIPE_C:
4043 tmp &= ~PIPE_C_SCRAMBLE_RESET;
4044 break;
4045 default:
4046 return;
4047 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004048 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
4049 tmp &= ~DC_BALANCE_RESET_VLV;
4050 I915_WRITE(PORT_DFT2_G4X, tmp);
4051
4052}
4053
David Weinehall36cdd012016-08-22 13:59:31 +03004054static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01004055 enum pipe pipe)
4056{
Daniel Vetter84093602013-11-01 10:50:21 +01004057 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
4058
4059 if (pipe == PIPE_A)
4060 tmp &= ~PIPE_A_SCRAMBLE_RESET;
4061 else
4062 tmp &= ~PIPE_B_SCRAMBLE_RESET;
4063 I915_WRITE(PORT_DFT2_G4X, tmp);
4064
4065 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
4066 I915_WRITE(PORT_DFT_I9XX,
4067 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
4068 }
4069}
4070
Daniel Vetter46a19182013-11-01 10:50:20 +01004071static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004072 uint32_t *val)
4073{
Daniel Vetter46a19182013-11-01 10:50:20 +01004074 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4075 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4076
4077 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004078 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4079 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4080 break;
4081 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4082 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4083 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004084 case INTEL_PIPE_CRC_SOURCE_PIPE:
4085 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4086 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004087 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004088 *val = 0;
4089 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004090 default:
4091 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004092 }
4093
4094 return 0;
4095}
4096
David Weinehall36cdd012016-08-22 13:59:31 +03004097static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4098 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004099{
David Weinehall36cdd012016-08-22 13:59:31 +03004100 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004101 struct intel_crtc *crtc =
4102 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004103 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004104 struct drm_atomic_state *state;
4105 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004106
4107 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004108 state = drm_atomic_state_alloc(dev);
4109 if (!state) {
4110 ret = -ENOMEM;
4111 goto out;
4112 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004113
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004114 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4115 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4116 if (IS_ERR(pipe_config)) {
4117 ret = PTR_ERR(pipe_config);
4118 goto out;
4119 }
4120
4121 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004122 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004123 pipe_config->pch_pfit.enabled != enable)
4124 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004125
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004126 ret = drm_atomic_commit(state);
4127out:
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004128 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
Chris Wilson08536952016-10-14 13:18:18 +01004129 drm_modeset_unlock_all(dev);
4130 drm_atomic_state_put(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004131}
4132
David Weinehall36cdd012016-08-22 13:59:31 +03004133static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004134 enum pipe pipe,
4135 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004136 uint32_t *val)
4137{
Daniel Vetter46a19182013-11-01 10:50:20 +01004138 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4139 *source = INTEL_PIPE_CRC_SOURCE_PF;
4140
4141 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004142 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4143 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4144 break;
4145 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4146 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4147 break;
4148 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004149 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4150 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004151
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004152 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4153 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004154 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004155 *val = 0;
4156 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004157 default:
4158 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004159 }
4160
4161 return 0;
4162}
4163
David Weinehall36cdd012016-08-22 13:59:31 +03004164static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4165 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004166 enum intel_pipe_crc_source source)
4167{
David Weinehall36cdd012016-08-22 13:59:31 +03004168 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004169 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03004170 struct intel_crtc *crtc =
4171 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02004172 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004173 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004174 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004175
Damien Lespiaucc3da172013-10-15 18:55:31 +01004176 if (pipe_crc->source == source)
4177 return 0;
4178
Damien Lespiauae676fc2013-10-15 18:55:32 +01004179 /* forbid changing the source without going back to 'none' */
4180 if (pipe_crc->source && source)
4181 return -EINVAL;
4182
Imre Deake1296492016-02-12 18:55:17 +02004183 power_domain = POWER_DOMAIN_PIPE(pipe);
4184 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004185 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4186 return -EIO;
4187 }
4188
David Weinehall36cdd012016-08-22 13:59:31 +03004189 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004190 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004191 else if (INTEL_GEN(dev_priv) < 5)
4192 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4193 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4194 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4195 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004196 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004197 else
David Weinehall36cdd012016-08-22 13:59:31 +03004198 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004199
4200 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004201 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004202
Damien Lespiau4b584362013-10-15 18:55:33 +01004203 /* none -> real source transition */
4204 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004205 struct intel_pipe_crc_entry *entries;
4206
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004207 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4208 pipe_name(pipe), pipe_crc_source_name(source));
4209
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004210 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4211 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004212 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004213 if (!entries) {
4214 ret = -ENOMEM;
4215 goto out;
4216 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004217
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004218 /*
4219 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4220 * enabled and disabled dynamically based on package C states,
4221 * user space can't make reliable use of the CRCs, so let's just
4222 * completely disable it.
4223 */
4224 hsw_disable_ips(crtc);
4225
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004226 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004227 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004228 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004229 pipe_crc->head = 0;
4230 pipe_crc->tail = 0;
4231 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004232 }
4233
Damien Lespiaucc3da172013-10-15 18:55:31 +01004234 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004235
Daniel Vetter926321d2013-10-16 13:30:34 +02004236 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4237 POSTING_READ(PIPE_CRC_CTL(pipe));
4238
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004239 /* real source -> none transition */
4240 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004241 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004242 struct intel_crtc *crtc =
4243 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004244
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004245 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4246 pipe_name(pipe));
4247
Daniel Vettera33d7102014-06-06 08:22:08 +02004248 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004249 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004250 intel_wait_for_vblank(dev, pipe);
4251 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004252
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004253 spin_lock_irq(&pipe_crc->lock);
4254 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004255 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004256 pipe_crc->head = 0;
4257 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004258 spin_unlock_irq(&pipe_crc->lock);
4259
4260 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004261
David Weinehall36cdd012016-08-22 13:59:31 +03004262 if (IS_G4X(dev_priv))
4263 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4264 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4265 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4266 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4267 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004268
4269 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004270 }
4271
Imre Deake1296492016-02-12 18:55:17 +02004272 ret = 0;
4273
4274out:
4275 intel_display_power_put(dev_priv, power_domain);
4276
4277 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004278}
4279
4280/*
4281 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004282 * command: wsp* object wsp+ name wsp+ source wsp*
4283 * object: 'pipe'
4284 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004285 * source: (none | plane1 | plane2 | pf)
4286 * wsp: (#0x20 | #0x9 | #0xA)+
4287 *
4288 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004289 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4290 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004291 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004292static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004293{
4294 int n_words = 0;
4295
4296 while (*buf) {
4297 char *end;
4298
4299 /* skip leading white space */
4300 buf = skip_spaces(buf);
4301 if (!*buf)
4302 break; /* end of buffer */
4303
4304 /* find end of word */
4305 for (end = buf; *end && !isspace(*end); end++)
4306 ;
4307
4308 if (n_words == max_words) {
4309 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4310 max_words);
4311 return -EINVAL; /* ran out of words[] before bytes */
4312 }
4313
4314 if (*end)
4315 *end++ = '\0';
4316 words[n_words++] = buf;
4317 buf = end;
4318 }
4319
4320 return n_words;
4321}
4322
Damien Lespiaub94dec82013-10-15 18:55:35 +01004323enum intel_pipe_crc_object {
4324 PIPE_CRC_OBJECT_PIPE,
4325};
4326
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004327static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004328 "pipe",
4329};
4330
4331static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004332display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004333{
4334 int i;
4335
4336 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4337 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004338 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004339 return 0;
4340 }
4341
4342 return -EINVAL;
4343}
4344
Damien Lespiaubd9db022013-10-15 18:55:36 +01004345static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004346{
4347 const char name = buf[0];
4348
4349 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4350 return -EINVAL;
4351
4352 *pipe = name - 'A';
4353
4354 return 0;
4355}
4356
4357static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004358display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004359{
4360 int i;
4361
4362 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4363 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004364 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004365 return 0;
4366 }
4367
4368 return -EINVAL;
4369}
4370
David Weinehall36cdd012016-08-22 13:59:31 +03004371static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4372 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004373{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004374#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004375 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004376 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004377 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004378 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004379 enum intel_pipe_crc_source source;
4380
Damien Lespiaubd9db022013-10-15 18:55:36 +01004381 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004382 if (n_words != N_WORDS) {
4383 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4384 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004385 return -EINVAL;
4386 }
4387
Damien Lespiaubd9db022013-10-15 18:55:36 +01004388 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004389 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004390 return -EINVAL;
4391 }
4392
Damien Lespiaubd9db022013-10-15 18:55:36 +01004393 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004394 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4395 return -EINVAL;
4396 }
4397
Damien Lespiaubd9db022013-10-15 18:55:36 +01004398 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004399 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004400 return -EINVAL;
4401 }
4402
David Weinehall36cdd012016-08-22 13:59:31 +03004403 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004404}
4405
Damien Lespiaubd9db022013-10-15 18:55:36 +01004406static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4407 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004408{
4409 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004410 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004411 char *tmpbuf;
4412 int ret;
4413
4414 if (len == 0)
4415 return 0;
4416
4417 if (len > PAGE_SIZE - 1) {
4418 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4419 PAGE_SIZE);
4420 return -E2BIG;
4421 }
4422
4423 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4424 if (!tmpbuf)
4425 return -ENOMEM;
4426
4427 if (copy_from_user(tmpbuf, ubuf, len)) {
4428 ret = -EFAULT;
4429 goto out;
4430 }
4431 tmpbuf[len] = '\0';
4432
David Weinehall36cdd012016-08-22 13:59:31 +03004433 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004434
4435out:
4436 kfree(tmpbuf);
4437 if (ret < 0)
4438 return ret;
4439
4440 *offp += len;
4441 return len;
4442}
4443
Damien Lespiaubd9db022013-10-15 18:55:36 +01004444static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004445 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004446 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004447 .read = seq_read,
4448 .llseek = seq_lseek,
4449 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004450 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004451};
4452
Todd Previteeb3394fa2015-04-18 00:04:19 -07004453static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004454 const char __user *ubuf,
4455 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004456{
4457 char *input_buffer;
4458 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004459 struct drm_device *dev;
4460 struct drm_connector *connector;
4461 struct list_head *connector_list;
4462 struct intel_dp *intel_dp;
4463 int val = 0;
4464
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304465 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004466
Todd Previteeb3394fa2015-04-18 00:04:19 -07004467 connector_list = &dev->mode_config.connector_list;
4468
4469 if (len == 0)
4470 return 0;
4471
4472 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4473 if (!input_buffer)
4474 return -ENOMEM;
4475
4476 if (copy_from_user(input_buffer, ubuf, len)) {
4477 status = -EFAULT;
4478 goto out;
4479 }
4480
4481 input_buffer[len] = '\0';
4482 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4483
4484 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004485 if (connector->connector_type !=
4486 DRM_MODE_CONNECTOR_DisplayPort)
4487 continue;
4488
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304489 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004490 connector->encoder != NULL) {
4491 intel_dp = enc_to_intel_dp(connector->encoder);
4492 status = kstrtoint(input_buffer, 10, &val);
4493 if (status < 0)
4494 goto out;
4495 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4496 /* To prevent erroneous activation of the compliance
4497 * testing code, only accept an actual value of 1 here
4498 */
4499 if (val == 1)
4500 intel_dp->compliance_test_active = 1;
4501 else
4502 intel_dp->compliance_test_active = 0;
4503 }
4504 }
4505out:
4506 kfree(input_buffer);
4507 if (status < 0)
4508 return status;
4509
4510 *offp += len;
4511 return len;
4512}
4513
4514static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4515{
4516 struct drm_device *dev = m->private;
4517 struct drm_connector *connector;
4518 struct list_head *connector_list = &dev->mode_config.connector_list;
4519 struct intel_dp *intel_dp;
4520
Todd Previteeb3394fa2015-04-18 00:04:19 -07004521 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004522 if (connector->connector_type !=
4523 DRM_MODE_CONNECTOR_DisplayPort)
4524 continue;
4525
4526 if (connector->status == connector_status_connected &&
4527 connector->encoder != NULL) {
4528 intel_dp = enc_to_intel_dp(connector->encoder);
4529 if (intel_dp->compliance_test_active)
4530 seq_puts(m, "1");
4531 else
4532 seq_puts(m, "0");
4533 } else
4534 seq_puts(m, "0");
4535 }
4536
4537 return 0;
4538}
4539
4540static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004541 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004542{
David Weinehall36cdd012016-08-22 13:59:31 +03004543 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004544
David Weinehall36cdd012016-08-22 13:59:31 +03004545 return single_open(file, i915_displayport_test_active_show,
4546 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004547}
4548
4549static const struct file_operations i915_displayport_test_active_fops = {
4550 .owner = THIS_MODULE,
4551 .open = i915_displayport_test_active_open,
4552 .read = seq_read,
4553 .llseek = seq_lseek,
4554 .release = single_release,
4555 .write = i915_displayport_test_active_write
4556};
4557
4558static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4559{
4560 struct drm_device *dev = m->private;
4561 struct drm_connector *connector;
4562 struct list_head *connector_list = &dev->mode_config.connector_list;
4563 struct intel_dp *intel_dp;
4564
Todd Previteeb3394fa2015-04-18 00:04:19 -07004565 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004566 if (connector->connector_type !=
4567 DRM_MODE_CONNECTOR_DisplayPort)
4568 continue;
4569
4570 if (connector->status == connector_status_connected &&
4571 connector->encoder != NULL) {
4572 intel_dp = enc_to_intel_dp(connector->encoder);
4573 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4574 } else
4575 seq_puts(m, "0");
4576 }
4577
4578 return 0;
4579}
4580static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004581 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004582{
David Weinehall36cdd012016-08-22 13:59:31 +03004583 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004584
David Weinehall36cdd012016-08-22 13:59:31 +03004585 return single_open(file, i915_displayport_test_data_show,
4586 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004587}
4588
4589static const struct file_operations i915_displayport_test_data_fops = {
4590 .owner = THIS_MODULE,
4591 .open = i915_displayport_test_data_open,
4592 .read = seq_read,
4593 .llseek = seq_lseek,
4594 .release = single_release
4595};
4596
4597static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4598{
4599 struct drm_device *dev = m->private;
4600 struct drm_connector *connector;
4601 struct list_head *connector_list = &dev->mode_config.connector_list;
4602 struct intel_dp *intel_dp;
4603
Todd Previteeb3394fa2015-04-18 00:04:19 -07004604 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004605 if (connector->connector_type !=
4606 DRM_MODE_CONNECTOR_DisplayPort)
4607 continue;
4608
4609 if (connector->status == connector_status_connected &&
4610 connector->encoder != NULL) {
4611 intel_dp = enc_to_intel_dp(connector->encoder);
4612 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4613 } else
4614 seq_puts(m, "0");
4615 }
4616
4617 return 0;
4618}
4619
4620static int i915_displayport_test_type_open(struct inode *inode,
4621 struct file *file)
4622{
David Weinehall36cdd012016-08-22 13:59:31 +03004623 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004624
David Weinehall36cdd012016-08-22 13:59:31 +03004625 return single_open(file, i915_displayport_test_type_show,
4626 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004627}
4628
4629static const struct file_operations i915_displayport_test_type_fops = {
4630 .owner = THIS_MODULE,
4631 .open = i915_displayport_test_type_open,
4632 .read = seq_read,
4633 .llseek = seq_lseek,
4634 .release = single_release
4635};
4636
Damien Lespiau97e94b22014-11-04 17:06:50 +00004637static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004638{
David Weinehall36cdd012016-08-22 13:59:31 +03004639 struct drm_i915_private *dev_priv = m->private;
4640 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004641 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004642 int num_levels;
4643
David Weinehall36cdd012016-08-22 13:59:31 +03004644 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004645 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004646 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004647 num_levels = 1;
4648 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004649 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004650
4651 drm_modeset_lock_all(dev);
4652
4653 for (level = 0; level < num_levels; level++) {
4654 unsigned int latency = wm[level];
4655
Damien Lespiau97e94b22014-11-04 17:06:50 +00004656 /*
4657 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004658 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004659 */
David Weinehall36cdd012016-08-22 13:59:31 +03004660 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4661 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004662 latency *= 10;
4663 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004664 latency *= 5;
4665
4666 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004667 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004668 }
4669
4670 drm_modeset_unlock_all(dev);
4671}
4672
4673static int pri_wm_latency_show(struct seq_file *m, void *data)
4674{
David Weinehall36cdd012016-08-22 13:59:31 +03004675 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004676 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004677
David Weinehall36cdd012016-08-22 13:59:31 +03004678 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004679 latencies = dev_priv->wm.skl_latency;
4680 else
David Weinehall36cdd012016-08-22 13:59:31 +03004681 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004682
4683 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004684
4685 return 0;
4686}
4687
4688static int spr_wm_latency_show(struct seq_file *m, void *data)
4689{
David Weinehall36cdd012016-08-22 13:59:31 +03004690 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004691 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004692
David Weinehall36cdd012016-08-22 13:59:31 +03004693 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004694 latencies = dev_priv->wm.skl_latency;
4695 else
David Weinehall36cdd012016-08-22 13:59:31 +03004696 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004697
4698 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004699
4700 return 0;
4701}
4702
4703static int cur_wm_latency_show(struct seq_file *m, void *data)
4704{
David Weinehall36cdd012016-08-22 13:59:31 +03004705 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004706 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004707
David Weinehall36cdd012016-08-22 13:59:31 +03004708 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004709 latencies = dev_priv->wm.skl_latency;
4710 else
David Weinehall36cdd012016-08-22 13:59:31 +03004711 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004712
4713 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004714
4715 return 0;
4716}
4717
4718static int pri_wm_latency_open(struct inode *inode, struct file *file)
4719{
David Weinehall36cdd012016-08-22 13:59:31 +03004720 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004721
David Weinehall36cdd012016-08-22 13:59:31 +03004722 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004723 return -ENODEV;
4724
David Weinehall36cdd012016-08-22 13:59:31 +03004725 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004726}
4727
4728static int spr_wm_latency_open(struct inode *inode, struct file *file)
4729{
David Weinehall36cdd012016-08-22 13:59:31 +03004730 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004731
David Weinehall36cdd012016-08-22 13:59:31 +03004732 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004733 return -ENODEV;
4734
David Weinehall36cdd012016-08-22 13:59:31 +03004735 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004736}
4737
4738static int cur_wm_latency_open(struct inode *inode, struct file *file)
4739{
David Weinehall36cdd012016-08-22 13:59:31 +03004740 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004741
David Weinehall36cdd012016-08-22 13:59:31 +03004742 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004743 return -ENODEV;
4744
David Weinehall36cdd012016-08-22 13:59:31 +03004745 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004746}
4747
4748static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004749 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004750{
4751 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004752 struct drm_i915_private *dev_priv = m->private;
4753 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004754 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004755 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004756 int level;
4757 int ret;
4758 char tmp[32];
4759
David Weinehall36cdd012016-08-22 13:59:31 +03004760 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004761 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004762 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004763 num_levels = 1;
4764 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004765 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004766
Ville Syrjälä369a1342014-01-22 14:36:08 +02004767 if (len >= sizeof(tmp))
4768 return -EINVAL;
4769
4770 if (copy_from_user(tmp, ubuf, len))
4771 return -EFAULT;
4772
4773 tmp[len] = '\0';
4774
Damien Lespiau97e94b22014-11-04 17:06:50 +00004775 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4776 &new[0], &new[1], &new[2], &new[3],
4777 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004778 if (ret != num_levels)
4779 return -EINVAL;
4780
4781 drm_modeset_lock_all(dev);
4782
4783 for (level = 0; level < num_levels; level++)
4784 wm[level] = new[level];
4785
4786 drm_modeset_unlock_all(dev);
4787
4788 return len;
4789}
4790
4791
4792static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4793 size_t len, loff_t *offp)
4794{
4795 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004796 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004797 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004798
David Weinehall36cdd012016-08-22 13:59:31 +03004799 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004800 latencies = dev_priv->wm.skl_latency;
4801 else
David Weinehall36cdd012016-08-22 13:59:31 +03004802 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004803
4804 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004805}
4806
4807static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4808 size_t len, loff_t *offp)
4809{
4810 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004811 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004812 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004813
David Weinehall36cdd012016-08-22 13:59:31 +03004814 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004815 latencies = dev_priv->wm.skl_latency;
4816 else
David Weinehall36cdd012016-08-22 13:59:31 +03004817 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004818
4819 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004820}
4821
4822static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4823 size_t len, loff_t *offp)
4824{
4825 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004826 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004827 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004828
David Weinehall36cdd012016-08-22 13:59:31 +03004829 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004830 latencies = dev_priv->wm.skl_latency;
4831 else
David Weinehall36cdd012016-08-22 13:59:31 +03004832 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004833
4834 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004835}
4836
4837static const struct file_operations i915_pri_wm_latency_fops = {
4838 .owner = THIS_MODULE,
4839 .open = pri_wm_latency_open,
4840 .read = seq_read,
4841 .llseek = seq_lseek,
4842 .release = single_release,
4843 .write = pri_wm_latency_write
4844};
4845
4846static const struct file_operations i915_spr_wm_latency_fops = {
4847 .owner = THIS_MODULE,
4848 .open = spr_wm_latency_open,
4849 .read = seq_read,
4850 .llseek = seq_lseek,
4851 .release = single_release,
4852 .write = spr_wm_latency_write
4853};
4854
4855static const struct file_operations i915_cur_wm_latency_fops = {
4856 .owner = THIS_MODULE,
4857 .open = cur_wm_latency_open,
4858 .read = seq_read,
4859 .llseek = seq_lseek,
4860 .release = single_release,
4861 .write = cur_wm_latency_write
4862};
4863
Kees Cook647416f2013-03-10 14:10:06 -07004864static int
4865i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004866{
David Weinehall36cdd012016-08-22 13:59:31 +03004867 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004868
Chris Wilsond98c52c2016-04-13 17:35:05 +01004869 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004870
Kees Cook647416f2013-03-10 14:10:06 -07004871 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004872}
4873
Kees Cook647416f2013-03-10 14:10:06 -07004874static int
4875i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004876{
David Weinehall36cdd012016-08-22 13:59:31 +03004877 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004878
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004879 /*
4880 * There is no safeguard against this debugfs entry colliding
4881 * with the hangcheck calling same i915_handle_error() in
4882 * parallel, causing an explosion. For now we assume that the
4883 * test harness is responsible enough not to inject gpu hangs
4884 * while it is writing to 'i915_wedged'
4885 */
4886
Chris Wilsond98c52c2016-04-13 17:35:05 +01004887 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004888 return -EAGAIN;
4889
Chris Wilsonc0336662016-05-06 15:40:21 +01004890 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004891 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004892
Kees Cook647416f2013-03-10 14:10:06 -07004893 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004894}
4895
Kees Cook647416f2013-03-10 14:10:06 -07004896DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4897 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004898 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004899
Kees Cook647416f2013-03-10 14:10:06 -07004900static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004901i915_ring_missed_irq_get(void *data, u64 *val)
4902{
David Weinehall36cdd012016-08-22 13:59:31 +03004903 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004904
4905 *val = dev_priv->gpu_error.missed_irq_rings;
4906 return 0;
4907}
4908
4909static int
4910i915_ring_missed_irq_set(void *data, u64 val)
4911{
David Weinehall36cdd012016-08-22 13:59:31 +03004912 struct drm_i915_private *dev_priv = data;
4913 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004914 int ret;
4915
4916 /* Lock against concurrent debugfs callers */
4917 ret = mutex_lock_interruptible(&dev->struct_mutex);
4918 if (ret)
4919 return ret;
4920 dev_priv->gpu_error.missed_irq_rings = val;
4921 mutex_unlock(&dev->struct_mutex);
4922
4923 return 0;
4924}
4925
4926DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4927 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4928 "0x%08llx\n");
4929
4930static int
4931i915_ring_test_irq_get(void *data, u64 *val)
4932{
David Weinehall36cdd012016-08-22 13:59:31 +03004933 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004934
4935 *val = dev_priv->gpu_error.test_irq_rings;
4936
4937 return 0;
4938}
4939
4940static int
4941i915_ring_test_irq_set(void *data, u64 val)
4942{
David Weinehall36cdd012016-08-22 13:59:31 +03004943 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004944
Chris Wilson3a122c22016-06-17 14:35:05 +01004945 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004946 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004947 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004948
4949 return 0;
4950}
4951
4952DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4953 i915_ring_test_irq_get, i915_ring_test_irq_set,
4954 "0x%08llx\n");
4955
Chris Wilsondd624af2013-01-15 12:39:35 +00004956#define DROP_UNBOUND 0x1
4957#define DROP_BOUND 0x2
4958#define DROP_RETIRE 0x4
4959#define DROP_ACTIVE 0x8
4960#define DROP_ALL (DROP_UNBOUND | \
4961 DROP_BOUND | \
4962 DROP_RETIRE | \
4963 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004964static int
4965i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004966{
Kees Cook647416f2013-03-10 14:10:06 -07004967 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004968
Kees Cook647416f2013-03-10 14:10:06 -07004969 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004970}
4971
Kees Cook647416f2013-03-10 14:10:06 -07004972static int
4973i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004974{
David Weinehall36cdd012016-08-22 13:59:31 +03004975 struct drm_i915_private *dev_priv = data;
4976 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004977 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004978
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004979 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004980
4981 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4982 * on ioctls on -EAGAIN. */
4983 ret = mutex_lock_interruptible(&dev->struct_mutex);
4984 if (ret)
4985 return ret;
4986
4987 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004988 ret = i915_gem_wait_for_idle(dev_priv,
4989 I915_WAIT_INTERRUPTIBLE |
4990 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004991 if (ret)
4992 goto unlock;
4993 }
4994
4995 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004996 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004997
Chris Wilson21ab4e72014-09-09 11:16:08 +01004998 if (val & DROP_BOUND)
4999 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01005000
Chris Wilson21ab4e72014-09-09 11:16:08 +01005001 if (val & DROP_UNBOUND)
5002 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00005003
5004unlock:
5005 mutex_unlock(&dev->struct_mutex);
5006
Kees Cook647416f2013-03-10 14:10:06 -07005007 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00005008}
5009
Kees Cook647416f2013-03-10 14:10:06 -07005010DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
5011 i915_drop_caches_get, i915_drop_caches_set,
5012 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00005013
Kees Cook647416f2013-03-10 14:10:06 -07005014static int
5015i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005016{
David Weinehall36cdd012016-08-22 13:59:31 +03005017 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005018
David Weinehall36cdd012016-08-22 13:59:31 +03005019 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005020 return -ENODEV;
5021
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005022 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005023 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005024}
5025
Kees Cook647416f2013-03-10 14:10:06 -07005026static int
5027i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005028{
David Weinehall36cdd012016-08-22 13:59:31 +03005029 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305030 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005031 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005032
David Weinehall36cdd012016-08-22 13:59:31 +03005033 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005034 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005035
Kees Cook647416f2013-03-10 14:10:06 -07005036 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005037
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005038 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005039 if (ret)
5040 return ret;
5041
Jesse Barnes358733e2011-07-27 11:53:01 -07005042 /*
5043 * Turbo will still be enabled, but won't go above the set value.
5044 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305045 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005046
Akash Goelbc4d91f2015-02-26 16:09:47 +05305047 hw_max = dev_priv->rps.max_freq;
5048 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005049
Ben Widawskyb39fb292014-03-19 18:31:11 -07005050 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005051 mutex_unlock(&dev_priv->rps.hw_lock);
5052 return -EINVAL;
5053 }
5054
Ben Widawskyb39fb292014-03-19 18:31:11 -07005055 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005056
Chris Wilsondc979972016-05-10 14:10:04 +01005057 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005058
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005059 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005060
Kees Cook647416f2013-03-10 14:10:06 -07005061 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005062}
5063
Kees Cook647416f2013-03-10 14:10:06 -07005064DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5065 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005066 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005067
Kees Cook647416f2013-03-10 14:10:06 -07005068static int
5069i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005070{
David Weinehall36cdd012016-08-22 13:59:31 +03005071 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02005072
Chris Wilson62e1baa2016-07-13 09:10:36 +01005073 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005074 return -ENODEV;
5075
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005076 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005077 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005078}
5079
Kees Cook647416f2013-03-10 14:10:06 -07005080static int
5081i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005082{
David Weinehall36cdd012016-08-22 13:59:31 +03005083 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305084 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005085 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005086
Chris Wilson62e1baa2016-07-13 09:10:36 +01005087 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005088 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005089
Kees Cook647416f2013-03-10 14:10:06 -07005090 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005091
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005092 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005093 if (ret)
5094 return ret;
5095
Jesse Barnes1523c312012-05-25 12:34:54 -07005096 /*
5097 * Turbo will still be enabled, but won't go below the set value.
5098 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305099 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005100
Akash Goelbc4d91f2015-02-26 16:09:47 +05305101 hw_max = dev_priv->rps.max_freq;
5102 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005103
David Weinehall36cdd012016-08-22 13:59:31 +03005104 if (val < hw_min ||
5105 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005106 mutex_unlock(&dev_priv->rps.hw_lock);
5107 return -EINVAL;
5108 }
5109
Ben Widawskyb39fb292014-03-19 18:31:11 -07005110 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005111
Chris Wilsondc979972016-05-10 14:10:04 +01005112 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005113
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005114 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005115
Kees Cook647416f2013-03-10 14:10:06 -07005116 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005117}
5118
Kees Cook647416f2013-03-10 14:10:06 -07005119DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5120 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005121 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005122
Kees Cook647416f2013-03-10 14:10:06 -07005123static int
5124i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005125{
David Weinehall36cdd012016-08-22 13:59:31 +03005126 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005127 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005128
David Weinehall36cdd012016-08-22 13:59:31 +03005129 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005130 return -ENODEV;
5131
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005132 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005133
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005134 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005135
5136 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005137
Kees Cook647416f2013-03-10 14:10:06 -07005138 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005139
Kees Cook647416f2013-03-10 14:10:06 -07005140 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005141}
5142
Kees Cook647416f2013-03-10 14:10:06 -07005143static int
5144i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005145{
David Weinehall36cdd012016-08-22 13:59:31 +03005146 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005147 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005148
David Weinehall36cdd012016-08-22 13:59:31 +03005149 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005150 return -ENODEV;
5151
Kees Cook647416f2013-03-10 14:10:06 -07005152 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005153 return -EINVAL;
5154
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005155 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005156 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005157
5158 /* Update the cache sharing policy here as well */
5159 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5160 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5161 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5162 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5163
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005164 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005165 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005166}
5167
Kees Cook647416f2013-03-10 14:10:06 -07005168DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5169 i915_cache_sharing_get, i915_cache_sharing_set,
5170 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005171
David Weinehall36cdd012016-08-22 13:59:31 +03005172static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005173 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005174{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005175 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005176 int ss;
5177 u32 sig1[ss_max], sig2[ss_max];
5178
5179 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5180 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5181 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5182 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5183
5184 for (ss = 0; ss < ss_max; ss++) {
5185 unsigned int eu_cnt;
5186
5187 if (sig1[ss] & CHV_SS_PG_ENABLE)
5188 /* skip disabled subslice */
5189 continue;
5190
Imre Deakf08a0c92016-08-31 19:13:04 +03005191 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005192 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005193 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5194 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5195 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5196 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005197 sseu->eu_total += eu_cnt;
5198 sseu->eu_per_subslice = max_t(unsigned int,
5199 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005200 }
Jeff McGee5d395252015-04-03 18:13:17 -07005201}
5202
David Weinehall36cdd012016-08-22 13:59:31 +03005203static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005204 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005205{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005206 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005207 int s, ss;
5208 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5209
Jeff McGee1c046bc2015-04-03 18:13:18 -07005210 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005211 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005212 s_max = 1;
5213 ss_max = 3;
5214 }
5215
5216 for (s = 0; s < s_max; s++) {
5217 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5218 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5219 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5220 }
5221
Jeff McGee5d395252015-04-03 18:13:17 -07005222 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5223 GEN9_PGCTL_SSA_EU19_ACK |
5224 GEN9_PGCTL_SSA_EU210_ACK |
5225 GEN9_PGCTL_SSA_EU311_ACK;
5226 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5227 GEN9_PGCTL_SSB_EU19_ACK |
5228 GEN9_PGCTL_SSB_EU210_ACK |
5229 GEN9_PGCTL_SSB_EU311_ACK;
5230
5231 for (s = 0; s < s_max; s++) {
5232 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5233 /* skip disabled slice */
5234 continue;
5235
Imre Deakf08a0c92016-08-31 19:13:04 +03005236 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005237
David Weinehall36cdd012016-08-22 13:59:31 +03005238 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005239 sseu->subslice_mask =
5240 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005241
Jeff McGee5d395252015-04-03 18:13:17 -07005242 for (ss = 0; ss < ss_max; ss++) {
5243 unsigned int eu_cnt;
5244
Imre Deak57ec1712016-08-31 19:13:05 +03005245 if (IS_BROXTON(dev_priv)) {
5246 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5247 /* skip disabled subslice */
5248 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005249
Imre Deak57ec1712016-08-31 19:13:05 +03005250 sseu->subslice_mask |= BIT(ss);
5251 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005252
Jeff McGee5d395252015-04-03 18:13:17 -07005253 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5254 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005255 sseu->eu_total += eu_cnt;
5256 sseu->eu_per_subslice = max_t(unsigned int,
5257 sseu->eu_per_subslice,
5258 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005259 }
5260 }
5261}
5262
David Weinehall36cdd012016-08-22 13:59:31 +03005263static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005264 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005265{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005266 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005267 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005268
Imre Deakf08a0c92016-08-31 19:13:04 +03005269 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005270
Imre Deakf08a0c92016-08-31 19:13:04 +03005271 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005272 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005273 sseu->eu_per_subslice =
5274 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005275 sseu->eu_total = sseu->eu_per_subslice *
5276 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005277
5278 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005279 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005280 u8 subslice_7eu =
5281 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005282
Imre Deak915490d2016-08-31 19:13:01 +03005283 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005284 }
5285 }
5286}
5287
Imre Deak615d8902016-08-31 19:13:03 +03005288static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5289 const struct sseu_dev_info *sseu)
5290{
5291 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5292 const char *type = is_available_info ? "Available" : "Enabled";
5293
Imre Deakc67ba532016-08-31 19:13:06 +03005294 seq_printf(m, " %s Slice Mask: %04x\n", type,
5295 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005296 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005297 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005298 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005299 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005300 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5301 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005302 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005303 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005304 seq_printf(m, " %s EU Total: %u\n", type,
5305 sseu->eu_total);
5306 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5307 sseu->eu_per_subslice);
5308
5309 if (!is_available_info)
5310 return;
5311
5312 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5313 if (HAS_POOLED_EU(dev_priv))
5314 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5315
5316 seq_printf(m, " Has Slice Power Gating: %s\n",
5317 yesno(sseu->has_slice_pg));
5318 seq_printf(m, " Has Subslice Power Gating: %s\n",
5319 yesno(sseu->has_subslice_pg));
5320 seq_printf(m, " Has EU Power Gating: %s\n",
5321 yesno(sseu->has_eu_pg));
5322}
5323
Jeff McGee38732182015-02-13 10:27:54 -06005324static int i915_sseu_status(struct seq_file *m, void *unused)
5325{
David Weinehall36cdd012016-08-22 13:59:31 +03005326 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005327 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005328
David Weinehall36cdd012016-08-22 13:59:31 +03005329 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005330 return -ENODEV;
5331
5332 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005333 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005334
Jeff McGee7f992ab2015-02-13 10:27:55 -06005335 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005336 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005337
5338 intel_runtime_pm_get(dev_priv);
5339
David Weinehall36cdd012016-08-22 13:59:31 +03005340 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005341 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005342 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005343 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005344 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005345 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005346 }
David Weinehall238010e2016-08-01 17:33:27 +03005347
5348 intel_runtime_pm_put(dev_priv);
5349
Imre Deak615d8902016-08-31 19:13:03 +03005350 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005351
Jeff McGee38732182015-02-13 10:27:54 -06005352 return 0;
5353}
5354
Ben Widawsky6d794d42011-04-25 11:25:56 -07005355static int i915_forcewake_open(struct inode *inode, struct file *file)
5356{
David Weinehall36cdd012016-08-22 13:59:31 +03005357 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005358
David Weinehall36cdd012016-08-22 13:59:31 +03005359 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005360 return 0;
5361
Chris Wilson6daccb02015-01-16 11:34:35 +02005362 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005363 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005364
5365 return 0;
5366}
5367
Ben Widawskyc43b5632012-04-16 14:07:40 -07005368static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005369{
David Weinehall36cdd012016-08-22 13:59:31 +03005370 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005371
David Weinehall36cdd012016-08-22 13:59:31 +03005372 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005373 return 0;
5374
Mika Kuoppala59bad942015-01-16 11:34:40 +02005375 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005376 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005377
5378 return 0;
5379}
5380
5381static const struct file_operations i915_forcewake_fops = {
5382 .owner = THIS_MODULE,
5383 .open = i915_forcewake_open,
5384 .release = i915_forcewake_release,
5385};
5386
5387static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5388{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005389 struct dentry *ent;
5390
5391 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005392 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005393 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005394 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005395 if (!ent)
5396 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005397
Ben Widawsky8eb57292011-05-11 15:10:58 -07005398 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005399}
5400
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005401static int i915_debugfs_create(struct dentry *root,
5402 struct drm_minor *minor,
5403 const char *name,
5404 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005405{
Jesse Barnes358733e2011-07-27 11:53:01 -07005406 struct dentry *ent;
5407
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005408 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005409 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005410 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005411 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005412 if (!ent)
5413 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005414
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005415 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005416}
5417
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005418static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005419 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005420 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005421 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005422 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005423 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005424 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005425 {"i915_gem_request", i915_gem_request_info, 0},
5426 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005427 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005428 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005429 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5430 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5431 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005432 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005433 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005434 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005435 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005436 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305437 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005438 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005439 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005440 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005441 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005442 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005443 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005444 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005445 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005446 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005447 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005448 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005449 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005450 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005451 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005452 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005453 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005454 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005455 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005456 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005457 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005458 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005459 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005460 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005461 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005462 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005463 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005464 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005465 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005466 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005467 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005468 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305469 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005470 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005471};
Ben Gamari27c202a2009-07-01 22:26:52 -04005472#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005473
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005474static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005475 const char *name;
5476 const struct file_operations *fops;
5477} i915_debugfs_files[] = {
5478 {"i915_wedged", &i915_wedged_fops},
5479 {"i915_max_freq", &i915_max_freq_fops},
5480 {"i915_min_freq", &i915_min_freq_fops},
5481 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005482 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5483 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005484 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005485#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005486 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005487#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005488 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005489 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005490 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5491 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5492 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005493 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005494 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5495 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05305496 {"i915_dp_test_active", &i915_displayport_test_active_fops},
5497 {"i915_guc_log_control", &i915_guc_log_control_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005498};
5499
David Weinehall36cdd012016-08-22 13:59:31 +03005500void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005501{
Daniel Vetterb3783602013-11-14 11:30:42 +01005502 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005503
Damien Lespiau055e3932014-08-18 13:49:10 +01005504 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005505 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005506
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005507 pipe_crc->opened = false;
5508 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005509 init_waitqueue_head(&pipe_crc->wq);
5510 }
5511}
5512
Chris Wilson1dac8912016-06-24 14:00:17 +01005513int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005514{
Chris Wilson91c8a322016-07-05 10:40:23 +01005515 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005516 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005517
Ben Widawsky6d794d42011-04-25 11:25:56 -07005518 ret = i915_forcewake_create(minor->debugfs_root, minor);
5519 if (ret)
5520 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005521
Damien Lespiau07144422013-10-15 18:55:40 +01005522 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5523 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5524 if (ret)
5525 return ret;
5526 }
5527
Daniel Vetter34b96742013-07-04 20:49:44 +02005528 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5529 ret = i915_debugfs_create(minor->debugfs_root, minor,
5530 i915_debugfs_files[i].name,
5531 i915_debugfs_files[i].fops);
5532 if (ret)
5533 return ret;
5534 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005535
Ben Gamari27c202a2009-07-01 22:26:52 -04005536 return drm_debugfs_create_files(i915_debugfs_list,
5537 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005538 minor->debugfs_root, minor);
5539}
5540
Chris Wilson1dac8912016-06-24 14:00:17 +01005541void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005542{
Chris Wilson91c8a322016-07-05 10:40:23 +01005543 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005544 int i;
5545
Ben Gamari27c202a2009-07-01 22:26:52 -04005546 drm_debugfs_remove_files(i915_debugfs_list,
5547 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005548
David Weinehall36cdd012016-08-22 13:59:31 +03005549 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005550 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005551
Daniel Vettere309a992013-10-16 22:55:51 +02005552 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005553 struct drm_info_list *info_list =
5554 (struct drm_info_list *)&i915_pipe_crc_data[i];
5555
5556 drm_debugfs_remove_files(info_list, 1, minor);
5557 }
5558
Daniel Vetter34b96742013-07-04 20:49:44 +02005559 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5560 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005561 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005562
5563 drm_debugfs_remove_files(info_list, 1, minor);
5564 }
Ben Gamari20172632009-02-17 20:08:50 -05005565}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005566
5567struct dpcd_block {
5568 /* DPCD dump start address. */
5569 unsigned int offset;
5570 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5571 unsigned int end;
5572 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5573 size_t size;
5574 /* Only valid for eDP. */
5575 bool edp;
5576};
5577
5578static const struct dpcd_block i915_dpcd_debug[] = {
5579 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5580 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5581 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5582 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5583 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5584 { .offset = DP_SET_POWER },
5585 { .offset = DP_EDP_DPCD_REV },
5586 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5587 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5588 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5589};
5590
5591static int i915_dpcd_show(struct seq_file *m, void *data)
5592{
5593 struct drm_connector *connector = m->private;
5594 struct intel_dp *intel_dp =
5595 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5596 uint8_t buf[16];
5597 ssize_t err;
5598 int i;
5599
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005600 if (connector->status != connector_status_connected)
5601 return -ENODEV;
5602
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005603 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5604 const struct dpcd_block *b = &i915_dpcd_debug[i];
5605 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5606
5607 if (b->edp &&
5608 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5609 continue;
5610
5611 /* low tech for now */
5612 if (WARN_ON(size > sizeof(buf)))
5613 continue;
5614
5615 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5616 if (err <= 0) {
5617 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5618 size, b->offset, err);
5619 continue;
5620 }
5621
5622 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005623 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005624
5625 return 0;
5626}
5627
5628static int i915_dpcd_open(struct inode *inode, struct file *file)
5629{
5630 return single_open(file, i915_dpcd_show, inode->i_private);
5631}
5632
5633static const struct file_operations i915_dpcd_fops = {
5634 .owner = THIS_MODULE,
5635 .open = i915_dpcd_open,
5636 .read = seq_read,
5637 .llseek = seq_lseek,
5638 .release = single_release,
5639};
5640
David Weinehallecbd6782016-08-23 12:23:56 +03005641static int i915_panel_show(struct seq_file *m, void *data)
5642{
5643 struct drm_connector *connector = m->private;
5644 struct intel_dp *intel_dp =
5645 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5646
5647 if (connector->status != connector_status_connected)
5648 return -ENODEV;
5649
5650 seq_printf(m, "Panel power up delay: %d\n",
5651 intel_dp->panel_power_up_delay);
5652 seq_printf(m, "Panel power down delay: %d\n",
5653 intel_dp->panel_power_down_delay);
5654 seq_printf(m, "Backlight on delay: %d\n",
5655 intel_dp->backlight_on_delay);
5656 seq_printf(m, "Backlight off delay: %d\n",
5657 intel_dp->backlight_off_delay);
5658
5659 return 0;
5660}
5661
5662static int i915_panel_open(struct inode *inode, struct file *file)
5663{
5664 return single_open(file, i915_panel_show, inode->i_private);
5665}
5666
5667static const struct file_operations i915_panel_fops = {
5668 .owner = THIS_MODULE,
5669 .open = i915_panel_open,
5670 .read = seq_read,
5671 .llseek = seq_lseek,
5672 .release = single_release,
5673};
5674
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005675/**
5676 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5677 * @connector: pointer to a registered drm_connector
5678 *
5679 * Cleanup will be done by drm_connector_unregister() through a call to
5680 * drm_debugfs_connector_remove().
5681 *
5682 * Returns 0 on success, negative error codes on error.
5683 */
5684int i915_debugfs_connector_add(struct drm_connector *connector)
5685{
5686 struct dentry *root = connector->debugfs_entry;
5687
5688 /* The connector must have been registered beforehands. */
5689 if (!root)
5690 return -ENODEV;
5691
5692 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5693 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005694 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5695 connector, &i915_dpcd_fops);
5696
5697 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5698 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5699 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005700
5701 return 0;
5702}