blob: dc057c770146931a173ef86709eaec70cd3993d3 [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 Wilson8baa1f02016-10-12 12:48:27 +0100110 return obj->fault_mappable ? '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{
115 return obj->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 Wilson37811fc2010-08-25 22:45:57 +0100161 obj->dirty ? " dirty" : "",
162 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
163 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 Wilsonb7abb712012-08-20 11:33:30 +0200406 if (obj->madv == I915_MADV_DONTNEED) {
407 purgeable_size += obj->base.size;
408 ++purgeable_count;
409 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100410
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100411 if (obj->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
428 if (obj->madv == I915_MADV_DONTNEED) {
429 purgeable_size += obj->base.size;
430 ++purgeable_count;
431 }
432
433 if (obj->mapping) {
434 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));
Damien Lespiau055e3932014-08-18 13:49:10 +0100746 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300747 seq_printf(m, "Pipe %c stat:\t%08x\n",
748 pipe_name(pipe),
749 I915_READ(PIPESTAT(pipe)));
750
751 seq_printf(m, "Port hotplug:\t%08x\n",
752 I915_READ(PORT_HOTPLUG_EN));
753 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
754 I915_READ(VLV_DPFLIPSTAT));
755 seq_printf(m, "DPINVGTT:\t%08x\n",
756 I915_READ(DPINVGTT));
757
758 for (i = 0; i < 4; i++) {
759 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
760 i, I915_READ(GEN8_GT_IMR(i)));
761 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
762 i, I915_READ(GEN8_GT_IIR(i)));
763 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
764 i, I915_READ(GEN8_GT_IER(i)));
765 }
766
767 seq_printf(m, "PCU interrupt mask:\t%08x\n",
768 I915_READ(GEN8_PCU_IMR));
769 seq_printf(m, "PCU interrupt identity:\t%08x\n",
770 I915_READ(GEN8_PCU_IIR));
771 seq_printf(m, "PCU interrupt enable:\t%08x\n",
772 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300773 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700774 seq_printf(m, "Master Interrupt Control:\t%08x\n",
775 I915_READ(GEN8_MASTER_IRQ));
776
777 for (i = 0; i < 4; i++) {
778 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
779 i, I915_READ(GEN8_GT_IMR(i)));
780 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
781 i, I915_READ(GEN8_GT_IIR(i)));
782 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
783 i, I915_READ(GEN8_GT_IER(i)));
784 }
785
Damien Lespiau055e3932014-08-18 13:49:10 +0100786 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200787 enum intel_display_power_domain power_domain;
788
789 power_domain = POWER_DOMAIN_PIPE(pipe);
790 if (!intel_display_power_get_if_enabled(dev_priv,
791 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300792 seq_printf(m, "Pipe %c power disabled\n",
793 pipe_name(pipe));
794 continue;
795 }
Ben Widawskya123f152013-11-02 21:07:10 -0700796 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000797 pipe_name(pipe),
798 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700799 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000800 pipe_name(pipe),
801 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700802 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000803 pipe_name(pipe),
804 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200805
806 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700807 }
808
809 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
810 I915_READ(GEN8_DE_PORT_IMR));
811 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
812 I915_READ(GEN8_DE_PORT_IIR));
813 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
814 I915_READ(GEN8_DE_PORT_IER));
815
816 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
817 I915_READ(GEN8_DE_MISC_IMR));
818 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
819 I915_READ(GEN8_DE_MISC_IIR));
820 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
821 I915_READ(GEN8_DE_MISC_IER));
822
823 seq_printf(m, "PCU interrupt mask:\t%08x\n",
824 I915_READ(GEN8_PCU_IMR));
825 seq_printf(m, "PCU interrupt identity:\t%08x\n",
826 I915_READ(GEN8_PCU_IIR));
827 seq_printf(m, "PCU interrupt enable:\t%08x\n",
828 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300829 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700830 seq_printf(m, "Display IER:\t%08x\n",
831 I915_READ(VLV_IER));
832 seq_printf(m, "Display IIR:\t%08x\n",
833 I915_READ(VLV_IIR));
834 seq_printf(m, "Display IIR_RW:\t%08x\n",
835 I915_READ(VLV_IIR_RW));
836 seq_printf(m, "Display IMR:\t%08x\n",
837 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100838 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700839 seq_printf(m, "Pipe %c stat:\t%08x\n",
840 pipe_name(pipe),
841 I915_READ(PIPESTAT(pipe)));
842
843 seq_printf(m, "Master IER:\t%08x\n",
844 I915_READ(VLV_MASTER_IER));
845
846 seq_printf(m, "Render IER:\t%08x\n",
847 I915_READ(GTIER));
848 seq_printf(m, "Render IIR:\t%08x\n",
849 I915_READ(GTIIR));
850 seq_printf(m, "Render IMR:\t%08x\n",
851 I915_READ(GTIMR));
852
853 seq_printf(m, "PM IER:\t\t%08x\n",
854 I915_READ(GEN6_PMIER));
855 seq_printf(m, "PM IIR:\t\t%08x\n",
856 I915_READ(GEN6_PMIIR));
857 seq_printf(m, "PM IMR:\t\t%08x\n",
858 I915_READ(GEN6_PMIMR));
859
860 seq_printf(m, "Port hotplug:\t%08x\n",
861 I915_READ(PORT_HOTPLUG_EN));
862 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
863 I915_READ(VLV_DPFLIPSTAT));
864 seq_printf(m, "DPINVGTT:\t%08x\n",
865 I915_READ(DPINVGTT));
866
David Weinehall36cdd012016-08-22 13:59:31 +0300867 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800868 seq_printf(m, "Interrupt enable: %08x\n",
869 I915_READ(IER));
870 seq_printf(m, "Interrupt identity: %08x\n",
871 I915_READ(IIR));
872 seq_printf(m, "Interrupt mask: %08x\n",
873 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100874 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800875 seq_printf(m, "Pipe %c stat: %08x\n",
876 pipe_name(pipe),
877 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800878 } else {
879 seq_printf(m, "North Display Interrupt enable: %08x\n",
880 I915_READ(DEIER));
881 seq_printf(m, "North Display Interrupt identity: %08x\n",
882 I915_READ(DEIIR));
883 seq_printf(m, "North Display Interrupt mask: %08x\n",
884 I915_READ(DEIMR));
885 seq_printf(m, "South Display Interrupt enable: %08x\n",
886 I915_READ(SDEIER));
887 seq_printf(m, "South Display Interrupt identity: %08x\n",
888 I915_READ(SDEIIR));
889 seq_printf(m, "South Display Interrupt mask: %08x\n",
890 I915_READ(SDEIMR));
891 seq_printf(m, "Graphics Interrupt enable: %08x\n",
892 I915_READ(GTIER));
893 seq_printf(m, "Graphics Interrupt identity: %08x\n",
894 I915_READ(GTIIR));
895 seq_printf(m, "Graphics Interrupt mask: %08x\n",
896 I915_READ(GTIMR));
897 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530898 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300899 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100900 seq_printf(m,
901 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000902 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000903 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000904 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000905 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200906 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100907
Ben Gamari20172632009-02-17 20:08:50 -0500908 return 0;
909}
910
Chris Wilsona6172a82009-02-11 14:26:38 +0000911static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
912{
David Weinehall36cdd012016-08-22 13:59:31 +0300913 struct drm_i915_private *dev_priv = node_to_i915(m->private);
914 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100915 int i, ret;
916
917 ret = mutex_lock_interruptible(&dev->struct_mutex);
918 if (ret)
919 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000920
Chris Wilsona6172a82009-02-11 14:26:38 +0000921 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
922 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100923 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000924
Chris Wilson6c085a72012-08-20 11:40:46 +0200925 seq_printf(m, "Fence %d, pin count = %d, object = ",
926 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100927 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100928 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100929 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100930 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100931 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000932 }
933
Chris Wilson05394f32010-11-08 19:18:58 +0000934 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000935 return 0;
936}
937
Ben Gamari20172632009-02-17 20:08:50 -0500938static int i915_hws_info(struct seq_file *m, void *data)
939{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100940 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300941 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000942 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100943 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100944 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500945
Akash Goel3b3f1652016-10-13 22:44:48 +0530946 engine = dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000947 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500948 if (hws == NULL)
949 return 0;
950
951 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
952 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
953 i * 4,
954 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
955 }
956 return 0;
957}
958
Chris Wilson98a2f412016-10-12 10:05:18 +0100959#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
960
Daniel Vetterd5442302012-04-27 15:17:40 +0200961static ssize_t
962i915_error_state_write(struct file *filp,
963 const char __user *ubuf,
964 size_t cnt,
965 loff_t *ppos)
966{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300967 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200968
969 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100970 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200971
972 return cnt;
973}
974
975static int i915_error_state_open(struct inode *inode, struct file *file)
976{
David Weinehall36cdd012016-08-22 13:59:31 +0300977 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200978 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200979
980 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
981 if (!error_priv)
982 return -ENOMEM;
983
David Weinehall36cdd012016-08-22 13:59:31 +0300984 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200985
David Weinehall36cdd012016-08-22 13:59:31 +0300986 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200987
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300988 file->private_data = error_priv;
989
990 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200991}
992
993static int i915_error_state_release(struct inode *inode, struct file *file)
994{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300995 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200996
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300997 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200998 kfree(error_priv);
999
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001000 return 0;
1001}
1002
1003static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1004 size_t count, loff_t *pos)
1005{
1006 struct i915_error_state_file_priv *error_priv = file->private_data;
1007 struct drm_i915_error_state_buf error_str;
1008 loff_t tmp_pos = 0;
1009 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001010 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001011
David Weinehall36cdd012016-08-22 13:59:31 +03001012 ret = i915_error_state_buf_init(&error_str,
1013 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001014 if (ret)
1015 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001016
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001017 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001018 if (ret)
1019 goto out;
1020
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001021 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1022 error_str.buf,
1023 error_str.bytes);
1024
1025 if (ret_count < 0)
1026 ret = ret_count;
1027 else
1028 *pos = error_str.start + ret_count;
1029out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001030 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001031 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001032}
1033
1034static const struct file_operations i915_error_state_fops = {
1035 .owner = THIS_MODULE,
1036 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001037 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001038 .write = i915_error_state_write,
1039 .llseek = default_llseek,
1040 .release = i915_error_state_release,
1041};
1042
Chris Wilson98a2f412016-10-12 10:05:18 +01001043#endif
1044
Kees Cook647416f2013-03-10 14:10:06 -07001045static int
1046i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001047{
David Weinehall36cdd012016-08-22 13:59:31 +03001048 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001049 int ret;
1050
David Weinehall36cdd012016-08-22 13:59:31 +03001051 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001052 if (ret)
1053 return ret;
1054
Kees Cook647416f2013-03-10 14:10:06 -07001055 *val = dev_priv->next_seqno;
David Weinehall36cdd012016-08-22 13:59:31 +03001056 mutex_unlock(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001057
Kees Cook647416f2013-03-10 14:10:06 -07001058 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001059}
1060
Kees Cook647416f2013-03-10 14:10:06 -07001061static int
1062i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001063{
David Weinehall36cdd012016-08-22 13:59:31 +03001064 struct drm_i915_private *dev_priv = data;
1065 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001066 int ret;
1067
Mika Kuoppala40633212012-12-04 15:12:00 +02001068 ret = mutex_lock_interruptible(&dev->struct_mutex);
1069 if (ret)
1070 return ret;
1071
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001072 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001073 mutex_unlock(&dev->struct_mutex);
1074
Kees Cook647416f2013-03-10 14:10:06 -07001075 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001076}
1077
Kees Cook647416f2013-03-10 14:10:06 -07001078DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1079 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001080 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001081
Deepak Sadb4bd12014-03-31 11:30:02 +05301082static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001083{
David Weinehall36cdd012016-08-22 13:59:31 +03001084 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1085 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001086 int ret = 0;
1087
1088 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001089
David Weinehall36cdd012016-08-22 13:59:31 +03001090 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001091 u16 rgvswctl = I915_READ16(MEMSWCTL);
1092 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1093
1094 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1095 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1096 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1097 MEMSTAT_VID_SHIFT);
1098 seq_printf(m, "Current P-state: %d\n",
1099 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001100 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001101 u32 freq_sts;
1102
1103 mutex_lock(&dev_priv->rps.hw_lock);
1104 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1105 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1106 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1107
1108 seq_printf(m, "actual GPU freq: %d MHz\n",
1109 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1110
1111 seq_printf(m, "current GPU freq: %d MHz\n",
1112 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1113
1114 seq_printf(m, "max GPU freq: %d MHz\n",
1115 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1116
1117 seq_printf(m, "min GPU freq: %d MHz\n",
1118 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1119
1120 seq_printf(m, "idle GPU freq: %d MHz\n",
1121 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1122
1123 seq_printf(m,
1124 "efficient (RPe) frequency: %d MHz\n",
1125 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1126 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001127 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001128 u32 rp_state_limits;
1129 u32 gt_perf_status;
1130 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001131 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001132 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001133 u32 rpupei, rpcurup, rpprevup;
1134 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001135 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001136 int max_freq;
1137
Bob Paauwe35040562015-06-25 14:54:07 -07001138 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001139 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001140 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1141 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1142 } else {
1143 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1144 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1145 }
1146
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001147 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001148 ret = mutex_lock_interruptible(&dev->struct_mutex);
1149 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001150 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001151
Mika Kuoppala59bad942015-01-16 11:34:40 +02001152 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001153
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001154 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001155 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301156 reqf >>= 23;
1157 else {
1158 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001159 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301160 reqf >>= 24;
1161 else
1162 reqf >>= 25;
1163 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001164 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001165
Chris Wilson0d8f9492014-03-27 09:06:14 +00001166 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1167 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1168 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1169
Jesse Barnesccab5c82011-01-18 15:49:25 -08001170 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301171 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1172 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1173 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1174 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1175 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1176 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001177 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301178 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001179 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001180 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1181 else
1182 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001183 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001184
Mika Kuoppala59bad942015-01-16 11:34:40 +02001185 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001186 mutex_unlock(&dev->struct_mutex);
1187
David Weinehall36cdd012016-08-22 13:59:31 +03001188 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001189 pm_ier = I915_READ(GEN6_PMIER);
1190 pm_imr = I915_READ(GEN6_PMIMR);
1191 pm_isr = I915_READ(GEN6_PMISR);
1192 pm_iir = I915_READ(GEN6_PMIIR);
1193 pm_mask = I915_READ(GEN6_PMINTRMSK);
1194 } else {
1195 pm_ier = I915_READ(GEN8_GT_IER(2));
1196 pm_imr = I915_READ(GEN8_GT_IMR(2));
1197 pm_isr = I915_READ(GEN8_GT_ISR(2));
1198 pm_iir = I915_READ(GEN8_GT_IIR(2));
1199 pm_mask = I915_READ(GEN6_PMINTRMSK);
1200 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001201 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 -03001202 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301203 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001204 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001205 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001206 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001207 seq_printf(m, "Render p-state VID: %d\n",
1208 gt_perf_status & 0xff);
1209 seq_printf(m, "Render p-state limit: %d\n",
1210 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001211 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1212 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1213 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1214 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001215 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001216 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301217 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1218 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1219 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1220 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1221 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1222 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001223 seq_printf(m, "Up threshold: %d%%\n",
1224 dev_priv->rps.up_threshold);
1225
Akash Goeld6cda9c2016-04-23 00:05:46 +05301226 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1227 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1228 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1229 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1230 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1231 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001232 seq_printf(m, "Down threshold: %d%%\n",
1233 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001234
David Weinehall36cdd012016-08-22 13:59:31 +03001235 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001236 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001237 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001238 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001239 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001240 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001241
1242 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001243 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001244 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001245 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001246 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001247
David Weinehall36cdd012016-08-22 13:59:31 +03001248 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001249 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001250 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001251 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001252 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001253 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001254 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001255 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001256
Chris Wilsond86ed342015-04-27 13:41:19 +01001257 seq_printf(m, "Current freq: %d MHz\n",
1258 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1259 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001260 seq_printf(m, "Idle freq: %d MHz\n",
1261 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001262 seq_printf(m, "Min freq: %d MHz\n",
1263 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001264 seq_printf(m, "Boost freq: %d MHz\n",
1265 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001266 seq_printf(m, "Max freq: %d MHz\n",
1267 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1268 seq_printf(m,
1269 "efficient (RPe) frequency: %d MHz\n",
1270 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001271 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001272 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001273 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001274
Mika Kahola1170f282015-09-25 14:00:32 +03001275 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1276 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1277 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1278
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001279out:
1280 intel_runtime_pm_put(dev_priv);
1281 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001282}
1283
Ben Widawskyd6369512016-09-20 16:54:32 +03001284static void i915_instdone_info(struct drm_i915_private *dev_priv,
1285 struct seq_file *m,
1286 struct intel_instdone *instdone)
1287{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001288 int slice;
1289 int subslice;
1290
Ben Widawskyd6369512016-09-20 16:54:32 +03001291 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1292 instdone->instdone);
1293
1294 if (INTEL_GEN(dev_priv) <= 3)
1295 return;
1296
1297 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1298 instdone->slice_common);
1299
1300 if (INTEL_GEN(dev_priv) <= 6)
1301 return;
1302
Ben Widawskyf9e61372016-09-20 16:54:33 +03001303 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1304 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1305 slice, subslice, instdone->sampler[slice][subslice]);
1306
1307 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1308 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1309 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001310}
1311
Chris Wilsonf6544492015-01-26 18:03:04 +02001312static int i915_hangcheck_info(struct seq_file *m, void *unused)
1313{
David Weinehall36cdd012016-08-22 13:59:31 +03001314 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001315 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001316 u64 acthd[I915_NUM_ENGINES];
1317 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001318 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001319 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001320
Chris Wilson8af29b02016-09-09 14:11:47 +01001321 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
1322 seq_printf(m, "Wedged\n");
1323 if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
1324 seq_printf(m, "Reset in progress\n");
1325 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
1326 seq_printf(m, "Waiter holding struct mutex\n");
1327 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
1328 seq_printf(m, "struct_mutex blocked for reset\n");
1329
Chris Wilsonf6544492015-01-26 18:03:04 +02001330 if (!i915.enable_hangcheck) {
1331 seq_printf(m, "Hangcheck disabled\n");
1332 return 0;
1333 }
1334
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001335 intel_runtime_pm_get(dev_priv);
1336
Akash Goel3b3f1652016-10-13 22:44:48 +05301337 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001338 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001339 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001340 }
1341
Akash Goel3b3f1652016-10-13 22:44:48 +05301342 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001343
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001344 intel_runtime_pm_put(dev_priv);
1345
Chris Wilsonf6544492015-01-26 18:03:04 +02001346 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1347 seq_printf(m, "Hangcheck active, fires in %dms\n",
1348 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1349 jiffies));
1350 } else
1351 seq_printf(m, "Hangcheck inactive\n");
1352
Akash Goel3b3f1652016-10-13 22:44:48 +05301353 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001354 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1355 struct rb_node *rb;
1356
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001357 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001358 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1359 engine->hangcheck.seqno,
1360 seqno[id],
1361 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001362 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1363 yesno(intel_engine_has_waiter(engine)),
1364 yesno(test_bit(engine->id,
1365 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilson33f53712016-10-04 21:11:32 +01001366 spin_lock(&b->lock);
1367 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1368 struct intel_wait *w = container_of(rb, typeof(*w), node);
1369
1370 seq_printf(m, "\t%s [%d] waiting for %x\n",
1371 w->tsk->comm, w->tsk->pid, w->seqno);
1372 }
1373 spin_unlock(&b->lock);
1374
Chris Wilsonf6544492015-01-26 18:03:04 +02001375 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001376 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001377 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001378 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1379 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001380
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001381 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001382 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001383
Ben Widawskyd6369512016-09-20 16:54:32 +03001384 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001385
Ben Widawskyd6369512016-09-20 16:54:32 +03001386 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001387
Ben Widawskyd6369512016-09-20 16:54:32 +03001388 i915_instdone_info(dev_priv, m,
1389 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001390 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001391 }
1392
1393 return 0;
1394}
1395
Ben Widawsky4d855292011-12-12 19:34:16 -08001396static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001397{
David Weinehall36cdd012016-08-22 13:59:31 +03001398 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1399 struct drm_device *dev = &dev_priv->drm;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001400 u32 rgvmodectl, rstdbyctl;
1401 u16 crstandvid;
1402 int ret;
1403
1404 ret = mutex_lock_interruptible(&dev->struct_mutex);
1405 if (ret)
1406 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001407 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001408
1409 rgvmodectl = I915_READ(MEMMODECTL);
1410 rstdbyctl = I915_READ(RSTDBYCTL);
1411 crstandvid = I915_READ16(CRSTANDVID);
1412
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001413 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001414 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001415
Jani Nikula742f4912015-09-03 11:16:09 +03001416 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001417 seq_printf(m, "Boost freq: %d\n",
1418 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1419 MEMMODE_BOOST_FREQ_SHIFT);
1420 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001421 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001422 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001423 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001424 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001425 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426 seq_printf(m, "Starting frequency: P%d\n",
1427 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001428 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001429 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001430 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1431 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1432 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1433 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001434 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001435 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001436 switch (rstdbyctl & RSX_STATUS_MASK) {
1437 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001438 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001439 break;
1440 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001442 break;
1443 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 break;
1446 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 break;
1449 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001457 break;
1458 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001459
1460 return 0;
1461}
1462
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001463static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001464{
David Weinehall36cdd012016-08-22 13:59:31 +03001465 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001466 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001467
1468 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001469 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001470 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001471 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001472 fw_domain->wake_count);
1473 }
1474 spin_unlock_irq(&dev_priv->uncore.lock);
1475
1476 return 0;
1477}
1478
Deepak S669ab5a2014-01-10 15:18:26 +05301479static int vlv_drpc_info(struct seq_file *m)
1480{
David Weinehall36cdd012016-08-22 13:59:31 +03001481 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001482 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301483
Imre Deakd46c0512014-04-14 20:24:27 +03001484 intel_runtime_pm_get(dev_priv);
1485
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001486 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301487 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1488 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1489
Imre Deakd46c0512014-04-14 20:24:27 +03001490 intel_runtime_pm_put(dev_priv);
1491
Deepak S669ab5a2014-01-10 15:18:26 +05301492 seq_printf(m, "Video Turbo Mode: %s\n",
1493 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1494 seq_printf(m, "Turbo enabled: %s\n",
1495 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1496 seq_printf(m, "HW control enabled: %s\n",
1497 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1498 seq_printf(m, "SW control enabled: %s\n",
1499 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1500 GEN6_RP_MEDIA_SW_MODE));
1501 seq_printf(m, "RC6 Enabled: %s\n",
1502 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1503 GEN6_RC_CTL_EI_MODE(1))));
1504 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001505 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301506 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001507 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301508
Imre Deak9cc19be2014-04-14 20:24:24 +03001509 seq_printf(m, "Render RC6 residency since boot: %u\n",
1510 I915_READ(VLV_GT_RENDER_RC6));
1511 seq_printf(m, "Media RC6 residency since boot: %u\n",
1512 I915_READ(VLV_GT_MEDIA_RC6));
1513
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001514 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301515}
1516
Ben Widawsky4d855292011-12-12 19:34:16 -08001517static int gen6_drpc_info(struct seq_file *m)
1518{
David Weinehall36cdd012016-08-22 13:59:31 +03001519 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1520 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001521 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301522 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001523 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001524 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001525
1526 ret = mutex_lock_interruptible(&dev->struct_mutex);
1527 if (ret)
1528 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001529 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001530
Chris Wilson907b28c2013-07-19 20:36:52 +01001531 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001532 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001533 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001534
1535 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001536 seq_puts(m, "RC information inaccurate because somebody "
1537 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001538 } else {
1539 /* NB: we cannot use forcewake, else we read the wrong values */
1540 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1541 udelay(10);
1542 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1543 }
1544
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001545 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001546 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001547
1548 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1549 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001550 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301551 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1552 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1553 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001555 mutex_lock(&dev_priv->rps.hw_lock);
1556 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1557 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001558
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001559 intel_runtime_pm_put(dev_priv);
1560
Ben Widawsky4d855292011-12-12 19:34:16 -08001561 seq_printf(m, "Video Turbo Mode: %s\n",
1562 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1563 seq_printf(m, "HW control enabled: %s\n",
1564 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1565 seq_printf(m, "SW control enabled: %s\n",
1566 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1567 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001568 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001569 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1570 seq_printf(m, "RC6 Enabled: %s\n",
1571 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001572 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301573 seq_printf(m, "Render Well Gating Enabled: %s\n",
1574 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1575 seq_printf(m, "Media Well Gating Enabled: %s\n",
1576 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1577 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001578 seq_printf(m, "Deep RC6 Enabled: %s\n",
1579 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1580 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1581 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001582 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001583 switch (gt_core_status & GEN6_RCn_MASK) {
1584 case GEN6_RC0:
1585 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001586 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001588 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001589 break;
1590 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001591 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001592 break;
1593 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001594 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001595 break;
1596 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001597 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001598 break;
1599 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001600 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001601 break;
1602 }
1603
1604 seq_printf(m, "Core Power Down: %s\n",
1605 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001606 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301607 seq_printf(m, "Render Power Well: %s\n",
1608 (gen9_powergate_status &
1609 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1610 seq_printf(m, "Media Power Well: %s\n",
1611 (gen9_powergate_status &
1612 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1613 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001614
1615 /* Not exactly sure what this is */
1616 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1617 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1618 seq_printf(m, "RC6 residency since boot: %u\n",
1619 I915_READ(GEN6_GT_GFX_RC6));
1620 seq_printf(m, "RC6+ residency since boot: %u\n",
1621 I915_READ(GEN6_GT_GFX_RC6p));
1622 seq_printf(m, "RC6++ residency since boot: %u\n",
1623 I915_READ(GEN6_GT_GFX_RC6pp));
1624
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001625 seq_printf(m, "RC6 voltage: %dmV\n",
1626 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1627 seq_printf(m, "RC6+ voltage: %dmV\n",
1628 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1629 seq_printf(m, "RC6++ voltage: %dmV\n",
1630 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301631 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001632}
1633
1634static int i915_drpc_info(struct seq_file *m, void *unused)
1635{
David Weinehall36cdd012016-08-22 13:59:31 +03001636 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001637
David Weinehall36cdd012016-08-22 13:59:31 +03001638 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301639 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001640 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001641 return gen6_drpc_info(m);
1642 else
1643 return ironlake_drpc_info(m);
1644}
1645
Daniel Vetter9a851782015-06-18 10:30:22 +02001646static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1647{
David Weinehall36cdd012016-08-22 13:59:31 +03001648 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001649
1650 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1651 dev_priv->fb_tracking.busy_bits);
1652
1653 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1654 dev_priv->fb_tracking.flip_bits);
1655
1656 return 0;
1657}
1658
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001659static int i915_fbc_status(struct seq_file *m, void *unused)
1660{
David Weinehall36cdd012016-08-22 13:59:31 +03001661 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001662
David Weinehall36cdd012016-08-22 13:59:31 +03001663 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001664 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001665 return 0;
1666 }
1667
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001668 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001669 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001670
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001671 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001672 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001673 else
1674 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001675 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001676
Nagaraju, Vathsalabc4ec7c2016-09-22 14:19:53 +05301677 if (intel_fbc_is_active(dev_priv) &&
1678 INTEL_GEN(dev_priv) >= 7)
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001679 seq_printf(m, "Compressing: %s\n",
1680 yesno(I915_READ(FBC_STATUS2) &
1681 FBC_COMPRESSION_MASK));
1682
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001683 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001684 intel_runtime_pm_put(dev_priv);
1685
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001686 return 0;
1687}
1688
Rodrigo Vivida46f932014-08-01 02:04:45 -07001689static int i915_fbc_fc_get(void *data, u64 *val)
1690{
David Weinehall36cdd012016-08-22 13:59:31 +03001691 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001692
David Weinehall36cdd012016-08-22 13:59:31 +03001693 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001694 return -ENODEV;
1695
Rodrigo Vivida46f932014-08-01 02:04:45 -07001696 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001697
1698 return 0;
1699}
1700
1701static int i915_fbc_fc_set(void *data, u64 val)
1702{
David Weinehall36cdd012016-08-22 13:59:31 +03001703 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001704 u32 reg;
1705
David Weinehall36cdd012016-08-22 13:59:31 +03001706 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001707 return -ENODEV;
1708
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001709 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001710
1711 reg = I915_READ(ILK_DPFC_CONTROL);
1712 dev_priv->fbc.false_color = val;
1713
1714 I915_WRITE(ILK_DPFC_CONTROL, val ?
1715 (reg | FBC_CTL_FALSE_COLOR) :
1716 (reg & ~FBC_CTL_FALSE_COLOR));
1717
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001718 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001719 return 0;
1720}
1721
1722DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1723 i915_fbc_fc_get, i915_fbc_fc_set,
1724 "%llu\n");
1725
Paulo Zanoni92d44622013-05-31 16:33:24 -03001726static int i915_ips_status(struct seq_file *m, void *unused)
1727{
David Weinehall36cdd012016-08-22 13:59:31 +03001728 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001729
David Weinehall36cdd012016-08-22 13:59:31 +03001730 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001731 seq_puts(m, "not supported\n");
1732 return 0;
1733 }
1734
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001735 intel_runtime_pm_get(dev_priv);
1736
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001737 seq_printf(m, "Enabled by kernel parameter: %s\n",
1738 yesno(i915.enable_ips));
1739
David Weinehall36cdd012016-08-22 13:59:31 +03001740 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001741 seq_puts(m, "Currently: unknown\n");
1742 } else {
1743 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1744 seq_puts(m, "Currently: enabled\n");
1745 else
1746 seq_puts(m, "Currently: disabled\n");
1747 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001748
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001749 intel_runtime_pm_put(dev_priv);
1750
Paulo Zanoni92d44622013-05-31 16:33:24 -03001751 return 0;
1752}
1753
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001754static int i915_sr_status(struct seq_file *m, void *unused)
1755{
David Weinehall36cdd012016-08-22 13:59:31 +03001756 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001757 bool sr_enabled = false;
1758
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001759 intel_runtime_pm_get(dev_priv);
1760
David Weinehall36cdd012016-08-22 13:59:31 +03001761 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001762 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001763 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1764 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001765 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001766 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001767 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001768 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001769 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001770 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001771 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001772
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001773 intel_runtime_pm_put(dev_priv);
1774
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001775 seq_printf(m, "self-refresh: %s\n",
1776 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001777
1778 return 0;
1779}
1780
Jesse Barnes7648fa92010-05-20 14:28:11 -07001781static int i915_emon_status(struct seq_file *m, void *unused)
1782{
David Weinehall36cdd012016-08-22 13:59:31 +03001783 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1784 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001785 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001786 int ret;
1787
David Weinehall36cdd012016-08-22 13:59:31 +03001788 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001789 return -ENODEV;
1790
Chris Wilsonde227ef2010-07-03 07:58:38 +01001791 ret = mutex_lock_interruptible(&dev->struct_mutex);
1792 if (ret)
1793 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001794
1795 temp = i915_mch_val(dev_priv);
1796 chipset = i915_chipset_val(dev_priv);
1797 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001798 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001799
1800 seq_printf(m, "GMCH temp: %ld\n", temp);
1801 seq_printf(m, "Chipset power: %ld\n", chipset);
1802 seq_printf(m, "GFX power: %ld\n", gfx);
1803 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1804
1805 return 0;
1806}
1807
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001808static int i915_ring_freq_table(struct seq_file *m, void *unused)
1809{
David Weinehall36cdd012016-08-22 13:59:31 +03001810 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001811 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001812 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301813 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001814
Carlos Santa26310342016-08-17 12:30:41 -07001815 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001816 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001817 return 0;
1818 }
1819
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001820 intel_runtime_pm_get(dev_priv);
1821
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001822 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001823 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001824 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001825
David Weinehall36cdd012016-08-22 13:59:31 +03001826 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301827 /* Convert GT frequency to 50 HZ units */
1828 min_gpu_freq =
1829 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1830 max_gpu_freq =
1831 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1832 } else {
1833 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1834 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1835 }
1836
Damien Lespiau267f0c92013-06-24 22:59:48 +01001837 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001838
Akash Goelf936ec32015-06-29 14:50:22 +05301839 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001840 ia_freq = gpu_freq;
1841 sandybridge_pcode_read(dev_priv,
1842 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1843 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001844 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301845 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001846 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001847 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001848 ((ia_freq >> 0) & 0xff) * 100,
1849 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001850 }
1851
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001852 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001853
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001854out:
1855 intel_runtime_pm_put(dev_priv);
1856 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001857}
1858
Chris Wilson44834a62010-08-19 16:09:23 +01001859static int i915_opregion(struct seq_file *m, void *unused)
1860{
David Weinehall36cdd012016-08-22 13:59:31 +03001861 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1862 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001863 struct intel_opregion *opregion = &dev_priv->opregion;
1864 int ret;
1865
1866 ret = mutex_lock_interruptible(&dev->struct_mutex);
1867 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001868 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001869
Jani Nikula2455a8e2015-12-14 12:50:53 +02001870 if (opregion->header)
1871 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001872
1873 mutex_unlock(&dev->struct_mutex);
1874
Daniel Vetter0d38f002012-04-21 22:49:10 +02001875out:
Chris Wilson44834a62010-08-19 16:09:23 +01001876 return 0;
1877}
1878
Jani Nikulaada8f952015-12-15 13:17:12 +02001879static int i915_vbt(struct seq_file *m, void *unused)
1880{
David Weinehall36cdd012016-08-22 13:59:31 +03001881 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001882
1883 if (opregion->vbt)
1884 seq_write(m, opregion->vbt, opregion->vbt_size);
1885
1886 return 0;
1887}
1888
Chris Wilson37811fc2010-08-25 22:45:57 +01001889static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1890{
David Weinehall36cdd012016-08-22 13:59:31 +03001891 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1892 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301893 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001894 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001895 int ret;
1896
1897 ret = mutex_lock_interruptible(&dev->struct_mutex);
1898 if (ret)
1899 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001900
Daniel Vetter06957262015-08-10 13:34:08 +02001901#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001902 if (dev_priv->fbdev) {
1903 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001904
Chris Wilson25bcce92016-07-02 15:36:00 +01001905 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1906 fbdev_fb->base.width,
1907 fbdev_fb->base.height,
1908 fbdev_fb->base.depth,
1909 fbdev_fb->base.bits_per_pixel,
1910 fbdev_fb->base.modifier[0],
1911 drm_framebuffer_read_refcount(&fbdev_fb->base));
1912 describe_obj(m, fbdev_fb->obj);
1913 seq_putc(m, '\n');
1914 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001915#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001916
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001917 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001918 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301919 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1920 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001921 continue;
1922
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001923 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 +01001924 fb->base.width,
1925 fb->base.height,
1926 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001927 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001928 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001929 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001930 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001931 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001932 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001933 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001934 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001935
1936 return 0;
1937}
1938
Chris Wilson7e37f882016-08-02 22:50:21 +01001939static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001940{
1941 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001942 ring->space, ring->head, ring->tail,
1943 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001944}
1945
Ben Widawskye76d3632011-03-19 18:14:29 -07001946static int i915_context_status(struct seq_file *m, void *unused)
1947{
David Weinehall36cdd012016-08-22 13:59:31 +03001948 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1949 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001950 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001951 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301952 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001953 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001954
Daniel Vetterf3d28872014-05-29 23:23:08 +02001955 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001956 if (ret)
1957 return ret;
1958
Ben Widawskya33afea2013-09-17 21:12:45 -07001959 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001960 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001961 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001962 struct task_struct *task;
1963
Chris Wilsonc84455b2016-08-15 10:49:08 +01001964 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001965 if (task) {
1966 seq_printf(m, "(%s [%d]) ",
1967 task->comm, task->pid);
1968 put_task_struct(task);
1969 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001970 } else if (IS_ERR(ctx->file_priv)) {
1971 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001972 } else {
1973 seq_puts(m, "(kernel) ");
1974 }
1975
Chris Wilsonbca44d82016-05-24 14:53:41 +01001976 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1977 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001978
Akash Goel3b3f1652016-10-13 22:44:48 +05301979 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001980 struct intel_context *ce = &ctx->engine[engine->id];
1981
1982 seq_printf(m, "%s: ", engine->name);
1983 seq_putc(m, ce->initialised ? 'I' : 'i');
1984 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001985 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001986 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001987 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001988 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001989 }
1990
Ben Widawskya33afea2013-09-17 21:12:45 -07001991 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001992 }
1993
Daniel Vetterf3d28872014-05-29 23:23:08 +02001994 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001995
1996 return 0;
1997}
1998
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001999static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002000 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002001 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002002{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002003 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002004 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002005 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002006
Chris Wilson7069b142016-04-28 09:56:52 +01002007 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2008
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002009 if (!vma) {
2010 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002011 return;
2012 }
2013
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002014 if (vma->flags & I915_VMA_GLOBAL_BIND)
2015 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002016 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002017
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002018 if (i915_gem_object_get_pages(vma->obj)) {
2019 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002020 return;
2021 }
2022
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002023 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2024 if (page) {
2025 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002026
2027 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002028 seq_printf(m,
2029 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2030 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002031 reg_state[j], reg_state[j + 1],
2032 reg_state[j + 2], reg_state[j + 3]);
2033 }
2034 kunmap_atomic(reg_state);
2035 }
2036
2037 seq_putc(m, '\n');
2038}
2039
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002040static int i915_dump_lrc(struct seq_file *m, void *unused)
2041{
David Weinehall36cdd012016-08-22 13:59:31 +03002042 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2043 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002044 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002045 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302046 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002047 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002048
2049 if (!i915.enable_execlists) {
2050 seq_printf(m, "Logical Ring Contexts are disabled\n");
2051 return 0;
2052 }
2053
2054 ret = mutex_lock_interruptible(&dev->struct_mutex);
2055 if (ret)
2056 return ret;
2057
Dave Gordone28e4042016-01-19 19:02:55 +00002058 list_for_each_entry(ctx, &dev_priv->context_list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302059 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002060 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002061
2062 mutex_unlock(&dev->struct_mutex);
2063
2064 return 0;
2065}
2066
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002067static const char *swizzle_string(unsigned swizzle)
2068{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002069 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002070 case I915_BIT_6_SWIZZLE_NONE:
2071 return "none";
2072 case I915_BIT_6_SWIZZLE_9:
2073 return "bit9";
2074 case I915_BIT_6_SWIZZLE_9_10:
2075 return "bit9/bit10";
2076 case I915_BIT_6_SWIZZLE_9_11:
2077 return "bit9/bit11";
2078 case I915_BIT_6_SWIZZLE_9_10_11:
2079 return "bit9/bit10/bit11";
2080 case I915_BIT_6_SWIZZLE_9_17:
2081 return "bit9/bit17";
2082 case I915_BIT_6_SWIZZLE_9_10_17:
2083 return "bit9/bit10/bit17";
2084 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002085 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002086 }
2087
2088 return "bug";
2089}
2090
2091static int i915_swizzle_info(struct seq_file *m, void *data)
2092{
David Weinehall36cdd012016-08-22 13:59:31 +03002093 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2094 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002095 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002096
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002097 ret = mutex_lock_interruptible(&dev->struct_mutex);
2098 if (ret)
2099 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002100 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002101
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002102 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2103 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2104 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2105 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2106
David Weinehall36cdd012016-08-22 13:59:31 +03002107 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002108 seq_printf(m, "DDC = 0x%08x\n",
2109 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002110 seq_printf(m, "DDC2 = 0x%08x\n",
2111 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002112 seq_printf(m, "C0DRB3 = 0x%04x\n",
2113 I915_READ16(C0DRB3));
2114 seq_printf(m, "C1DRB3 = 0x%04x\n",
2115 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002116 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002117 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2118 I915_READ(MAD_DIMM_C0));
2119 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2120 I915_READ(MAD_DIMM_C1));
2121 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2122 I915_READ(MAD_DIMM_C2));
2123 seq_printf(m, "TILECTL = 0x%08x\n",
2124 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002125 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002126 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2127 I915_READ(GAMTARBMODE));
2128 else
2129 seq_printf(m, "ARB_MODE = 0x%08x\n",
2130 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002131 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2132 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002133 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002134
2135 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2136 seq_puts(m, "L-shaped memory detected\n");
2137
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002138 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002139 mutex_unlock(&dev->struct_mutex);
2140
2141 return 0;
2142}
2143
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002144static int per_file_ctx(int id, void *ptr, void *data)
2145{
Chris Wilsone2efd132016-05-24 14:53:34 +01002146 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002147 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002148 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2149
2150 if (!ppgtt) {
2151 seq_printf(m, " no ppgtt for context %d\n",
2152 ctx->user_handle);
2153 return 0;
2154 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002155
Oscar Mateof83d6512014-05-22 14:13:38 +01002156 if (i915_gem_context_is_default(ctx))
2157 seq_puts(m, " default context:\n");
2158 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002159 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002160 ppgtt->debug_dump(ppgtt, m);
2161
2162 return 0;
2163}
2164
David Weinehall36cdd012016-08-22 13:59:31 +03002165static void gen8_ppgtt_info(struct seq_file *m,
2166 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002167{
Ben Widawsky77df6772013-11-02 21:07:30 -07002168 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302169 struct intel_engine_cs *engine;
2170 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002171 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002172
Ben Widawsky77df6772013-11-02 21:07:30 -07002173 if (!ppgtt)
2174 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002175
Akash Goel3b3f1652016-10-13 22:44:48 +05302176 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002177 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002178 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002179 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002180 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002181 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002182 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002183 }
2184 }
2185}
2186
David Weinehall36cdd012016-08-22 13:59:31 +03002187static void gen6_ppgtt_info(struct seq_file *m,
2188 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002189{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002190 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302191 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002192
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002193 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002194 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2195
Akash Goel3b3f1652016-10-13 22:44:48 +05302196 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002197 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002198 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002199 seq_printf(m, "GFX_MODE: 0x%08x\n",
2200 I915_READ(RING_MODE_GEN7(engine)));
2201 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2202 I915_READ(RING_PP_DIR_BASE(engine)));
2203 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2204 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2205 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2206 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002207 }
2208 if (dev_priv->mm.aliasing_ppgtt) {
2209 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2210
Damien Lespiau267f0c92013-06-24 22:59:48 +01002211 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002212 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002213
Ben Widawsky87d60b62013-12-06 14:11:29 -08002214 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002215 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002216
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002217 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002218}
2219
2220static int i915_ppgtt_info(struct seq_file *m, void *data)
2221{
David Weinehall36cdd012016-08-22 13:59:31 +03002222 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2223 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002224 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002225 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002226
Chris Wilson637ee292016-08-22 14:28:20 +01002227 mutex_lock(&dev->filelist_mutex);
2228 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002229 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002230 goto out_unlock;
2231
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002232 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002233
David Weinehall36cdd012016-08-22 13:59:31 +03002234 if (INTEL_GEN(dev_priv) >= 8)
2235 gen8_ppgtt_info(m, dev_priv);
2236 else if (INTEL_GEN(dev_priv) >= 6)
2237 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002238
Michel Thierryea91e402015-07-29 17:23:57 +01002239 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2240 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002241 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002242
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002243 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002244 if (!task) {
2245 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002246 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002247 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002248 seq_printf(m, "\nproc: %s\n", task->comm);
2249 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002250 idr_for_each(&file_priv->context_idr, per_file_ctx,
2251 (void *)(unsigned long)m);
2252 }
2253
Chris Wilson637ee292016-08-22 14:28:20 +01002254out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002255 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002256 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002257out_unlock:
2258 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002259 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002260}
2261
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002262static int count_irq_waiters(struct drm_i915_private *i915)
2263{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002264 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302265 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002266 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002267
Akash Goel3b3f1652016-10-13 22:44:48 +05302268 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002269 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002270
2271 return count;
2272}
2273
Chris Wilson7466c292016-08-15 09:49:33 +01002274static const char *rps_power_to_str(unsigned int power)
2275{
2276 static const char * const strings[] = {
2277 [LOW_POWER] = "low power",
2278 [BETWEEN] = "mixed",
2279 [HIGH_POWER] = "high power",
2280 };
2281
2282 if (power >= ARRAY_SIZE(strings) || !strings[power])
2283 return "unknown";
2284
2285 return strings[power];
2286}
2287
Chris Wilson1854d5c2015-04-07 16:20:32 +01002288static int i915_rps_boost_info(struct seq_file *m, void *data)
2289{
David Weinehall36cdd012016-08-22 13:59:31 +03002290 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2291 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002292 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002293
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002294 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002295 seq_printf(m, "GPU busy? %s [%x]\n",
2296 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002297 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002298 seq_printf(m, "Frequency requested %d\n",
2299 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2300 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002301 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2302 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2303 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2304 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002305 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2306 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2307 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2308 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002309
2310 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002311 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002312 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2313 struct drm_i915_file_private *file_priv = file->driver_priv;
2314 struct task_struct *task;
2315
2316 rcu_read_lock();
2317 task = pid_task(file->pid, PIDTYPE_PID);
2318 seq_printf(m, "%s [%d]: %d boosts%s\n",
2319 task ? task->comm : "<unknown>",
2320 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002321 file_priv->rps.boosts,
2322 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002323 rcu_read_unlock();
2324 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002325 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002326 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002327 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002328
Chris Wilson7466c292016-08-15 09:49:33 +01002329 if (INTEL_GEN(dev_priv) >= 6 &&
2330 dev_priv->rps.enabled &&
2331 dev_priv->gt.active_engines) {
2332 u32 rpup, rpupei;
2333 u32 rpdown, rpdownei;
2334
2335 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2336 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2337 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2338 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2339 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2340 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2341
2342 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2343 rps_power_to_str(dev_priv->rps.power));
2344 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2345 100 * rpup / rpupei,
2346 dev_priv->rps.up_threshold);
2347 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2348 100 * rpdown / rpdownei,
2349 dev_priv->rps.down_threshold);
2350 } else {
2351 seq_puts(m, "\nRPS Autotuning inactive\n");
2352 }
2353
Chris Wilson8d3afd72015-05-21 21:01:47 +01002354 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002355}
2356
Ben Widawsky63573eb2013-07-04 11:02:07 -07002357static int i915_llc(struct seq_file *m, void *data)
2358{
David Weinehall36cdd012016-08-22 13:59:31 +03002359 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002360 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002361
David Weinehall36cdd012016-08-22 13:59:31 +03002362 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002363 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2364 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002365
2366 return 0;
2367}
2368
Alex Daifdf5d352015-08-12 15:43:37 +01002369static int i915_guc_load_status_info(struct seq_file *m, void *data)
2370{
David Weinehall36cdd012016-08-22 13:59:31 +03002371 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002372 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2373 u32 tmp, i;
2374
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002375 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002376 return 0;
2377
2378 seq_printf(m, "GuC firmware status:\n");
2379 seq_printf(m, "\tpath: %s\n",
2380 guc_fw->guc_fw_path);
2381 seq_printf(m, "\tfetch: %s\n",
2382 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2383 seq_printf(m, "\tload: %s\n",
2384 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2385 seq_printf(m, "\tversion wanted: %d.%d\n",
2386 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2387 seq_printf(m, "\tversion found: %d.%d\n",
2388 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002389 seq_printf(m, "\theader: offset is %d; size = %d\n",
2390 guc_fw->header_offset, guc_fw->header_size);
2391 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2392 guc_fw->ucode_offset, guc_fw->ucode_size);
2393 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2394 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002395
2396 tmp = I915_READ(GUC_STATUS);
2397
2398 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2399 seq_printf(m, "\tBootrom status = 0x%x\n",
2400 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2401 seq_printf(m, "\tuKernel status = 0x%x\n",
2402 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2403 seq_printf(m, "\tMIA Core status = 0x%x\n",
2404 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2405 seq_puts(m, "\nScratch registers:\n");
2406 for (i = 0; i < 16; i++)
2407 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2408
2409 return 0;
2410}
2411
Dave Gordon8b417c22015-08-12 15:43:44 +01002412static void i915_guc_client_info(struct seq_file *m,
2413 struct drm_i915_private *dev_priv,
2414 struct i915_guc_client *client)
2415{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002416 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002417 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002418 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002419
2420 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2421 client->priority, client->ctx_index, client->proc_desc_offset);
2422 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2423 client->doorbell_id, client->doorbell_offset, client->cookie);
2424 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2425 client->wq_size, client->wq_offset, client->wq_tail);
2426
Dave Gordon551aaec2016-05-13 15:36:33 +01002427 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002428 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2429 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2430
Akash Goel3b3f1652016-10-13 22:44:48 +05302431 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002432 u64 submissions = client->submissions[id];
2433 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002434 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002435 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002436 }
2437 seq_printf(m, "\tTotal: %llu\n", tot);
2438}
2439
2440static int i915_guc_info(struct seq_file *m, void *data)
2441{
David Weinehall36cdd012016-08-22 13:59:31 +03002442 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2443 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002444 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002445 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002446 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002447 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002448 u64 total = 0;
2449
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002450 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002451 return 0;
2452
Alex Dai5a843302015-12-02 16:56:29 -08002453 if (mutex_lock_interruptible(&dev->struct_mutex))
2454 return 0;
2455
Dave Gordon8b417c22015-08-12 15:43:44 +01002456 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002457 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002458 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002459 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002460
2461 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002462
Dave Gordon9636f6d2016-06-13 17:57:28 +01002463 seq_printf(m, "Doorbell map:\n");
2464 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2465 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2466
Dave Gordon8b417c22015-08-12 15:43:44 +01002467 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2468 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2469 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2470 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2471 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2472
2473 seq_printf(m, "\nGuC submissions:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05302474 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002475 u64 submissions = guc.submissions[id];
2476 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002477 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002478 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002479 }
2480 seq_printf(m, "\t%s: %llu\n", "Total", total);
2481
2482 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2483 i915_guc_client_info(m, dev_priv, &client);
2484
2485 /* Add more as required ... */
2486
2487 return 0;
2488}
2489
Alex Dai4c7e77f2015-08-12 15:43:40 +01002490static int i915_guc_log_dump(struct seq_file *m, void *data)
2491{
David Weinehall36cdd012016-08-22 13:59:31 +03002492 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002493 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002494 int i = 0, pg;
2495
Chris Wilson8b797af2016-08-15 10:48:51 +01002496 if (!dev_priv->guc.log_vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002497 return 0;
2498
Chris Wilson8b797af2016-08-15 10:48:51 +01002499 obj = dev_priv->guc.log_vma->obj;
2500 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2501 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002502
2503 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2504 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2505 *(log + i), *(log + i + 1),
2506 *(log + i + 2), *(log + i + 3));
2507
2508 kunmap_atomic(log);
2509 }
2510
2511 seq_putc(m, '\n');
2512
2513 return 0;
2514}
2515
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002516static int i915_edp_psr_status(struct seq_file *m, void *data)
2517{
David Weinehall36cdd012016-08-22 13:59:31 +03002518 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002519 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002520 u32 stat[3];
2521 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002522 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002523
David Weinehall36cdd012016-08-22 13:59:31 +03002524 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002525 seq_puts(m, "PSR not supported\n");
2526 return 0;
2527 }
2528
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002529 intel_runtime_pm_get(dev_priv);
2530
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002531 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002532 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2533 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002534 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002535 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002536 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2537 dev_priv->psr.busy_frontbuffer_bits);
2538 seq_printf(m, "Re-enable work scheduled: %s\n",
2539 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002540
David Weinehall36cdd012016-08-22 13:59:31 +03002541 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002542 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002543 else {
2544 for_each_pipe(dev_priv, pipe) {
2545 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2546 VLV_EDP_PSR_CURR_STATE_MASK;
2547 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2548 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2549 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002550 }
2551 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002552
2553 seq_printf(m, "Main link in standby mode: %s\n",
2554 yesno(dev_priv->psr.link_standby));
2555
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002556 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002557
David Weinehall36cdd012016-08-22 13:59:31 +03002558 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002559 for_each_pipe(dev_priv, pipe) {
2560 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2561 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2562 seq_printf(m, " pipe %c", pipe_name(pipe));
2563 }
2564 seq_puts(m, "\n");
2565
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002566 /*
2567 * VLV/CHV PSR has no kind of performance counter
2568 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2569 */
David Weinehall36cdd012016-08-22 13:59:31 +03002570 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002571 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002572 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002573
2574 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2575 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002576 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002577
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002578 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002579 return 0;
2580}
2581
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002582static int i915_sink_crc(struct seq_file *m, void *data)
2583{
David Weinehall36cdd012016-08-22 13:59:31 +03002584 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2585 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002586 struct intel_connector *connector;
2587 struct intel_dp *intel_dp = NULL;
2588 int ret;
2589 u8 crc[6];
2590
2591 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002592 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002593 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002594
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002595 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002596 continue;
2597
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002598 crtc = connector->base.state->crtc;
2599 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002600 continue;
2601
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002602 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002603 continue;
2604
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002605 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002606
2607 ret = intel_dp_sink_crc(intel_dp, crc);
2608 if (ret)
2609 goto out;
2610
2611 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2612 crc[0], crc[1], crc[2],
2613 crc[3], crc[4], crc[5]);
2614 goto out;
2615 }
2616 ret = -ENODEV;
2617out:
2618 drm_modeset_unlock_all(dev);
2619 return ret;
2620}
2621
Jesse Barnesec013e72013-08-20 10:29:23 +01002622static int i915_energy_uJ(struct seq_file *m, void *data)
2623{
David Weinehall36cdd012016-08-22 13:59:31 +03002624 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002625 u64 power;
2626 u32 units;
2627
David Weinehall36cdd012016-08-22 13:59:31 +03002628 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002629 return -ENODEV;
2630
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002631 intel_runtime_pm_get(dev_priv);
2632
Jesse Barnesec013e72013-08-20 10:29:23 +01002633 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2634 power = (power & 0x1f00) >> 8;
2635 units = 1000000 / (1 << power); /* convert to uJ */
2636 power = I915_READ(MCH_SECP_NRG_STTS);
2637 power *= units;
2638
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002639 intel_runtime_pm_put(dev_priv);
2640
Jesse Barnesec013e72013-08-20 10:29:23 +01002641 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002642
2643 return 0;
2644}
2645
Damien Lespiau6455c872015-06-04 18:23:57 +01002646static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002647{
David Weinehall36cdd012016-08-22 13:59:31 +03002648 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002649 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002650
Chris Wilsona156e642016-04-03 14:14:21 +01002651 if (!HAS_RUNTIME_PM(dev_priv))
2652 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002653
Chris Wilson67d97da2016-07-04 08:08:31 +01002654 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002655 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002656 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002657#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002658 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002659 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002660#else
2661 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2662#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002663 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002664 pci_power_name(pdev->current_state),
2665 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002666
Jesse Barnesec013e72013-08-20 10:29:23 +01002667 return 0;
2668}
2669
Imre Deak1da51582013-11-25 17:15:35 +02002670static int i915_power_domain_info(struct seq_file *m, void *unused)
2671{
David Weinehall36cdd012016-08-22 13:59:31 +03002672 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002673 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2674 int i;
2675
2676 mutex_lock(&power_domains->lock);
2677
2678 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2679 for (i = 0; i < power_domains->power_well_count; i++) {
2680 struct i915_power_well *power_well;
2681 enum intel_display_power_domain power_domain;
2682
2683 power_well = &power_domains->power_wells[i];
2684 seq_printf(m, "%-25s %d\n", power_well->name,
2685 power_well->count);
2686
2687 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2688 power_domain++) {
2689 if (!(BIT(power_domain) & power_well->domains))
2690 continue;
2691
2692 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002693 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002694 power_domains->domain_use_count[power_domain]);
2695 }
2696 }
2697
2698 mutex_unlock(&power_domains->lock);
2699
2700 return 0;
2701}
2702
Damien Lespiaub7cec662015-10-27 14:47:01 +02002703static int i915_dmc_info(struct seq_file *m, void *unused)
2704{
David Weinehall36cdd012016-08-22 13:59:31 +03002705 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002706 struct intel_csr *csr;
2707
David Weinehall36cdd012016-08-22 13:59:31 +03002708 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002709 seq_puts(m, "not supported\n");
2710 return 0;
2711 }
2712
2713 csr = &dev_priv->csr;
2714
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002715 intel_runtime_pm_get(dev_priv);
2716
Damien Lespiaub7cec662015-10-27 14:47:01 +02002717 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2718 seq_printf(m, "path: %s\n", csr->fw_path);
2719
2720 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002721 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002722
2723 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2724 CSR_VERSION_MINOR(csr->version));
2725
David Weinehall36cdd012016-08-22 13:59:31 +03002726 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002727 seq_printf(m, "DC3 -> DC5 count: %d\n",
2728 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2729 seq_printf(m, "DC5 -> DC6 count: %d\n",
2730 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002731 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002732 seq_printf(m, "DC3 -> DC5 count: %d\n",
2733 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002734 }
2735
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002736out:
2737 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2738 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2739 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2740
Damien Lespiau83372062015-10-30 17:53:32 +02002741 intel_runtime_pm_put(dev_priv);
2742
Damien Lespiaub7cec662015-10-27 14:47:01 +02002743 return 0;
2744}
2745
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002746static void intel_seq_print_mode(struct seq_file *m, int tabs,
2747 struct drm_display_mode *mode)
2748{
2749 int i;
2750
2751 for (i = 0; i < tabs; i++)
2752 seq_putc(m, '\t');
2753
2754 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",
2755 mode->base.id, mode->name,
2756 mode->vrefresh, mode->clock,
2757 mode->hdisplay, mode->hsync_start,
2758 mode->hsync_end, mode->htotal,
2759 mode->vdisplay, mode->vsync_start,
2760 mode->vsync_end, mode->vtotal,
2761 mode->type, mode->flags);
2762}
2763
2764static void intel_encoder_info(struct seq_file *m,
2765 struct intel_crtc *intel_crtc,
2766 struct intel_encoder *intel_encoder)
2767{
David Weinehall36cdd012016-08-22 13:59:31 +03002768 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2769 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002770 struct drm_crtc *crtc = &intel_crtc->base;
2771 struct intel_connector *intel_connector;
2772 struct drm_encoder *encoder;
2773
2774 encoder = &intel_encoder->base;
2775 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002776 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002777 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2778 struct drm_connector *connector = &intel_connector->base;
2779 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2780 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002781 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002782 drm_get_connector_status_name(connector->status));
2783 if (connector->status == connector_status_connected) {
2784 struct drm_display_mode *mode = &crtc->mode;
2785 seq_printf(m, ", mode:\n");
2786 intel_seq_print_mode(m, 2, mode);
2787 } else {
2788 seq_putc(m, '\n');
2789 }
2790 }
2791}
2792
2793static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2794{
David Weinehall36cdd012016-08-22 13:59:31 +03002795 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2796 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002797 struct drm_crtc *crtc = &intel_crtc->base;
2798 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002799 struct drm_plane_state *plane_state = crtc->primary->state;
2800 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002801
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002802 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002803 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002804 fb->base.id, plane_state->src_x >> 16,
2805 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002806 else
2807 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002808 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2809 intel_encoder_info(m, intel_crtc, intel_encoder);
2810}
2811
2812static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2813{
2814 struct drm_display_mode *mode = panel->fixed_mode;
2815
2816 seq_printf(m, "\tfixed mode:\n");
2817 intel_seq_print_mode(m, 2, mode);
2818}
2819
2820static void intel_dp_info(struct seq_file *m,
2821 struct intel_connector *intel_connector)
2822{
2823 struct intel_encoder *intel_encoder = intel_connector->encoder;
2824 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2825
2826 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002827 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002828 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002829 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002830
2831 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2832 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002833}
2834
2835static void intel_hdmi_info(struct seq_file *m,
2836 struct intel_connector *intel_connector)
2837{
2838 struct intel_encoder *intel_encoder = intel_connector->encoder;
2839 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2840
Jani Nikula742f4912015-09-03 11:16:09 +03002841 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002842}
2843
2844static void intel_lvds_info(struct seq_file *m,
2845 struct intel_connector *intel_connector)
2846{
2847 intel_panel_info(m, &intel_connector->panel);
2848}
2849
2850static void intel_connector_info(struct seq_file *m,
2851 struct drm_connector *connector)
2852{
2853 struct intel_connector *intel_connector = to_intel_connector(connector);
2854 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002855 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002856
2857 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002858 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002859 drm_get_connector_status_name(connector->status));
2860 if (connector->status == connector_status_connected) {
2861 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2862 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2863 connector->display_info.width_mm,
2864 connector->display_info.height_mm);
2865 seq_printf(m, "\tsubpixel order: %s\n",
2866 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2867 seq_printf(m, "\tCEA rev: %d\n",
2868 connector->display_info.cea_rev);
2869 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002870
2871 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2872 return;
2873
2874 switch (connector->connector_type) {
2875 case DRM_MODE_CONNECTOR_DisplayPort:
2876 case DRM_MODE_CONNECTOR_eDP:
Dhinakaran Pandiyanbe754b12016-09-28 23:55:04 -07002877 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002878 break;
2879 case DRM_MODE_CONNECTOR_LVDS:
2880 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002881 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002882 break;
2883 case DRM_MODE_CONNECTOR_HDMIA:
2884 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2885 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2886 intel_hdmi_info(m, intel_connector);
2887 break;
2888 default:
2889 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002890 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002891
Jesse Barnesf103fc72014-02-20 12:39:57 -08002892 seq_printf(m, "\tmodes:\n");
2893 list_for_each_entry(mode, &connector->modes, head)
2894 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002895}
2896
David Weinehall36cdd012016-08-22 13:59:31 +03002897static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002898{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002899 u32 state;
2900
David Weinehall36cdd012016-08-22 13:59:31 +03002901 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002902 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002903 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002904 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002905
2906 return state;
2907}
2908
David Weinehall36cdd012016-08-22 13:59:31 +03002909static bool cursor_position(struct drm_i915_private *dev_priv,
2910 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002911{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002912 u32 pos;
2913
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002914 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002915
2916 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2917 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2918 *x = -*x;
2919
2920 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2921 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2922 *y = -*y;
2923
David Weinehall36cdd012016-08-22 13:59:31 +03002924 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002925}
2926
Robert Fekete3abc4e02015-10-27 16:58:32 +01002927static const char *plane_type(enum drm_plane_type type)
2928{
2929 switch (type) {
2930 case DRM_PLANE_TYPE_OVERLAY:
2931 return "OVL";
2932 case DRM_PLANE_TYPE_PRIMARY:
2933 return "PRI";
2934 case DRM_PLANE_TYPE_CURSOR:
2935 return "CUR";
2936 /*
2937 * Deliberately omitting default: to generate compiler warnings
2938 * when a new drm_plane_type gets added.
2939 */
2940 }
2941
2942 return "unknown";
2943}
2944
2945static const char *plane_rotation(unsigned int rotation)
2946{
2947 static char buf[48];
2948 /*
2949 * According to doc only one DRM_ROTATE_ is allowed but this
2950 * will print them all to visualize if the values are misused
2951 */
2952 snprintf(buf, sizeof(buf),
2953 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03002954 (rotation & DRM_ROTATE_0) ? "0 " : "",
2955 (rotation & DRM_ROTATE_90) ? "90 " : "",
2956 (rotation & DRM_ROTATE_180) ? "180 " : "",
2957 (rotation & DRM_ROTATE_270) ? "270 " : "",
2958 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
2959 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01002960 rotation);
2961
2962 return buf;
2963}
2964
2965static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2966{
David Weinehall36cdd012016-08-22 13:59:31 +03002967 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2968 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01002969 struct intel_plane *intel_plane;
2970
2971 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
2972 struct drm_plane_state *state;
2973 struct drm_plane *plane = &intel_plane->base;
Eric Engestromd3828142016-08-15 16:29:55 +01002974 char *format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01002975
2976 if (!plane->state) {
2977 seq_puts(m, "plane->state is NULL!\n");
2978 continue;
2979 }
2980
2981 state = plane->state;
2982
Eric Engestrom90844f02016-08-15 01:02:38 +01002983 if (state->fb) {
2984 format_name = drm_get_format_name(state->fb->pixel_format);
2985 } else {
2986 format_name = kstrdup("N/A", GFP_KERNEL);
2987 }
2988
Robert Fekete3abc4e02015-10-27 16:58:32 +01002989 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",
2990 plane->base.id,
2991 plane_type(intel_plane->base.type),
2992 state->crtc_x, state->crtc_y,
2993 state->crtc_w, state->crtc_h,
2994 (state->src_x >> 16),
2995 ((state->src_x & 0xffff) * 15625) >> 10,
2996 (state->src_y >> 16),
2997 ((state->src_y & 0xffff) * 15625) >> 10,
2998 (state->src_w >> 16),
2999 ((state->src_w & 0xffff) * 15625) >> 10,
3000 (state->src_h >> 16),
3001 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestrom90844f02016-08-15 01:02:38 +01003002 format_name,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003003 plane_rotation(state->rotation));
Eric Engestrom90844f02016-08-15 01:02:38 +01003004
3005 kfree(format_name);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003006 }
3007}
3008
3009static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3010{
3011 struct intel_crtc_state *pipe_config;
3012 int num_scalers = intel_crtc->num_scalers;
3013 int i;
3014
3015 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3016
3017 /* Not all platformas have a scaler */
3018 if (num_scalers) {
3019 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3020 num_scalers,
3021 pipe_config->scaler_state.scaler_users,
3022 pipe_config->scaler_state.scaler_id);
3023
3024 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3025 struct intel_scaler *sc =
3026 &pipe_config->scaler_state.scalers[i];
3027
3028 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3029 i, yesno(sc->in_use), sc->mode);
3030 }
3031 seq_puts(m, "\n");
3032 } else {
3033 seq_puts(m, "\tNo scalers available on this platform\n");
3034 }
3035}
3036
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003037static int i915_display_info(struct seq_file *m, void *unused)
3038{
David Weinehall36cdd012016-08-22 13:59:31 +03003039 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3040 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003041 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003042 struct drm_connector *connector;
3043
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003044 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003045 drm_modeset_lock_all(dev);
3046 seq_printf(m, "CRTC info\n");
3047 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003048 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003049 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003050 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003051 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003052
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003053 pipe_config = to_intel_crtc_state(crtc->base.state);
3054
Robert Fekete3abc4e02015-10-27 16:58:32 +01003055 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003056 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003057 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003058 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3059 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3060
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003061 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003062 intel_crtc_info(m, crtc);
3063
David Weinehall36cdd012016-08-22 13:59:31 +03003064 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003065 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 +03003066 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003067 x, y, crtc->base.cursor->state->crtc_w,
3068 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003069 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003070 intel_scaler_info(m, crtc);
3071 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003072 }
Daniel Vettercace8412014-05-22 17:56:31 +02003073
3074 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3075 yesno(!crtc->cpu_fifo_underrun_disabled),
3076 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003077 }
3078
3079 seq_printf(m, "\n");
3080 seq_printf(m, "Connector info\n");
3081 seq_printf(m, "--------------\n");
3082 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3083 intel_connector_info(m, connector);
3084 }
3085 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003086 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003087
3088 return 0;
3089}
3090
Chris Wilson1b365952016-10-04 21:11:31 +01003091static int i915_engine_info(struct seq_file *m, void *unused)
3092{
3093 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3094 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303095 enum intel_engine_id id;
Chris Wilson1b365952016-10-04 21:11:31 +01003096
Akash Goel3b3f1652016-10-13 22:44:48 +05303097 for_each_engine(engine, dev_priv, id) {
Chris Wilson1b365952016-10-04 21:11:31 +01003098 struct intel_breadcrumbs *b = &engine->breadcrumbs;
3099 struct drm_i915_gem_request *rq;
3100 struct rb_node *rb;
3101 u64 addr;
3102
3103 seq_printf(m, "%s\n", engine->name);
3104 seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [score %d]\n",
3105 intel_engine_get_seqno(engine),
3106 engine->last_submitted_seqno,
3107 engine->hangcheck.seqno,
3108 engine->hangcheck.score);
3109
3110 rcu_read_lock();
3111
3112 seq_printf(m, "\tRequests:\n");
3113
3114 rq = list_first_entry(&engine->request_list,
3115 struct drm_i915_gem_request, link);
3116 if (&rq->link != &engine->request_list)
3117 print_request(m, rq, "\t\tfirst ");
3118
3119 rq = list_last_entry(&engine->request_list,
3120 struct drm_i915_gem_request, link);
3121 if (&rq->link != &engine->request_list)
3122 print_request(m, rq, "\t\tlast ");
3123
3124 rq = i915_gem_find_active_request(engine);
3125 if (rq) {
3126 print_request(m, rq, "\t\tactive ");
3127 seq_printf(m,
3128 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
3129 rq->head, rq->postfix, rq->tail,
3130 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
3131 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
3132 }
3133
3134 seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
3135 I915_READ(RING_START(engine->mmio_base)),
3136 rq ? i915_ggtt_offset(rq->ring->vma) : 0);
3137 seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
3138 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
3139 rq ? rq->ring->head : 0);
3140 seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
3141 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
3142 rq ? rq->ring->tail : 0);
3143 seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
3144 I915_READ(RING_CTL(engine->mmio_base)),
3145 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
3146
3147 rcu_read_unlock();
3148
3149 addr = intel_engine_get_active_head(engine);
3150 seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
3151 upper_32_bits(addr), lower_32_bits(addr));
3152 addr = intel_engine_get_last_batch_head(engine);
3153 seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
3154 upper_32_bits(addr), lower_32_bits(addr));
3155
3156 if (i915.enable_execlists) {
3157 u32 ptr, read, write;
3158
3159 seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
3160 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
3161 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
3162
3163 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
3164 read = GEN8_CSB_READ_PTR(ptr);
3165 write = GEN8_CSB_WRITE_PTR(ptr);
3166 seq_printf(m, "\tExeclist CSB read %d, write %d\n",
3167 read, write);
3168 if (read >= GEN8_CSB_ENTRIES)
3169 read = 0;
3170 if (write >= GEN8_CSB_ENTRIES)
3171 write = 0;
3172 if (read > write)
3173 write += GEN8_CSB_ENTRIES;
3174 while (read < write) {
3175 unsigned int idx = ++read % GEN8_CSB_ENTRIES;
3176
3177 seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3178 idx,
3179 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3180 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3181 }
3182
3183 rcu_read_lock();
3184 rq = READ_ONCE(engine->execlist_port[0].request);
3185 if (rq)
3186 print_request(m, rq, "\t\tELSP[0] ");
3187 else
3188 seq_printf(m, "\t\tELSP[0] idle\n");
3189 rq = READ_ONCE(engine->execlist_port[1].request);
3190 if (rq)
3191 print_request(m, rq, "\t\tELSP[1] ");
3192 else
3193 seq_printf(m, "\t\tELSP[1] idle\n");
3194 rcu_read_unlock();
3195 } else if (INTEL_GEN(dev_priv) > 6) {
3196 seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
3197 I915_READ(RING_PP_DIR_BASE(engine)));
3198 seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
3199 I915_READ(RING_PP_DIR_BASE_READ(engine)));
3200 seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
3201 I915_READ(RING_PP_DIR_DCLV(engine)));
3202 }
3203
3204 spin_lock(&b->lock);
3205 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
3206 struct intel_wait *w = container_of(rb, typeof(*w), node);
3207
3208 seq_printf(m, "\t%s [%d] waiting for %x\n",
3209 w->tsk->comm, w->tsk->pid, w->seqno);
3210 }
3211 spin_unlock(&b->lock);
3212
3213 seq_puts(m, "\n");
3214 }
3215
3216 return 0;
3217}
3218
Ben Widawskye04934c2014-06-30 09:53:42 -07003219static int i915_semaphore_status(struct seq_file *m, void *unused)
3220{
David Weinehall36cdd012016-08-22 13:59:31 +03003221 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3222 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003223 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003224 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003225 enum intel_engine_id id;
3226 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003227
Chris Wilson39df9192016-07-20 13:31:57 +01003228 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003229 seq_puts(m, "Semaphores are disabled\n");
3230 return 0;
3231 }
3232
3233 ret = mutex_lock_interruptible(&dev->struct_mutex);
3234 if (ret)
3235 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003236 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003237
David Weinehall36cdd012016-08-22 13:59:31 +03003238 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003239 struct page *page;
3240 uint64_t *seqno;
3241
Chris Wilson51d545d2016-08-15 10:49:02 +01003242 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003243
3244 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303245 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003246 uint64_t offset;
3247
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003248 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003249
3250 seq_puts(m, " Last signal:");
3251 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003252 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003253 seq_printf(m, "0x%08llx (0x%02llx) ",
3254 seqno[offset], offset * 8);
3255 }
3256 seq_putc(m, '\n');
3257
3258 seq_puts(m, " Last wait: ");
3259 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003260 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003261 seq_printf(m, "0x%08llx (0x%02llx) ",
3262 seqno[offset], offset * 8);
3263 }
3264 seq_putc(m, '\n');
3265
3266 }
3267 kunmap_atomic(seqno);
3268 } else {
3269 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303270 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003271 for (j = 0; j < num_rings; j++)
3272 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003273 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003274 seq_putc(m, '\n');
3275 }
3276
3277 seq_puts(m, "\nSync seqno:\n");
Akash Goel3b3f1652016-10-13 22:44:48 +05303278 for_each_engine(engine, dev_priv, id) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003279 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003280 seq_printf(m, " 0x%08x ",
3281 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003282 seq_putc(m, '\n');
3283 }
3284 seq_putc(m, '\n');
3285
Paulo Zanoni03872062014-07-09 14:31:57 -03003286 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003287 mutex_unlock(&dev->struct_mutex);
3288 return 0;
3289}
3290
Daniel Vetter728e29d2014-06-25 22:01:53 +03003291static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3292{
David Weinehall36cdd012016-08-22 13:59:31 +03003293 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3294 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003295 int i;
3296
3297 drm_modeset_lock_all(dev);
3298 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3299 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3300
3301 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003302 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3303 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003304 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003305 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3306 seq_printf(m, " dpll_md: 0x%08x\n",
3307 pll->config.hw_state.dpll_md);
3308 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3309 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3310 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003311 }
3312 drm_modeset_unlock_all(dev);
3313
3314 return 0;
3315}
3316
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003317static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003318{
3319 int i;
3320 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003321 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003322 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3323 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003324 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003325 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003326
Arun Siluvery888b5992014-08-26 14:44:51 +01003327 ret = mutex_lock_interruptible(&dev->struct_mutex);
3328 if (ret)
3329 return ret;
3330
3331 intel_runtime_pm_get(dev_priv);
3332
Arun Siluvery33136b02016-01-21 21:43:47 +00003333 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303334 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003335 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003336 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003337 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003338 i915_reg_t addr;
3339 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003340 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003341
Arun Siluvery33136b02016-01-21 21:43:47 +00003342 addr = workarounds->reg[i].addr;
3343 mask = workarounds->reg[i].mask;
3344 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003345 read = I915_READ(addr);
3346 ok = (value & mask) == (read & mask);
3347 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 +02003348 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003349 }
3350
3351 intel_runtime_pm_put(dev_priv);
3352 mutex_unlock(&dev->struct_mutex);
3353
3354 return 0;
3355}
3356
Damien Lespiauc5511e42014-11-04 17:06:51 +00003357static int i915_ddb_info(struct seq_file *m, void *unused)
3358{
David Weinehall36cdd012016-08-22 13:59:31 +03003359 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3360 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003361 struct skl_ddb_allocation *ddb;
3362 struct skl_ddb_entry *entry;
3363 enum pipe pipe;
3364 int plane;
3365
David Weinehall36cdd012016-08-22 13:59:31 +03003366 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003367 return 0;
3368
Damien Lespiauc5511e42014-11-04 17:06:51 +00003369 drm_modeset_lock_all(dev);
3370
3371 ddb = &dev_priv->wm.skl_hw.ddb;
3372
3373 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3374
3375 for_each_pipe(dev_priv, pipe) {
3376 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3377
Damien Lespiaudd740782015-02-28 14:54:08 +00003378 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003379 entry = &ddb->plane[pipe][plane];
3380 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3381 entry->start, entry->end,
3382 skl_ddb_entry_size(entry));
3383 }
3384
Matt Roper4969d332015-09-24 15:53:10 -07003385 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003386 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3387 entry->end, skl_ddb_entry_size(entry));
3388 }
3389
3390 drm_modeset_unlock_all(dev);
3391
3392 return 0;
3393}
3394
Vandana Kannana54746e2015-03-03 20:53:10 +05303395static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003396 struct drm_device *dev,
3397 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303398{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003399 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303400 struct i915_drrs *drrs = &dev_priv->drrs;
3401 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003402 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303403
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003404 drm_for_each_connector(connector, dev) {
3405 if (connector->state->crtc != &intel_crtc->base)
3406 continue;
3407
3408 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303409 }
3410
3411 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3412 seq_puts(m, "\tVBT: DRRS_type: Static");
3413 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3414 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3415 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3416 seq_puts(m, "\tVBT: DRRS_type: None");
3417 else
3418 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3419
3420 seq_puts(m, "\n\n");
3421
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003422 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303423 struct intel_panel *panel;
3424
3425 mutex_lock(&drrs->mutex);
3426 /* DRRS Supported */
3427 seq_puts(m, "\tDRRS Supported: Yes\n");
3428
3429 /* disable_drrs() will make drrs->dp NULL */
3430 if (!drrs->dp) {
3431 seq_puts(m, "Idleness DRRS: Disabled");
3432 mutex_unlock(&drrs->mutex);
3433 return;
3434 }
3435
3436 panel = &drrs->dp->attached_connector->panel;
3437 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3438 drrs->busy_frontbuffer_bits);
3439
3440 seq_puts(m, "\n\t\t");
3441 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3442 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3443 vrefresh = panel->fixed_mode->vrefresh;
3444 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3445 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3446 vrefresh = panel->downclock_mode->vrefresh;
3447 } else {
3448 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3449 drrs->refresh_rate_type);
3450 mutex_unlock(&drrs->mutex);
3451 return;
3452 }
3453 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3454
3455 seq_puts(m, "\n\t\t");
3456 mutex_unlock(&drrs->mutex);
3457 } else {
3458 /* DRRS not supported. Print the VBT parameter*/
3459 seq_puts(m, "\tDRRS Supported : No");
3460 }
3461 seq_puts(m, "\n");
3462}
3463
3464static int i915_drrs_status(struct seq_file *m, void *unused)
3465{
David Weinehall36cdd012016-08-22 13:59:31 +03003466 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3467 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303468 struct intel_crtc *intel_crtc;
3469 int active_crtc_cnt = 0;
3470
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003471 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303472 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003473 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303474 active_crtc_cnt++;
3475 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3476
3477 drrs_status_per_crtc(m, dev, intel_crtc);
3478 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303479 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003480 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303481
3482 if (!active_crtc_cnt)
3483 seq_puts(m, "No active crtc found\n");
3484
3485 return 0;
3486}
3487
Damien Lespiau07144422013-10-15 18:55:40 +01003488struct pipe_crc_info {
3489 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003490 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003491 enum pipe pipe;
3492};
3493
Dave Airlie11bed952014-05-12 15:22:27 +10003494static int i915_dp_mst_info(struct seq_file *m, void *unused)
3495{
David Weinehall36cdd012016-08-22 13:59:31 +03003496 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3497 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003498 struct intel_encoder *intel_encoder;
3499 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003500 struct drm_connector *connector;
3501
Dave Airlie11bed952014-05-12 15:22:27 +10003502 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003503 drm_for_each_connector(connector, dev) {
3504 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003505 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003506
3507 intel_encoder = intel_attached_encoder(connector);
3508 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3509 continue;
3510
3511 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003512 if (!intel_dig_port->dp.can_mst)
3513 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003514
Jim Bride40ae80c2016-04-14 10:18:37 -07003515 seq_printf(m, "MST Source Port %c\n",
3516 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003517 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3518 }
3519 drm_modeset_unlock_all(dev);
3520 return 0;
3521}
3522
Damien Lespiau07144422013-10-15 18:55:40 +01003523static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003524{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003525 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003526 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003527 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3528
David Weinehall36cdd012016-08-22 13:59:31 +03003529 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003530 return -ENODEV;
3531
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003532 spin_lock_irq(&pipe_crc->lock);
3533
3534 if (pipe_crc->opened) {
3535 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003536 return -EBUSY; /* already open */
3537 }
3538
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003539 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003540 filep->private_data = inode->i_private;
3541
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003542 spin_unlock_irq(&pipe_crc->lock);
3543
Damien Lespiau07144422013-10-15 18:55:40 +01003544 return 0;
3545}
3546
3547static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3548{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003549 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003550 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003551 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3552
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003553 spin_lock_irq(&pipe_crc->lock);
3554 pipe_crc->opened = false;
3555 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003556
Damien Lespiau07144422013-10-15 18:55:40 +01003557 return 0;
3558}
3559
3560/* (6 fields, 8 chars each, space separated (5) + '\n') */
3561#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3562/* account for \'0' */
3563#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3564
3565static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3566{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003567 assert_spin_locked(&pipe_crc->lock);
3568 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3569 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003570}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003571
Damien Lespiau07144422013-10-15 18:55:40 +01003572static ssize_t
3573i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3574 loff_t *pos)
3575{
3576 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003577 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003578 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3579 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003580 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003581 ssize_t bytes_read;
3582
3583 /*
3584 * Don't allow user space to provide buffers not big enough to hold
3585 * a line of data.
3586 */
3587 if (count < PIPE_CRC_LINE_LEN)
3588 return -EINVAL;
3589
3590 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3591 return 0;
3592
3593 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003594 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003595 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003596 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003597
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003598 if (filep->f_flags & O_NONBLOCK) {
3599 spin_unlock_irq(&pipe_crc->lock);
3600 return -EAGAIN;
3601 }
3602
3603 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3604 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3605 if (ret) {
3606 spin_unlock_irq(&pipe_crc->lock);
3607 return ret;
3608 }
Damien Lespiau07144422013-10-15 18:55:40 +01003609 }
3610
3611 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003612 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003613
Damien Lespiau07144422013-10-15 18:55:40 +01003614 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003615 while (n_entries > 0) {
3616 struct intel_pipe_crc_entry *entry =
3617 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003618
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003619 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3620 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3621 break;
3622
3623 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3624 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3625
Damien Lespiau07144422013-10-15 18:55:40 +01003626 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3627 "%8u %8x %8x %8x %8x %8x\n",
3628 entry->frame, entry->crc[0],
3629 entry->crc[1], entry->crc[2],
3630 entry->crc[3], entry->crc[4]);
3631
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003632 spin_unlock_irq(&pipe_crc->lock);
3633
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003634 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003635 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003636
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003637 user_buf += PIPE_CRC_LINE_LEN;
3638 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003639
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003640 spin_lock_irq(&pipe_crc->lock);
3641 }
3642
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003643 spin_unlock_irq(&pipe_crc->lock);
3644
Damien Lespiau07144422013-10-15 18:55:40 +01003645 return bytes_read;
3646}
3647
3648static const struct file_operations i915_pipe_crc_fops = {
3649 .owner = THIS_MODULE,
3650 .open = i915_pipe_crc_open,
3651 .read = i915_pipe_crc_read,
3652 .release = i915_pipe_crc_release,
3653};
3654
3655static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3656 {
3657 .name = "i915_pipe_A_crc",
3658 .pipe = PIPE_A,
3659 },
3660 {
3661 .name = "i915_pipe_B_crc",
3662 .pipe = PIPE_B,
3663 },
3664 {
3665 .name = "i915_pipe_C_crc",
3666 .pipe = PIPE_C,
3667 },
3668};
3669
3670static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3671 enum pipe pipe)
3672{
David Weinehall36cdd012016-08-22 13:59:31 +03003673 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003674 struct dentry *ent;
3675 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3676
David Weinehall36cdd012016-08-22 13:59:31 +03003677 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003678 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3679 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003680 if (!ent)
3681 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003682
3683 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003684}
3685
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003686static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003687 "none",
3688 "plane1",
3689 "plane2",
3690 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003691 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003692 "TV",
3693 "DP-B",
3694 "DP-C",
3695 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003696 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003697};
3698
3699static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3700{
3701 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3702 return pipe_crc_sources[source];
3703}
3704
Damien Lespiaubd9db022013-10-15 18:55:36 +01003705static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003706{
David Weinehall36cdd012016-08-22 13:59:31 +03003707 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003708 int i;
3709
3710 for (i = 0; i < I915_MAX_PIPES; i++)
3711 seq_printf(m, "%c %s\n", pipe_name(i),
3712 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3713
3714 return 0;
3715}
3716
Damien Lespiaubd9db022013-10-15 18:55:36 +01003717static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003718{
David Weinehall36cdd012016-08-22 13:59:31 +03003719 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003720}
3721
Daniel Vetter46a19182013-11-01 10:50:20 +01003722static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003723 uint32_t *val)
3724{
Daniel Vetter46a19182013-11-01 10:50:20 +01003725 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3726 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3727
3728 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003729 case INTEL_PIPE_CRC_SOURCE_PIPE:
3730 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3731 break;
3732 case INTEL_PIPE_CRC_SOURCE_NONE:
3733 *val = 0;
3734 break;
3735 default:
3736 return -EINVAL;
3737 }
3738
3739 return 0;
3740}
3741
David Weinehall36cdd012016-08-22 13:59:31 +03003742static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3743 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003744 enum intel_pipe_crc_source *source)
3745{
David Weinehall36cdd012016-08-22 13:59:31 +03003746 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003747 struct intel_encoder *encoder;
3748 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003749 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003750 int ret = 0;
3751
3752 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3753
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003754 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003755 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003756 if (!encoder->base.crtc)
3757 continue;
3758
3759 crtc = to_intel_crtc(encoder->base.crtc);
3760
3761 if (crtc->pipe != pipe)
3762 continue;
3763
3764 switch (encoder->type) {
3765 case INTEL_OUTPUT_TVOUT:
3766 *source = INTEL_PIPE_CRC_SOURCE_TV;
3767 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003768 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003769 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003770 dig_port = enc_to_dig_port(&encoder->base);
3771 switch (dig_port->port) {
3772 case PORT_B:
3773 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3774 break;
3775 case PORT_C:
3776 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3777 break;
3778 case PORT_D:
3779 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3780 break;
3781 default:
3782 WARN(1, "nonexisting DP port %c\n",
3783 port_name(dig_port->port));
3784 break;
3785 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003786 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003787 default:
3788 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003789 }
3790 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003791 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003792
3793 return ret;
3794}
3795
David Weinehall36cdd012016-08-22 13:59:31 +03003796static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003797 enum pipe pipe,
3798 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003799 uint32_t *val)
3800{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003801 bool need_stable_symbols = false;
3802
Daniel Vetter46a19182013-11-01 10:50:20 +01003803 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003804 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003805 if (ret)
3806 return ret;
3807 }
3808
3809 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003810 case INTEL_PIPE_CRC_SOURCE_PIPE:
3811 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3812 break;
3813 case INTEL_PIPE_CRC_SOURCE_DP_B:
3814 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003815 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003816 break;
3817 case INTEL_PIPE_CRC_SOURCE_DP_C:
3818 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003819 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003820 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003821 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003822 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003823 return -EINVAL;
3824 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3825 need_stable_symbols = true;
3826 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003827 case INTEL_PIPE_CRC_SOURCE_NONE:
3828 *val = 0;
3829 break;
3830 default:
3831 return -EINVAL;
3832 }
3833
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003834 /*
3835 * When the pipe CRC tap point is after the transcoders we need
3836 * to tweak symbol-level features to produce a deterministic series of
3837 * symbols for a given frame. We need to reset those features only once
3838 * a frame (instead of every nth symbol):
3839 * - DC-balance: used to ensure a better clock recovery from the data
3840 * link (SDVO)
3841 * - DisplayPort scrambling: used for EMI reduction
3842 */
3843 if (need_stable_symbols) {
3844 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3845
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003846 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003847 switch (pipe) {
3848 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003849 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003850 break;
3851 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003852 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003853 break;
3854 case PIPE_C:
3855 tmp |= PIPE_C_SCRAMBLE_RESET;
3856 break;
3857 default:
3858 return -EINVAL;
3859 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003860 I915_WRITE(PORT_DFT2_G4X, tmp);
3861 }
3862
Daniel Vetter7ac01292013-10-18 16:37:06 +02003863 return 0;
3864}
3865
David Weinehall36cdd012016-08-22 13:59:31 +03003866static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003867 enum pipe pipe,
3868 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003869 uint32_t *val)
3870{
Daniel Vetter84093602013-11-01 10:50:21 +01003871 bool need_stable_symbols = false;
3872
Daniel Vetter46a19182013-11-01 10:50:20 +01003873 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003874 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003875 if (ret)
3876 return ret;
3877 }
3878
3879 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003880 case INTEL_PIPE_CRC_SOURCE_PIPE:
3881 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3882 break;
3883 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003884 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003885 return -EINVAL;
3886 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3887 break;
3888 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003889 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003890 return -EINVAL;
3891 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003892 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003893 break;
3894 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003895 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003896 return -EINVAL;
3897 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003898 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003899 break;
3900 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003901 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003902 return -EINVAL;
3903 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003904 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003905 break;
3906 case INTEL_PIPE_CRC_SOURCE_NONE:
3907 *val = 0;
3908 break;
3909 default:
3910 return -EINVAL;
3911 }
3912
Daniel Vetter84093602013-11-01 10:50:21 +01003913 /*
3914 * When the pipe CRC tap point is after the transcoders we need
3915 * to tweak symbol-level features to produce a deterministic series of
3916 * symbols for a given frame. We need to reset those features only once
3917 * a frame (instead of every nth symbol):
3918 * - DC-balance: used to ensure a better clock recovery from the data
3919 * link (SDVO)
3920 * - DisplayPort scrambling: used for EMI reduction
3921 */
3922 if (need_stable_symbols) {
3923 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3924
David Weinehall36cdd012016-08-22 13:59:31 +03003925 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003926
3927 I915_WRITE(PORT_DFT_I9XX,
3928 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3929
3930 if (pipe == PIPE_A)
3931 tmp |= PIPE_A_SCRAMBLE_RESET;
3932 else
3933 tmp |= PIPE_B_SCRAMBLE_RESET;
3934
3935 I915_WRITE(PORT_DFT2_G4X, tmp);
3936 }
3937
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003938 return 0;
3939}
3940
David Weinehall36cdd012016-08-22 13:59:31 +03003941static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003942 enum pipe pipe)
3943{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003944 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3945
Ville Syrjäläeb736672014-12-09 21:28:28 +02003946 switch (pipe) {
3947 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003948 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003949 break;
3950 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003951 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003952 break;
3953 case PIPE_C:
3954 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3955 break;
3956 default:
3957 return;
3958 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003959 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3960 tmp &= ~DC_BALANCE_RESET_VLV;
3961 I915_WRITE(PORT_DFT2_G4X, tmp);
3962
3963}
3964
David Weinehall36cdd012016-08-22 13:59:31 +03003965static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01003966 enum pipe pipe)
3967{
Daniel Vetter84093602013-11-01 10:50:21 +01003968 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3969
3970 if (pipe == PIPE_A)
3971 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3972 else
3973 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3974 I915_WRITE(PORT_DFT2_G4X, tmp);
3975
3976 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3977 I915_WRITE(PORT_DFT_I9XX,
3978 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3979 }
3980}
3981
Daniel Vetter46a19182013-11-01 10:50:20 +01003982static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003983 uint32_t *val)
3984{
Daniel Vetter46a19182013-11-01 10:50:20 +01003985 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3986 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3987
3988 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003989 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3990 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3991 break;
3992 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3993 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3994 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003995 case INTEL_PIPE_CRC_SOURCE_PIPE:
3996 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3997 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003998 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003999 *val = 0;
4000 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004001 default:
4002 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004003 }
4004
4005 return 0;
4006}
4007
David Weinehall36cdd012016-08-22 13:59:31 +03004008static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
4009 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004010{
David Weinehall36cdd012016-08-22 13:59:31 +03004011 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004012 struct intel_crtc *crtc =
4013 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004014 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004015 struct drm_atomic_state *state;
4016 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004017
4018 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004019 state = drm_atomic_state_alloc(dev);
4020 if (!state) {
4021 ret = -ENOMEM;
4022 goto out;
4023 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004024
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004025 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4026 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4027 if (IS_ERR(pipe_config)) {
4028 ret = PTR_ERR(pipe_config);
4029 goto out;
4030 }
4031
4032 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004033 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004034 pipe_config->pch_pfit.enabled != enable)
4035 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004036
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004037 ret = drm_atomic_commit(state);
4038out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004039 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004040 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4041 if (ret)
4042 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004043}
4044
David Weinehall36cdd012016-08-22 13:59:31 +03004045static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004046 enum pipe pipe,
4047 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004048 uint32_t *val)
4049{
Daniel Vetter46a19182013-11-01 10:50:20 +01004050 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4051 *source = INTEL_PIPE_CRC_SOURCE_PF;
4052
4053 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004054 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4055 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4056 break;
4057 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4058 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4059 break;
4060 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03004061 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4062 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004063
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004064 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4065 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004066 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004067 *val = 0;
4068 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004069 default:
4070 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004071 }
4072
4073 return 0;
4074}
4075
David Weinehall36cdd012016-08-22 13:59:31 +03004076static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
4077 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02004078 enum intel_pipe_crc_source source)
4079{
David Weinehall36cdd012016-08-22 13:59:31 +03004080 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004081 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03004082 struct intel_crtc *crtc =
4083 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02004084 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004085 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004086 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004087
Damien Lespiaucc3da172013-10-15 18:55:31 +01004088 if (pipe_crc->source == source)
4089 return 0;
4090
Damien Lespiauae676fc2013-10-15 18:55:32 +01004091 /* forbid changing the source without going back to 'none' */
4092 if (pipe_crc->source && source)
4093 return -EINVAL;
4094
Imre Deake1296492016-02-12 18:55:17 +02004095 power_domain = POWER_DOMAIN_PIPE(pipe);
4096 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004097 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4098 return -EIO;
4099 }
4100
David Weinehall36cdd012016-08-22 13:59:31 +03004101 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004102 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004103 else if (INTEL_GEN(dev_priv) < 5)
4104 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4105 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4106 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4107 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004108 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004109 else
David Weinehall36cdd012016-08-22 13:59:31 +03004110 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004111
4112 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004113 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004114
Damien Lespiau4b584362013-10-15 18:55:33 +01004115 /* none -> real source transition */
4116 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004117 struct intel_pipe_crc_entry *entries;
4118
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004119 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4120 pipe_name(pipe), pipe_crc_source_name(source));
4121
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004122 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4123 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004124 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004125 if (!entries) {
4126 ret = -ENOMEM;
4127 goto out;
4128 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004129
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004130 /*
4131 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4132 * enabled and disabled dynamically based on package C states,
4133 * user space can't make reliable use of the CRCs, so let's just
4134 * completely disable it.
4135 */
4136 hsw_disable_ips(crtc);
4137
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004138 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004139 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004140 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004141 pipe_crc->head = 0;
4142 pipe_crc->tail = 0;
4143 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004144 }
4145
Damien Lespiaucc3da172013-10-15 18:55:31 +01004146 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004147
Daniel Vetter926321d2013-10-16 13:30:34 +02004148 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4149 POSTING_READ(PIPE_CRC_CTL(pipe));
4150
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004151 /* real source -> none transition */
4152 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004153 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004154 struct intel_crtc *crtc =
4155 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004156
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004157 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4158 pipe_name(pipe));
4159
Daniel Vettera33d7102014-06-06 08:22:08 +02004160 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004161 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004162 intel_wait_for_vblank(dev, pipe);
4163 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004164
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004165 spin_lock_irq(&pipe_crc->lock);
4166 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004167 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004168 pipe_crc->head = 0;
4169 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004170 spin_unlock_irq(&pipe_crc->lock);
4171
4172 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004173
David Weinehall36cdd012016-08-22 13:59:31 +03004174 if (IS_G4X(dev_priv))
4175 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4176 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4177 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4178 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4179 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004180
4181 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004182 }
4183
Imre Deake1296492016-02-12 18:55:17 +02004184 ret = 0;
4185
4186out:
4187 intel_display_power_put(dev_priv, power_domain);
4188
4189 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004190}
4191
4192/*
4193 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004194 * command: wsp* object wsp+ name wsp+ source wsp*
4195 * object: 'pipe'
4196 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004197 * source: (none | plane1 | plane2 | pf)
4198 * wsp: (#0x20 | #0x9 | #0xA)+
4199 *
4200 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004201 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4202 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004203 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004204static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004205{
4206 int n_words = 0;
4207
4208 while (*buf) {
4209 char *end;
4210
4211 /* skip leading white space */
4212 buf = skip_spaces(buf);
4213 if (!*buf)
4214 break; /* end of buffer */
4215
4216 /* find end of word */
4217 for (end = buf; *end && !isspace(*end); end++)
4218 ;
4219
4220 if (n_words == max_words) {
4221 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4222 max_words);
4223 return -EINVAL; /* ran out of words[] before bytes */
4224 }
4225
4226 if (*end)
4227 *end++ = '\0';
4228 words[n_words++] = buf;
4229 buf = end;
4230 }
4231
4232 return n_words;
4233}
4234
Damien Lespiaub94dec82013-10-15 18:55:35 +01004235enum intel_pipe_crc_object {
4236 PIPE_CRC_OBJECT_PIPE,
4237};
4238
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004239static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004240 "pipe",
4241};
4242
4243static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004244display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004245{
4246 int i;
4247
4248 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4249 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004250 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004251 return 0;
4252 }
4253
4254 return -EINVAL;
4255}
4256
Damien Lespiaubd9db022013-10-15 18:55:36 +01004257static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004258{
4259 const char name = buf[0];
4260
4261 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4262 return -EINVAL;
4263
4264 *pipe = name - 'A';
4265
4266 return 0;
4267}
4268
4269static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004270display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004271{
4272 int i;
4273
4274 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4275 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004276 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004277 return 0;
4278 }
4279
4280 return -EINVAL;
4281}
4282
David Weinehall36cdd012016-08-22 13:59:31 +03004283static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4284 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004285{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004286#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004287 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004288 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004289 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004290 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004291 enum intel_pipe_crc_source source;
4292
Damien Lespiaubd9db022013-10-15 18:55:36 +01004293 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004294 if (n_words != N_WORDS) {
4295 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4296 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004297 return -EINVAL;
4298 }
4299
Damien Lespiaubd9db022013-10-15 18:55:36 +01004300 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004301 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004302 return -EINVAL;
4303 }
4304
Damien Lespiaubd9db022013-10-15 18:55:36 +01004305 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004306 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4307 return -EINVAL;
4308 }
4309
Damien Lespiaubd9db022013-10-15 18:55:36 +01004310 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004311 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004312 return -EINVAL;
4313 }
4314
David Weinehall36cdd012016-08-22 13:59:31 +03004315 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004316}
4317
Damien Lespiaubd9db022013-10-15 18:55:36 +01004318static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4319 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004320{
4321 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004322 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004323 char *tmpbuf;
4324 int ret;
4325
4326 if (len == 0)
4327 return 0;
4328
4329 if (len > PAGE_SIZE - 1) {
4330 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4331 PAGE_SIZE);
4332 return -E2BIG;
4333 }
4334
4335 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4336 if (!tmpbuf)
4337 return -ENOMEM;
4338
4339 if (copy_from_user(tmpbuf, ubuf, len)) {
4340 ret = -EFAULT;
4341 goto out;
4342 }
4343 tmpbuf[len] = '\0';
4344
David Weinehall36cdd012016-08-22 13:59:31 +03004345 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004346
4347out:
4348 kfree(tmpbuf);
4349 if (ret < 0)
4350 return ret;
4351
4352 *offp += len;
4353 return len;
4354}
4355
Damien Lespiaubd9db022013-10-15 18:55:36 +01004356static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004357 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004358 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004359 .read = seq_read,
4360 .llseek = seq_lseek,
4361 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004362 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004363};
4364
Todd Previteeb3394fa2015-04-18 00:04:19 -07004365static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004366 const char __user *ubuf,
4367 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004368{
4369 char *input_buffer;
4370 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004371 struct drm_device *dev;
4372 struct drm_connector *connector;
4373 struct list_head *connector_list;
4374 struct intel_dp *intel_dp;
4375 int val = 0;
4376
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304377 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004378
Todd Previteeb3394fa2015-04-18 00:04:19 -07004379 connector_list = &dev->mode_config.connector_list;
4380
4381 if (len == 0)
4382 return 0;
4383
4384 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4385 if (!input_buffer)
4386 return -ENOMEM;
4387
4388 if (copy_from_user(input_buffer, ubuf, len)) {
4389 status = -EFAULT;
4390 goto out;
4391 }
4392
4393 input_buffer[len] = '\0';
4394 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4395
4396 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004397 if (connector->connector_type !=
4398 DRM_MODE_CONNECTOR_DisplayPort)
4399 continue;
4400
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304401 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004402 connector->encoder != NULL) {
4403 intel_dp = enc_to_intel_dp(connector->encoder);
4404 status = kstrtoint(input_buffer, 10, &val);
4405 if (status < 0)
4406 goto out;
4407 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4408 /* To prevent erroneous activation of the compliance
4409 * testing code, only accept an actual value of 1 here
4410 */
4411 if (val == 1)
4412 intel_dp->compliance_test_active = 1;
4413 else
4414 intel_dp->compliance_test_active = 0;
4415 }
4416 }
4417out:
4418 kfree(input_buffer);
4419 if (status < 0)
4420 return status;
4421
4422 *offp += len;
4423 return len;
4424}
4425
4426static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4427{
4428 struct drm_device *dev = m->private;
4429 struct drm_connector *connector;
4430 struct list_head *connector_list = &dev->mode_config.connector_list;
4431 struct intel_dp *intel_dp;
4432
Todd Previteeb3394fa2015-04-18 00:04:19 -07004433 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004434 if (connector->connector_type !=
4435 DRM_MODE_CONNECTOR_DisplayPort)
4436 continue;
4437
4438 if (connector->status == connector_status_connected &&
4439 connector->encoder != NULL) {
4440 intel_dp = enc_to_intel_dp(connector->encoder);
4441 if (intel_dp->compliance_test_active)
4442 seq_puts(m, "1");
4443 else
4444 seq_puts(m, "0");
4445 } else
4446 seq_puts(m, "0");
4447 }
4448
4449 return 0;
4450}
4451
4452static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004453 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004454{
David Weinehall36cdd012016-08-22 13:59:31 +03004455 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004456
David Weinehall36cdd012016-08-22 13:59:31 +03004457 return single_open(file, i915_displayport_test_active_show,
4458 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004459}
4460
4461static const struct file_operations i915_displayport_test_active_fops = {
4462 .owner = THIS_MODULE,
4463 .open = i915_displayport_test_active_open,
4464 .read = seq_read,
4465 .llseek = seq_lseek,
4466 .release = single_release,
4467 .write = i915_displayport_test_active_write
4468};
4469
4470static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4471{
4472 struct drm_device *dev = m->private;
4473 struct drm_connector *connector;
4474 struct list_head *connector_list = &dev->mode_config.connector_list;
4475 struct intel_dp *intel_dp;
4476
Todd Previteeb3394fa2015-04-18 00:04:19 -07004477 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004478 if (connector->connector_type !=
4479 DRM_MODE_CONNECTOR_DisplayPort)
4480 continue;
4481
4482 if (connector->status == connector_status_connected &&
4483 connector->encoder != NULL) {
4484 intel_dp = enc_to_intel_dp(connector->encoder);
4485 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4486 } else
4487 seq_puts(m, "0");
4488 }
4489
4490 return 0;
4491}
4492static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004493 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004494{
David Weinehall36cdd012016-08-22 13:59:31 +03004495 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004496
David Weinehall36cdd012016-08-22 13:59:31 +03004497 return single_open(file, i915_displayport_test_data_show,
4498 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004499}
4500
4501static const struct file_operations i915_displayport_test_data_fops = {
4502 .owner = THIS_MODULE,
4503 .open = i915_displayport_test_data_open,
4504 .read = seq_read,
4505 .llseek = seq_lseek,
4506 .release = single_release
4507};
4508
4509static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4510{
4511 struct drm_device *dev = m->private;
4512 struct drm_connector *connector;
4513 struct list_head *connector_list = &dev->mode_config.connector_list;
4514 struct intel_dp *intel_dp;
4515
Todd Previteeb3394fa2015-04-18 00:04:19 -07004516 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004517 if (connector->connector_type !=
4518 DRM_MODE_CONNECTOR_DisplayPort)
4519 continue;
4520
4521 if (connector->status == connector_status_connected &&
4522 connector->encoder != NULL) {
4523 intel_dp = enc_to_intel_dp(connector->encoder);
4524 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4525 } else
4526 seq_puts(m, "0");
4527 }
4528
4529 return 0;
4530}
4531
4532static int i915_displayport_test_type_open(struct inode *inode,
4533 struct file *file)
4534{
David Weinehall36cdd012016-08-22 13:59:31 +03004535 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004536
David Weinehall36cdd012016-08-22 13:59:31 +03004537 return single_open(file, i915_displayport_test_type_show,
4538 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004539}
4540
4541static const struct file_operations i915_displayport_test_type_fops = {
4542 .owner = THIS_MODULE,
4543 .open = i915_displayport_test_type_open,
4544 .read = seq_read,
4545 .llseek = seq_lseek,
4546 .release = single_release
4547};
4548
Damien Lespiau97e94b22014-11-04 17:06:50 +00004549static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004550{
David Weinehall36cdd012016-08-22 13:59:31 +03004551 struct drm_i915_private *dev_priv = m->private;
4552 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004553 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004554 int num_levels;
4555
David Weinehall36cdd012016-08-22 13:59:31 +03004556 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004557 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004558 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004559 num_levels = 1;
4560 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004561 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004562
4563 drm_modeset_lock_all(dev);
4564
4565 for (level = 0; level < num_levels; level++) {
4566 unsigned int latency = wm[level];
4567
Damien Lespiau97e94b22014-11-04 17:06:50 +00004568 /*
4569 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004570 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004571 */
David Weinehall36cdd012016-08-22 13:59:31 +03004572 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4573 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004574 latency *= 10;
4575 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004576 latency *= 5;
4577
4578 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004579 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004580 }
4581
4582 drm_modeset_unlock_all(dev);
4583}
4584
4585static int pri_wm_latency_show(struct seq_file *m, void *data)
4586{
David Weinehall36cdd012016-08-22 13:59:31 +03004587 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004588 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004589
David Weinehall36cdd012016-08-22 13:59:31 +03004590 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004591 latencies = dev_priv->wm.skl_latency;
4592 else
David Weinehall36cdd012016-08-22 13:59:31 +03004593 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004594
4595 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004596
4597 return 0;
4598}
4599
4600static int spr_wm_latency_show(struct seq_file *m, void *data)
4601{
David Weinehall36cdd012016-08-22 13:59:31 +03004602 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004603 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004604
David Weinehall36cdd012016-08-22 13:59:31 +03004605 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004606 latencies = dev_priv->wm.skl_latency;
4607 else
David Weinehall36cdd012016-08-22 13:59:31 +03004608 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004609
4610 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004611
4612 return 0;
4613}
4614
4615static int cur_wm_latency_show(struct seq_file *m, void *data)
4616{
David Weinehall36cdd012016-08-22 13:59:31 +03004617 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004618 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004619
David Weinehall36cdd012016-08-22 13:59:31 +03004620 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004621 latencies = dev_priv->wm.skl_latency;
4622 else
David Weinehall36cdd012016-08-22 13:59:31 +03004623 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004624
4625 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004626
4627 return 0;
4628}
4629
4630static int pri_wm_latency_open(struct inode *inode, struct file *file)
4631{
David Weinehall36cdd012016-08-22 13:59:31 +03004632 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004633
David Weinehall36cdd012016-08-22 13:59:31 +03004634 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004635 return -ENODEV;
4636
David Weinehall36cdd012016-08-22 13:59:31 +03004637 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004638}
4639
4640static int spr_wm_latency_open(struct inode *inode, struct file *file)
4641{
David Weinehall36cdd012016-08-22 13:59:31 +03004642 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004643
David Weinehall36cdd012016-08-22 13:59:31 +03004644 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004645 return -ENODEV;
4646
David Weinehall36cdd012016-08-22 13:59:31 +03004647 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004648}
4649
4650static int cur_wm_latency_open(struct inode *inode, struct file *file)
4651{
David Weinehall36cdd012016-08-22 13:59:31 +03004652 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004653
David Weinehall36cdd012016-08-22 13:59:31 +03004654 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004655 return -ENODEV;
4656
David Weinehall36cdd012016-08-22 13:59:31 +03004657 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004658}
4659
4660static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004661 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004662{
4663 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004664 struct drm_i915_private *dev_priv = m->private;
4665 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004666 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004667 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004668 int level;
4669 int ret;
4670 char tmp[32];
4671
David Weinehall36cdd012016-08-22 13:59:31 +03004672 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004673 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004674 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004675 num_levels = 1;
4676 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004677 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004678
Ville Syrjälä369a1342014-01-22 14:36:08 +02004679 if (len >= sizeof(tmp))
4680 return -EINVAL;
4681
4682 if (copy_from_user(tmp, ubuf, len))
4683 return -EFAULT;
4684
4685 tmp[len] = '\0';
4686
Damien Lespiau97e94b22014-11-04 17:06:50 +00004687 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4688 &new[0], &new[1], &new[2], &new[3],
4689 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004690 if (ret != num_levels)
4691 return -EINVAL;
4692
4693 drm_modeset_lock_all(dev);
4694
4695 for (level = 0; level < num_levels; level++)
4696 wm[level] = new[level];
4697
4698 drm_modeset_unlock_all(dev);
4699
4700 return len;
4701}
4702
4703
4704static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4705 size_t len, loff_t *offp)
4706{
4707 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004708 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004709 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004710
David Weinehall36cdd012016-08-22 13:59:31 +03004711 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004712 latencies = dev_priv->wm.skl_latency;
4713 else
David Weinehall36cdd012016-08-22 13:59:31 +03004714 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004715
4716 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004717}
4718
4719static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4720 size_t len, loff_t *offp)
4721{
4722 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004723 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004724 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004725
David Weinehall36cdd012016-08-22 13:59:31 +03004726 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004727 latencies = dev_priv->wm.skl_latency;
4728 else
David Weinehall36cdd012016-08-22 13:59:31 +03004729 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004730
4731 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004732}
4733
4734static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4735 size_t len, loff_t *offp)
4736{
4737 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004738 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004739 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004740
David Weinehall36cdd012016-08-22 13:59:31 +03004741 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004742 latencies = dev_priv->wm.skl_latency;
4743 else
David Weinehall36cdd012016-08-22 13:59:31 +03004744 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004745
4746 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004747}
4748
4749static const struct file_operations i915_pri_wm_latency_fops = {
4750 .owner = THIS_MODULE,
4751 .open = pri_wm_latency_open,
4752 .read = seq_read,
4753 .llseek = seq_lseek,
4754 .release = single_release,
4755 .write = pri_wm_latency_write
4756};
4757
4758static const struct file_operations i915_spr_wm_latency_fops = {
4759 .owner = THIS_MODULE,
4760 .open = spr_wm_latency_open,
4761 .read = seq_read,
4762 .llseek = seq_lseek,
4763 .release = single_release,
4764 .write = spr_wm_latency_write
4765};
4766
4767static const struct file_operations i915_cur_wm_latency_fops = {
4768 .owner = THIS_MODULE,
4769 .open = cur_wm_latency_open,
4770 .read = seq_read,
4771 .llseek = seq_lseek,
4772 .release = single_release,
4773 .write = cur_wm_latency_write
4774};
4775
Kees Cook647416f2013-03-10 14:10:06 -07004776static int
4777i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004778{
David Weinehall36cdd012016-08-22 13:59:31 +03004779 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004780
Chris Wilsond98c52c2016-04-13 17:35:05 +01004781 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004782
Kees Cook647416f2013-03-10 14:10:06 -07004783 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004784}
4785
Kees Cook647416f2013-03-10 14:10:06 -07004786static int
4787i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004788{
David Weinehall36cdd012016-08-22 13:59:31 +03004789 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004790
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004791 /*
4792 * There is no safeguard against this debugfs entry colliding
4793 * with the hangcheck calling same i915_handle_error() in
4794 * parallel, causing an explosion. For now we assume that the
4795 * test harness is responsible enough not to inject gpu hangs
4796 * while it is writing to 'i915_wedged'
4797 */
4798
Chris Wilsond98c52c2016-04-13 17:35:05 +01004799 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004800 return -EAGAIN;
4801
Imre Deakd46c0512014-04-14 20:24:27 +03004802 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004803
Chris Wilsonc0336662016-05-06 15:40:21 +01004804 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004805 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004806
4807 intel_runtime_pm_put(dev_priv);
4808
Kees Cook647416f2013-03-10 14:10:06 -07004809 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004810}
4811
Kees Cook647416f2013-03-10 14:10:06 -07004812DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4813 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004814 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004815
Kees Cook647416f2013-03-10 14:10:06 -07004816static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004817i915_ring_missed_irq_get(void *data, u64 *val)
4818{
David Weinehall36cdd012016-08-22 13:59:31 +03004819 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004820
4821 *val = dev_priv->gpu_error.missed_irq_rings;
4822 return 0;
4823}
4824
4825static int
4826i915_ring_missed_irq_set(void *data, u64 val)
4827{
David Weinehall36cdd012016-08-22 13:59:31 +03004828 struct drm_i915_private *dev_priv = data;
4829 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004830 int ret;
4831
4832 /* Lock against concurrent debugfs callers */
4833 ret = mutex_lock_interruptible(&dev->struct_mutex);
4834 if (ret)
4835 return ret;
4836 dev_priv->gpu_error.missed_irq_rings = val;
4837 mutex_unlock(&dev->struct_mutex);
4838
4839 return 0;
4840}
4841
4842DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4843 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4844 "0x%08llx\n");
4845
4846static int
4847i915_ring_test_irq_get(void *data, u64 *val)
4848{
David Weinehall36cdd012016-08-22 13:59:31 +03004849 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004850
4851 *val = dev_priv->gpu_error.test_irq_rings;
4852
4853 return 0;
4854}
4855
4856static int
4857i915_ring_test_irq_set(void *data, u64 val)
4858{
David Weinehall36cdd012016-08-22 13:59:31 +03004859 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004860
Chris Wilson3a122c22016-06-17 14:35:05 +01004861 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004862 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004863 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004864
4865 return 0;
4866}
4867
4868DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4869 i915_ring_test_irq_get, i915_ring_test_irq_set,
4870 "0x%08llx\n");
4871
Chris Wilsondd624af2013-01-15 12:39:35 +00004872#define DROP_UNBOUND 0x1
4873#define DROP_BOUND 0x2
4874#define DROP_RETIRE 0x4
4875#define DROP_ACTIVE 0x8
4876#define DROP_ALL (DROP_UNBOUND | \
4877 DROP_BOUND | \
4878 DROP_RETIRE | \
4879 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004880static int
4881i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004882{
Kees Cook647416f2013-03-10 14:10:06 -07004883 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004884
Kees Cook647416f2013-03-10 14:10:06 -07004885 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004886}
4887
Kees Cook647416f2013-03-10 14:10:06 -07004888static int
4889i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004890{
David Weinehall36cdd012016-08-22 13:59:31 +03004891 struct drm_i915_private *dev_priv = data;
4892 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004893 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004894
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004895 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004896
4897 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4898 * on ioctls on -EAGAIN. */
4899 ret = mutex_lock_interruptible(&dev->struct_mutex);
4900 if (ret)
4901 return ret;
4902
4903 if (val & DROP_ACTIVE) {
Chris Wilson22dd3bb2016-09-09 14:11:50 +01004904 ret = i915_gem_wait_for_idle(dev_priv,
4905 I915_WAIT_INTERRUPTIBLE |
4906 I915_WAIT_LOCKED);
Chris Wilsondd624af2013-01-15 12:39:35 +00004907 if (ret)
4908 goto unlock;
4909 }
4910
4911 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004912 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004913
Chris Wilson21ab4e72014-09-09 11:16:08 +01004914 if (val & DROP_BOUND)
4915 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004916
Chris Wilson21ab4e72014-09-09 11:16:08 +01004917 if (val & DROP_UNBOUND)
4918 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004919
4920unlock:
4921 mutex_unlock(&dev->struct_mutex);
4922
Kees Cook647416f2013-03-10 14:10:06 -07004923 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004924}
4925
Kees Cook647416f2013-03-10 14:10:06 -07004926DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4927 i915_drop_caches_get, i915_drop_caches_set,
4928 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004929
Kees Cook647416f2013-03-10 14:10:06 -07004930static int
4931i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004932{
David Weinehall36cdd012016-08-22 13:59:31 +03004933 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004934
David Weinehall36cdd012016-08-22 13:59:31 +03004935 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004936 return -ENODEV;
4937
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004938 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004939 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004940}
4941
Kees Cook647416f2013-03-10 14:10:06 -07004942static int
4943i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004944{
David Weinehall36cdd012016-08-22 13:59:31 +03004945 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304946 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004947 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004948
David Weinehall36cdd012016-08-22 13:59:31 +03004949 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004950 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004951
Kees Cook647416f2013-03-10 14:10:06 -07004952 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004953
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004954 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004955 if (ret)
4956 return ret;
4957
Jesse Barnes358733e2011-07-27 11:53:01 -07004958 /*
4959 * Turbo will still be enabled, but won't go above the set value.
4960 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304961 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004962
Akash Goelbc4d91f2015-02-26 16:09:47 +05304963 hw_max = dev_priv->rps.max_freq;
4964 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004965
Ben Widawskyb39fb292014-03-19 18:31:11 -07004966 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004967 mutex_unlock(&dev_priv->rps.hw_lock);
4968 return -EINVAL;
4969 }
4970
Ben Widawskyb39fb292014-03-19 18:31:11 -07004971 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004972
Chris Wilsondc979972016-05-10 14:10:04 +01004973 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004974
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004975 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004976
Kees Cook647416f2013-03-10 14:10:06 -07004977 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004978}
4979
Kees Cook647416f2013-03-10 14:10:06 -07004980DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4981 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004982 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004983
Kees Cook647416f2013-03-10 14:10:06 -07004984static int
4985i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004986{
David Weinehall36cdd012016-08-22 13:59:31 +03004987 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004988
Chris Wilson62e1baa2016-07-13 09:10:36 +01004989 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004990 return -ENODEV;
4991
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004992 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004993 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004994}
4995
Kees Cook647416f2013-03-10 14:10:06 -07004996static int
4997i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004998{
David Weinehall36cdd012016-08-22 13:59:31 +03004999 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305000 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005001 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005002
Chris Wilson62e1baa2016-07-13 09:10:36 +01005003 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005004 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005005
Kees Cook647416f2013-03-10 14:10:06 -07005006 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005007
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005008 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005009 if (ret)
5010 return ret;
5011
Jesse Barnes1523c312012-05-25 12:34:54 -07005012 /*
5013 * Turbo will still be enabled, but won't go below the set value.
5014 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305015 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005016
Akash Goelbc4d91f2015-02-26 16:09:47 +05305017 hw_max = dev_priv->rps.max_freq;
5018 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005019
David Weinehall36cdd012016-08-22 13:59:31 +03005020 if (val < hw_min ||
5021 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005022 mutex_unlock(&dev_priv->rps.hw_lock);
5023 return -EINVAL;
5024 }
5025
Ben Widawskyb39fb292014-03-19 18:31:11 -07005026 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005027
Chris Wilsondc979972016-05-10 14:10:04 +01005028 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005029
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005030 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005031
Kees Cook647416f2013-03-10 14:10:06 -07005032 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005033}
5034
Kees Cook647416f2013-03-10 14:10:06 -07005035DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5036 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005037 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005038
Kees Cook647416f2013-03-10 14:10:06 -07005039static int
5040i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005041{
David Weinehall36cdd012016-08-22 13:59:31 +03005042 struct drm_i915_private *dev_priv = data;
5043 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005044 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005045 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005046
David Weinehall36cdd012016-08-22 13:59:31 +03005047 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005048 return -ENODEV;
5049
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005050 ret = mutex_lock_interruptible(&dev->struct_mutex);
5051 if (ret)
5052 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005053 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005054
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005055 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005056
5057 intel_runtime_pm_put(dev_priv);
David Weinehall36cdd012016-08-22 13:59:31 +03005058 mutex_unlock(&dev->struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005059
Kees Cook647416f2013-03-10 14:10:06 -07005060 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005061
Kees Cook647416f2013-03-10 14:10:06 -07005062 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005063}
5064
Kees Cook647416f2013-03-10 14:10:06 -07005065static int
5066i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005067{
David Weinehall36cdd012016-08-22 13:59:31 +03005068 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005069 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005070
David Weinehall36cdd012016-08-22 13:59:31 +03005071 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02005072 return -ENODEV;
5073
Kees Cook647416f2013-03-10 14:10:06 -07005074 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005075 return -EINVAL;
5076
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005077 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005078 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005079
5080 /* Update the cache sharing policy here as well */
5081 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5082 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5083 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5084 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5085
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005086 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005087 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005088}
5089
Kees Cook647416f2013-03-10 14:10:06 -07005090DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5091 i915_cache_sharing_get, i915_cache_sharing_set,
5092 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005093
David Weinehall36cdd012016-08-22 13:59:31 +03005094static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005095 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005096{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005097 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005098 int ss;
5099 u32 sig1[ss_max], sig2[ss_max];
5100
5101 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5102 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5103 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5104 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5105
5106 for (ss = 0; ss < ss_max; ss++) {
5107 unsigned int eu_cnt;
5108
5109 if (sig1[ss] & CHV_SS_PG_ENABLE)
5110 /* skip disabled subslice */
5111 continue;
5112
Imre Deakf08a0c92016-08-31 19:13:04 +03005113 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03005114 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07005115 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5116 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5117 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5118 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005119 sseu->eu_total += eu_cnt;
5120 sseu->eu_per_subslice = max_t(unsigned int,
5121 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005122 }
Jeff McGee5d395252015-04-03 18:13:17 -07005123}
5124
David Weinehall36cdd012016-08-22 13:59:31 +03005125static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005126 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005127{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005128 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005129 int s, ss;
5130 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5131
Jeff McGee1c046bc2015-04-03 18:13:18 -07005132 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005133 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005134 s_max = 1;
5135 ss_max = 3;
5136 }
5137
5138 for (s = 0; s < s_max; s++) {
5139 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5140 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5141 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5142 }
5143
Jeff McGee5d395252015-04-03 18:13:17 -07005144 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5145 GEN9_PGCTL_SSA_EU19_ACK |
5146 GEN9_PGCTL_SSA_EU210_ACK |
5147 GEN9_PGCTL_SSA_EU311_ACK;
5148 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5149 GEN9_PGCTL_SSB_EU19_ACK |
5150 GEN9_PGCTL_SSB_EU210_ACK |
5151 GEN9_PGCTL_SSB_EU311_ACK;
5152
5153 for (s = 0; s < s_max; s++) {
5154 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5155 /* skip disabled slice */
5156 continue;
5157
Imre Deakf08a0c92016-08-31 19:13:04 +03005158 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005159
David Weinehall36cdd012016-08-22 13:59:31 +03005160 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005161 sseu->subslice_mask =
5162 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005163
Jeff McGee5d395252015-04-03 18:13:17 -07005164 for (ss = 0; ss < ss_max; ss++) {
5165 unsigned int eu_cnt;
5166
Imre Deak57ec1712016-08-31 19:13:05 +03005167 if (IS_BROXTON(dev_priv)) {
5168 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5169 /* skip disabled subslice */
5170 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005171
Imre Deak57ec1712016-08-31 19:13:05 +03005172 sseu->subslice_mask |= BIT(ss);
5173 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005174
Jeff McGee5d395252015-04-03 18:13:17 -07005175 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5176 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005177 sseu->eu_total += eu_cnt;
5178 sseu->eu_per_subslice = max_t(unsigned int,
5179 sseu->eu_per_subslice,
5180 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005181 }
5182 }
5183}
5184
David Weinehall36cdd012016-08-22 13:59:31 +03005185static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005186 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005187{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005188 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005189 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005190
Imre Deakf08a0c92016-08-31 19:13:04 +03005191 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005192
Imre Deakf08a0c92016-08-31 19:13:04 +03005193 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005194 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005195 sseu->eu_per_subslice =
5196 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005197 sseu->eu_total = sseu->eu_per_subslice *
5198 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005199
5200 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005201 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005202 u8 subslice_7eu =
5203 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005204
Imre Deak915490d2016-08-31 19:13:01 +03005205 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005206 }
5207 }
5208}
5209
Imre Deak615d8902016-08-31 19:13:03 +03005210static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5211 const struct sseu_dev_info *sseu)
5212{
5213 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5214 const char *type = is_available_info ? "Available" : "Enabled";
5215
Imre Deakc67ba532016-08-31 19:13:06 +03005216 seq_printf(m, " %s Slice Mask: %04x\n", type,
5217 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005218 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005219 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005220 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005221 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005222 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5223 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005224 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005225 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005226 seq_printf(m, " %s EU Total: %u\n", type,
5227 sseu->eu_total);
5228 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5229 sseu->eu_per_subslice);
5230
5231 if (!is_available_info)
5232 return;
5233
5234 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5235 if (HAS_POOLED_EU(dev_priv))
5236 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5237
5238 seq_printf(m, " Has Slice Power Gating: %s\n",
5239 yesno(sseu->has_slice_pg));
5240 seq_printf(m, " Has Subslice Power Gating: %s\n",
5241 yesno(sseu->has_subslice_pg));
5242 seq_printf(m, " Has EU Power Gating: %s\n",
5243 yesno(sseu->has_eu_pg));
5244}
5245
Jeff McGee38732182015-02-13 10:27:54 -06005246static int i915_sseu_status(struct seq_file *m, void *unused)
5247{
David Weinehall36cdd012016-08-22 13:59:31 +03005248 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005249 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005250
David Weinehall36cdd012016-08-22 13:59:31 +03005251 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005252 return -ENODEV;
5253
5254 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005255 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005256
Jeff McGee7f992ab2015-02-13 10:27:55 -06005257 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005258 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005259
5260 intel_runtime_pm_get(dev_priv);
5261
David Weinehall36cdd012016-08-22 13:59:31 +03005262 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005263 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005264 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005265 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005266 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005267 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005268 }
David Weinehall238010e2016-08-01 17:33:27 +03005269
5270 intel_runtime_pm_put(dev_priv);
5271
Imre Deak615d8902016-08-31 19:13:03 +03005272 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005273
Jeff McGee38732182015-02-13 10:27:54 -06005274 return 0;
5275}
5276
Ben Widawsky6d794d42011-04-25 11:25:56 -07005277static int i915_forcewake_open(struct inode *inode, struct file *file)
5278{
David Weinehall36cdd012016-08-22 13:59:31 +03005279 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005280
David Weinehall36cdd012016-08-22 13:59:31 +03005281 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005282 return 0;
5283
Chris Wilson6daccb02015-01-16 11:34:35 +02005284 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005285 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005286
5287 return 0;
5288}
5289
Ben Widawskyc43b5632012-04-16 14:07:40 -07005290static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005291{
David Weinehall36cdd012016-08-22 13:59:31 +03005292 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005293
David Weinehall36cdd012016-08-22 13:59:31 +03005294 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005295 return 0;
5296
Mika Kuoppala59bad942015-01-16 11:34:40 +02005297 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005298 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005299
5300 return 0;
5301}
5302
5303static const struct file_operations i915_forcewake_fops = {
5304 .owner = THIS_MODULE,
5305 .open = i915_forcewake_open,
5306 .release = i915_forcewake_release,
5307};
5308
5309static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5310{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005311 struct dentry *ent;
5312
5313 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005314 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005315 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005316 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005317 if (!ent)
5318 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005319
Ben Widawsky8eb57292011-05-11 15:10:58 -07005320 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005321}
5322
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005323static int i915_debugfs_create(struct dentry *root,
5324 struct drm_minor *minor,
5325 const char *name,
5326 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005327{
Jesse Barnes358733e2011-07-27 11:53:01 -07005328 struct dentry *ent;
5329
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005330 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005331 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005332 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005333 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005334 if (!ent)
5335 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005336
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005337 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005338}
5339
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005340static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005341 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005342 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005343 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005344 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005345 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005346 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005347 {"i915_gem_request", i915_gem_request_info, 0},
5348 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005349 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005350 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005351 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5352 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5353 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005354 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005355 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005356 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005357 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005358 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305359 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005360 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005361 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005362 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005363 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005364 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005365 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005366 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005367 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005368 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005369 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005370 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005371 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005372 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005373 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005374 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005375 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005376 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005377 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005378 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005379 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005380 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005381 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005382 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005383 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01005384 {"i915_engine_info", i915_engine_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005385 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005386 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005387 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005388 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005389 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005390 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305391 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005392 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005393};
Ben Gamari27c202a2009-07-01 22:26:52 -04005394#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005395
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005396static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005397 const char *name;
5398 const struct file_operations *fops;
5399} i915_debugfs_files[] = {
5400 {"i915_wedged", &i915_wedged_fops},
5401 {"i915_max_freq", &i915_max_freq_fops},
5402 {"i915_min_freq", &i915_min_freq_fops},
5403 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005404 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5405 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005406 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005407#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02005408 {"i915_error_state", &i915_error_state_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01005409#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02005410 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005411 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005412 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5413 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5414 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005415 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005416 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5417 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5418 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005419};
5420
David Weinehall36cdd012016-08-22 13:59:31 +03005421void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005422{
Daniel Vetterb3783602013-11-14 11:30:42 +01005423 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005424
Damien Lespiau055e3932014-08-18 13:49:10 +01005425 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005426 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005427
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005428 pipe_crc->opened = false;
5429 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005430 init_waitqueue_head(&pipe_crc->wq);
5431 }
5432}
5433
Chris Wilson1dac8912016-06-24 14:00:17 +01005434int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005435{
Chris Wilson91c8a322016-07-05 10:40:23 +01005436 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005437 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005438
Ben Widawsky6d794d42011-04-25 11:25:56 -07005439 ret = i915_forcewake_create(minor->debugfs_root, minor);
5440 if (ret)
5441 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005442
Damien Lespiau07144422013-10-15 18:55:40 +01005443 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5444 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5445 if (ret)
5446 return ret;
5447 }
5448
Daniel Vetter34b96742013-07-04 20:49:44 +02005449 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5450 ret = i915_debugfs_create(minor->debugfs_root, minor,
5451 i915_debugfs_files[i].name,
5452 i915_debugfs_files[i].fops);
5453 if (ret)
5454 return ret;
5455 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005456
Ben Gamari27c202a2009-07-01 22:26:52 -04005457 return drm_debugfs_create_files(i915_debugfs_list,
5458 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005459 minor->debugfs_root, minor);
5460}
5461
Chris Wilson1dac8912016-06-24 14:00:17 +01005462void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005463{
Chris Wilson91c8a322016-07-05 10:40:23 +01005464 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005465 int i;
5466
Ben Gamari27c202a2009-07-01 22:26:52 -04005467 drm_debugfs_remove_files(i915_debugfs_list,
5468 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005469
David Weinehall36cdd012016-08-22 13:59:31 +03005470 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005471 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005472
Daniel Vettere309a992013-10-16 22:55:51 +02005473 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005474 struct drm_info_list *info_list =
5475 (struct drm_info_list *)&i915_pipe_crc_data[i];
5476
5477 drm_debugfs_remove_files(info_list, 1, minor);
5478 }
5479
Daniel Vetter34b96742013-07-04 20:49:44 +02005480 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5481 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005482 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005483
5484 drm_debugfs_remove_files(info_list, 1, minor);
5485 }
Ben Gamari20172632009-02-17 20:08:50 -05005486}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005487
5488struct dpcd_block {
5489 /* DPCD dump start address. */
5490 unsigned int offset;
5491 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5492 unsigned int end;
5493 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5494 size_t size;
5495 /* Only valid for eDP. */
5496 bool edp;
5497};
5498
5499static const struct dpcd_block i915_dpcd_debug[] = {
5500 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5501 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5502 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5503 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5504 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5505 { .offset = DP_SET_POWER },
5506 { .offset = DP_EDP_DPCD_REV },
5507 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5508 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5509 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5510};
5511
5512static int i915_dpcd_show(struct seq_file *m, void *data)
5513{
5514 struct drm_connector *connector = m->private;
5515 struct intel_dp *intel_dp =
5516 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5517 uint8_t buf[16];
5518 ssize_t err;
5519 int i;
5520
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005521 if (connector->status != connector_status_connected)
5522 return -ENODEV;
5523
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005524 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5525 const struct dpcd_block *b = &i915_dpcd_debug[i];
5526 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5527
5528 if (b->edp &&
5529 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5530 continue;
5531
5532 /* low tech for now */
5533 if (WARN_ON(size > sizeof(buf)))
5534 continue;
5535
5536 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5537 if (err <= 0) {
5538 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5539 size, b->offset, err);
5540 continue;
5541 }
5542
5543 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005544 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005545
5546 return 0;
5547}
5548
5549static int i915_dpcd_open(struct inode *inode, struct file *file)
5550{
5551 return single_open(file, i915_dpcd_show, inode->i_private);
5552}
5553
5554static const struct file_operations i915_dpcd_fops = {
5555 .owner = THIS_MODULE,
5556 .open = i915_dpcd_open,
5557 .read = seq_read,
5558 .llseek = seq_lseek,
5559 .release = single_release,
5560};
5561
David Weinehallecbd6782016-08-23 12:23:56 +03005562static int i915_panel_show(struct seq_file *m, void *data)
5563{
5564 struct drm_connector *connector = m->private;
5565 struct intel_dp *intel_dp =
5566 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5567
5568 if (connector->status != connector_status_connected)
5569 return -ENODEV;
5570
5571 seq_printf(m, "Panel power up delay: %d\n",
5572 intel_dp->panel_power_up_delay);
5573 seq_printf(m, "Panel power down delay: %d\n",
5574 intel_dp->panel_power_down_delay);
5575 seq_printf(m, "Backlight on delay: %d\n",
5576 intel_dp->backlight_on_delay);
5577 seq_printf(m, "Backlight off delay: %d\n",
5578 intel_dp->backlight_off_delay);
5579
5580 return 0;
5581}
5582
5583static int i915_panel_open(struct inode *inode, struct file *file)
5584{
5585 return single_open(file, i915_panel_show, inode->i_private);
5586}
5587
5588static const struct file_operations i915_panel_fops = {
5589 .owner = THIS_MODULE,
5590 .open = i915_panel_open,
5591 .read = seq_read,
5592 .llseek = seq_lseek,
5593 .release = single_release,
5594};
5595
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005596/**
5597 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5598 * @connector: pointer to a registered drm_connector
5599 *
5600 * Cleanup will be done by drm_connector_unregister() through a call to
5601 * drm_debugfs_connector_remove().
5602 *
5603 * Returns 0 on success, negative error codes on error.
5604 */
5605int i915_debugfs_connector_add(struct drm_connector *connector)
5606{
5607 struct dentry *root = connector->debugfs_entry;
5608
5609 /* The connector must have been registered beforehands. */
5610 if (!root)
5611 return -ENODEV;
5612
5613 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5614 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005615 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5616 connector, &i915_dpcd_fops);
5617
5618 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5619 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5620 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005621
5622 return 0;
5623}