blob: 0ba28a8ad6694a149559c5a22598387613443fda [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
David Weinehall36cdd012016-08-22 13:59:31 +030043static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
44{
45 return to_i915(node->minor->dev);
46}
47
Damien Lespiau497666d2013-10-15 18:55:39 +010048/* As the drm_debugfs_init() routines are called before dev->dev_private is
49 * allocated we need to hook into the minor for release. */
50static int
51drm_add_fake_info_node(struct drm_minor *minor,
52 struct dentry *ent,
53 const void *key)
54{
55 struct drm_info_node *node;
56
57 node = kmalloc(sizeof(*node), GFP_KERNEL);
58 if (node == NULL) {
59 debugfs_remove(ent);
60 return -ENOMEM;
61 }
62
63 node->minor = minor;
64 node->dent = ent;
David Weinehall36cdd012016-08-22 13:59:31 +030065 node->info_ent = (void *)key;
Damien Lespiau497666d2013-10-15 18:55:39 +010066
67 mutex_lock(&minor->debugfs_lock);
68 list_add(&node->list, &minor->debugfs_list);
69 mutex_unlock(&minor->debugfs_lock);
70
71 return 0;
72}
73
Chris Wilson70d39fe2010-08-25 16:03:34 +010074static int i915_capabilities(struct seq_file *m, void *data)
75{
David Weinehall36cdd012016-08-22 13:59:31 +030076 struct drm_i915_private *dev_priv = node_to_i915(m->private);
77 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010078
David Weinehall36cdd012016-08-22 13:59:31 +030079 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
80 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010081#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
82#define SEP_SEMICOLON ;
83 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
84#undef PRINT_FLAG
85#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010086
87 return 0;
88}
Ben Gamari433e12f2009-02-17 20:08:51 -050089
Imre Deaka7363de2016-05-12 16:18:52 +030090static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000091{
Chris Wilson573adb32016-08-04 16:32:39 +010092 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000093}
94
Imre Deaka7363de2016-05-12 16:18:52 +030095static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010096{
97 return obj->pin_display ? 'p' : ' ';
98}
99
Imre Deaka7363de2016-05-12 16:18:52 +0300100static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000101{
Chris Wilson3e510a82016-08-05 10:14:23 +0100102 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -0400103 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100104 case I915_TILING_NONE: return ' ';
105 case I915_TILING_X: return 'X';
106 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400107 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000108}
109
Imre Deaka7363de2016-05-12 16:18:52 +0300110static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700111{
Chris Wilson058d88c2016-08-15 10:49:06 +0100112 return i915_gem_object_to_ggtt(obj, NULL) ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100113}
114
Imre Deaka7363de2016-05-12 16:18:52 +0300115static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100116{
117 return obj->mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700118}
119
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100120static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
121{
122 u64 size = 0;
123 struct i915_vma *vma;
124
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000125 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100126 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100127 size += vma->node.size;
128 }
129
130 return size;
131}
132
Chris Wilson37811fc2010-08-25 22:45:57 +0100133static void
134describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
135{
Chris Wilsonb4716182015-04-27 13:41:17 +0100136 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000137 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700138 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100139 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800140 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000141 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800142
Chris Wilson188c1ab2016-04-03 14:14:20 +0100143 lockdep_assert_held(&obj->base.dev->struct_mutex);
144
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100145 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100147 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100148 get_pin_flag(obj),
149 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700150 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100151 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800152 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100153 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100154 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000155 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100156 seq_printf(m, "%x ",
Chris Wilsond72d9082016-08-04 07:52:31 +0100157 i915_gem_active_get_seqno(&obj->last_read[id],
158 &obj->base.dev->struct_mutex));
Chris Wilson49ef5292016-08-18 17:17:00 +0100159 seq_printf(m, "] %x %s%s%s",
Chris Wilsond72d9082016-08-04 07:52:31 +0100160 i915_gem_active_get_seqno(&obj->last_write,
161 &obj->base.dev->struct_mutex),
David Weinehall36cdd012016-08-22 13:59:31 +0300162 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100163 obj->dirty ? " dirty" : "",
164 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
165 if (obj->base.name)
166 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000167 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100168 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800169 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300170 }
171 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100172 if (obj->pin_display)
173 seq_printf(m, " (display)");
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);
Chris Wilson49ef5292016-08-18 17:17:00 +0100183 if (vma->fence)
184 seq_printf(m, " , fence: %d%s",
185 vma->fence->id,
186 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000187 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700188 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000189 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100190 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100191 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000192 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100193 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000194 *t++ = 'p';
195 if (obj->fault_mappable)
196 *t++ = 'f';
197 *t = '\0';
198 seq_printf(m, " (%s mappable)", s);
199 }
Chris Wilson27c01aa2016-08-04 07:52:30 +0100200
Chris Wilsond72d9082016-08-04 07:52:31 +0100201 engine = i915_gem_active_get_engine(&obj->last_write,
David Weinehall36cdd012016-08-22 13:59:31 +0300202 &dev_priv->drm.struct_mutex);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100203 if (engine)
204 seq_printf(m, " (%s)", engine->name);
205
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100206 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
207 if (frontbuffer_bits)
208 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100209}
210
Chris Wilson6d2b88852013-08-07 18:30:54 +0100211static int obj_rank_by_stolen(void *priv,
212 struct list_head *A, struct list_head *B)
213{
214 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200215 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100216 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200217 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100218
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200219 if (a->stolen->start < b->stolen->start)
220 return -1;
221 if (a->stolen->start > b->stolen->start)
222 return 1;
223 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100224}
225
226static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
227{
David Weinehall36cdd012016-08-22 13:59:31 +0300228 struct drm_i915_private *dev_priv = node_to_i915(m->private);
229 struct drm_device *dev = &dev_priv->drm;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100230 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300231 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100232 LIST_HEAD(stolen);
233 int count, ret;
234
235 ret = mutex_lock_interruptible(&dev->struct_mutex);
236 if (ret)
237 return ret;
238
239 total_obj_size = total_gtt_size = count = 0;
240 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
241 if (obj->stolen == NULL)
242 continue;
243
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200244 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245
246 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100247 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100248 count++;
249 }
250 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
251 if (obj->stolen == NULL)
252 continue;
253
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200254 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100255
256 total_obj_size += obj->base.size;
257 count++;
258 }
259 list_sort(NULL, &stolen, obj_rank_by_stolen);
260 seq_puts(m, "Stolen:\n");
261 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200262 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263 seq_puts(m, " ");
264 describe_obj(m, obj);
265 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200266 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100267 }
268 mutex_unlock(&dev->struct_mutex);
269
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300270 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100271 count, total_obj_size, total_gtt_size);
272 return 0;
273}
274
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100275struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000276 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300277 unsigned long count;
278 u64 total, unbound;
279 u64 global, shared;
280 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100281};
282
283static int per_file_stats(int id, void *ptr, void *data)
284{
285 struct drm_i915_gem_object *obj = ptr;
286 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000287 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100288
289 stats->count++;
290 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100291 if (!obj->bind_count)
292 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000293 if (obj->base.name || obj->base.dma_buf)
294 stats->shared += obj->base.size;
295
Chris Wilson894eeec2016-08-04 07:52:20 +0100296 list_for_each_entry(vma, &obj->vma_list, obj_link) {
297 if (!drm_mm_node_allocated(&vma->node))
298 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000299
Chris Wilson3272db52016-08-04 16:32:32 +0100300 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100301 stats->global += vma->node.size;
302 } else {
303 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000304
Chris Wilson2bfa9962016-08-04 07:52:25 +0100305 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000306 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000307 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100308
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100309 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100310 stats->active += vma->node.size;
311 else
312 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100313 }
314
315 return 0;
316}
317
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100318#define print_file_stats(m, name, stats) do { \
319 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300320 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 +0100321 name, \
322 stats.count, \
323 stats.total, \
324 stats.active, \
325 stats.inactive, \
326 stats.global, \
327 stats.shared, \
328 stats.unbound); \
329} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800330
331static void print_batch_pool_stats(struct seq_file *m,
332 struct drm_i915_private *dev_priv)
333{
334 struct drm_i915_gem_object *obj;
335 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000336 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000337 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800338
339 memset(&stats, 0, sizeof(stats));
340
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000341 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000342 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100343 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000344 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100345 batch_pool_link)
346 per_file_stats(0, obj, &stats);
347 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100348 }
Brad Volkin493018d2014-12-11 12:13:08 -0800349
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100350 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800351}
352
Chris Wilson15da9562016-05-24 14:53:43 +0100353static int per_file_ctx_stats(int id, void *ptr, void *data)
354{
355 struct i915_gem_context *ctx = ptr;
356 int n;
357
358 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
359 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100360 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100361 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100362 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100363 }
364
365 return 0;
366}
367
368static void print_context_stats(struct seq_file *m,
369 struct drm_i915_private *dev_priv)
370{
David Weinehall36cdd012016-08-22 13:59:31 +0300371 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100372 struct file_stats stats;
373 struct drm_file *file;
374
375 memset(&stats, 0, sizeof(stats));
376
David Weinehall36cdd012016-08-22 13:59:31 +0300377 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100378 if (dev_priv->kernel_context)
379 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
380
David Weinehall36cdd012016-08-22 13:59:31 +0300381 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100382 struct drm_i915_file_private *fpriv = file->driver_priv;
383 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
384 }
David Weinehall36cdd012016-08-22 13:59:31 +0300385 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100386
387 print_file_stats(m, "[k]contexts", stats);
388}
389
David Weinehall36cdd012016-08-22 13:59:31 +0300390static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100391{
David Weinehall36cdd012016-08-22 13:59:31 +0300392 struct drm_i915_private *dev_priv = node_to_i915(m->private);
393 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300394 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilson2bd160a2016-08-15 10:48:45 +0100395 u32 count, mapped_count, purgeable_count, dpy_count;
396 u64 size, mapped_size, purgeable_size, dpy_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000397 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100398 struct drm_file *file;
Chris Wilson73aa8082010-09-30 11:46:12 +0100399 int ret;
400
401 ret = mutex_lock_interruptible(&dev->struct_mutex);
402 if (ret)
403 return ret;
404
Chris Wilson6299f992010-11-24 12:23:44 +0000405 seq_printf(m, "%u objects, %zu bytes\n",
406 dev_priv->mm.object_count,
407 dev_priv->mm.object_memory);
408
Chris Wilson1544c422016-08-15 13:18:16 +0100409 size = count = 0;
410 mapped_size = mapped_count = 0;
411 purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700412 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100413 size += obj->base.size;
414 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200415
Chris Wilsonb7abb712012-08-20 11:33:30 +0200416 if (obj->madv == I915_MADV_DONTNEED) {
417 purgeable_size += obj->base.size;
418 ++purgeable_count;
419 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100420
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100421 if (obj->mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100422 mapped_count++;
423 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100424 }
Chris Wilson6299f992010-11-24 12:23:44 +0000425 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100426 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
427
428 size = count = dpy_size = dpy_count = 0;
429 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
430 size += obj->base.size;
431 ++count;
432
433 if (obj->pin_display) {
434 dpy_size += obj->base.size;
435 ++dpy_count;
436 }
437
438 if (obj->madv == I915_MADV_DONTNEED) {
439 purgeable_size += obj->base.size;
440 ++purgeable_count;
441 }
442
443 if (obj->mapping) {
444 mapped_count++;
445 mapped_size += obj->base.size;
446 }
447 }
448 seq_printf(m, "%u bound objects, %llu bytes\n",
449 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300450 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200451 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100452 seq_printf(m, "%u mapped objects, %llu bytes\n",
453 mapped_count, mapped_size);
454 seq_printf(m, "%u display objects (pinned), %llu bytes\n",
455 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000456
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300457 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300458 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100459
Damien Lespiau267f0c92013-06-24 22:59:48 +0100460 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800461 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200462 mutex_unlock(&dev->struct_mutex);
463
464 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100465 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100466 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
467 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100468 struct drm_i915_file_private *file_priv = file->driver_priv;
469 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900470 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100471
472 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000473 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100474 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100475 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100476 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900477 /*
478 * Although we have a valid reference on file->pid, that does
479 * not guarantee that the task_struct who called get_pid() is
480 * still alive (e.g. get_pid(current) => fork() => exit()).
481 * Therefore, we need to protect this ->comm access using RCU.
482 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100483 mutex_lock(&dev->struct_mutex);
484 request = list_first_entry_or_null(&file_priv->mm.request_list,
485 struct drm_i915_gem_request,
486 client_list);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900487 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100488 task = pid_task(request && request->ctx->pid ?
489 request->ctx->pid : file->pid,
490 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800491 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900492 rcu_read_unlock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100493 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100494 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200495 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100496
497 return 0;
498}
499
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100500static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000501{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100502 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300503 struct drm_i915_private *dev_priv = node_to_i915(node);
504 struct drm_device *dev = &dev_priv->drm;
Chris Wilson5f4b0912016-08-19 12:56:25 +0100505 bool show_pin_display_only = !!node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000506 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300507 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000508 int count, ret;
509
510 ret = mutex_lock_interruptible(&dev->struct_mutex);
511 if (ret)
512 return ret;
513
514 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700515 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6da84822016-08-15 10:48:44 +0100516 if (show_pin_display_only && !obj->pin_display)
Chris Wilson1b502472012-04-24 15:47:30 +0100517 continue;
518
Damien Lespiau267f0c92013-06-24 22:59:48 +0100519 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000520 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100521 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000522 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100523 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000524 count++;
525 }
526
527 mutex_unlock(&dev->struct_mutex);
528
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300529 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000530 count, total_obj_size, total_gtt_size);
531
532 return 0;
533}
534
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100535static int i915_gem_pageflip_info(struct seq_file *m, void *data)
536{
David Weinehall36cdd012016-08-22 13:59:31 +0300537 struct drm_i915_private *dev_priv = node_to_i915(m->private);
538 struct drm_device *dev = &dev_priv->drm;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100539 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200540 int ret;
541
542 ret = mutex_lock_interruptible(&dev->struct_mutex);
543 if (ret)
544 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100545
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100546 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800547 const char pipe = pipe_name(crtc->pipe);
548 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200549 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100550
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200551 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200552 work = crtc->flip_work;
553 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800554 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100555 pipe, plane);
556 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200557 u32 pending;
558 u32 addr;
559
560 pending = atomic_read(&work->pending);
561 if (pending) {
562 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
563 pipe, plane);
564 } else {
565 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
566 pipe, plane);
567 }
568 if (work->flip_queued_req) {
569 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
570
571 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
572 engine->name,
573 i915_gem_request_get_seqno(work->flip_queued_req),
574 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100575 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100576 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200577 } else
578 seq_printf(m, "Flip not associated with any ring\n");
579 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
580 work->flip_queued_vblank,
581 work->flip_ready_vblank,
582 intel_crtc_get_vblank_counter(crtc));
583 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
584
David Weinehall36cdd012016-08-22 13:59:31 +0300585 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter5a21b662016-05-24 17:13:53 +0200586 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
587 else
588 addr = I915_READ(DSPADDR(crtc->plane));
589 seq_printf(m, "Current scanout address 0x%08x\n", addr);
590
591 if (work->pending_flip_obj) {
592 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
593 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100594 }
595 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200596 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100597 }
598
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200599 mutex_unlock(&dev->struct_mutex);
600
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100601 return 0;
602}
603
Brad Volkin493018d2014-12-11 12:13:08 -0800604static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
605{
David Weinehall36cdd012016-08-22 13:59:31 +0300606 struct drm_i915_private *dev_priv = node_to_i915(m->private);
607 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800608 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000609 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100610 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000611 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800612
613 ret = mutex_lock_interruptible(&dev->struct_mutex);
614 if (ret)
615 return ret;
616
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000617 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000618 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100619 int count;
620
621 count = 0;
622 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000623 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100624 batch_pool_link)
625 count++;
626 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000627 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100628
629 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000630 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100631 batch_pool_link) {
632 seq_puts(m, " ");
633 describe_obj(m, obj);
634 seq_putc(m, '\n');
635 }
636
637 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100638 }
Brad Volkin493018d2014-12-11 12:13:08 -0800639 }
640
Chris Wilson8d9d5742015-04-07 16:20:38 +0100641 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800642
643 mutex_unlock(&dev->struct_mutex);
644
645 return 0;
646}
647
Ben Gamari20172632009-02-17 20:08:50 -0500648static int i915_gem_request_info(struct seq_file *m, void *data)
649{
David Weinehall36cdd012016-08-22 13:59:31 +0300650 struct drm_i915_private *dev_priv = node_to_i915(m->private);
651 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000652 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200653 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000654 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100655
656 ret = mutex_lock_interruptible(&dev->struct_mutex);
657 if (ret)
658 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500659
Chris Wilson2d1070b2015-04-01 10:36:56 +0100660 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000661 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100662 int count;
663
664 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100665 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100666 count++;
667 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100668 continue;
669
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000670 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100671 list_for_each_entry(req, &engine->request_list, link) {
Chris Wilsonc84455b2016-08-15 10:49:08 +0100672 struct pid *pid = req->ctx->pid;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100673 struct task_struct *task;
674
675 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100676 task = pid ? pid_task(pid, PIDTYPE_PID) : NULL;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100677 seq_printf(m, " %x @ %d: %s [%d]\n",
Chris Wilson04769652016-07-20 09:21:11 +0100678 req->fence.seqno,
Daniel Vettereed29a52015-05-21 14:21:25 +0200679 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100680 task ? task->comm : "<unknown>",
681 task ? task->pid : -1);
682 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100683 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100684
685 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500686 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100687 mutex_unlock(&dev->struct_mutex);
688
Chris Wilson2d1070b2015-04-01 10:36:56 +0100689 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100690 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100691
Ben Gamari20172632009-02-17 20:08:50 -0500692 return 0;
693}
694
Chris Wilsonb2223492010-10-27 15:27:33 +0100695static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000696 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100697{
Chris Wilson688e6c72016-07-01 17:23:15 +0100698 struct intel_breadcrumbs *b = &engine->breadcrumbs;
699 struct rb_node *rb;
700
Chris Wilson12471ba2016-04-09 10:57:55 +0100701 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100702 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100703
704 spin_lock(&b->lock);
705 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
706 struct intel_wait *w = container_of(rb, typeof(*w), node);
707
708 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
709 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
710 }
711 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100712}
713
Ben Gamari20172632009-02-17 20:08:50 -0500714static int i915_gem_seqno_info(struct seq_file *m, void *data)
715{
David Weinehall36cdd012016-08-22 13:59:31 +0300716 struct drm_i915_private *dev_priv = node_to_i915(m->private);
717 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000718 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000719 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100720
721 ret = mutex_lock_interruptible(&dev->struct_mutex);
722 if (ret)
723 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200724 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500725
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000726 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000727 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100728
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200729 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100730 mutex_unlock(&dev->struct_mutex);
731
Ben Gamari20172632009-02-17 20:08:50 -0500732 return 0;
733}
734
735
736static int i915_interrupt_info(struct seq_file *m, void *data)
737{
David Weinehall36cdd012016-08-22 13:59:31 +0300738 struct drm_i915_private *dev_priv = node_to_i915(m->private);
739 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000740 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800741 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100742
743 ret = mutex_lock_interruptible(&dev->struct_mutex);
744 if (ret)
745 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200746 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500747
David Weinehall36cdd012016-08-22 13:59:31 +0300748 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300749 seq_printf(m, "Master Interrupt Control:\t%08x\n",
750 I915_READ(GEN8_MASTER_IRQ));
751
752 seq_printf(m, "Display IER:\t%08x\n",
753 I915_READ(VLV_IER));
754 seq_printf(m, "Display IIR:\t%08x\n",
755 I915_READ(VLV_IIR));
756 seq_printf(m, "Display IIR_RW:\t%08x\n",
757 I915_READ(VLV_IIR_RW));
758 seq_printf(m, "Display IMR:\t%08x\n",
759 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100760 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300761 seq_printf(m, "Pipe %c stat:\t%08x\n",
762 pipe_name(pipe),
763 I915_READ(PIPESTAT(pipe)));
764
765 seq_printf(m, "Port hotplug:\t%08x\n",
766 I915_READ(PORT_HOTPLUG_EN));
767 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
768 I915_READ(VLV_DPFLIPSTAT));
769 seq_printf(m, "DPINVGTT:\t%08x\n",
770 I915_READ(DPINVGTT));
771
772 for (i = 0; i < 4; i++) {
773 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
774 i, I915_READ(GEN8_GT_IMR(i)));
775 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
776 i, I915_READ(GEN8_GT_IIR(i)));
777 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
778 i, I915_READ(GEN8_GT_IER(i)));
779 }
780
781 seq_printf(m, "PCU interrupt mask:\t%08x\n",
782 I915_READ(GEN8_PCU_IMR));
783 seq_printf(m, "PCU interrupt identity:\t%08x\n",
784 I915_READ(GEN8_PCU_IIR));
785 seq_printf(m, "PCU interrupt enable:\t%08x\n",
786 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300787 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700788 seq_printf(m, "Master Interrupt Control:\t%08x\n",
789 I915_READ(GEN8_MASTER_IRQ));
790
791 for (i = 0; i < 4; i++) {
792 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
793 i, I915_READ(GEN8_GT_IMR(i)));
794 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
795 i, I915_READ(GEN8_GT_IIR(i)));
796 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
797 i, I915_READ(GEN8_GT_IER(i)));
798 }
799
Damien Lespiau055e3932014-08-18 13:49:10 +0100800 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200801 enum intel_display_power_domain power_domain;
802
803 power_domain = POWER_DOMAIN_PIPE(pipe);
804 if (!intel_display_power_get_if_enabled(dev_priv,
805 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300806 seq_printf(m, "Pipe %c power disabled\n",
807 pipe_name(pipe));
808 continue;
809 }
Ben Widawskya123f152013-11-02 21:07:10 -0700810 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000811 pipe_name(pipe),
812 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700813 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000814 pipe_name(pipe),
815 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700816 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000817 pipe_name(pipe),
818 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200819
820 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700821 }
822
823 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
824 I915_READ(GEN8_DE_PORT_IMR));
825 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
826 I915_READ(GEN8_DE_PORT_IIR));
827 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
828 I915_READ(GEN8_DE_PORT_IER));
829
830 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
831 I915_READ(GEN8_DE_MISC_IMR));
832 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
833 I915_READ(GEN8_DE_MISC_IIR));
834 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
835 I915_READ(GEN8_DE_MISC_IER));
836
837 seq_printf(m, "PCU interrupt mask:\t%08x\n",
838 I915_READ(GEN8_PCU_IMR));
839 seq_printf(m, "PCU interrupt identity:\t%08x\n",
840 I915_READ(GEN8_PCU_IIR));
841 seq_printf(m, "PCU interrupt enable:\t%08x\n",
842 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300843 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700844 seq_printf(m, "Display IER:\t%08x\n",
845 I915_READ(VLV_IER));
846 seq_printf(m, "Display IIR:\t%08x\n",
847 I915_READ(VLV_IIR));
848 seq_printf(m, "Display IIR_RW:\t%08x\n",
849 I915_READ(VLV_IIR_RW));
850 seq_printf(m, "Display IMR:\t%08x\n",
851 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100852 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700853 seq_printf(m, "Pipe %c stat:\t%08x\n",
854 pipe_name(pipe),
855 I915_READ(PIPESTAT(pipe)));
856
857 seq_printf(m, "Master IER:\t%08x\n",
858 I915_READ(VLV_MASTER_IER));
859
860 seq_printf(m, "Render IER:\t%08x\n",
861 I915_READ(GTIER));
862 seq_printf(m, "Render IIR:\t%08x\n",
863 I915_READ(GTIIR));
864 seq_printf(m, "Render IMR:\t%08x\n",
865 I915_READ(GTIMR));
866
867 seq_printf(m, "PM IER:\t\t%08x\n",
868 I915_READ(GEN6_PMIER));
869 seq_printf(m, "PM IIR:\t\t%08x\n",
870 I915_READ(GEN6_PMIIR));
871 seq_printf(m, "PM IMR:\t\t%08x\n",
872 I915_READ(GEN6_PMIMR));
873
874 seq_printf(m, "Port hotplug:\t%08x\n",
875 I915_READ(PORT_HOTPLUG_EN));
876 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
877 I915_READ(VLV_DPFLIPSTAT));
878 seq_printf(m, "DPINVGTT:\t%08x\n",
879 I915_READ(DPINVGTT));
880
David Weinehall36cdd012016-08-22 13:59:31 +0300881 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800882 seq_printf(m, "Interrupt enable: %08x\n",
883 I915_READ(IER));
884 seq_printf(m, "Interrupt identity: %08x\n",
885 I915_READ(IIR));
886 seq_printf(m, "Interrupt mask: %08x\n",
887 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100888 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800889 seq_printf(m, "Pipe %c stat: %08x\n",
890 pipe_name(pipe),
891 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800892 } else {
893 seq_printf(m, "North Display Interrupt enable: %08x\n",
894 I915_READ(DEIER));
895 seq_printf(m, "North Display Interrupt identity: %08x\n",
896 I915_READ(DEIIR));
897 seq_printf(m, "North Display Interrupt mask: %08x\n",
898 I915_READ(DEIMR));
899 seq_printf(m, "South Display Interrupt enable: %08x\n",
900 I915_READ(SDEIER));
901 seq_printf(m, "South Display Interrupt identity: %08x\n",
902 I915_READ(SDEIIR));
903 seq_printf(m, "South Display Interrupt mask: %08x\n",
904 I915_READ(SDEIMR));
905 seq_printf(m, "Graphics Interrupt enable: %08x\n",
906 I915_READ(GTIER));
907 seq_printf(m, "Graphics Interrupt identity: %08x\n",
908 I915_READ(GTIIR));
909 seq_printf(m, "Graphics Interrupt mask: %08x\n",
910 I915_READ(GTIMR));
911 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000912 for_each_engine(engine, dev_priv) {
David Weinehall36cdd012016-08-22 13:59:31 +0300913 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100914 seq_printf(m,
915 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000916 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000917 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000918 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000919 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200920 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100921 mutex_unlock(&dev->struct_mutex);
922
Ben Gamari20172632009-02-17 20:08:50 -0500923 return 0;
924}
925
Chris Wilsona6172a82009-02-11 14:26:38 +0000926static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
927{
David Weinehall36cdd012016-08-22 13:59:31 +0300928 struct drm_i915_private *dev_priv = node_to_i915(m->private);
929 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100930 int i, ret;
931
932 ret = mutex_lock_interruptible(&dev->struct_mutex);
933 if (ret)
934 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000935
Chris Wilsona6172a82009-02-11 14:26:38 +0000936 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
937 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100938 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000939
Chris Wilson6c085a72012-08-20 11:40:46 +0200940 seq_printf(m, "Fence %d, pin count = %d, object = ",
941 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100942 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100943 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100944 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100945 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100946 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000947 }
948
Chris Wilson05394f32010-11-08 19:18:58 +0000949 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000950 return 0;
951}
952
Ben Gamari20172632009-02-17 20:08:50 -0500953static int i915_hws_info(struct seq_file *m, void *data)
954{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100955 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300956 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000957 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100958 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100959 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500960
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +0000961 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000962 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500963 if (hws == NULL)
964 return 0;
965
966 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
967 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
968 i * 4,
969 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
970 }
971 return 0;
972}
973
Daniel Vetterd5442302012-04-27 15:17:40 +0200974static ssize_t
975i915_error_state_write(struct file *filp,
976 const char __user *ubuf,
977 size_t cnt,
978 loff_t *ppos)
979{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300980 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200981
982 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100983 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200984
985 return cnt;
986}
987
988static int i915_error_state_open(struct inode *inode, struct file *file)
989{
David Weinehall36cdd012016-08-22 13:59:31 +0300990 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200991 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200992
993 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
994 if (!error_priv)
995 return -ENOMEM;
996
David Weinehall36cdd012016-08-22 13:59:31 +0300997 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200998
David Weinehall36cdd012016-08-22 13:59:31 +0300999 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001000
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001001 file->private_data = error_priv;
1002
1003 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001004}
1005
1006static int i915_error_state_release(struct inode *inode, struct file *file)
1007{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001008 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001009
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001010 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001011 kfree(error_priv);
1012
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001013 return 0;
1014}
1015
1016static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1017 size_t count, loff_t *pos)
1018{
1019 struct i915_error_state_file_priv *error_priv = file->private_data;
1020 struct drm_i915_error_state_buf error_str;
1021 loff_t tmp_pos = 0;
1022 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001023 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001024
David Weinehall36cdd012016-08-22 13:59:31 +03001025 ret = i915_error_state_buf_init(&error_str,
1026 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001027 if (ret)
1028 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001029
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001030 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001031 if (ret)
1032 goto out;
1033
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001034 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1035 error_str.buf,
1036 error_str.bytes);
1037
1038 if (ret_count < 0)
1039 ret = ret_count;
1040 else
1041 *pos = error_str.start + ret_count;
1042out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001043 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001044 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001045}
1046
1047static const struct file_operations i915_error_state_fops = {
1048 .owner = THIS_MODULE,
1049 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001050 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001051 .write = i915_error_state_write,
1052 .llseek = default_llseek,
1053 .release = i915_error_state_release,
1054};
1055
Kees Cook647416f2013-03-10 14:10:06 -07001056static int
1057i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001058{
David Weinehall36cdd012016-08-22 13:59:31 +03001059 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001060 int ret;
1061
David Weinehall36cdd012016-08-22 13:59:31 +03001062 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001063 if (ret)
1064 return ret;
1065
Kees Cook647416f2013-03-10 14:10:06 -07001066 *val = dev_priv->next_seqno;
David Weinehall36cdd012016-08-22 13:59:31 +03001067 mutex_unlock(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001068
Kees Cook647416f2013-03-10 14:10:06 -07001069 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001070}
1071
Kees Cook647416f2013-03-10 14:10:06 -07001072static int
1073i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001074{
David Weinehall36cdd012016-08-22 13:59:31 +03001075 struct drm_i915_private *dev_priv = data;
1076 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001077 int ret;
1078
Mika Kuoppala40633212012-12-04 15:12:00 +02001079 ret = mutex_lock_interruptible(&dev->struct_mutex);
1080 if (ret)
1081 return ret;
1082
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001083 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001084 mutex_unlock(&dev->struct_mutex);
1085
Kees Cook647416f2013-03-10 14:10:06 -07001086 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001087}
1088
Kees Cook647416f2013-03-10 14:10:06 -07001089DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1090 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001091 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001092
Deepak Sadb4bd12014-03-31 11:30:02 +05301093static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001094{
David Weinehall36cdd012016-08-22 13:59:31 +03001095 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1096 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001097 int ret = 0;
1098
1099 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001100
David Weinehall36cdd012016-08-22 13:59:31 +03001101 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001102 u16 rgvswctl = I915_READ16(MEMSWCTL);
1103 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1104
1105 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1106 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1107 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1108 MEMSTAT_VID_SHIFT);
1109 seq_printf(m, "Current P-state: %d\n",
1110 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001111 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001112 u32 freq_sts;
1113
1114 mutex_lock(&dev_priv->rps.hw_lock);
1115 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1116 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1117 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1118
1119 seq_printf(m, "actual GPU freq: %d MHz\n",
1120 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1121
1122 seq_printf(m, "current GPU freq: %d MHz\n",
1123 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1124
1125 seq_printf(m, "max GPU freq: %d MHz\n",
1126 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1127
1128 seq_printf(m, "min GPU freq: %d MHz\n",
1129 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1130
1131 seq_printf(m, "idle GPU freq: %d MHz\n",
1132 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1133
1134 seq_printf(m,
1135 "efficient (RPe) frequency: %d MHz\n",
1136 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1137 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001138 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001139 u32 rp_state_limits;
1140 u32 gt_perf_status;
1141 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001142 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001143 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001144 u32 rpupei, rpcurup, rpprevup;
1145 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001146 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001147 int max_freq;
1148
Bob Paauwe35040562015-06-25 14:54:07 -07001149 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001150 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001151 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1152 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1153 } else {
1154 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1155 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1156 }
1157
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001158 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001159 ret = mutex_lock_interruptible(&dev->struct_mutex);
1160 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001161 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001162
Mika Kuoppala59bad942015-01-16 11:34:40 +02001163 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001164
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001165 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001166 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301167 reqf >>= 23;
1168 else {
1169 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001170 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301171 reqf >>= 24;
1172 else
1173 reqf >>= 25;
1174 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001175 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001176
Chris Wilson0d8f9492014-03-27 09:06:14 +00001177 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1178 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1179 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1180
Jesse Barnesccab5c82011-01-18 15:49:25 -08001181 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301182 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1183 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1184 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1185 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1186 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1187 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001188 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301189 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001190 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001191 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1192 else
1193 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001194 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001195
Mika Kuoppala59bad942015-01-16 11:34:40 +02001196 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001197 mutex_unlock(&dev->struct_mutex);
1198
David Weinehall36cdd012016-08-22 13:59:31 +03001199 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001200 pm_ier = I915_READ(GEN6_PMIER);
1201 pm_imr = I915_READ(GEN6_PMIMR);
1202 pm_isr = I915_READ(GEN6_PMISR);
1203 pm_iir = I915_READ(GEN6_PMIIR);
1204 pm_mask = I915_READ(GEN6_PMINTRMSK);
1205 } else {
1206 pm_ier = I915_READ(GEN8_GT_IER(2));
1207 pm_imr = I915_READ(GEN8_GT_IMR(2));
1208 pm_isr = I915_READ(GEN8_GT_ISR(2));
1209 pm_iir = I915_READ(GEN8_GT_IIR(2));
1210 pm_mask = I915_READ(GEN6_PMINTRMSK);
1211 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001212 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 -03001213 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301214 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001215 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001216 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001217 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001218 seq_printf(m, "Render p-state VID: %d\n",
1219 gt_perf_status & 0xff);
1220 seq_printf(m, "Render p-state limit: %d\n",
1221 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001222 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1223 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1224 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1225 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001226 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001227 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301228 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1229 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1230 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1231 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1232 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1233 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001234 seq_printf(m, "Up threshold: %d%%\n",
1235 dev_priv->rps.up_threshold);
1236
Akash Goeld6cda9c2016-04-23 00:05:46 +05301237 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1238 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1239 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1240 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1241 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1242 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001243 seq_printf(m, "Down threshold: %d%%\n",
1244 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001245
David Weinehall36cdd012016-08-22 13:59:31 +03001246 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001247 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001248 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001249 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001250 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001251 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001252
1253 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001254 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001255 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001256 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001257 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258
David Weinehall36cdd012016-08-22 13:59:31 +03001259 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001260 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001261 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001262 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001264 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001265 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001266 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001267
Chris Wilsond86ed342015-04-27 13:41:19 +01001268 seq_printf(m, "Current freq: %d MHz\n",
1269 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1270 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001271 seq_printf(m, "Idle freq: %d MHz\n",
1272 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001273 seq_printf(m, "Min freq: %d MHz\n",
1274 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001275 seq_printf(m, "Boost freq: %d MHz\n",
1276 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001277 seq_printf(m, "Max freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1279 seq_printf(m,
1280 "efficient (RPe) frequency: %d MHz\n",
1281 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001282 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001283 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001284 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001285
Mika Kahola1170f282015-09-25 14:00:32 +03001286 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1287 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1288 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1289
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001290out:
1291 intel_runtime_pm_put(dev_priv);
1292 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001293}
1294
Chris Wilsonf6544492015-01-26 18:03:04 +02001295static int i915_hangcheck_info(struct seq_file *m, void *unused)
1296{
David Weinehall36cdd012016-08-22 13:59:31 +03001297 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001298 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001299 u64 acthd[I915_NUM_ENGINES];
1300 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001301 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001302 enum intel_engine_id id;
1303 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001304
1305 if (!i915.enable_hangcheck) {
1306 seq_printf(m, "Hangcheck disabled\n");
1307 return 0;
1308 }
1309
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001310 intel_runtime_pm_get(dev_priv);
1311
Dave Gordonc3232b12016-03-23 18:19:53 +00001312 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001313 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001314 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001315 }
1316
Chris Wilsonc0336662016-05-06 15:40:21 +01001317 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001318
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001319 intel_runtime_pm_put(dev_priv);
1320
Chris Wilsonf6544492015-01-26 18:03:04 +02001321 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1322 seq_printf(m, "Hangcheck active, fires in %dms\n",
1323 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1324 jiffies));
1325 } else
1326 seq_printf(m, "Hangcheck inactive\n");
1327
Dave Gordonc3232b12016-03-23 18:19:53 +00001328 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001329 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001330 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1331 engine->hangcheck.seqno,
1332 seqno[id],
1333 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001334 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1335 yesno(intel_engine_has_waiter(engine)),
1336 yesno(test_bit(engine->id,
1337 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilsonf6544492015-01-26 18:03:04 +02001338 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001339 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001340 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001341 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1342 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001343
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001344 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001345 seq_puts(m, "\tinstdone read =");
1346
1347 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1348 seq_printf(m, " 0x%08x", instdone[j]);
1349
1350 seq_puts(m, "\n\tinstdone accu =");
1351
1352 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1353 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001354 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001355
1356 seq_puts(m, "\n");
1357 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001358 }
1359
1360 return 0;
1361}
1362
Ben Widawsky4d855292011-12-12 19:34:16 -08001363static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001364{
David Weinehall36cdd012016-08-22 13:59:31 +03001365 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1366 struct drm_device *dev = &dev_priv->drm;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001367 u32 rgvmodectl, rstdbyctl;
1368 u16 crstandvid;
1369 int ret;
1370
1371 ret = mutex_lock_interruptible(&dev->struct_mutex);
1372 if (ret)
1373 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001374 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001375
1376 rgvmodectl = I915_READ(MEMMODECTL);
1377 rstdbyctl = I915_READ(RSTDBYCTL);
1378 crstandvid = I915_READ16(CRSTANDVID);
1379
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001380 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001381 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001382
Jani Nikula742f4912015-09-03 11:16:09 +03001383 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001384 seq_printf(m, "Boost freq: %d\n",
1385 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1386 MEMMODE_BOOST_FREQ_SHIFT);
1387 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001388 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001389 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001390 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001391 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001392 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001393 seq_printf(m, "Starting frequency: P%d\n",
1394 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001395 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001396 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001397 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1398 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1399 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1400 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001401 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001402 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001403 switch (rstdbyctl & RSX_STATUS_MASK) {
1404 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001405 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001406 break;
1407 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001408 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001409 break;
1410 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001411 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001412 break;
1413 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001414 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001415 break;
1416 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001417 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001418 break;
1419 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001420 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001421 break;
1422 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001423 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001424 break;
1425 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426
1427 return 0;
1428}
1429
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001430static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001431{
David Weinehall36cdd012016-08-22 13:59:31 +03001432 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001433 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001434
1435 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001436 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001437 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001438 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001439 fw_domain->wake_count);
1440 }
1441 spin_unlock_irq(&dev_priv->uncore.lock);
1442
1443 return 0;
1444}
1445
Deepak S669ab5a2014-01-10 15:18:26 +05301446static int vlv_drpc_info(struct seq_file *m)
1447{
David Weinehall36cdd012016-08-22 13:59:31 +03001448 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001449 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301450
Imre Deakd46c0512014-04-14 20:24:27 +03001451 intel_runtime_pm_get(dev_priv);
1452
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001453 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301454 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1455 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1456
Imre Deakd46c0512014-04-14 20:24:27 +03001457 intel_runtime_pm_put(dev_priv);
1458
Deepak S669ab5a2014-01-10 15:18:26 +05301459 seq_printf(m, "Video Turbo Mode: %s\n",
1460 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1461 seq_printf(m, "Turbo enabled: %s\n",
1462 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1463 seq_printf(m, "HW control enabled: %s\n",
1464 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1465 seq_printf(m, "SW control enabled: %s\n",
1466 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1467 GEN6_RP_MEDIA_SW_MODE));
1468 seq_printf(m, "RC6 Enabled: %s\n",
1469 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1470 GEN6_RC_CTL_EI_MODE(1))));
1471 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001472 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301473 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001474 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301475
Imre Deak9cc19be2014-04-14 20:24:24 +03001476 seq_printf(m, "Render RC6 residency since boot: %u\n",
1477 I915_READ(VLV_GT_RENDER_RC6));
1478 seq_printf(m, "Media RC6 residency since boot: %u\n",
1479 I915_READ(VLV_GT_MEDIA_RC6));
1480
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001481 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301482}
1483
Ben Widawsky4d855292011-12-12 19:34:16 -08001484static int gen6_drpc_info(struct seq_file *m)
1485{
David Weinehall36cdd012016-08-22 13:59:31 +03001486 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1487 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001488 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301489 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001490 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001491 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001492
1493 ret = mutex_lock_interruptible(&dev->struct_mutex);
1494 if (ret)
1495 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001496 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001497
Chris Wilson907b28c2013-07-19 20:36:52 +01001498 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001499 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001500 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001501
1502 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001503 seq_puts(m, "RC information inaccurate because somebody "
1504 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001505 } else {
1506 /* NB: we cannot use forcewake, else we read the wrong values */
1507 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1508 udelay(10);
1509 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1510 }
1511
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001512 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001513 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001514
1515 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1516 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001517 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301518 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1519 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1520 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001521 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001522 mutex_lock(&dev_priv->rps.hw_lock);
1523 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1524 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001525
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001526 intel_runtime_pm_put(dev_priv);
1527
Ben Widawsky4d855292011-12-12 19:34:16 -08001528 seq_printf(m, "Video Turbo Mode: %s\n",
1529 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1530 seq_printf(m, "HW control enabled: %s\n",
1531 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1532 seq_printf(m, "SW control enabled: %s\n",
1533 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1534 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001535 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001536 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1537 seq_printf(m, "RC6 Enabled: %s\n",
1538 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001539 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301540 seq_printf(m, "Render Well Gating Enabled: %s\n",
1541 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1542 seq_printf(m, "Media Well Gating Enabled: %s\n",
1543 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1544 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001545 seq_printf(m, "Deep RC6 Enabled: %s\n",
1546 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1547 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1548 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001549 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001550 switch (gt_core_status & GEN6_RCn_MASK) {
1551 case GEN6_RC0:
1552 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001553 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001555 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001556 break;
1557 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001558 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 break;
1560 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001561 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001562 break;
1563 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001564 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 break;
1566 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001567 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001568 break;
1569 }
1570
1571 seq_printf(m, "Core Power Down: %s\n",
1572 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001573 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301574 seq_printf(m, "Render Power Well: %s\n",
1575 (gen9_powergate_status &
1576 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1577 seq_printf(m, "Media Power Well: %s\n",
1578 (gen9_powergate_status &
1579 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1580 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001581
1582 /* Not exactly sure what this is */
1583 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1584 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1585 seq_printf(m, "RC6 residency since boot: %u\n",
1586 I915_READ(GEN6_GT_GFX_RC6));
1587 seq_printf(m, "RC6+ residency since boot: %u\n",
1588 I915_READ(GEN6_GT_GFX_RC6p));
1589 seq_printf(m, "RC6++ residency since boot: %u\n",
1590 I915_READ(GEN6_GT_GFX_RC6pp));
1591
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001592 seq_printf(m, "RC6 voltage: %dmV\n",
1593 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1594 seq_printf(m, "RC6+ voltage: %dmV\n",
1595 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1596 seq_printf(m, "RC6++ voltage: %dmV\n",
1597 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301598 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001599}
1600
1601static int i915_drpc_info(struct seq_file *m, void *unused)
1602{
David Weinehall36cdd012016-08-22 13:59:31 +03001603 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001604
David Weinehall36cdd012016-08-22 13:59:31 +03001605 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301606 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001607 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001608 return gen6_drpc_info(m);
1609 else
1610 return ironlake_drpc_info(m);
1611}
1612
Daniel Vetter9a851782015-06-18 10:30:22 +02001613static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1614{
David Weinehall36cdd012016-08-22 13:59:31 +03001615 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001616
1617 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1618 dev_priv->fb_tracking.busy_bits);
1619
1620 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1621 dev_priv->fb_tracking.flip_bits);
1622
1623 return 0;
1624}
1625
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001626static int i915_fbc_status(struct seq_file *m, void *unused)
1627{
David Weinehall36cdd012016-08-22 13:59:31 +03001628 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001629
David Weinehall36cdd012016-08-22 13:59:31 +03001630 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001631 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001632 return 0;
1633 }
1634
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001635 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001636 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001637
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001638 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001639 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001640 else
1641 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001642 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001643
David Weinehall36cdd012016-08-22 13:59:31 +03001644 if (INTEL_GEN(dev_priv) >= 7)
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001645 seq_printf(m, "Compressing: %s\n",
1646 yesno(I915_READ(FBC_STATUS2) &
1647 FBC_COMPRESSION_MASK));
1648
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001649 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001650 intel_runtime_pm_put(dev_priv);
1651
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001652 return 0;
1653}
1654
Rodrigo Vivida46f932014-08-01 02:04:45 -07001655static int i915_fbc_fc_get(void *data, u64 *val)
1656{
David Weinehall36cdd012016-08-22 13:59:31 +03001657 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001658
David Weinehall36cdd012016-08-22 13:59:31 +03001659 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001660 return -ENODEV;
1661
Rodrigo Vivida46f932014-08-01 02:04:45 -07001662 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001663
1664 return 0;
1665}
1666
1667static int i915_fbc_fc_set(void *data, u64 val)
1668{
David Weinehall36cdd012016-08-22 13:59:31 +03001669 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001670 u32 reg;
1671
David Weinehall36cdd012016-08-22 13:59:31 +03001672 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001673 return -ENODEV;
1674
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001675 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001676
1677 reg = I915_READ(ILK_DPFC_CONTROL);
1678 dev_priv->fbc.false_color = val;
1679
1680 I915_WRITE(ILK_DPFC_CONTROL, val ?
1681 (reg | FBC_CTL_FALSE_COLOR) :
1682 (reg & ~FBC_CTL_FALSE_COLOR));
1683
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001684 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001685 return 0;
1686}
1687
1688DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1689 i915_fbc_fc_get, i915_fbc_fc_set,
1690 "%llu\n");
1691
Paulo Zanoni92d44622013-05-31 16:33:24 -03001692static int i915_ips_status(struct seq_file *m, void *unused)
1693{
David Weinehall36cdd012016-08-22 13:59:31 +03001694 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001695
David Weinehall36cdd012016-08-22 13:59:31 +03001696 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001697 seq_puts(m, "not supported\n");
1698 return 0;
1699 }
1700
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001701 intel_runtime_pm_get(dev_priv);
1702
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001703 seq_printf(m, "Enabled by kernel parameter: %s\n",
1704 yesno(i915.enable_ips));
1705
David Weinehall36cdd012016-08-22 13:59:31 +03001706 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001707 seq_puts(m, "Currently: unknown\n");
1708 } else {
1709 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1710 seq_puts(m, "Currently: enabled\n");
1711 else
1712 seq_puts(m, "Currently: disabled\n");
1713 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001714
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001715 intel_runtime_pm_put(dev_priv);
1716
Paulo Zanoni92d44622013-05-31 16:33:24 -03001717 return 0;
1718}
1719
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001720static int i915_sr_status(struct seq_file *m, void *unused)
1721{
David Weinehall36cdd012016-08-22 13:59:31 +03001722 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001723 bool sr_enabled = false;
1724
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001725 intel_runtime_pm_get(dev_priv);
1726
David Weinehall36cdd012016-08-22 13:59:31 +03001727 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001728 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001729 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1730 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001731 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001732 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001733 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001734 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001735 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001736 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001737 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001738
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001739 intel_runtime_pm_put(dev_priv);
1740
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001741 seq_printf(m, "self-refresh: %s\n",
1742 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001743
1744 return 0;
1745}
1746
Jesse Barnes7648fa92010-05-20 14:28:11 -07001747static int i915_emon_status(struct seq_file *m, void *unused)
1748{
David Weinehall36cdd012016-08-22 13:59:31 +03001749 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1750 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001751 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001752 int ret;
1753
David Weinehall36cdd012016-08-22 13:59:31 +03001754 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001755 return -ENODEV;
1756
Chris Wilsonde227ef2010-07-03 07:58:38 +01001757 ret = mutex_lock_interruptible(&dev->struct_mutex);
1758 if (ret)
1759 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001760
1761 temp = i915_mch_val(dev_priv);
1762 chipset = i915_chipset_val(dev_priv);
1763 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001764 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001765
1766 seq_printf(m, "GMCH temp: %ld\n", temp);
1767 seq_printf(m, "Chipset power: %ld\n", chipset);
1768 seq_printf(m, "GFX power: %ld\n", gfx);
1769 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1770
1771 return 0;
1772}
1773
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001774static int i915_ring_freq_table(struct seq_file *m, void *unused)
1775{
David Weinehall36cdd012016-08-22 13:59:31 +03001776 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001777 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001778 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301779 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001780
David Weinehall36cdd012016-08-22 13:59:31 +03001781 if (!HAS_CORE_RING_FREQ(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001782 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001783 return 0;
1784 }
1785
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001786 intel_runtime_pm_get(dev_priv);
1787
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001788 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001790 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001791
David Weinehall36cdd012016-08-22 13:59:31 +03001792 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301793 /* Convert GT frequency to 50 HZ units */
1794 min_gpu_freq =
1795 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1796 max_gpu_freq =
1797 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1798 } else {
1799 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1800 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1801 }
1802
Damien Lespiau267f0c92013-06-24 22:59:48 +01001803 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001804
Akash Goelf936ec32015-06-29 14:50:22 +05301805 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001806 ia_freq = gpu_freq;
1807 sandybridge_pcode_read(dev_priv,
1808 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1809 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001810 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301811 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001812 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001813 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001814 ((ia_freq >> 0) & 0xff) * 100,
1815 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001816 }
1817
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001818 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001819
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001820out:
1821 intel_runtime_pm_put(dev_priv);
1822 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001823}
1824
Chris Wilson44834a62010-08-19 16:09:23 +01001825static int i915_opregion(struct seq_file *m, void *unused)
1826{
David Weinehall36cdd012016-08-22 13:59:31 +03001827 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1828 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001829 struct intel_opregion *opregion = &dev_priv->opregion;
1830 int ret;
1831
1832 ret = mutex_lock_interruptible(&dev->struct_mutex);
1833 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001834 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001835
Jani Nikula2455a8e2015-12-14 12:50:53 +02001836 if (opregion->header)
1837 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001838
1839 mutex_unlock(&dev->struct_mutex);
1840
Daniel Vetter0d38f002012-04-21 22:49:10 +02001841out:
Chris Wilson44834a62010-08-19 16:09:23 +01001842 return 0;
1843}
1844
Jani Nikulaada8f952015-12-15 13:17:12 +02001845static int i915_vbt(struct seq_file *m, void *unused)
1846{
David Weinehall36cdd012016-08-22 13:59:31 +03001847 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001848
1849 if (opregion->vbt)
1850 seq_write(m, opregion->vbt, opregion->vbt_size);
1851
1852 return 0;
1853}
1854
Chris Wilson37811fc2010-08-25 22:45:57 +01001855static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1856{
David Weinehall36cdd012016-08-22 13:59:31 +03001857 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1858 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301859 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001860 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001861 int ret;
1862
1863 ret = mutex_lock_interruptible(&dev->struct_mutex);
1864 if (ret)
1865 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001866
Daniel Vetter06957262015-08-10 13:34:08 +02001867#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001868 if (dev_priv->fbdev) {
1869 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001870
Chris Wilson25bcce92016-07-02 15:36:00 +01001871 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1872 fbdev_fb->base.width,
1873 fbdev_fb->base.height,
1874 fbdev_fb->base.depth,
1875 fbdev_fb->base.bits_per_pixel,
1876 fbdev_fb->base.modifier[0],
1877 drm_framebuffer_read_refcount(&fbdev_fb->base));
1878 describe_obj(m, fbdev_fb->obj);
1879 seq_putc(m, '\n');
1880 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001881#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001882
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001883 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001884 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301885 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1886 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001887 continue;
1888
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001889 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 +01001890 fb->base.width,
1891 fb->base.height,
1892 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001893 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001894 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001895 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001896 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001897 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001898 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001899 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001900 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001901
1902 return 0;
1903}
1904
Chris Wilson7e37f882016-08-02 22:50:21 +01001905static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001906{
1907 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001908 ring->space, ring->head, ring->tail,
1909 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001910}
1911
Ben Widawskye76d3632011-03-19 18:14:29 -07001912static int i915_context_status(struct seq_file *m, void *unused)
1913{
David Weinehall36cdd012016-08-22 13:59:31 +03001914 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1915 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001916 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001917 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00001918 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001919
Daniel Vetterf3d28872014-05-29 23:23:08 +02001920 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001921 if (ret)
1922 return ret;
1923
Ben Widawskya33afea2013-09-17 21:12:45 -07001924 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001925 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001926 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001927 struct task_struct *task;
1928
Chris Wilsonc84455b2016-08-15 10:49:08 +01001929 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001930 if (task) {
1931 seq_printf(m, "(%s [%d]) ",
1932 task->comm, task->pid);
1933 put_task_struct(task);
1934 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001935 } else if (IS_ERR(ctx->file_priv)) {
1936 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001937 } else {
1938 seq_puts(m, "(kernel) ");
1939 }
1940
Chris Wilsonbca44d82016-05-24 14:53:41 +01001941 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1942 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001943
Chris Wilsonbca44d82016-05-24 14:53:41 +01001944 for_each_engine(engine, dev_priv) {
1945 struct intel_context *ce = &ctx->engine[engine->id];
1946
1947 seq_printf(m, "%s: ", engine->name);
1948 seq_putc(m, ce->initialised ? 'I' : 'i');
1949 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001950 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001951 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001952 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001953 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001954 }
1955
Ben Widawskya33afea2013-09-17 21:12:45 -07001956 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001957 }
1958
Daniel Vetterf3d28872014-05-29 23:23:08 +02001959 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001960
1961 return 0;
1962}
1963
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001964static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001965 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001966 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001967{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001968 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001969 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001970 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001971
Chris Wilson7069b142016-04-28 09:56:52 +01001972 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1973
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001974 if (!vma) {
1975 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001976 return;
1977 }
1978
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001979 if (vma->flags & I915_VMA_GLOBAL_BIND)
1980 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01001981 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001982
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001983 if (i915_gem_object_get_pages(vma->obj)) {
1984 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001985 return;
1986 }
1987
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001988 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
1989 if (page) {
1990 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001991
1992 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001993 seq_printf(m,
1994 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1995 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001996 reg_state[j], reg_state[j + 1],
1997 reg_state[j + 2], reg_state[j + 3]);
1998 }
1999 kunmap_atomic(reg_state);
2000 }
2001
2002 seq_putc(m, '\n');
2003}
2004
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002005static int i915_dump_lrc(struct seq_file *m, void *unused)
2006{
David Weinehall36cdd012016-08-22 13:59:31 +03002007 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2008 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002009 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002010 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002011 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002012
2013 if (!i915.enable_execlists) {
2014 seq_printf(m, "Logical Ring Contexts are disabled\n");
2015 return 0;
2016 }
2017
2018 ret = mutex_lock_interruptible(&dev->struct_mutex);
2019 if (ret)
2020 return ret;
2021
Dave Gordone28e4042016-01-19 19:02:55 +00002022 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002023 for_each_engine(engine, dev_priv)
2024 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002025
2026 mutex_unlock(&dev->struct_mutex);
2027
2028 return 0;
2029}
2030
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002031static int i915_execlists(struct seq_file *m, void *data)
2032{
David Weinehall36cdd012016-08-22 13:59:31 +03002033 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2034 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002035 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002036 u32 status_pointer;
2037 u8 read_pointer;
2038 u8 write_pointer;
2039 u32 status;
2040 u32 ctx_id;
2041 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002042 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002043
2044 if (!i915.enable_execlists) {
2045 seq_puts(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
Michel Thierryfc0412e2014-10-16 16:13:38 +01002053 intel_runtime_pm_get(dev_priv);
2054
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002055 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002056 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002057 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002058
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002059 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002060
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002061 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2062 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002063 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2064 status, ctx_id);
2065
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002066 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002067 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2068
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002069 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002070 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002071 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002072 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002073 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2074 read_pointer, write_pointer);
2075
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002076 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002077 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2078 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002079
2080 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2081 i, status, ctx_id);
2082 }
2083
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002084 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002085 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002086 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002087 head_req = list_first_entry_or_null(&engine->execlist_queue,
2088 struct drm_i915_gem_request,
2089 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002090 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002091
2092 seq_printf(m, "\t%d requests in queue\n", count);
2093 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002094 seq_printf(m, "\tHead request context: %u\n",
2095 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002096 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002097 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002098 }
2099
2100 seq_putc(m, '\n');
2101 }
2102
Michel Thierryfc0412e2014-10-16 16:13:38 +01002103 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002104 mutex_unlock(&dev->struct_mutex);
2105
2106 return 0;
2107}
2108
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002109static const char *swizzle_string(unsigned swizzle)
2110{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002111 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002112 case I915_BIT_6_SWIZZLE_NONE:
2113 return "none";
2114 case I915_BIT_6_SWIZZLE_9:
2115 return "bit9";
2116 case I915_BIT_6_SWIZZLE_9_10:
2117 return "bit9/bit10";
2118 case I915_BIT_6_SWIZZLE_9_11:
2119 return "bit9/bit11";
2120 case I915_BIT_6_SWIZZLE_9_10_11:
2121 return "bit9/bit10/bit11";
2122 case I915_BIT_6_SWIZZLE_9_17:
2123 return "bit9/bit17";
2124 case I915_BIT_6_SWIZZLE_9_10_17:
2125 return "bit9/bit10/bit17";
2126 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002127 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002128 }
2129
2130 return "bug";
2131}
2132
2133static int i915_swizzle_info(struct seq_file *m, void *data)
2134{
David Weinehall36cdd012016-08-22 13:59:31 +03002135 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2136 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002137 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002138
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002139 ret = mutex_lock_interruptible(&dev->struct_mutex);
2140 if (ret)
2141 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002142 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002143
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002144 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2145 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2146 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2147 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2148
David Weinehall36cdd012016-08-22 13:59:31 +03002149 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002150 seq_printf(m, "DDC = 0x%08x\n",
2151 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002152 seq_printf(m, "DDC2 = 0x%08x\n",
2153 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002154 seq_printf(m, "C0DRB3 = 0x%04x\n",
2155 I915_READ16(C0DRB3));
2156 seq_printf(m, "C1DRB3 = 0x%04x\n",
2157 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002158 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002159 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2160 I915_READ(MAD_DIMM_C0));
2161 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2162 I915_READ(MAD_DIMM_C1));
2163 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2164 I915_READ(MAD_DIMM_C2));
2165 seq_printf(m, "TILECTL = 0x%08x\n",
2166 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002167 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002168 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2169 I915_READ(GAMTARBMODE));
2170 else
2171 seq_printf(m, "ARB_MODE = 0x%08x\n",
2172 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002173 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2174 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002175 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002176
2177 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2178 seq_puts(m, "L-shaped memory detected\n");
2179
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002180 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002181 mutex_unlock(&dev->struct_mutex);
2182
2183 return 0;
2184}
2185
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002186static int per_file_ctx(int id, void *ptr, void *data)
2187{
Chris Wilsone2efd132016-05-24 14:53:34 +01002188 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002189 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002190 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2191
2192 if (!ppgtt) {
2193 seq_printf(m, " no ppgtt for context %d\n",
2194 ctx->user_handle);
2195 return 0;
2196 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002197
Oscar Mateof83d6512014-05-22 14:13:38 +01002198 if (i915_gem_context_is_default(ctx))
2199 seq_puts(m, " default context:\n");
2200 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002201 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002202 ppgtt->debug_dump(ppgtt, m);
2203
2204 return 0;
2205}
2206
David Weinehall36cdd012016-08-22 13:59:31 +03002207static void gen8_ppgtt_info(struct seq_file *m,
2208 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002209{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002210 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002211 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002212 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002213
Ben Widawsky77df6772013-11-02 21:07:30 -07002214 if (!ppgtt)
2215 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002216
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002217 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002218 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002219 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002220 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002221 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002222 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002223 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002224 }
2225 }
2226}
2227
David Weinehall36cdd012016-08-22 13:59:31 +03002228static void gen6_ppgtt_info(struct seq_file *m,
2229 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002230{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002231 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002232
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002233 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002234 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2235
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002236 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002237 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002238 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002239 seq_printf(m, "GFX_MODE: 0x%08x\n",
2240 I915_READ(RING_MODE_GEN7(engine)));
2241 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2242 I915_READ(RING_PP_DIR_BASE(engine)));
2243 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2244 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2245 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2246 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002247 }
2248 if (dev_priv->mm.aliasing_ppgtt) {
2249 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2250
Damien Lespiau267f0c92013-06-24 22:59:48 +01002251 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002252 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002253
Ben Widawsky87d60b62013-12-06 14:11:29 -08002254 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002255 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002256
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002257 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002258}
2259
2260static int i915_ppgtt_info(struct seq_file *m, void *data)
2261{
David Weinehall36cdd012016-08-22 13:59:31 +03002262 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2263 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002264 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002265 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002266
Chris Wilson637ee292016-08-22 14:28:20 +01002267 mutex_lock(&dev->filelist_mutex);
2268 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002269 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002270 goto out_unlock;
2271
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002272 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002273
David Weinehall36cdd012016-08-22 13:59:31 +03002274 if (INTEL_GEN(dev_priv) >= 8)
2275 gen8_ppgtt_info(m, dev_priv);
2276 else if (INTEL_GEN(dev_priv) >= 6)
2277 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002278
Michel Thierryea91e402015-07-29 17:23:57 +01002279 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2280 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002281 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002282
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002283 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002284 if (!task) {
2285 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002286 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002287 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002288 seq_printf(m, "\nproc: %s\n", task->comm);
2289 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002290 idr_for_each(&file_priv->context_idr, per_file_ctx,
2291 (void *)(unsigned long)m);
2292 }
2293
Chris Wilson637ee292016-08-22 14:28:20 +01002294out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002295 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002296 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002297out_unlock:
2298 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002299 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002300}
2301
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002302static int count_irq_waiters(struct drm_i915_private *i915)
2303{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002304 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002305 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002306
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002307 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002308 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002309
2310 return count;
2311}
2312
Chris Wilson7466c292016-08-15 09:49:33 +01002313static const char *rps_power_to_str(unsigned int power)
2314{
2315 static const char * const strings[] = {
2316 [LOW_POWER] = "low power",
2317 [BETWEEN] = "mixed",
2318 [HIGH_POWER] = "high power",
2319 };
2320
2321 if (power >= ARRAY_SIZE(strings) || !strings[power])
2322 return "unknown";
2323
2324 return strings[power];
2325}
2326
Chris Wilson1854d5c2015-04-07 16:20:32 +01002327static int i915_rps_boost_info(struct seq_file *m, void *data)
2328{
David Weinehall36cdd012016-08-22 13:59:31 +03002329 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2330 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002331 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002332
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002333 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002334 seq_printf(m, "GPU busy? %s [%x]\n",
2335 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002336 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002337 seq_printf(m, "Frequency requested %d\n",
2338 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2339 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002340 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2341 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2342 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2343 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002344 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2345 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2346 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2347 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002348
2349 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002350 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002351 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2352 struct drm_i915_file_private *file_priv = file->driver_priv;
2353 struct task_struct *task;
2354
2355 rcu_read_lock();
2356 task = pid_task(file->pid, PIDTYPE_PID);
2357 seq_printf(m, "%s [%d]: %d boosts%s\n",
2358 task ? task->comm : "<unknown>",
2359 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002360 file_priv->rps.boosts,
2361 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002362 rcu_read_unlock();
2363 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002364 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002365 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002366 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002367
Chris Wilson7466c292016-08-15 09:49:33 +01002368 if (INTEL_GEN(dev_priv) >= 6 &&
2369 dev_priv->rps.enabled &&
2370 dev_priv->gt.active_engines) {
2371 u32 rpup, rpupei;
2372 u32 rpdown, rpdownei;
2373
2374 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2375 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2376 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2377 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2378 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2379 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2380
2381 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2382 rps_power_to_str(dev_priv->rps.power));
2383 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2384 100 * rpup / rpupei,
2385 dev_priv->rps.up_threshold);
2386 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2387 100 * rpdown / rpdownei,
2388 dev_priv->rps.down_threshold);
2389 } else {
2390 seq_puts(m, "\nRPS Autotuning inactive\n");
2391 }
2392
Chris Wilson8d3afd72015-05-21 21:01:47 +01002393 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002394}
2395
Ben Widawsky63573eb2013-07-04 11:02:07 -07002396static int i915_llc(struct seq_file *m, void *data)
2397{
David Weinehall36cdd012016-08-22 13:59:31 +03002398 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002399 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002400
David Weinehall36cdd012016-08-22 13:59:31 +03002401 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002402 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2403 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002404
2405 return 0;
2406}
2407
Alex Daifdf5d352015-08-12 15:43:37 +01002408static int i915_guc_load_status_info(struct seq_file *m, void *data)
2409{
David Weinehall36cdd012016-08-22 13:59:31 +03002410 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002411 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2412 u32 tmp, i;
2413
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002414 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002415 return 0;
2416
2417 seq_printf(m, "GuC firmware status:\n");
2418 seq_printf(m, "\tpath: %s\n",
2419 guc_fw->guc_fw_path);
2420 seq_printf(m, "\tfetch: %s\n",
2421 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2422 seq_printf(m, "\tload: %s\n",
2423 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2424 seq_printf(m, "\tversion wanted: %d.%d\n",
2425 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2426 seq_printf(m, "\tversion found: %d.%d\n",
2427 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002428 seq_printf(m, "\theader: offset is %d; size = %d\n",
2429 guc_fw->header_offset, guc_fw->header_size);
2430 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2431 guc_fw->ucode_offset, guc_fw->ucode_size);
2432 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2433 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002434
2435 tmp = I915_READ(GUC_STATUS);
2436
2437 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2438 seq_printf(m, "\tBootrom status = 0x%x\n",
2439 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2440 seq_printf(m, "\tuKernel status = 0x%x\n",
2441 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2442 seq_printf(m, "\tMIA Core status = 0x%x\n",
2443 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2444 seq_puts(m, "\nScratch registers:\n");
2445 for (i = 0; i < 16; i++)
2446 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2447
2448 return 0;
2449}
2450
Dave Gordon8b417c22015-08-12 15:43:44 +01002451static void i915_guc_client_info(struct seq_file *m,
2452 struct drm_i915_private *dev_priv,
2453 struct i915_guc_client *client)
2454{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002455 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002456 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002457 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002458
2459 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2460 client->priority, client->ctx_index, client->proc_desc_offset);
2461 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2462 client->doorbell_id, client->doorbell_offset, client->cookie);
2463 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2464 client->wq_size, client->wq_offset, client->wq_tail);
2465
Dave Gordon551aaec2016-05-13 15:36:33 +01002466 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002467 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2468 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2469
Dave Gordonc18468c2016-08-09 15:19:22 +01002470 for_each_engine_id(engine, dev_priv, id) {
2471 u64 submissions = client->submissions[id];
2472 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002473 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002474 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002475 }
2476 seq_printf(m, "\tTotal: %llu\n", tot);
2477}
2478
2479static int i915_guc_info(struct seq_file *m, void *data)
2480{
David Weinehall36cdd012016-08-22 13:59:31 +03002481 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2482 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002483 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002484 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002485 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002486 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002487 u64 total = 0;
2488
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002489 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002490 return 0;
2491
Alex Dai5a843302015-12-02 16:56:29 -08002492 if (mutex_lock_interruptible(&dev->struct_mutex))
2493 return 0;
2494
Dave Gordon8b417c22015-08-12 15:43:44 +01002495 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002496 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002497 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002498 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002499
2500 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002501
Dave Gordon9636f6d2016-06-13 17:57:28 +01002502 seq_printf(m, "Doorbell map:\n");
2503 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2504 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2505
Dave Gordon8b417c22015-08-12 15:43:44 +01002506 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2507 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2508 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2509 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2510 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2511
2512 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonc18468c2016-08-09 15:19:22 +01002513 for_each_engine_id(engine, dev_priv, id) {
2514 u64 submissions = guc.submissions[id];
2515 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002516 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002517 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002518 }
2519 seq_printf(m, "\t%s: %llu\n", "Total", total);
2520
2521 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2522 i915_guc_client_info(m, dev_priv, &client);
2523
2524 /* Add more as required ... */
2525
2526 return 0;
2527}
2528
Alex Dai4c7e77f2015-08-12 15:43:40 +01002529static int i915_guc_log_dump(struct seq_file *m, void *data)
2530{
David Weinehall36cdd012016-08-22 13:59:31 +03002531 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002532 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002533 int i = 0, pg;
2534
Chris Wilson8b797af2016-08-15 10:48:51 +01002535 if (!dev_priv->guc.log_vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002536 return 0;
2537
Chris Wilson8b797af2016-08-15 10:48:51 +01002538 obj = dev_priv->guc.log_vma->obj;
2539 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2540 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002541
2542 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2543 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2544 *(log + i), *(log + i + 1),
2545 *(log + i + 2), *(log + i + 3));
2546
2547 kunmap_atomic(log);
2548 }
2549
2550 seq_putc(m, '\n');
2551
2552 return 0;
2553}
2554
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002555static int i915_edp_psr_status(struct seq_file *m, void *data)
2556{
David Weinehall36cdd012016-08-22 13:59:31 +03002557 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002558 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002559 u32 stat[3];
2560 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002561 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002562
David Weinehall36cdd012016-08-22 13:59:31 +03002563 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002564 seq_puts(m, "PSR not supported\n");
2565 return 0;
2566 }
2567
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002568 intel_runtime_pm_get(dev_priv);
2569
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002570 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002571 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2572 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002573 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002574 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002575 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2576 dev_priv->psr.busy_frontbuffer_bits);
2577 seq_printf(m, "Re-enable work scheduled: %s\n",
2578 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002579
David Weinehall36cdd012016-08-22 13:59:31 +03002580 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002581 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002582 else {
2583 for_each_pipe(dev_priv, pipe) {
2584 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2585 VLV_EDP_PSR_CURR_STATE_MASK;
2586 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2587 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2588 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002589 }
2590 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002591
2592 seq_printf(m, "Main link in standby mode: %s\n",
2593 yesno(dev_priv->psr.link_standby));
2594
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002595 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002596
David Weinehall36cdd012016-08-22 13:59:31 +03002597 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002598 for_each_pipe(dev_priv, pipe) {
2599 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2600 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2601 seq_printf(m, " pipe %c", pipe_name(pipe));
2602 }
2603 seq_puts(m, "\n");
2604
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002605 /*
2606 * VLV/CHV PSR has no kind of performance counter
2607 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2608 */
David Weinehall36cdd012016-08-22 13:59:31 +03002609 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002610 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002611 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002612
2613 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2614 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002615 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002616
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002617 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002618 return 0;
2619}
2620
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002621static int i915_sink_crc(struct seq_file *m, void *data)
2622{
David Weinehall36cdd012016-08-22 13:59:31 +03002623 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2624 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002625 struct intel_connector *connector;
2626 struct intel_dp *intel_dp = NULL;
2627 int ret;
2628 u8 crc[6];
2629
2630 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002631 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002632 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002633
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002634 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002635 continue;
2636
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002637 crtc = connector->base.state->crtc;
2638 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002639 continue;
2640
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002641 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002642 continue;
2643
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002644 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002645
2646 ret = intel_dp_sink_crc(intel_dp, crc);
2647 if (ret)
2648 goto out;
2649
2650 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2651 crc[0], crc[1], crc[2],
2652 crc[3], crc[4], crc[5]);
2653 goto out;
2654 }
2655 ret = -ENODEV;
2656out:
2657 drm_modeset_unlock_all(dev);
2658 return ret;
2659}
2660
Jesse Barnesec013e72013-08-20 10:29:23 +01002661static int i915_energy_uJ(struct seq_file *m, void *data)
2662{
David Weinehall36cdd012016-08-22 13:59:31 +03002663 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002664 u64 power;
2665 u32 units;
2666
David Weinehall36cdd012016-08-22 13:59:31 +03002667 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002668 return -ENODEV;
2669
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002670 intel_runtime_pm_get(dev_priv);
2671
Jesse Barnesec013e72013-08-20 10:29:23 +01002672 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2673 power = (power & 0x1f00) >> 8;
2674 units = 1000000 / (1 << power); /* convert to uJ */
2675 power = I915_READ(MCH_SECP_NRG_STTS);
2676 power *= units;
2677
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002678 intel_runtime_pm_put(dev_priv);
2679
Jesse Barnesec013e72013-08-20 10:29:23 +01002680 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002681
2682 return 0;
2683}
2684
Damien Lespiau6455c872015-06-04 18:23:57 +01002685static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002686{
David Weinehall36cdd012016-08-22 13:59:31 +03002687 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002688 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002689
Chris Wilsona156e642016-04-03 14:14:21 +01002690 if (!HAS_RUNTIME_PM(dev_priv))
2691 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002692
Chris Wilson67d97da2016-07-04 08:08:31 +01002693 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002694 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002695 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002696#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002697 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002698 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002699#else
2700 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2701#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002702 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002703 pci_power_name(pdev->current_state),
2704 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002705
Jesse Barnesec013e72013-08-20 10:29:23 +01002706 return 0;
2707}
2708
Imre Deak1da51582013-11-25 17:15:35 +02002709static int i915_power_domain_info(struct seq_file *m, void *unused)
2710{
David Weinehall36cdd012016-08-22 13:59:31 +03002711 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002712 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2713 int i;
2714
2715 mutex_lock(&power_domains->lock);
2716
2717 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2718 for (i = 0; i < power_domains->power_well_count; i++) {
2719 struct i915_power_well *power_well;
2720 enum intel_display_power_domain power_domain;
2721
2722 power_well = &power_domains->power_wells[i];
2723 seq_printf(m, "%-25s %d\n", power_well->name,
2724 power_well->count);
2725
2726 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2727 power_domain++) {
2728 if (!(BIT(power_domain) & power_well->domains))
2729 continue;
2730
2731 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002732 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002733 power_domains->domain_use_count[power_domain]);
2734 }
2735 }
2736
2737 mutex_unlock(&power_domains->lock);
2738
2739 return 0;
2740}
2741
Damien Lespiaub7cec662015-10-27 14:47:01 +02002742static int i915_dmc_info(struct seq_file *m, void *unused)
2743{
David Weinehall36cdd012016-08-22 13:59:31 +03002744 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002745 struct intel_csr *csr;
2746
David Weinehall36cdd012016-08-22 13:59:31 +03002747 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002748 seq_puts(m, "not supported\n");
2749 return 0;
2750 }
2751
2752 csr = &dev_priv->csr;
2753
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002754 intel_runtime_pm_get(dev_priv);
2755
Damien Lespiaub7cec662015-10-27 14:47:01 +02002756 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2757 seq_printf(m, "path: %s\n", csr->fw_path);
2758
2759 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002760 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002761
2762 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2763 CSR_VERSION_MINOR(csr->version));
2764
David Weinehall36cdd012016-08-22 13:59:31 +03002765 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002766 seq_printf(m, "DC3 -> DC5 count: %d\n",
2767 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2768 seq_printf(m, "DC5 -> DC6 count: %d\n",
2769 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002770 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002771 seq_printf(m, "DC3 -> DC5 count: %d\n",
2772 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002773 }
2774
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002775out:
2776 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2777 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2778 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2779
Damien Lespiau83372062015-10-30 17:53:32 +02002780 intel_runtime_pm_put(dev_priv);
2781
Damien Lespiaub7cec662015-10-27 14:47:01 +02002782 return 0;
2783}
2784
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002785static void intel_seq_print_mode(struct seq_file *m, int tabs,
2786 struct drm_display_mode *mode)
2787{
2788 int i;
2789
2790 for (i = 0; i < tabs; i++)
2791 seq_putc(m, '\t');
2792
2793 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",
2794 mode->base.id, mode->name,
2795 mode->vrefresh, mode->clock,
2796 mode->hdisplay, mode->hsync_start,
2797 mode->hsync_end, mode->htotal,
2798 mode->vdisplay, mode->vsync_start,
2799 mode->vsync_end, mode->vtotal,
2800 mode->type, mode->flags);
2801}
2802
2803static void intel_encoder_info(struct seq_file *m,
2804 struct intel_crtc *intel_crtc,
2805 struct intel_encoder *intel_encoder)
2806{
David Weinehall36cdd012016-08-22 13:59:31 +03002807 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2808 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002809 struct drm_crtc *crtc = &intel_crtc->base;
2810 struct intel_connector *intel_connector;
2811 struct drm_encoder *encoder;
2812
2813 encoder = &intel_encoder->base;
2814 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002815 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002816 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2817 struct drm_connector *connector = &intel_connector->base;
2818 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2819 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002820 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002821 drm_get_connector_status_name(connector->status));
2822 if (connector->status == connector_status_connected) {
2823 struct drm_display_mode *mode = &crtc->mode;
2824 seq_printf(m, ", mode:\n");
2825 intel_seq_print_mode(m, 2, mode);
2826 } else {
2827 seq_putc(m, '\n');
2828 }
2829 }
2830}
2831
2832static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2833{
David Weinehall36cdd012016-08-22 13:59:31 +03002834 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2835 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002836 struct drm_crtc *crtc = &intel_crtc->base;
2837 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002838 struct drm_plane_state *plane_state = crtc->primary->state;
2839 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002840
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002841 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002842 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002843 fb->base.id, plane_state->src_x >> 16,
2844 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002845 else
2846 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002847 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2848 intel_encoder_info(m, intel_crtc, intel_encoder);
2849}
2850
2851static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2852{
2853 struct drm_display_mode *mode = panel->fixed_mode;
2854
2855 seq_printf(m, "\tfixed mode:\n");
2856 intel_seq_print_mode(m, 2, mode);
2857}
2858
2859static void intel_dp_info(struct seq_file *m,
2860 struct intel_connector *intel_connector)
2861{
2862 struct intel_encoder *intel_encoder = intel_connector->encoder;
2863 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2864
2865 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002866 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002867 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002868 intel_panel_info(m, &intel_connector->panel);
2869}
2870
2871static void intel_hdmi_info(struct seq_file *m,
2872 struct intel_connector *intel_connector)
2873{
2874 struct intel_encoder *intel_encoder = intel_connector->encoder;
2875 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2876
Jani Nikula742f4912015-09-03 11:16:09 +03002877 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002878}
2879
2880static void intel_lvds_info(struct seq_file *m,
2881 struct intel_connector *intel_connector)
2882{
2883 intel_panel_info(m, &intel_connector->panel);
2884}
2885
2886static void intel_connector_info(struct seq_file *m,
2887 struct drm_connector *connector)
2888{
2889 struct intel_connector *intel_connector = to_intel_connector(connector);
2890 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002891 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002892
2893 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002894 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002895 drm_get_connector_status_name(connector->status));
2896 if (connector->status == connector_status_connected) {
2897 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2898 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2899 connector->display_info.width_mm,
2900 connector->display_info.height_mm);
2901 seq_printf(m, "\tsubpixel order: %s\n",
2902 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2903 seq_printf(m, "\tCEA rev: %d\n",
2904 connector->display_info.cea_rev);
2905 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002906
2907 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2908 return;
2909
2910 switch (connector->connector_type) {
2911 case DRM_MODE_CONNECTOR_DisplayPort:
2912 case DRM_MODE_CONNECTOR_eDP:
2913 intel_dp_info(m, intel_connector);
2914 break;
2915 case DRM_MODE_CONNECTOR_LVDS:
2916 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002917 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002918 break;
2919 case DRM_MODE_CONNECTOR_HDMIA:
2920 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2921 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2922 intel_hdmi_info(m, intel_connector);
2923 break;
2924 default:
2925 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002926 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002927
Jesse Barnesf103fc72014-02-20 12:39:57 -08002928 seq_printf(m, "\tmodes:\n");
2929 list_for_each_entry(mode, &connector->modes, head)
2930 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002931}
2932
David Weinehall36cdd012016-08-22 13:59:31 +03002933static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002934{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002935 u32 state;
2936
David Weinehall36cdd012016-08-22 13:59:31 +03002937 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002938 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002939 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002940 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002941
2942 return state;
2943}
2944
David Weinehall36cdd012016-08-22 13:59:31 +03002945static bool cursor_position(struct drm_i915_private *dev_priv,
2946 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002947{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002948 u32 pos;
2949
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002950 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002951
2952 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2953 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2954 *x = -*x;
2955
2956 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2957 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2958 *y = -*y;
2959
David Weinehall36cdd012016-08-22 13:59:31 +03002960 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002961}
2962
Robert Fekete3abc4e02015-10-27 16:58:32 +01002963static const char *plane_type(enum drm_plane_type type)
2964{
2965 switch (type) {
2966 case DRM_PLANE_TYPE_OVERLAY:
2967 return "OVL";
2968 case DRM_PLANE_TYPE_PRIMARY:
2969 return "PRI";
2970 case DRM_PLANE_TYPE_CURSOR:
2971 return "CUR";
2972 /*
2973 * Deliberately omitting default: to generate compiler warnings
2974 * when a new drm_plane_type gets added.
2975 */
2976 }
2977
2978 return "unknown";
2979}
2980
2981static const char *plane_rotation(unsigned int rotation)
2982{
2983 static char buf[48];
2984 /*
2985 * According to doc only one DRM_ROTATE_ is allowed but this
2986 * will print them all to visualize if the values are misused
2987 */
2988 snprintf(buf, sizeof(buf),
2989 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03002990 (rotation & DRM_ROTATE_0) ? "0 " : "",
2991 (rotation & DRM_ROTATE_90) ? "90 " : "",
2992 (rotation & DRM_ROTATE_180) ? "180 " : "",
2993 (rotation & DRM_ROTATE_270) ? "270 " : "",
2994 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
2995 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01002996 rotation);
2997
2998 return buf;
2999}
3000
3001static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3002{
David Weinehall36cdd012016-08-22 13:59:31 +03003003 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3004 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003005 struct intel_plane *intel_plane;
3006
3007 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3008 struct drm_plane_state *state;
3009 struct drm_plane *plane = &intel_plane->base;
3010
3011 if (!plane->state) {
3012 seq_puts(m, "plane->state is NULL!\n");
3013 continue;
3014 }
3015
3016 state = plane->state;
3017
3018 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",
3019 plane->base.id,
3020 plane_type(intel_plane->base.type),
3021 state->crtc_x, state->crtc_y,
3022 state->crtc_w, state->crtc_h,
3023 (state->src_x >> 16),
3024 ((state->src_x & 0xffff) * 15625) >> 10,
3025 (state->src_y >> 16),
3026 ((state->src_y & 0xffff) * 15625) >> 10,
3027 (state->src_w >> 16),
3028 ((state->src_w & 0xffff) * 15625) >> 10,
3029 (state->src_h >> 16),
3030 ((state->src_h & 0xffff) * 15625) >> 10,
3031 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3032 plane_rotation(state->rotation));
3033 }
3034}
3035
3036static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3037{
3038 struct intel_crtc_state *pipe_config;
3039 int num_scalers = intel_crtc->num_scalers;
3040 int i;
3041
3042 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3043
3044 /* Not all platformas have a scaler */
3045 if (num_scalers) {
3046 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3047 num_scalers,
3048 pipe_config->scaler_state.scaler_users,
3049 pipe_config->scaler_state.scaler_id);
3050
3051 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3052 struct intel_scaler *sc =
3053 &pipe_config->scaler_state.scalers[i];
3054
3055 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3056 i, yesno(sc->in_use), sc->mode);
3057 }
3058 seq_puts(m, "\n");
3059 } else {
3060 seq_puts(m, "\tNo scalers available on this platform\n");
3061 }
3062}
3063
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003064static int i915_display_info(struct seq_file *m, void *unused)
3065{
David Weinehall36cdd012016-08-22 13:59:31 +03003066 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3067 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003068 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003069 struct drm_connector *connector;
3070
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003071 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003072 drm_modeset_lock_all(dev);
3073 seq_printf(m, "CRTC info\n");
3074 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003075 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003076 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003077 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003078 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003079
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003080 pipe_config = to_intel_crtc_state(crtc->base.state);
3081
Robert Fekete3abc4e02015-10-27 16:58:32 +01003082 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003083 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003084 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003085 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3086 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3087
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003088 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003089 intel_crtc_info(m, crtc);
3090
David Weinehall36cdd012016-08-22 13:59:31 +03003091 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003092 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 +03003093 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003094 x, y, crtc->base.cursor->state->crtc_w,
3095 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003096 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003097 intel_scaler_info(m, crtc);
3098 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003099 }
Daniel Vettercace8412014-05-22 17:56:31 +02003100
3101 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3102 yesno(!crtc->cpu_fifo_underrun_disabled),
3103 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003104 }
3105
3106 seq_printf(m, "\n");
3107 seq_printf(m, "Connector info\n");
3108 seq_printf(m, "--------------\n");
3109 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3110 intel_connector_info(m, connector);
3111 }
3112 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003113 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003114
3115 return 0;
3116}
3117
Ben Widawskye04934c2014-06-30 09:53:42 -07003118static int i915_semaphore_status(struct seq_file *m, void *unused)
3119{
David Weinehall36cdd012016-08-22 13:59:31 +03003120 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3121 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003122 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003123 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003124 enum intel_engine_id id;
3125 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003126
Chris Wilson39df9192016-07-20 13:31:57 +01003127 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003128 seq_puts(m, "Semaphores are disabled\n");
3129 return 0;
3130 }
3131
3132 ret = mutex_lock_interruptible(&dev->struct_mutex);
3133 if (ret)
3134 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003135 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003136
David Weinehall36cdd012016-08-22 13:59:31 +03003137 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003138 struct page *page;
3139 uint64_t *seqno;
3140
Chris Wilson51d545d2016-08-15 10:49:02 +01003141 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003142
3143 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003144 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003145 uint64_t offset;
3146
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003147 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003148
3149 seq_puts(m, " Last signal:");
3150 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003151 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003152 seq_printf(m, "0x%08llx (0x%02llx) ",
3153 seqno[offset], offset * 8);
3154 }
3155 seq_putc(m, '\n');
3156
3157 seq_puts(m, " Last wait: ");
3158 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003159 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003160 seq_printf(m, "0x%08llx (0x%02llx) ",
3161 seqno[offset], offset * 8);
3162 }
3163 seq_putc(m, '\n');
3164
3165 }
3166 kunmap_atomic(seqno);
3167 } else {
3168 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003169 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003170 for (j = 0; j < num_rings; j++)
3171 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003172 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003173 seq_putc(m, '\n');
3174 }
3175
3176 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003177 for_each_engine(engine, dev_priv) {
3178 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003179 seq_printf(m, " 0x%08x ",
3180 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003181 seq_putc(m, '\n');
3182 }
3183 seq_putc(m, '\n');
3184
Paulo Zanoni03872062014-07-09 14:31:57 -03003185 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003186 mutex_unlock(&dev->struct_mutex);
3187 return 0;
3188}
3189
Daniel Vetter728e29d2014-06-25 22:01:53 +03003190static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3191{
David Weinehall36cdd012016-08-22 13:59:31 +03003192 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3193 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003194 int i;
3195
3196 drm_modeset_lock_all(dev);
3197 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3198 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3199
3200 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003201 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3202 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003203 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003204 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3205 seq_printf(m, " dpll_md: 0x%08x\n",
3206 pll->config.hw_state.dpll_md);
3207 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3208 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3209 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003210 }
3211 drm_modeset_unlock_all(dev);
3212
3213 return 0;
3214}
3215
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003216static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003217{
3218 int i;
3219 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003220 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003221 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3222 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003223 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003224 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003225
Arun Siluvery888b5992014-08-26 14:44:51 +01003226 ret = mutex_lock_interruptible(&dev->struct_mutex);
3227 if (ret)
3228 return ret;
3229
3230 intel_runtime_pm_get(dev_priv);
3231
Arun Siluvery33136b02016-01-21 21:43:47 +00003232 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003233 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003234 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003235 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003236 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003237 i915_reg_t addr;
3238 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003239 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003240
Arun Siluvery33136b02016-01-21 21:43:47 +00003241 addr = workarounds->reg[i].addr;
3242 mask = workarounds->reg[i].mask;
3243 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003244 read = I915_READ(addr);
3245 ok = (value & mask) == (read & mask);
3246 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 +02003247 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003248 }
3249
3250 intel_runtime_pm_put(dev_priv);
3251 mutex_unlock(&dev->struct_mutex);
3252
3253 return 0;
3254}
3255
Damien Lespiauc5511e42014-11-04 17:06:51 +00003256static int i915_ddb_info(struct seq_file *m, void *unused)
3257{
David Weinehall36cdd012016-08-22 13:59:31 +03003258 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3259 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003260 struct skl_ddb_allocation *ddb;
3261 struct skl_ddb_entry *entry;
3262 enum pipe pipe;
3263 int plane;
3264
David Weinehall36cdd012016-08-22 13:59:31 +03003265 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003266 return 0;
3267
Damien Lespiauc5511e42014-11-04 17:06:51 +00003268 drm_modeset_lock_all(dev);
3269
3270 ddb = &dev_priv->wm.skl_hw.ddb;
3271
3272 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3273
3274 for_each_pipe(dev_priv, pipe) {
3275 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3276
Damien Lespiaudd740782015-02-28 14:54:08 +00003277 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003278 entry = &ddb->plane[pipe][plane];
3279 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3280 entry->start, entry->end,
3281 skl_ddb_entry_size(entry));
3282 }
3283
Matt Roper4969d332015-09-24 15:53:10 -07003284 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003285 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3286 entry->end, skl_ddb_entry_size(entry));
3287 }
3288
3289 drm_modeset_unlock_all(dev);
3290
3291 return 0;
3292}
3293
Vandana Kannana54746e2015-03-03 20:53:10 +05303294static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003295 struct drm_device *dev,
3296 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303297{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003298 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303299 struct i915_drrs *drrs = &dev_priv->drrs;
3300 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003301 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303302
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003303 drm_for_each_connector(connector, dev) {
3304 if (connector->state->crtc != &intel_crtc->base)
3305 continue;
3306
3307 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303308 }
3309
3310 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3311 seq_puts(m, "\tVBT: DRRS_type: Static");
3312 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3313 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3314 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3315 seq_puts(m, "\tVBT: DRRS_type: None");
3316 else
3317 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3318
3319 seq_puts(m, "\n\n");
3320
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003321 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303322 struct intel_panel *panel;
3323
3324 mutex_lock(&drrs->mutex);
3325 /* DRRS Supported */
3326 seq_puts(m, "\tDRRS Supported: Yes\n");
3327
3328 /* disable_drrs() will make drrs->dp NULL */
3329 if (!drrs->dp) {
3330 seq_puts(m, "Idleness DRRS: Disabled");
3331 mutex_unlock(&drrs->mutex);
3332 return;
3333 }
3334
3335 panel = &drrs->dp->attached_connector->panel;
3336 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3337 drrs->busy_frontbuffer_bits);
3338
3339 seq_puts(m, "\n\t\t");
3340 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3341 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3342 vrefresh = panel->fixed_mode->vrefresh;
3343 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3344 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3345 vrefresh = panel->downclock_mode->vrefresh;
3346 } else {
3347 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3348 drrs->refresh_rate_type);
3349 mutex_unlock(&drrs->mutex);
3350 return;
3351 }
3352 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3353
3354 seq_puts(m, "\n\t\t");
3355 mutex_unlock(&drrs->mutex);
3356 } else {
3357 /* DRRS not supported. Print the VBT parameter*/
3358 seq_puts(m, "\tDRRS Supported : No");
3359 }
3360 seq_puts(m, "\n");
3361}
3362
3363static int i915_drrs_status(struct seq_file *m, void *unused)
3364{
David Weinehall36cdd012016-08-22 13:59:31 +03003365 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3366 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303367 struct intel_crtc *intel_crtc;
3368 int active_crtc_cnt = 0;
3369
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003370 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303371 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003372 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303373 active_crtc_cnt++;
3374 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3375
3376 drrs_status_per_crtc(m, dev, intel_crtc);
3377 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303378 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003379 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303380
3381 if (!active_crtc_cnt)
3382 seq_puts(m, "No active crtc found\n");
3383
3384 return 0;
3385}
3386
Damien Lespiau07144422013-10-15 18:55:40 +01003387struct pipe_crc_info {
3388 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003389 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003390 enum pipe pipe;
3391};
3392
Dave Airlie11bed952014-05-12 15:22:27 +10003393static int i915_dp_mst_info(struct seq_file *m, void *unused)
3394{
David Weinehall36cdd012016-08-22 13:59:31 +03003395 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3396 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003397 struct intel_encoder *intel_encoder;
3398 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003399 struct drm_connector *connector;
3400
Dave Airlie11bed952014-05-12 15:22:27 +10003401 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003402 drm_for_each_connector(connector, dev) {
3403 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003404 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003405
3406 intel_encoder = intel_attached_encoder(connector);
3407 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3408 continue;
3409
3410 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003411 if (!intel_dig_port->dp.can_mst)
3412 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003413
Jim Bride40ae80c2016-04-14 10:18:37 -07003414 seq_printf(m, "MST Source Port %c\n",
3415 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003416 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3417 }
3418 drm_modeset_unlock_all(dev);
3419 return 0;
3420}
3421
Damien Lespiau07144422013-10-15 18:55:40 +01003422static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003423{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003424 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003425 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003426 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3427
David Weinehall36cdd012016-08-22 13:59:31 +03003428 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003429 return -ENODEV;
3430
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003431 spin_lock_irq(&pipe_crc->lock);
3432
3433 if (pipe_crc->opened) {
3434 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003435 return -EBUSY; /* already open */
3436 }
3437
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003438 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003439 filep->private_data = inode->i_private;
3440
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003441 spin_unlock_irq(&pipe_crc->lock);
3442
Damien Lespiau07144422013-10-15 18:55:40 +01003443 return 0;
3444}
3445
3446static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3447{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003448 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003449 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003450 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3451
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003452 spin_lock_irq(&pipe_crc->lock);
3453 pipe_crc->opened = false;
3454 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003455
Damien Lespiau07144422013-10-15 18:55:40 +01003456 return 0;
3457}
3458
3459/* (6 fields, 8 chars each, space separated (5) + '\n') */
3460#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3461/* account for \'0' */
3462#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3463
3464static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3465{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003466 assert_spin_locked(&pipe_crc->lock);
3467 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3468 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003469}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003470
Damien Lespiau07144422013-10-15 18:55:40 +01003471static ssize_t
3472i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3473 loff_t *pos)
3474{
3475 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003476 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003477 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3478 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003479 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003480 ssize_t bytes_read;
3481
3482 /*
3483 * Don't allow user space to provide buffers not big enough to hold
3484 * a line of data.
3485 */
3486 if (count < PIPE_CRC_LINE_LEN)
3487 return -EINVAL;
3488
3489 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3490 return 0;
3491
3492 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003493 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003494 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003495 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003496
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003497 if (filep->f_flags & O_NONBLOCK) {
3498 spin_unlock_irq(&pipe_crc->lock);
3499 return -EAGAIN;
3500 }
3501
3502 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3503 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3504 if (ret) {
3505 spin_unlock_irq(&pipe_crc->lock);
3506 return ret;
3507 }
Damien Lespiau07144422013-10-15 18:55:40 +01003508 }
3509
3510 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003511 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003512
Damien Lespiau07144422013-10-15 18:55:40 +01003513 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003514 while (n_entries > 0) {
3515 struct intel_pipe_crc_entry *entry =
3516 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003517
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003518 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3519 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3520 break;
3521
3522 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3523 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3524
Damien Lespiau07144422013-10-15 18:55:40 +01003525 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3526 "%8u %8x %8x %8x %8x %8x\n",
3527 entry->frame, entry->crc[0],
3528 entry->crc[1], entry->crc[2],
3529 entry->crc[3], entry->crc[4]);
3530
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003531 spin_unlock_irq(&pipe_crc->lock);
3532
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003533 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003534 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003535
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003536 user_buf += PIPE_CRC_LINE_LEN;
3537 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003538
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003539 spin_lock_irq(&pipe_crc->lock);
3540 }
3541
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003542 spin_unlock_irq(&pipe_crc->lock);
3543
Damien Lespiau07144422013-10-15 18:55:40 +01003544 return bytes_read;
3545}
3546
3547static const struct file_operations i915_pipe_crc_fops = {
3548 .owner = THIS_MODULE,
3549 .open = i915_pipe_crc_open,
3550 .read = i915_pipe_crc_read,
3551 .release = i915_pipe_crc_release,
3552};
3553
3554static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3555 {
3556 .name = "i915_pipe_A_crc",
3557 .pipe = PIPE_A,
3558 },
3559 {
3560 .name = "i915_pipe_B_crc",
3561 .pipe = PIPE_B,
3562 },
3563 {
3564 .name = "i915_pipe_C_crc",
3565 .pipe = PIPE_C,
3566 },
3567};
3568
3569static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3570 enum pipe pipe)
3571{
David Weinehall36cdd012016-08-22 13:59:31 +03003572 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003573 struct dentry *ent;
3574 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3575
David Weinehall36cdd012016-08-22 13:59:31 +03003576 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003577 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3578 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003579 if (!ent)
3580 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003581
3582 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003583}
3584
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003585static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003586 "none",
3587 "plane1",
3588 "plane2",
3589 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003590 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003591 "TV",
3592 "DP-B",
3593 "DP-C",
3594 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003595 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003596};
3597
3598static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3599{
3600 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3601 return pipe_crc_sources[source];
3602}
3603
Damien Lespiaubd9db022013-10-15 18:55:36 +01003604static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003605{
David Weinehall36cdd012016-08-22 13:59:31 +03003606 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003607 int i;
3608
3609 for (i = 0; i < I915_MAX_PIPES; i++)
3610 seq_printf(m, "%c %s\n", pipe_name(i),
3611 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3612
3613 return 0;
3614}
3615
Damien Lespiaubd9db022013-10-15 18:55:36 +01003616static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003617{
David Weinehall36cdd012016-08-22 13:59:31 +03003618 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003619}
3620
Daniel Vetter46a19182013-11-01 10:50:20 +01003621static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003622 uint32_t *val)
3623{
Daniel Vetter46a19182013-11-01 10:50:20 +01003624 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3625 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3626
3627 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003628 case INTEL_PIPE_CRC_SOURCE_PIPE:
3629 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3630 break;
3631 case INTEL_PIPE_CRC_SOURCE_NONE:
3632 *val = 0;
3633 break;
3634 default:
3635 return -EINVAL;
3636 }
3637
3638 return 0;
3639}
3640
David Weinehall36cdd012016-08-22 13:59:31 +03003641static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3642 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003643 enum intel_pipe_crc_source *source)
3644{
David Weinehall36cdd012016-08-22 13:59:31 +03003645 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003646 struct intel_encoder *encoder;
3647 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003648 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003649 int ret = 0;
3650
3651 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3652
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003653 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003654 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003655 if (!encoder->base.crtc)
3656 continue;
3657
3658 crtc = to_intel_crtc(encoder->base.crtc);
3659
3660 if (crtc->pipe != pipe)
3661 continue;
3662
3663 switch (encoder->type) {
3664 case INTEL_OUTPUT_TVOUT:
3665 *source = INTEL_PIPE_CRC_SOURCE_TV;
3666 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003667 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003668 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003669 dig_port = enc_to_dig_port(&encoder->base);
3670 switch (dig_port->port) {
3671 case PORT_B:
3672 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3673 break;
3674 case PORT_C:
3675 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3676 break;
3677 case PORT_D:
3678 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3679 break;
3680 default:
3681 WARN(1, "nonexisting DP port %c\n",
3682 port_name(dig_port->port));
3683 break;
3684 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003685 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003686 default:
3687 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003688 }
3689 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003690 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003691
3692 return ret;
3693}
3694
David Weinehall36cdd012016-08-22 13:59:31 +03003695static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003696 enum pipe pipe,
3697 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003698 uint32_t *val)
3699{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003700 bool need_stable_symbols = false;
3701
Daniel Vetter46a19182013-11-01 10:50:20 +01003702 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003703 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003704 if (ret)
3705 return ret;
3706 }
3707
3708 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003709 case INTEL_PIPE_CRC_SOURCE_PIPE:
3710 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3711 break;
3712 case INTEL_PIPE_CRC_SOURCE_DP_B:
3713 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003714 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003715 break;
3716 case INTEL_PIPE_CRC_SOURCE_DP_C:
3717 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003718 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003719 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003720 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003721 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003722 return -EINVAL;
3723 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3724 need_stable_symbols = true;
3725 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003726 case INTEL_PIPE_CRC_SOURCE_NONE:
3727 *val = 0;
3728 break;
3729 default:
3730 return -EINVAL;
3731 }
3732
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003733 /*
3734 * When the pipe CRC tap point is after the transcoders we need
3735 * to tweak symbol-level features to produce a deterministic series of
3736 * symbols for a given frame. We need to reset those features only once
3737 * a frame (instead of every nth symbol):
3738 * - DC-balance: used to ensure a better clock recovery from the data
3739 * link (SDVO)
3740 * - DisplayPort scrambling: used for EMI reduction
3741 */
3742 if (need_stable_symbols) {
3743 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3744
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003745 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003746 switch (pipe) {
3747 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003748 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003749 break;
3750 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003751 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003752 break;
3753 case PIPE_C:
3754 tmp |= PIPE_C_SCRAMBLE_RESET;
3755 break;
3756 default:
3757 return -EINVAL;
3758 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003759 I915_WRITE(PORT_DFT2_G4X, tmp);
3760 }
3761
Daniel Vetter7ac01292013-10-18 16:37:06 +02003762 return 0;
3763}
3764
David Weinehall36cdd012016-08-22 13:59:31 +03003765static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003766 enum pipe pipe,
3767 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003768 uint32_t *val)
3769{
Daniel Vetter84093602013-11-01 10:50:21 +01003770 bool need_stable_symbols = false;
3771
Daniel Vetter46a19182013-11-01 10:50:20 +01003772 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003773 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003774 if (ret)
3775 return ret;
3776 }
3777
3778 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003779 case INTEL_PIPE_CRC_SOURCE_PIPE:
3780 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3781 break;
3782 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003783 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003784 return -EINVAL;
3785 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3786 break;
3787 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003788 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003789 return -EINVAL;
3790 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003791 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003792 break;
3793 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003794 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003795 return -EINVAL;
3796 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003797 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003798 break;
3799 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003800 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003801 return -EINVAL;
3802 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003803 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003804 break;
3805 case INTEL_PIPE_CRC_SOURCE_NONE:
3806 *val = 0;
3807 break;
3808 default:
3809 return -EINVAL;
3810 }
3811
Daniel Vetter84093602013-11-01 10:50:21 +01003812 /*
3813 * When the pipe CRC tap point is after the transcoders we need
3814 * to tweak symbol-level features to produce a deterministic series of
3815 * symbols for a given frame. We need to reset those features only once
3816 * a frame (instead of every nth symbol):
3817 * - DC-balance: used to ensure a better clock recovery from the data
3818 * link (SDVO)
3819 * - DisplayPort scrambling: used for EMI reduction
3820 */
3821 if (need_stable_symbols) {
3822 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3823
David Weinehall36cdd012016-08-22 13:59:31 +03003824 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003825
3826 I915_WRITE(PORT_DFT_I9XX,
3827 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3828
3829 if (pipe == PIPE_A)
3830 tmp |= PIPE_A_SCRAMBLE_RESET;
3831 else
3832 tmp |= PIPE_B_SCRAMBLE_RESET;
3833
3834 I915_WRITE(PORT_DFT2_G4X, tmp);
3835 }
3836
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003837 return 0;
3838}
3839
David Weinehall36cdd012016-08-22 13:59:31 +03003840static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003841 enum pipe pipe)
3842{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003843 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3844
Ville Syrjäläeb736672014-12-09 21:28:28 +02003845 switch (pipe) {
3846 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003847 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003848 break;
3849 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003850 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003851 break;
3852 case PIPE_C:
3853 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3854 break;
3855 default:
3856 return;
3857 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003858 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3859 tmp &= ~DC_BALANCE_RESET_VLV;
3860 I915_WRITE(PORT_DFT2_G4X, tmp);
3861
3862}
3863
David Weinehall36cdd012016-08-22 13:59:31 +03003864static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01003865 enum pipe pipe)
3866{
Daniel Vetter84093602013-11-01 10:50:21 +01003867 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3868
3869 if (pipe == PIPE_A)
3870 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3871 else
3872 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3873 I915_WRITE(PORT_DFT2_G4X, tmp);
3874
3875 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3876 I915_WRITE(PORT_DFT_I9XX,
3877 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3878 }
3879}
3880
Daniel Vetter46a19182013-11-01 10:50:20 +01003881static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003882 uint32_t *val)
3883{
Daniel Vetter46a19182013-11-01 10:50:20 +01003884 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3885 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3886
3887 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003888 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3889 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3890 break;
3891 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3892 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3893 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003894 case INTEL_PIPE_CRC_SOURCE_PIPE:
3895 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3896 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003897 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003898 *val = 0;
3899 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003900 default:
3901 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003902 }
3903
3904 return 0;
3905}
3906
David Weinehall36cdd012016-08-22 13:59:31 +03003907static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
3908 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003909{
David Weinehall36cdd012016-08-22 13:59:31 +03003910 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003911 struct intel_crtc *crtc =
3912 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003913 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003914 struct drm_atomic_state *state;
3915 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003916
3917 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003918 state = drm_atomic_state_alloc(dev);
3919 if (!state) {
3920 ret = -ENOMEM;
3921 goto out;
3922 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003923
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003924 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3925 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3926 if (IS_ERR(pipe_config)) {
3927 ret = PTR_ERR(pipe_config);
3928 goto out;
3929 }
3930
3931 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003932 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003933 pipe_config->pch_pfit.enabled != enable)
3934 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003935
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003936 ret = drm_atomic_commit(state);
3937out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003938 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003939 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3940 if (ret)
3941 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003942}
3943
David Weinehall36cdd012016-08-22 13:59:31 +03003944static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003945 enum pipe pipe,
3946 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003947 uint32_t *val)
3948{
Daniel Vetter46a19182013-11-01 10:50:20 +01003949 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3950 *source = INTEL_PIPE_CRC_SOURCE_PF;
3951
3952 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003953 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3954 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3955 break;
3956 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3957 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3958 break;
3959 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03003960 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
3961 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003962
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003963 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3964 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003965 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003966 *val = 0;
3967 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003968 default:
3969 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003970 }
3971
3972 return 0;
3973}
3974
David Weinehall36cdd012016-08-22 13:59:31 +03003975static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
3976 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02003977 enum intel_pipe_crc_source source)
3978{
David Weinehall36cdd012016-08-22 13:59:31 +03003979 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003980 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03003981 struct intel_crtc *crtc =
3982 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02003983 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01003984 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003985 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003986
Damien Lespiaucc3da172013-10-15 18:55:31 +01003987 if (pipe_crc->source == source)
3988 return 0;
3989
Damien Lespiauae676fc2013-10-15 18:55:32 +01003990 /* forbid changing the source without going back to 'none' */
3991 if (pipe_crc->source && source)
3992 return -EINVAL;
3993
Imre Deake1296492016-02-12 18:55:17 +02003994 power_domain = POWER_DOMAIN_PIPE(pipe);
3995 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003996 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3997 return -EIO;
3998 }
3999
David Weinehall36cdd012016-08-22 13:59:31 +03004000 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004001 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03004002 else if (INTEL_GEN(dev_priv) < 5)
4003 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4004 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4005 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
4006 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01004007 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004008 else
David Weinehall36cdd012016-08-22 13:59:31 +03004009 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004010
4011 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004012 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004013
Damien Lespiau4b584362013-10-15 18:55:33 +01004014 /* none -> real source transition */
4015 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004016 struct intel_pipe_crc_entry *entries;
4017
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004018 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4019 pipe_name(pipe), pipe_crc_source_name(source));
4020
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004021 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4022 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004023 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004024 if (!entries) {
4025 ret = -ENOMEM;
4026 goto out;
4027 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004028
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004029 /*
4030 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4031 * enabled and disabled dynamically based on package C states,
4032 * user space can't make reliable use of the CRCs, so let's just
4033 * completely disable it.
4034 */
4035 hsw_disable_ips(crtc);
4036
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004037 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004038 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004039 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004040 pipe_crc->head = 0;
4041 pipe_crc->tail = 0;
4042 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004043 }
4044
Damien Lespiaucc3da172013-10-15 18:55:31 +01004045 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004046
Daniel Vetter926321d2013-10-16 13:30:34 +02004047 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4048 POSTING_READ(PIPE_CRC_CTL(pipe));
4049
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004050 /* real source -> none transition */
4051 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004052 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004053 struct intel_crtc *crtc =
4054 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004055
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004056 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4057 pipe_name(pipe));
4058
Daniel Vettera33d7102014-06-06 08:22:08 +02004059 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004060 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004061 intel_wait_for_vblank(dev, pipe);
4062 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004063
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004064 spin_lock_irq(&pipe_crc->lock);
4065 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004066 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004067 pipe_crc->head = 0;
4068 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004069 spin_unlock_irq(&pipe_crc->lock);
4070
4071 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004072
David Weinehall36cdd012016-08-22 13:59:31 +03004073 if (IS_G4X(dev_priv))
4074 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4075 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4076 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4077 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4078 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004079
4080 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004081 }
4082
Imre Deake1296492016-02-12 18:55:17 +02004083 ret = 0;
4084
4085out:
4086 intel_display_power_put(dev_priv, power_domain);
4087
4088 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004089}
4090
4091/*
4092 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004093 * command: wsp* object wsp+ name wsp+ source wsp*
4094 * object: 'pipe'
4095 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004096 * source: (none | plane1 | plane2 | pf)
4097 * wsp: (#0x20 | #0x9 | #0xA)+
4098 *
4099 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004100 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4101 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004102 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004103static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004104{
4105 int n_words = 0;
4106
4107 while (*buf) {
4108 char *end;
4109
4110 /* skip leading white space */
4111 buf = skip_spaces(buf);
4112 if (!*buf)
4113 break; /* end of buffer */
4114
4115 /* find end of word */
4116 for (end = buf; *end && !isspace(*end); end++)
4117 ;
4118
4119 if (n_words == max_words) {
4120 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4121 max_words);
4122 return -EINVAL; /* ran out of words[] before bytes */
4123 }
4124
4125 if (*end)
4126 *end++ = '\0';
4127 words[n_words++] = buf;
4128 buf = end;
4129 }
4130
4131 return n_words;
4132}
4133
Damien Lespiaub94dec82013-10-15 18:55:35 +01004134enum intel_pipe_crc_object {
4135 PIPE_CRC_OBJECT_PIPE,
4136};
4137
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004138static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004139 "pipe",
4140};
4141
4142static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004143display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004144{
4145 int i;
4146
4147 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4148 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004149 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004150 return 0;
4151 }
4152
4153 return -EINVAL;
4154}
4155
Damien Lespiaubd9db022013-10-15 18:55:36 +01004156static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004157{
4158 const char name = buf[0];
4159
4160 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4161 return -EINVAL;
4162
4163 *pipe = name - 'A';
4164
4165 return 0;
4166}
4167
4168static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004169display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004170{
4171 int i;
4172
4173 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4174 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004175 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004176 return 0;
4177 }
4178
4179 return -EINVAL;
4180}
4181
David Weinehall36cdd012016-08-22 13:59:31 +03004182static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4183 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004184{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004185#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004186 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004187 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004188 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004189 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004190 enum intel_pipe_crc_source source;
4191
Damien Lespiaubd9db022013-10-15 18:55:36 +01004192 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004193 if (n_words != N_WORDS) {
4194 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4195 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004196 return -EINVAL;
4197 }
4198
Damien Lespiaubd9db022013-10-15 18:55:36 +01004199 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004200 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004201 return -EINVAL;
4202 }
4203
Damien Lespiaubd9db022013-10-15 18:55:36 +01004204 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004205 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4206 return -EINVAL;
4207 }
4208
Damien Lespiaubd9db022013-10-15 18:55:36 +01004209 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004210 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004211 return -EINVAL;
4212 }
4213
David Weinehall36cdd012016-08-22 13:59:31 +03004214 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004215}
4216
Damien Lespiaubd9db022013-10-15 18:55:36 +01004217static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4218 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004219{
4220 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004221 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004222 char *tmpbuf;
4223 int ret;
4224
4225 if (len == 0)
4226 return 0;
4227
4228 if (len > PAGE_SIZE - 1) {
4229 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4230 PAGE_SIZE);
4231 return -E2BIG;
4232 }
4233
4234 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4235 if (!tmpbuf)
4236 return -ENOMEM;
4237
4238 if (copy_from_user(tmpbuf, ubuf, len)) {
4239 ret = -EFAULT;
4240 goto out;
4241 }
4242 tmpbuf[len] = '\0';
4243
David Weinehall36cdd012016-08-22 13:59:31 +03004244 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004245
4246out:
4247 kfree(tmpbuf);
4248 if (ret < 0)
4249 return ret;
4250
4251 *offp += len;
4252 return len;
4253}
4254
Damien Lespiaubd9db022013-10-15 18:55:36 +01004255static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004256 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004257 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004258 .read = seq_read,
4259 .llseek = seq_lseek,
4260 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004261 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004262};
4263
Todd Previteeb3394fa2015-04-18 00:04:19 -07004264static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004265 const char __user *ubuf,
4266 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004267{
4268 char *input_buffer;
4269 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004270 struct drm_device *dev;
4271 struct drm_connector *connector;
4272 struct list_head *connector_list;
4273 struct intel_dp *intel_dp;
4274 int val = 0;
4275
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304276 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004277
Todd Previteeb3394fa2015-04-18 00:04:19 -07004278 connector_list = &dev->mode_config.connector_list;
4279
4280 if (len == 0)
4281 return 0;
4282
4283 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4284 if (!input_buffer)
4285 return -ENOMEM;
4286
4287 if (copy_from_user(input_buffer, ubuf, len)) {
4288 status = -EFAULT;
4289 goto out;
4290 }
4291
4292 input_buffer[len] = '\0';
4293 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4294
4295 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004296 if (connector->connector_type !=
4297 DRM_MODE_CONNECTOR_DisplayPort)
4298 continue;
4299
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304300 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004301 connector->encoder != NULL) {
4302 intel_dp = enc_to_intel_dp(connector->encoder);
4303 status = kstrtoint(input_buffer, 10, &val);
4304 if (status < 0)
4305 goto out;
4306 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4307 /* To prevent erroneous activation of the compliance
4308 * testing code, only accept an actual value of 1 here
4309 */
4310 if (val == 1)
4311 intel_dp->compliance_test_active = 1;
4312 else
4313 intel_dp->compliance_test_active = 0;
4314 }
4315 }
4316out:
4317 kfree(input_buffer);
4318 if (status < 0)
4319 return status;
4320
4321 *offp += len;
4322 return len;
4323}
4324
4325static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4326{
4327 struct drm_device *dev = m->private;
4328 struct drm_connector *connector;
4329 struct list_head *connector_list = &dev->mode_config.connector_list;
4330 struct intel_dp *intel_dp;
4331
Todd Previteeb3394fa2015-04-18 00:04:19 -07004332 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004333 if (connector->connector_type !=
4334 DRM_MODE_CONNECTOR_DisplayPort)
4335 continue;
4336
4337 if (connector->status == connector_status_connected &&
4338 connector->encoder != NULL) {
4339 intel_dp = enc_to_intel_dp(connector->encoder);
4340 if (intel_dp->compliance_test_active)
4341 seq_puts(m, "1");
4342 else
4343 seq_puts(m, "0");
4344 } else
4345 seq_puts(m, "0");
4346 }
4347
4348 return 0;
4349}
4350
4351static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004352 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004353{
David Weinehall36cdd012016-08-22 13:59:31 +03004354 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004355
David Weinehall36cdd012016-08-22 13:59:31 +03004356 return single_open(file, i915_displayport_test_active_show,
4357 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004358}
4359
4360static const struct file_operations i915_displayport_test_active_fops = {
4361 .owner = THIS_MODULE,
4362 .open = i915_displayport_test_active_open,
4363 .read = seq_read,
4364 .llseek = seq_lseek,
4365 .release = single_release,
4366 .write = i915_displayport_test_active_write
4367};
4368
4369static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4370{
4371 struct drm_device *dev = m->private;
4372 struct drm_connector *connector;
4373 struct list_head *connector_list = &dev->mode_config.connector_list;
4374 struct intel_dp *intel_dp;
4375
Todd Previteeb3394fa2015-04-18 00:04:19 -07004376 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004377 if (connector->connector_type !=
4378 DRM_MODE_CONNECTOR_DisplayPort)
4379 continue;
4380
4381 if (connector->status == connector_status_connected &&
4382 connector->encoder != NULL) {
4383 intel_dp = enc_to_intel_dp(connector->encoder);
4384 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4385 } else
4386 seq_puts(m, "0");
4387 }
4388
4389 return 0;
4390}
4391static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004392 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004393{
David Weinehall36cdd012016-08-22 13:59:31 +03004394 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004395
David Weinehall36cdd012016-08-22 13:59:31 +03004396 return single_open(file, i915_displayport_test_data_show,
4397 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004398}
4399
4400static const struct file_operations i915_displayport_test_data_fops = {
4401 .owner = THIS_MODULE,
4402 .open = i915_displayport_test_data_open,
4403 .read = seq_read,
4404 .llseek = seq_lseek,
4405 .release = single_release
4406};
4407
4408static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4409{
4410 struct drm_device *dev = m->private;
4411 struct drm_connector *connector;
4412 struct list_head *connector_list = &dev->mode_config.connector_list;
4413 struct intel_dp *intel_dp;
4414
Todd Previteeb3394fa2015-04-18 00:04:19 -07004415 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004416 if (connector->connector_type !=
4417 DRM_MODE_CONNECTOR_DisplayPort)
4418 continue;
4419
4420 if (connector->status == connector_status_connected &&
4421 connector->encoder != NULL) {
4422 intel_dp = enc_to_intel_dp(connector->encoder);
4423 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4424 } else
4425 seq_puts(m, "0");
4426 }
4427
4428 return 0;
4429}
4430
4431static int i915_displayport_test_type_open(struct inode *inode,
4432 struct file *file)
4433{
David Weinehall36cdd012016-08-22 13:59:31 +03004434 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004435
David Weinehall36cdd012016-08-22 13:59:31 +03004436 return single_open(file, i915_displayport_test_type_show,
4437 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004438}
4439
4440static const struct file_operations i915_displayport_test_type_fops = {
4441 .owner = THIS_MODULE,
4442 .open = i915_displayport_test_type_open,
4443 .read = seq_read,
4444 .llseek = seq_lseek,
4445 .release = single_release
4446};
4447
Damien Lespiau97e94b22014-11-04 17:06:50 +00004448static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004449{
David Weinehall36cdd012016-08-22 13:59:31 +03004450 struct drm_i915_private *dev_priv = m->private;
4451 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004452 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004453 int num_levels;
4454
David Weinehall36cdd012016-08-22 13:59:31 +03004455 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004456 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004457 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004458 num_levels = 1;
4459 else
4460 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004461
4462 drm_modeset_lock_all(dev);
4463
4464 for (level = 0; level < num_levels; level++) {
4465 unsigned int latency = wm[level];
4466
Damien Lespiau97e94b22014-11-04 17:06:50 +00004467 /*
4468 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004469 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004470 */
David Weinehall36cdd012016-08-22 13:59:31 +03004471 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4472 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004473 latency *= 10;
4474 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004475 latency *= 5;
4476
4477 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004478 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004479 }
4480
4481 drm_modeset_unlock_all(dev);
4482}
4483
4484static int pri_wm_latency_show(struct seq_file *m, void *data)
4485{
David Weinehall36cdd012016-08-22 13:59:31 +03004486 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004487 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004488
David Weinehall36cdd012016-08-22 13:59:31 +03004489 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004490 latencies = dev_priv->wm.skl_latency;
4491 else
David Weinehall36cdd012016-08-22 13:59:31 +03004492 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004493
4494 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004495
4496 return 0;
4497}
4498
4499static int spr_wm_latency_show(struct seq_file *m, void *data)
4500{
David Weinehall36cdd012016-08-22 13:59:31 +03004501 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004502 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004503
David Weinehall36cdd012016-08-22 13:59:31 +03004504 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004505 latencies = dev_priv->wm.skl_latency;
4506 else
David Weinehall36cdd012016-08-22 13:59:31 +03004507 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004508
4509 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004510
4511 return 0;
4512}
4513
4514static int cur_wm_latency_show(struct seq_file *m, void *data)
4515{
David Weinehall36cdd012016-08-22 13:59:31 +03004516 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004517 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004518
David Weinehall36cdd012016-08-22 13:59:31 +03004519 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004520 latencies = dev_priv->wm.skl_latency;
4521 else
David Weinehall36cdd012016-08-22 13:59:31 +03004522 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004523
4524 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004525
4526 return 0;
4527}
4528
4529static int pri_wm_latency_open(struct inode *inode, struct file *file)
4530{
David Weinehall36cdd012016-08-22 13:59:31 +03004531 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004532
David Weinehall36cdd012016-08-22 13:59:31 +03004533 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004534 return -ENODEV;
4535
David Weinehall36cdd012016-08-22 13:59:31 +03004536 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004537}
4538
4539static int spr_wm_latency_open(struct inode *inode, struct file *file)
4540{
David Weinehall36cdd012016-08-22 13:59:31 +03004541 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004542
David Weinehall36cdd012016-08-22 13:59:31 +03004543 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004544 return -ENODEV;
4545
David Weinehall36cdd012016-08-22 13:59:31 +03004546 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004547}
4548
4549static int cur_wm_latency_open(struct inode *inode, struct file *file)
4550{
David Weinehall36cdd012016-08-22 13:59:31 +03004551 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004552
David Weinehall36cdd012016-08-22 13:59:31 +03004553 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004554 return -ENODEV;
4555
David Weinehall36cdd012016-08-22 13:59:31 +03004556 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004557}
4558
4559static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004560 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004561{
4562 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004563 struct drm_i915_private *dev_priv = m->private;
4564 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004565 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004566 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004567 int level;
4568 int ret;
4569 char tmp[32];
4570
David Weinehall36cdd012016-08-22 13:59:31 +03004571 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004572 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004573 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004574 num_levels = 1;
4575 else
4576 num_levels = ilk_wm_max_level(dev) + 1;
4577
Ville Syrjälä369a1342014-01-22 14:36:08 +02004578 if (len >= sizeof(tmp))
4579 return -EINVAL;
4580
4581 if (copy_from_user(tmp, ubuf, len))
4582 return -EFAULT;
4583
4584 tmp[len] = '\0';
4585
Damien Lespiau97e94b22014-11-04 17:06:50 +00004586 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4587 &new[0], &new[1], &new[2], &new[3],
4588 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004589 if (ret != num_levels)
4590 return -EINVAL;
4591
4592 drm_modeset_lock_all(dev);
4593
4594 for (level = 0; level < num_levels; level++)
4595 wm[level] = new[level];
4596
4597 drm_modeset_unlock_all(dev);
4598
4599 return len;
4600}
4601
4602
4603static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4604 size_t len, loff_t *offp)
4605{
4606 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004607 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004608 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004609
David Weinehall36cdd012016-08-22 13:59:31 +03004610 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004611 latencies = dev_priv->wm.skl_latency;
4612 else
David Weinehall36cdd012016-08-22 13:59:31 +03004613 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004614
4615 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004616}
4617
4618static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4619 size_t len, loff_t *offp)
4620{
4621 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004622 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004623 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004624
David Weinehall36cdd012016-08-22 13:59:31 +03004625 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004626 latencies = dev_priv->wm.skl_latency;
4627 else
David Weinehall36cdd012016-08-22 13:59:31 +03004628 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004629
4630 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004631}
4632
4633static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4634 size_t len, loff_t *offp)
4635{
4636 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004637 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004638 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004639
David Weinehall36cdd012016-08-22 13:59:31 +03004640 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004641 latencies = dev_priv->wm.skl_latency;
4642 else
David Weinehall36cdd012016-08-22 13:59:31 +03004643 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004644
4645 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004646}
4647
4648static const struct file_operations i915_pri_wm_latency_fops = {
4649 .owner = THIS_MODULE,
4650 .open = pri_wm_latency_open,
4651 .read = seq_read,
4652 .llseek = seq_lseek,
4653 .release = single_release,
4654 .write = pri_wm_latency_write
4655};
4656
4657static const struct file_operations i915_spr_wm_latency_fops = {
4658 .owner = THIS_MODULE,
4659 .open = spr_wm_latency_open,
4660 .read = seq_read,
4661 .llseek = seq_lseek,
4662 .release = single_release,
4663 .write = spr_wm_latency_write
4664};
4665
4666static const struct file_operations i915_cur_wm_latency_fops = {
4667 .owner = THIS_MODULE,
4668 .open = cur_wm_latency_open,
4669 .read = seq_read,
4670 .llseek = seq_lseek,
4671 .release = single_release,
4672 .write = cur_wm_latency_write
4673};
4674
Kees Cook647416f2013-03-10 14:10:06 -07004675static int
4676i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004677{
David Weinehall36cdd012016-08-22 13:59:31 +03004678 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004679
Chris Wilsond98c52c2016-04-13 17:35:05 +01004680 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004681
Kees Cook647416f2013-03-10 14:10:06 -07004682 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004683}
4684
Kees Cook647416f2013-03-10 14:10:06 -07004685static int
4686i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004687{
David Weinehall36cdd012016-08-22 13:59:31 +03004688 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004689
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004690 /*
4691 * There is no safeguard against this debugfs entry colliding
4692 * with the hangcheck calling same i915_handle_error() in
4693 * parallel, causing an explosion. For now we assume that the
4694 * test harness is responsible enough not to inject gpu hangs
4695 * while it is writing to 'i915_wedged'
4696 */
4697
Chris Wilsond98c52c2016-04-13 17:35:05 +01004698 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004699 return -EAGAIN;
4700
Imre Deakd46c0512014-04-14 20:24:27 +03004701 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004702
Chris Wilsonc0336662016-05-06 15:40:21 +01004703 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004704 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004705
4706 intel_runtime_pm_put(dev_priv);
4707
Kees Cook647416f2013-03-10 14:10:06 -07004708 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004709}
4710
Kees Cook647416f2013-03-10 14:10:06 -07004711DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4712 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004713 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004714
Kees Cook647416f2013-03-10 14:10:06 -07004715static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004716i915_ring_missed_irq_get(void *data, u64 *val)
4717{
David Weinehall36cdd012016-08-22 13:59:31 +03004718 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004719
4720 *val = dev_priv->gpu_error.missed_irq_rings;
4721 return 0;
4722}
4723
4724static int
4725i915_ring_missed_irq_set(void *data, u64 val)
4726{
David Weinehall36cdd012016-08-22 13:59:31 +03004727 struct drm_i915_private *dev_priv = data;
4728 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004729 int ret;
4730
4731 /* Lock against concurrent debugfs callers */
4732 ret = mutex_lock_interruptible(&dev->struct_mutex);
4733 if (ret)
4734 return ret;
4735 dev_priv->gpu_error.missed_irq_rings = val;
4736 mutex_unlock(&dev->struct_mutex);
4737
4738 return 0;
4739}
4740
4741DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4742 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4743 "0x%08llx\n");
4744
4745static int
4746i915_ring_test_irq_get(void *data, u64 *val)
4747{
David Weinehall36cdd012016-08-22 13:59:31 +03004748 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004749
4750 *val = dev_priv->gpu_error.test_irq_rings;
4751
4752 return 0;
4753}
4754
4755static int
4756i915_ring_test_irq_set(void *data, u64 val)
4757{
David Weinehall36cdd012016-08-22 13:59:31 +03004758 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004759
Chris Wilson3a122c22016-06-17 14:35:05 +01004760 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004761 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004762 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004763
4764 return 0;
4765}
4766
4767DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4768 i915_ring_test_irq_get, i915_ring_test_irq_set,
4769 "0x%08llx\n");
4770
Chris Wilsondd624af2013-01-15 12:39:35 +00004771#define DROP_UNBOUND 0x1
4772#define DROP_BOUND 0x2
4773#define DROP_RETIRE 0x4
4774#define DROP_ACTIVE 0x8
4775#define DROP_ALL (DROP_UNBOUND | \
4776 DROP_BOUND | \
4777 DROP_RETIRE | \
4778 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004779static int
4780i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004781{
Kees Cook647416f2013-03-10 14:10:06 -07004782 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004783
Kees Cook647416f2013-03-10 14:10:06 -07004784 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004785}
4786
Kees Cook647416f2013-03-10 14:10:06 -07004787static int
4788i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004789{
David Weinehall36cdd012016-08-22 13:59:31 +03004790 struct drm_i915_private *dev_priv = data;
4791 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004792 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004793
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004794 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004795
4796 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4797 * on ioctls on -EAGAIN. */
4798 ret = mutex_lock_interruptible(&dev->struct_mutex);
4799 if (ret)
4800 return ret;
4801
4802 if (val & DROP_ACTIVE) {
Chris Wilsondcff85c2016-08-05 10:14:11 +01004803 ret = i915_gem_wait_for_idle(dev_priv, true);
Chris Wilsondd624af2013-01-15 12:39:35 +00004804 if (ret)
4805 goto unlock;
4806 }
4807
4808 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004809 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004810
Chris Wilson21ab4e72014-09-09 11:16:08 +01004811 if (val & DROP_BOUND)
4812 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004813
Chris Wilson21ab4e72014-09-09 11:16:08 +01004814 if (val & DROP_UNBOUND)
4815 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004816
4817unlock:
4818 mutex_unlock(&dev->struct_mutex);
4819
Kees Cook647416f2013-03-10 14:10:06 -07004820 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004821}
4822
Kees Cook647416f2013-03-10 14:10:06 -07004823DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4824 i915_drop_caches_get, i915_drop_caches_set,
4825 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004826
Kees Cook647416f2013-03-10 14:10:06 -07004827static int
4828i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004829{
David Weinehall36cdd012016-08-22 13:59:31 +03004830 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004831
David Weinehall36cdd012016-08-22 13:59:31 +03004832 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004833 return -ENODEV;
4834
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004835 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004836 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004837}
4838
Kees Cook647416f2013-03-10 14:10:06 -07004839static int
4840i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004841{
David Weinehall36cdd012016-08-22 13:59:31 +03004842 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304843 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004844 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004845
David Weinehall36cdd012016-08-22 13:59:31 +03004846 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004847 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004848
Kees Cook647416f2013-03-10 14:10:06 -07004849 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004850
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004851 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004852 if (ret)
4853 return ret;
4854
Jesse Barnes358733e2011-07-27 11:53:01 -07004855 /*
4856 * Turbo will still be enabled, but won't go above the set value.
4857 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304858 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004859
Akash Goelbc4d91f2015-02-26 16:09:47 +05304860 hw_max = dev_priv->rps.max_freq;
4861 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004862
Ben Widawskyb39fb292014-03-19 18:31:11 -07004863 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004864 mutex_unlock(&dev_priv->rps.hw_lock);
4865 return -EINVAL;
4866 }
4867
Ben Widawskyb39fb292014-03-19 18:31:11 -07004868 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004869
Chris Wilsondc979972016-05-10 14:10:04 +01004870 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004871
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004872 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004873
Kees Cook647416f2013-03-10 14:10:06 -07004874 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004875}
4876
Kees Cook647416f2013-03-10 14:10:06 -07004877DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4878 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004879 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004880
Kees Cook647416f2013-03-10 14:10:06 -07004881static int
4882i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004883{
David Weinehall36cdd012016-08-22 13:59:31 +03004884 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004885
Chris Wilson62e1baa2016-07-13 09:10:36 +01004886 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004887 return -ENODEV;
4888
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004889 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004890 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004891}
4892
Kees Cook647416f2013-03-10 14:10:06 -07004893static int
4894i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004895{
David Weinehall36cdd012016-08-22 13:59:31 +03004896 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304897 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004898 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004899
Chris Wilson62e1baa2016-07-13 09:10:36 +01004900 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004901 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004902
Kees Cook647416f2013-03-10 14:10:06 -07004903 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004904
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004905 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004906 if (ret)
4907 return ret;
4908
Jesse Barnes1523c312012-05-25 12:34:54 -07004909 /*
4910 * Turbo will still be enabled, but won't go below the set value.
4911 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304912 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004913
Akash Goelbc4d91f2015-02-26 16:09:47 +05304914 hw_max = dev_priv->rps.max_freq;
4915 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004916
David Weinehall36cdd012016-08-22 13:59:31 +03004917 if (val < hw_min ||
4918 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004919 mutex_unlock(&dev_priv->rps.hw_lock);
4920 return -EINVAL;
4921 }
4922
Ben Widawskyb39fb292014-03-19 18:31:11 -07004923 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004924
Chris Wilsondc979972016-05-10 14:10:04 +01004925 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004926
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004927 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004928
Kees Cook647416f2013-03-10 14:10:06 -07004929 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004930}
4931
Kees Cook647416f2013-03-10 14:10:06 -07004932DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4933 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004934 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004935
Kees Cook647416f2013-03-10 14:10:06 -07004936static int
4937i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004938{
David Weinehall36cdd012016-08-22 13:59:31 +03004939 struct drm_i915_private *dev_priv = data;
4940 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004941 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004942 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004943
David Weinehall36cdd012016-08-22 13:59:31 +03004944 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004945 return -ENODEV;
4946
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004947 ret = mutex_lock_interruptible(&dev->struct_mutex);
4948 if (ret)
4949 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004950 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004951
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004952 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004953
4954 intel_runtime_pm_put(dev_priv);
David Weinehall36cdd012016-08-22 13:59:31 +03004955 mutex_unlock(&dev->struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004956
Kees Cook647416f2013-03-10 14:10:06 -07004957 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004958
Kees Cook647416f2013-03-10 14:10:06 -07004959 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004960}
4961
Kees Cook647416f2013-03-10 14:10:06 -07004962static int
4963i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004964{
David Weinehall36cdd012016-08-22 13:59:31 +03004965 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004966 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004967
David Weinehall36cdd012016-08-22 13:59:31 +03004968 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004969 return -ENODEV;
4970
Kees Cook647416f2013-03-10 14:10:06 -07004971 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004972 return -EINVAL;
4973
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004974 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004975 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004976
4977 /* Update the cache sharing policy here as well */
4978 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4979 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4980 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4981 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4982
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004983 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004984 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004985}
4986
Kees Cook647416f2013-03-10 14:10:06 -07004987DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4988 i915_cache_sharing_get, i915_cache_sharing_set,
4989 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004990
David Weinehall36cdd012016-08-22 13:59:31 +03004991static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004992 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004993{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004994 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004995 int ss;
4996 u32 sig1[ss_max], sig2[ss_max];
4997
4998 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4999 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5000 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5001 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5002
5003 for (ss = 0; ss < ss_max; ss++) {
5004 unsigned int eu_cnt;
5005
5006 if (sig1[ss] & CHV_SS_PG_ENABLE)
5007 /* skip disabled subslice */
5008 continue;
5009
Imre Deakf08a0c92016-08-31 19:13:04 +03005010 sseu->slice_mask = BIT(0);
Imre Deak915490d2016-08-31 19:13:01 +03005011 sseu->subslice_per_slice++;
Jeff McGee5d395252015-04-03 18:13:17 -07005012 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5013 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5014 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5015 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005016 sseu->eu_total += eu_cnt;
5017 sseu->eu_per_subslice = max_t(unsigned int,
5018 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005019 }
Imre Deak915490d2016-08-31 19:13:01 +03005020 sseu->subslice_total = sseu->subslice_per_slice;
Jeff McGee5d395252015-04-03 18:13:17 -07005021}
5022
David Weinehall36cdd012016-08-22 13:59:31 +03005023static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005024 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005025{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005026 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005027 int s, ss;
5028 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5029
Jeff McGee1c046bc2015-04-03 18:13:18 -07005030 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005031 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005032 s_max = 1;
5033 ss_max = 3;
5034 }
5035
5036 for (s = 0; s < s_max; s++) {
5037 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5038 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5039 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5040 }
5041
Jeff McGee5d395252015-04-03 18:13:17 -07005042 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5043 GEN9_PGCTL_SSA_EU19_ACK |
5044 GEN9_PGCTL_SSA_EU210_ACK |
5045 GEN9_PGCTL_SSA_EU311_ACK;
5046 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5047 GEN9_PGCTL_SSB_EU19_ACK |
5048 GEN9_PGCTL_SSB_EU210_ACK |
5049 GEN9_PGCTL_SSB_EU311_ACK;
5050
5051 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005052 unsigned int ss_cnt = 0;
5053
Jeff McGee5d395252015-04-03 18:13:17 -07005054 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5055 /* skip disabled slice */
5056 continue;
5057
Imre Deakf08a0c92016-08-31 19:13:04 +03005058 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005059
David Weinehall36cdd012016-08-22 13:59:31 +03005060 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak43b67992016-08-31 19:13:02 +03005061 ss_cnt = INTEL_INFO(dev_priv)->sseu.subslice_per_slice;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005062
Jeff McGee5d395252015-04-03 18:13:17 -07005063 for (ss = 0; ss < ss_max; ss++) {
5064 unsigned int eu_cnt;
5065
David Weinehall36cdd012016-08-22 13:59:31 +03005066 if (IS_BROXTON(dev_priv) &&
Jeff McGee1c046bc2015-04-03 18:13:18 -07005067 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5068 /* skip disabled subslice */
5069 continue;
5070
David Weinehall36cdd012016-08-22 13:59:31 +03005071 if (IS_BROXTON(dev_priv))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005072 ss_cnt++;
5073
Jeff McGee5d395252015-04-03 18:13:17 -07005074 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5075 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005076 sseu->eu_total += eu_cnt;
5077 sseu->eu_per_subslice = max_t(unsigned int,
5078 sseu->eu_per_subslice,
5079 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005080 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005081
Imre Deak915490d2016-08-31 19:13:01 +03005082 sseu->subslice_total += ss_cnt;
5083 sseu->subslice_per_slice = max_t(unsigned int,
5084 sseu->subslice_per_slice,
5085 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005086 }
5087}
5088
David Weinehall36cdd012016-08-22 13:59:31 +03005089static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005090 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005091{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005092 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005093 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005094
Imre Deakf08a0c92016-08-31 19:13:04 +03005095 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005096
Imre Deakf08a0c92016-08-31 19:13:04 +03005097 if (sseu->slice_mask) {
Imre Deak43b67992016-08-31 19:13:02 +03005098 sseu->subslice_per_slice =
5099 INTEL_INFO(dev_priv)->sseu.subslice_per_slice;
Imre Deakf08a0c92016-08-31 19:13:04 +03005100 sseu->subslice_total = hweight8(sseu->slice_mask) *
Imre Deak915490d2016-08-31 19:13:01 +03005101 sseu->subslice_per_slice;
Imre Deak43b67992016-08-31 19:13:02 +03005102 sseu->eu_per_subslice =
5103 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak915490d2016-08-31 19:13:01 +03005104 sseu->eu_total = sseu->eu_per_subslice * sseu->subslice_total;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005105
5106 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deakf08a0c92016-08-31 19:13:04 +03005107 for (s = 0; s < hweight8(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005108 u8 subslice_7eu =
5109 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005110
Imre Deak915490d2016-08-31 19:13:01 +03005111 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005112 }
5113 }
5114}
5115
Imre Deak615d8902016-08-31 19:13:03 +03005116static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5117 const struct sseu_dev_info *sseu)
5118{
5119 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5120 const char *type = is_available_info ? "Available" : "Enabled";
5121
5122 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005123 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005124 seq_printf(m, " %s Subslice Total: %u\n", type,
5125 sseu->subslice_total);
5126 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
5127 sseu->subslice_per_slice);
5128 seq_printf(m, " %s EU Total: %u\n", type,
5129 sseu->eu_total);
5130 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5131 sseu->eu_per_subslice);
5132
5133 if (!is_available_info)
5134 return;
5135
5136 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5137 if (HAS_POOLED_EU(dev_priv))
5138 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5139
5140 seq_printf(m, " Has Slice Power Gating: %s\n",
5141 yesno(sseu->has_slice_pg));
5142 seq_printf(m, " Has Subslice Power Gating: %s\n",
5143 yesno(sseu->has_subslice_pg));
5144 seq_printf(m, " Has EU Power Gating: %s\n",
5145 yesno(sseu->has_eu_pg));
5146}
5147
Jeff McGee38732182015-02-13 10:27:54 -06005148static int i915_sseu_status(struct seq_file *m, void *unused)
5149{
David Weinehall36cdd012016-08-22 13:59:31 +03005150 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005151 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005152
David Weinehall36cdd012016-08-22 13:59:31 +03005153 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005154 return -ENODEV;
5155
5156 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005157 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005158
Jeff McGee7f992ab2015-02-13 10:27:55 -06005159 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005160 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005161
5162 intel_runtime_pm_get(dev_priv);
5163
David Weinehall36cdd012016-08-22 13:59:31 +03005164 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005165 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005166 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005167 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005168 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005169 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005170 }
David Weinehall238010e2016-08-01 17:33:27 +03005171
5172 intel_runtime_pm_put(dev_priv);
5173
Imre Deak615d8902016-08-31 19:13:03 +03005174 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005175
Jeff McGee38732182015-02-13 10:27:54 -06005176 return 0;
5177}
5178
Ben Widawsky6d794d42011-04-25 11:25:56 -07005179static int i915_forcewake_open(struct inode *inode, struct file *file)
5180{
David Weinehall36cdd012016-08-22 13:59:31 +03005181 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005182
David Weinehall36cdd012016-08-22 13:59:31 +03005183 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005184 return 0;
5185
Chris Wilson6daccb02015-01-16 11:34:35 +02005186 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005187 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005188
5189 return 0;
5190}
5191
Ben Widawskyc43b5632012-04-16 14:07:40 -07005192static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005193{
David Weinehall36cdd012016-08-22 13:59:31 +03005194 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005195
David Weinehall36cdd012016-08-22 13:59:31 +03005196 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005197 return 0;
5198
Mika Kuoppala59bad942015-01-16 11:34:40 +02005199 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005200 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005201
5202 return 0;
5203}
5204
5205static const struct file_operations i915_forcewake_fops = {
5206 .owner = THIS_MODULE,
5207 .open = i915_forcewake_open,
5208 .release = i915_forcewake_release,
5209};
5210
5211static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5212{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005213 struct dentry *ent;
5214
5215 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005216 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005217 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005218 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005219 if (!ent)
5220 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005221
Ben Widawsky8eb57292011-05-11 15:10:58 -07005222 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005223}
5224
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005225static int i915_debugfs_create(struct dentry *root,
5226 struct drm_minor *minor,
5227 const char *name,
5228 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005229{
Jesse Barnes358733e2011-07-27 11:53:01 -07005230 struct dentry *ent;
5231
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005232 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005233 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005234 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005235 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005236 if (!ent)
5237 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005238
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005239 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005240}
5241
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005242static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005243 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005244 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005245 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005246 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005247 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005248 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005249 {"i915_gem_request", i915_gem_request_info, 0},
5250 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005251 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005252 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005253 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5254 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5255 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005256 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005257 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005258 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005259 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005260 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305261 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005262 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005263 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005264 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005265 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005266 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005267 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005268 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005269 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005270 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005271 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005272 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005273 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005274 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005275 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005276 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005277 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005278 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005279 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005280 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005281 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005282 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005283 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005284 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005285 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005286 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005287 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005288 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005289 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005290 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005291 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005292 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305293 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005294 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005295};
Ben Gamari27c202a2009-07-01 22:26:52 -04005296#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005297
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005298static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005299 const char *name;
5300 const struct file_operations *fops;
5301} i915_debugfs_files[] = {
5302 {"i915_wedged", &i915_wedged_fops},
5303 {"i915_max_freq", &i915_max_freq_fops},
5304 {"i915_min_freq", &i915_min_freq_fops},
5305 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005306 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5307 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005308 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5309 {"i915_error_state", &i915_error_state_fops},
5310 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005311 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005312 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5313 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5314 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005315 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005316 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5317 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5318 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005319};
5320
David Weinehall36cdd012016-08-22 13:59:31 +03005321void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005322{
Daniel Vetterb3783602013-11-14 11:30:42 +01005323 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005324
Damien Lespiau055e3932014-08-18 13:49:10 +01005325 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005326 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005327
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005328 pipe_crc->opened = false;
5329 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005330 init_waitqueue_head(&pipe_crc->wq);
5331 }
5332}
5333
Chris Wilson1dac8912016-06-24 14:00:17 +01005334int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005335{
Chris Wilson91c8a322016-07-05 10:40:23 +01005336 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005337 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005338
Ben Widawsky6d794d42011-04-25 11:25:56 -07005339 ret = i915_forcewake_create(minor->debugfs_root, minor);
5340 if (ret)
5341 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005342
Damien Lespiau07144422013-10-15 18:55:40 +01005343 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5344 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5345 if (ret)
5346 return ret;
5347 }
5348
Daniel Vetter34b96742013-07-04 20:49:44 +02005349 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5350 ret = i915_debugfs_create(minor->debugfs_root, minor,
5351 i915_debugfs_files[i].name,
5352 i915_debugfs_files[i].fops);
5353 if (ret)
5354 return ret;
5355 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005356
Ben Gamari27c202a2009-07-01 22:26:52 -04005357 return drm_debugfs_create_files(i915_debugfs_list,
5358 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005359 minor->debugfs_root, minor);
5360}
5361
Chris Wilson1dac8912016-06-24 14:00:17 +01005362void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005363{
Chris Wilson91c8a322016-07-05 10:40:23 +01005364 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005365 int i;
5366
Ben Gamari27c202a2009-07-01 22:26:52 -04005367 drm_debugfs_remove_files(i915_debugfs_list,
5368 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005369
David Weinehall36cdd012016-08-22 13:59:31 +03005370 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005371 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005372
Daniel Vettere309a992013-10-16 22:55:51 +02005373 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005374 struct drm_info_list *info_list =
5375 (struct drm_info_list *)&i915_pipe_crc_data[i];
5376
5377 drm_debugfs_remove_files(info_list, 1, minor);
5378 }
5379
Daniel Vetter34b96742013-07-04 20:49:44 +02005380 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5381 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005382 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005383
5384 drm_debugfs_remove_files(info_list, 1, minor);
5385 }
Ben Gamari20172632009-02-17 20:08:50 -05005386}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005387
5388struct dpcd_block {
5389 /* DPCD dump start address. */
5390 unsigned int offset;
5391 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5392 unsigned int end;
5393 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5394 size_t size;
5395 /* Only valid for eDP. */
5396 bool edp;
5397};
5398
5399static const struct dpcd_block i915_dpcd_debug[] = {
5400 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5401 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5402 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5403 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5404 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5405 { .offset = DP_SET_POWER },
5406 { .offset = DP_EDP_DPCD_REV },
5407 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5408 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5409 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5410};
5411
5412static int i915_dpcd_show(struct seq_file *m, void *data)
5413{
5414 struct drm_connector *connector = m->private;
5415 struct intel_dp *intel_dp =
5416 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5417 uint8_t buf[16];
5418 ssize_t err;
5419 int i;
5420
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005421 if (connector->status != connector_status_connected)
5422 return -ENODEV;
5423
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005424 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5425 const struct dpcd_block *b = &i915_dpcd_debug[i];
5426 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5427
5428 if (b->edp &&
5429 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5430 continue;
5431
5432 /* low tech for now */
5433 if (WARN_ON(size > sizeof(buf)))
5434 continue;
5435
5436 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5437 if (err <= 0) {
5438 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5439 size, b->offset, err);
5440 continue;
5441 }
5442
5443 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005444 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005445
5446 return 0;
5447}
5448
5449static int i915_dpcd_open(struct inode *inode, struct file *file)
5450{
5451 return single_open(file, i915_dpcd_show, inode->i_private);
5452}
5453
5454static const struct file_operations i915_dpcd_fops = {
5455 .owner = THIS_MODULE,
5456 .open = i915_dpcd_open,
5457 .read = seq_read,
5458 .llseek = seq_lseek,
5459 .release = single_release,
5460};
5461
David Weinehallecbd6782016-08-23 12:23:56 +03005462static int i915_panel_show(struct seq_file *m, void *data)
5463{
5464 struct drm_connector *connector = m->private;
5465 struct intel_dp *intel_dp =
5466 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5467
5468 if (connector->status != connector_status_connected)
5469 return -ENODEV;
5470
5471 seq_printf(m, "Panel power up delay: %d\n",
5472 intel_dp->panel_power_up_delay);
5473 seq_printf(m, "Panel power down delay: %d\n",
5474 intel_dp->panel_power_down_delay);
5475 seq_printf(m, "Backlight on delay: %d\n",
5476 intel_dp->backlight_on_delay);
5477 seq_printf(m, "Backlight off delay: %d\n",
5478 intel_dp->backlight_off_delay);
5479
5480 return 0;
5481}
5482
5483static int i915_panel_open(struct inode *inode, struct file *file)
5484{
5485 return single_open(file, i915_panel_show, inode->i_private);
5486}
5487
5488static const struct file_operations i915_panel_fops = {
5489 .owner = THIS_MODULE,
5490 .open = i915_panel_open,
5491 .read = seq_read,
5492 .llseek = seq_lseek,
5493 .release = single_release,
5494};
5495
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005496/**
5497 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5498 * @connector: pointer to a registered drm_connector
5499 *
5500 * Cleanup will be done by drm_connector_unregister() through a call to
5501 * drm_debugfs_connector_remove().
5502 *
5503 * Returns 0 on success, negative error codes on error.
5504 */
5505int i915_debugfs_connector_add(struct drm_connector *connector)
5506{
5507 struct dentry *root = connector->debugfs_entry;
5508
5509 /* The connector must have been registered beforehands. */
5510 if (!root)
5511 return -ENODEV;
5512
5513 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5514 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005515 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5516 connector, &i915_dpcd_fops);
5517
5518 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5519 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5520 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005521
5522 return 0;
5523}