blob: eb8753fb107ae6b31c9909feb65477a9993e6978 [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
Damien Lespiau497666d2013-10-15 18:55:39 +010043/* As the drm_debugfs_init() routines are called before dev->dev_private is
44 * allocated we need to hook into the minor for release. */
45static int
46drm_add_fake_info_node(struct drm_minor *minor,
47 struct dentry *ent,
48 const void *key)
49{
50 struct drm_info_node *node;
51
52 node = kmalloc(sizeof(*node), GFP_KERNEL);
53 if (node == NULL) {
54 debugfs_remove(ent);
55 return -ENOMEM;
56 }
57
58 node->minor = minor;
59 node->dent = ent;
60 node->info_ent = (void *) key;
61
62 mutex_lock(&minor->debugfs_lock);
63 list_add(&node->list, &minor->debugfs_list);
64 mutex_unlock(&minor->debugfs_lock);
65
66 return 0;
67}
68
Chris Wilson70d39fe2010-08-25 16:03:34 +010069static int i915_capabilities(struct seq_file *m, void *data)
70{
Damien Lespiau9f25d002014-05-13 15:30:28 +010071 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010072 struct drm_device *dev = node->minor->dev;
73 const struct intel_device_info *info = INTEL_INFO(dev);
74
75 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030076 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010077#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
78#define SEP_SEMICOLON ;
79 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
80#undef PRINT_FLAG
81#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010082
83 return 0;
84}
Ben Gamari433e12f2009-02-17 20:08:51 -050085
Imre Deaka7363de2016-05-12 16:18:52 +030086static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000087{
Chris Wilson573adb32016-08-04 16:32:39 +010088 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000089}
90
Imre Deaka7363de2016-05-12 16:18:52 +030091static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010092{
93 return obj->pin_display ? 'p' : ' ';
94}
95
Imre Deaka7363de2016-05-12 16:18:52 +030096static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000097{
Chris Wilson3e510a82016-08-05 10:14:23 +010098 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -040099 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100100 case I915_TILING_NONE: return ' ';
101 case I915_TILING_X: return 'X';
102 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400103 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000104}
105
Imre Deaka7363de2016-05-12 16:18:52 +0300106static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700107{
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100108 return i915_gem_obj_to_ggtt(obj) ? 'g' : ' ';
109}
110
Imre Deaka7363de2016-05-12 16:18:52 +0300111static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100112{
113 return obj->mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700114}
115
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100116static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
117{
118 u64 size = 0;
119 struct i915_vma *vma;
120
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000121 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100122 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100123 size += vma->node.size;
124 }
125
126 return size;
127}
128
Chris Wilson37811fc2010-08-25 22:45:57 +0100129static void
130describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
131{
Chris Wilsonb4716182015-04-27 13:41:17 +0100132 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000133 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700134 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100135 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800136 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000137 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800138
Chris Wilson188c1ab2016-04-03 14:14:20 +0100139 lockdep_assert_held(&obj->base.dev->struct_mutex);
140
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100141 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100142 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100143 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100144 get_pin_flag(obj),
145 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700146 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100147 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800148 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100149 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100150 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000151 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100152 seq_printf(m, "%x ",
Chris Wilsond72d9082016-08-04 07:52:31 +0100153 i915_gem_active_get_seqno(&obj->last_read[id],
154 &obj->base.dev->struct_mutex));
Chris Wilsonb4716182015-04-27 13:41:17 +0100155 seq_printf(m, "] %x %x%s%s%s",
Chris Wilsond72d9082016-08-04 07:52:31 +0100156 i915_gem_active_get_seqno(&obj->last_write,
157 &obj->base.dev->struct_mutex),
158 i915_gem_active_get_seqno(&obj->last_fence,
159 &obj->base.dev->struct_mutex),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100160 i915_cache_level_str(to_i915(obj->base.dev), 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 Wilson37811fc2010-08-25 22:45:57 +0100172 if (obj->fence_reg != I915_FENCE_REG_NONE)
173 seq_printf(m, " (fence: %d)", obj->fence_reg);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000174 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100175 if (!drm_mm_node_allocated(&vma->node))
176 continue;
177
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100178 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100179 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100180 vma->node.start, vma->node.size);
Chris Wilson3272db52016-08-04 16:32:32 +0100181 if (i915_vma_is_ggtt(vma))
Chris Wilson596c5922016-02-26 11:03:20 +0000182 seq_printf(m, ", type: %u", vma->ggtt_view.type);
183 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700184 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000185 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100186 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100187 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000188 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100189 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000190 *t++ = 'p';
191 if (obj->fault_mappable)
192 *t++ = 'f';
193 *t = '\0';
194 seq_printf(m, " (%s mappable)", s);
195 }
Chris Wilson27c01aa2016-08-04 07:52:30 +0100196
Chris Wilsond72d9082016-08-04 07:52:31 +0100197 engine = i915_gem_active_get_engine(&obj->last_write,
198 &obj->base.dev->struct_mutex);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100199 if (engine)
200 seq_printf(m, " (%s)", engine->name);
201
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100202 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
203 if (frontbuffer_bits)
204 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100205}
206
Chris Wilson6d2b88852013-08-07 18:30:54 +0100207static int obj_rank_by_stolen(void *priv,
208 struct list_head *A, struct list_head *B)
209{
210 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200211 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100212 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200213 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100214
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200215 if (a->stolen->start < b->stolen->start)
216 return -1;
217 if (a->stolen->start > b->stolen->start)
218 return 1;
219 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100220}
221
222static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
223{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100224 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100225 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100226 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100227 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300228 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100229 LIST_HEAD(stolen);
230 int count, ret;
231
232 ret = mutex_lock_interruptible(&dev->struct_mutex);
233 if (ret)
234 return ret;
235
236 total_obj_size = total_gtt_size = count = 0;
237 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
238 if (obj->stolen == NULL)
239 continue;
240
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200241 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100242
243 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100244 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245 count++;
246 }
247 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
248 if (obj->stolen == NULL)
249 continue;
250
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200251 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252
253 total_obj_size += obj->base.size;
254 count++;
255 }
256 list_sort(NULL, &stolen, obj_rank_by_stolen);
257 seq_puts(m, "Stolen:\n");
258 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200259 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100260 seq_puts(m, " ");
261 describe_obj(m, obj);
262 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200263 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100264 }
265 mutex_unlock(&dev->struct_mutex);
266
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300267 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100268 count, total_obj_size, total_gtt_size);
269 return 0;
270}
271
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100272struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000273 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300274 unsigned long count;
275 u64 total, unbound;
276 u64 global, shared;
277 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100278};
279
280static int per_file_stats(int id, void *ptr, void *data)
281{
282 struct drm_i915_gem_object *obj = ptr;
283 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000284 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100285
286 stats->count++;
287 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100288 if (!obj->bind_count)
289 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000290 if (obj->base.name || obj->base.dma_buf)
291 stats->shared += obj->base.size;
292
Chris Wilson894eeec2016-08-04 07:52:20 +0100293 list_for_each_entry(vma, &obj->vma_list, obj_link) {
294 if (!drm_mm_node_allocated(&vma->node))
295 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000296
Chris Wilson3272db52016-08-04 16:32:32 +0100297 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100298 stats->global += vma->node.size;
299 } else {
300 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000301
Chris Wilson2bfa9962016-08-04 07:52:25 +0100302 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000303 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000304 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100305
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100306 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100307 stats->active += vma->node.size;
308 else
309 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100310 }
311
312 return 0;
313}
314
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100315#define print_file_stats(m, name, stats) do { \
316 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300317 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 +0100318 name, \
319 stats.count, \
320 stats.total, \
321 stats.active, \
322 stats.inactive, \
323 stats.global, \
324 stats.shared, \
325 stats.unbound); \
326} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800327
328static void print_batch_pool_stats(struct seq_file *m,
329 struct drm_i915_private *dev_priv)
330{
331 struct drm_i915_gem_object *obj;
332 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000333 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000334 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800335
336 memset(&stats, 0, sizeof(stats));
337
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000338 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000339 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100340 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000341 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100342 batch_pool_link)
343 per_file_stats(0, obj, &stats);
344 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100345 }
Brad Volkin493018d2014-12-11 12:13:08 -0800346
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100347 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800348}
349
Chris Wilson15da9562016-05-24 14:53:43 +0100350static int per_file_ctx_stats(int id, void *ptr, void *data)
351{
352 struct i915_gem_context *ctx = ptr;
353 int n;
354
355 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
356 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100357 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100358 if (ctx->engine[n].ring)
359 per_file_stats(0, ctx->engine[n].ring->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100360 }
361
362 return 0;
363}
364
365static void print_context_stats(struct seq_file *m,
366 struct drm_i915_private *dev_priv)
367{
368 struct file_stats stats;
369 struct drm_file *file;
370
371 memset(&stats, 0, sizeof(stats));
372
Chris Wilson91c8a322016-07-05 10:40:23 +0100373 mutex_lock(&dev_priv->drm.struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100374 if (dev_priv->kernel_context)
375 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
376
Chris Wilson91c8a322016-07-05 10:40:23 +0100377 list_for_each_entry(file, &dev_priv->drm.filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100378 struct drm_i915_file_private *fpriv = file->driver_priv;
379 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
380 }
Chris Wilson91c8a322016-07-05 10:40:23 +0100381 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100382
383 print_file_stats(m, "[k]contexts", stats);
384}
385
Ben Widawskyca191b12013-07-31 17:00:14 -0700386static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100387{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100388 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100389 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300390 struct drm_i915_private *dev_priv = to_i915(dev);
391 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100392 u32 count, mapped_count, purgeable_count, dpy_count;
393 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000394 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100395 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100396 int ret;
397
398 ret = mutex_lock_interruptible(&dev->struct_mutex);
399 if (ret)
400 return ret;
401
Chris Wilson6299f992010-11-24 12:23:44 +0000402 seq_printf(m, "%u objects, %zu bytes\n",
403 dev_priv->mm.object_count,
404 dev_priv->mm.object_memory);
405
Chris Wilsonb7abb712012-08-20 11:33:30 +0200406 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700407 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100408 size += obj->base.size;
409 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200410
Chris Wilsonb7abb712012-08-20 11:33:30 +0200411 if (obj->madv == I915_MADV_DONTNEED) {
412 purgeable_size += obj->base.size;
413 ++purgeable_count;
414 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100415
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100416 if (obj->mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100417 mapped_count++;
418 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100419 }
Chris Wilson6299f992010-11-24 12:23:44 +0000420 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100421 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
422
423 size = count = dpy_size = dpy_count = 0;
424 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
425 size += obj->base.size;
426 ++count;
427
428 if (obj->pin_display) {
429 dpy_size += obj->base.size;
430 ++dpy_count;
431 }
432
433 if (obj->madv == I915_MADV_DONTNEED) {
434 purgeable_size += obj->base.size;
435 ++purgeable_count;
436 }
437
438 if (obj->mapping) {
439 mapped_count++;
440 mapped_size += obj->base.size;
441 }
442 }
443 seq_printf(m, "%u bound objects, %llu bytes\n",
444 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300445 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200446 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100447 seq_printf(m, "%u mapped objects, %llu bytes\n",
448 mapped_count, mapped_size);
449 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
450 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000451
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300452 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300453 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100454
Damien Lespiau267f0c92013-06-24 22:59:48 +0100455 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800456 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200457 mutex_unlock(&dev->struct_mutex);
458
459 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100460 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100461 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
462 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900463 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100464
465 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000466 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100467 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100468 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100469 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900470 /*
471 * Although we have a valid reference on file->pid, that does
472 * not guarantee that the task_struct who called get_pid() is
473 * still alive (e.g. get_pid(current) => fork() => exit()).
474 * Therefore, we need to protect this ->comm access using RCU.
475 */
476 rcu_read_lock();
477 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800478 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900479 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100480 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200481 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100482
483 return 0;
484}
485
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100486static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000487{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100488 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000489 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100490 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson6da84822016-08-15 10:48:44 +0100491 bool show_pin_display_only = !!data;
Chris Wilson08c18322011-01-10 00:00:24 +0000492 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300493 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000494 int count, ret;
495
496 ret = mutex_lock_interruptible(&dev->struct_mutex);
497 if (ret)
498 return ret;
499
500 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700501 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6da84822016-08-15 10:48:44 +0100502 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100503 continue;
504
Damien Lespiau267f0c92013-06-24 22:59:48 +0100505 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000506 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100507 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000508 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100509 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000510 count++;
511 }
512
513 mutex_unlock(&dev->struct_mutex);
514
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300515 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000516 count, total_obj_size, total_gtt_size);
517
518 return 0;
519}
520
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100521static int i915_gem_pageflip_info(struct seq_file *m, void *data)
522{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100523 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100524 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100525 struct drm_i915_private *dev_priv = to_i915(dev);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100526 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200527 int ret;
528
529 ret = mutex_lock_interruptible(&dev->struct_mutex);
530 if (ret)
531 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100532
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100533 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800534 const char pipe = pipe_name(crtc->pipe);
535 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200536 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100537
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200538 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200539 work = crtc->flip_work;
540 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800541 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542 pipe, plane);
543 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200544 u32 pending;
545 u32 addr;
546
547 pending = atomic_read(&work->pending);
548 if (pending) {
549 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
550 pipe, plane);
551 } else {
552 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
553 pipe, plane);
554 }
555 if (work->flip_queued_req) {
556 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
557
558 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
559 engine->name,
560 i915_gem_request_get_seqno(work->flip_queued_req),
561 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100562 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100563 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200564 } else
565 seq_printf(m, "Flip not associated with any ring\n");
566 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
567 work->flip_queued_vblank,
568 work->flip_ready_vblank,
569 intel_crtc_get_vblank_counter(crtc));
570 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
571
572 if (INTEL_INFO(dev)->gen >= 4)
573 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
574 else
575 addr = I915_READ(DSPADDR(crtc->plane));
576 seq_printf(m, "Current scanout address 0x%08x\n", addr);
577
578 if (work->pending_flip_obj) {
579 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
580 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100581 }
582 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200583 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100584 }
585
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200586 mutex_unlock(&dev->struct_mutex);
587
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100588 return 0;
589}
590
Brad Volkin493018d2014-12-11 12:13:08 -0800591static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
592{
593 struct drm_info_node *node = m->private;
594 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100595 struct drm_i915_private *dev_priv = to_i915(dev);
Brad Volkin493018d2014-12-11 12:13:08 -0800596 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000597 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100598 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000599 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800600
601 ret = mutex_lock_interruptible(&dev->struct_mutex);
602 if (ret)
603 return ret;
604
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000605 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000606 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100607 int count;
608
609 count = 0;
610 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000611 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100612 batch_pool_link)
613 count++;
614 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000615 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100616
617 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000618 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100619 batch_pool_link) {
620 seq_puts(m, " ");
621 describe_obj(m, obj);
622 seq_putc(m, '\n');
623 }
624
625 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100626 }
Brad Volkin493018d2014-12-11 12:13:08 -0800627 }
628
Chris Wilson8d9d5742015-04-07 16:20:38 +0100629 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800630
631 mutex_unlock(&dev->struct_mutex);
632
633 return 0;
634}
635
Ben Gamari20172632009-02-17 20:08:50 -0500636static int i915_gem_request_info(struct seq_file *m, void *data)
637{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100638 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500639 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100640 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000641 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200642 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000643 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100644
645 ret = mutex_lock_interruptible(&dev->struct_mutex);
646 if (ret)
647 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500648
Chris Wilson2d1070b2015-04-01 10:36:56 +0100649 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000650 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100651 int count;
652
653 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100654 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100655 count++;
656 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100657 continue;
658
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000659 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100660 list_for_each_entry(req, &engine->request_list, link) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100661 struct task_struct *task;
662
663 rcu_read_lock();
664 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200665 if (req->pid)
666 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100667 seq_printf(m, " %x @ %d: %s [%d]\n",
Chris Wilson04769652016-07-20 09:21:11 +0100668 req->fence.seqno,
Daniel Vettereed29a52015-05-21 14:21:25 +0200669 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100670 task ? task->comm : "<unknown>",
671 task ? task->pid : -1);
672 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100673 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100674
675 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500676 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100677 mutex_unlock(&dev->struct_mutex);
678
Chris Wilson2d1070b2015-04-01 10:36:56 +0100679 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100680 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100681
Ben Gamari20172632009-02-17 20:08:50 -0500682 return 0;
683}
684
Chris Wilsonb2223492010-10-27 15:27:33 +0100685static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000686 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100687{
Chris Wilson688e6c72016-07-01 17:23:15 +0100688 struct intel_breadcrumbs *b = &engine->breadcrumbs;
689 struct rb_node *rb;
690
Chris Wilson12471ba2016-04-09 10:57:55 +0100691 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100692 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100693
694 spin_lock(&b->lock);
695 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
696 struct intel_wait *w = container_of(rb, typeof(*w), node);
697
698 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
699 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
700 }
701 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100702}
703
Ben Gamari20172632009-02-17 20:08:50 -0500704static int i915_gem_seqno_info(struct seq_file *m, void *data)
705{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100706 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500707 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100708 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000709 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000710 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100711
712 ret = mutex_lock_interruptible(&dev->struct_mutex);
713 if (ret)
714 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200715 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500716
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000717 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000718 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100719
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200720 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100721 mutex_unlock(&dev->struct_mutex);
722
Ben Gamari20172632009-02-17 20:08:50 -0500723 return 0;
724}
725
726
727static int i915_interrupt_info(struct seq_file *m, void *data)
728{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100729 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500730 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100731 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000732 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800733 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100734
735 ret = mutex_lock_interruptible(&dev->struct_mutex);
736 if (ret)
737 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200738 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500739
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300740 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300741 seq_printf(m, "Master Interrupt Control:\t%08x\n",
742 I915_READ(GEN8_MASTER_IRQ));
743
744 seq_printf(m, "Display IER:\t%08x\n",
745 I915_READ(VLV_IER));
746 seq_printf(m, "Display IIR:\t%08x\n",
747 I915_READ(VLV_IIR));
748 seq_printf(m, "Display IIR_RW:\t%08x\n",
749 I915_READ(VLV_IIR_RW));
750 seq_printf(m, "Display IMR:\t%08x\n",
751 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100752 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300753 seq_printf(m, "Pipe %c stat:\t%08x\n",
754 pipe_name(pipe),
755 I915_READ(PIPESTAT(pipe)));
756
757 seq_printf(m, "Port hotplug:\t%08x\n",
758 I915_READ(PORT_HOTPLUG_EN));
759 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
760 I915_READ(VLV_DPFLIPSTAT));
761 seq_printf(m, "DPINVGTT:\t%08x\n",
762 I915_READ(DPINVGTT));
763
764 for (i = 0; i < 4; i++) {
765 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
766 i, I915_READ(GEN8_GT_IMR(i)));
767 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
768 i, I915_READ(GEN8_GT_IIR(i)));
769 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
770 i, I915_READ(GEN8_GT_IER(i)));
771 }
772
773 seq_printf(m, "PCU interrupt mask:\t%08x\n",
774 I915_READ(GEN8_PCU_IMR));
775 seq_printf(m, "PCU interrupt identity:\t%08x\n",
776 I915_READ(GEN8_PCU_IIR));
777 seq_printf(m, "PCU interrupt enable:\t%08x\n",
778 I915_READ(GEN8_PCU_IER));
779 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700780 seq_printf(m, "Master Interrupt Control:\t%08x\n",
781 I915_READ(GEN8_MASTER_IRQ));
782
783 for (i = 0; i < 4; i++) {
784 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
785 i, I915_READ(GEN8_GT_IMR(i)));
786 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
787 i, I915_READ(GEN8_GT_IIR(i)));
788 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
789 i, I915_READ(GEN8_GT_IER(i)));
790 }
791
Damien Lespiau055e3932014-08-18 13:49:10 +0100792 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200793 enum intel_display_power_domain power_domain;
794
795 power_domain = POWER_DOMAIN_PIPE(pipe);
796 if (!intel_display_power_get_if_enabled(dev_priv,
797 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300798 seq_printf(m, "Pipe %c power disabled\n",
799 pipe_name(pipe));
800 continue;
801 }
Ben Widawskya123f152013-11-02 21:07:10 -0700802 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000803 pipe_name(pipe),
804 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700805 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000806 pipe_name(pipe),
807 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700808 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000809 pipe_name(pipe),
810 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200811
812 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700813 }
814
815 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
816 I915_READ(GEN8_DE_PORT_IMR));
817 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
818 I915_READ(GEN8_DE_PORT_IIR));
819 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
820 I915_READ(GEN8_DE_PORT_IER));
821
822 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
823 I915_READ(GEN8_DE_MISC_IMR));
824 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
825 I915_READ(GEN8_DE_MISC_IIR));
826 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
827 I915_READ(GEN8_DE_MISC_IER));
828
829 seq_printf(m, "PCU interrupt mask:\t%08x\n",
830 I915_READ(GEN8_PCU_IMR));
831 seq_printf(m, "PCU interrupt identity:\t%08x\n",
832 I915_READ(GEN8_PCU_IIR));
833 seq_printf(m, "PCU interrupt enable:\t%08x\n",
834 I915_READ(GEN8_PCU_IER));
835 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700836 seq_printf(m, "Display IER:\t%08x\n",
837 I915_READ(VLV_IER));
838 seq_printf(m, "Display IIR:\t%08x\n",
839 I915_READ(VLV_IIR));
840 seq_printf(m, "Display IIR_RW:\t%08x\n",
841 I915_READ(VLV_IIR_RW));
842 seq_printf(m, "Display IMR:\t%08x\n",
843 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100844 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700845 seq_printf(m, "Pipe %c stat:\t%08x\n",
846 pipe_name(pipe),
847 I915_READ(PIPESTAT(pipe)));
848
849 seq_printf(m, "Master IER:\t%08x\n",
850 I915_READ(VLV_MASTER_IER));
851
852 seq_printf(m, "Render IER:\t%08x\n",
853 I915_READ(GTIER));
854 seq_printf(m, "Render IIR:\t%08x\n",
855 I915_READ(GTIIR));
856 seq_printf(m, "Render IMR:\t%08x\n",
857 I915_READ(GTIMR));
858
859 seq_printf(m, "PM IER:\t\t%08x\n",
860 I915_READ(GEN6_PMIER));
861 seq_printf(m, "PM IIR:\t\t%08x\n",
862 I915_READ(GEN6_PMIIR));
863 seq_printf(m, "PM IMR:\t\t%08x\n",
864 I915_READ(GEN6_PMIMR));
865
866 seq_printf(m, "Port hotplug:\t%08x\n",
867 I915_READ(PORT_HOTPLUG_EN));
868 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
869 I915_READ(VLV_DPFLIPSTAT));
870 seq_printf(m, "DPINVGTT:\t%08x\n",
871 I915_READ(DPINVGTT));
872
873 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800874 seq_printf(m, "Interrupt enable: %08x\n",
875 I915_READ(IER));
876 seq_printf(m, "Interrupt identity: %08x\n",
877 I915_READ(IIR));
878 seq_printf(m, "Interrupt mask: %08x\n",
879 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100880 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800881 seq_printf(m, "Pipe %c stat: %08x\n",
882 pipe_name(pipe),
883 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800884 } else {
885 seq_printf(m, "North Display Interrupt enable: %08x\n",
886 I915_READ(DEIER));
887 seq_printf(m, "North Display Interrupt identity: %08x\n",
888 I915_READ(DEIIR));
889 seq_printf(m, "North Display Interrupt mask: %08x\n",
890 I915_READ(DEIMR));
891 seq_printf(m, "South Display Interrupt enable: %08x\n",
892 I915_READ(SDEIER));
893 seq_printf(m, "South Display Interrupt identity: %08x\n",
894 I915_READ(SDEIIR));
895 seq_printf(m, "South Display Interrupt mask: %08x\n",
896 I915_READ(SDEIMR));
897 seq_printf(m, "Graphics Interrupt enable: %08x\n",
898 I915_READ(GTIER));
899 seq_printf(m, "Graphics Interrupt identity: %08x\n",
900 I915_READ(GTIIR));
901 seq_printf(m, "Graphics Interrupt mask: %08x\n",
902 I915_READ(GTIMR));
903 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000904 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -0700905 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100906 seq_printf(m,
907 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000908 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000909 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000910 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000911 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200912 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100913 mutex_unlock(&dev->struct_mutex);
914
Ben Gamari20172632009-02-17 20:08:50 -0500915 return 0;
916}
917
Chris Wilsona6172a82009-02-11 14:26:38 +0000918static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
919{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100920 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000921 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100922 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100923 int i, ret;
924
925 ret = mutex_lock_interruptible(&dev->struct_mutex);
926 if (ret)
927 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000928
Chris Wilsona6172a82009-02-11 14:26:38 +0000929 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
930 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000931 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000932
Chris Wilson6c085a72012-08-20 11:40:46 +0200933 seq_printf(m, "Fence %d, pin count = %d, object = ",
934 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100935 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100936 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100937 else
Chris Wilson05394f32010-11-08 19:18:58 +0000938 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100939 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000940 }
941
Chris Wilson05394f32010-11-08 19:18:58 +0000942 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000943 return 0;
944}
945
Ben Gamari20172632009-02-17 20:08:50 -0500946static int i915_hws_info(struct seq_file *m, void *data)
947{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100948 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500949 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100950 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000951 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100952 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100953 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500954
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +0000955 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000956 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500957 if (hws == NULL)
958 return 0;
959
960 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
961 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
962 i * 4,
963 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
964 }
965 return 0;
966}
967
Daniel Vetterd5442302012-04-27 15:17:40 +0200968static ssize_t
969i915_error_state_write(struct file *filp,
970 const char __user *ubuf,
971 size_t cnt,
972 loff_t *ppos)
973{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300974 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200975 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200976 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200977
978 DRM_DEBUG_DRIVER("Resetting error state\n");
979
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200980 ret = mutex_lock_interruptible(&dev->struct_mutex);
981 if (ret)
982 return ret;
983
Daniel Vetterd5442302012-04-27 15:17:40 +0200984 i915_destroy_error_state(dev);
985 mutex_unlock(&dev->struct_mutex);
986
987 return cnt;
988}
989
990static int i915_error_state_open(struct inode *inode, struct file *file)
991{
992 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200993 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200994
995 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
996 if (!error_priv)
997 return -ENOMEM;
998
999 error_priv->dev = dev;
1000
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001001 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001002
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001003 file->private_data = error_priv;
1004
1005 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001006}
1007
1008static int i915_error_state_release(struct inode *inode, struct file *file)
1009{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001010 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001011
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001012 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001013 kfree(error_priv);
1014
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001015 return 0;
1016}
1017
1018static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1019 size_t count, loff_t *pos)
1020{
1021 struct i915_error_state_file_priv *error_priv = file->private_data;
1022 struct drm_i915_error_state_buf error_str;
1023 loff_t tmp_pos = 0;
1024 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001025 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001026
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001027 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001028 if (ret)
1029 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001030
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001031 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001032 if (ret)
1033 goto out;
1034
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001035 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1036 error_str.buf,
1037 error_str.bytes);
1038
1039 if (ret_count < 0)
1040 ret = ret_count;
1041 else
1042 *pos = error_str.start + ret_count;
1043out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001044 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001045 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001046}
1047
1048static const struct file_operations i915_error_state_fops = {
1049 .owner = THIS_MODULE,
1050 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001051 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001052 .write = i915_error_state_write,
1053 .llseek = default_llseek,
1054 .release = i915_error_state_release,
1055};
1056
Kees Cook647416f2013-03-10 14:10:06 -07001057static int
1058i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001059{
Kees Cook647416f2013-03-10 14:10:06 -07001060 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001061 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala40633212012-12-04 15:12:00 +02001062 int ret;
1063
1064 ret = mutex_lock_interruptible(&dev->struct_mutex);
1065 if (ret)
1066 return ret;
1067
Kees Cook647416f2013-03-10 14:10:06 -07001068 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001069 mutex_unlock(&dev->struct_mutex);
1070
Kees Cook647416f2013-03-10 14:10:06 -07001071 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001072}
1073
Kees Cook647416f2013-03-10 14:10:06 -07001074static int
1075i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001076{
Kees Cook647416f2013-03-10 14:10:06 -07001077 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001078 int ret;
1079
Mika Kuoppala40633212012-12-04 15:12:00 +02001080 ret = mutex_lock_interruptible(&dev->struct_mutex);
1081 if (ret)
1082 return ret;
1083
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001084 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001085 mutex_unlock(&dev->struct_mutex);
1086
Kees Cook647416f2013-03-10 14:10:06 -07001087 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001088}
1089
Kees Cook647416f2013-03-10 14:10:06 -07001090DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1091 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001092 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001093
Deepak Sadb4bd12014-03-31 11:30:02 +05301094static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001095{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001096 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001097 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001098 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001099 int ret = 0;
1100
1101 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001102
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001103 if (IS_GEN5(dev)) {
1104 u16 rgvswctl = I915_READ16(MEMSWCTL);
1105 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1106
1107 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1108 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1109 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1110 MEMSTAT_VID_SHIFT);
1111 seq_printf(m, "Current P-state: %d\n",
1112 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001113 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1114 u32 freq_sts;
1115
1116 mutex_lock(&dev_priv->rps.hw_lock);
1117 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1118 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1119 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1120
1121 seq_printf(m, "actual GPU freq: %d MHz\n",
1122 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1123
1124 seq_printf(m, "current GPU freq: %d MHz\n",
1125 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1126
1127 seq_printf(m, "max GPU freq: %d MHz\n",
1128 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1129
1130 seq_printf(m, "min GPU freq: %d MHz\n",
1131 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1132
1133 seq_printf(m, "idle GPU freq: %d MHz\n",
1134 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1135
1136 seq_printf(m,
1137 "efficient (RPe) frequency: %d MHz\n",
1138 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1139 mutex_unlock(&dev_priv->rps.hw_lock);
1140 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001141 u32 rp_state_limits;
1142 u32 gt_perf_status;
1143 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001144 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001145 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001146 u32 rpupei, rpcurup, rpprevup;
1147 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001148 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001149 int max_freq;
1150
Bob Paauwe35040562015-06-25 14:54:07 -07001151 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1152 if (IS_BROXTON(dev)) {
1153 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1154 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1155 } else {
1156 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1157 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1158 }
1159
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001160 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001161 ret = mutex_lock_interruptible(&dev->struct_mutex);
1162 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001163 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001164
Mika Kuoppala59bad942015-01-16 11:34:40 +02001165 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001166
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001167 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301168 if (IS_GEN9(dev))
1169 reqf >>= 23;
1170 else {
1171 reqf &= ~GEN6_TURBO_DISABLE;
1172 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1173 reqf >>= 24;
1174 else
1175 reqf >>= 25;
1176 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001177 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001178
Chris Wilson0d8f9492014-03-27 09:06:14 +00001179 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1180 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1181 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1182
Jesse Barnesccab5c82011-01-18 15:49:25 -08001183 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301184 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1185 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1186 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1187 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1188 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1189 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301190 if (IS_GEN9(dev))
1191 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1192 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001193 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1194 else
1195 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001196 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001197
Mika Kuoppala59bad942015-01-16 11:34:40 +02001198 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001199 mutex_unlock(&dev->struct_mutex);
1200
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001201 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1202 pm_ier = I915_READ(GEN6_PMIER);
1203 pm_imr = I915_READ(GEN6_PMIMR);
1204 pm_isr = I915_READ(GEN6_PMISR);
1205 pm_iir = I915_READ(GEN6_PMIIR);
1206 pm_mask = I915_READ(GEN6_PMINTRMSK);
1207 } else {
1208 pm_ier = I915_READ(GEN8_GT_IER(2));
1209 pm_imr = I915_READ(GEN8_GT_IMR(2));
1210 pm_isr = I915_READ(GEN8_GT_ISR(2));
1211 pm_iir = I915_READ(GEN8_GT_IIR(2));
1212 pm_mask = I915_READ(GEN6_PMINTRMSK);
1213 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001214 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 -03001215 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301216 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001217 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001218 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301219 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001220 seq_printf(m, "Render p-state VID: %d\n",
1221 gt_perf_status & 0xff);
1222 seq_printf(m, "Render p-state limit: %d\n",
1223 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001224 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1225 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1226 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1227 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001228 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001229 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301230 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1231 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1232 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1233 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1234 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1235 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001236 seq_printf(m, "Up threshold: %d%%\n",
1237 dev_priv->rps.up_threshold);
1238
Akash Goeld6cda9c2016-04-23 00:05:46 +05301239 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1240 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1241 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1242 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1243 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1244 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001245 seq_printf(m, "Down threshold: %d%%\n",
1246 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001247
Bob Paauwe35040562015-06-25 14:54:07 -07001248 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1249 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001250 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1251 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001252 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001253 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001254
1255 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001256 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1257 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001259 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260
Bob Paauwe35040562015-06-25 14:54:07 -07001261 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1262 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001263 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1264 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001265 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001266 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001267 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001268 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001269
Chris Wilsond86ed342015-04-27 13:41:19 +01001270 seq_printf(m, "Current freq: %d MHz\n",
1271 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1272 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001273 seq_printf(m, "Idle freq: %d MHz\n",
1274 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001275 seq_printf(m, "Min freq: %d MHz\n",
1276 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001277 seq_printf(m, "Boost freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001279 seq_printf(m, "Max freq: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1281 seq_printf(m,
1282 "efficient (RPe) frequency: %d MHz\n",
1283 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001284 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001285 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001286 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001287
Mika Kahola1170f282015-09-25 14:00:32 +03001288 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1289 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1290 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1291
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001292out:
1293 intel_runtime_pm_put(dev_priv);
1294 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001295}
1296
Chris Wilsonf6544492015-01-26 18:03:04 +02001297static int i915_hangcheck_info(struct seq_file *m, void *unused)
1298{
1299 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001300 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001301 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001302 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001303 u64 acthd[I915_NUM_ENGINES];
1304 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001305 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001306 enum intel_engine_id id;
1307 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001308
1309 if (!i915.enable_hangcheck) {
1310 seq_printf(m, "Hangcheck disabled\n");
1311 return 0;
1312 }
1313
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001314 intel_runtime_pm_get(dev_priv);
1315
Dave Gordonc3232b12016-03-23 18:19:53 +00001316 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001317 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001318 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001319 }
1320
Chris Wilsonc0336662016-05-06 15:40:21 +01001321 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001322
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001323 intel_runtime_pm_put(dev_priv);
1324
Chris Wilsonf6544492015-01-26 18:03:04 +02001325 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1326 seq_printf(m, "Hangcheck active, fires in %dms\n",
1327 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1328 jiffies));
1329 } else
1330 seq_printf(m, "Hangcheck inactive\n");
1331
Dave Gordonc3232b12016-03-23 18:19:53 +00001332 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001333 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001334 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1335 engine->hangcheck.seqno,
1336 seqno[id],
1337 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001338 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1339 yesno(intel_engine_has_waiter(engine)),
1340 yesno(test_bit(engine->id,
1341 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilsonf6544492015-01-26 18:03:04 +02001342 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001343 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001344 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001345 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1346 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001347
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001348 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001349 seq_puts(m, "\tinstdone read =");
1350
1351 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1352 seq_printf(m, " 0x%08x", instdone[j]);
1353
1354 seq_puts(m, "\n\tinstdone accu =");
1355
1356 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1357 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001358 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001359
1360 seq_puts(m, "\n");
1361 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001362 }
1363
1364 return 0;
1365}
1366
Ben Widawsky4d855292011-12-12 19:34:16 -08001367static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001368{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001369 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001370 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001371 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001372 u32 rgvmodectl, rstdbyctl;
1373 u16 crstandvid;
1374 int ret;
1375
1376 ret = mutex_lock_interruptible(&dev->struct_mutex);
1377 if (ret)
1378 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001379 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001380
1381 rgvmodectl = I915_READ(MEMMODECTL);
1382 rstdbyctl = I915_READ(RSTDBYCTL);
1383 crstandvid = I915_READ16(CRSTANDVID);
1384
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001385 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001386 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001387
Jani Nikula742f4912015-09-03 11:16:09 +03001388 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001389 seq_printf(m, "Boost freq: %d\n",
1390 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1391 MEMMODE_BOOST_FREQ_SHIFT);
1392 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001393 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001394 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001395 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001396 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001397 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001398 seq_printf(m, "Starting frequency: P%d\n",
1399 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001400 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001401 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001402 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1403 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1404 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1405 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001406 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001407 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001408 switch (rstdbyctl & RSX_STATUS_MASK) {
1409 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001410 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001411 break;
1412 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001413 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001414 break;
1415 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001416 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001417 break;
1418 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001419 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001420 break;
1421 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001422 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001423 break;
1424 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001425 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001426 break;
1427 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001428 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001429 break;
1430 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001431
1432 return 0;
1433}
1434
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001435static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001436{
1437 struct drm_info_node *node = m->private;
1438 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001439 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001440 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001441
1442 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001443 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001444 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001445 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001446 fw_domain->wake_count);
1447 }
1448 spin_unlock_irq(&dev_priv->uncore.lock);
1449
1450 return 0;
1451}
1452
Deepak S669ab5a2014-01-10 15:18:26 +05301453static int vlv_drpc_info(struct seq_file *m)
1454{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001455 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301456 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001457 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001458 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301459
Imre Deakd46c0512014-04-14 20:24:27 +03001460 intel_runtime_pm_get(dev_priv);
1461
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001462 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301463 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1464 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1465
Imre Deakd46c0512014-04-14 20:24:27 +03001466 intel_runtime_pm_put(dev_priv);
1467
Deepak S669ab5a2014-01-10 15:18:26 +05301468 seq_printf(m, "Video Turbo Mode: %s\n",
1469 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1470 seq_printf(m, "Turbo enabled: %s\n",
1471 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1472 seq_printf(m, "HW control enabled: %s\n",
1473 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1474 seq_printf(m, "SW control enabled: %s\n",
1475 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1476 GEN6_RP_MEDIA_SW_MODE));
1477 seq_printf(m, "RC6 Enabled: %s\n",
1478 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1479 GEN6_RC_CTL_EI_MODE(1))));
1480 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001481 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301482 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001483 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301484
Imre Deak9cc19be2014-04-14 20:24:24 +03001485 seq_printf(m, "Render RC6 residency since boot: %u\n",
1486 I915_READ(VLV_GT_RENDER_RC6));
1487 seq_printf(m, "Media RC6 residency since boot: %u\n",
1488 I915_READ(VLV_GT_MEDIA_RC6));
1489
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001490 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301491}
1492
Ben Widawsky4d855292011-12-12 19:34:16 -08001493static int gen6_drpc_info(struct seq_file *m)
1494{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001495 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001496 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001497 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001498 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301499 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001500 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001501 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001502
1503 ret = mutex_lock_interruptible(&dev->struct_mutex);
1504 if (ret)
1505 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001506 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001507
Chris Wilson907b28c2013-07-19 20:36:52 +01001508 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001509 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001510 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001511
1512 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001513 seq_puts(m, "RC information inaccurate because somebody "
1514 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001515 } else {
1516 /* NB: we cannot use forcewake, else we read the wrong values */
1517 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1518 udelay(10);
1519 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1520 }
1521
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001522 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001523 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001524
1525 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1526 rcctl1 = I915_READ(GEN6_RC_CONTROL);
Akash Goelf2dd7572016-06-27 20:10:01 +05301527 if (INTEL_INFO(dev)->gen >= 9) {
1528 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1529 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1530 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001531 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001532 mutex_lock(&dev_priv->rps.hw_lock);
1533 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1534 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001535
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001536 intel_runtime_pm_put(dev_priv);
1537
Ben Widawsky4d855292011-12-12 19:34:16 -08001538 seq_printf(m, "Video Turbo Mode: %s\n",
1539 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1540 seq_printf(m, "HW control enabled: %s\n",
1541 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1542 seq_printf(m, "SW control enabled: %s\n",
1543 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1544 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001545 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001546 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1547 seq_printf(m, "RC6 Enabled: %s\n",
1548 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
Akash Goelf2dd7572016-06-27 20:10:01 +05301549 if (INTEL_INFO(dev)->gen >= 9) {
1550 seq_printf(m, "Render Well Gating Enabled: %s\n",
1551 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1552 seq_printf(m, "Media Well Gating Enabled: %s\n",
1553 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1554 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001555 seq_printf(m, "Deep RC6 Enabled: %s\n",
1556 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1557 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1558 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001559 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001560 switch (gt_core_status & GEN6_RCn_MASK) {
1561 case GEN6_RC0:
1562 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001563 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001564 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001565 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001566 break;
1567 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001568 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001569 break;
1570 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001571 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001572 break;
1573 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001574 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001575 break;
1576 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001577 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001578 break;
1579 }
1580
1581 seq_printf(m, "Core Power Down: %s\n",
1582 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Akash Goelf2dd7572016-06-27 20:10:01 +05301583 if (INTEL_INFO(dev)->gen >= 9) {
1584 seq_printf(m, "Render Power Well: %s\n",
1585 (gen9_powergate_status &
1586 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1587 seq_printf(m, "Media Power Well: %s\n",
1588 (gen9_powergate_status &
1589 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1590 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001591
1592 /* Not exactly sure what this is */
1593 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1594 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1595 seq_printf(m, "RC6 residency since boot: %u\n",
1596 I915_READ(GEN6_GT_GFX_RC6));
1597 seq_printf(m, "RC6+ residency since boot: %u\n",
1598 I915_READ(GEN6_GT_GFX_RC6p));
1599 seq_printf(m, "RC6++ residency since boot: %u\n",
1600 I915_READ(GEN6_GT_GFX_RC6pp));
1601
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001602 seq_printf(m, "RC6 voltage: %dmV\n",
1603 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1604 seq_printf(m, "RC6+ voltage: %dmV\n",
1605 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1606 seq_printf(m, "RC6++ voltage: %dmV\n",
1607 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301608 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001609}
1610
1611static int i915_drpc_info(struct seq_file *m, void *unused)
1612{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001613 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001614 struct drm_device *dev = node->minor->dev;
1615
Wayne Boyer666a4532015-12-09 12:29:35 -08001616 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301617 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001618 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001619 return gen6_drpc_info(m);
1620 else
1621 return ironlake_drpc_info(m);
1622}
1623
Daniel Vetter9a851782015-06-18 10:30:22 +02001624static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1625{
1626 struct drm_info_node *node = m->private;
1627 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001628 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter9a851782015-06-18 10:30:22 +02001629
1630 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1631 dev_priv->fb_tracking.busy_bits);
1632
1633 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1634 dev_priv->fb_tracking.flip_bits);
1635
1636 return 0;
1637}
1638
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001639static int i915_fbc_status(struct seq_file *m, void *unused)
1640{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001641 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001642 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001643 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001644
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001645 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001646 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001647 return 0;
1648 }
1649
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001650 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001651 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001652
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001653 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001654 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001655 else
1656 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001657 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001658
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001659 if (INTEL_INFO(dev_priv)->gen >= 7)
1660 seq_printf(m, "Compressing: %s\n",
1661 yesno(I915_READ(FBC_STATUS2) &
1662 FBC_COMPRESSION_MASK));
1663
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001664 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001665 intel_runtime_pm_put(dev_priv);
1666
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001667 return 0;
1668}
1669
Rodrigo Vivida46f932014-08-01 02:04:45 -07001670static int i915_fbc_fc_get(void *data, u64 *val)
1671{
1672 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001673 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001674
1675 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1676 return -ENODEV;
1677
Rodrigo Vivida46f932014-08-01 02:04:45 -07001678 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001679
1680 return 0;
1681}
1682
1683static int i915_fbc_fc_set(void *data, u64 val)
1684{
1685 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001686 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001687 u32 reg;
1688
1689 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1690 return -ENODEV;
1691
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001692 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001693
1694 reg = I915_READ(ILK_DPFC_CONTROL);
1695 dev_priv->fbc.false_color = val;
1696
1697 I915_WRITE(ILK_DPFC_CONTROL, val ?
1698 (reg | FBC_CTL_FALSE_COLOR) :
1699 (reg & ~FBC_CTL_FALSE_COLOR));
1700
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001701 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001702 return 0;
1703}
1704
1705DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1706 i915_fbc_fc_get, i915_fbc_fc_set,
1707 "%llu\n");
1708
Paulo Zanoni92d44622013-05-31 16:33:24 -03001709static int i915_ips_status(struct seq_file *m, void *unused)
1710{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001711 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001712 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001713 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001714
Damien Lespiauf5adf942013-06-24 18:29:34 +01001715 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001716 seq_puts(m, "not supported\n");
1717 return 0;
1718 }
1719
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001720 intel_runtime_pm_get(dev_priv);
1721
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001722 seq_printf(m, "Enabled by kernel parameter: %s\n",
1723 yesno(i915.enable_ips));
1724
1725 if (INTEL_INFO(dev)->gen >= 8) {
1726 seq_puts(m, "Currently: unknown\n");
1727 } else {
1728 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1729 seq_puts(m, "Currently: enabled\n");
1730 else
1731 seq_puts(m, "Currently: disabled\n");
1732 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001733
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001734 intel_runtime_pm_put(dev_priv);
1735
Paulo Zanoni92d44622013-05-31 16:33:24 -03001736 return 0;
1737}
1738
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001739static int i915_sr_status(struct seq_file *m, void *unused)
1740{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001741 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001742 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001743 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001744 bool sr_enabled = false;
1745
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001746 intel_runtime_pm_get(dev_priv);
1747
Yuanhan Liu13982612010-12-15 15:42:31 +08001748 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001749 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001750 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1751 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001752 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1753 else if (IS_I915GM(dev))
1754 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1755 else if (IS_PINEVIEW(dev))
1756 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001757 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001758 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001759
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001760 intel_runtime_pm_put(dev_priv);
1761
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001762 seq_printf(m, "self-refresh: %s\n",
1763 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001764
1765 return 0;
1766}
1767
Jesse Barnes7648fa92010-05-20 14:28:11 -07001768static int i915_emon_status(struct seq_file *m, void *unused)
1769{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001770 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001771 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001772 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001773 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001774 int ret;
1775
Chris Wilson582be6b2012-04-30 19:35:02 +01001776 if (!IS_GEN5(dev))
1777 return -ENODEV;
1778
Chris Wilsonde227ef2010-07-03 07:58:38 +01001779 ret = mutex_lock_interruptible(&dev->struct_mutex);
1780 if (ret)
1781 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001782
1783 temp = i915_mch_val(dev_priv);
1784 chipset = i915_chipset_val(dev_priv);
1785 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001786 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001787
1788 seq_printf(m, "GMCH temp: %ld\n", temp);
1789 seq_printf(m, "Chipset power: %ld\n", chipset);
1790 seq_printf(m, "GFX power: %ld\n", gfx);
1791 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1792
1793 return 0;
1794}
1795
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001796static int i915_ring_freq_table(struct seq_file *m, void *unused)
1797{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001798 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001799 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001800 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001801 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001802 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301803 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001804
Akash Goel97d33082015-06-29 14:50:23 +05301805 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001806 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001807 return 0;
1808 }
1809
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001810 intel_runtime_pm_get(dev_priv);
1811
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001812 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001813 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001814 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001815
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001816 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301817 /* Convert GT frequency to 50 HZ units */
1818 min_gpu_freq =
1819 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1820 max_gpu_freq =
1821 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1822 } else {
1823 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1824 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1825 }
1826
Damien Lespiau267f0c92013-06-24 22:59:48 +01001827 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001828
Akash Goelf936ec32015-06-29 14:50:22 +05301829 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001830 ia_freq = gpu_freq;
1831 sandybridge_pcode_read(dev_priv,
1832 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1833 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001834 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301835 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001836 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1837 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001838 ((ia_freq >> 0) & 0xff) * 100,
1839 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001840 }
1841
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001842 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001843
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001844out:
1845 intel_runtime_pm_put(dev_priv);
1846 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001847}
1848
Chris Wilson44834a62010-08-19 16:09:23 +01001849static int i915_opregion(struct seq_file *m, void *unused)
1850{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001851 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001852 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001853 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson44834a62010-08-19 16:09:23 +01001854 struct intel_opregion *opregion = &dev_priv->opregion;
1855 int ret;
1856
1857 ret = mutex_lock_interruptible(&dev->struct_mutex);
1858 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001859 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001860
Jani Nikula2455a8e2015-12-14 12:50:53 +02001861 if (opregion->header)
1862 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001863
1864 mutex_unlock(&dev->struct_mutex);
1865
Daniel Vetter0d38f002012-04-21 22:49:10 +02001866out:
Chris Wilson44834a62010-08-19 16:09:23 +01001867 return 0;
1868}
1869
Jani Nikulaada8f952015-12-15 13:17:12 +02001870static int i915_vbt(struct seq_file *m, void *unused)
1871{
1872 struct drm_info_node *node = m->private;
1873 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001874 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulaada8f952015-12-15 13:17:12 +02001875 struct intel_opregion *opregion = &dev_priv->opregion;
1876
1877 if (opregion->vbt)
1878 seq_write(m, opregion->vbt, opregion->vbt_size);
1879
1880 return 0;
1881}
1882
Chris Wilson37811fc2010-08-25 22:45:57 +01001883static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1884{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001885 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001886 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301887 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001888 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001889 int ret;
1890
1891 ret = mutex_lock_interruptible(&dev->struct_mutex);
1892 if (ret)
1893 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001894
Daniel Vetter06957262015-08-10 13:34:08 +02001895#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson25bcce92016-07-02 15:36:00 +01001896 if (to_i915(dev)->fbdev) {
1897 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001898
Chris Wilson25bcce92016-07-02 15:36:00 +01001899 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1900 fbdev_fb->base.width,
1901 fbdev_fb->base.height,
1902 fbdev_fb->base.depth,
1903 fbdev_fb->base.bits_per_pixel,
1904 fbdev_fb->base.modifier[0],
1905 drm_framebuffer_read_refcount(&fbdev_fb->base));
1906 describe_obj(m, fbdev_fb->obj);
1907 seq_putc(m, '\n');
1908 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001909#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001910
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001911 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001912 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301913 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1914 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001915 continue;
1916
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001917 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 +01001918 fb->base.width,
1919 fb->base.height,
1920 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001921 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001922 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001923 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001924 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001925 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001926 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001927 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001928 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001929
1930 return 0;
1931}
1932
Chris Wilson7e37f882016-08-02 22:50:21 +01001933static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001934{
1935 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001936 ring->space, ring->head, ring->tail,
1937 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001938}
1939
Ben Widawskye76d3632011-03-19 18:14:29 -07001940static int i915_context_status(struct seq_file *m, void *unused)
1941{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001942 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001943 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001944 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001945 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001946 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00001947 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001948
Daniel Vetterf3d28872014-05-29 23:23:08 +02001949 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001950 if (ret)
1951 return ret;
1952
Ben Widawskya33afea2013-09-17 21:12:45 -07001953 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001954 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001955 if (IS_ERR(ctx->file_priv)) {
1956 seq_puts(m, "(deleted) ");
1957 } else if (ctx->file_priv) {
1958 struct pid *pid = ctx->file_priv->file->pid;
1959 struct task_struct *task;
1960
1961 task = get_pid_task(pid, PIDTYPE_PID);
1962 if (task) {
1963 seq_printf(m, "(%s [%d]) ",
1964 task->comm, task->pid);
1965 put_task_struct(task);
1966 }
1967 } else {
1968 seq_puts(m, "(kernel) ");
1969 }
1970
Chris Wilsonbca44d82016-05-24 14:53:41 +01001971 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1972 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001973
Chris Wilsonbca44d82016-05-24 14:53:41 +01001974 for_each_engine(engine, dev_priv) {
1975 struct intel_context *ce = &ctx->engine[engine->id];
1976
1977 seq_printf(m, "%s: ", engine->name);
1978 seq_putc(m, ce->initialised ? 'I' : 'i');
1979 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001980 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001981 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001982 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001983 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001984 }
1985
Ben Widawskya33afea2013-09-17 21:12:45 -07001986 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001987 }
1988
Daniel Vetterf3d28872014-05-29 23:23:08 +02001989 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001990
1991 return 0;
1992}
1993
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001994static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001995 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001996 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001997{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001998 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001999 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002000 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002001
Chris Wilson7069b142016-04-28 09:56:52 +01002002 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2003
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002004 if (!vma) {
2005 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002006 return;
2007 }
2008
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002009 if (vma->flags & I915_VMA_GLOBAL_BIND)
2010 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
2011 lower_32_bits(vma->node.start));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002012
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002013 if (i915_gem_object_get_pages(vma->obj)) {
2014 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002015 return;
2016 }
2017
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002018 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2019 if (page) {
2020 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002021
2022 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002023 seq_printf(m,
2024 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2025 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002026 reg_state[j], reg_state[j + 1],
2027 reg_state[j + 2], reg_state[j + 3]);
2028 }
2029 kunmap_atomic(reg_state);
2030 }
2031
2032 seq_putc(m, '\n');
2033}
2034
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002035static int i915_dump_lrc(struct seq_file *m, void *unused)
2036{
2037 struct drm_info_node *node = (struct drm_info_node *) m->private;
2038 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002039 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002040 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002041 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002042 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002043
2044 if (!i915.enable_execlists) {
2045 seq_printf(m, "Logical Ring Contexts are disabled\n");
2046 return 0;
2047 }
2048
2049 ret = mutex_lock_interruptible(&dev->struct_mutex);
2050 if (ret)
2051 return ret;
2052
Dave Gordone28e4042016-01-19 19:02:55 +00002053 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002054 for_each_engine(engine, dev_priv)
2055 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002056
2057 mutex_unlock(&dev->struct_mutex);
2058
2059 return 0;
2060}
2061
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002062static int i915_execlists(struct seq_file *m, void *data)
2063{
2064 struct drm_info_node *node = (struct drm_info_node *)m->private;
2065 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002066 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002067 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002068 u32 status_pointer;
2069 u8 read_pointer;
2070 u8 write_pointer;
2071 u32 status;
2072 u32 ctx_id;
2073 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002074 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002075
2076 if (!i915.enable_execlists) {
2077 seq_puts(m, "Logical Ring Contexts are disabled\n");
2078 return 0;
2079 }
2080
2081 ret = mutex_lock_interruptible(&dev->struct_mutex);
2082 if (ret)
2083 return ret;
2084
Michel Thierryfc0412e2014-10-16 16:13:38 +01002085 intel_runtime_pm_get(dev_priv);
2086
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002087 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002088 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002089 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002090
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002091 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002092
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002093 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2094 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002095 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2096 status, ctx_id);
2097
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002098 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002099 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2100
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002101 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002102 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002103 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002104 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002105 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2106 read_pointer, write_pointer);
2107
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002108 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002109 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2110 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002111
2112 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2113 i, status, ctx_id);
2114 }
2115
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002116 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002117 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002118 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002119 head_req = list_first_entry_or_null(&engine->execlist_queue,
2120 struct drm_i915_gem_request,
2121 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002122 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002123
2124 seq_printf(m, "\t%d requests in queue\n", count);
2125 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002126 seq_printf(m, "\tHead request context: %u\n",
2127 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002128 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002129 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002130 }
2131
2132 seq_putc(m, '\n');
2133 }
2134
Michel Thierryfc0412e2014-10-16 16:13:38 +01002135 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002136 mutex_unlock(&dev->struct_mutex);
2137
2138 return 0;
2139}
2140
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002141static const char *swizzle_string(unsigned swizzle)
2142{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002143 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002144 case I915_BIT_6_SWIZZLE_NONE:
2145 return "none";
2146 case I915_BIT_6_SWIZZLE_9:
2147 return "bit9";
2148 case I915_BIT_6_SWIZZLE_9_10:
2149 return "bit9/bit10";
2150 case I915_BIT_6_SWIZZLE_9_11:
2151 return "bit9/bit11";
2152 case I915_BIT_6_SWIZZLE_9_10_11:
2153 return "bit9/bit10/bit11";
2154 case I915_BIT_6_SWIZZLE_9_17:
2155 return "bit9/bit17";
2156 case I915_BIT_6_SWIZZLE_9_10_17:
2157 return "bit9/bit10/bit17";
2158 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002159 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002160 }
2161
2162 return "bug";
2163}
2164
2165static int i915_swizzle_info(struct seq_file *m, void *data)
2166{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002167 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002168 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002169 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002170 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002171
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002172 ret = mutex_lock_interruptible(&dev->struct_mutex);
2173 if (ret)
2174 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002175 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002176
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002177 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2178 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2179 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2180 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2181
2182 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2183 seq_printf(m, "DDC = 0x%08x\n",
2184 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002185 seq_printf(m, "DDC2 = 0x%08x\n",
2186 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002187 seq_printf(m, "C0DRB3 = 0x%04x\n",
2188 I915_READ16(C0DRB3));
2189 seq_printf(m, "C1DRB3 = 0x%04x\n",
2190 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002191 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002192 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2193 I915_READ(MAD_DIMM_C0));
2194 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2195 I915_READ(MAD_DIMM_C1));
2196 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2197 I915_READ(MAD_DIMM_C2));
2198 seq_printf(m, "TILECTL = 0x%08x\n",
2199 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002200 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002201 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2202 I915_READ(GAMTARBMODE));
2203 else
2204 seq_printf(m, "ARB_MODE = 0x%08x\n",
2205 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002206 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2207 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002208 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002209
2210 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2211 seq_puts(m, "L-shaped memory detected\n");
2212
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002213 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002214 mutex_unlock(&dev->struct_mutex);
2215
2216 return 0;
2217}
2218
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002219static int per_file_ctx(int id, void *ptr, void *data)
2220{
Chris Wilsone2efd132016-05-24 14:53:34 +01002221 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002222 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002223 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2224
2225 if (!ppgtt) {
2226 seq_printf(m, " no ppgtt for context %d\n",
2227 ctx->user_handle);
2228 return 0;
2229 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002230
Oscar Mateof83d6512014-05-22 14:13:38 +01002231 if (i915_gem_context_is_default(ctx))
2232 seq_puts(m, " default context:\n");
2233 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002234 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002235 ppgtt->debug_dump(ppgtt, m);
2236
2237 return 0;
2238}
2239
Ben Widawsky77df6772013-11-02 21:07:30 -07002240static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002241{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002242 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002243 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002244 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002245 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002246
Ben Widawsky77df6772013-11-02 21:07:30 -07002247 if (!ppgtt)
2248 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002249
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002250 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002251 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002252 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002253 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002254 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002255 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002256 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002257 }
2258 }
2259}
2260
2261static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2262{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002263 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002264 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002265
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002266 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002267 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2268
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002269 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002270 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002271 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002272 seq_printf(m, "GFX_MODE: 0x%08x\n",
2273 I915_READ(RING_MODE_GEN7(engine)));
2274 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2275 I915_READ(RING_PP_DIR_BASE(engine)));
2276 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2277 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2278 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2279 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002280 }
2281 if (dev_priv->mm.aliasing_ppgtt) {
2282 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2283
Damien Lespiau267f0c92013-06-24 22:59:48 +01002284 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002285 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002286
Ben Widawsky87d60b62013-12-06 14:11:29 -08002287 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002288 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002289
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002290 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002291}
2292
2293static int i915_ppgtt_info(struct seq_file *m, void *data)
2294{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002295 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002296 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002297 struct drm_i915_private *dev_priv = to_i915(dev);
Michel Thierryea91e402015-07-29 17:23:57 +01002298 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002299
2300 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2301 if (ret)
2302 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002303 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002304
2305 if (INTEL_INFO(dev)->gen >= 8)
2306 gen8_ppgtt_info(m, dev);
2307 else if (INTEL_INFO(dev)->gen >= 6)
2308 gen6_ppgtt_info(m, dev);
2309
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002310 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002311 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2312 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002313 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002314
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002315 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002316 if (!task) {
2317 ret = -ESRCH;
Wei Yongjunb0212482016-06-13 23:42:00 +00002318 goto out_unlock;
Dan Carpenter06812762015-10-02 18:14:22 +03002319 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002320 seq_printf(m, "\nproc: %s\n", task->comm);
2321 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002322 idr_for_each(&file_priv->context_idr, per_file_ctx,
2323 (void *)(unsigned long)m);
2324 }
Wei Yongjunb0212482016-06-13 23:42:00 +00002325out_unlock:
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002326 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002327
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002328 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002329 mutex_unlock(&dev->struct_mutex);
2330
Dan Carpenter06812762015-10-02 18:14:22 +03002331 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002332}
2333
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002334static int count_irq_waiters(struct drm_i915_private *i915)
2335{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002336 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002337 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002338
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002339 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002340 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002341
2342 return count;
2343}
2344
Chris Wilson7466c292016-08-15 09:49:33 +01002345static const char *rps_power_to_str(unsigned int power)
2346{
2347 static const char * const strings[] = {
2348 [LOW_POWER] = "low power",
2349 [BETWEEN] = "mixed",
2350 [HIGH_POWER] = "high power",
2351 };
2352
2353 if (power >= ARRAY_SIZE(strings) || !strings[power])
2354 return "unknown";
2355
2356 return strings[power];
2357}
2358
Chris Wilson1854d5c2015-04-07 16:20:32 +01002359static int i915_rps_boost_info(struct seq_file *m, void *data)
2360{
2361 struct drm_info_node *node = m->private;
2362 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002363 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002364 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002365
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002366 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002367 seq_printf(m, "GPU busy? %s [%x]\n",
2368 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002369 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002370 seq_printf(m, "Frequency requested %d\n",
2371 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2372 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002373 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2374 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2375 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2376 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002377 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2378 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2379 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2380 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002381
2382 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002383 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002384 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2385 struct drm_i915_file_private *file_priv = file->driver_priv;
2386 struct task_struct *task;
2387
2388 rcu_read_lock();
2389 task = pid_task(file->pid, PIDTYPE_PID);
2390 seq_printf(m, "%s [%d]: %d boosts%s\n",
2391 task ? task->comm : "<unknown>",
2392 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002393 file_priv->rps.boosts,
2394 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002395 rcu_read_unlock();
2396 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002397 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002398 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002399 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002400
Chris Wilson7466c292016-08-15 09:49:33 +01002401 if (INTEL_GEN(dev_priv) >= 6 &&
2402 dev_priv->rps.enabled &&
2403 dev_priv->gt.active_engines) {
2404 u32 rpup, rpupei;
2405 u32 rpdown, rpdownei;
2406
2407 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2408 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2409 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2410 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2411 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2412 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2413
2414 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2415 rps_power_to_str(dev_priv->rps.power));
2416 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2417 100 * rpup / rpupei,
2418 dev_priv->rps.up_threshold);
2419 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2420 100 * rpdown / rpdownei,
2421 dev_priv->rps.down_threshold);
2422 } else {
2423 seq_puts(m, "\nRPS Autotuning inactive\n");
2424 }
2425
Chris Wilson8d3afd72015-05-21 21:01:47 +01002426 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002427}
2428
Ben Widawsky63573eb2013-07-04 11:02:07 -07002429static int i915_llc(struct seq_file *m, void *data)
2430{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002431 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002432 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002433 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002434 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002435
Ben Widawsky63573eb2013-07-04 11:02:07 -07002436 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002437 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2438 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002439
2440 return 0;
2441}
2442
Alex Daifdf5d352015-08-12 15:43:37 +01002443static int i915_guc_load_status_info(struct seq_file *m, void *data)
2444{
2445 struct drm_info_node *node = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002446 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
Alex Daifdf5d352015-08-12 15:43:37 +01002447 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2448 u32 tmp, i;
2449
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002450 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002451 return 0;
2452
2453 seq_printf(m, "GuC firmware status:\n");
2454 seq_printf(m, "\tpath: %s\n",
2455 guc_fw->guc_fw_path);
2456 seq_printf(m, "\tfetch: %s\n",
2457 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2458 seq_printf(m, "\tload: %s\n",
2459 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2460 seq_printf(m, "\tversion wanted: %d.%d\n",
2461 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2462 seq_printf(m, "\tversion found: %d.%d\n",
2463 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002464 seq_printf(m, "\theader: offset is %d; size = %d\n",
2465 guc_fw->header_offset, guc_fw->header_size);
2466 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2467 guc_fw->ucode_offset, guc_fw->ucode_size);
2468 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2469 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002470
2471 tmp = I915_READ(GUC_STATUS);
2472
2473 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2474 seq_printf(m, "\tBootrom status = 0x%x\n",
2475 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2476 seq_printf(m, "\tuKernel status = 0x%x\n",
2477 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2478 seq_printf(m, "\tMIA Core status = 0x%x\n",
2479 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2480 seq_puts(m, "\nScratch registers:\n");
2481 for (i = 0; i < 16; i++)
2482 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2483
2484 return 0;
2485}
2486
Dave Gordon8b417c22015-08-12 15:43:44 +01002487static void i915_guc_client_info(struct seq_file *m,
2488 struct drm_i915_private *dev_priv,
2489 struct i915_guc_client *client)
2490{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002491 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002492 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002493 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002494
2495 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2496 client->priority, client->ctx_index, client->proc_desc_offset);
2497 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2498 client->doorbell_id, client->doorbell_offset, client->cookie);
2499 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2500 client->wq_size, client->wq_offset, client->wq_tail);
2501
Dave Gordon551aaec2016-05-13 15:36:33 +01002502 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002503 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2504 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2505
Dave Gordonc18468c2016-08-09 15:19:22 +01002506 for_each_engine_id(engine, dev_priv, id) {
2507 u64 submissions = client->submissions[id];
2508 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002509 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002510 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002511 }
2512 seq_printf(m, "\tTotal: %llu\n", tot);
2513}
2514
2515static int i915_guc_info(struct seq_file *m, void *data)
2516{
2517 struct drm_info_node *node = m->private;
2518 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002519 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Gordon8b417c22015-08-12 15:43:44 +01002520 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002521 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002522 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002523 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002524 u64 total = 0;
2525
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002526 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002527 return 0;
2528
Alex Dai5a843302015-12-02 16:56:29 -08002529 if (mutex_lock_interruptible(&dev->struct_mutex))
2530 return 0;
2531
Dave Gordon8b417c22015-08-12 15:43:44 +01002532 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002533 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002534 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002535 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002536
2537 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002538
Dave Gordon9636f6d2016-06-13 17:57:28 +01002539 seq_printf(m, "Doorbell map:\n");
2540 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2541 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2542
Dave Gordon8b417c22015-08-12 15:43:44 +01002543 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2544 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2545 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2546 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2547 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2548
2549 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonc18468c2016-08-09 15:19:22 +01002550 for_each_engine_id(engine, dev_priv, id) {
2551 u64 submissions = guc.submissions[id];
2552 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002553 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002554 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002555 }
2556 seq_printf(m, "\t%s: %llu\n", "Total", total);
2557
2558 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2559 i915_guc_client_info(m, dev_priv, &client);
2560
2561 /* Add more as required ... */
2562
2563 return 0;
2564}
2565
Alex Dai4c7e77f2015-08-12 15:43:40 +01002566static int i915_guc_log_dump(struct seq_file *m, void *data)
2567{
2568 struct drm_info_node *node = m->private;
2569 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002570 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson8b797af2016-08-15 10:48:51 +01002571 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002572 int i = 0, pg;
2573
Chris Wilson8b797af2016-08-15 10:48:51 +01002574 if (!dev_priv->guc.log_vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002575 return 0;
2576
Chris Wilson8b797af2016-08-15 10:48:51 +01002577 obj = dev_priv->guc.log_vma->obj;
2578 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2579 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002580
2581 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2582 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2583 *(log + i), *(log + i + 1),
2584 *(log + i + 2), *(log + i + 3));
2585
2586 kunmap_atomic(log);
2587 }
2588
2589 seq_putc(m, '\n');
2590
2591 return 0;
2592}
2593
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002594static int i915_edp_psr_status(struct seq_file *m, void *data)
2595{
2596 struct drm_info_node *node = m->private;
2597 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002598 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002599 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002600 u32 stat[3];
2601 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002602 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002603
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002604 if (!HAS_PSR(dev)) {
2605 seq_puts(m, "PSR not supported\n");
2606 return 0;
2607 }
2608
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002609 intel_runtime_pm_get(dev_priv);
2610
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002611 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002612 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2613 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002614 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002615 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002616 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2617 dev_priv->psr.busy_frontbuffer_bits);
2618 seq_printf(m, "Re-enable work scheduled: %s\n",
2619 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002620
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002621 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002622 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002623 else {
2624 for_each_pipe(dev_priv, pipe) {
2625 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2626 VLV_EDP_PSR_CURR_STATE_MASK;
2627 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2628 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2629 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002630 }
2631 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002632
2633 seq_printf(m, "Main link in standby mode: %s\n",
2634 yesno(dev_priv->psr.link_standby));
2635
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002636 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002637
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002638 if (!HAS_DDI(dev))
2639 for_each_pipe(dev_priv, pipe) {
2640 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2641 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2642 seq_printf(m, " pipe %c", pipe_name(pipe));
2643 }
2644 seq_puts(m, "\n");
2645
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002646 /*
2647 * VLV/CHV PSR has no kind of performance counter
2648 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2649 */
2650 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002651 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002652 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002653
2654 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2655 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002656 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002657
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002658 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002659 return 0;
2660}
2661
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002662static int i915_sink_crc(struct seq_file *m, void *data)
2663{
2664 struct drm_info_node *node = m->private;
2665 struct drm_device *dev = node->minor->dev;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002666 struct intel_connector *connector;
2667 struct intel_dp *intel_dp = NULL;
2668 int ret;
2669 u8 crc[6];
2670
2671 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002672 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002673 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002674
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002675 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002676 continue;
2677
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002678 crtc = connector->base.state->crtc;
2679 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002680 continue;
2681
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002682 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002683 continue;
2684
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002685 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002686
2687 ret = intel_dp_sink_crc(intel_dp, crc);
2688 if (ret)
2689 goto out;
2690
2691 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2692 crc[0], crc[1], crc[2],
2693 crc[3], crc[4], crc[5]);
2694 goto out;
2695 }
2696 ret = -ENODEV;
2697out:
2698 drm_modeset_unlock_all(dev);
2699 return ret;
2700}
2701
Jesse Barnesec013e72013-08-20 10:29:23 +01002702static int i915_energy_uJ(struct seq_file *m, void *data)
2703{
2704 struct drm_info_node *node = m->private;
2705 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002706 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesec013e72013-08-20 10:29:23 +01002707 u64 power;
2708 u32 units;
2709
2710 if (INTEL_INFO(dev)->gen < 6)
2711 return -ENODEV;
2712
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002713 intel_runtime_pm_get(dev_priv);
2714
Jesse Barnesec013e72013-08-20 10:29:23 +01002715 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2716 power = (power & 0x1f00) >> 8;
2717 units = 1000000 / (1 << power); /* convert to uJ */
2718 power = I915_READ(MCH_SECP_NRG_STTS);
2719 power *= units;
2720
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002721 intel_runtime_pm_put(dev_priv);
2722
Jesse Barnesec013e72013-08-20 10:29:23 +01002723 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002724
2725 return 0;
2726}
2727
Damien Lespiau6455c872015-06-04 18:23:57 +01002728static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002729{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002730 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002731 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002732 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni371db662013-08-19 13:18:10 -03002733
Chris Wilsona156e642016-04-03 14:14:21 +01002734 if (!HAS_RUNTIME_PM(dev_priv))
2735 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002736
Chris Wilson67d97da2016-07-04 08:08:31 +01002737 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002738 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002739 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002740#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002741 seq_printf(m, "Usage count: %d\n",
2742 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002743#else
2744 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2745#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002746 seq_printf(m, "PCI device power state: %s [%d]\n",
Chris Wilson91c8a322016-07-05 10:40:23 +01002747 pci_power_name(dev_priv->drm.pdev->current_state),
2748 dev_priv->drm.pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002749
Jesse Barnesec013e72013-08-20 10:29:23 +01002750 return 0;
2751}
2752
Imre Deak1da51582013-11-25 17:15:35 +02002753static int i915_power_domain_info(struct seq_file *m, void *unused)
2754{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002755 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002756 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002757 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1da51582013-11-25 17:15:35 +02002758 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2759 int i;
2760
2761 mutex_lock(&power_domains->lock);
2762
2763 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2764 for (i = 0; i < power_domains->power_well_count; i++) {
2765 struct i915_power_well *power_well;
2766 enum intel_display_power_domain power_domain;
2767
2768 power_well = &power_domains->power_wells[i];
2769 seq_printf(m, "%-25s %d\n", power_well->name,
2770 power_well->count);
2771
2772 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2773 power_domain++) {
2774 if (!(BIT(power_domain) & power_well->domains))
2775 continue;
2776
2777 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002778 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002779 power_domains->domain_use_count[power_domain]);
2780 }
2781 }
2782
2783 mutex_unlock(&power_domains->lock);
2784
2785 return 0;
2786}
2787
Damien Lespiaub7cec662015-10-27 14:47:01 +02002788static int i915_dmc_info(struct seq_file *m, void *unused)
2789{
2790 struct drm_info_node *node = m->private;
2791 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002792 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002793 struct intel_csr *csr;
2794
2795 if (!HAS_CSR(dev)) {
2796 seq_puts(m, "not supported\n");
2797 return 0;
2798 }
2799
2800 csr = &dev_priv->csr;
2801
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002802 intel_runtime_pm_get(dev_priv);
2803
Damien Lespiaub7cec662015-10-27 14:47:01 +02002804 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2805 seq_printf(m, "path: %s\n", csr->fw_path);
2806
2807 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002808 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002809
2810 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2811 CSR_VERSION_MINOR(csr->version));
2812
Damien Lespiau83372062015-10-30 17:53:32 +02002813 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2814 seq_printf(m, "DC3 -> DC5 count: %d\n",
2815 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2816 seq_printf(m, "DC5 -> DC6 count: %d\n",
2817 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002818 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2819 seq_printf(m, "DC3 -> DC5 count: %d\n",
2820 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002821 }
2822
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002823out:
2824 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2825 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2826 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2827
Damien Lespiau83372062015-10-30 17:53:32 +02002828 intel_runtime_pm_put(dev_priv);
2829
Damien Lespiaub7cec662015-10-27 14:47:01 +02002830 return 0;
2831}
2832
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002833static void intel_seq_print_mode(struct seq_file *m, int tabs,
2834 struct drm_display_mode *mode)
2835{
2836 int i;
2837
2838 for (i = 0; i < tabs; i++)
2839 seq_putc(m, '\t');
2840
2841 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",
2842 mode->base.id, mode->name,
2843 mode->vrefresh, mode->clock,
2844 mode->hdisplay, mode->hsync_start,
2845 mode->hsync_end, mode->htotal,
2846 mode->vdisplay, mode->vsync_start,
2847 mode->vsync_end, mode->vtotal,
2848 mode->type, mode->flags);
2849}
2850
2851static void intel_encoder_info(struct seq_file *m,
2852 struct intel_crtc *intel_crtc,
2853 struct intel_encoder *intel_encoder)
2854{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002855 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002856 struct drm_device *dev = node->minor->dev;
2857 struct drm_crtc *crtc = &intel_crtc->base;
2858 struct intel_connector *intel_connector;
2859 struct drm_encoder *encoder;
2860
2861 encoder = &intel_encoder->base;
2862 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002863 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002864 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2865 struct drm_connector *connector = &intel_connector->base;
2866 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2867 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002868 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002869 drm_get_connector_status_name(connector->status));
2870 if (connector->status == connector_status_connected) {
2871 struct drm_display_mode *mode = &crtc->mode;
2872 seq_printf(m, ", mode:\n");
2873 intel_seq_print_mode(m, 2, mode);
2874 } else {
2875 seq_putc(m, '\n');
2876 }
2877 }
2878}
2879
2880static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2881{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002882 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002883 struct drm_device *dev = node->minor->dev;
2884 struct drm_crtc *crtc = &intel_crtc->base;
2885 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002886 struct drm_plane_state *plane_state = crtc->primary->state;
2887 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002888
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002889 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002890 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002891 fb->base.id, plane_state->src_x >> 16,
2892 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002893 else
2894 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002895 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2896 intel_encoder_info(m, intel_crtc, intel_encoder);
2897}
2898
2899static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2900{
2901 struct drm_display_mode *mode = panel->fixed_mode;
2902
2903 seq_printf(m, "\tfixed mode:\n");
2904 intel_seq_print_mode(m, 2, mode);
2905}
2906
2907static void intel_dp_info(struct seq_file *m,
2908 struct intel_connector *intel_connector)
2909{
2910 struct intel_encoder *intel_encoder = intel_connector->encoder;
2911 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2912
2913 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002914 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002915 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002916 intel_panel_info(m, &intel_connector->panel);
2917}
2918
2919static void intel_hdmi_info(struct seq_file *m,
2920 struct intel_connector *intel_connector)
2921{
2922 struct intel_encoder *intel_encoder = intel_connector->encoder;
2923 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2924
Jani Nikula742f4912015-09-03 11:16:09 +03002925 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002926}
2927
2928static void intel_lvds_info(struct seq_file *m,
2929 struct intel_connector *intel_connector)
2930{
2931 intel_panel_info(m, &intel_connector->panel);
2932}
2933
2934static void intel_connector_info(struct seq_file *m,
2935 struct drm_connector *connector)
2936{
2937 struct intel_connector *intel_connector = to_intel_connector(connector);
2938 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002939 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002940
2941 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002942 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002943 drm_get_connector_status_name(connector->status));
2944 if (connector->status == connector_status_connected) {
2945 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2946 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2947 connector->display_info.width_mm,
2948 connector->display_info.height_mm);
2949 seq_printf(m, "\tsubpixel order: %s\n",
2950 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2951 seq_printf(m, "\tCEA rev: %d\n",
2952 connector->display_info.cea_rev);
2953 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002954
2955 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2956 return;
2957
2958 switch (connector->connector_type) {
2959 case DRM_MODE_CONNECTOR_DisplayPort:
2960 case DRM_MODE_CONNECTOR_eDP:
2961 intel_dp_info(m, intel_connector);
2962 break;
2963 case DRM_MODE_CONNECTOR_LVDS:
2964 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002965 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002966 break;
2967 case DRM_MODE_CONNECTOR_HDMIA:
2968 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2969 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2970 intel_hdmi_info(m, intel_connector);
2971 break;
2972 default:
2973 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002974 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002975
Jesse Barnesf103fc72014-02-20 12:39:57 -08002976 seq_printf(m, "\tmodes:\n");
2977 list_for_each_entry(mode, &connector->modes, head)
2978 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002979}
2980
Chris Wilson065f2ec22014-03-12 09:13:13 +00002981static bool cursor_active(struct drm_device *dev, int pipe)
2982{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002983 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec22014-03-12 09:13:13 +00002984 u32 state;
2985
2986 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002987 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002988 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002989 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002990
2991 return state;
2992}
2993
2994static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2995{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002996 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec22014-03-12 09:13:13 +00002997 u32 pos;
2998
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002999 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00003000
3001 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3002 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3003 *x = -*x;
3004
3005 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3006 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3007 *y = -*y;
3008
3009 return cursor_active(dev, pipe);
3010}
3011
Robert Fekete3abc4e02015-10-27 16:58:32 +01003012static const char *plane_type(enum drm_plane_type type)
3013{
3014 switch (type) {
3015 case DRM_PLANE_TYPE_OVERLAY:
3016 return "OVL";
3017 case DRM_PLANE_TYPE_PRIMARY:
3018 return "PRI";
3019 case DRM_PLANE_TYPE_CURSOR:
3020 return "CUR";
3021 /*
3022 * Deliberately omitting default: to generate compiler warnings
3023 * when a new drm_plane_type gets added.
3024 */
3025 }
3026
3027 return "unknown";
3028}
3029
3030static const char *plane_rotation(unsigned int rotation)
3031{
3032 static char buf[48];
3033 /*
3034 * According to doc only one DRM_ROTATE_ is allowed but this
3035 * will print them all to visualize if the values are misused
3036 */
3037 snprintf(buf, sizeof(buf),
3038 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003039 (rotation & DRM_ROTATE_0) ? "0 " : "",
3040 (rotation & DRM_ROTATE_90) ? "90 " : "",
3041 (rotation & DRM_ROTATE_180) ? "180 " : "",
3042 (rotation & DRM_ROTATE_270) ? "270 " : "",
3043 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3044 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003045 rotation);
3046
3047 return buf;
3048}
3049
3050static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3051{
3052 struct drm_info_node *node = m->private;
3053 struct drm_device *dev = node->minor->dev;
3054 struct intel_plane *intel_plane;
3055
3056 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3057 struct drm_plane_state *state;
3058 struct drm_plane *plane = &intel_plane->base;
3059
3060 if (!plane->state) {
3061 seq_puts(m, "plane->state is NULL!\n");
3062 continue;
3063 }
3064
3065 state = plane->state;
3066
3067 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",
3068 plane->base.id,
3069 plane_type(intel_plane->base.type),
3070 state->crtc_x, state->crtc_y,
3071 state->crtc_w, state->crtc_h,
3072 (state->src_x >> 16),
3073 ((state->src_x & 0xffff) * 15625) >> 10,
3074 (state->src_y >> 16),
3075 ((state->src_y & 0xffff) * 15625) >> 10,
3076 (state->src_w >> 16),
3077 ((state->src_w & 0xffff) * 15625) >> 10,
3078 (state->src_h >> 16),
3079 ((state->src_h & 0xffff) * 15625) >> 10,
3080 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3081 plane_rotation(state->rotation));
3082 }
3083}
3084
3085static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3086{
3087 struct intel_crtc_state *pipe_config;
3088 int num_scalers = intel_crtc->num_scalers;
3089 int i;
3090
3091 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3092
3093 /* Not all platformas have a scaler */
3094 if (num_scalers) {
3095 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3096 num_scalers,
3097 pipe_config->scaler_state.scaler_users,
3098 pipe_config->scaler_state.scaler_id);
3099
3100 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3101 struct intel_scaler *sc =
3102 &pipe_config->scaler_state.scalers[i];
3103
3104 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3105 i, yesno(sc->in_use), sc->mode);
3106 }
3107 seq_puts(m, "\n");
3108 } else {
3109 seq_puts(m, "\tNo scalers available on this platform\n");
3110 }
3111}
3112
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003113static int i915_display_info(struct seq_file *m, void *unused)
3114{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003115 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003116 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003117 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec22014-03-12 09:13:13 +00003118 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003119 struct drm_connector *connector;
3120
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003121 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003122 drm_modeset_lock_all(dev);
3123 seq_printf(m, "CRTC info\n");
3124 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003125 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003126 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003127 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003128 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003129
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003130 pipe_config = to_intel_crtc_state(crtc->base.state);
3131
Robert Fekete3abc4e02015-10-27 16:58:32 +01003132 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003133 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003134 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003135 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3136 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3137
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003138 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003139 intel_crtc_info(m, crtc);
3140
Paulo Zanonia23dc652014-04-01 14:55:11 -03003141 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003142 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 +03003143 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003144 x, y, crtc->base.cursor->state->crtc_w,
3145 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003146 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003147 intel_scaler_info(m, crtc);
3148 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003149 }
Daniel Vettercace8412014-05-22 17:56:31 +02003150
3151 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3152 yesno(!crtc->cpu_fifo_underrun_disabled),
3153 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003154 }
3155
3156 seq_printf(m, "\n");
3157 seq_printf(m, "Connector info\n");
3158 seq_printf(m, "--------------\n");
3159 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3160 intel_connector_info(m, connector);
3161 }
3162 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003163 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003164
3165 return 0;
3166}
3167
Ben Widawskye04934c2014-06-30 09:53:42 -07003168static int i915_semaphore_status(struct seq_file *m, void *unused)
3169{
3170 struct drm_info_node *node = (struct drm_info_node *) m->private;
3171 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003172 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003173 struct intel_engine_cs *engine;
Tvrtko Ursulinc1bb1142016-08-10 16:22:10 +01003174 int num_rings = INTEL_INFO(dev)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003175 enum intel_engine_id id;
3176 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003177
Chris Wilson39df9192016-07-20 13:31:57 +01003178 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003179 seq_puts(m, "Semaphores are disabled\n");
3180 return 0;
3181 }
3182
3183 ret = mutex_lock_interruptible(&dev->struct_mutex);
3184 if (ret)
3185 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003186 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003187
3188 if (IS_BROADWELL(dev)) {
3189 struct page *page;
3190 uint64_t *seqno;
3191
3192 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3193
3194 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003195 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003196 uint64_t offset;
3197
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003198 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003199
3200 seq_puts(m, " Last signal:");
3201 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003202 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003203 seq_printf(m, "0x%08llx (0x%02llx) ",
3204 seqno[offset], offset * 8);
3205 }
3206 seq_putc(m, '\n');
3207
3208 seq_puts(m, " Last wait: ");
3209 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003210 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003211 seq_printf(m, "0x%08llx (0x%02llx) ",
3212 seqno[offset], offset * 8);
3213 }
3214 seq_putc(m, '\n');
3215
3216 }
3217 kunmap_atomic(seqno);
3218 } else {
3219 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003220 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003221 for (j = 0; j < num_rings; j++)
3222 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003223 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003224 seq_putc(m, '\n');
3225 }
3226
3227 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003228 for_each_engine(engine, dev_priv) {
3229 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003230 seq_printf(m, " 0x%08x ",
3231 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003232 seq_putc(m, '\n');
3233 }
3234 seq_putc(m, '\n');
3235
Paulo Zanoni03872062014-07-09 14:31:57 -03003236 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003237 mutex_unlock(&dev->struct_mutex);
3238 return 0;
3239}
3240
Daniel Vetter728e29d2014-06-25 22:01:53 +03003241static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3242{
3243 struct drm_info_node *node = (struct drm_info_node *) m->private;
3244 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003245 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003246 int i;
3247
3248 drm_modeset_lock_all(dev);
3249 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3250 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3251
3252 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003253 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3254 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003255 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003256 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3257 seq_printf(m, " dpll_md: 0x%08x\n",
3258 pll->config.hw_state.dpll_md);
3259 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3260 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3261 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003262 }
3263 drm_modeset_unlock_all(dev);
3264
3265 return 0;
3266}
3267
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003268static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003269{
3270 int i;
3271 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003272 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003273 struct drm_info_node *node = (struct drm_info_node *) m->private;
3274 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003275 struct drm_i915_private *dev_priv = to_i915(dev);
Arun Siluvery33136b02016-01-21 21:43:47 +00003276 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003277 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003278
Arun Siluvery888b5992014-08-26 14:44:51 +01003279 ret = mutex_lock_interruptible(&dev->struct_mutex);
3280 if (ret)
3281 return ret;
3282
3283 intel_runtime_pm_get(dev_priv);
3284
Arun Siluvery33136b02016-01-21 21:43:47 +00003285 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003286 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003287 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003288 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003289 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003290 i915_reg_t addr;
3291 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003292 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003293
Arun Siluvery33136b02016-01-21 21:43:47 +00003294 addr = workarounds->reg[i].addr;
3295 mask = workarounds->reg[i].mask;
3296 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003297 read = I915_READ(addr);
3298 ok = (value & mask) == (read & mask);
3299 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 +02003300 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003301 }
3302
3303 intel_runtime_pm_put(dev_priv);
3304 mutex_unlock(&dev->struct_mutex);
3305
3306 return 0;
3307}
3308
Damien Lespiauc5511e42014-11-04 17:06:51 +00003309static int i915_ddb_info(struct seq_file *m, void *unused)
3310{
3311 struct drm_info_node *node = m->private;
3312 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003313 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiauc5511e42014-11-04 17:06:51 +00003314 struct skl_ddb_allocation *ddb;
3315 struct skl_ddb_entry *entry;
3316 enum pipe pipe;
3317 int plane;
3318
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003319 if (INTEL_INFO(dev)->gen < 9)
3320 return 0;
3321
Damien Lespiauc5511e42014-11-04 17:06:51 +00003322 drm_modeset_lock_all(dev);
3323
3324 ddb = &dev_priv->wm.skl_hw.ddb;
3325
3326 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3327
3328 for_each_pipe(dev_priv, pipe) {
3329 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3330
Damien Lespiaudd740782015-02-28 14:54:08 +00003331 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003332 entry = &ddb->plane[pipe][plane];
3333 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3334 entry->start, entry->end,
3335 skl_ddb_entry_size(entry));
3336 }
3337
Matt Roper4969d332015-09-24 15:53:10 -07003338 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003339 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3340 entry->end, skl_ddb_entry_size(entry));
3341 }
3342
3343 drm_modeset_unlock_all(dev);
3344
3345 return 0;
3346}
3347
Vandana Kannana54746e2015-03-03 20:53:10 +05303348static void drrs_status_per_crtc(struct seq_file *m,
3349 struct drm_device *dev, struct intel_crtc *intel_crtc)
3350{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003351 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303352 struct i915_drrs *drrs = &dev_priv->drrs;
3353 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003354 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303355
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003356 drm_for_each_connector(connector, dev) {
3357 if (connector->state->crtc != &intel_crtc->base)
3358 continue;
3359
3360 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303361 }
3362
3363 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3364 seq_puts(m, "\tVBT: DRRS_type: Static");
3365 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3366 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3367 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3368 seq_puts(m, "\tVBT: DRRS_type: None");
3369 else
3370 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3371
3372 seq_puts(m, "\n\n");
3373
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003374 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303375 struct intel_panel *panel;
3376
3377 mutex_lock(&drrs->mutex);
3378 /* DRRS Supported */
3379 seq_puts(m, "\tDRRS Supported: Yes\n");
3380
3381 /* disable_drrs() will make drrs->dp NULL */
3382 if (!drrs->dp) {
3383 seq_puts(m, "Idleness DRRS: Disabled");
3384 mutex_unlock(&drrs->mutex);
3385 return;
3386 }
3387
3388 panel = &drrs->dp->attached_connector->panel;
3389 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3390 drrs->busy_frontbuffer_bits);
3391
3392 seq_puts(m, "\n\t\t");
3393 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3394 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3395 vrefresh = panel->fixed_mode->vrefresh;
3396 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3397 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3398 vrefresh = panel->downclock_mode->vrefresh;
3399 } else {
3400 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3401 drrs->refresh_rate_type);
3402 mutex_unlock(&drrs->mutex);
3403 return;
3404 }
3405 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3406
3407 seq_puts(m, "\n\t\t");
3408 mutex_unlock(&drrs->mutex);
3409 } else {
3410 /* DRRS not supported. Print the VBT parameter*/
3411 seq_puts(m, "\tDRRS Supported : No");
3412 }
3413 seq_puts(m, "\n");
3414}
3415
3416static int i915_drrs_status(struct seq_file *m, void *unused)
3417{
3418 struct drm_info_node *node = m->private;
3419 struct drm_device *dev = node->minor->dev;
3420 struct intel_crtc *intel_crtc;
3421 int active_crtc_cnt = 0;
3422
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003423 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303424 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003425 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303426 active_crtc_cnt++;
3427 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3428
3429 drrs_status_per_crtc(m, dev, intel_crtc);
3430 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303431 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003432 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303433
3434 if (!active_crtc_cnt)
3435 seq_puts(m, "No active crtc found\n");
3436
3437 return 0;
3438}
3439
Damien Lespiau07144422013-10-15 18:55:40 +01003440struct pipe_crc_info {
3441 const char *name;
3442 struct drm_device *dev;
3443 enum pipe pipe;
3444};
3445
Dave Airlie11bed952014-05-12 15:22:27 +10003446static int i915_dp_mst_info(struct seq_file *m, void *unused)
3447{
3448 struct drm_info_node *node = (struct drm_info_node *) m->private;
3449 struct drm_device *dev = node->minor->dev;
Dave Airlie11bed952014-05-12 15:22:27 +10003450 struct intel_encoder *intel_encoder;
3451 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003452 struct drm_connector *connector;
3453
Dave Airlie11bed952014-05-12 15:22:27 +10003454 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003455 drm_for_each_connector(connector, dev) {
3456 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003457 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003458
3459 intel_encoder = intel_attached_encoder(connector);
3460 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3461 continue;
3462
3463 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003464 if (!intel_dig_port->dp.can_mst)
3465 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003466
Jim Bride40ae80c2016-04-14 10:18:37 -07003467 seq_printf(m, "MST Source Port %c\n",
3468 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003469 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3470 }
3471 drm_modeset_unlock_all(dev);
3472 return 0;
3473}
3474
Damien Lespiau07144422013-10-15 18:55:40 +01003475static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003476{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003477 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003478 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003479 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3480
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003481 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3482 return -ENODEV;
3483
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003484 spin_lock_irq(&pipe_crc->lock);
3485
3486 if (pipe_crc->opened) {
3487 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003488 return -EBUSY; /* already open */
3489 }
3490
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003491 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003492 filep->private_data = inode->i_private;
3493
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003494 spin_unlock_irq(&pipe_crc->lock);
3495
Damien Lespiau07144422013-10-15 18:55:40 +01003496 return 0;
3497}
3498
3499static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3500{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003501 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003502 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003503 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3504
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003505 spin_lock_irq(&pipe_crc->lock);
3506 pipe_crc->opened = false;
3507 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003508
Damien Lespiau07144422013-10-15 18:55:40 +01003509 return 0;
3510}
3511
3512/* (6 fields, 8 chars each, space separated (5) + '\n') */
3513#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3514/* account for \'0' */
3515#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3516
3517static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3518{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003519 assert_spin_locked(&pipe_crc->lock);
3520 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3521 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003522}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003523
Damien Lespiau07144422013-10-15 18:55:40 +01003524static ssize_t
3525i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3526 loff_t *pos)
3527{
3528 struct pipe_crc_info *info = filep->private_data;
3529 struct drm_device *dev = info->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003530 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003531 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3532 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003533 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003534 ssize_t bytes_read;
3535
3536 /*
3537 * Don't allow user space to provide buffers not big enough to hold
3538 * a line of data.
3539 */
3540 if (count < PIPE_CRC_LINE_LEN)
3541 return -EINVAL;
3542
3543 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3544 return 0;
3545
3546 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003547 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003548 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003549 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003550
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003551 if (filep->f_flags & O_NONBLOCK) {
3552 spin_unlock_irq(&pipe_crc->lock);
3553 return -EAGAIN;
3554 }
3555
3556 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3557 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3558 if (ret) {
3559 spin_unlock_irq(&pipe_crc->lock);
3560 return ret;
3561 }
Damien Lespiau07144422013-10-15 18:55:40 +01003562 }
3563
3564 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003565 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003566
Damien Lespiau07144422013-10-15 18:55:40 +01003567 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003568 while (n_entries > 0) {
3569 struct intel_pipe_crc_entry *entry =
3570 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003571
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003572 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3573 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3574 break;
3575
3576 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3577 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3578
Damien Lespiau07144422013-10-15 18:55:40 +01003579 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3580 "%8u %8x %8x %8x %8x %8x\n",
3581 entry->frame, entry->crc[0],
3582 entry->crc[1], entry->crc[2],
3583 entry->crc[3], entry->crc[4]);
3584
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003585 spin_unlock_irq(&pipe_crc->lock);
3586
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003587 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003588 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003589
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003590 user_buf += PIPE_CRC_LINE_LEN;
3591 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003592
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003593 spin_lock_irq(&pipe_crc->lock);
3594 }
3595
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003596 spin_unlock_irq(&pipe_crc->lock);
3597
Damien Lespiau07144422013-10-15 18:55:40 +01003598 return bytes_read;
3599}
3600
3601static const struct file_operations i915_pipe_crc_fops = {
3602 .owner = THIS_MODULE,
3603 .open = i915_pipe_crc_open,
3604 .read = i915_pipe_crc_read,
3605 .release = i915_pipe_crc_release,
3606};
3607
3608static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3609 {
3610 .name = "i915_pipe_A_crc",
3611 .pipe = PIPE_A,
3612 },
3613 {
3614 .name = "i915_pipe_B_crc",
3615 .pipe = PIPE_B,
3616 },
3617 {
3618 .name = "i915_pipe_C_crc",
3619 .pipe = PIPE_C,
3620 },
3621};
3622
3623static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3624 enum pipe pipe)
3625{
3626 struct drm_device *dev = minor->dev;
3627 struct dentry *ent;
3628 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3629
3630 info->dev = dev;
3631 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3632 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003633 if (!ent)
3634 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003635
3636 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003637}
3638
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003639static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003640 "none",
3641 "plane1",
3642 "plane2",
3643 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003644 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003645 "TV",
3646 "DP-B",
3647 "DP-C",
3648 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003649 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003650};
3651
3652static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3653{
3654 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3655 return pipe_crc_sources[source];
3656}
3657
Damien Lespiaubd9db022013-10-15 18:55:36 +01003658static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003659{
3660 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003661 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003662 int i;
3663
3664 for (i = 0; i < I915_MAX_PIPES; i++)
3665 seq_printf(m, "%c %s\n", pipe_name(i),
3666 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3667
3668 return 0;
3669}
3670
Damien Lespiaubd9db022013-10-15 18:55:36 +01003671static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003672{
3673 struct drm_device *dev = inode->i_private;
3674
Damien Lespiaubd9db022013-10-15 18:55:36 +01003675 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003676}
3677
Daniel Vetter46a19182013-11-01 10:50:20 +01003678static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003679 uint32_t *val)
3680{
Daniel Vetter46a19182013-11-01 10:50:20 +01003681 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3682 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3683
3684 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003685 case INTEL_PIPE_CRC_SOURCE_PIPE:
3686 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3687 break;
3688 case INTEL_PIPE_CRC_SOURCE_NONE:
3689 *val = 0;
3690 break;
3691 default:
3692 return -EINVAL;
3693 }
3694
3695 return 0;
3696}
3697
Daniel Vetter46a19182013-11-01 10:50:20 +01003698static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3699 enum intel_pipe_crc_source *source)
3700{
3701 struct intel_encoder *encoder;
3702 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003703 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003704 int ret = 0;
3705
3706 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3707
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003708 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003709 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003710 if (!encoder->base.crtc)
3711 continue;
3712
3713 crtc = to_intel_crtc(encoder->base.crtc);
3714
3715 if (crtc->pipe != pipe)
3716 continue;
3717
3718 switch (encoder->type) {
3719 case INTEL_OUTPUT_TVOUT:
3720 *source = INTEL_PIPE_CRC_SOURCE_TV;
3721 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003722 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003723 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003724 dig_port = enc_to_dig_port(&encoder->base);
3725 switch (dig_port->port) {
3726 case PORT_B:
3727 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3728 break;
3729 case PORT_C:
3730 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3731 break;
3732 case PORT_D:
3733 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3734 break;
3735 default:
3736 WARN(1, "nonexisting DP port %c\n",
3737 port_name(dig_port->port));
3738 break;
3739 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003740 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003741 default:
3742 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003743 }
3744 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003745 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003746
3747 return ret;
3748}
3749
3750static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3751 enum pipe pipe,
3752 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003753 uint32_t *val)
3754{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003755 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003756 bool need_stable_symbols = false;
3757
Daniel Vetter46a19182013-11-01 10:50:20 +01003758 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3759 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3760 if (ret)
3761 return ret;
3762 }
3763
3764 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003765 case INTEL_PIPE_CRC_SOURCE_PIPE:
3766 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3767 break;
3768 case INTEL_PIPE_CRC_SOURCE_DP_B:
3769 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003770 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003771 break;
3772 case INTEL_PIPE_CRC_SOURCE_DP_C:
3773 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003774 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003775 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003776 case INTEL_PIPE_CRC_SOURCE_DP_D:
3777 if (!IS_CHERRYVIEW(dev))
3778 return -EINVAL;
3779 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3780 need_stable_symbols = true;
3781 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003782 case INTEL_PIPE_CRC_SOURCE_NONE:
3783 *val = 0;
3784 break;
3785 default:
3786 return -EINVAL;
3787 }
3788
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003789 /*
3790 * When the pipe CRC tap point is after the transcoders we need
3791 * to tweak symbol-level features to produce a deterministic series of
3792 * symbols for a given frame. We need to reset those features only once
3793 * a frame (instead of every nth symbol):
3794 * - DC-balance: used to ensure a better clock recovery from the data
3795 * link (SDVO)
3796 * - DisplayPort scrambling: used for EMI reduction
3797 */
3798 if (need_stable_symbols) {
3799 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3800
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003801 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003802 switch (pipe) {
3803 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003804 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003805 break;
3806 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003807 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003808 break;
3809 case PIPE_C:
3810 tmp |= PIPE_C_SCRAMBLE_RESET;
3811 break;
3812 default:
3813 return -EINVAL;
3814 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003815 I915_WRITE(PORT_DFT2_G4X, tmp);
3816 }
3817
Daniel Vetter7ac01292013-10-18 16:37:06 +02003818 return 0;
3819}
3820
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003821static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003822 enum pipe pipe,
3823 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003824 uint32_t *val)
3825{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003826 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003827 bool need_stable_symbols = false;
3828
Daniel Vetter46a19182013-11-01 10:50:20 +01003829 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3830 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3831 if (ret)
3832 return ret;
3833 }
3834
3835 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003836 case INTEL_PIPE_CRC_SOURCE_PIPE:
3837 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3838 break;
3839 case INTEL_PIPE_CRC_SOURCE_TV:
3840 if (!SUPPORTS_TV(dev))
3841 return -EINVAL;
3842 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3843 break;
3844 case INTEL_PIPE_CRC_SOURCE_DP_B:
3845 if (!IS_G4X(dev))
3846 return -EINVAL;
3847 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003848 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003849 break;
3850 case INTEL_PIPE_CRC_SOURCE_DP_C:
3851 if (!IS_G4X(dev))
3852 return -EINVAL;
3853 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003854 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003855 break;
3856 case INTEL_PIPE_CRC_SOURCE_DP_D:
3857 if (!IS_G4X(dev))
3858 return -EINVAL;
3859 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003860 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003861 break;
3862 case INTEL_PIPE_CRC_SOURCE_NONE:
3863 *val = 0;
3864 break;
3865 default:
3866 return -EINVAL;
3867 }
3868
Daniel Vetter84093602013-11-01 10:50:21 +01003869 /*
3870 * When the pipe CRC tap point is after the transcoders we need
3871 * to tweak symbol-level features to produce a deterministic series of
3872 * symbols for a given frame. We need to reset those features only once
3873 * a frame (instead of every nth symbol):
3874 * - DC-balance: used to ensure a better clock recovery from the data
3875 * link (SDVO)
3876 * - DisplayPort scrambling: used for EMI reduction
3877 */
3878 if (need_stable_symbols) {
3879 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3880
3881 WARN_ON(!IS_G4X(dev));
3882
3883 I915_WRITE(PORT_DFT_I9XX,
3884 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3885
3886 if (pipe == PIPE_A)
3887 tmp |= PIPE_A_SCRAMBLE_RESET;
3888 else
3889 tmp |= PIPE_B_SCRAMBLE_RESET;
3890
3891 I915_WRITE(PORT_DFT2_G4X, tmp);
3892 }
3893
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003894 return 0;
3895}
3896
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003897static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3898 enum pipe pipe)
3899{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003900 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003901 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3902
Ville Syrjäläeb736672014-12-09 21:28:28 +02003903 switch (pipe) {
3904 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003905 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003906 break;
3907 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003908 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003909 break;
3910 case PIPE_C:
3911 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3912 break;
3913 default:
3914 return;
3915 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003916 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3917 tmp &= ~DC_BALANCE_RESET_VLV;
3918 I915_WRITE(PORT_DFT2_G4X, tmp);
3919
3920}
3921
Daniel Vetter84093602013-11-01 10:50:21 +01003922static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3923 enum pipe pipe)
3924{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003925 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003926 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3927
3928 if (pipe == PIPE_A)
3929 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3930 else
3931 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3932 I915_WRITE(PORT_DFT2_G4X, tmp);
3933
3934 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3935 I915_WRITE(PORT_DFT_I9XX,
3936 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3937 }
3938}
3939
Daniel Vetter46a19182013-11-01 10:50:20 +01003940static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003941 uint32_t *val)
3942{
Daniel Vetter46a19182013-11-01 10:50:20 +01003943 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3944 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3945
3946 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003947 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3948 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3949 break;
3950 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3951 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3952 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003953 case INTEL_PIPE_CRC_SOURCE_PIPE:
3954 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3955 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003956 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003957 *val = 0;
3958 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003959 default:
3960 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003961 }
3962
3963 return 0;
3964}
3965
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003966static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003967{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003968 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003969 struct intel_crtc *crtc =
3970 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003971 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003972 struct drm_atomic_state *state;
3973 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003974
3975 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003976 state = drm_atomic_state_alloc(dev);
3977 if (!state) {
3978 ret = -ENOMEM;
3979 goto out;
3980 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003981
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003982 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3983 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3984 if (IS_ERR(pipe_config)) {
3985 ret = PTR_ERR(pipe_config);
3986 goto out;
3987 }
3988
3989 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003990 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003991 pipe_config->pch_pfit.enabled != enable)
3992 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003993
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003994 ret = drm_atomic_commit(state);
3995out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003996 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003997 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3998 if (ret)
3999 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004000}
4001
4002static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4003 enum pipe pipe,
4004 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004005 uint32_t *val)
4006{
Daniel Vetter46a19182013-11-01 10:50:20 +01004007 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4008 *source = INTEL_PIPE_CRC_SOURCE_PF;
4009
4010 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004011 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4012 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4013 break;
4014 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4015 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4016 break;
4017 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004018 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004019 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004020
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004021 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4022 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004023 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004024 *val = 0;
4025 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004026 default:
4027 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004028 }
4029
4030 return 0;
4031}
4032
Daniel Vetter926321d2013-10-16 13:30:34 +02004033static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4034 enum intel_pipe_crc_source source)
4035{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004036 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaucc3da172013-10-15 18:55:31 +01004037 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004038 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4039 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004040 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004041 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004042 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004043
Damien Lespiaucc3da172013-10-15 18:55:31 +01004044 if (pipe_crc->source == source)
4045 return 0;
4046
Damien Lespiauae676fc2013-10-15 18:55:32 +01004047 /* forbid changing the source without going back to 'none' */
4048 if (pipe_crc->source && source)
4049 return -EINVAL;
4050
Imre Deake1296492016-02-12 18:55:17 +02004051 power_domain = POWER_DOMAIN_PIPE(pipe);
4052 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004053 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4054 return -EIO;
4055 }
4056
Daniel Vetter52f843f2013-10-21 17:26:38 +02004057 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004058 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004059 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004060 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004061 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004062 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004063 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004064 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004065 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004066 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004067
4068 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004069 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004070
Damien Lespiau4b584362013-10-15 18:55:33 +01004071 /* none -> real source transition */
4072 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004073 struct intel_pipe_crc_entry *entries;
4074
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004075 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4076 pipe_name(pipe), pipe_crc_source_name(source));
4077
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004078 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4079 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004080 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004081 if (!entries) {
4082 ret = -ENOMEM;
4083 goto out;
4084 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004085
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004086 /*
4087 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4088 * enabled and disabled dynamically based on package C states,
4089 * user space can't make reliable use of the CRCs, so let's just
4090 * completely disable it.
4091 */
4092 hsw_disable_ips(crtc);
4093
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004094 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004095 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004096 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004097 pipe_crc->head = 0;
4098 pipe_crc->tail = 0;
4099 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004100 }
4101
Damien Lespiaucc3da172013-10-15 18:55:31 +01004102 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004103
Daniel Vetter926321d2013-10-16 13:30:34 +02004104 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4105 POSTING_READ(PIPE_CRC_CTL(pipe));
4106
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004107 /* real source -> none transition */
4108 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004109 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004110 struct intel_crtc *crtc =
4111 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004112
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004113 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4114 pipe_name(pipe));
4115
Daniel Vettera33d7102014-06-06 08:22:08 +02004116 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004117 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004118 intel_wait_for_vblank(dev, pipe);
4119 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004120
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004121 spin_lock_irq(&pipe_crc->lock);
4122 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004123 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004124 pipe_crc->head = 0;
4125 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004126 spin_unlock_irq(&pipe_crc->lock);
4127
4128 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004129
4130 if (IS_G4X(dev))
4131 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004132 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004133 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004134 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004135 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004136
4137 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004138 }
4139
Imre Deake1296492016-02-12 18:55:17 +02004140 ret = 0;
4141
4142out:
4143 intel_display_power_put(dev_priv, power_domain);
4144
4145 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004146}
4147
4148/*
4149 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004150 * command: wsp* object wsp+ name wsp+ source wsp*
4151 * object: 'pipe'
4152 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004153 * source: (none | plane1 | plane2 | pf)
4154 * wsp: (#0x20 | #0x9 | #0xA)+
4155 *
4156 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004157 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4158 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004159 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004160static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004161{
4162 int n_words = 0;
4163
4164 while (*buf) {
4165 char *end;
4166
4167 /* skip leading white space */
4168 buf = skip_spaces(buf);
4169 if (!*buf)
4170 break; /* end of buffer */
4171
4172 /* find end of word */
4173 for (end = buf; *end && !isspace(*end); end++)
4174 ;
4175
4176 if (n_words == max_words) {
4177 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4178 max_words);
4179 return -EINVAL; /* ran out of words[] before bytes */
4180 }
4181
4182 if (*end)
4183 *end++ = '\0';
4184 words[n_words++] = buf;
4185 buf = end;
4186 }
4187
4188 return n_words;
4189}
4190
Damien Lespiaub94dec82013-10-15 18:55:35 +01004191enum intel_pipe_crc_object {
4192 PIPE_CRC_OBJECT_PIPE,
4193};
4194
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004195static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004196 "pipe",
4197};
4198
4199static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004200display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004201{
4202 int i;
4203
4204 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4205 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004206 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004207 return 0;
4208 }
4209
4210 return -EINVAL;
4211}
4212
Damien Lespiaubd9db022013-10-15 18:55:36 +01004213static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004214{
4215 const char name = buf[0];
4216
4217 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4218 return -EINVAL;
4219
4220 *pipe = name - 'A';
4221
4222 return 0;
4223}
4224
4225static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004226display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004227{
4228 int i;
4229
4230 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4231 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004232 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004233 return 0;
4234 }
4235
4236 return -EINVAL;
4237}
4238
Damien Lespiaubd9db022013-10-15 18:55:36 +01004239static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004240{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004241#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004242 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004243 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004244 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004245 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004246 enum intel_pipe_crc_source source;
4247
Damien Lespiaubd9db022013-10-15 18:55:36 +01004248 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004249 if (n_words != N_WORDS) {
4250 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4251 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004252 return -EINVAL;
4253 }
4254
Damien Lespiaubd9db022013-10-15 18:55:36 +01004255 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004256 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004257 return -EINVAL;
4258 }
4259
Damien Lespiaubd9db022013-10-15 18:55:36 +01004260 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004261 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4262 return -EINVAL;
4263 }
4264
Damien Lespiaubd9db022013-10-15 18:55:36 +01004265 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004266 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004267 return -EINVAL;
4268 }
4269
4270 return pipe_crc_set_source(dev, pipe, source);
4271}
4272
Damien Lespiaubd9db022013-10-15 18:55:36 +01004273static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4274 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004275{
4276 struct seq_file *m = file->private_data;
4277 struct drm_device *dev = m->private;
4278 char *tmpbuf;
4279 int ret;
4280
4281 if (len == 0)
4282 return 0;
4283
4284 if (len > PAGE_SIZE - 1) {
4285 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4286 PAGE_SIZE);
4287 return -E2BIG;
4288 }
4289
4290 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4291 if (!tmpbuf)
4292 return -ENOMEM;
4293
4294 if (copy_from_user(tmpbuf, ubuf, len)) {
4295 ret = -EFAULT;
4296 goto out;
4297 }
4298 tmpbuf[len] = '\0';
4299
Damien Lespiaubd9db022013-10-15 18:55:36 +01004300 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004301
4302out:
4303 kfree(tmpbuf);
4304 if (ret < 0)
4305 return ret;
4306
4307 *offp += len;
4308 return len;
4309}
4310
Damien Lespiaubd9db022013-10-15 18:55:36 +01004311static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004312 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004313 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004314 .read = seq_read,
4315 .llseek = seq_lseek,
4316 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004317 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004318};
4319
Todd Previteeb3394fa2015-04-18 00:04:19 -07004320static ssize_t i915_displayport_test_active_write(struct file *file,
4321 const char __user *ubuf,
4322 size_t len, loff_t *offp)
4323{
4324 char *input_buffer;
4325 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004326 struct drm_device *dev;
4327 struct drm_connector *connector;
4328 struct list_head *connector_list;
4329 struct intel_dp *intel_dp;
4330 int val = 0;
4331
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304332 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004333
Todd Previteeb3394fa2015-04-18 00:04:19 -07004334 connector_list = &dev->mode_config.connector_list;
4335
4336 if (len == 0)
4337 return 0;
4338
4339 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4340 if (!input_buffer)
4341 return -ENOMEM;
4342
4343 if (copy_from_user(input_buffer, ubuf, len)) {
4344 status = -EFAULT;
4345 goto out;
4346 }
4347
4348 input_buffer[len] = '\0';
4349 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4350
4351 list_for_each_entry(connector, connector_list, head) {
4352
4353 if (connector->connector_type !=
4354 DRM_MODE_CONNECTOR_DisplayPort)
4355 continue;
4356
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304357 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004358 connector->encoder != NULL) {
4359 intel_dp = enc_to_intel_dp(connector->encoder);
4360 status = kstrtoint(input_buffer, 10, &val);
4361 if (status < 0)
4362 goto out;
4363 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4364 /* To prevent erroneous activation of the compliance
4365 * testing code, only accept an actual value of 1 here
4366 */
4367 if (val == 1)
4368 intel_dp->compliance_test_active = 1;
4369 else
4370 intel_dp->compliance_test_active = 0;
4371 }
4372 }
4373out:
4374 kfree(input_buffer);
4375 if (status < 0)
4376 return status;
4377
4378 *offp += len;
4379 return len;
4380}
4381
4382static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4383{
4384 struct drm_device *dev = m->private;
4385 struct drm_connector *connector;
4386 struct list_head *connector_list = &dev->mode_config.connector_list;
4387 struct intel_dp *intel_dp;
4388
Todd Previteeb3394fa2015-04-18 00:04:19 -07004389 list_for_each_entry(connector, connector_list, head) {
4390
4391 if (connector->connector_type !=
4392 DRM_MODE_CONNECTOR_DisplayPort)
4393 continue;
4394
4395 if (connector->status == connector_status_connected &&
4396 connector->encoder != NULL) {
4397 intel_dp = enc_to_intel_dp(connector->encoder);
4398 if (intel_dp->compliance_test_active)
4399 seq_puts(m, "1");
4400 else
4401 seq_puts(m, "0");
4402 } else
4403 seq_puts(m, "0");
4404 }
4405
4406 return 0;
4407}
4408
4409static int i915_displayport_test_active_open(struct inode *inode,
4410 struct file *file)
4411{
4412 struct drm_device *dev = inode->i_private;
4413
4414 return single_open(file, i915_displayport_test_active_show, dev);
4415}
4416
4417static const struct file_operations i915_displayport_test_active_fops = {
4418 .owner = THIS_MODULE,
4419 .open = i915_displayport_test_active_open,
4420 .read = seq_read,
4421 .llseek = seq_lseek,
4422 .release = single_release,
4423 .write = i915_displayport_test_active_write
4424};
4425
4426static int i915_displayport_test_data_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) {
4434
4435 if (connector->connector_type !=
4436 DRM_MODE_CONNECTOR_DisplayPort)
4437 continue;
4438
4439 if (connector->status == connector_status_connected &&
4440 connector->encoder != NULL) {
4441 intel_dp = enc_to_intel_dp(connector->encoder);
4442 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4443 } else
4444 seq_puts(m, "0");
4445 }
4446
4447 return 0;
4448}
4449static int i915_displayport_test_data_open(struct inode *inode,
4450 struct file *file)
4451{
4452 struct drm_device *dev = inode->i_private;
4453
4454 return single_open(file, i915_displayport_test_data_show, dev);
4455}
4456
4457static const struct file_operations i915_displayport_test_data_fops = {
4458 .owner = THIS_MODULE,
4459 .open = i915_displayport_test_data_open,
4460 .read = seq_read,
4461 .llseek = seq_lseek,
4462 .release = single_release
4463};
4464
4465static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4466{
4467 struct drm_device *dev = m->private;
4468 struct drm_connector *connector;
4469 struct list_head *connector_list = &dev->mode_config.connector_list;
4470 struct intel_dp *intel_dp;
4471
Todd Previteeb3394fa2015-04-18 00:04:19 -07004472 list_for_each_entry(connector, connector_list, head) {
4473
4474 if (connector->connector_type !=
4475 DRM_MODE_CONNECTOR_DisplayPort)
4476 continue;
4477
4478 if (connector->status == connector_status_connected &&
4479 connector->encoder != NULL) {
4480 intel_dp = enc_to_intel_dp(connector->encoder);
4481 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4482 } else
4483 seq_puts(m, "0");
4484 }
4485
4486 return 0;
4487}
4488
4489static int i915_displayport_test_type_open(struct inode *inode,
4490 struct file *file)
4491{
4492 struct drm_device *dev = inode->i_private;
4493
4494 return single_open(file, i915_displayport_test_type_show, dev);
4495}
4496
4497static const struct file_operations i915_displayport_test_type_fops = {
4498 .owner = THIS_MODULE,
4499 .open = i915_displayport_test_type_open,
4500 .read = seq_read,
4501 .llseek = seq_lseek,
4502 .release = single_release
4503};
4504
Damien Lespiau97e94b22014-11-04 17:06:50 +00004505static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004506{
4507 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004508 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004509 int num_levels;
4510
4511 if (IS_CHERRYVIEW(dev))
4512 num_levels = 3;
4513 else if (IS_VALLEYVIEW(dev))
4514 num_levels = 1;
4515 else
4516 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004517
4518 drm_modeset_lock_all(dev);
4519
4520 for (level = 0; level < num_levels; level++) {
4521 unsigned int latency = wm[level];
4522
Damien Lespiau97e94b22014-11-04 17:06:50 +00004523 /*
4524 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004525 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004526 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004527 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4528 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004529 latency *= 10;
4530 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004531 latency *= 5;
4532
4533 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004534 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004535 }
4536
4537 drm_modeset_unlock_all(dev);
4538}
4539
4540static int pri_wm_latency_show(struct seq_file *m, void *data)
4541{
4542 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004543 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004544 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004545
Damien Lespiau97e94b22014-11-04 17:06:50 +00004546 if (INTEL_INFO(dev)->gen >= 9)
4547 latencies = dev_priv->wm.skl_latency;
4548 else
4549 latencies = to_i915(dev)->wm.pri_latency;
4550
4551 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004552
4553 return 0;
4554}
4555
4556static int spr_wm_latency_show(struct seq_file *m, void *data)
4557{
4558 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004559 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004560 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004561
Damien Lespiau97e94b22014-11-04 17:06:50 +00004562 if (INTEL_INFO(dev)->gen >= 9)
4563 latencies = dev_priv->wm.skl_latency;
4564 else
4565 latencies = to_i915(dev)->wm.spr_latency;
4566
4567 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004568
4569 return 0;
4570}
4571
4572static int cur_wm_latency_show(struct seq_file *m, void *data)
4573{
4574 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004575 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004576 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004577
Damien Lespiau97e94b22014-11-04 17:06:50 +00004578 if (INTEL_INFO(dev)->gen >= 9)
4579 latencies = dev_priv->wm.skl_latency;
4580 else
4581 latencies = to_i915(dev)->wm.cur_latency;
4582
4583 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004584
4585 return 0;
4586}
4587
4588static int pri_wm_latency_open(struct inode *inode, struct file *file)
4589{
4590 struct drm_device *dev = inode->i_private;
4591
Ville Syrjäläde38b952015-06-24 22:00:09 +03004592 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004593 return -ENODEV;
4594
4595 return single_open(file, pri_wm_latency_show, dev);
4596}
4597
4598static int spr_wm_latency_open(struct inode *inode, struct file *file)
4599{
4600 struct drm_device *dev = inode->i_private;
4601
Sonika Jindal9ad02572014-07-21 15:23:39 +05304602 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004603 return -ENODEV;
4604
4605 return single_open(file, spr_wm_latency_show, dev);
4606}
4607
4608static int cur_wm_latency_open(struct inode *inode, struct file *file)
4609{
4610 struct drm_device *dev = inode->i_private;
4611
Sonika Jindal9ad02572014-07-21 15:23:39 +05304612 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004613 return -ENODEV;
4614
4615 return single_open(file, cur_wm_latency_show, dev);
4616}
4617
4618static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004619 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004620{
4621 struct seq_file *m = file->private_data;
4622 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004623 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004624 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004625 int level;
4626 int ret;
4627 char tmp[32];
4628
Ville Syrjäläde38b952015-06-24 22:00:09 +03004629 if (IS_CHERRYVIEW(dev))
4630 num_levels = 3;
4631 else if (IS_VALLEYVIEW(dev))
4632 num_levels = 1;
4633 else
4634 num_levels = ilk_wm_max_level(dev) + 1;
4635
Ville Syrjälä369a1342014-01-22 14:36:08 +02004636 if (len >= sizeof(tmp))
4637 return -EINVAL;
4638
4639 if (copy_from_user(tmp, ubuf, len))
4640 return -EFAULT;
4641
4642 tmp[len] = '\0';
4643
Damien Lespiau97e94b22014-11-04 17:06:50 +00004644 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4645 &new[0], &new[1], &new[2], &new[3],
4646 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004647 if (ret != num_levels)
4648 return -EINVAL;
4649
4650 drm_modeset_lock_all(dev);
4651
4652 for (level = 0; level < num_levels; level++)
4653 wm[level] = new[level];
4654
4655 drm_modeset_unlock_all(dev);
4656
4657 return len;
4658}
4659
4660
4661static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4662 size_t len, loff_t *offp)
4663{
4664 struct seq_file *m = file->private_data;
4665 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004666 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004667 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004668
Damien Lespiau97e94b22014-11-04 17:06:50 +00004669 if (INTEL_INFO(dev)->gen >= 9)
4670 latencies = dev_priv->wm.skl_latency;
4671 else
4672 latencies = to_i915(dev)->wm.pri_latency;
4673
4674 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004675}
4676
4677static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4678 size_t len, loff_t *offp)
4679{
4680 struct seq_file *m = file->private_data;
4681 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004682 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004683 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004684
Damien Lespiau97e94b22014-11-04 17:06:50 +00004685 if (INTEL_INFO(dev)->gen >= 9)
4686 latencies = dev_priv->wm.skl_latency;
4687 else
4688 latencies = to_i915(dev)->wm.spr_latency;
4689
4690 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004691}
4692
4693static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4694 size_t len, loff_t *offp)
4695{
4696 struct seq_file *m = file->private_data;
4697 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004698 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004699 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004700
Damien Lespiau97e94b22014-11-04 17:06:50 +00004701 if (INTEL_INFO(dev)->gen >= 9)
4702 latencies = dev_priv->wm.skl_latency;
4703 else
4704 latencies = to_i915(dev)->wm.cur_latency;
4705
4706 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004707}
4708
4709static const struct file_operations i915_pri_wm_latency_fops = {
4710 .owner = THIS_MODULE,
4711 .open = pri_wm_latency_open,
4712 .read = seq_read,
4713 .llseek = seq_lseek,
4714 .release = single_release,
4715 .write = pri_wm_latency_write
4716};
4717
4718static const struct file_operations i915_spr_wm_latency_fops = {
4719 .owner = THIS_MODULE,
4720 .open = spr_wm_latency_open,
4721 .read = seq_read,
4722 .llseek = seq_lseek,
4723 .release = single_release,
4724 .write = spr_wm_latency_write
4725};
4726
4727static const struct file_operations i915_cur_wm_latency_fops = {
4728 .owner = THIS_MODULE,
4729 .open = cur_wm_latency_open,
4730 .read = seq_read,
4731 .llseek = seq_lseek,
4732 .release = single_release,
4733 .write = cur_wm_latency_write
4734};
4735
Kees Cook647416f2013-03-10 14:10:06 -07004736static int
4737i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004738{
Kees Cook647416f2013-03-10 14:10:06 -07004739 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004740 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004741
Chris Wilsond98c52c2016-04-13 17:35:05 +01004742 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004743
Kees Cook647416f2013-03-10 14:10:06 -07004744 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004745}
4746
Kees Cook647416f2013-03-10 14:10:06 -07004747static int
4748i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004749{
Kees Cook647416f2013-03-10 14:10:06 -07004750 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004751 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakd46c0512014-04-14 20:24:27 +03004752
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004753 /*
4754 * There is no safeguard against this debugfs entry colliding
4755 * with the hangcheck calling same i915_handle_error() in
4756 * parallel, causing an explosion. For now we assume that the
4757 * test harness is responsible enough not to inject gpu hangs
4758 * while it is writing to 'i915_wedged'
4759 */
4760
Chris Wilsond98c52c2016-04-13 17:35:05 +01004761 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004762 return -EAGAIN;
4763
Imre Deakd46c0512014-04-14 20:24:27 +03004764 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004765
Chris Wilsonc0336662016-05-06 15:40:21 +01004766 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004767 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004768
4769 intel_runtime_pm_put(dev_priv);
4770
Kees Cook647416f2013-03-10 14:10:06 -07004771 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004772}
4773
Kees Cook647416f2013-03-10 14:10:06 -07004774DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4775 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004776 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004777
Kees Cook647416f2013-03-10 14:10:06 -07004778static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004779i915_ring_missed_irq_get(void *data, u64 *val)
4780{
4781 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004782 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004783
4784 *val = dev_priv->gpu_error.missed_irq_rings;
4785 return 0;
4786}
4787
4788static int
4789i915_ring_missed_irq_set(void *data, u64 val)
4790{
4791 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004792 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004793 int ret;
4794
4795 /* Lock against concurrent debugfs callers */
4796 ret = mutex_lock_interruptible(&dev->struct_mutex);
4797 if (ret)
4798 return ret;
4799 dev_priv->gpu_error.missed_irq_rings = val;
4800 mutex_unlock(&dev->struct_mutex);
4801
4802 return 0;
4803}
4804
4805DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4806 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4807 "0x%08llx\n");
4808
4809static int
4810i915_ring_test_irq_get(void *data, u64 *val)
4811{
4812 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004813 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004814
4815 *val = dev_priv->gpu_error.test_irq_rings;
4816
4817 return 0;
4818}
4819
4820static int
4821i915_ring_test_irq_set(void *data, u64 val)
4822{
4823 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004824 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004825
Chris Wilson3a122c22016-06-17 14:35:05 +01004826 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004827 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004828 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004829
4830 return 0;
4831}
4832
4833DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4834 i915_ring_test_irq_get, i915_ring_test_irq_set,
4835 "0x%08llx\n");
4836
Chris Wilsondd624af2013-01-15 12:39:35 +00004837#define DROP_UNBOUND 0x1
4838#define DROP_BOUND 0x2
4839#define DROP_RETIRE 0x4
4840#define DROP_ACTIVE 0x8
4841#define DROP_ALL (DROP_UNBOUND | \
4842 DROP_BOUND | \
4843 DROP_RETIRE | \
4844 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004845static int
4846i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004847{
Kees Cook647416f2013-03-10 14:10:06 -07004848 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004849
Kees Cook647416f2013-03-10 14:10:06 -07004850 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004851}
4852
Kees Cook647416f2013-03-10 14:10:06 -07004853static int
4854i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004855{
Kees Cook647416f2013-03-10 14:10:06 -07004856 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004857 struct drm_i915_private *dev_priv = to_i915(dev);
Kees Cook647416f2013-03-10 14:10:06 -07004858 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004859
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004860 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004861
4862 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4863 * on ioctls on -EAGAIN. */
4864 ret = mutex_lock_interruptible(&dev->struct_mutex);
4865 if (ret)
4866 return ret;
4867
4868 if (val & DROP_ACTIVE) {
Chris Wilsondcff85c2016-08-05 10:14:11 +01004869 ret = i915_gem_wait_for_idle(dev_priv, true);
Chris Wilsondd624af2013-01-15 12:39:35 +00004870 if (ret)
4871 goto unlock;
4872 }
4873
4874 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004875 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004876
Chris Wilson21ab4e72014-09-09 11:16:08 +01004877 if (val & DROP_BOUND)
4878 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004879
Chris Wilson21ab4e72014-09-09 11:16:08 +01004880 if (val & DROP_UNBOUND)
4881 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004882
4883unlock:
4884 mutex_unlock(&dev->struct_mutex);
4885
Kees Cook647416f2013-03-10 14:10:06 -07004886 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004887}
4888
Kees Cook647416f2013-03-10 14:10:06 -07004889DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4890 i915_drop_caches_get, i915_drop_caches_set,
4891 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004892
Kees Cook647416f2013-03-10 14:10:06 -07004893static int
4894i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004895{
Kees Cook647416f2013-03-10 14:10:06 -07004896 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004897 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02004898
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004899 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004900 return -ENODEV;
4901
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004902 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004903 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004904}
4905
Kees Cook647416f2013-03-10 14:10:06 -07004906static int
4907i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004908{
Kees Cook647416f2013-03-10 14:10:06 -07004909 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004910 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05304911 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004912 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004913
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004914 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004915 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004916
Kees Cook647416f2013-03-10 14:10:06 -07004917 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004918
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004919 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004920 if (ret)
4921 return ret;
4922
Jesse Barnes358733e2011-07-27 11:53:01 -07004923 /*
4924 * Turbo will still be enabled, but won't go above the set value.
4925 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304926 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004927
Akash Goelbc4d91f2015-02-26 16:09:47 +05304928 hw_max = dev_priv->rps.max_freq;
4929 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004930
Ben Widawskyb39fb292014-03-19 18:31:11 -07004931 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004932 mutex_unlock(&dev_priv->rps.hw_lock);
4933 return -EINVAL;
4934 }
4935
Ben Widawskyb39fb292014-03-19 18:31:11 -07004936 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004937
Chris Wilsondc979972016-05-10 14:10:04 +01004938 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004939
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004940 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004941
Kees Cook647416f2013-03-10 14:10:06 -07004942 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004943}
4944
Kees Cook647416f2013-03-10 14:10:06 -07004945DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4946 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004947 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004948
Kees Cook647416f2013-03-10 14:10:06 -07004949static int
4950i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004951{
Kees Cook647416f2013-03-10 14:10:06 -07004952 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004953 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02004954
Chris Wilson62e1baa2016-07-13 09:10:36 +01004955 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004956 return -ENODEV;
4957
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004958 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004959 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004960}
4961
Kees Cook647416f2013-03-10 14:10:06 -07004962static int
4963i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004964{
Kees Cook647416f2013-03-10 14:10:06 -07004965 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004966 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05304967 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004968 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004969
Chris Wilson62e1baa2016-07-13 09:10:36 +01004970 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004971 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004972
Kees Cook647416f2013-03-10 14:10:06 -07004973 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004974
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004975 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004976 if (ret)
4977 return ret;
4978
Jesse Barnes1523c312012-05-25 12:34:54 -07004979 /*
4980 * Turbo will still be enabled, but won't go below the set value.
4981 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304982 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004983
Akash Goelbc4d91f2015-02-26 16:09:47 +05304984 hw_max = dev_priv->rps.max_freq;
4985 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004986
Ben Widawskyb39fb292014-03-19 18:31:11 -07004987 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004988 mutex_unlock(&dev_priv->rps.hw_lock);
4989 return -EINVAL;
4990 }
4991
Ben Widawskyb39fb292014-03-19 18:31:11 -07004992 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004993
Chris Wilsondc979972016-05-10 14:10:04 +01004994 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004995
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004996 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004997
Kees Cook647416f2013-03-10 14:10:06 -07004998 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004999}
5000
Kees Cook647416f2013-03-10 14:10:06 -07005001DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5002 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005003 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005004
Kees Cook647416f2013-03-10 14:10:06 -07005005static int
5006i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005007{
Kees Cook647416f2013-03-10 14:10:06 -07005008 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005009 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005010 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005011 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005012
Daniel Vetter004777c2012-08-09 15:07:01 +02005013 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5014 return -ENODEV;
5015
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005016 ret = mutex_lock_interruptible(&dev->struct_mutex);
5017 if (ret)
5018 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005019 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005020
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005021 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005022
5023 intel_runtime_pm_put(dev_priv);
Chris Wilson91c8a322016-07-05 10:40:23 +01005024 mutex_unlock(&dev_priv->drm.struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005025
Kees Cook647416f2013-03-10 14:10:06 -07005026 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005027
Kees Cook647416f2013-03-10 14:10:06 -07005028 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005029}
5030
Kees Cook647416f2013-03-10 14:10:06 -07005031static int
5032i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005033{
Kees Cook647416f2013-03-10 14:10:06 -07005034 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005035 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005036 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005037
Daniel Vetter004777c2012-08-09 15:07:01 +02005038 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5039 return -ENODEV;
5040
Kees Cook647416f2013-03-10 14:10:06 -07005041 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005042 return -EINVAL;
5043
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005044 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005045 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005046
5047 /* Update the cache sharing policy here as well */
5048 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5049 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5050 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5051 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5052
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005053 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005054 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005055}
5056
Kees Cook647416f2013-03-10 14:10:06 -07005057DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5058 i915_cache_sharing_get, i915_cache_sharing_set,
5059 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005060
Jeff McGee5d395252015-04-03 18:13:17 -07005061struct sseu_dev_status {
5062 unsigned int slice_total;
5063 unsigned int subslice_total;
5064 unsigned int subslice_per_slice;
5065 unsigned int eu_total;
5066 unsigned int eu_per_subslice;
5067};
5068
5069static void cherryview_sseu_device_status(struct drm_device *dev,
5070 struct sseu_dev_status *stat)
5071{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005072 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005073 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005074 int ss;
5075 u32 sig1[ss_max], sig2[ss_max];
5076
5077 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5078 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5079 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5080 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5081
5082 for (ss = 0; ss < ss_max; ss++) {
5083 unsigned int eu_cnt;
5084
5085 if (sig1[ss] & CHV_SS_PG_ENABLE)
5086 /* skip disabled subslice */
5087 continue;
5088
5089 stat->slice_total = 1;
5090 stat->subslice_per_slice++;
5091 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5092 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5093 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5094 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5095 stat->eu_total += eu_cnt;
5096 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5097 }
5098 stat->subslice_total = stat->subslice_per_slice;
5099}
5100
5101static void gen9_sseu_device_status(struct drm_device *dev,
5102 struct sseu_dev_status *stat)
5103{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005104 struct drm_i915_private *dev_priv = to_i915(dev);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005105 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005106 int s, ss;
5107 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5108
Jeff McGee1c046bc2015-04-03 18:13:18 -07005109 /* BXT has a single slice and at most 3 subslices. */
5110 if (IS_BROXTON(dev)) {
5111 s_max = 1;
5112 ss_max = 3;
5113 }
5114
5115 for (s = 0; s < s_max; s++) {
5116 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5117 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5118 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5119 }
5120
Jeff McGee5d395252015-04-03 18:13:17 -07005121 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5122 GEN9_PGCTL_SSA_EU19_ACK |
5123 GEN9_PGCTL_SSA_EU210_ACK |
5124 GEN9_PGCTL_SSA_EU311_ACK;
5125 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5126 GEN9_PGCTL_SSB_EU19_ACK |
5127 GEN9_PGCTL_SSB_EU210_ACK |
5128 GEN9_PGCTL_SSB_EU311_ACK;
5129
5130 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005131 unsigned int ss_cnt = 0;
5132
Jeff McGee5d395252015-04-03 18:13:17 -07005133 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5134 /* skip disabled slice */
5135 continue;
5136
5137 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005138
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005139 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005140 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5141
Jeff McGee5d395252015-04-03 18:13:17 -07005142 for (ss = 0; ss < ss_max; ss++) {
5143 unsigned int eu_cnt;
5144
Jeff McGee1c046bc2015-04-03 18:13:18 -07005145 if (IS_BROXTON(dev) &&
5146 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5147 /* skip disabled subslice */
5148 continue;
5149
5150 if (IS_BROXTON(dev))
5151 ss_cnt++;
5152
Jeff McGee5d395252015-04-03 18:13:17 -07005153 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5154 eu_mask[ss%2]);
5155 stat->eu_total += eu_cnt;
5156 stat->eu_per_subslice = max(stat->eu_per_subslice,
5157 eu_cnt);
5158 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005159
5160 stat->subslice_total += ss_cnt;
5161 stat->subslice_per_slice = max(stat->subslice_per_slice,
5162 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005163 }
5164}
5165
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005166static void broadwell_sseu_device_status(struct drm_device *dev,
5167 struct sseu_dev_status *stat)
5168{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005169 struct drm_i915_private *dev_priv = to_i915(dev);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005170 int s;
5171 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5172
5173 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5174
5175 if (stat->slice_total) {
5176 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5177 stat->subslice_total = stat->slice_total *
5178 stat->subslice_per_slice;
5179 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5180 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5181
5182 /* subtract fused off EU(s) from enabled slice(s) */
5183 for (s = 0; s < stat->slice_total; s++) {
5184 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5185
5186 stat->eu_total -= hweight8(subslice_7eu);
5187 }
5188 }
5189}
5190
Jeff McGee38732182015-02-13 10:27:54 -06005191static int i915_sseu_status(struct seq_file *m, void *unused)
5192{
5193 struct drm_info_node *node = (struct drm_info_node *) m->private;
David Weinehall238010e2016-08-01 17:33:27 +03005194 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
5195 struct drm_device *dev = &dev_priv->drm;
Jeff McGee5d395252015-04-03 18:13:17 -07005196 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005197
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005198 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005199 return -ENODEV;
5200
5201 seq_puts(m, "SSEU Device Info\n");
5202 seq_printf(m, " Available Slice Total: %u\n",
5203 INTEL_INFO(dev)->slice_total);
5204 seq_printf(m, " Available Subslice Total: %u\n",
5205 INTEL_INFO(dev)->subslice_total);
5206 seq_printf(m, " Available Subslice Per Slice: %u\n",
5207 INTEL_INFO(dev)->subslice_per_slice);
5208 seq_printf(m, " Available EU Total: %u\n",
5209 INTEL_INFO(dev)->eu_total);
5210 seq_printf(m, " Available EU Per Subslice: %u\n",
5211 INTEL_INFO(dev)->eu_per_subslice);
arun.siluvery@linux.intel.com33e141e2016-06-03 06:34:33 +01005212 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev)));
5213 if (HAS_POOLED_EU(dev))
5214 seq_printf(m, " Min EU in pool: %u\n",
5215 INTEL_INFO(dev)->min_eu_in_pool);
Jeff McGee38732182015-02-13 10:27:54 -06005216 seq_printf(m, " Has Slice Power Gating: %s\n",
5217 yesno(INTEL_INFO(dev)->has_slice_pg));
5218 seq_printf(m, " Has Subslice Power Gating: %s\n",
5219 yesno(INTEL_INFO(dev)->has_subslice_pg));
5220 seq_printf(m, " Has EU Power Gating: %s\n",
5221 yesno(INTEL_INFO(dev)->has_eu_pg));
5222
Jeff McGee7f992ab2015-02-13 10:27:55 -06005223 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005224 memset(&stat, 0, sizeof(stat));
David Weinehall238010e2016-08-01 17:33:27 +03005225
5226 intel_runtime_pm_get(dev_priv);
5227
Jeff McGee5575f032015-02-27 10:22:32 -08005228 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005229 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005230 } else if (IS_BROADWELL(dev)) {
5231 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005232 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005233 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005234 }
David Weinehall238010e2016-08-01 17:33:27 +03005235
5236 intel_runtime_pm_put(dev_priv);
5237
Jeff McGee5d395252015-04-03 18:13:17 -07005238 seq_printf(m, " Enabled Slice Total: %u\n",
5239 stat.slice_total);
5240 seq_printf(m, " Enabled Subslice Total: %u\n",
5241 stat.subslice_total);
5242 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5243 stat.subslice_per_slice);
5244 seq_printf(m, " Enabled EU Total: %u\n",
5245 stat.eu_total);
5246 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5247 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005248
Jeff McGee38732182015-02-13 10:27:54 -06005249 return 0;
5250}
5251
Ben Widawsky6d794d42011-04-25 11:25:56 -07005252static int i915_forcewake_open(struct inode *inode, struct file *file)
5253{
5254 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005255 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005256
Daniel Vetter075edca2012-01-24 09:44:28 +01005257 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005258 return 0;
5259
Chris Wilson6daccb02015-01-16 11:34:35 +02005260 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005261 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005262
5263 return 0;
5264}
5265
Ben Widawskyc43b5632012-04-16 14:07:40 -07005266static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005267{
5268 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005269 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005270
Daniel Vetter075edca2012-01-24 09:44:28 +01005271 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005272 return 0;
5273
Mika Kuoppala59bad942015-01-16 11:34:40 +02005274 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005275 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005276
5277 return 0;
5278}
5279
5280static const struct file_operations i915_forcewake_fops = {
5281 .owner = THIS_MODULE,
5282 .open = i915_forcewake_open,
5283 .release = i915_forcewake_release,
5284};
5285
5286static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5287{
5288 struct drm_device *dev = minor->dev;
5289 struct dentry *ent;
5290
5291 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005292 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005293 root, dev,
5294 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005295 if (!ent)
5296 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005297
Ben Widawsky8eb57292011-05-11 15:10:58 -07005298 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005299}
5300
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005301static int i915_debugfs_create(struct dentry *root,
5302 struct drm_minor *minor,
5303 const char *name,
5304 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005305{
5306 struct drm_device *dev = minor->dev;
5307 struct dentry *ent;
5308
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005309 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005310 S_IRUGO | S_IWUSR,
5311 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005312 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005313 if (!ent)
5314 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005315
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005316 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005317}
5318
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005319static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005320 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005321 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005322 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005323 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005324 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005325 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005326 {"i915_gem_request", i915_gem_request_info, 0},
5327 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005328 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005329 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005330 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5331 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5332 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005333 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005334 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005335 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005336 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005337 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305338 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005339 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005340 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005341 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005342 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005343 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005344 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005345 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005346 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005347 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005348 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005349 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005350 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005351 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005352 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005353 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005354 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005355 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005356 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005357 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005358 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005359 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005360 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005361 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005362 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005363 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005364 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005365 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005366 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005367 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005368 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005369 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305370 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005371 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005372};
Ben Gamari27c202a2009-07-01 22:26:52 -04005373#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005374
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005375static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005376 const char *name;
5377 const struct file_operations *fops;
5378} i915_debugfs_files[] = {
5379 {"i915_wedged", &i915_wedged_fops},
5380 {"i915_max_freq", &i915_max_freq_fops},
5381 {"i915_min_freq", &i915_min_freq_fops},
5382 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005383 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5384 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005385 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5386 {"i915_error_state", &i915_error_state_fops},
5387 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005388 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005389 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5390 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5391 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005392 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005393 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5394 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5395 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005396};
5397
Damien Lespiau07144422013-10-15 18:55:40 +01005398void intel_display_crc_init(struct drm_device *dev)
5399{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005400 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb3783602013-11-14 11:30:42 +01005401 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005402
Damien Lespiau055e3932014-08-18 13:49:10 +01005403 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005404 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005405
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005406 pipe_crc->opened = false;
5407 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005408 init_waitqueue_head(&pipe_crc->wq);
5409 }
5410}
5411
Chris Wilson1dac8912016-06-24 14:00:17 +01005412int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005413{
Chris Wilson91c8a322016-07-05 10:40:23 +01005414 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005415 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005416
Ben Widawsky6d794d42011-04-25 11:25:56 -07005417 ret = i915_forcewake_create(minor->debugfs_root, minor);
5418 if (ret)
5419 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005420
Damien Lespiau07144422013-10-15 18:55:40 +01005421 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5422 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5423 if (ret)
5424 return ret;
5425 }
5426
Daniel Vetter34b96742013-07-04 20:49:44 +02005427 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5428 ret = i915_debugfs_create(minor->debugfs_root, minor,
5429 i915_debugfs_files[i].name,
5430 i915_debugfs_files[i].fops);
5431 if (ret)
5432 return ret;
5433 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005434
Ben Gamari27c202a2009-07-01 22:26:52 -04005435 return drm_debugfs_create_files(i915_debugfs_list,
5436 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005437 minor->debugfs_root, minor);
5438}
5439
Chris Wilson1dac8912016-06-24 14:00:17 +01005440void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005441{
Chris Wilson91c8a322016-07-05 10:40:23 +01005442 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005443 int i;
5444
Ben Gamari27c202a2009-07-01 22:26:52 -04005445 drm_debugfs_remove_files(i915_debugfs_list,
5446 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005447
Ben Widawsky6d794d42011-04-25 11:25:56 -07005448 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5449 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005450
Daniel Vettere309a992013-10-16 22:55:51 +02005451 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005452 struct drm_info_list *info_list =
5453 (struct drm_info_list *)&i915_pipe_crc_data[i];
5454
5455 drm_debugfs_remove_files(info_list, 1, minor);
5456 }
5457
Daniel Vetter34b96742013-07-04 20:49:44 +02005458 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5459 struct drm_info_list *info_list =
5460 (struct drm_info_list *) i915_debugfs_files[i].fops;
5461
5462 drm_debugfs_remove_files(info_list, 1, minor);
5463 }
Ben Gamari20172632009-02-17 20:08:50 -05005464}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005465
5466struct dpcd_block {
5467 /* DPCD dump start address. */
5468 unsigned int offset;
5469 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5470 unsigned int end;
5471 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5472 size_t size;
5473 /* Only valid for eDP. */
5474 bool edp;
5475};
5476
5477static const struct dpcd_block i915_dpcd_debug[] = {
5478 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5479 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5480 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5481 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5482 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5483 { .offset = DP_SET_POWER },
5484 { .offset = DP_EDP_DPCD_REV },
5485 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5486 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5487 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5488};
5489
5490static int i915_dpcd_show(struct seq_file *m, void *data)
5491{
5492 struct drm_connector *connector = m->private;
5493 struct intel_dp *intel_dp =
5494 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5495 uint8_t buf[16];
5496 ssize_t err;
5497 int i;
5498
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005499 if (connector->status != connector_status_connected)
5500 return -ENODEV;
5501
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005502 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5503 const struct dpcd_block *b = &i915_dpcd_debug[i];
5504 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5505
5506 if (b->edp &&
5507 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5508 continue;
5509
5510 /* low tech for now */
5511 if (WARN_ON(size > sizeof(buf)))
5512 continue;
5513
5514 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5515 if (err <= 0) {
5516 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5517 size, b->offset, err);
5518 continue;
5519 }
5520
5521 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005522 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005523
5524 return 0;
5525}
5526
5527static int i915_dpcd_open(struct inode *inode, struct file *file)
5528{
5529 return single_open(file, i915_dpcd_show, inode->i_private);
5530}
5531
5532static const struct file_operations i915_dpcd_fops = {
5533 .owner = THIS_MODULE,
5534 .open = i915_dpcd_open,
5535 .read = seq_read,
5536 .llseek = seq_lseek,
5537 .release = single_release,
5538};
5539
5540/**
5541 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5542 * @connector: pointer to a registered drm_connector
5543 *
5544 * Cleanup will be done by drm_connector_unregister() through a call to
5545 * drm_debugfs_connector_remove().
5546 *
5547 * Returns 0 on success, negative error codes on error.
5548 */
5549int i915_debugfs_connector_add(struct drm_connector *connector)
5550{
5551 struct dentry *root = connector->debugfs_entry;
5552
5553 /* The connector must have been registered beforehands. */
5554 if (!root)
5555 return -ENODEV;
5556
5557 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5558 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5559 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5560 &i915_dpcd_fops);
5561
5562 return 0;
5563}