blob: b8e40fde132abdfd2d945de03e0bba1e21927ab2 [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 Wilson6d2b8882013-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 Carpenterba0635f2015-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000717 struct intel_engine_cs *engine;
Ben Gamari20172632009-02-17 20:08:50 -0500718
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000719 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000720 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100721
Ben Gamari20172632009-02-17 20:08:50 -0500722 return 0;
723}
724
725
726static int i915_interrupt_info(struct seq_file *m, void *data)
727{
David Weinehall36cdd012016-08-22 13:59:31 +0300728 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000729 struct intel_engine_cs *engine;
Chris Wilson4bb05042016-09-03 07:53:43 +0100730 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100731
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200732 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500733
David Weinehall36cdd012016-08-22 13:59:31 +0300734 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300735 seq_printf(m, "Master Interrupt Control:\t%08x\n",
736 I915_READ(GEN8_MASTER_IRQ));
737
738 seq_printf(m, "Display IER:\t%08x\n",
739 I915_READ(VLV_IER));
740 seq_printf(m, "Display IIR:\t%08x\n",
741 I915_READ(VLV_IIR));
742 seq_printf(m, "Display IIR_RW:\t%08x\n",
743 I915_READ(VLV_IIR_RW));
744 seq_printf(m, "Display IMR:\t%08x\n",
745 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100746 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300747 seq_printf(m, "Pipe %c stat:\t%08x\n",
748 pipe_name(pipe),
749 I915_READ(PIPESTAT(pipe)));
750
751 seq_printf(m, "Port hotplug:\t%08x\n",
752 I915_READ(PORT_HOTPLUG_EN));
753 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
754 I915_READ(VLV_DPFLIPSTAT));
755 seq_printf(m, "DPINVGTT:\t%08x\n",
756 I915_READ(DPINVGTT));
757
758 for (i = 0; i < 4; i++) {
759 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
760 i, I915_READ(GEN8_GT_IMR(i)));
761 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
762 i, I915_READ(GEN8_GT_IIR(i)));
763 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
764 i, I915_READ(GEN8_GT_IER(i)));
765 }
766
767 seq_printf(m, "PCU interrupt mask:\t%08x\n",
768 I915_READ(GEN8_PCU_IMR));
769 seq_printf(m, "PCU interrupt identity:\t%08x\n",
770 I915_READ(GEN8_PCU_IIR));
771 seq_printf(m, "PCU interrupt enable:\t%08x\n",
772 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300773 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700774 seq_printf(m, "Master Interrupt Control:\t%08x\n",
775 I915_READ(GEN8_MASTER_IRQ));
776
777 for (i = 0; i < 4; i++) {
778 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
779 i, I915_READ(GEN8_GT_IMR(i)));
780 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
781 i, I915_READ(GEN8_GT_IIR(i)));
782 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
783 i, I915_READ(GEN8_GT_IER(i)));
784 }
785
Damien Lespiau055e3932014-08-18 13:49:10 +0100786 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200787 enum intel_display_power_domain power_domain;
788
789 power_domain = POWER_DOMAIN_PIPE(pipe);
790 if (!intel_display_power_get_if_enabled(dev_priv,
791 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300792 seq_printf(m, "Pipe %c power disabled\n",
793 pipe_name(pipe));
794 continue;
795 }
Ben Widawskya123f152013-11-02 21:07:10 -0700796 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000797 pipe_name(pipe),
798 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700799 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000800 pipe_name(pipe),
801 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700802 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000803 pipe_name(pipe),
804 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200805
806 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700807 }
808
809 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
810 I915_READ(GEN8_DE_PORT_IMR));
811 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
812 I915_READ(GEN8_DE_PORT_IIR));
813 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
814 I915_READ(GEN8_DE_PORT_IER));
815
816 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
817 I915_READ(GEN8_DE_MISC_IMR));
818 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
819 I915_READ(GEN8_DE_MISC_IIR));
820 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
821 I915_READ(GEN8_DE_MISC_IER));
822
823 seq_printf(m, "PCU interrupt mask:\t%08x\n",
824 I915_READ(GEN8_PCU_IMR));
825 seq_printf(m, "PCU interrupt identity:\t%08x\n",
826 I915_READ(GEN8_PCU_IIR));
827 seq_printf(m, "PCU interrupt enable:\t%08x\n",
828 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300829 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700830 seq_printf(m, "Display IER:\t%08x\n",
831 I915_READ(VLV_IER));
832 seq_printf(m, "Display IIR:\t%08x\n",
833 I915_READ(VLV_IIR));
834 seq_printf(m, "Display IIR_RW:\t%08x\n",
835 I915_READ(VLV_IIR_RW));
836 seq_printf(m, "Display IMR:\t%08x\n",
837 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100838 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700839 seq_printf(m, "Pipe %c stat:\t%08x\n",
840 pipe_name(pipe),
841 I915_READ(PIPESTAT(pipe)));
842
843 seq_printf(m, "Master IER:\t%08x\n",
844 I915_READ(VLV_MASTER_IER));
845
846 seq_printf(m, "Render IER:\t%08x\n",
847 I915_READ(GTIER));
848 seq_printf(m, "Render IIR:\t%08x\n",
849 I915_READ(GTIIR));
850 seq_printf(m, "Render IMR:\t%08x\n",
851 I915_READ(GTIMR));
852
853 seq_printf(m, "PM IER:\t\t%08x\n",
854 I915_READ(GEN6_PMIER));
855 seq_printf(m, "PM IIR:\t\t%08x\n",
856 I915_READ(GEN6_PMIIR));
857 seq_printf(m, "PM IMR:\t\t%08x\n",
858 I915_READ(GEN6_PMIMR));
859
860 seq_printf(m, "Port hotplug:\t%08x\n",
861 I915_READ(PORT_HOTPLUG_EN));
862 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
863 I915_READ(VLV_DPFLIPSTAT));
864 seq_printf(m, "DPINVGTT:\t%08x\n",
865 I915_READ(DPINVGTT));
866
David Weinehall36cdd012016-08-22 13:59:31 +0300867 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800868 seq_printf(m, "Interrupt enable: %08x\n",
869 I915_READ(IER));
870 seq_printf(m, "Interrupt identity: %08x\n",
871 I915_READ(IIR));
872 seq_printf(m, "Interrupt mask: %08x\n",
873 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100874 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800875 seq_printf(m, "Pipe %c stat: %08x\n",
876 pipe_name(pipe),
877 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800878 } else {
879 seq_printf(m, "North Display Interrupt enable: %08x\n",
880 I915_READ(DEIER));
881 seq_printf(m, "North Display Interrupt identity: %08x\n",
882 I915_READ(DEIIR));
883 seq_printf(m, "North Display Interrupt mask: %08x\n",
884 I915_READ(DEIMR));
885 seq_printf(m, "South Display Interrupt enable: %08x\n",
886 I915_READ(SDEIER));
887 seq_printf(m, "South Display Interrupt identity: %08x\n",
888 I915_READ(SDEIIR));
889 seq_printf(m, "South Display Interrupt mask: %08x\n",
890 I915_READ(SDEIMR));
891 seq_printf(m, "Graphics Interrupt enable: %08x\n",
892 I915_READ(GTIER));
893 seq_printf(m, "Graphics Interrupt identity: %08x\n",
894 I915_READ(GTIIR));
895 seq_printf(m, "Graphics Interrupt mask: %08x\n",
896 I915_READ(GTIMR));
897 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000898 for_each_engine(engine, dev_priv) {
David Weinehall36cdd012016-08-22 13:59:31 +0300899 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100900 seq_printf(m,
901 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000902 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000903 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000904 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000905 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200906 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100907
Ben Gamari20172632009-02-17 20:08:50 -0500908 return 0;
909}
910
Chris Wilsona6172a82009-02-11 14:26:38 +0000911static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
912{
David Weinehall36cdd012016-08-22 13:59:31 +0300913 struct drm_i915_private *dev_priv = node_to_i915(m->private);
914 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100915 int i, ret;
916
917 ret = mutex_lock_interruptible(&dev->struct_mutex);
918 if (ret)
919 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000920
Chris Wilsona6172a82009-02-11 14:26:38 +0000921 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
922 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100923 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000924
Chris Wilson6c085a72012-08-20 11:40:46 +0200925 seq_printf(m, "Fence %d, pin count = %d, object = ",
926 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100927 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100928 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100929 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100930 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100931 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000932 }
933
Chris Wilson05394f32010-11-08 19:18:58 +0000934 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000935 return 0;
936}
937
Ben Gamari20172632009-02-17 20:08:50 -0500938static int i915_hws_info(struct seq_file *m, void *data)
939{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100940 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300941 struct drm_i915_private *dev_priv = node_to_i915(node);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000942 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100943 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100944 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500945
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +0000946 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000947 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500948 if (hws == NULL)
949 return 0;
950
951 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
952 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
953 i * 4,
954 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
955 }
956 return 0;
957}
958
Daniel Vetterd5442302012-04-27 15:17:40 +0200959static ssize_t
960i915_error_state_write(struct file *filp,
961 const char __user *ubuf,
962 size_t cnt,
963 loff_t *ppos)
964{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300965 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200966
967 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson662d19e2016-09-01 21:55:10 +0100968 i915_destroy_error_state(error_priv->dev);
Daniel Vetterd5442302012-04-27 15:17:40 +0200969
970 return cnt;
971}
972
973static int i915_error_state_open(struct inode *inode, struct file *file)
974{
David Weinehall36cdd012016-08-22 13:59:31 +0300975 struct drm_i915_private *dev_priv = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200976 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200977
978 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
979 if (!error_priv)
980 return -ENOMEM;
981
David Weinehall36cdd012016-08-22 13:59:31 +0300982 error_priv->dev = &dev_priv->drm;
Daniel Vetterd5442302012-04-27 15:17:40 +0200983
David Weinehall36cdd012016-08-22 13:59:31 +0300984 i915_error_state_get(&dev_priv->drm, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200985
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300986 file->private_data = error_priv;
987
988 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200989}
990
991static int i915_error_state_release(struct inode *inode, struct file *file)
992{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300993 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200994
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300995 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200996 kfree(error_priv);
997
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300998 return 0;
999}
1000
1001static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1002 size_t count, loff_t *pos)
1003{
1004 struct i915_error_state_file_priv *error_priv = file->private_data;
1005 struct drm_i915_error_state_buf error_str;
1006 loff_t tmp_pos = 0;
1007 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001008 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001009
David Weinehall36cdd012016-08-22 13:59:31 +03001010 ret = i915_error_state_buf_init(&error_str,
1011 to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001012 if (ret)
1013 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001014
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001015 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001016 if (ret)
1017 goto out;
1018
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001019 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1020 error_str.buf,
1021 error_str.bytes);
1022
1023 if (ret_count < 0)
1024 ret = ret_count;
1025 else
1026 *pos = error_str.start + ret_count;
1027out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001028 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001029 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001030}
1031
1032static const struct file_operations i915_error_state_fops = {
1033 .owner = THIS_MODULE,
1034 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001035 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001036 .write = i915_error_state_write,
1037 .llseek = default_llseek,
1038 .release = i915_error_state_release,
1039};
1040
Kees Cook647416f2013-03-10 14:10:06 -07001041static int
1042i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001043{
David Weinehall36cdd012016-08-22 13:59:31 +03001044 struct drm_i915_private *dev_priv = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001045 int ret;
1046
David Weinehall36cdd012016-08-22 13:59:31 +03001047 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001048 if (ret)
1049 return ret;
1050
Kees Cook647416f2013-03-10 14:10:06 -07001051 *val = dev_priv->next_seqno;
David Weinehall36cdd012016-08-22 13:59:31 +03001052 mutex_unlock(&dev_priv->drm.struct_mutex);
Mika Kuoppala40633212012-12-04 15:12:00 +02001053
Kees Cook647416f2013-03-10 14:10:06 -07001054 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001055}
1056
Kees Cook647416f2013-03-10 14:10:06 -07001057static int
1058i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001059{
David Weinehall36cdd012016-08-22 13:59:31 +03001060 struct drm_i915_private *dev_priv = data;
1061 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001062 int ret;
1063
Mika Kuoppala40633212012-12-04 15:12:00 +02001064 ret = mutex_lock_interruptible(&dev->struct_mutex);
1065 if (ret)
1066 return ret;
1067
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001068 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001069 mutex_unlock(&dev->struct_mutex);
1070
Kees Cook647416f2013-03-10 14:10:06 -07001071 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001072}
1073
Kees Cook647416f2013-03-10 14:10:06 -07001074DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1075 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001076 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001077
Deepak Sadb4bd12014-03-31 11:30:02 +05301078static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001079{
David Weinehall36cdd012016-08-22 13:59:31 +03001080 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1081 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001082 int ret = 0;
1083
1084 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001085
David Weinehall36cdd012016-08-22 13:59:31 +03001086 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001087 u16 rgvswctl = I915_READ16(MEMSWCTL);
1088 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1089
1090 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1091 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1092 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1093 MEMSTAT_VID_SHIFT);
1094 seq_printf(m, "Current P-state: %d\n",
1095 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001096 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Wayne Boyer666a4532015-12-09 12:29:35 -08001097 u32 freq_sts;
1098
1099 mutex_lock(&dev_priv->rps.hw_lock);
1100 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1101 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1102 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1103
1104 seq_printf(m, "actual GPU freq: %d MHz\n",
1105 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1106
1107 seq_printf(m, "current GPU freq: %d MHz\n",
1108 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1109
1110 seq_printf(m, "max GPU freq: %d MHz\n",
1111 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1112
1113 seq_printf(m, "min GPU freq: %d MHz\n",
1114 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1115
1116 seq_printf(m, "idle GPU freq: %d MHz\n",
1117 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1118
1119 seq_printf(m,
1120 "efficient (RPe) frequency: %d MHz\n",
1121 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1122 mutex_unlock(&dev_priv->rps.hw_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001123 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001124 u32 rp_state_limits;
1125 u32 gt_perf_status;
1126 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001127 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001128 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001129 u32 rpupei, rpcurup, rpprevup;
1130 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001131 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001132 int max_freq;
1133
Bob Paauwe35040562015-06-25 14:54:07 -07001134 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
David Weinehall36cdd012016-08-22 13:59:31 +03001135 if (IS_BROXTON(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001136 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1137 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1138 } else {
1139 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1140 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1141 }
1142
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001144 ret = mutex_lock_interruptible(&dev->struct_mutex);
1145 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001146 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001147
Mika Kuoppala59bad942015-01-16 11:34:40 +02001148 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001149
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001150 reqf = I915_READ(GEN6_RPNSWREQ);
David Weinehall36cdd012016-08-22 13:59:31 +03001151 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301152 reqf >>= 23;
1153 else {
1154 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001155 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301156 reqf >>= 24;
1157 else
1158 reqf >>= 25;
1159 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001160 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001161
Chris Wilson0d8f9492014-03-27 09:06:14 +00001162 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1163 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1164 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1165
Jesse Barnesccab5c82011-01-18 15:49:25 -08001166 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301167 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1168 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1169 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1170 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1171 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1172 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
David Weinehall36cdd012016-08-22 13:59:31 +03001173 if (IS_GEN9(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301174 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001175 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001176 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1177 else
1178 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001179 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001180
Mika Kuoppala59bad942015-01-16 11:34:40 +02001181 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001182 mutex_unlock(&dev->struct_mutex);
1183
David Weinehall36cdd012016-08-22 13:59:31 +03001184 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001185 pm_ier = I915_READ(GEN6_PMIER);
1186 pm_imr = I915_READ(GEN6_PMIMR);
1187 pm_isr = I915_READ(GEN6_PMISR);
1188 pm_iir = I915_READ(GEN6_PMIIR);
1189 pm_mask = I915_READ(GEN6_PMINTRMSK);
1190 } else {
1191 pm_ier = I915_READ(GEN8_GT_IER(2));
1192 pm_imr = I915_READ(GEN8_GT_IMR(2));
1193 pm_isr = I915_READ(GEN8_GT_ISR(2));
1194 pm_iir = I915_READ(GEN8_GT_IIR(2));
1195 pm_mask = I915_READ(GEN6_PMINTRMSK);
1196 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001197 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 -03001198 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301199 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001200 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001201 seq_printf(m, "Render p-state ratio: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03001202 (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001203 seq_printf(m, "Render p-state VID: %d\n",
1204 gt_perf_status & 0xff);
1205 seq_printf(m, "Render p-state limit: %d\n",
1206 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001207 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1208 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1209 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1210 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001211 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001212 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301213 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1214 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1215 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1216 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1217 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1218 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001219 seq_printf(m, "Up threshold: %d%%\n",
1220 dev_priv->rps.up_threshold);
1221
Akash Goeld6cda9c2016-04-23 00:05:46 +05301222 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1223 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1224 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1225 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1226 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1227 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001228 seq_printf(m, "Down threshold: %d%%\n",
1229 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001230
David Weinehall36cdd012016-08-22 13:59:31 +03001231 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001232 rp_state_cap >> 16) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001233 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001234 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001235 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001236 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001237
1238 max_freq = (rp_state_cap & 0xff00) >> 8;
David Weinehall36cdd012016-08-22 13:59:31 +03001239 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001240 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001241 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001242 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001243
David Weinehall36cdd012016-08-22 13:59:31 +03001244 max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001245 rp_state_cap >> 0) & 0xff;
David Weinehall36cdd012016-08-22 13:59:31 +03001246 max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001247 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001248 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001249 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001250 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001251 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001252
Chris Wilsond86ed342015-04-27 13:41:19 +01001253 seq_printf(m, "Current freq: %d MHz\n",
1254 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1255 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001256 seq_printf(m, "Idle freq: %d MHz\n",
1257 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001258 seq_printf(m, "Min freq: %d MHz\n",
1259 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001260 seq_printf(m, "Boost freq: %d MHz\n",
1261 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001262 seq_printf(m, "Max freq: %d MHz\n",
1263 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1264 seq_printf(m,
1265 "efficient (RPe) frequency: %d MHz\n",
1266 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001267 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001268 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001269 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001270
Mika Kahola1170f282015-09-25 14:00:32 +03001271 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1272 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1273 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1274
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001275out:
1276 intel_runtime_pm_put(dev_priv);
1277 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001278}
1279
Chris Wilsonf654449a2015-01-26 18:03:04 +02001280static int i915_hangcheck_info(struct seq_file *m, void *unused)
1281{
David Weinehall36cdd012016-08-22 13:59:31 +03001282 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001283 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001284 u64 acthd[I915_NUM_ENGINES];
1285 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001286 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001287 enum intel_engine_id id;
1288 int j;
Chris Wilsonf654449a2015-01-26 18:03:04 +02001289
1290 if (!i915.enable_hangcheck) {
1291 seq_printf(m, "Hangcheck disabled\n");
1292 return 0;
1293 }
1294
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001295 intel_runtime_pm_get(dev_priv);
1296
Dave Gordonc3232b12016-03-23 18:19:53 +00001297 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001298 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001299 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001300 }
1301
Chris Wilsonc0336662016-05-06 15:40:21 +01001302 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001303
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001304 intel_runtime_pm_put(dev_priv);
1305
Chris Wilsonf654449a2015-01-26 18:03:04 +02001306 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1307 seq_printf(m, "Hangcheck active, fires in %dms\n",
1308 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1309 jiffies));
1310 } else
1311 seq_printf(m, "Hangcheck inactive\n");
1312
Dave Gordonc3232b12016-03-23 18:19:53 +00001313 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001314 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001315 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1316 engine->hangcheck.seqno,
1317 seqno[id],
1318 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001319 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1320 yesno(intel_engine_has_waiter(engine)),
1321 yesno(test_bit(engine->id,
1322 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilsonf654449a2015-01-26 18:03:04 +02001323 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001324 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001325 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001326 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1327 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001328
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001329 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001330 seq_puts(m, "\tinstdone read =");
1331
1332 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1333 seq_printf(m, " 0x%08x", instdone[j]);
1334
1335 seq_puts(m, "\n\tinstdone accu =");
1336
1337 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1338 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001339 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001340
1341 seq_puts(m, "\n");
1342 }
Chris Wilsonf654449a2015-01-26 18:03:04 +02001343 }
1344
1345 return 0;
1346}
1347
Ben Widawsky4d855292011-12-12 19:34:16 -08001348static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001349{
David Weinehall36cdd012016-08-22 13:59:31 +03001350 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1351 struct drm_device *dev = &dev_priv->drm;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001352 u32 rgvmodectl, rstdbyctl;
1353 u16 crstandvid;
1354 int ret;
1355
1356 ret = mutex_lock_interruptible(&dev->struct_mutex);
1357 if (ret)
1358 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001359 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001360
1361 rgvmodectl = I915_READ(MEMMODECTL);
1362 rstdbyctl = I915_READ(RSTDBYCTL);
1363 crstandvid = I915_READ16(CRSTANDVID);
1364
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001365 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001366 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001367
Jani Nikula742f4912015-09-03 11:16:09 +03001368 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001369 seq_printf(m, "Boost freq: %d\n",
1370 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1371 MEMMODE_BOOST_FREQ_SHIFT);
1372 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001373 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001374 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001375 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001376 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001377 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001378 seq_printf(m, "Starting frequency: P%d\n",
1379 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001380 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001381 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001382 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1383 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1384 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1385 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001386 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001387 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001388 switch (rstdbyctl & RSX_STATUS_MASK) {
1389 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001390 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001391 break;
1392 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001393 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001394 break;
1395 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001396 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001397 break;
1398 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001399 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001400 break;
1401 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001402 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001403 break;
1404 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001405 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001406 break;
1407 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001408 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001409 break;
1410 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001411
1412 return 0;
1413}
1414
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001415static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001416{
David Weinehall36cdd012016-08-22 13:59:31 +03001417 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001418 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001419
1420 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001421 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001422 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001423 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001424 fw_domain->wake_count);
1425 }
1426 spin_unlock_irq(&dev_priv->uncore.lock);
1427
1428 return 0;
1429}
1430
Deepak S669ab5a2014-01-10 15:18:26 +05301431static int vlv_drpc_info(struct seq_file *m)
1432{
David Weinehall36cdd012016-08-22 13:59:31 +03001433 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001434 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301435
Imre Deakd46c0512014-04-14 20:24:27 +03001436 intel_runtime_pm_get(dev_priv);
1437
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001438 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301439 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1440 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1441
Imre Deakd46c0512014-04-14 20:24:27 +03001442 intel_runtime_pm_put(dev_priv);
1443
Deepak S669ab5a2014-01-10 15:18:26 +05301444 seq_printf(m, "Video Turbo Mode: %s\n",
1445 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1446 seq_printf(m, "Turbo enabled: %s\n",
1447 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1448 seq_printf(m, "HW control enabled: %s\n",
1449 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1450 seq_printf(m, "SW control enabled: %s\n",
1451 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1452 GEN6_RP_MEDIA_SW_MODE));
1453 seq_printf(m, "RC6 Enabled: %s\n",
1454 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1455 GEN6_RC_CTL_EI_MODE(1))));
1456 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001457 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301458 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001459 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301460
Imre Deak9cc19be2014-04-14 20:24:24 +03001461 seq_printf(m, "Render RC6 residency since boot: %u\n",
1462 I915_READ(VLV_GT_RENDER_RC6));
1463 seq_printf(m, "Media RC6 residency since boot: %u\n",
1464 I915_READ(VLV_GT_MEDIA_RC6));
1465
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001466 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301467}
1468
Ben Widawsky4d855292011-12-12 19:34:16 -08001469static int gen6_drpc_info(struct seq_file *m)
1470{
David Weinehall36cdd012016-08-22 13:59:31 +03001471 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1472 struct drm_device *dev = &dev_priv->drm;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001473 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301474 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001475 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001476 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001477
1478 ret = mutex_lock_interruptible(&dev->struct_mutex);
1479 if (ret)
1480 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001481 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001482
Chris Wilson907b28c2013-07-19 20:36:52 +01001483 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001484 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001485 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001486
1487 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001488 seq_puts(m, "RC information inaccurate because somebody "
1489 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001490 } else {
1491 /* NB: we cannot use forcewake, else we read the wrong values */
1492 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1493 udelay(10);
1494 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1495 }
1496
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001497 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001498 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001499
1500 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1501 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001502 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301503 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1504 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1505 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001506 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001507 mutex_lock(&dev_priv->rps.hw_lock);
1508 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1509 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001510
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001511 intel_runtime_pm_put(dev_priv);
1512
Ben Widawsky4d855292011-12-12 19:34:16 -08001513 seq_printf(m, "Video Turbo Mode: %s\n",
1514 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1515 seq_printf(m, "HW control enabled: %s\n",
1516 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1517 seq_printf(m, "SW control enabled: %s\n",
1518 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1519 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001520 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001521 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1522 seq_printf(m, "RC6 Enabled: %s\n",
1523 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001524 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301525 seq_printf(m, "Render Well Gating Enabled: %s\n",
1526 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1527 seq_printf(m, "Media Well Gating Enabled: %s\n",
1528 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1529 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001530 seq_printf(m, "Deep RC6 Enabled: %s\n",
1531 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1532 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1533 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001534 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001535 switch (gt_core_status & GEN6_RCn_MASK) {
1536 case GEN6_RC0:
1537 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001538 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001539 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001540 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001541 break;
1542 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001543 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001544 break;
1545 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001546 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 break;
1548 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001549 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001550 break;
1551 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001552 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001553 break;
1554 }
1555
1556 seq_printf(m, "Core Power Down: %s\n",
1557 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001558 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301559 seq_printf(m, "Render Power Well: %s\n",
1560 (gen9_powergate_status &
1561 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1562 seq_printf(m, "Media Power Well: %s\n",
1563 (gen9_powergate_status &
1564 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1565 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001566
1567 /* Not exactly sure what this is */
1568 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1569 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1570 seq_printf(m, "RC6 residency since boot: %u\n",
1571 I915_READ(GEN6_GT_GFX_RC6));
1572 seq_printf(m, "RC6+ residency since boot: %u\n",
1573 I915_READ(GEN6_GT_GFX_RC6p));
1574 seq_printf(m, "RC6++ residency since boot: %u\n",
1575 I915_READ(GEN6_GT_GFX_RC6pp));
1576
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001577 seq_printf(m, "RC6 voltage: %dmV\n",
1578 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1579 seq_printf(m, "RC6+ voltage: %dmV\n",
1580 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1581 seq_printf(m, "RC6++ voltage: %dmV\n",
1582 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301583 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001584}
1585
1586static int i915_drpc_info(struct seq_file *m, void *unused)
1587{
David Weinehall36cdd012016-08-22 13:59:31 +03001588 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky4d855292011-12-12 19:34:16 -08001589
David Weinehall36cdd012016-08-22 13:59:31 +03001590 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Deepak S669ab5a2014-01-10 15:18:26 +05301591 return vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001592 else if (INTEL_GEN(dev_priv) >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 return gen6_drpc_info(m);
1594 else
1595 return ironlake_drpc_info(m);
1596}
1597
Daniel Vetter9a851782015-06-18 10:30:22 +02001598static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1599{
David Weinehall36cdd012016-08-22 13:59:31 +03001600 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001601
1602 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1603 dev_priv->fb_tracking.busy_bits);
1604
1605 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1606 dev_priv->fb_tracking.flip_bits);
1607
1608 return 0;
1609}
1610
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001611static int i915_fbc_status(struct seq_file *m, void *unused)
1612{
David Weinehall36cdd012016-08-22 13:59:31 +03001613 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001614
David Weinehall36cdd012016-08-22 13:59:31 +03001615 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001616 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001617 return 0;
1618 }
1619
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001620 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001621 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001622
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001623 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001624 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001625 else
1626 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001627 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001628
David Weinehall36cdd012016-08-22 13:59:31 +03001629 if (INTEL_GEN(dev_priv) >= 7)
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001630 seq_printf(m, "Compressing: %s\n",
1631 yesno(I915_READ(FBC_STATUS2) &
1632 FBC_COMPRESSION_MASK));
1633
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001634 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001635 intel_runtime_pm_put(dev_priv);
1636
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001637 return 0;
1638}
1639
Rodrigo Vivida46f932014-08-01 02:04:45 -07001640static int i915_fbc_fc_get(void *data, u64 *val)
1641{
David Weinehall36cdd012016-08-22 13:59:31 +03001642 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001643
David Weinehall36cdd012016-08-22 13:59:31 +03001644 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001645 return -ENODEV;
1646
Rodrigo Vivida46f932014-08-01 02:04:45 -07001647 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001648
1649 return 0;
1650}
1651
1652static int i915_fbc_fc_set(void *data, u64 val)
1653{
David Weinehall36cdd012016-08-22 13:59:31 +03001654 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001655 u32 reg;
1656
David Weinehall36cdd012016-08-22 13:59:31 +03001657 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001658 return -ENODEV;
1659
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001660 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001661
1662 reg = I915_READ(ILK_DPFC_CONTROL);
1663 dev_priv->fbc.false_color = val;
1664
1665 I915_WRITE(ILK_DPFC_CONTROL, val ?
1666 (reg | FBC_CTL_FALSE_COLOR) :
1667 (reg & ~FBC_CTL_FALSE_COLOR));
1668
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001669 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001670 return 0;
1671}
1672
1673DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1674 i915_fbc_fc_get, i915_fbc_fc_set,
1675 "%llu\n");
1676
Paulo Zanoni92d44622013-05-31 16:33:24 -03001677static int i915_ips_status(struct seq_file *m, void *unused)
1678{
David Weinehall36cdd012016-08-22 13:59:31 +03001679 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001680
David Weinehall36cdd012016-08-22 13:59:31 +03001681 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001682 seq_puts(m, "not supported\n");
1683 return 0;
1684 }
1685
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001686 intel_runtime_pm_get(dev_priv);
1687
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001688 seq_printf(m, "Enabled by kernel parameter: %s\n",
1689 yesno(i915.enable_ips));
1690
David Weinehall36cdd012016-08-22 13:59:31 +03001691 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001692 seq_puts(m, "Currently: unknown\n");
1693 } else {
1694 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1695 seq_puts(m, "Currently: enabled\n");
1696 else
1697 seq_puts(m, "Currently: disabled\n");
1698 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001699
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001700 intel_runtime_pm_put(dev_priv);
1701
Paulo Zanoni92d44622013-05-31 16:33:24 -03001702 return 0;
1703}
1704
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001705static int i915_sr_status(struct seq_file *m, void *unused)
1706{
David Weinehall36cdd012016-08-22 13:59:31 +03001707 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001708 bool sr_enabled = false;
1709
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001710 intel_runtime_pm_get(dev_priv);
1711
David Weinehall36cdd012016-08-22 13:59:31 +03001712 if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001713 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001714 else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
1715 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001716 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001717 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001718 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001719 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001720 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001721 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001722 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001723
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001724 intel_runtime_pm_put(dev_priv);
1725
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001726 seq_printf(m, "self-refresh: %s\n",
1727 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001728
1729 return 0;
1730}
1731
Jesse Barnes7648fa92010-05-20 14:28:11 -07001732static int i915_emon_status(struct seq_file *m, void *unused)
1733{
David Weinehall36cdd012016-08-22 13:59:31 +03001734 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1735 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001736 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001737 int ret;
1738
David Weinehall36cdd012016-08-22 13:59:31 +03001739 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001740 return -ENODEV;
1741
Chris Wilsonde227ef2010-07-03 07:58:38 +01001742 ret = mutex_lock_interruptible(&dev->struct_mutex);
1743 if (ret)
1744 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001745
1746 temp = i915_mch_val(dev_priv);
1747 chipset = i915_chipset_val(dev_priv);
1748 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001749 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001750
1751 seq_printf(m, "GMCH temp: %ld\n", temp);
1752 seq_printf(m, "Chipset power: %ld\n", chipset);
1753 seq_printf(m, "GFX power: %ld\n", gfx);
1754 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1755
1756 return 0;
1757}
1758
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001759static int i915_ring_freq_table(struct seq_file *m, void *unused)
1760{
David Weinehall36cdd012016-08-22 13:59:31 +03001761 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001762 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001763 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301764 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001765
David Weinehall36cdd012016-08-22 13:59:31 +03001766 if (!HAS_CORE_RING_FREQ(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001767 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001768 return 0;
1769 }
1770
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001771 intel_runtime_pm_get(dev_priv);
1772
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001773 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001774 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001775 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001776
David Weinehall36cdd012016-08-22 13:59:31 +03001777 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301778 /* Convert GT frequency to 50 HZ units */
1779 min_gpu_freq =
1780 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1781 max_gpu_freq =
1782 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1783 } else {
1784 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1785 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1786 }
1787
Damien Lespiau267f0c92013-06-24 22:59:48 +01001788 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789
Akash Goelf936ec32015-06-29 14:50:22 +05301790 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001791 ia_freq = gpu_freq;
1792 sandybridge_pcode_read(dev_priv,
1793 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1794 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001795 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301796 intel_gpu_freq(dev_priv, (gpu_freq *
David Weinehall36cdd012016-08-22 13:59:31 +03001797 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001798 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001799 ((ia_freq >> 0) & 0xff) * 100,
1800 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001801 }
1802
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001803 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001804
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001805out:
1806 intel_runtime_pm_put(dev_priv);
1807 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001808}
1809
Chris Wilson44834a62010-08-19 16:09:23 +01001810static int i915_opregion(struct seq_file *m, void *unused)
1811{
David Weinehall36cdd012016-08-22 13:59:31 +03001812 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1813 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001814 struct intel_opregion *opregion = &dev_priv->opregion;
1815 int ret;
1816
1817 ret = mutex_lock_interruptible(&dev->struct_mutex);
1818 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001819 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001820
Jani Nikula2455a8e2015-12-14 12:50:53 +02001821 if (opregion->header)
1822 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001823
1824 mutex_unlock(&dev->struct_mutex);
1825
Daniel Vetter0d38f002012-04-21 22:49:10 +02001826out:
Chris Wilson44834a62010-08-19 16:09:23 +01001827 return 0;
1828}
1829
Jani Nikulaada8f952015-12-15 13:17:12 +02001830static int i915_vbt(struct seq_file *m, void *unused)
1831{
David Weinehall36cdd012016-08-22 13:59:31 +03001832 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001833
1834 if (opregion->vbt)
1835 seq_write(m, opregion->vbt, opregion->vbt_size);
1836
1837 return 0;
1838}
1839
Chris Wilson37811fc2010-08-25 22:45:57 +01001840static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1841{
David Weinehall36cdd012016-08-22 13:59:31 +03001842 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1843 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301844 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001845 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001846 int ret;
1847
1848 ret = mutex_lock_interruptible(&dev->struct_mutex);
1849 if (ret)
1850 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001851
Daniel Vetter06957262015-08-10 13:34:08 +02001852#ifdef CONFIG_DRM_FBDEV_EMULATION
David Weinehall36cdd012016-08-22 13:59:31 +03001853 if (dev_priv->fbdev) {
1854 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001855
Chris Wilson25bcce92016-07-02 15:36:00 +01001856 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1857 fbdev_fb->base.width,
1858 fbdev_fb->base.height,
1859 fbdev_fb->base.depth,
1860 fbdev_fb->base.bits_per_pixel,
1861 fbdev_fb->base.modifier[0],
1862 drm_framebuffer_read_refcount(&fbdev_fb->base));
1863 describe_obj(m, fbdev_fb->obj);
1864 seq_putc(m, '\n');
1865 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001866#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001867
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001868 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001869 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301870 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1871 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001872 continue;
1873
Tvrtko Ursulinc1ca5062015-02-10 17:16:07 +00001874 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 +01001875 fb->base.width,
1876 fb->base.height,
1877 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001878 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca5062015-02-10 17:16:07 +00001879 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001880 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001881 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001882 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001883 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001884 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001885 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001886
1887 return 0;
1888}
1889
Chris Wilson7e37f882016-08-02 22:50:21 +01001890static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001891{
1892 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01001893 ring->space, ring->head, ring->tail,
1894 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001895}
1896
Ben Widawskye76d3632011-03-19 18:14:29 -07001897static int i915_context_status(struct seq_file *m, void *unused)
1898{
David Weinehall36cdd012016-08-22 13:59:31 +03001899 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1900 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001901 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001902 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00001903 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001904
Daniel Vetterf3d28872014-05-29 23:23:08 +02001905 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001906 if (ret)
1907 return ret;
1908
Ben Widawskya33afea2013-09-17 21:12:45 -07001909 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001910 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001911 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001912 struct task_struct *task;
1913
Chris Wilsonc84455b2016-08-15 10:49:08 +01001914 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001915 if (task) {
1916 seq_printf(m, "(%s [%d]) ",
1917 task->comm, task->pid);
1918 put_task_struct(task);
1919 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001920 } else if (IS_ERR(ctx->file_priv)) {
1921 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001922 } else {
1923 seq_puts(m, "(kernel) ");
1924 }
1925
Chris Wilsonbca44d82016-05-24 14:53:41 +01001926 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1927 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001928
Chris Wilsonbca44d82016-05-24 14:53:41 +01001929 for_each_engine(engine, dev_priv) {
1930 struct intel_context *ce = &ctx->engine[engine->id];
1931
1932 seq_printf(m, "%s: ", engine->name);
1933 seq_putc(m, ce->initialised ? 'I' : 'i');
1934 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001935 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001936 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001937 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001938 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001939 }
1940
Ben Widawskya33afea2013-09-17 21:12:45 -07001941 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001942 }
1943
Daniel Vetterf3d28872014-05-29 23:23:08 +02001944 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001945
1946 return 0;
1947}
1948
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001949static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001950 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001951 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001952{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001953 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001954 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001955 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001956
Chris Wilson7069b142016-04-28 09:56:52 +01001957 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
1958
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001959 if (!vma) {
1960 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001961 return;
1962 }
1963
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001964 if (vma->flags & I915_VMA_GLOBAL_BIND)
1965 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01001966 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001967
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001968 if (i915_gem_object_get_pages(vma->obj)) {
1969 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001970 return;
1971 }
1972
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001973 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
1974 if (page) {
1975 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001976
1977 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001978 seq_printf(m,
1979 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1980 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001981 reg_state[j], reg_state[j + 1],
1982 reg_state[j + 2], reg_state[j + 3]);
1983 }
1984 kunmap_atomic(reg_state);
1985 }
1986
1987 seq_putc(m, '\n');
1988}
1989
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001990static int i915_dump_lrc(struct seq_file *m, void *unused)
1991{
David Weinehall36cdd012016-08-22 13:59:31 +03001992 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1993 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001994 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001995 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001996 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001997
1998 if (!i915.enable_execlists) {
1999 seq_printf(m, "Logical Ring Contexts are disabled\n");
2000 return 0;
2001 }
2002
2003 ret = mutex_lock_interruptible(&dev->struct_mutex);
2004 if (ret)
2005 return ret;
2006
Dave Gordone28e4042016-01-19 19:02:55 +00002007 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3cc2016-04-28 09:56:53 +01002008 for_each_engine(engine, dev_priv)
2009 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002010
2011 mutex_unlock(&dev->struct_mutex);
2012
2013 return 0;
2014}
2015
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002016static int i915_execlists(struct seq_file *m, void *data)
2017{
David Weinehall36cdd012016-08-22 13:59:31 +03002018 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2019 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002020 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002021 u32 status_pointer;
2022 u8 read_pointer;
2023 u8 write_pointer;
2024 u32 status;
2025 u32 ctx_id;
2026 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002027 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002028
2029 if (!i915.enable_execlists) {
2030 seq_puts(m, "Logical Ring Contexts are disabled\n");
2031 return 0;
2032 }
2033
2034 ret = mutex_lock_interruptible(&dev->struct_mutex);
2035 if (ret)
2036 return ret;
2037
Michel Thierryfc0412e2014-10-16 16:13:38 +01002038 intel_runtime_pm_get(dev_priv);
2039
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002040 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002041 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002042 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002043
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002044 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002045
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002046 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2047 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002048 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2049 status, ctx_id);
2050
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002051 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002052 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2053
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002054 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002055 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002056 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002057 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002058 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2059 read_pointer, write_pointer);
2060
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002061 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002062 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2063 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002064
2065 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2066 i, status, ctx_id);
2067 }
2068
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002069 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002070 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002071 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002072 head_req = list_first_entry_or_null(&engine->execlist_queue,
2073 struct drm_i915_gem_request,
2074 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002075 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002076
2077 seq_printf(m, "\t%d requests in queue\n", count);
2078 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002079 seq_printf(m, "\tHead request context: %u\n",
2080 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002081 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002082 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002083 }
2084
2085 seq_putc(m, '\n');
2086 }
2087
Michel Thierryfc0412e2014-10-16 16:13:38 +01002088 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002089 mutex_unlock(&dev->struct_mutex);
2090
2091 return 0;
2092}
2093
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002094static const char *swizzle_string(unsigned swizzle)
2095{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002096 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002097 case I915_BIT_6_SWIZZLE_NONE:
2098 return "none";
2099 case I915_BIT_6_SWIZZLE_9:
2100 return "bit9";
2101 case I915_BIT_6_SWIZZLE_9_10:
2102 return "bit9/bit10";
2103 case I915_BIT_6_SWIZZLE_9_11:
2104 return "bit9/bit11";
2105 case I915_BIT_6_SWIZZLE_9_10_11:
2106 return "bit9/bit10/bit11";
2107 case I915_BIT_6_SWIZZLE_9_17:
2108 return "bit9/bit17";
2109 case I915_BIT_6_SWIZZLE_9_10_17:
2110 return "bit9/bit10/bit17";
2111 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002112 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002113 }
2114
2115 return "bug";
2116}
2117
2118static int i915_swizzle_info(struct seq_file *m, void *data)
2119{
David Weinehall36cdd012016-08-22 13:59:31 +03002120 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2121 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002122 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002123
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002124 ret = mutex_lock_interruptible(&dev->struct_mutex);
2125 if (ret)
2126 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002127 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002128
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002129 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2130 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2131 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2132 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2133
David Weinehall36cdd012016-08-22 13:59:31 +03002134 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002135 seq_printf(m, "DDC = 0x%08x\n",
2136 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002137 seq_printf(m, "DDC2 = 0x%08x\n",
2138 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002139 seq_printf(m, "C0DRB3 = 0x%04x\n",
2140 I915_READ16(C0DRB3));
2141 seq_printf(m, "C1DRB3 = 0x%04x\n",
2142 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002143 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002144 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2145 I915_READ(MAD_DIMM_C0));
2146 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2147 I915_READ(MAD_DIMM_C1));
2148 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2149 I915_READ(MAD_DIMM_C2));
2150 seq_printf(m, "TILECTL = 0x%08x\n",
2151 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002152 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002153 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2154 I915_READ(GAMTARBMODE));
2155 else
2156 seq_printf(m, "ARB_MODE = 0x%08x\n",
2157 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002158 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2159 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002160 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002161
2162 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2163 seq_puts(m, "L-shaped memory detected\n");
2164
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002165 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002166 mutex_unlock(&dev->struct_mutex);
2167
2168 return 0;
2169}
2170
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002171static int per_file_ctx(int id, void *ptr, void *data)
2172{
Chris Wilsone2efd132016-05-24 14:53:34 +01002173 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002174 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002175 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2176
2177 if (!ppgtt) {
2178 seq_printf(m, " no ppgtt for context %d\n",
2179 ctx->user_handle);
2180 return 0;
2181 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002182
Oscar Mateof83d6512014-05-22 14:13:38 +01002183 if (i915_gem_context_is_default(ctx))
2184 seq_puts(m, " default context:\n");
2185 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002186 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002187 ppgtt->debug_dump(ppgtt, m);
2188
2189 return 0;
2190}
2191
David Weinehall36cdd012016-08-22 13:59:31 +03002192static void gen8_ppgtt_info(struct seq_file *m,
2193 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002194{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002195 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002196 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002197 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002198
Ben Widawsky77df6772013-11-02 21:07:30 -07002199 if (!ppgtt)
2200 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002201
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002202 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002203 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002204 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002205 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002206 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002207 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002208 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002209 }
2210 }
2211}
2212
David Weinehall36cdd012016-08-22 13:59:31 +03002213static void gen6_ppgtt_info(struct seq_file *m,
2214 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002215{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002216 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002217
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002218 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002219 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2220
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002221 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002222 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002223 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002224 seq_printf(m, "GFX_MODE: 0x%08x\n",
2225 I915_READ(RING_MODE_GEN7(engine)));
2226 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2227 I915_READ(RING_PP_DIR_BASE(engine)));
2228 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2229 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2230 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2231 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002232 }
2233 if (dev_priv->mm.aliasing_ppgtt) {
2234 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2235
Damien Lespiau267f0c92013-06-24 22:59:48 +01002236 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002237 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002238
Ben Widawsky87d60b62013-12-06 14:11:29 -08002239 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002240 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002241
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002242 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002243}
2244
2245static int i915_ppgtt_info(struct seq_file *m, void *data)
2246{
David Weinehall36cdd012016-08-22 13:59:31 +03002247 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2248 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002249 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002250 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002251
Chris Wilson637ee292016-08-22 14:28:20 +01002252 mutex_lock(&dev->filelist_mutex);
2253 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002254 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002255 goto out_unlock;
2256
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002257 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002258
David Weinehall36cdd012016-08-22 13:59:31 +03002259 if (INTEL_GEN(dev_priv) >= 8)
2260 gen8_ppgtt_info(m, dev_priv);
2261 else if (INTEL_GEN(dev_priv) >= 6)
2262 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002263
Michel Thierryea91e402015-07-29 17:23:57 +01002264 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2265 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002266 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002267
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002268 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002269 if (!task) {
2270 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002271 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002272 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002273 seq_printf(m, "\nproc: %s\n", task->comm);
2274 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002275 idr_for_each(&file_priv->context_idr, per_file_ctx,
2276 (void *)(unsigned long)m);
2277 }
2278
Chris Wilson637ee292016-08-22 14:28:20 +01002279out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002280 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002281 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002282out_unlock:
2283 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002284 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002285}
2286
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002287static int count_irq_waiters(struct drm_i915_private *i915)
2288{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002289 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002290 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002291
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002292 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002293 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002294
2295 return count;
2296}
2297
Chris Wilson7466c292016-08-15 09:49:33 +01002298static const char *rps_power_to_str(unsigned int power)
2299{
2300 static const char * const strings[] = {
2301 [LOW_POWER] = "low power",
2302 [BETWEEN] = "mixed",
2303 [HIGH_POWER] = "high power",
2304 };
2305
2306 if (power >= ARRAY_SIZE(strings) || !strings[power])
2307 return "unknown";
2308
2309 return strings[power];
2310}
2311
Chris Wilson1854d5c2015-04-07 16:20:32 +01002312static int i915_rps_boost_info(struct seq_file *m, void *data)
2313{
David Weinehall36cdd012016-08-22 13:59:31 +03002314 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2315 struct drm_device *dev = &dev_priv->drm;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002316 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002317
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002318 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002319 seq_printf(m, "GPU busy? %s [%x]\n",
2320 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002321 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7466c292016-08-15 09:49:33 +01002322 seq_printf(m, "Frequency requested %d\n",
2323 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
2324 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002325 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2326 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2327 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2328 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002329 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
2330 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
2331 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
2332 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002333
2334 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002335 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002336 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2337 struct drm_i915_file_private *file_priv = file->driver_priv;
2338 struct task_struct *task;
2339
2340 rcu_read_lock();
2341 task = pid_task(file->pid, PIDTYPE_PID);
2342 seq_printf(m, "%s [%d]: %d boosts%s\n",
2343 task ? task->comm : "<unknown>",
2344 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002345 file_priv->rps.boosts,
2346 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002347 rcu_read_unlock();
2348 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002349 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002350 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002351 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002352
Chris Wilson7466c292016-08-15 09:49:33 +01002353 if (INTEL_GEN(dev_priv) >= 6 &&
2354 dev_priv->rps.enabled &&
2355 dev_priv->gt.active_engines) {
2356 u32 rpup, rpupei;
2357 u32 rpdown, rpdownei;
2358
2359 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2360 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2361 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2362 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2363 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2364 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2365
2366 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
2367 rps_power_to_str(dev_priv->rps.power));
2368 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
2369 100 * rpup / rpupei,
2370 dev_priv->rps.up_threshold);
2371 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
2372 100 * rpdown / rpdownei,
2373 dev_priv->rps.down_threshold);
2374 } else {
2375 seq_puts(m, "\nRPS Autotuning inactive\n");
2376 }
2377
Chris Wilson8d3afd72015-05-21 21:01:47 +01002378 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002379}
2380
Ben Widawsky63573eb2013-07-04 11:02:07 -07002381static int i915_llc(struct seq_file *m, void *data)
2382{
David Weinehall36cdd012016-08-22 13:59:31 +03002383 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002384 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002385
David Weinehall36cdd012016-08-22 13:59:31 +03002386 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002387 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2388 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002389
2390 return 0;
2391}
2392
Alex Daifdf5d352015-08-12 15:43:37 +01002393static int i915_guc_load_status_info(struct seq_file *m, void *data)
2394{
David Weinehall36cdd012016-08-22 13:59:31 +03002395 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Alex Daifdf5d352015-08-12 15:43:37 +01002396 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2397 u32 tmp, i;
2398
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002399 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002400 return 0;
2401
2402 seq_printf(m, "GuC firmware status:\n");
2403 seq_printf(m, "\tpath: %s\n",
2404 guc_fw->guc_fw_path);
2405 seq_printf(m, "\tfetch: %s\n",
2406 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2407 seq_printf(m, "\tload: %s\n",
2408 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2409 seq_printf(m, "\tversion wanted: %d.%d\n",
2410 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2411 seq_printf(m, "\tversion found: %d.%d\n",
2412 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002413 seq_printf(m, "\theader: offset is %d; size = %d\n",
2414 guc_fw->header_offset, guc_fw->header_size);
2415 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2416 guc_fw->ucode_offset, guc_fw->ucode_size);
2417 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2418 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002419
2420 tmp = I915_READ(GUC_STATUS);
2421
2422 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2423 seq_printf(m, "\tBootrom status = 0x%x\n",
2424 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2425 seq_printf(m, "\tuKernel status = 0x%x\n",
2426 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2427 seq_printf(m, "\tMIA Core status = 0x%x\n",
2428 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2429 seq_puts(m, "\nScratch registers:\n");
2430 for (i = 0; i < 16; i++)
2431 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2432
2433 return 0;
2434}
2435
Dave Gordon8b417c22015-08-12 15:43:44 +01002436static void i915_guc_client_info(struct seq_file *m,
2437 struct drm_i915_private *dev_priv,
2438 struct i915_guc_client *client)
2439{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002440 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002441 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002442 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002443
2444 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2445 client->priority, client->ctx_index, client->proc_desc_offset);
2446 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2447 client->doorbell_id, client->doorbell_offset, client->cookie);
2448 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2449 client->wq_size, client->wq_offset, client->wq_tail);
2450
Dave Gordon551aaec2016-05-13 15:36:33 +01002451 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002452 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2453 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2454
Dave Gordonc18468c2016-08-09 15:19:22 +01002455 for_each_engine_id(engine, dev_priv, id) {
2456 u64 submissions = client->submissions[id];
2457 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002458 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002459 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002460 }
2461 seq_printf(m, "\tTotal: %llu\n", tot);
2462}
2463
2464static int i915_guc_info(struct seq_file *m, void *data)
2465{
David Weinehall36cdd012016-08-22 13:59:31 +03002466 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2467 struct drm_device *dev = &dev_priv->drm;
Dave Gordon8b417c22015-08-12 15:43:44 +01002468 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002469 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002470 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002471 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002472 u64 total = 0;
2473
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002474 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002475 return 0;
2476
Alex Dai5a843302015-12-02 16:56:29 -08002477 if (mutex_lock_interruptible(&dev->struct_mutex))
2478 return 0;
2479
Dave Gordon8b417c22015-08-12 15:43:44 +01002480 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002481 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002482 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002483 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002484
2485 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002486
Dave Gordon9636f6d2016-06-13 17:57:28 +01002487 seq_printf(m, "Doorbell map:\n");
2488 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2489 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2490
Dave Gordon8b417c22015-08-12 15:43:44 +01002491 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2492 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2493 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2494 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2495 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2496
2497 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonc18468c2016-08-09 15:19:22 +01002498 for_each_engine_id(engine, dev_priv, id) {
2499 u64 submissions = guc.submissions[id];
2500 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002501 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002502 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002503 }
2504 seq_printf(m, "\t%s: %llu\n", "Total", total);
2505
2506 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2507 i915_guc_client_info(m, dev_priv, &client);
2508
2509 /* Add more as required ... */
2510
2511 return 0;
2512}
2513
Alex Dai4c7e77f2015-08-12 15:43:40 +01002514static int i915_guc_log_dump(struct seq_file *m, void *data)
2515{
David Weinehall36cdd012016-08-22 13:59:31 +03002516 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson8b797af2016-08-15 10:48:51 +01002517 struct drm_i915_gem_object *obj;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002518 int i = 0, pg;
2519
Chris Wilson8b797af2016-08-15 10:48:51 +01002520 if (!dev_priv->guc.log_vma)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002521 return 0;
2522
Chris Wilson8b797af2016-08-15 10:48:51 +01002523 obj = dev_priv->guc.log_vma->obj;
2524 for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
2525 u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
Alex Dai4c7e77f2015-08-12 15:43:40 +01002526
2527 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2528 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2529 *(log + i), *(log + i + 1),
2530 *(log + i + 2), *(log + i + 3));
2531
2532 kunmap_atomic(log);
2533 }
2534
2535 seq_putc(m, '\n');
2536
2537 return 0;
2538}
2539
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002540static int i915_edp_psr_status(struct seq_file *m, void *data)
2541{
David Weinehall36cdd012016-08-22 13:59:31 +03002542 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002543 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002544 u32 stat[3];
2545 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002546 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002547
David Weinehall36cdd012016-08-22 13:59:31 +03002548 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002549 seq_puts(m, "PSR not supported\n");
2550 return 0;
2551 }
2552
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002553 intel_runtime_pm_get(dev_priv);
2554
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002555 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002556 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2557 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002558 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002559 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002560 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2561 dev_priv->psr.busy_frontbuffer_bits);
2562 seq_printf(m, "Re-enable work scheduled: %s\n",
2563 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002564
David Weinehall36cdd012016-08-22 13:59:31 +03002565 if (HAS_DDI(dev_priv))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002566 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002567 else {
2568 for_each_pipe(dev_priv, pipe) {
2569 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2570 VLV_EDP_PSR_CURR_STATE_MASK;
2571 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2572 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2573 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002574 }
2575 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002576
2577 seq_printf(m, "Main link in standby mode: %s\n",
2578 yesno(dev_priv->psr.link_standby));
2579
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002580 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002581
David Weinehall36cdd012016-08-22 13:59:31 +03002582 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002583 for_each_pipe(dev_priv, pipe) {
2584 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2585 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2586 seq_printf(m, " pipe %c", pipe_name(pipe));
2587 }
2588 seq_puts(m, "\n");
2589
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002590 /*
2591 * VLV/CHV PSR has no kind of performance counter
2592 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2593 */
David Weinehall36cdd012016-08-22 13:59:31 +03002594 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002595 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002596 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002597
2598 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2599 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002600 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002601
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002602 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002603 return 0;
2604}
2605
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002606static int i915_sink_crc(struct seq_file *m, void *data)
2607{
David Weinehall36cdd012016-08-22 13:59:31 +03002608 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2609 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002610 struct intel_connector *connector;
2611 struct intel_dp *intel_dp = NULL;
2612 int ret;
2613 u8 crc[6];
2614
2615 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002616 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002617 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002618
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002619 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002620 continue;
2621
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002622 crtc = connector->base.state->crtc;
2623 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002624 continue;
2625
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002626 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002627 continue;
2628
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002629 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002630
2631 ret = intel_dp_sink_crc(intel_dp, crc);
2632 if (ret)
2633 goto out;
2634
2635 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2636 crc[0], crc[1], crc[2],
2637 crc[3], crc[4], crc[5]);
2638 goto out;
2639 }
2640 ret = -ENODEV;
2641out:
2642 drm_modeset_unlock_all(dev);
2643 return ret;
2644}
2645
Jesse Barnesec013e72013-08-20 10:29:23 +01002646static int i915_energy_uJ(struct seq_file *m, void *data)
2647{
David Weinehall36cdd012016-08-22 13:59:31 +03002648 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesec013e72013-08-20 10:29:23 +01002649 u64 power;
2650 u32 units;
2651
David Weinehall36cdd012016-08-22 13:59:31 +03002652 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002653 return -ENODEV;
2654
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002655 intel_runtime_pm_get(dev_priv);
2656
Jesse Barnesec013e72013-08-20 10:29:23 +01002657 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2658 power = (power & 0x1f00) >> 8;
2659 units = 1000000 / (1 << power); /* convert to uJ */
2660 power = I915_READ(MCH_SECP_NRG_STTS);
2661 power *= units;
2662
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002663 intel_runtime_pm_put(dev_priv);
2664
Jesse Barnesec013e72013-08-20 10:29:23 +01002665 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002666
2667 return 0;
2668}
2669
Damien Lespiau6455c872015-06-04 18:23:57 +01002670static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002671{
David Weinehall36cdd012016-08-22 13:59:31 +03002672 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002673 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002674
Chris Wilsona156e642016-04-03 14:14:21 +01002675 if (!HAS_RUNTIME_PM(dev_priv))
2676 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002677
Chris Wilson67d97da2016-07-04 08:08:31 +01002678 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002679 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002680 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002681#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002682 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002683 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002684#else
2685 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2686#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002687 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002688 pci_power_name(pdev->current_state),
2689 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002690
Jesse Barnesec013e72013-08-20 10:29:23 +01002691 return 0;
2692}
2693
Imre Deak1da51582013-11-25 17:15:35 +02002694static int i915_power_domain_info(struct seq_file *m, void *unused)
2695{
David Weinehall36cdd012016-08-22 13:59:31 +03002696 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002697 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2698 int i;
2699
2700 mutex_lock(&power_domains->lock);
2701
2702 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2703 for (i = 0; i < power_domains->power_well_count; i++) {
2704 struct i915_power_well *power_well;
2705 enum intel_display_power_domain power_domain;
2706
2707 power_well = &power_domains->power_wells[i];
2708 seq_printf(m, "%-25s %d\n", power_well->name,
2709 power_well->count);
2710
2711 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2712 power_domain++) {
2713 if (!(BIT(power_domain) & power_well->domains))
2714 continue;
2715
2716 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002717 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002718 power_domains->domain_use_count[power_domain]);
2719 }
2720 }
2721
2722 mutex_unlock(&power_domains->lock);
2723
2724 return 0;
2725}
2726
Damien Lespiaub7cec662015-10-27 14:47:01 +02002727static int i915_dmc_info(struct seq_file *m, void *unused)
2728{
David Weinehall36cdd012016-08-22 13:59:31 +03002729 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002730 struct intel_csr *csr;
2731
David Weinehall36cdd012016-08-22 13:59:31 +03002732 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002733 seq_puts(m, "not supported\n");
2734 return 0;
2735 }
2736
2737 csr = &dev_priv->csr;
2738
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002739 intel_runtime_pm_get(dev_priv);
2740
Damien Lespiaub7cec662015-10-27 14:47:01 +02002741 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2742 seq_printf(m, "path: %s\n", csr->fw_path);
2743
2744 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002745 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002746
2747 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2748 CSR_VERSION_MINOR(csr->version));
2749
David Weinehall36cdd012016-08-22 13:59:31 +03002750 if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
Damien Lespiau83372062015-10-30 17:53:32 +02002751 seq_printf(m, "DC3 -> DC5 count: %d\n",
2752 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2753 seq_printf(m, "DC5 -> DC6 count: %d\n",
2754 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002755 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002756 seq_printf(m, "DC3 -> DC5 count: %d\n",
2757 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002758 }
2759
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002760out:
2761 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2762 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2763 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2764
Damien Lespiau83372062015-10-30 17:53:32 +02002765 intel_runtime_pm_put(dev_priv);
2766
Damien Lespiaub7cec662015-10-27 14:47:01 +02002767 return 0;
2768}
2769
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002770static void intel_seq_print_mode(struct seq_file *m, int tabs,
2771 struct drm_display_mode *mode)
2772{
2773 int i;
2774
2775 for (i = 0; i < tabs; i++)
2776 seq_putc(m, '\t');
2777
2778 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",
2779 mode->base.id, mode->name,
2780 mode->vrefresh, mode->clock,
2781 mode->hdisplay, mode->hsync_start,
2782 mode->hsync_end, mode->htotal,
2783 mode->vdisplay, mode->vsync_start,
2784 mode->vsync_end, mode->vtotal,
2785 mode->type, mode->flags);
2786}
2787
2788static void intel_encoder_info(struct seq_file *m,
2789 struct intel_crtc *intel_crtc,
2790 struct intel_encoder *intel_encoder)
2791{
David Weinehall36cdd012016-08-22 13:59:31 +03002792 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2793 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002794 struct drm_crtc *crtc = &intel_crtc->base;
2795 struct intel_connector *intel_connector;
2796 struct drm_encoder *encoder;
2797
2798 encoder = &intel_encoder->base;
2799 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a02014-06-03 14:56:21 +03002800 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002801 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2802 struct drm_connector *connector = &intel_connector->base;
2803 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2804 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002805 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002806 drm_get_connector_status_name(connector->status));
2807 if (connector->status == connector_status_connected) {
2808 struct drm_display_mode *mode = &crtc->mode;
2809 seq_printf(m, ", mode:\n");
2810 intel_seq_print_mode(m, 2, mode);
2811 } else {
2812 seq_putc(m, '\n');
2813 }
2814 }
2815}
2816
2817static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2818{
David Weinehall36cdd012016-08-22 13:59:31 +03002819 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2820 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002821 struct drm_crtc *crtc = &intel_crtc->base;
2822 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002823 struct drm_plane_state *plane_state = crtc->primary->state;
2824 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002825
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002826 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002827 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002828 fb->base.id, plane_state->src_x >> 16,
2829 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002830 else
2831 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002832 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2833 intel_encoder_info(m, intel_crtc, intel_encoder);
2834}
2835
2836static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2837{
2838 struct drm_display_mode *mode = panel->fixed_mode;
2839
2840 seq_printf(m, "\tfixed mode:\n");
2841 intel_seq_print_mode(m, 2, mode);
2842}
2843
2844static void intel_dp_info(struct seq_file *m,
2845 struct intel_connector *intel_connector)
2846{
2847 struct intel_encoder *intel_encoder = intel_connector->encoder;
2848 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2849
2850 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002851 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002852 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002853 intel_panel_info(m, &intel_connector->panel);
2854}
2855
2856static void intel_hdmi_info(struct seq_file *m,
2857 struct intel_connector *intel_connector)
2858{
2859 struct intel_encoder *intel_encoder = intel_connector->encoder;
2860 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2861
Jani Nikula742f4912015-09-03 11:16:09 +03002862 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002863}
2864
2865static void intel_lvds_info(struct seq_file *m,
2866 struct intel_connector *intel_connector)
2867{
2868 intel_panel_info(m, &intel_connector->panel);
2869}
2870
2871static void intel_connector_info(struct seq_file *m,
2872 struct drm_connector *connector)
2873{
2874 struct intel_connector *intel_connector = to_intel_connector(connector);
2875 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002876 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002877
2878 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002879 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002880 drm_get_connector_status_name(connector->status));
2881 if (connector->status == connector_status_connected) {
2882 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2883 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2884 connector->display_info.width_mm,
2885 connector->display_info.height_mm);
2886 seq_printf(m, "\tsubpixel order: %s\n",
2887 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2888 seq_printf(m, "\tCEA rev: %d\n",
2889 connector->display_info.cea_rev);
2890 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002891
2892 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
2893 return;
2894
2895 switch (connector->connector_type) {
2896 case DRM_MODE_CONNECTOR_DisplayPort:
2897 case DRM_MODE_CONNECTOR_eDP:
2898 intel_dp_info(m, intel_connector);
2899 break;
2900 case DRM_MODE_CONNECTOR_LVDS:
2901 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002902 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002903 break;
2904 case DRM_MODE_CONNECTOR_HDMIA:
2905 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
2906 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
2907 intel_hdmi_info(m, intel_connector);
2908 break;
2909 default:
2910 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002911 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002912
Jesse Barnesf103fc72014-02-20 12:39:57 -08002913 seq_printf(m, "\tmodes:\n");
2914 list_for_each_entry(mode, &connector->modes, head)
2915 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002916}
2917
David Weinehall36cdd012016-08-22 13:59:31 +03002918static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002919{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002920 u32 state;
2921
David Weinehall36cdd012016-08-22 13:59:31 +03002922 if (IS_845G(dev_priv) || IS_I865G(dev_priv))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002923 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002924 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002925 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002926
2927 return state;
2928}
2929
David Weinehall36cdd012016-08-22 13:59:31 +03002930static bool cursor_position(struct drm_i915_private *dev_priv,
2931 int pipe, int *x, int *y)
Chris Wilson065f2ec2014-03-12 09:13:13 +00002932{
Chris Wilson065f2ec2014-03-12 09:13:13 +00002933 u32 pos;
2934
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002935 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002936
2937 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2938 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2939 *x = -*x;
2940
2941 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2942 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2943 *y = -*y;
2944
David Weinehall36cdd012016-08-22 13:59:31 +03002945 return cursor_active(dev_priv, pipe);
Chris Wilson065f2ec2014-03-12 09:13:13 +00002946}
2947
Robert Fekete3abc4e02015-10-27 16:58:32 +01002948static const char *plane_type(enum drm_plane_type type)
2949{
2950 switch (type) {
2951 case DRM_PLANE_TYPE_OVERLAY:
2952 return "OVL";
2953 case DRM_PLANE_TYPE_PRIMARY:
2954 return "PRI";
2955 case DRM_PLANE_TYPE_CURSOR:
2956 return "CUR";
2957 /*
2958 * Deliberately omitting default: to generate compiler warnings
2959 * when a new drm_plane_type gets added.
2960 */
2961 }
2962
2963 return "unknown";
2964}
2965
2966static const char *plane_rotation(unsigned int rotation)
2967{
2968 static char buf[48];
2969 /*
2970 * According to doc only one DRM_ROTATE_ is allowed but this
2971 * will print them all to visualize if the values are misused
2972 */
2973 snprintf(buf, sizeof(buf),
2974 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03002975 (rotation & DRM_ROTATE_0) ? "0 " : "",
2976 (rotation & DRM_ROTATE_90) ? "90 " : "",
2977 (rotation & DRM_ROTATE_180) ? "180 " : "",
2978 (rotation & DRM_ROTATE_270) ? "270 " : "",
2979 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
2980 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01002981 rotation);
2982
2983 return buf;
2984}
2985
2986static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2987{
David Weinehall36cdd012016-08-22 13:59:31 +03002988 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2989 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01002990 struct intel_plane *intel_plane;
2991
2992 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
2993 struct drm_plane_state *state;
2994 struct drm_plane *plane = &intel_plane->base;
2995
2996 if (!plane->state) {
2997 seq_puts(m, "plane->state is NULL!\n");
2998 continue;
2999 }
3000
3001 state = plane->state;
3002
3003 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",
3004 plane->base.id,
3005 plane_type(intel_plane->base.type),
3006 state->crtc_x, state->crtc_y,
3007 state->crtc_w, state->crtc_h,
3008 (state->src_x >> 16),
3009 ((state->src_x & 0xffff) * 15625) >> 10,
3010 (state->src_y >> 16),
3011 ((state->src_y & 0xffff) * 15625) >> 10,
3012 (state->src_w >> 16),
3013 ((state->src_w & 0xffff) * 15625) >> 10,
3014 (state->src_h >> 16),
3015 ((state->src_h & 0xffff) * 15625) >> 10,
3016 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3017 plane_rotation(state->rotation));
3018 }
3019}
3020
3021static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3022{
3023 struct intel_crtc_state *pipe_config;
3024 int num_scalers = intel_crtc->num_scalers;
3025 int i;
3026
3027 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3028
3029 /* Not all platformas have a scaler */
3030 if (num_scalers) {
3031 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3032 num_scalers,
3033 pipe_config->scaler_state.scaler_users,
3034 pipe_config->scaler_state.scaler_id);
3035
3036 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3037 struct intel_scaler *sc =
3038 &pipe_config->scaler_state.scalers[i];
3039
3040 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3041 i, yesno(sc->in_use), sc->mode);
3042 }
3043 seq_puts(m, "\n");
3044 } else {
3045 seq_puts(m, "\tNo scalers available on this platform\n");
3046 }
3047}
3048
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003049static int i915_display_info(struct seq_file *m, void *unused)
3050{
David Weinehall36cdd012016-08-22 13:59:31 +03003051 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3052 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003053 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003054 struct drm_connector *connector;
3055
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003056 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003057 drm_modeset_lock_all(dev);
3058 seq_printf(m, "CRTC info\n");
3059 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003060 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003061 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003062 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003063 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003064
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003065 pipe_config = to_intel_crtc_state(crtc->base.state);
3066
Robert Fekete3abc4e02015-10-27 16:58:32 +01003067 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003068 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003069 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003070 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3071 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3072
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003073 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003074 intel_crtc_info(m, crtc);
3075
David Weinehall36cdd012016-08-22 13:59:31 +03003076 active = cursor_position(dev_priv, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003077 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 +03003078 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003079 x, y, crtc->base.cursor->state->crtc_w,
3080 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003081 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003082 intel_scaler_info(m, crtc);
3083 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003084 }
Daniel Vettercace8412014-05-22 17:56:31 +02003085
3086 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3087 yesno(!crtc->cpu_fifo_underrun_disabled),
3088 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003089 }
3090
3091 seq_printf(m, "\n");
3092 seq_printf(m, "Connector info\n");
3093 seq_printf(m, "--------------\n");
3094 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3095 intel_connector_info(m, connector);
3096 }
3097 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003098 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003099
3100 return 0;
3101}
3102
Ben Widawskye04934c2014-06-30 09:53:42 -07003103static int i915_semaphore_status(struct seq_file *m, void *unused)
3104{
David Weinehall36cdd012016-08-22 13:59:31 +03003105 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3106 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003107 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003108 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003109 enum intel_engine_id id;
3110 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003111
Chris Wilson39df9192016-07-20 13:31:57 +01003112 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003113 seq_puts(m, "Semaphores are disabled\n");
3114 return 0;
3115 }
3116
3117 ret = mutex_lock_interruptible(&dev->struct_mutex);
3118 if (ret)
3119 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003120 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003121
David Weinehall36cdd012016-08-22 13:59:31 +03003122 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003123 struct page *page;
3124 uint64_t *seqno;
3125
Chris Wilson51d545d2016-08-15 10:49:02 +01003126 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003127
3128 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003129 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003130 uint64_t offset;
3131
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003132 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003133
3134 seq_puts(m, " Last signal:");
3135 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003136 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003137 seq_printf(m, "0x%08llx (0x%02llx) ",
3138 seqno[offset], offset * 8);
3139 }
3140 seq_putc(m, '\n');
3141
3142 seq_puts(m, " Last wait: ");
3143 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003144 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003145 seq_printf(m, "0x%08llx (0x%02llx) ",
3146 seqno[offset], offset * 8);
3147 }
3148 seq_putc(m, '\n');
3149
3150 }
3151 kunmap_atomic(seqno);
3152 } else {
3153 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003154 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003155 for (j = 0; j < num_rings; j++)
3156 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003157 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003158 seq_putc(m, '\n');
3159 }
3160
3161 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003162 for_each_engine(engine, dev_priv) {
3163 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003164 seq_printf(m, " 0x%08x ",
3165 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003166 seq_putc(m, '\n');
3167 }
3168 seq_putc(m, '\n');
3169
Paulo Zanoni03872062014-07-09 14:31:57 -03003170 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003171 mutex_unlock(&dev->struct_mutex);
3172 return 0;
3173}
3174
Daniel Vetter728e29d2014-06-25 22:01:53 +03003175static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3176{
David Weinehall36cdd012016-08-22 13:59:31 +03003177 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3178 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003179 int i;
3180
3181 drm_modeset_lock_all(dev);
3182 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3183 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3184
3185 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003186 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3187 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003188 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003189 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3190 seq_printf(m, " dpll_md: 0x%08x\n",
3191 pll->config.hw_state.dpll_md);
3192 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3193 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3194 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003195 }
3196 drm_modeset_unlock_all(dev);
3197
3198 return 0;
3199}
3200
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003201static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003202{
3203 int i;
3204 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003205 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003206 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3207 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003208 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003209 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003210
Arun Siluvery888b5992014-08-26 14:44:51 +01003211 ret = mutex_lock_interruptible(&dev->struct_mutex);
3212 if (ret)
3213 return ret;
3214
3215 intel_runtime_pm_get(dev_priv);
3216
Arun Siluvery33136b02016-01-21 21:43:47 +00003217 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003218 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003219 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003220 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003221 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003222 i915_reg_t addr;
3223 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003224 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003225
Arun Siluvery33136b02016-01-21 21:43:47 +00003226 addr = workarounds->reg[i].addr;
3227 mask = workarounds->reg[i].mask;
3228 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003229 read = I915_READ(addr);
3230 ok = (value & mask) == (read & mask);
3231 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 +02003232 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003233 }
3234
3235 intel_runtime_pm_put(dev_priv);
3236 mutex_unlock(&dev->struct_mutex);
3237
3238 return 0;
3239}
3240
Damien Lespiauc5511e42014-11-04 17:06:51 +00003241static int i915_ddb_info(struct seq_file *m, void *unused)
3242{
David Weinehall36cdd012016-08-22 13:59:31 +03003243 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3244 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003245 struct skl_ddb_allocation *ddb;
3246 struct skl_ddb_entry *entry;
3247 enum pipe pipe;
3248 int plane;
3249
David Weinehall36cdd012016-08-22 13:59:31 +03003250 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003251 return 0;
3252
Damien Lespiauc5511e42014-11-04 17:06:51 +00003253 drm_modeset_lock_all(dev);
3254
3255 ddb = &dev_priv->wm.skl_hw.ddb;
3256
3257 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3258
3259 for_each_pipe(dev_priv, pipe) {
3260 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3261
Damien Lespiaudd740782015-02-28 14:54:08 +00003262 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003263 entry = &ddb->plane[pipe][plane];
3264 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3265 entry->start, entry->end,
3266 skl_ddb_entry_size(entry));
3267 }
3268
Matt Roper4969d332015-09-24 15:53:10 -07003269 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003270 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3271 entry->end, skl_ddb_entry_size(entry));
3272 }
3273
3274 drm_modeset_unlock_all(dev);
3275
3276 return 0;
3277}
3278
Vandana Kannana54746e2015-03-03 20:53:10 +05303279static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003280 struct drm_device *dev,
3281 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303282{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003283 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303284 struct i915_drrs *drrs = &dev_priv->drrs;
3285 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003286 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303287
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003288 drm_for_each_connector(connector, dev) {
3289 if (connector->state->crtc != &intel_crtc->base)
3290 continue;
3291
3292 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303293 }
3294
3295 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3296 seq_puts(m, "\tVBT: DRRS_type: Static");
3297 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3298 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3299 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3300 seq_puts(m, "\tVBT: DRRS_type: None");
3301 else
3302 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3303
3304 seq_puts(m, "\n\n");
3305
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003306 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303307 struct intel_panel *panel;
3308
3309 mutex_lock(&drrs->mutex);
3310 /* DRRS Supported */
3311 seq_puts(m, "\tDRRS Supported: Yes\n");
3312
3313 /* disable_drrs() will make drrs->dp NULL */
3314 if (!drrs->dp) {
3315 seq_puts(m, "Idleness DRRS: Disabled");
3316 mutex_unlock(&drrs->mutex);
3317 return;
3318 }
3319
3320 panel = &drrs->dp->attached_connector->panel;
3321 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3322 drrs->busy_frontbuffer_bits);
3323
3324 seq_puts(m, "\n\t\t");
3325 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3326 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3327 vrefresh = panel->fixed_mode->vrefresh;
3328 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3329 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3330 vrefresh = panel->downclock_mode->vrefresh;
3331 } else {
3332 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3333 drrs->refresh_rate_type);
3334 mutex_unlock(&drrs->mutex);
3335 return;
3336 }
3337 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3338
3339 seq_puts(m, "\n\t\t");
3340 mutex_unlock(&drrs->mutex);
3341 } else {
3342 /* DRRS not supported. Print the VBT parameter*/
3343 seq_puts(m, "\tDRRS Supported : No");
3344 }
3345 seq_puts(m, "\n");
3346}
3347
3348static int i915_drrs_status(struct seq_file *m, void *unused)
3349{
David Weinehall36cdd012016-08-22 13:59:31 +03003350 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3351 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303352 struct intel_crtc *intel_crtc;
3353 int active_crtc_cnt = 0;
3354
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003355 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303356 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003357 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303358 active_crtc_cnt++;
3359 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3360
3361 drrs_status_per_crtc(m, dev, intel_crtc);
3362 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303363 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003364 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303365
3366 if (!active_crtc_cnt)
3367 seq_puts(m, "No active crtc found\n");
3368
3369 return 0;
3370}
3371
Damien Lespiau07144422013-10-15 18:55:40 +01003372struct pipe_crc_info {
3373 const char *name;
David Weinehall36cdd012016-08-22 13:59:31 +03003374 struct drm_i915_private *dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003375 enum pipe pipe;
3376};
3377
Dave Airlie11bed9582014-05-12 15:22:27 +10003378static int i915_dp_mst_info(struct seq_file *m, void *unused)
3379{
David Weinehall36cdd012016-08-22 13:59:31 +03003380 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3381 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed9582014-05-12 15:22:27 +10003382 struct intel_encoder *intel_encoder;
3383 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003384 struct drm_connector *connector;
3385
Dave Airlie11bed9582014-05-12 15:22:27 +10003386 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003387 drm_for_each_connector(connector, dev) {
3388 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed9582014-05-12 15:22:27 +10003389 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003390
3391 intel_encoder = intel_attached_encoder(connector);
3392 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3393 continue;
3394
3395 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed9582014-05-12 15:22:27 +10003396 if (!intel_dig_port->dp.can_mst)
3397 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003398
Jim Bride40ae80c2016-04-14 10:18:37 -07003399 seq_printf(m, "MST Source Port %c\n",
3400 port_name(intel_dig_port->port));
Dave Airlie11bed9582014-05-12 15:22:27 +10003401 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3402 }
3403 drm_modeset_unlock_all(dev);
3404 return 0;
3405}
3406
Damien Lespiau07144422013-10-15 18:55:40 +01003407static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003408{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003409 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003410 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003411 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3412
David Weinehall36cdd012016-08-22 13:59:31 +03003413 if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003414 return -ENODEV;
3415
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003416 spin_lock_irq(&pipe_crc->lock);
3417
3418 if (pipe_crc->opened) {
3419 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003420 return -EBUSY; /* already open */
3421 }
3422
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003423 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003424 filep->private_data = inode->i_private;
3425
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003426 spin_unlock_irq(&pipe_crc->lock);
3427
Damien Lespiau07144422013-10-15 18:55:40 +01003428 return 0;
3429}
3430
3431static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3432{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003433 struct pipe_crc_info *info = inode->i_private;
David Weinehall36cdd012016-08-22 13:59:31 +03003434 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003435 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3436
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003437 spin_lock_irq(&pipe_crc->lock);
3438 pipe_crc->opened = false;
3439 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003440
Damien Lespiau07144422013-10-15 18:55:40 +01003441 return 0;
3442}
3443
3444/* (6 fields, 8 chars each, space separated (5) + '\n') */
3445#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3446/* account for \'0' */
3447#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3448
3449static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3450{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003451 assert_spin_locked(&pipe_crc->lock);
3452 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3453 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003454}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003455
Damien Lespiau07144422013-10-15 18:55:40 +01003456static ssize_t
3457i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3458 loff_t *pos)
3459{
3460 struct pipe_crc_info *info = filep->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003461 struct drm_i915_private *dev_priv = info->dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003462 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3463 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003464 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003465 ssize_t bytes_read;
3466
3467 /*
3468 * Don't allow user space to provide buffers not big enough to hold
3469 * a line of data.
3470 */
3471 if (count < PIPE_CRC_LINE_LEN)
3472 return -EINVAL;
3473
3474 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3475 return 0;
3476
3477 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003478 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003479 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003480 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003481
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003482 if (filep->f_flags & O_NONBLOCK) {
3483 spin_unlock_irq(&pipe_crc->lock);
3484 return -EAGAIN;
3485 }
3486
3487 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3488 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3489 if (ret) {
3490 spin_unlock_irq(&pipe_crc->lock);
3491 return ret;
3492 }
Damien Lespiau07144422013-10-15 18:55:40 +01003493 }
3494
3495 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003496 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003497
Damien Lespiau07144422013-10-15 18:55:40 +01003498 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003499 while (n_entries > 0) {
3500 struct intel_pipe_crc_entry *entry =
3501 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003502
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003503 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3504 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3505 break;
3506
3507 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3508 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3509
Damien Lespiau07144422013-10-15 18:55:40 +01003510 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3511 "%8u %8x %8x %8x %8x %8x\n",
3512 entry->frame, entry->crc[0],
3513 entry->crc[1], entry->crc[2],
3514 entry->crc[3], entry->crc[4]);
3515
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003516 spin_unlock_irq(&pipe_crc->lock);
3517
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003518 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003519 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003520
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003521 user_buf += PIPE_CRC_LINE_LEN;
3522 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003523
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003524 spin_lock_irq(&pipe_crc->lock);
3525 }
3526
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003527 spin_unlock_irq(&pipe_crc->lock);
3528
Damien Lespiau07144422013-10-15 18:55:40 +01003529 return bytes_read;
3530}
3531
3532static const struct file_operations i915_pipe_crc_fops = {
3533 .owner = THIS_MODULE,
3534 .open = i915_pipe_crc_open,
3535 .read = i915_pipe_crc_read,
3536 .release = i915_pipe_crc_release,
3537};
3538
3539static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3540 {
3541 .name = "i915_pipe_A_crc",
3542 .pipe = PIPE_A,
3543 },
3544 {
3545 .name = "i915_pipe_B_crc",
3546 .pipe = PIPE_B,
3547 },
3548 {
3549 .name = "i915_pipe_C_crc",
3550 .pipe = PIPE_C,
3551 },
3552};
3553
3554static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3555 enum pipe pipe)
3556{
David Weinehall36cdd012016-08-22 13:59:31 +03003557 struct drm_i915_private *dev_priv = to_i915(minor->dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003558 struct dentry *ent;
3559 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3560
David Weinehall36cdd012016-08-22 13:59:31 +03003561 info->dev_priv = dev_priv;
Damien Lespiau07144422013-10-15 18:55:40 +01003562 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3563 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003564 if (!ent)
3565 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003566
3567 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003568}
3569
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003570static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003571 "none",
3572 "plane1",
3573 "plane2",
3574 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003575 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003576 "TV",
3577 "DP-B",
3578 "DP-C",
3579 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003580 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003581};
3582
3583static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3584{
3585 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3586 return pipe_crc_sources[source];
3587}
3588
Damien Lespiaubd9db022013-10-15 18:55:36 +01003589static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003590{
David Weinehall36cdd012016-08-22 13:59:31 +03003591 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02003592 int i;
3593
3594 for (i = 0; i < I915_MAX_PIPES; i++)
3595 seq_printf(m, "%c %s\n", pipe_name(i),
3596 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3597
3598 return 0;
3599}
3600
Damien Lespiaubd9db022013-10-15 18:55:36 +01003601static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003602{
David Weinehall36cdd012016-08-22 13:59:31 +03003603 return single_open(file, display_crc_ctl_show, inode->i_private);
Daniel Vetter926321d2013-10-16 13:30:34 +02003604}
3605
Daniel Vetter46a19182013-11-01 10:50:20 +01003606static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003607 uint32_t *val)
3608{
Daniel Vetter46a19182013-11-01 10:50:20 +01003609 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3610 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3611
3612 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003613 case INTEL_PIPE_CRC_SOURCE_PIPE:
3614 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3615 break;
3616 case INTEL_PIPE_CRC_SOURCE_NONE:
3617 *val = 0;
3618 break;
3619 default:
3620 return -EINVAL;
3621 }
3622
3623 return 0;
3624}
3625
David Weinehall36cdd012016-08-22 13:59:31 +03003626static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
3627 enum pipe pipe,
Daniel Vetter46a19182013-11-01 10:50:20 +01003628 enum intel_pipe_crc_source *source)
3629{
David Weinehall36cdd012016-08-22 13:59:31 +03003630 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter46a19182013-11-01 10:50:20 +01003631 struct intel_encoder *encoder;
3632 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003633 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003634 int ret = 0;
3635
3636 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3637
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003638 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003639 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003640 if (!encoder->base.crtc)
3641 continue;
3642
3643 crtc = to_intel_crtc(encoder->base.crtc);
3644
3645 if (crtc->pipe != pipe)
3646 continue;
3647
3648 switch (encoder->type) {
3649 case INTEL_OUTPUT_TVOUT:
3650 *source = INTEL_PIPE_CRC_SOURCE_TV;
3651 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003652 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003653 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003654 dig_port = enc_to_dig_port(&encoder->base);
3655 switch (dig_port->port) {
3656 case PORT_B:
3657 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3658 break;
3659 case PORT_C:
3660 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3661 break;
3662 case PORT_D:
3663 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3664 break;
3665 default:
3666 WARN(1, "nonexisting DP port %c\n",
3667 port_name(dig_port->port));
3668 break;
3669 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003670 break;
Paulo Zanoni6847d712014-10-27 17:47:52 -02003671 default:
3672 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003673 }
3674 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003675 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003676
3677 return ret;
3678}
3679
David Weinehall36cdd012016-08-22 13:59:31 +03003680static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003681 enum pipe pipe,
3682 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003683 uint32_t *val)
3684{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003685 bool need_stable_symbols = false;
3686
Daniel Vetter46a19182013-11-01 10:50:20 +01003687 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003688 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003689 if (ret)
3690 return ret;
3691 }
3692
3693 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003694 case INTEL_PIPE_CRC_SOURCE_PIPE:
3695 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3696 break;
3697 case INTEL_PIPE_CRC_SOURCE_DP_B:
3698 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003699 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003700 break;
3701 case INTEL_PIPE_CRC_SOURCE_DP_C:
3702 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003703 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003704 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003705 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003706 if (!IS_CHERRYVIEW(dev_priv))
Ville Syrjälä2be57922014-12-09 21:28:29 +02003707 return -EINVAL;
3708 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3709 need_stable_symbols = true;
3710 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003711 case INTEL_PIPE_CRC_SOURCE_NONE:
3712 *val = 0;
3713 break;
3714 default:
3715 return -EINVAL;
3716 }
3717
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003718 /*
3719 * When the pipe CRC tap point is after the transcoders we need
3720 * to tweak symbol-level features to produce a deterministic series of
3721 * symbols for a given frame. We need to reset those features only once
3722 * a frame (instead of every nth symbol):
3723 * - DC-balance: used to ensure a better clock recovery from the data
3724 * link (SDVO)
3725 * - DisplayPort scrambling: used for EMI reduction
3726 */
3727 if (need_stable_symbols) {
3728 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3729
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003730 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003731 switch (pipe) {
3732 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003733 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003734 break;
3735 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003736 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003737 break;
3738 case PIPE_C:
3739 tmp |= PIPE_C_SCRAMBLE_RESET;
3740 break;
3741 default:
3742 return -EINVAL;
3743 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003744 I915_WRITE(PORT_DFT2_G4X, tmp);
3745 }
3746
Daniel Vetter7ac01292013-10-18 16:37:06 +02003747 return 0;
3748}
3749
David Weinehall36cdd012016-08-22 13:59:31 +03003750static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetter46a19182013-11-01 10:50:20 +01003751 enum pipe pipe,
3752 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003753 uint32_t *val)
3754{
Daniel Vetter84093602013-11-01 10:50:21 +01003755 bool need_stable_symbols = false;
3756
Daniel Vetter46a19182013-11-01 10:50:20 +01003757 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
David Weinehall36cdd012016-08-22 13:59:31 +03003758 int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
Daniel Vetter46a19182013-11-01 10:50:20 +01003759 if (ret)
3760 return ret;
3761 }
3762
3763 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003764 case INTEL_PIPE_CRC_SOURCE_PIPE:
3765 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3766 break;
3767 case INTEL_PIPE_CRC_SOURCE_TV:
David Weinehall36cdd012016-08-22 13:59:31 +03003768 if (!SUPPORTS_TV(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003769 return -EINVAL;
3770 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3771 break;
3772 case INTEL_PIPE_CRC_SOURCE_DP_B:
David Weinehall36cdd012016-08-22 13:59:31 +03003773 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003774 return -EINVAL;
3775 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003776 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003777 break;
3778 case INTEL_PIPE_CRC_SOURCE_DP_C:
David Weinehall36cdd012016-08-22 13:59:31 +03003779 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003780 return -EINVAL;
3781 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003782 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003783 break;
3784 case INTEL_PIPE_CRC_SOURCE_DP_D:
David Weinehall36cdd012016-08-22 13:59:31 +03003785 if (!IS_G4X(dev_priv))
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003786 return -EINVAL;
3787 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003788 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003789 break;
3790 case INTEL_PIPE_CRC_SOURCE_NONE:
3791 *val = 0;
3792 break;
3793 default:
3794 return -EINVAL;
3795 }
3796
Daniel Vetter84093602013-11-01 10:50:21 +01003797 /*
3798 * When the pipe CRC tap point is after the transcoders we need
3799 * to tweak symbol-level features to produce a deterministic series of
3800 * symbols for a given frame. We need to reset those features only once
3801 * a frame (instead of every nth symbol):
3802 * - DC-balance: used to ensure a better clock recovery from the data
3803 * link (SDVO)
3804 * - DisplayPort scrambling: used for EMI reduction
3805 */
3806 if (need_stable_symbols) {
3807 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3808
David Weinehall36cdd012016-08-22 13:59:31 +03003809 WARN_ON(!IS_G4X(dev_priv));
Daniel Vetter84093602013-11-01 10:50:21 +01003810
3811 I915_WRITE(PORT_DFT_I9XX,
3812 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3813
3814 if (pipe == PIPE_A)
3815 tmp |= PIPE_A_SCRAMBLE_RESET;
3816 else
3817 tmp |= PIPE_B_SCRAMBLE_RESET;
3818
3819 I915_WRITE(PORT_DFT2_G4X, tmp);
3820 }
3821
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003822 return 0;
3823}
3824
David Weinehall36cdd012016-08-22 13:59:31 +03003825static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003826 enum pipe pipe)
3827{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003828 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3829
Ville Syrjäläeb736672014-12-09 21:28:28 +02003830 switch (pipe) {
3831 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003832 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003833 break;
3834 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003835 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003836 break;
3837 case PIPE_C:
3838 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3839 break;
3840 default:
3841 return;
3842 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003843 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3844 tmp &= ~DC_BALANCE_RESET_VLV;
3845 I915_WRITE(PORT_DFT2_G4X, tmp);
3846
3847}
3848
David Weinehall36cdd012016-08-22 13:59:31 +03003849static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
Daniel Vetter84093602013-11-01 10:50:21 +01003850 enum pipe pipe)
3851{
Daniel Vetter84093602013-11-01 10:50:21 +01003852 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3853
3854 if (pipe == PIPE_A)
3855 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3856 else
3857 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3858 I915_WRITE(PORT_DFT2_G4X, tmp);
3859
3860 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3861 I915_WRITE(PORT_DFT_I9XX,
3862 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3863 }
3864}
3865
Daniel Vetter46a19182013-11-01 10:50:20 +01003866static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003867 uint32_t *val)
3868{
Daniel Vetter46a19182013-11-01 10:50:20 +01003869 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3870 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3871
3872 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003873 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3874 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3875 break;
3876 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3877 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3878 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003879 case INTEL_PIPE_CRC_SOURCE_PIPE:
3880 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3881 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003882 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003883 *val = 0;
3884 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003885 default:
3886 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003887 }
3888
3889 return 0;
3890}
3891
David Weinehall36cdd012016-08-22 13:59:31 +03003892static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
3893 bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003894{
David Weinehall36cdd012016-08-22 13:59:31 +03003895 struct drm_device *dev = &dev_priv->drm;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003896 struct intel_crtc *crtc =
3897 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003898 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003899 struct drm_atomic_state *state;
3900 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003901
3902 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003903 state = drm_atomic_state_alloc(dev);
3904 if (!state) {
3905 ret = -ENOMEM;
3906 goto out;
3907 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003908
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003909 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3910 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3911 if (IS_ERR(pipe_config)) {
3912 ret = PTR_ERR(pipe_config);
3913 goto out;
3914 }
3915
3916 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003917 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003918 pipe_config->pch_pfit.enabled != enable)
3919 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003920
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003921 ret = drm_atomic_commit(state);
3922out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003923 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003924 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3925 if (ret)
3926 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003927}
3928
David Weinehall36cdd012016-08-22 13:59:31 +03003929static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003930 enum pipe pipe,
3931 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003932 uint32_t *val)
3933{
Daniel Vetter46a19182013-11-01 10:50:20 +01003934 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3935 *source = INTEL_PIPE_CRC_SOURCE_PF;
3936
3937 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003938 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3939 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3940 break;
3941 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3942 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3943 break;
3944 case INTEL_PIPE_CRC_SOURCE_PF:
David Weinehall36cdd012016-08-22 13:59:31 +03003945 if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
3946 hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003947
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003948 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3949 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003950 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003951 *val = 0;
3952 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003953 default:
3954 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003955 }
3956
3957 return 0;
3958}
3959
David Weinehall36cdd012016-08-22 13:59:31 +03003960static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
3961 enum pipe pipe,
Daniel Vetter926321d2013-10-16 13:30:34 +02003962 enum intel_pipe_crc_source source)
3963{
David Weinehall36cdd012016-08-22 13:59:31 +03003964 struct drm_device *dev = &dev_priv->drm;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003965 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
David Weinehall36cdd012016-08-22 13:59:31 +03003966 struct intel_crtc *crtc =
3967 to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
Imre Deake1296492016-02-12 18:55:17 +02003968 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01003969 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003970 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003971
Damien Lespiaucc3da172013-10-15 18:55:31 +01003972 if (pipe_crc->source == source)
3973 return 0;
3974
Damien Lespiauae676fc2013-10-15 18:55:32 +01003975 /* forbid changing the source without going back to 'none' */
3976 if (pipe_crc->source && source)
3977 return -EINVAL;
3978
Imre Deake1296492016-02-12 18:55:17 +02003979 power_domain = POWER_DOMAIN_PIPE(pipe);
3980 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003981 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3982 return -EIO;
3983 }
3984
David Weinehall36cdd012016-08-22 13:59:31 +03003985 if (IS_GEN2(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01003986 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
David Weinehall36cdd012016-08-22 13:59:31 +03003987 else if (INTEL_GEN(dev_priv) < 5)
3988 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
3989 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3990 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
3991 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
Daniel Vetter46a19182013-11-01 10:50:20 +01003992 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003993 else
David Weinehall36cdd012016-08-22 13:59:31 +03003994 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003995
3996 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02003997 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003998
Damien Lespiau4b584362013-10-15 18:55:33 +01003999 /* none -> real source transition */
4000 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004001 struct intel_pipe_crc_entry *entries;
4002
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004003 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4004 pipe_name(pipe), pipe_crc_source_name(source));
4005
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004006 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4007 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004008 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004009 if (!entries) {
4010 ret = -ENOMEM;
4011 goto out;
4012 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004013
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004014 /*
4015 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4016 * enabled and disabled dynamically based on package C states,
4017 * user space can't make reliable use of the CRCs, so let's just
4018 * completely disable it.
4019 */
4020 hsw_disable_ips(crtc);
4021
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004022 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004023 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004024 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004025 pipe_crc->head = 0;
4026 pipe_crc->tail = 0;
4027 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004028 }
4029
Damien Lespiaucc3da172013-10-15 18:55:31 +01004030 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004031
Daniel Vetter926321d2013-10-16 13:30:34 +02004032 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4033 POSTING_READ(PIPE_CRC_CTL(pipe));
4034
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004035 /* real source -> none transition */
4036 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004037 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004038 struct intel_crtc *crtc =
4039 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004040
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004041 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4042 pipe_name(pipe));
4043
Daniel Vettera33d7102014-06-06 08:22:08 +02004044 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004045 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004046 intel_wait_for_vblank(dev, pipe);
4047 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004048
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004049 spin_lock_irq(&pipe_crc->lock);
4050 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004051 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004052 pipe_crc->head = 0;
4053 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004054 spin_unlock_irq(&pipe_crc->lock);
4055
4056 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004057
David Weinehall36cdd012016-08-22 13:59:31 +03004058 if (IS_G4X(dev_priv))
4059 g4x_undo_pipe_scramble_reset(dev_priv, pipe);
4060 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4061 vlv_undo_pipe_scramble_reset(dev_priv, pipe);
4062 else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
4063 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004064
4065 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004066 }
4067
Imre Deake1296492016-02-12 18:55:17 +02004068 ret = 0;
4069
4070out:
4071 intel_display_power_put(dev_priv, power_domain);
4072
4073 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004074}
4075
4076/*
4077 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004078 * command: wsp* object wsp+ name wsp+ source wsp*
4079 * object: 'pipe'
4080 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004081 * source: (none | plane1 | plane2 | pf)
4082 * wsp: (#0x20 | #0x9 | #0xA)+
4083 *
4084 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004085 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4086 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004087 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004088static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004089{
4090 int n_words = 0;
4091
4092 while (*buf) {
4093 char *end;
4094
4095 /* skip leading white space */
4096 buf = skip_spaces(buf);
4097 if (!*buf)
4098 break; /* end of buffer */
4099
4100 /* find end of word */
4101 for (end = buf; *end && !isspace(*end); end++)
4102 ;
4103
4104 if (n_words == max_words) {
4105 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4106 max_words);
4107 return -EINVAL; /* ran out of words[] before bytes */
4108 }
4109
4110 if (*end)
4111 *end++ = '\0';
4112 words[n_words++] = buf;
4113 buf = end;
4114 }
4115
4116 return n_words;
4117}
4118
Damien Lespiaub94dec82013-10-15 18:55:35 +01004119enum intel_pipe_crc_object {
4120 PIPE_CRC_OBJECT_PIPE,
4121};
4122
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004123static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004124 "pipe",
4125};
4126
4127static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004128display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004129{
4130 int i;
4131
4132 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4133 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004134 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004135 return 0;
4136 }
4137
4138 return -EINVAL;
4139}
4140
Damien Lespiaubd9db022013-10-15 18:55:36 +01004141static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004142{
4143 const char name = buf[0];
4144
4145 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4146 return -EINVAL;
4147
4148 *pipe = name - 'A';
4149
4150 return 0;
4151}
4152
4153static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004154display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004155{
4156 int i;
4157
4158 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4159 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004160 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004161 return 0;
4162 }
4163
4164 return -EINVAL;
4165}
4166
David Weinehall36cdd012016-08-22 13:59:31 +03004167static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
4168 char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004169{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004170#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004171 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004172 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004173 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004174 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004175 enum intel_pipe_crc_source source;
4176
Damien Lespiaubd9db022013-10-15 18:55:36 +01004177 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004178 if (n_words != N_WORDS) {
4179 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4180 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004181 return -EINVAL;
4182 }
4183
Damien Lespiaubd9db022013-10-15 18:55:36 +01004184 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004185 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004186 return -EINVAL;
4187 }
4188
Damien Lespiaubd9db022013-10-15 18:55:36 +01004189 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004190 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4191 return -EINVAL;
4192 }
4193
Damien Lespiaubd9db022013-10-15 18:55:36 +01004194 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004195 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004196 return -EINVAL;
4197 }
4198
David Weinehall36cdd012016-08-22 13:59:31 +03004199 return pipe_crc_set_source(dev_priv, pipe, source);
Daniel Vetter926321d2013-10-16 13:30:34 +02004200}
4201
Damien Lespiaubd9db022013-10-15 18:55:36 +01004202static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4203 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004204{
4205 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004206 struct drm_i915_private *dev_priv = m->private;
Daniel Vetter926321d2013-10-16 13:30:34 +02004207 char *tmpbuf;
4208 int ret;
4209
4210 if (len == 0)
4211 return 0;
4212
4213 if (len > PAGE_SIZE - 1) {
4214 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4215 PAGE_SIZE);
4216 return -E2BIG;
4217 }
4218
4219 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4220 if (!tmpbuf)
4221 return -ENOMEM;
4222
4223 if (copy_from_user(tmpbuf, ubuf, len)) {
4224 ret = -EFAULT;
4225 goto out;
4226 }
4227 tmpbuf[len] = '\0';
4228
David Weinehall36cdd012016-08-22 13:59:31 +03004229 ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004230
4231out:
4232 kfree(tmpbuf);
4233 if (ret < 0)
4234 return ret;
4235
4236 *offp += len;
4237 return len;
4238}
4239
Damien Lespiaubd9db022013-10-15 18:55:36 +01004240static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004241 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004242 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004243 .read = seq_read,
4244 .llseek = seq_lseek,
4245 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004246 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004247};
4248
Todd Previteeb3394fa2015-04-18 00:04:19 -07004249static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03004250 const char __user *ubuf,
4251 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004252{
4253 char *input_buffer;
4254 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004255 struct drm_device *dev;
4256 struct drm_connector *connector;
4257 struct list_head *connector_list;
4258 struct intel_dp *intel_dp;
4259 int val = 0;
4260
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304261 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004262
Todd Previteeb3394fa2015-04-18 00:04:19 -07004263 connector_list = &dev->mode_config.connector_list;
4264
4265 if (len == 0)
4266 return 0;
4267
4268 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4269 if (!input_buffer)
4270 return -ENOMEM;
4271
4272 if (copy_from_user(input_buffer, ubuf, len)) {
4273 status = -EFAULT;
4274 goto out;
4275 }
4276
4277 input_buffer[len] = '\0';
4278 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4279
4280 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004281 if (connector->connector_type !=
4282 DRM_MODE_CONNECTOR_DisplayPort)
4283 continue;
4284
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304285 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004286 connector->encoder != NULL) {
4287 intel_dp = enc_to_intel_dp(connector->encoder);
4288 status = kstrtoint(input_buffer, 10, &val);
4289 if (status < 0)
4290 goto out;
4291 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4292 /* To prevent erroneous activation of the compliance
4293 * testing code, only accept an actual value of 1 here
4294 */
4295 if (val == 1)
4296 intel_dp->compliance_test_active = 1;
4297 else
4298 intel_dp->compliance_test_active = 0;
4299 }
4300 }
4301out:
4302 kfree(input_buffer);
4303 if (status < 0)
4304 return status;
4305
4306 *offp += len;
4307 return len;
4308}
4309
4310static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4311{
4312 struct drm_device *dev = m->private;
4313 struct drm_connector *connector;
4314 struct list_head *connector_list = &dev->mode_config.connector_list;
4315 struct intel_dp *intel_dp;
4316
Todd Previteeb3394fa2015-04-18 00:04:19 -07004317 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004318 if (connector->connector_type !=
4319 DRM_MODE_CONNECTOR_DisplayPort)
4320 continue;
4321
4322 if (connector->status == connector_status_connected &&
4323 connector->encoder != NULL) {
4324 intel_dp = enc_to_intel_dp(connector->encoder);
4325 if (intel_dp->compliance_test_active)
4326 seq_puts(m, "1");
4327 else
4328 seq_puts(m, "0");
4329 } else
4330 seq_puts(m, "0");
4331 }
4332
4333 return 0;
4334}
4335
4336static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004337 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004338{
David Weinehall36cdd012016-08-22 13:59:31 +03004339 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004340
David Weinehall36cdd012016-08-22 13:59:31 +03004341 return single_open(file, i915_displayport_test_active_show,
4342 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004343}
4344
4345static const struct file_operations i915_displayport_test_active_fops = {
4346 .owner = THIS_MODULE,
4347 .open = i915_displayport_test_active_open,
4348 .read = seq_read,
4349 .llseek = seq_lseek,
4350 .release = single_release,
4351 .write = i915_displayport_test_active_write
4352};
4353
4354static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4355{
4356 struct drm_device *dev = m->private;
4357 struct drm_connector *connector;
4358 struct list_head *connector_list = &dev->mode_config.connector_list;
4359 struct intel_dp *intel_dp;
4360
Todd Previteeb3394fa2015-04-18 00:04:19 -07004361 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004362 if (connector->connector_type !=
4363 DRM_MODE_CONNECTOR_DisplayPort)
4364 continue;
4365
4366 if (connector->status == connector_status_connected &&
4367 connector->encoder != NULL) {
4368 intel_dp = enc_to_intel_dp(connector->encoder);
4369 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4370 } else
4371 seq_puts(m, "0");
4372 }
4373
4374 return 0;
4375}
4376static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03004377 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07004378{
David Weinehall36cdd012016-08-22 13:59:31 +03004379 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004380
David Weinehall36cdd012016-08-22 13:59:31 +03004381 return single_open(file, i915_displayport_test_data_show,
4382 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004383}
4384
4385static const struct file_operations i915_displayport_test_data_fops = {
4386 .owner = THIS_MODULE,
4387 .open = i915_displayport_test_data_open,
4388 .read = seq_read,
4389 .llseek = seq_lseek,
4390 .release = single_release
4391};
4392
4393static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4394{
4395 struct drm_device *dev = m->private;
4396 struct drm_connector *connector;
4397 struct list_head *connector_list = &dev->mode_config.connector_list;
4398 struct intel_dp *intel_dp;
4399
Todd Previteeb3394fa2015-04-18 00:04:19 -07004400 list_for_each_entry(connector, connector_list, head) {
Todd Previteeb3394fa2015-04-18 00:04:19 -07004401 if (connector->connector_type !=
4402 DRM_MODE_CONNECTOR_DisplayPort)
4403 continue;
4404
4405 if (connector->status == connector_status_connected &&
4406 connector->encoder != NULL) {
4407 intel_dp = enc_to_intel_dp(connector->encoder);
4408 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4409 } else
4410 seq_puts(m, "0");
4411 }
4412
4413 return 0;
4414}
4415
4416static int i915_displayport_test_type_open(struct inode *inode,
4417 struct file *file)
4418{
David Weinehall36cdd012016-08-22 13:59:31 +03004419 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004420
David Weinehall36cdd012016-08-22 13:59:31 +03004421 return single_open(file, i915_displayport_test_type_show,
4422 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07004423}
4424
4425static const struct file_operations i915_displayport_test_type_fops = {
4426 .owner = THIS_MODULE,
4427 .open = i915_displayport_test_type_open,
4428 .read = seq_read,
4429 .llseek = seq_lseek,
4430 .release = single_release
4431};
4432
Damien Lespiau97e94b22014-11-04 17:06:50 +00004433static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004434{
David Weinehall36cdd012016-08-22 13:59:31 +03004435 struct drm_i915_private *dev_priv = m->private;
4436 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004437 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004438 int num_levels;
4439
David Weinehall36cdd012016-08-22 13:59:31 +03004440 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004441 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004442 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004443 num_levels = 1;
4444 else
4445 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004446
4447 drm_modeset_lock_all(dev);
4448
4449 for (level = 0; level < num_levels; level++) {
4450 unsigned int latency = wm[level];
4451
Damien Lespiau97e94b22014-11-04 17:06:50 +00004452 /*
4453 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004454 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004455 */
David Weinehall36cdd012016-08-22 13:59:31 +03004456 if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
4457 IS_CHERRYVIEW(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004458 latency *= 10;
4459 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004460 latency *= 5;
4461
4462 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004463 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004464 }
4465
4466 drm_modeset_unlock_all(dev);
4467}
4468
4469static int pri_wm_latency_show(struct seq_file *m, void *data)
4470{
David Weinehall36cdd012016-08-22 13:59:31 +03004471 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004472 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004473
David Weinehall36cdd012016-08-22 13:59:31 +03004474 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004475 latencies = dev_priv->wm.skl_latency;
4476 else
David Weinehall36cdd012016-08-22 13:59:31 +03004477 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004478
4479 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004480
4481 return 0;
4482}
4483
4484static int spr_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.spr_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 cur_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.cur_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 pri_wm_latency_open(struct inode *inode, struct file *file)
4515{
David Weinehall36cdd012016-08-22 13:59:31 +03004516 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004517
David Weinehall36cdd012016-08-22 13:59:31 +03004518 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004519 return -ENODEV;
4520
David Weinehall36cdd012016-08-22 13:59:31 +03004521 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004522}
4523
4524static int spr_wm_latency_open(struct inode *inode, struct file *file)
4525{
David Weinehall36cdd012016-08-22 13:59:31 +03004526 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004527
David Weinehall36cdd012016-08-22 13:59:31 +03004528 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004529 return -ENODEV;
4530
David Weinehall36cdd012016-08-22 13:59:31 +03004531 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004532}
4533
4534static int cur_wm_latency_open(struct inode *inode, struct file *file)
4535{
David Weinehall36cdd012016-08-22 13:59:31 +03004536 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004537
David Weinehall36cdd012016-08-22 13:59:31 +03004538 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004539 return -ENODEV;
4540
David Weinehall36cdd012016-08-22 13:59:31 +03004541 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004542}
4543
4544static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004545 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004546{
4547 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004548 struct drm_i915_private *dev_priv = m->private;
4549 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004550 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004551 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004552 int level;
4553 int ret;
4554 char tmp[32];
4555
David Weinehall36cdd012016-08-22 13:59:31 +03004556 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004557 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03004558 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03004559 num_levels = 1;
4560 else
4561 num_levels = ilk_wm_max_level(dev) + 1;
4562
Ville Syrjälä369a1342014-01-22 14:36:08 +02004563 if (len >= sizeof(tmp))
4564 return -EINVAL;
4565
4566 if (copy_from_user(tmp, ubuf, len))
4567 return -EFAULT;
4568
4569 tmp[len] = '\0';
4570
Damien Lespiau97e94b22014-11-04 17:06:50 +00004571 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4572 &new[0], &new[1], &new[2], &new[3],
4573 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004574 if (ret != num_levels)
4575 return -EINVAL;
4576
4577 drm_modeset_lock_all(dev);
4578
4579 for (level = 0; level < num_levels; level++)
4580 wm[level] = new[level];
4581
4582 drm_modeset_unlock_all(dev);
4583
4584 return len;
4585}
4586
4587
4588static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4589 size_t len, loff_t *offp)
4590{
4591 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004592 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004593 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004594
David Weinehall36cdd012016-08-22 13:59:31 +03004595 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004596 latencies = dev_priv->wm.skl_latency;
4597 else
David Weinehall36cdd012016-08-22 13:59:31 +03004598 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004599
4600 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004601}
4602
4603static ssize_t spr_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.spr_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 cur_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.cur_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 const struct file_operations i915_pri_wm_latency_fops = {
4634 .owner = THIS_MODULE,
4635 .open = pri_wm_latency_open,
4636 .read = seq_read,
4637 .llseek = seq_lseek,
4638 .release = single_release,
4639 .write = pri_wm_latency_write
4640};
4641
4642static const struct file_operations i915_spr_wm_latency_fops = {
4643 .owner = THIS_MODULE,
4644 .open = spr_wm_latency_open,
4645 .read = seq_read,
4646 .llseek = seq_lseek,
4647 .release = single_release,
4648 .write = spr_wm_latency_write
4649};
4650
4651static const struct file_operations i915_cur_wm_latency_fops = {
4652 .owner = THIS_MODULE,
4653 .open = cur_wm_latency_open,
4654 .read = seq_read,
4655 .llseek = seq_lseek,
4656 .release = single_release,
4657 .write = cur_wm_latency_write
4658};
4659
Kees Cook647416f2013-03-10 14:10:06 -07004660static int
4661i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004662{
David Weinehall36cdd012016-08-22 13:59:31 +03004663 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004664
Chris Wilsond98c52c2016-04-13 17:35:05 +01004665 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004666
Kees Cook647416f2013-03-10 14:10:06 -07004667 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004668}
4669
Kees Cook647416f2013-03-10 14:10:06 -07004670static int
4671i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004672{
David Weinehall36cdd012016-08-22 13:59:31 +03004673 struct drm_i915_private *dev_priv = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004674
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004675 /*
4676 * There is no safeguard against this debugfs entry colliding
4677 * with the hangcheck calling same i915_handle_error() in
4678 * parallel, causing an explosion. For now we assume that the
4679 * test harness is responsible enough not to inject gpu hangs
4680 * while it is writing to 'i915_wedged'
4681 */
4682
Chris Wilsond98c52c2016-04-13 17:35:05 +01004683 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004684 return -EAGAIN;
4685
Imre Deakd46c0512014-04-14 20:24:27 +03004686 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004687
Chris Wilsonc0336662016-05-06 15:40:21 +01004688 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004689 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004690
4691 intel_runtime_pm_put(dev_priv);
4692
Kees Cook647416f2013-03-10 14:10:06 -07004693 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004694}
4695
Kees Cook647416f2013-03-10 14:10:06 -07004696DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4697 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004698 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004699
Kees Cook647416f2013-03-10 14:10:06 -07004700static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004701i915_ring_missed_irq_get(void *data, u64 *val)
4702{
David Weinehall36cdd012016-08-22 13:59:31 +03004703 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004704
4705 *val = dev_priv->gpu_error.missed_irq_rings;
4706 return 0;
4707}
4708
4709static int
4710i915_ring_missed_irq_set(void *data, u64 val)
4711{
David Weinehall36cdd012016-08-22 13:59:31 +03004712 struct drm_i915_private *dev_priv = data;
4713 struct drm_device *dev = &dev_priv->drm;
Chris Wilson094f9a52013-09-25 17:34:55 +01004714 int ret;
4715
4716 /* Lock against concurrent debugfs callers */
4717 ret = mutex_lock_interruptible(&dev->struct_mutex);
4718 if (ret)
4719 return ret;
4720 dev_priv->gpu_error.missed_irq_rings = val;
4721 mutex_unlock(&dev->struct_mutex);
4722
4723 return 0;
4724}
4725
4726DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4727 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4728 "0x%08llx\n");
4729
4730static int
4731i915_ring_test_irq_get(void *data, u64 *val)
4732{
David Weinehall36cdd012016-08-22 13:59:31 +03004733 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004734
4735 *val = dev_priv->gpu_error.test_irq_rings;
4736
4737 return 0;
4738}
4739
4740static int
4741i915_ring_test_irq_set(void *data, u64 val)
4742{
David Weinehall36cdd012016-08-22 13:59:31 +03004743 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004744
Chris Wilson3a122c22016-06-17 14:35:05 +01004745 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004746 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004747 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004748
4749 return 0;
4750}
4751
4752DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4753 i915_ring_test_irq_get, i915_ring_test_irq_set,
4754 "0x%08llx\n");
4755
Chris Wilsondd624af2013-01-15 12:39:35 +00004756#define DROP_UNBOUND 0x1
4757#define DROP_BOUND 0x2
4758#define DROP_RETIRE 0x4
4759#define DROP_ACTIVE 0x8
4760#define DROP_ALL (DROP_UNBOUND | \
4761 DROP_BOUND | \
4762 DROP_RETIRE | \
4763 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004764static int
4765i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004766{
Kees Cook647416f2013-03-10 14:10:06 -07004767 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004768
Kees Cook647416f2013-03-10 14:10:06 -07004769 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004770}
4771
Kees Cook647416f2013-03-10 14:10:06 -07004772static int
4773i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004774{
David Weinehall36cdd012016-08-22 13:59:31 +03004775 struct drm_i915_private *dev_priv = data;
4776 struct drm_device *dev = &dev_priv->drm;
Kees Cook647416f2013-03-10 14:10:06 -07004777 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004778
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004779 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004780
4781 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4782 * on ioctls on -EAGAIN. */
4783 ret = mutex_lock_interruptible(&dev->struct_mutex);
4784 if (ret)
4785 return ret;
4786
4787 if (val & DROP_ACTIVE) {
Chris Wilsondcff85c2016-08-05 10:14:11 +01004788 ret = i915_gem_wait_for_idle(dev_priv, true);
Chris Wilsondd624af2013-01-15 12:39:35 +00004789 if (ret)
4790 goto unlock;
4791 }
4792
4793 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004794 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004795
Chris Wilson21ab4e72014-09-09 11:16:08 +01004796 if (val & DROP_BOUND)
4797 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004798
Chris Wilson21ab4e72014-09-09 11:16:08 +01004799 if (val & DROP_UNBOUND)
4800 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004801
4802unlock:
4803 mutex_unlock(&dev->struct_mutex);
4804
Kees Cook647416f2013-03-10 14:10:06 -07004805 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004806}
4807
Kees Cook647416f2013-03-10 14:10:06 -07004808DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4809 i915_drop_caches_get, i915_drop_caches_set,
4810 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004811
Kees Cook647416f2013-03-10 14:10:06 -07004812static int
4813i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004814{
David Weinehall36cdd012016-08-22 13:59:31 +03004815 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004816
David Weinehall36cdd012016-08-22 13:59:31 +03004817 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004818 return -ENODEV;
4819
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004820 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004821 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004822}
4823
Kees Cook647416f2013-03-10 14:10:06 -07004824static int
4825i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004826{
David Weinehall36cdd012016-08-22 13:59:31 +03004827 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304828 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004829 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004830
David Weinehall36cdd012016-08-22 13:59:31 +03004831 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004832 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004833
Kees Cook647416f2013-03-10 14:10:06 -07004834 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004835
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004836 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004837 if (ret)
4838 return ret;
4839
Jesse Barnes358733e2011-07-27 11:53:01 -07004840 /*
4841 * Turbo will still be enabled, but won't go above the set value.
4842 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304843 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004844
Akash Goelbc4d91f2015-02-26 16:09:47 +05304845 hw_max = dev_priv->rps.max_freq;
4846 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004847
Ben Widawskyb39fb292014-03-19 18:31:11 -07004848 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004849 mutex_unlock(&dev_priv->rps.hw_lock);
4850 return -EINVAL;
4851 }
4852
Ben Widawskyb39fb292014-03-19 18:31:11 -07004853 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004854
Chris Wilsondc979972016-05-10 14:10:04 +01004855 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004856
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004857 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004858
Kees Cook647416f2013-03-10 14:10:06 -07004859 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004860}
4861
Kees Cook647416f2013-03-10 14:10:06 -07004862DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4863 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004864 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004865
Kees Cook647416f2013-03-10 14:10:06 -07004866static int
4867i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004868{
David Weinehall36cdd012016-08-22 13:59:31 +03004869 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004870
Chris Wilson62e1baa2016-07-13 09:10:36 +01004871 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004872 return -ENODEV;
4873
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004874 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004875 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004876}
4877
Kees Cook647416f2013-03-10 14:10:06 -07004878static int
4879i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004880{
David Weinehall36cdd012016-08-22 13:59:31 +03004881 struct drm_i915_private *dev_priv = data;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304882 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004883 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004884
Chris Wilson62e1baa2016-07-13 09:10:36 +01004885 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004886 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004887
Kees Cook647416f2013-03-10 14:10:06 -07004888 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004889
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004890 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004891 if (ret)
4892 return ret;
4893
Jesse Barnes1523c312012-05-25 12:34:54 -07004894 /*
4895 * Turbo will still be enabled, but won't go below the set value.
4896 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304897 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004898
Akash Goelbc4d91f2015-02-26 16:09:47 +05304899 hw_max = dev_priv->rps.max_freq;
4900 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004901
David Weinehall36cdd012016-08-22 13:59:31 +03004902 if (val < hw_min ||
4903 val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004904 mutex_unlock(&dev_priv->rps.hw_lock);
4905 return -EINVAL;
4906 }
4907
Ben Widawskyb39fb292014-03-19 18:31:11 -07004908 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004909
Chris Wilsondc979972016-05-10 14:10:04 +01004910 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004911
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004912 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004913
Kees Cook647416f2013-03-10 14:10:06 -07004914 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004915}
4916
Kees Cook647416f2013-03-10 14:10:06 -07004917DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4918 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004919 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004920
Kees Cook647416f2013-03-10 14:10:06 -07004921static int
4922i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004923{
David Weinehall36cdd012016-08-22 13:59:31 +03004924 struct drm_i915_private *dev_priv = data;
4925 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004926 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004927 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004928
David Weinehall36cdd012016-08-22 13:59:31 +03004929 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004930 return -ENODEV;
4931
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004932 ret = mutex_lock_interruptible(&dev->struct_mutex);
4933 if (ret)
4934 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004935 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004936
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004937 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004938
4939 intel_runtime_pm_put(dev_priv);
David Weinehall36cdd012016-08-22 13:59:31 +03004940 mutex_unlock(&dev->struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004941
Kees Cook647416f2013-03-10 14:10:06 -07004942 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004943
Kees Cook647416f2013-03-10 14:10:06 -07004944 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004945}
4946
Kees Cook647416f2013-03-10 14:10:06 -07004947static int
4948i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004949{
David Weinehall36cdd012016-08-22 13:59:31 +03004950 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004951 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004952
David Weinehall36cdd012016-08-22 13:59:31 +03004953 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004954 return -ENODEV;
4955
Kees Cook647416f2013-03-10 14:10:06 -07004956 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004957 return -EINVAL;
4958
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004959 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004960 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004961
4962 /* Update the cache sharing policy here as well */
4963 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4964 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4965 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4966 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4967
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004968 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004969 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004970}
4971
Kees Cook647416f2013-03-10 14:10:06 -07004972DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4973 i915_cache_sharing_get, i915_cache_sharing_set,
4974 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004975
David Weinehall36cdd012016-08-22 13:59:31 +03004976static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004977 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004978{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004979 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004980 int ss;
4981 u32 sig1[ss_max], sig2[ss_max];
4982
4983 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4984 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4985 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4986 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4987
4988 for (ss = 0; ss < ss_max; ss++) {
4989 unsigned int eu_cnt;
4990
4991 if (sig1[ss] & CHV_SS_PG_ENABLE)
4992 /* skip disabled subslice */
4993 continue;
4994
Imre Deakf08a0c92016-08-31 19:13:04 +03004995 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004996 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004997 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4998 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4999 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5000 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03005001 sseu->eu_total += eu_cnt;
5002 sseu->eu_per_subslice = max_t(unsigned int,
5003 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005004 }
Jeff McGee5d395252015-04-03 18:13:17 -07005005}
5006
David Weinehall36cdd012016-08-22 13:59:31 +03005007static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005008 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07005009{
Jeff McGee1c046bc2015-04-03 18:13:18 -07005010 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005011 int s, ss;
5012 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5013
Jeff McGee1c046bc2015-04-03 18:13:18 -07005014 /* BXT has a single slice and at most 3 subslices. */
David Weinehall36cdd012016-08-22 13:59:31 +03005015 if (IS_BROXTON(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005016 s_max = 1;
5017 ss_max = 3;
5018 }
5019
5020 for (s = 0; s < s_max; s++) {
5021 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5022 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5023 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5024 }
5025
Jeff McGee5d395252015-04-03 18:13:17 -07005026 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5027 GEN9_PGCTL_SSA_EU19_ACK |
5028 GEN9_PGCTL_SSA_EU210_ACK |
5029 GEN9_PGCTL_SSA_EU311_ACK;
5030 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5031 GEN9_PGCTL_SSB_EU19_ACK |
5032 GEN9_PGCTL_SSB_EU210_ACK |
5033 GEN9_PGCTL_SSB_EU311_ACK;
5034
5035 for (s = 0; s < s_max; s++) {
5036 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5037 /* skip disabled slice */
5038 continue;
5039
Imre Deakf08a0c92016-08-31 19:13:04 +03005040 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005041
David Weinehall36cdd012016-08-22 13:59:31 +03005042 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03005043 sseu->subslice_mask =
5044 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005045
Jeff McGee5d395252015-04-03 18:13:17 -07005046 for (ss = 0; ss < ss_max; ss++) {
5047 unsigned int eu_cnt;
5048
Imre Deak57ec1712016-08-31 19:13:05 +03005049 if (IS_BROXTON(dev_priv)) {
5050 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5051 /* skip disabled subslice */
5052 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005053
Imre Deak57ec1712016-08-31 19:13:05 +03005054 sseu->subslice_mask |= BIT(ss);
5055 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005056
Jeff McGee5d395252015-04-03 18:13:17 -07005057 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5058 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03005059 sseu->eu_total += eu_cnt;
5060 sseu->eu_per_subslice = max_t(unsigned int,
5061 sseu->eu_per_subslice,
5062 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005063 }
5064 }
5065}
5066
David Weinehall36cdd012016-08-22 13:59:31 +03005067static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03005068 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005069{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005070 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03005071 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005072
Imre Deakf08a0c92016-08-31 19:13:04 +03005073 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005074
Imre Deakf08a0c92016-08-31 19:13:04 +03005075 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03005076 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03005077 sseu->eu_per_subslice =
5078 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03005079 sseu->eu_total = sseu->eu_per_subslice *
5080 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005081
5082 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03005083 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03005084 u8 subslice_7eu =
5085 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005086
Imre Deak915490d2016-08-31 19:13:01 +03005087 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005088 }
5089 }
5090}
5091
Imre Deak615d8902016-08-31 19:13:03 +03005092static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
5093 const struct sseu_dev_info *sseu)
5094{
5095 struct drm_i915_private *dev_priv = node_to_i915(m->private);
5096 const char *type = is_available_info ? "Available" : "Enabled";
5097
Imre Deakc67ba532016-08-31 19:13:06 +03005098 seq_printf(m, " %s Slice Mask: %04x\n", type,
5099 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005100 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03005101 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005102 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005103 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03005104 seq_printf(m, " %s Subslice Mask: %04x\n", type,
5105 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03005106 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03005107 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03005108 seq_printf(m, " %s EU Total: %u\n", type,
5109 sseu->eu_total);
5110 seq_printf(m, " %s EU Per Subslice: %u\n", type,
5111 sseu->eu_per_subslice);
5112
5113 if (!is_available_info)
5114 return;
5115
5116 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
5117 if (HAS_POOLED_EU(dev_priv))
5118 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
5119
5120 seq_printf(m, " Has Slice Power Gating: %s\n",
5121 yesno(sseu->has_slice_pg));
5122 seq_printf(m, " Has Subslice Power Gating: %s\n",
5123 yesno(sseu->has_subslice_pg));
5124 seq_printf(m, " Has EU Power Gating: %s\n",
5125 yesno(sseu->has_eu_pg));
5126}
5127
Jeff McGee38732182015-02-13 10:27:54 -06005128static int i915_sseu_status(struct seq_file *m, void *unused)
5129{
David Weinehall36cdd012016-08-22 13:59:31 +03005130 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03005131 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06005132
David Weinehall36cdd012016-08-22 13:59:31 +03005133 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005134 return -ENODEV;
5135
5136 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03005137 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06005138
Jeff McGee7f992ab2015-02-13 10:27:55 -06005139 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03005140 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03005141
5142 intel_runtime_pm_get(dev_priv);
5143
David Weinehall36cdd012016-08-22 13:59:31 +03005144 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005145 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005146 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03005147 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03005148 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03005149 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005150 }
David Weinehall238010e2016-08-01 17:33:27 +03005151
5152 intel_runtime_pm_put(dev_priv);
5153
Imre Deak615d8902016-08-31 19:13:03 +03005154 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005155
Jeff McGee38732182015-02-13 10:27:54 -06005156 return 0;
5157}
5158
Ben Widawsky6d794d42011-04-25 11:25:56 -07005159static int i915_forcewake_open(struct inode *inode, struct file *file)
5160{
David Weinehall36cdd012016-08-22 13:59:31 +03005161 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005162
David Weinehall36cdd012016-08-22 13:59:31 +03005163 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005164 return 0;
5165
Chris Wilson6daccb02015-01-16 11:34:35 +02005166 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005167 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005168
5169 return 0;
5170}
5171
Ben Widawskyc43b5632012-04-16 14:07:40 -07005172static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005173{
David Weinehall36cdd012016-08-22 13:59:31 +03005174 struct drm_i915_private *dev_priv = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005175
David Weinehall36cdd012016-08-22 13:59:31 +03005176 if (INTEL_GEN(dev_priv) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005177 return 0;
5178
Mika Kuoppala59bad942015-01-16 11:34:40 +02005179 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005180 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005181
5182 return 0;
5183}
5184
5185static const struct file_operations i915_forcewake_fops = {
5186 .owner = THIS_MODULE,
5187 .open = i915_forcewake_open,
5188 .release = i915_forcewake_release,
5189};
5190
5191static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5192{
Ben Widawsky6d794d42011-04-25 11:25:56 -07005193 struct dentry *ent;
5194
5195 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005196 S_IRUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005197 root, to_i915(minor->dev),
Ben Widawsky6d794d42011-04-25 11:25:56 -07005198 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005199 if (!ent)
5200 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005201
Ben Widawsky8eb57292011-05-11 15:10:58 -07005202 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005203}
5204
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005205static int i915_debugfs_create(struct dentry *root,
5206 struct drm_minor *minor,
5207 const char *name,
5208 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005209{
Jesse Barnes358733e2011-07-27 11:53:01 -07005210 struct dentry *ent;
5211
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005212 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005213 S_IRUGO | S_IWUSR,
David Weinehall36cdd012016-08-22 13:59:31 +03005214 root, to_i915(minor->dev),
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005215 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005216 if (!ent)
5217 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005218
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005219 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005220}
5221
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005222static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005223 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005224 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005225 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6da84822016-08-15 10:48:44 +01005226 {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
Chris Wilson6d2b8882013-08-07 18:30:54 +01005227 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005228 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005229 {"i915_gem_request", i915_gem_request_info, 0},
5230 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005231 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005232 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005233 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5234 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5235 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005236 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005237 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005238 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005239 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005240 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305241 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf654449a2015-01-26 18:03:04 +02005242 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005243 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005244 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005245 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005246 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005247 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005248 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005249 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005250 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005251 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005252 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005253 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005254 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005255 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005256 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005257 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005258 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005259 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005260 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005261 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005262 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005263 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005264 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005265 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005266 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005267 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005268 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed9582014-05-12 15:22:27 +10005269 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005270 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005271 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005272 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305273 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005274 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005275};
Ben Gamari27c202a2009-07-01 22:26:52 -04005276#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005277
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005278static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005279 const char *name;
5280 const struct file_operations *fops;
5281} i915_debugfs_files[] = {
5282 {"i915_wedged", &i915_wedged_fops},
5283 {"i915_max_freq", &i915_max_freq_fops},
5284 {"i915_min_freq", &i915_min_freq_fops},
5285 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005286 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5287 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005288 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5289 {"i915_error_state", &i915_error_state_fops},
5290 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005291 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005292 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5293 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5294 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005295 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005296 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5297 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5298 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005299};
5300
David Weinehall36cdd012016-08-22 13:59:31 +03005301void intel_display_crc_init(struct drm_i915_private *dev_priv)
Damien Lespiau07144422013-10-15 18:55:40 +01005302{
Daniel Vetterb3783602013-11-14 11:30:42 +01005303 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005304
Damien Lespiau055e3932014-08-18 13:49:10 +01005305 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005306 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005307
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005308 pipe_crc->opened = false;
5309 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005310 init_waitqueue_head(&pipe_crc->wq);
5311 }
5312}
5313
Chris Wilson1dac8912016-06-24 14:00:17 +01005314int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005315{
Chris Wilson91c8a322016-07-05 10:40:23 +01005316 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005317 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005318
Ben Widawsky6d794d42011-04-25 11:25:56 -07005319 ret = i915_forcewake_create(minor->debugfs_root, minor);
5320 if (ret)
5321 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005322
Damien Lespiau07144422013-10-15 18:55:40 +01005323 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5324 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5325 if (ret)
5326 return ret;
5327 }
5328
Daniel Vetter34b96742013-07-04 20:49:44 +02005329 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5330 ret = i915_debugfs_create(minor->debugfs_root, minor,
5331 i915_debugfs_files[i].name,
5332 i915_debugfs_files[i].fops);
5333 if (ret)
5334 return ret;
5335 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005336
Ben Gamari27c202a2009-07-01 22:26:52 -04005337 return drm_debugfs_create_files(i915_debugfs_list,
5338 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005339 minor->debugfs_root, minor);
5340}
5341
Chris Wilson1dac8912016-06-24 14:00:17 +01005342void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005343{
Chris Wilson91c8a322016-07-05 10:40:23 +01005344 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005345 int i;
5346
Ben Gamari27c202a2009-07-01 22:26:52 -04005347 drm_debugfs_remove_files(i915_debugfs_list,
5348 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005349
David Weinehall36cdd012016-08-22 13:59:31 +03005350 drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005351 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005352
Daniel Vettere309a992013-10-16 22:55:51 +02005353 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005354 struct drm_info_list *info_list =
5355 (struct drm_info_list *)&i915_pipe_crc_data[i];
5356
5357 drm_debugfs_remove_files(info_list, 1, minor);
5358 }
5359
Daniel Vetter34b96742013-07-04 20:49:44 +02005360 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5361 struct drm_info_list *info_list =
David Weinehall36cdd012016-08-22 13:59:31 +03005362 (struct drm_info_list *)i915_debugfs_files[i].fops;
Daniel Vetter34b96742013-07-04 20:49:44 +02005363
5364 drm_debugfs_remove_files(info_list, 1, minor);
5365 }
Ben Gamari20172632009-02-17 20:08:50 -05005366}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005367
5368struct dpcd_block {
5369 /* DPCD dump start address. */
5370 unsigned int offset;
5371 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5372 unsigned int end;
5373 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5374 size_t size;
5375 /* Only valid for eDP. */
5376 bool edp;
5377};
5378
5379static const struct dpcd_block i915_dpcd_debug[] = {
5380 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5381 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5382 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5383 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5384 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5385 { .offset = DP_SET_POWER },
5386 { .offset = DP_EDP_DPCD_REV },
5387 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5388 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5389 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5390};
5391
5392static int i915_dpcd_show(struct seq_file *m, void *data)
5393{
5394 struct drm_connector *connector = m->private;
5395 struct intel_dp *intel_dp =
5396 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5397 uint8_t buf[16];
5398 ssize_t err;
5399 int i;
5400
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005401 if (connector->status != connector_status_connected)
5402 return -ENODEV;
5403
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005404 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5405 const struct dpcd_block *b = &i915_dpcd_debug[i];
5406 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5407
5408 if (b->edp &&
5409 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5410 continue;
5411
5412 /* low tech for now */
5413 if (WARN_ON(size > sizeof(buf)))
5414 continue;
5415
5416 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5417 if (err <= 0) {
5418 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5419 size, b->offset, err);
5420 continue;
5421 }
5422
5423 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005424 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005425
5426 return 0;
5427}
5428
5429static int i915_dpcd_open(struct inode *inode, struct file *file)
5430{
5431 return single_open(file, i915_dpcd_show, inode->i_private);
5432}
5433
5434static const struct file_operations i915_dpcd_fops = {
5435 .owner = THIS_MODULE,
5436 .open = i915_dpcd_open,
5437 .read = seq_read,
5438 .llseek = seq_lseek,
5439 .release = single_release,
5440};
5441
David Weinehallecbd6782016-08-23 12:23:56 +03005442static int i915_panel_show(struct seq_file *m, void *data)
5443{
5444 struct drm_connector *connector = m->private;
5445 struct intel_dp *intel_dp =
5446 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5447
5448 if (connector->status != connector_status_connected)
5449 return -ENODEV;
5450
5451 seq_printf(m, "Panel power up delay: %d\n",
5452 intel_dp->panel_power_up_delay);
5453 seq_printf(m, "Panel power down delay: %d\n",
5454 intel_dp->panel_power_down_delay);
5455 seq_printf(m, "Backlight on delay: %d\n",
5456 intel_dp->backlight_on_delay);
5457 seq_printf(m, "Backlight off delay: %d\n",
5458 intel_dp->backlight_off_delay);
5459
5460 return 0;
5461}
5462
5463static int i915_panel_open(struct inode *inode, struct file *file)
5464{
5465 return single_open(file, i915_panel_show, inode->i_private);
5466}
5467
5468static const struct file_operations i915_panel_fops = {
5469 .owner = THIS_MODULE,
5470 .open = i915_panel_open,
5471 .read = seq_read,
5472 .llseek = seq_lseek,
5473 .release = single_release,
5474};
5475
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005476/**
5477 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5478 * @connector: pointer to a registered drm_connector
5479 *
5480 * Cleanup will be done by drm_connector_unregister() through a call to
5481 * drm_debugfs_connector_remove().
5482 *
5483 * Returns 0 on success, negative error codes on error.
5484 */
5485int i915_debugfs_connector_add(struct drm_connector *connector)
5486{
5487 struct dentry *root = connector->debugfs_entry;
5488
5489 /* The connector must have been registered beforehands. */
5490 if (!root)
5491 return -ENODEV;
5492
5493 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5494 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03005495 debugfs_create_file("i915_dpcd", S_IRUGO, root,
5496 connector, &i915_dpcd_fops);
5497
5498 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5499 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
5500 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005501
5502 return 0;
5503}