blob: 8d47d1bf7b8533841ed8c776d22098dfd8faa042 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Damien Lespiau497666d2013-10-15 18:55:39 +010049/* As the drm_debugfs_init() routines are called before dev->dev_private is
50 * allocated we need to hook into the minor for release. */
51static int
52drm_add_fake_info_node(struct drm_minor *minor,
53 struct dentry *ent,
54 const void *key)
55{
56 struct drm_info_node *node;
57
58 node = kmalloc(sizeof(*node), GFP_KERNEL);
59 if (node == NULL) {
60 debugfs_remove(ent);
61 return -ENOMEM;
62 }
63
64 node->minor = minor;
65 node->dent = ent;
66 node->info_ent = (void *) key;
67
68 mutex_lock(&minor->debugfs_lock);
69 list_add(&node->list, &minor->debugfs_list);
70 mutex_unlock(&minor->debugfs_lock);
71
72 return 0;
73}
74
Chris Wilson70d39fe2010-08-25 16:03:34 +010075static int i915_capabilities(struct seq_file *m, void *data)
76{
Damien Lespiau9f25d002014-05-13 15:30:28 +010077 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010078 struct drm_device *dev = node->minor->dev;
79 const struct intel_device_info *info = INTEL_INFO(dev);
80
81 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030082 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010083#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
84#define SEP_SEMICOLON ;
85 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
86#undef PRINT_FLAG
87#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010088
89 return 0;
90}
Ben Gamari433e12f2009-02-17 20:08:51 -050091
Imre Deaka7363de2016-05-12 16:18:52 +030092static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000093{
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010094 return obj->active ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000095}
96
Imre Deaka7363de2016-05-12 16:18:52 +030097static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010098{
99 return obj->pin_display ? 'p' : ' ';
100}
101
Imre Deaka7363de2016-05-12 16:18:52 +0300102static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000103{
Akshay Joshi0206e352011-08-16 15:34:10 -0400104 switch (obj->tiling_mode) {
105 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100106 case I915_TILING_NONE: return ' ';
107 case I915_TILING_X: return 'X';
108 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400109 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000110}
111
Imre Deaka7363de2016-05-12 16:18:52 +0300112static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700113{
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100114 return i915_gem_obj_to_ggtt(obj) ? 'g' : ' ';
115}
116
Imre Deaka7363de2016-05-12 16:18:52 +0300117static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100118{
119 return obj->mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700120}
121
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100122static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
123{
124 u64 size = 0;
125 struct i915_vma *vma;
126
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000127 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100128 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100129 size += vma->node.size;
130 }
131
132 return size;
133}
134
Chris Wilson37811fc2010-08-25 22:45:57 +0100135static void
136describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
137{
Chris Wilsonb4716182015-04-27 13:41:17 +0100138 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000139 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700140 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800141 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000142 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800143
Chris Wilson188c1ab2016-04-03 14:14:20 +0100144 lockdep_assert_held(&obj->base.dev->struct_mutex);
145
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100146 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100147 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100148 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100149 get_pin_flag(obj),
150 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700151 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100152 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800153 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100154 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100155 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000156 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100157 seq_printf(m, "%x ",
Chris Wilsond72d9082016-08-04 07:52:31 +0100158 i915_gem_active_get_seqno(&obj->last_read[id],
159 &obj->base.dev->struct_mutex));
Chris Wilsonb4716182015-04-27 13:41:17 +0100160 seq_printf(m, "] %x %x%s%s%s",
Chris Wilsond72d9082016-08-04 07:52:31 +0100161 i915_gem_active_get_seqno(&obj->last_write,
162 &obj->base.dev->struct_mutex),
163 i915_gem_active_get_seqno(&obj->last_fence,
164 &obj->base.dev->struct_mutex),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100165 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100166 obj->dirty ? " dirty" : "",
167 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
168 if (obj->base.name)
169 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000170 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100171 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800172 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300173 }
174 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100175 if (obj->pin_display)
176 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100177 if (obj->fence_reg != I915_FENCE_REG_NONE)
178 seq_printf(m, " (fence: %d)", obj->fence_reg);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000179 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100180 if (!drm_mm_node_allocated(&vma->node))
181 continue;
182
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100183 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100184 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100185 vma->node.start, vma->node.size);
Chris Wilson3272db52016-08-04 16:32:32 +0100186 if (i915_vma_is_ggtt(vma))
Chris Wilson596c5922016-02-26 11:03:20 +0000187 seq_printf(m, ", type: %u", vma->ggtt_view.type);
188 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700189 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000190 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100191 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100192 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000193 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100194 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000195 *t++ = 'p';
196 if (obj->fault_mappable)
197 *t++ = 'f';
198 *t = '\0';
199 seq_printf(m, " (%s mappable)", s);
200 }
Chris Wilson27c01aa2016-08-04 07:52:30 +0100201
Chris Wilsond72d9082016-08-04 07:52:31 +0100202 engine = i915_gem_active_get_engine(&obj->last_write,
203 &obj->base.dev->struct_mutex);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100204 if (engine)
205 seq_printf(m, " (%s)", engine->name);
206
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200207 if (obj->frontbuffer_bits)
208 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100209}
210
Ben Gamari433e12f2009-02-17 20:08:51 -0500211static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500212{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100213 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500214 uintptr_t list = (uintptr_t) node->info_ent->data;
215 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500216 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300217 struct drm_i915_private *dev_priv = to_i915(dev);
218 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Ben Widawskyca191b12013-07-31 17:00:14 -0700219 struct i915_vma *vma;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300220 u64 total_obj_size, total_gtt_size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100221 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100222
223 ret = mutex_lock_interruptible(&dev->struct_mutex);
224 if (ret)
225 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500226
Ben Widawskyca191b12013-07-31 17:00:14 -0700227 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500228 switch (list) {
229 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100230 seq_puts(m, "Active:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300231 head = &ggtt->base.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500232 break;
233 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100234 seq_puts(m, "Inactive:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300235 head = &ggtt->base.inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500236 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500237 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100238 mutex_unlock(&dev->struct_mutex);
239 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500240 }
241
Chris Wilson8f2480f2010-09-26 11:44:19 +0100242 total_obj_size = total_gtt_size = count = 0;
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000243 list_for_each_entry(vma, head, vm_link) {
Ben Widawskyca191b12013-07-31 17:00:14 -0700244 seq_printf(m, " ");
245 describe_obj(m, vma->obj);
246 seq_printf(m, "\n");
247 total_obj_size += vma->obj->base.size;
248 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100249 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500250 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100251 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700252
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300253 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson8f2480f2010-09-26 11:44:19 +0100254 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500255 return 0;
256}
257
Chris Wilson6d2b88852013-08-07 18:30:54 +0100258static int obj_rank_by_stolen(void *priv,
259 struct list_head *A, struct list_head *B)
260{
261 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200262 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200264 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100265
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200266 if (a->stolen->start < b->stolen->start)
267 return -1;
268 if (a->stolen->start > b->stolen->start)
269 return 1;
270 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100271}
272
273static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
274{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100275 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100276 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100277 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100278 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300279 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 LIST_HEAD(stolen);
281 int count, ret;
282
283 ret = mutex_lock_interruptible(&dev->struct_mutex);
284 if (ret)
285 return ret;
286
287 total_obj_size = total_gtt_size = count = 0;
288 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
289 if (obj->stolen == NULL)
290 continue;
291
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200292 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100293
294 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100295 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100296 count++;
297 }
298 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
299 if (obj->stolen == NULL)
300 continue;
301
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200302 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100303
304 total_obj_size += obj->base.size;
305 count++;
306 }
307 list_sort(NULL, &stolen, obj_rank_by_stolen);
308 seq_puts(m, "Stolen:\n");
309 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200310 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100311 seq_puts(m, " ");
312 describe_obj(m, obj);
313 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200314 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100315 }
316 mutex_unlock(&dev->struct_mutex);
317
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300318 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100319 count, total_obj_size, total_gtt_size);
320 return 0;
321}
322
Chris Wilson6299f992010-11-24 12:23:44 +0000323#define count_objects(list, member) do { \
324 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100325 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000326 ++count; \
327 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700328 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000329 ++mappable_count; \
330 } \
331 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400332} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000333
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100334struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000335 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300336 unsigned long count;
337 u64 total, unbound;
338 u64 global, shared;
339 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100340};
341
342static int per_file_stats(int id, void *ptr, void *data)
343{
344 struct drm_i915_gem_object *obj = ptr;
345 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000346 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100347
348 stats->count++;
349 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100350 if (!obj->bind_count)
351 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000352 if (obj->base.name || obj->base.dma_buf)
353 stats->shared += obj->base.size;
354
Chris Wilson894eeec2016-08-04 07:52:20 +0100355 list_for_each_entry(vma, &obj->vma_list, obj_link) {
356 if (!drm_mm_node_allocated(&vma->node))
357 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000358
Chris Wilson3272db52016-08-04 16:32:32 +0100359 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100360 stats->global += vma->node.size;
361 } else {
362 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000363
Chris Wilson2bfa9962016-08-04 07:52:25 +0100364 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000365 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000366 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100367
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100368 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100369 stats->active += vma->node.size;
370 else
371 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100372 }
373
374 return 0;
375}
376
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100377#define print_file_stats(m, name, stats) do { \
378 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300379 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 +0100380 name, \
381 stats.count, \
382 stats.total, \
383 stats.active, \
384 stats.inactive, \
385 stats.global, \
386 stats.shared, \
387 stats.unbound); \
388} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800389
390static void print_batch_pool_stats(struct seq_file *m,
391 struct drm_i915_private *dev_priv)
392{
393 struct drm_i915_gem_object *obj;
394 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000395 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000396 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800397
398 memset(&stats, 0, sizeof(stats));
399
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000400 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000401 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100402 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000403 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100404 batch_pool_link)
405 per_file_stats(0, obj, &stats);
406 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100407 }
Brad Volkin493018d2014-12-11 12:13:08 -0800408
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100409 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800410}
411
Chris Wilson15da9562016-05-24 14:53:43 +0100412static int per_file_ctx_stats(int id, void *ptr, void *data)
413{
414 struct i915_gem_context *ctx = ptr;
415 int n;
416
417 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
418 if (ctx->engine[n].state)
419 per_file_stats(0, ctx->engine[n].state, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100420 if (ctx->engine[n].ring)
421 per_file_stats(0, ctx->engine[n].ring->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100422 }
423
424 return 0;
425}
426
427static void print_context_stats(struct seq_file *m,
428 struct drm_i915_private *dev_priv)
429{
430 struct file_stats stats;
431 struct drm_file *file;
432
433 memset(&stats, 0, sizeof(stats));
434
Chris Wilson91c8a322016-07-05 10:40:23 +0100435 mutex_lock(&dev_priv->drm.struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100436 if (dev_priv->kernel_context)
437 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
438
Chris Wilson91c8a322016-07-05 10:40:23 +0100439 list_for_each_entry(file, &dev_priv->drm.filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100440 struct drm_i915_file_private *fpriv = file->driver_priv;
441 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
442 }
Chris Wilson91c8a322016-07-05 10:40:23 +0100443 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100444
445 print_file_stats(m, "[k]contexts", stats);
446}
447
Ben Widawskyca191b12013-07-31 17:00:14 -0700448#define count_vmas(list, member) do { \
449 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100450 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700451 ++count; \
452 if (vma->obj->map_and_fenceable) { \
453 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
454 ++mappable_count; \
455 } \
456 } \
457} while (0)
458
459static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100460{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100461 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100462 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300463 struct drm_i915_private *dev_priv = to_i915(dev);
464 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200465 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300466 u64 size, mappable_size, purgeable_size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100467 unsigned long pin_mapped_count = 0, pin_mapped_purgeable_count = 0;
468 u64 pin_mapped_size = 0, pin_mapped_purgeable_size = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000469 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100470 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700471 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100472 int ret;
473
474 ret = mutex_lock_interruptible(&dev->struct_mutex);
475 if (ret)
476 return ret;
477
Chris Wilson6299f992010-11-24 12:23:44 +0000478 seq_printf(m, "%u objects, %zu bytes\n",
479 dev_priv->mm.object_count,
480 dev_priv->mm.object_memory);
481
482 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700483 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300484 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000485 count, mappable_count, size, mappable_size);
486
487 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300488 count_vmas(&ggtt->base.active_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300489 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000490 count, mappable_count, size, mappable_size);
491
492 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300493 count_vmas(&ggtt->base.inactive_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300494 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000495 count, mappable_count, size, mappable_size);
496
Chris Wilsonb7abb712012-08-20 11:33:30 +0200497 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700498 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200499 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200500 if (obj->madv == I915_MADV_DONTNEED)
501 purgeable_size += obj->base.size, ++purgeable_count;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100502 if (obj->mapping) {
503 pin_mapped_count++;
504 pin_mapped_size += obj->base.size;
505 if (obj->pages_pin_count == 0) {
506 pin_mapped_purgeable_count++;
507 pin_mapped_purgeable_size += obj->base.size;
508 }
509 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200510 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300511 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200512
Chris Wilson6299f992010-11-24 12:23:44 +0000513 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700514 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000515 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700516 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000517 ++count;
518 }
Chris Wilson30154652015-04-07 17:28:24 +0100519 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700520 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000521 ++mappable_count;
522 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200523 if (obj->madv == I915_MADV_DONTNEED) {
524 purgeable_size += obj->base.size;
525 ++purgeable_count;
526 }
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100527 if (obj->mapping) {
528 pin_mapped_count++;
529 pin_mapped_size += obj->base.size;
530 if (obj->pages_pin_count == 0) {
531 pin_mapped_purgeable_count++;
532 pin_mapped_purgeable_size += obj->base.size;
533 }
534 }
Chris Wilson6299f992010-11-24 12:23:44 +0000535 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300536 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200537 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300538 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000539 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300540 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000541 count, size);
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100542 seq_printf(m,
543 "%lu [%lu] pin mapped objects, %llu [%llu] bytes [purgeable]\n",
544 pin_mapped_count, pin_mapped_purgeable_count,
545 pin_mapped_size, pin_mapped_purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000546
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300547 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300548 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100549
Damien Lespiau267f0c92013-06-24 22:59:48 +0100550 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800551 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200552 mutex_unlock(&dev->struct_mutex);
553
554 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100555 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100556 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
557 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900558 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100559
560 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000561 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100562 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100563 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100564 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900565 /*
566 * Although we have a valid reference on file->pid, that does
567 * not guarantee that the task_struct who called get_pid() is
568 * still alive (e.g. get_pid(current) => fork() => exit()).
569 * Therefore, we need to protect this ->comm access using RCU.
570 */
571 rcu_read_lock();
572 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800573 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900574 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100575 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200576 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100577
578 return 0;
579}
580
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100581static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000582{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100583 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000584 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100585 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100586 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson08c18322011-01-10 00:00:24 +0000587 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300588 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000589 int count, ret;
590
591 ret = mutex_lock_interruptible(&dev->struct_mutex);
592 if (ret)
593 return ret;
594
595 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700596 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800597 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100598 continue;
599
Damien Lespiau267f0c92013-06-24 22:59:48 +0100600 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000601 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100602 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000603 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100604 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000605 count++;
606 }
607
608 mutex_unlock(&dev->struct_mutex);
609
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300610 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000611 count, total_obj_size, total_gtt_size);
612
613 return 0;
614}
615
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100616static int i915_gem_pageflip_info(struct seq_file *m, void *data)
617{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100618 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100619 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100620 struct drm_i915_private *dev_priv = to_i915(dev);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100621 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200622 int ret;
623
624 ret = mutex_lock_interruptible(&dev->struct_mutex);
625 if (ret)
626 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100627
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100628 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800629 const char pipe = pipe_name(crtc->pipe);
630 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200631 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100632
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200633 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200634 work = crtc->flip_work;
635 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800636 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100637 pipe, plane);
638 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200639 u32 pending;
640 u32 addr;
641
642 pending = atomic_read(&work->pending);
643 if (pending) {
644 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
645 pipe, plane);
646 } else {
647 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
648 pipe, plane);
649 }
650 if (work->flip_queued_req) {
651 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
652
653 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
654 engine->name,
655 i915_gem_request_get_seqno(work->flip_queued_req),
656 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100657 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100658 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200659 } else
660 seq_printf(m, "Flip not associated with any ring\n");
661 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
662 work->flip_queued_vblank,
663 work->flip_ready_vblank,
664 intel_crtc_get_vblank_counter(crtc));
665 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
666
667 if (INTEL_INFO(dev)->gen >= 4)
668 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
669 else
670 addr = I915_READ(DSPADDR(crtc->plane));
671 seq_printf(m, "Current scanout address 0x%08x\n", addr);
672
673 if (work->pending_flip_obj) {
674 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
675 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100676 }
677 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200678 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100679 }
680
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200681 mutex_unlock(&dev->struct_mutex);
682
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100683 return 0;
684}
685
Brad Volkin493018d2014-12-11 12:13:08 -0800686static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
687{
688 struct drm_info_node *node = m->private;
689 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100690 struct drm_i915_private *dev_priv = to_i915(dev);
Brad Volkin493018d2014-12-11 12:13:08 -0800691 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000692 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100693 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000694 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800695
696 ret = mutex_lock_interruptible(&dev->struct_mutex);
697 if (ret)
698 return ret;
699
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000700 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000701 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100702 int count;
703
704 count = 0;
705 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000706 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100707 batch_pool_link)
708 count++;
709 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000710 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100711
712 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000713 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100714 batch_pool_link) {
715 seq_puts(m, " ");
716 describe_obj(m, obj);
717 seq_putc(m, '\n');
718 }
719
720 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100721 }
Brad Volkin493018d2014-12-11 12:13:08 -0800722 }
723
Chris Wilson8d9d5742015-04-07 16:20:38 +0100724 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800725
726 mutex_unlock(&dev->struct_mutex);
727
728 return 0;
729}
730
Ben Gamari20172632009-02-17 20:08:50 -0500731static int i915_gem_request_info(struct seq_file *m, void *data)
732{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100733 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500734 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100735 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000736 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200737 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000738 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100739
740 ret = mutex_lock_interruptible(&dev->struct_mutex);
741 if (ret)
742 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500743
Chris Wilson2d1070b2015-04-01 10:36:56 +0100744 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000745 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100746 int count;
747
748 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100749 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100750 count++;
751 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100752 continue;
753
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000754 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100755 list_for_each_entry(req, &engine->request_list, link) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100756 struct task_struct *task;
757
758 rcu_read_lock();
759 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200760 if (req->pid)
761 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100762 seq_printf(m, " %x @ %d: %s [%d]\n",
Chris Wilson04769652016-07-20 09:21:11 +0100763 req->fence.seqno,
Daniel Vettereed29a52015-05-21 14:21:25 +0200764 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100765 task ? task->comm : "<unknown>",
766 task ? task->pid : -1);
767 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100768 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100769
770 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500771 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100772 mutex_unlock(&dev->struct_mutex);
773
Chris Wilson2d1070b2015-04-01 10:36:56 +0100774 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100775 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100776
Ben Gamari20172632009-02-17 20:08:50 -0500777 return 0;
778}
779
Chris Wilsonb2223492010-10-27 15:27:33 +0100780static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000781 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100782{
Chris Wilson688e6c72016-07-01 17:23:15 +0100783 struct intel_breadcrumbs *b = &engine->breadcrumbs;
784 struct rb_node *rb;
785
Chris Wilson12471ba2016-04-09 10:57:55 +0100786 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100787 engine->name, intel_engine_get_seqno(engine));
Chris Wilsonaca34b62016-07-06 12:39:02 +0100788 seq_printf(m, "Current user interrupts (%s): %lx\n",
789 engine->name, READ_ONCE(engine->breadcrumbs.irq_wakeups));
Chris Wilson688e6c72016-07-01 17:23:15 +0100790
791 spin_lock(&b->lock);
792 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
793 struct intel_wait *w = container_of(rb, typeof(*w), node);
794
795 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
796 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
797 }
798 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100799}
800
Ben Gamari20172632009-02-17 20:08:50 -0500801static int i915_gem_seqno_info(struct seq_file *m, void *data)
802{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100803 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500804 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100805 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000806 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000807 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100808
809 ret = mutex_lock_interruptible(&dev->struct_mutex);
810 if (ret)
811 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200812 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500813
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000814 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000815 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100816
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200817 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100818 mutex_unlock(&dev->struct_mutex);
819
Ben Gamari20172632009-02-17 20:08:50 -0500820 return 0;
821}
822
823
824static int i915_interrupt_info(struct seq_file *m, void *data)
825{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100826 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500827 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100828 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000829 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800830 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100831
832 ret = mutex_lock_interruptible(&dev->struct_mutex);
833 if (ret)
834 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200835 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500836
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300837 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300838 seq_printf(m, "Master Interrupt Control:\t%08x\n",
839 I915_READ(GEN8_MASTER_IRQ));
840
841 seq_printf(m, "Display IER:\t%08x\n",
842 I915_READ(VLV_IER));
843 seq_printf(m, "Display IIR:\t%08x\n",
844 I915_READ(VLV_IIR));
845 seq_printf(m, "Display IIR_RW:\t%08x\n",
846 I915_READ(VLV_IIR_RW));
847 seq_printf(m, "Display IMR:\t%08x\n",
848 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100849 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300850 seq_printf(m, "Pipe %c stat:\t%08x\n",
851 pipe_name(pipe),
852 I915_READ(PIPESTAT(pipe)));
853
854 seq_printf(m, "Port hotplug:\t%08x\n",
855 I915_READ(PORT_HOTPLUG_EN));
856 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
857 I915_READ(VLV_DPFLIPSTAT));
858 seq_printf(m, "DPINVGTT:\t%08x\n",
859 I915_READ(DPINVGTT));
860
861 for (i = 0; i < 4; i++) {
862 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
863 i, I915_READ(GEN8_GT_IMR(i)));
864 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
865 i, I915_READ(GEN8_GT_IIR(i)));
866 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
867 i, I915_READ(GEN8_GT_IER(i)));
868 }
869
870 seq_printf(m, "PCU interrupt mask:\t%08x\n",
871 I915_READ(GEN8_PCU_IMR));
872 seq_printf(m, "PCU interrupt identity:\t%08x\n",
873 I915_READ(GEN8_PCU_IIR));
874 seq_printf(m, "PCU interrupt enable:\t%08x\n",
875 I915_READ(GEN8_PCU_IER));
876 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700877 seq_printf(m, "Master Interrupt Control:\t%08x\n",
878 I915_READ(GEN8_MASTER_IRQ));
879
880 for (i = 0; i < 4; i++) {
881 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
882 i, I915_READ(GEN8_GT_IMR(i)));
883 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
884 i, I915_READ(GEN8_GT_IIR(i)));
885 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
886 i, I915_READ(GEN8_GT_IER(i)));
887 }
888
Damien Lespiau055e3932014-08-18 13:49:10 +0100889 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200890 enum intel_display_power_domain power_domain;
891
892 power_domain = POWER_DOMAIN_PIPE(pipe);
893 if (!intel_display_power_get_if_enabled(dev_priv,
894 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300895 seq_printf(m, "Pipe %c power disabled\n",
896 pipe_name(pipe));
897 continue;
898 }
Ben Widawskya123f152013-11-02 21:07:10 -0700899 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000900 pipe_name(pipe),
901 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700902 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000903 pipe_name(pipe),
904 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700905 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000906 pipe_name(pipe),
907 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200908
909 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700910 }
911
912 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
913 I915_READ(GEN8_DE_PORT_IMR));
914 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
915 I915_READ(GEN8_DE_PORT_IIR));
916 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
917 I915_READ(GEN8_DE_PORT_IER));
918
919 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
920 I915_READ(GEN8_DE_MISC_IMR));
921 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
922 I915_READ(GEN8_DE_MISC_IIR));
923 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
924 I915_READ(GEN8_DE_MISC_IER));
925
926 seq_printf(m, "PCU interrupt mask:\t%08x\n",
927 I915_READ(GEN8_PCU_IMR));
928 seq_printf(m, "PCU interrupt identity:\t%08x\n",
929 I915_READ(GEN8_PCU_IIR));
930 seq_printf(m, "PCU interrupt enable:\t%08x\n",
931 I915_READ(GEN8_PCU_IER));
932 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700933 seq_printf(m, "Display IER:\t%08x\n",
934 I915_READ(VLV_IER));
935 seq_printf(m, "Display IIR:\t%08x\n",
936 I915_READ(VLV_IIR));
937 seq_printf(m, "Display IIR_RW:\t%08x\n",
938 I915_READ(VLV_IIR_RW));
939 seq_printf(m, "Display IMR:\t%08x\n",
940 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100941 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700942 seq_printf(m, "Pipe %c stat:\t%08x\n",
943 pipe_name(pipe),
944 I915_READ(PIPESTAT(pipe)));
945
946 seq_printf(m, "Master IER:\t%08x\n",
947 I915_READ(VLV_MASTER_IER));
948
949 seq_printf(m, "Render IER:\t%08x\n",
950 I915_READ(GTIER));
951 seq_printf(m, "Render IIR:\t%08x\n",
952 I915_READ(GTIIR));
953 seq_printf(m, "Render IMR:\t%08x\n",
954 I915_READ(GTIMR));
955
956 seq_printf(m, "PM IER:\t\t%08x\n",
957 I915_READ(GEN6_PMIER));
958 seq_printf(m, "PM IIR:\t\t%08x\n",
959 I915_READ(GEN6_PMIIR));
960 seq_printf(m, "PM IMR:\t\t%08x\n",
961 I915_READ(GEN6_PMIMR));
962
963 seq_printf(m, "Port hotplug:\t%08x\n",
964 I915_READ(PORT_HOTPLUG_EN));
965 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
966 I915_READ(VLV_DPFLIPSTAT));
967 seq_printf(m, "DPINVGTT:\t%08x\n",
968 I915_READ(DPINVGTT));
969
970 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800971 seq_printf(m, "Interrupt enable: %08x\n",
972 I915_READ(IER));
973 seq_printf(m, "Interrupt identity: %08x\n",
974 I915_READ(IIR));
975 seq_printf(m, "Interrupt mask: %08x\n",
976 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100977 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800978 seq_printf(m, "Pipe %c stat: %08x\n",
979 pipe_name(pipe),
980 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800981 } else {
982 seq_printf(m, "North Display Interrupt enable: %08x\n",
983 I915_READ(DEIER));
984 seq_printf(m, "North Display Interrupt identity: %08x\n",
985 I915_READ(DEIIR));
986 seq_printf(m, "North Display Interrupt mask: %08x\n",
987 I915_READ(DEIMR));
988 seq_printf(m, "South Display Interrupt enable: %08x\n",
989 I915_READ(SDEIER));
990 seq_printf(m, "South Display Interrupt identity: %08x\n",
991 I915_READ(SDEIIR));
992 seq_printf(m, "South Display Interrupt mask: %08x\n",
993 I915_READ(SDEIMR));
994 seq_printf(m, "Graphics Interrupt enable: %08x\n",
995 I915_READ(GTIER));
996 seq_printf(m, "Graphics Interrupt identity: %08x\n",
997 I915_READ(GTIIR));
998 seq_printf(m, "Graphics Interrupt mask: %08x\n",
999 I915_READ(GTIMR));
1000 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001001 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -07001002 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001003 seq_printf(m,
1004 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001005 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +00001006 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001007 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +00001008 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001009 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001010 mutex_unlock(&dev->struct_mutex);
1011
Ben Gamari20172632009-02-17 20:08:50 -05001012 return 0;
1013}
1014
Chris Wilsona6172a82009-02-11 14:26:38 +00001015static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
1016{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001017 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +00001018 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001019 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001020 int i, ret;
1021
1022 ret = mutex_lock_interruptible(&dev->struct_mutex);
1023 if (ret)
1024 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +00001025
Chris Wilsona6172a82009-02-11 14:26:38 +00001026 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
1027 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +00001028 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +00001029
Chris Wilson6c085a72012-08-20 11:40:46 +02001030 seq_printf(m, "Fence %d, pin count = %d, object = ",
1031 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001032 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001033 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001034 else
Chris Wilson05394f32010-11-08 19:18:58 +00001035 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001036 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001037 }
1038
Chris Wilson05394f32010-11-08 19:18:58 +00001039 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001040 return 0;
1041}
1042
Ben Gamari20172632009-02-17 20:08:50 -05001043static int i915_hws_info(struct seq_file *m, void *data)
1044{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001045 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001046 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001047 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001048 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001049 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001050 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001051
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001052 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001053 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001054 if (hws == NULL)
1055 return 0;
1056
1057 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1058 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1059 i * 4,
1060 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1061 }
1062 return 0;
1063}
1064
Daniel Vetterd5442302012-04-27 15:17:40 +02001065static ssize_t
1066i915_error_state_write(struct file *filp,
1067 const char __user *ubuf,
1068 size_t cnt,
1069 loff_t *ppos)
1070{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001071 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001072 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001073 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001074
1075 DRM_DEBUG_DRIVER("Resetting error state\n");
1076
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001077 ret = mutex_lock_interruptible(&dev->struct_mutex);
1078 if (ret)
1079 return ret;
1080
Daniel Vetterd5442302012-04-27 15:17:40 +02001081 i915_destroy_error_state(dev);
1082 mutex_unlock(&dev->struct_mutex);
1083
1084 return cnt;
1085}
1086
1087static int i915_error_state_open(struct inode *inode, struct file *file)
1088{
1089 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001090 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001091
1092 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1093 if (!error_priv)
1094 return -ENOMEM;
1095
1096 error_priv->dev = dev;
1097
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001098 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001099
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001100 file->private_data = error_priv;
1101
1102 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001103}
1104
1105static int i915_error_state_release(struct inode *inode, struct file *file)
1106{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001107 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001108
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001109 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001110 kfree(error_priv);
1111
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001112 return 0;
1113}
1114
1115static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1116 size_t count, loff_t *pos)
1117{
1118 struct i915_error_state_file_priv *error_priv = file->private_data;
1119 struct drm_i915_error_state_buf error_str;
1120 loff_t tmp_pos = 0;
1121 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001122 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001123
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001124 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001125 if (ret)
1126 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001127
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001128 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001129 if (ret)
1130 goto out;
1131
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001132 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1133 error_str.buf,
1134 error_str.bytes);
1135
1136 if (ret_count < 0)
1137 ret = ret_count;
1138 else
1139 *pos = error_str.start + ret_count;
1140out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001141 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001142 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001143}
1144
1145static const struct file_operations i915_error_state_fops = {
1146 .owner = THIS_MODULE,
1147 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001148 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001149 .write = i915_error_state_write,
1150 .llseek = default_llseek,
1151 .release = i915_error_state_release,
1152};
1153
Kees Cook647416f2013-03-10 14:10:06 -07001154static int
1155i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001156{
Kees Cook647416f2013-03-10 14:10:06 -07001157 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001158 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala40633212012-12-04 15:12:00 +02001159 int ret;
1160
1161 ret = mutex_lock_interruptible(&dev->struct_mutex);
1162 if (ret)
1163 return ret;
1164
Kees Cook647416f2013-03-10 14:10:06 -07001165 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001166 mutex_unlock(&dev->struct_mutex);
1167
Kees Cook647416f2013-03-10 14:10:06 -07001168 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001169}
1170
Kees Cook647416f2013-03-10 14:10:06 -07001171static int
1172i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001173{
Kees Cook647416f2013-03-10 14:10:06 -07001174 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001175 int ret;
1176
Mika Kuoppala40633212012-12-04 15:12:00 +02001177 ret = mutex_lock_interruptible(&dev->struct_mutex);
1178 if (ret)
1179 return ret;
1180
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001181 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001182 mutex_unlock(&dev->struct_mutex);
1183
Kees Cook647416f2013-03-10 14:10:06 -07001184 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001185}
1186
Kees Cook647416f2013-03-10 14:10:06 -07001187DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1188 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001189 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001190
Deepak Sadb4bd12014-03-31 11:30:02 +05301191static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001192{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001193 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001194 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001195 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001196 int ret = 0;
1197
1198 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001199
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001200 if (IS_GEN5(dev)) {
1201 u16 rgvswctl = I915_READ16(MEMSWCTL);
1202 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1203
1204 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1205 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1206 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1207 MEMSTAT_VID_SHIFT);
1208 seq_printf(m, "Current P-state: %d\n",
1209 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001210 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1211 u32 freq_sts;
1212
1213 mutex_lock(&dev_priv->rps.hw_lock);
1214 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1215 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1216 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1217
1218 seq_printf(m, "actual GPU freq: %d MHz\n",
1219 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1220
1221 seq_printf(m, "current GPU freq: %d MHz\n",
1222 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1223
1224 seq_printf(m, "max GPU freq: %d MHz\n",
1225 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1226
1227 seq_printf(m, "min GPU freq: %d MHz\n",
1228 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1229
1230 seq_printf(m, "idle GPU freq: %d MHz\n",
1231 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1232
1233 seq_printf(m,
1234 "efficient (RPe) frequency: %d MHz\n",
1235 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1236 mutex_unlock(&dev_priv->rps.hw_lock);
1237 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001238 u32 rp_state_limits;
1239 u32 gt_perf_status;
1240 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001241 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001242 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001243 u32 rpupei, rpcurup, rpprevup;
1244 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001245 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001246 int max_freq;
1247
Bob Paauwe35040562015-06-25 14:54:07 -07001248 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1249 if (IS_BROXTON(dev)) {
1250 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1251 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1252 } else {
1253 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1254 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1255 }
1256
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001257 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001258 ret = mutex_lock_interruptible(&dev->struct_mutex);
1259 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001260 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001261
Mika Kuoppala59bad942015-01-16 11:34:40 +02001262 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001264 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301265 if (IS_GEN9(dev))
1266 reqf >>= 23;
1267 else {
1268 reqf &= ~GEN6_TURBO_DISABLE;
1269 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1270 reqf >>= 24;
1271 else
1272 reqf >>= 25;
1273 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001274 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001275
Chris Wilson0d8f9492014-03-27 09:06:14 +00001276 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1277 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1278 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1279
Jesse Barnesccab5c82011-01-18 15:49:25 -08001280 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301281 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1282 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1283 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1284 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1285 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1286 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301287 if (IS_GEN9(dev))
1288 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1289 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001290 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1291 else
1292 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001293 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001294
Mika Kuoppala59bad942015-01-16 11:34:40 +02001295 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001296 mutex_unlock(&dev->struct_mutex);
1297
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001298 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1299 pm_ier = I915_READ(GEN6_PMIER);
1300 pm_imr = I915_READ(GEN6_PMIMR);
1301 pm_isr = I915_READ(GEN6_PMISR);
1302 pm_iir = I915_READ(GEN6_PMIIR);
1303 pm_mask = I915_READ(GEN6_PMINTRMSK);
1304 } else {
1305 pm_ier = I915_READ(GEN8_GT_IER(2));
1306 pm_imr = I915_READ(GEN8_GT_IMR(2));
1307 pm_isr = I915_READ(GEN8_GT_ISR(2));
1308 pm_iir = I915_READ(GEN8_GT_IIR(2));
1309 pm_mask = I915_READ(GEN6_PMINTRMSK);
1310 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001311 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 -03001312 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301313 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001314 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001315 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301316 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001317 seq_printf(m, "Render p-state VID: %d\n",
1318 gt_perf_status & 0xff);
1319 seq_printf(m, "Render p-state limit: %d\n",
1320 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001321 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1322 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1323 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1324 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001325 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001326 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301327 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1328 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1329 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1330 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1331 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1332 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001333 seq_printf(m, "Up threshold: %d%%\n",
1334 dev_priv->rps.up_threshold);
1335
Akash Goeld6cda9c2016-04-23 00:05:46 +05301336 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1337 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1338 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1339 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1340 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1341 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001342 seq_printf(m, "Down threshold: %d%%\n",
1343 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001344
Bob Paauwe35040562015-06-25 14:54:07 -07001345 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1346 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001347 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1348 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001349 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001350 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001351
1352 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001353 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1354 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001355 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001356 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001357
Bob Paauwe35040562015-06-25 14:54:07 -07001358 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1359 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001360 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1361 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001362 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001363 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001364 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001365 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001366
Chris Wilsond86ed342015-04-27 13:41:19 +01001367 seq_printf(m, "Current freq: %d MHz\n",
1368 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1369 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001370 seq_printf(m, "Idle freq: %d MHz\n",
1371 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001372 seq_printf(m, "Min freq: %d MHz\n",
1373 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001374 seq_printf(m, "Boost freq: %d MHz\n",
1375 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001376 seq_printf(m, "Max freq: %d MHz\n",
1377 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1378 seq_printf(m,
1379 "efficient (RPe) frequency: %d MHz\n",
1380 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001381 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001382 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001383 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001384
Mika Kahola1170f282015-09-25 14:00:32 +03001385 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1386 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1387 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1388
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001389out:
1390 intel_runtime_pm_put(dev_priv);
1391 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001392}
1393
Chris Wilsonf6544492015-01-26 18:03:04 +02001394static int i915_hangcheck_info(struct seq_file *m, void *unused)
1395{
1396 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001397 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001398 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001399 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001400 u64 acthd[I915_NUM_ENGINES];
1401 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001402 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001403 enum intel_engine_id id;
1404 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001405
1406 if (!i915.enable_hangcheck) {
1407 seq_printf(m, "Hangcheck disabled\n");
1408 return 0;
1409 }
1410
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001411 intel_runtime_pm_get(dev_priv);
1412
Dave Gordonc3232b12016-03-23 18:19:53 +00001413 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001414 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001415 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001416 }
1417
Chris Wilsonc0336662016-05-06 15:40:21 +01001418 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001419
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001420 intel_runtime_pm_put(dev_priv);
1421
Chris Wilsonf6544492015-01-26 18:03:04 +02001422 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1423 seq_printf(m, "Hangcheck active, fires in %dms\n",
1424 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1425 jiffies));
1426 } else
1427 seq_printf(m, "Hangcheck inactive\n");
1428
Dave Gordonc3232b12016-03-23 18:19:53 +00001429 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001430 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001431 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1432 engine->hangcheck.seqno,
1433 seqno[id],
1434 engine->last_submitted_seqno);
Chris Wilson688e6c72016-07-01 17:23:15 +01001435 seq_printf(m, "\twaiters? %d\n",
1436 intel_engine_has_waiter(engine));
Chris Wilsonaca34b62016-07-06 12:39:02 +01001437 seq_printf(m, "\tuser interrupts = %lx [current %lx]\n",
Chris Wilson12471ba2016-04-09 10:57:55 +01001438 engine->hangcheck.user_interrupts,
Chris Wilsonaca34b62016-07-06 12:39:02 +01001439 READ_ONCE(engine->breadcrumbs.irq_wakeups));
Chris Wilsonf6544492015-01-26 18:03:04 +02001440 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001441 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001442 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001443 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1444 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001445
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001446 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001447 seq_puts(m, "\tinstdone read =");
1448
1449 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1450 seq_printf(m, " 0x%08x", instdone[j]);
1451
1452 seq_puts(m, "\n\tinstdone accu =");
1453
1454 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1455 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001456 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001457
1458 seq_puts(m, "\n");
1459 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001460 }
1461
1462 return 0;
1463}
1464
Ben Widawsky4d855292011-12-12 19:34:16 -08001465static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001466{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001467 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001468 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001469 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001470 u32 rgvmodectl, rstdbyctl;
1471 u16 crstandvid;
1472 int ret;
1473
1474 ret = mutex_lock_interruptible(&dev->struct_mutex);
1475 if (ret)
1476 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001477 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001478
1479 rgvmodectl = I915_READ(MEMMODECTL);
1480 rstdbyctl = I915_READ(RSTDBYCTL);
1481 crstandvid = I915_READ16(CRSTANDVID);
1482
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001483 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001484 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001485
Jani Nikula742f4912015-09-03 11:16:09 +03001486 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001487 seq_printf(m, "Boost freq: %d\n",
1488 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1489 MEMMODE_BOOST_FREQ_SHIFT);
1490 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001491 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001492 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001493 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001494 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001495 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001496 seq_printf(m, "Starting frequency: P%d\n",
1497 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001498 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001499 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001500 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1501 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1502 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1503 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001504 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001505 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001506 switch (rstdbyctl & RSX_STATUS_MASK) {
1507 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001508 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001509 break;
1510 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001511 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001512 break;
1513 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001514 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001515 break;
1516 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001517 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001518 break;
1519 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001520 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001521 break;
1522 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001523 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001524 break;
1525 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001526 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001527 break;
1528 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001529
1530 return 0;
1531}
1532
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001533static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001534{
1535 struct drm_info_node *node = m->private;
1536 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001537 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001538 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001539
1540 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001541 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001542 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001543 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001544 fw_domain->wake_count);
1545 }
1546 spin_unlock_irq(&dev_priv->uncore.lock);
1547
1548 return 0;
1549}
1550
Deepak S669ab5a2014-01-10 15:18:26 +05301551static int vlv_drpc_info(struct seq_file *m)
1552{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001553 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301554 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001555 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001556 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301557
Imre Deakd46c0512014-04-14 20:24:27 +03001558 intel_runtime_pm_get(dev_priv);
1559
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001560 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301561 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1562 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1563
Imre Deakd46c0512014-04-14 20:24:27 +03001564 intel_runtime_pm_put(dev_priv);
1565
Deepak S669ab5a2014-01-10 15:18:26 +05301566 seq_printf(m, "Video Turbo Mode: %s\n",
1567 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1568 seq_printf(m, "Turbo enabled: %s\n",
1569 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1570 seq_printf(m, "HW control enabled: %s\n",
1571 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1572 seq_printf(m, "SW control enabled: %s\n",
1573 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1574 GEN6_RP_MEDIA_SW_MODE));
1575 seq_printf(m, "RC6 Enabled: %s\n",
1576 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1577 GEN6_RC_CTL_EI_MODE(1))));
1578 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001579 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301580 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001581 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301582
Imre Deak9cc19be2014-04-14 20:24:24 +03001583 seq_printf(m, "Render RC6 residency since boot: %u\n",
1584 I915_READ(VLV_GT_RENDER_RC6));
1585 seq_printf(m, "Media RC6 residency since boot: %u\n",
1586 I915_READ(VLV_GT_MEDIA_RC6));
1587
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001588 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301589}
1590
Ben Widawsky4d855292011-12-12 19:34:16 -08001591static int gen6_drpc_info(struct seq_file *m)
1592{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001593 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001594 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001595 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001596 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301597 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001598 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001599 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001600
1601 ret = mutex_lock_interruptible(&dev->struct_mutex);
1602 if (ret)
1603 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001604 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001605
Chris Wilson907b28c2013-07-19 20:36:52 +01001606 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001607 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001608 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001609
1610 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001611 seq_puts(m, "RC information inaccurate because somebody "
1612 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001613 } else {
1614 /* NB: we cannot use forcewake, else we read the wrong values */
1615 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1616 udelay(10);
1617 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1618 }
1619
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001620 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001621 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001622
1623 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1624 rcctl1 = I915_READ(GEN6_RC_CONTROL);
Akash Goelf2dd7572016-06-27 20:10:01 +05301625 if (INTEL_INFO(dev)->gen >= 9) {
1626 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1627 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1628 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001629 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001630 mutex_lock(&dev_priv->rps.hw_lock);
1631 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1632 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001633
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001634 intel_runtime_pm_put(dev_priv);
1635
Ben Widawsky4d855292011-12-12 19:34:16 -08001636 seq_printf(m, "Video Turbo Mode: %s\n",
1637 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1638 seq_printf(m, "HW control enabled: %s\n",
1639 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1640 seq_printf(m, "SW control enabled: %s\n",
1641 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1642 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001643 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001644 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1645 seq_printf(m, "RC6 Enabled: %s\n",
1646 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
Akash Goelf2dd7572016-06-27 20:10:01 +05301647 if (INTEL_INFO(dev)->gen >= 9) {
1648 seq_printf(m, "Render Well Gating Enabled: %s\n",
1649 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1650 seq_printf(m, "Media Well Gating Enabled: %s\n",
1651 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1652 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001653 seq_printf(m, "Deep RC6 Enabled: %s\n",
1654 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1655 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1656 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001657 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001658 switch (gt_core_status & GEN6_RCn_MASK) {
1659 case GEN6_RC0:
1660 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001661 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001662 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001663 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001664 break;
1665 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001666 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001667 break;
1668 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001669 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001670 break;
1671 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001672 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001673 break;
1674 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001675 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001676 break;
1677 }
1678
1679 seq_printf(m, "Core Power Down: %s\n",
1680 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Akash Goelf2dd7572016-06-27 20:10:01 +05301681 if (INTEL_INFO(dev)->gen >= 9) {
1682 seq_printf(m, "Render Power Well: %s\n",
1683 (gen9_powergate_status &
1684 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1685 seq_printf(m, "Media Power Well: %s\n",
1686 (gen9_powergate_status &
1687 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1688 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001689
1690 /* Not exactly sure what this is */
1691 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1692 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1693 seq_printf(m, "RC6 residency since boot: %u\n",
1694 I915_READ(GEN6_GT_GFX_RC6));
1695 seq_printf(m, "RC6+ residency since boot: %u\n",
1696 I915_READ(GEN6_GT_GFX_RC6p));
1697 seq_printf(m, "RC6++ residency since boot: %u\n",
1698 I915_READ(GEN6_GT_GFX_RC6pp));
1699
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001700 seq_printf(m, "RC6 voltage: %dmV\n",
1701 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1702 seq_printf(m, "RC6+ voltage: %dmV\n",
1703 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1704 seq_printf(m, "RC6++ voltage: %dmV\n",
1705 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301706 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001707}
1708
1709static int i915_drpc_info(struct seq_file *m, void *unused)
1710{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001711 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001712 struct drm_device *dev = node->minor->dev;
1713
Wayne Boyer666a4532015-12-09 12:29:35 -08001714 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301715 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001716 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001717 return gen6_drpc_info(m);
1718 else
1719 return ironlake_drpc_info(m);
1720}
1721
Daniel Vetter9a851782015-06-18 10:30:22 +02001722static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1723{
1724 struct drm_info_node *node = m->private;
1725 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001726 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter9a851782015-06-18 10:30:22 +02001727
1728 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1729 dev_priv->fb_tracking.busy_bits);
1730
1731 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1732 dev_priv->fb_tracking.flip_bits);
1733
1734 return 0;
1735}
1736
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001737static int i915_fbc_status(struct seq_file *m, void *unused)
1738{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001739 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001740 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001741 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001742
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001743 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001744 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001745 return 0;
1746 }
1747
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001748 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001749 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001750
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001751 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001752 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001753 else
1754 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001755 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001756
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001757 if (INTEL_INFO(dev_priv)->gen >= 7)
1758 seq_printf(m, "Compressing: %s\n",
1759 yesno(I915_READ(FBC_STATUS2) &
1760 FBC_COMPRESSION_MASK));
1761
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001762 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001763 intel_runtime_pm_put(dev_priv);
1764
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001765 return 0;
1766}
1767
Rodrigo Vivida46f932014-08-01 02:04:45 -07001768static int i915_fbc_fc_get(void *data, u64 *val)
1769{
1770 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001771 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001772
1773 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1774 return -ENODEV;
1775
Rodrigo Vivida46f932014-08-01 02:04:45 -07001776 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001777
1778 return 0;
1779}
1780
1781static int i915_fbc_fc_set(void *data, u64 val)
1782{
1783 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001784 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001785 u32 reg;
1786
1787 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1788 return -ENODEV;
1789
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001790 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001791
1792 reg = I915_READ(ILK_DPFC_CONTROL);
1793 dev_priv->fbc.false_color = val;
1794
1795 I915_WRITE(ILK_DPFC_CONTROL, val ?
1796 (reg | FBC_CTL_FALSE_COLOR) :
1797 (reg & ~FBC_CTL_FALSE_COLOR));
1798
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001799 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001800 return 0;
1801}
1802
1803DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1804 i915_fbc_fc_get, i915_fbc_fc_set,
1805 "%llu\n");
1806
Paulo Zanoni92d44622013-05-31 16:33:24 -03001807static int i915_ips_status(struct seq_file *m, void *unused)
1808{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001809 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001810 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001811 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001812
Damien Lespiauf5adf942013-06-24 18:29:34 +01001813 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001814 seq_puts(m, "not supported\n");
1815 return 0;
1816 }
1817
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001818 intel_runtime_pm_get(dev_priv);
1819
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001820 seq_printf(m, "Enabled by kernel parameter: %s\n",
1821 yesno(i915.enable_ips));
1822
1823 if (INTEL_INFO(dev)->gen >= 8) {
1824 seq_puts(m, "Currently: unknown\n");
1825 } else {
1826 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1827 seq_puts(m, "Currently: enabled\n");
1828 else
1829 seq_puts(m, "Currently: disabled\n");
1830 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001831
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001832 intel_runtime_pm_put(dev_priv);
1833
Paulo Zanoni92d44622013-05-31 16:33:24 -03001834 return 0;
1835}
1836
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001837static int i915_sr_status(struct seq_file *m, void *unused)
1838{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001839 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001840 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001841 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001842 bool sr_enabled = false;
1843
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001844 intel_runtime_pm_get(dev_priv);
1845
Yuanhan Liu13982612010-12-15 15:42:31 +08001846 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001847 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001848 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1849 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001850 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1851 else if (IS_I915GM(dev))
1852 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1853 else if (IS_PINEVIEW(dev))
1854 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001855 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001856 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001857
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001858 intel_runtime_pm_put(dev_priv);
1859
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001860 seq_printf(m, "self-refresh: %s\n",
1861 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001862
1863 return 0;
1864}
1865
Jesse Barnes7648fa92010-05-20 14:28:11 -07001866static int i915_emon_status(struct seq_file *m, void *unused)
1867{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001868 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001869 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001870 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001871 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001872 int ret;
1873
Chris Wilson582be6b2012-04-30 19:35:02 +01001874 if (!IS_GEN5(dev))
1875 return -ENODEV;
1876
Chris Wilsonde227ef2010-07-03 07:58:38 +01001877 ret = mutex_lock_interruptible(&dev->struct_mutex);
1878 if (ret)
1879 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001880
1881 temp = i915_mch_val(dev_priv);
1882 chipset = i915_chipset_val(dev_priv);
1883 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001884 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001885
1886 seq_printf(m, "GMCH temp: %ld\n", temp);
1887 seq_printf(m, "Chipset power: %ld\n", chipset);
1888 seq_printf(m, "GFX power: %ld\n", gfx);
1889 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1890
1891 return 0;
1892}
1893
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001894static int i915_ring_freq_table(struct seq_file *m, void *unused)
1895{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001896 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001897 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001898 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001899 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001900 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301901 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001902
Akash Goel97d33082015-06-29 14:50:23 +05301903 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001904 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001905 return 0;
1906 }
1907
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001908 intel_runtime_pm_get(dev_priv);
1909
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001910 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001911 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001912 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001913
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001914 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301915 /* Convert GT frequency to 50 HZ units */
1916 min_gpu_freq =
1917 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1918 max_gpu_freq =
1919 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1920 } else {
1921 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1922 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1923 }
1924
Damien Lespiau267f0c92013-06-24 22:59:48 +01001925 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001926
Akash Goelf936ec32015-06-29 14:50:22 +05301927 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001928 ia_freq = gpu_freq;
1929 sandybridge_pcode_read(dev_priv,
1930 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1931 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001932 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301933 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001934 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1935 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001936 ((ia_freq >> 0) & 0xff) * 100,
1937 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001938 }
1939
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001940 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001941
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001942out:
1943 intel_runtime_pm_put(dev_priv);
1944 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001945}
1946
Chris Wilson44834a62010-08-19 16:09:23 +01001947static int i915_opregion(struct seq_file *m, void *unused)
1948{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001949 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001950 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001951 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson44834a62010-08-19 16:09:23 +01001952 struct intel_opregion *opregion = &dev_priv->opregion;
1953 int ret;
1954
1955 ret = mutex_lock_interruptible(&dev->struct_mutex);
1956 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001957 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001958
Jani Nikula2455a8e2015-12-14 12:50:53 +02001959 if (opregion->header)
1960 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001961
1962 mutex_unlock(&dev->struct_mutex);
1963
Daniel Vetter0d38f002012-04-21 22:49:10 +02001964out:
Chris Wilson44834a62010-08-19 16:09:23 +01001965 return 0;
1966}
1967
Jani Nikulaada8f952015-12-15 13:17:12 +02001968static int i915_vbt(struct seq_file *m, void *unused)
1969{
1970 struct drm_info_node *node = m->private;
1971 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001972 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulaada8f952015-12-15 13:17:12 +02001973 struct intel_opregion *opregion = &dev_priv->opregion;
1974
1975 if (opregion->vbt)
1976 seq_write(m, opregion->vbt, opregion->vbt_size);
1977
1978 return 0;
1979}
1980
Chris Wilson37811fc2010-08-25 22:45:57 +01001981static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1982{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001983 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001984 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301985 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001986 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001987 int ret;
1988
1989 ret = mutex_lock_interruptible(&dev->struct_mutex);
1990 if (ret)
1991 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001992
Daniel Vetter06957262015-08-10 13:34:08 +02001993#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson25bcce92016-07-02 15:36:00 +01001994 if (to_i915(dev)->fbdev) {
1995 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001996
Chris Wilson25bcce92016-07-02 15:36:00 +01001997 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1998 fbdev_fb->base.width,
1999 fbdev_fb->base.height,
2000 fbdev_fb->base.depth,
2001 fbdev_fb->base.bits_per_pixel,
2002 fbdev_fb->base.modifier[0],
2003 drm_framebuffer_read_refcount(&fbdev_fb->base));
2004 describe_obj(m, fbdev_fb->obj);
2005 seq_putc(m, '\n');
2006 }
Daniel Vetter4520f532013-10-09 09:18:51 +02002007#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01002008
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002009 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02002010 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05302011 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
2012 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01002013 continue;
2014
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002015 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 +01002016 fb->base.width,
2017 fb->base.height,
2018 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01002019 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002020 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10002021 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00002022 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01002023 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01002024 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002025 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01002026 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01002027
2028 return 0;
2029}
2030
Chris Wilson7e37f882016-08-02 22:50:21 +01002031static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002032{
2033 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01002034 ring->space, ring->head, ring->tail,
2035 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002036}
2037
Ben Widawskye76d3632011-03-19 18:14:29 -07002038static int i915_context_status(struct seq_file *m, void *unused)
2039{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002040 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07002041 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002042 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002043 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002044 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00002045 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07002046
Daniel Vetterf3d28872014-05-29 23:23:08 +02002047 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002048 if (ret)
2049 return ret;
2050
Ben Widawskya33afea2013-09-17 21:12:45 -07002051 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01002052 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsond28b99a2016-05-24 14:53:39 +01002053 if (IS_ERR(ctx->file_priv)) {
2054 seq_puts(m, "(deleted) ");
2055 } else if (ctx->file_priv) {
2056 struct pid *pid = ctx->file_priv->file->pid;
2057 struct task_struct *task;
2058
2059 task = get_pid_task(pid, PIDTYPE_PID);
2060 if (task) {
2061 seq_printf(m, "(%s [%d]) ",
2062 task->comm, task->pid);
2063 put_task_struct(task);
2064 }
2065 } else {
2066 seq_puts(m, "(kernel) ");
2067 }
2068
Chris Wilsonbca44d82016-05-24 14:53:41 +01002069 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
2070 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07002071
Chris Wilsonbca44d82016-05-24 14:53:41 +01002072 for_each_engine(engine, dev_priv) {
2073 struct intel_context *ce = &ctx->engine[engine->id];
2074
2075 seq_printf(m, "%s: ", engine->name);
2076 seq_putc(m, ce->initialised ? 'I' : 'i');
2077 if (ce->state)
2078 describe_obj(m, ce->state);
Chris Wilsondca33ec2016-08-02 22:50:20 +01002079 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01002080 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002081 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002082 }
2083
Ben Widawskya33afea2013-09-17 21:12:45 -07002084 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002085 }
2086
Daniel Vetterf3d28872014-05-29 23:23:08 +02002087 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002088
2089 return 0;
2090}
2091
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002092static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002093 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002094 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002095{
Chris Wilsonbca44d82016-05-24 14:53:41 +01002096 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002097 struct page *page;
2098 uint32_t *reg_state;
2099 int j;
2100 unsigned long ggtt_offset = 0;
2101
Chris Wilson7069b142016-04-28 09:56:52 +01002102 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2103
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002104 if (ctx_obj == NULL) {
Chris Wilson7069b142016-04-28 09:56:52 +01002105 seq_puts(m, "\tNot allocated\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002106 return;
2107 }
2108
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002109 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2110 seq_puts(m, "\tNot bound in GGTT\n");
2111 else
2112 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2113
2114 if (i915_gem_object_get_pages(ctx_obj)) {
2115 seq_puts(m, "\tFailed to get pages for context object\n");
2116 return;
2117 }
2118
Alex Daid1675192015-08-12 15:43:43 +01002119 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002120 if (!WARN_ON(page == NULL)) {
2121 reg_state = kmap_atomic(page);
2122
2123 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2124 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2125 ggtt_offset + 4096 + (j * 4),
2126 reg_state[j], reg_state[j + 1],
2127 reg_state[j + 2], reg_state[j + 3]);
2128 }
2129 kunmap_atomic(reg_state);
2130 }
2131
2132 seq_putc(m, '\n');
2133}
2134
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002135static int i915_dump_lrc(struct seq_file *m, void *unused)
2136{
2137 struct drm_info_node *node = (struct drm_info_node *) m->private;
2138 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002139 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002140 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002141 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002142 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002143
2144 if (!i915.enable_execlists) {
2145 seq_printf(m, "Logical Ring Contexts are disabled\n");
2146 return 0;
2147 }
2148
2149 ret = mutex_lock_interruptible(&dev->struct_mutex);
2150 if (ret)
2151 return ret;
2152
Dave Gordone28e4042016-01-19 19:02:55 +00002153 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002154 for_each_engine(engine, dev_priv)
2155 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002156
2157 mutex_unlock(&dev->struct_mutex);
2158
2159 return 0;
2160}
2161
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002162static int i915_execlists(struct seq_file *m, void *data)
2163{
2164 struct drm_info_node *node = (struct drm_info_node *)m->private;
2165 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002166 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002167 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002168 u32 status_pointer;
2169 u8 read_pointer;
2170 u8 write_pointer;
2171 u32 status;
2172 u32 ctx_id;
2173 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002174 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002175
2176 if (!i915.enable_execlists) {
2177 seq_puts(m, "Logical Ring Contexts are disabled\n");
2178 return 0;
2179 }
2180
2181 ret = mutex_lock_interruptible(&dev->struct_mutex);
2182 if (ret)
2183 return ret;
2184
Michel Thierryfc0412e2014-10-16 16:13:38 +01002185 intel_runtime_pm_get(dev_priv);
2186
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002187 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002188 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002189 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002190
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002191 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002192
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002193 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2194 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002195 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2196 status, ctx_id);
2197
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002198 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002199 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2200
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002201 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002202 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002203 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002204 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002205 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2206 read_pointer, write_pointer);
2207
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002208 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002209 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2210 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002211
2212 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2213 i, status, ctx_id);
2214 }
2215
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002216 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002217 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002218 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002219 head_req = list_first_entry_or_null(&engine->execlist_queue,
2220 struct drm_i915_gem_request,
2221 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002222 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002223
2224 seq_printf(m, "\t%d requests in queue\n", count);
2225 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002226 seq_printf(m, "\tHead request context: %u\n",
2227 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002228 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002229 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002230 }
2231
2232 seq_putc(m, '\n');
2233 }
2234
Michel Thierryfc0412e2014-10-16 16:13:38 +01002235 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002236 mutex_unlock(&dev->struct_mutex);
2237
2238 return 0;
2239}
2240
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002241static const char *swizzle_string(unsigned swizzle)
2242{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002243 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002244 case I915_BIT_6_SWIZZLE_NONE:
2245 return "none";
2246 case I915_BIT_6_SWIZZLE_9:
2247 return "bit9";
2248 case I915_BIT_6_SWIZZLE_9_10:
2249 return "bit9/bit10";
2250 case I915_BIT_6_SWIZZLE_9_11:
2251 return "bit9/bit11";
2252 case I915_BIT_6_SWIZZLE_9_10_11:
2253 return "bit9/bit10/bit11";
2254 case I915_BIT_6_SWIZZLE_9_17:
2255 return "bit9/bit17";
2256 case I915_BIT_6_SWIZZLE_9_10_17:
2257 return "bit9/bit10/bit17";
2258 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002259 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002260 }
2261
2262 return "bug";
2263}
2264
2265static int i915_swizzle_info(struct seq_file *m, void *data)
2266{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002267 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002268 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002269 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002270 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002271
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002272 ret = mutex_lock_interruptible(&dev->struct_mutex);
2273 if (ret)
2274 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002275 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002276
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002277 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2278 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2279 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2280 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2281
2282 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2283 seq_printf(m, "DDC = 0x%08x\n",
2284 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002285 seq_printf(m, "DDC2 = 0x%08x\n",
2286 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002287 seq_printf(m, "C0DRB3 = 0x%04x\n",
2288 I915_READ16(C0DRB3));
2289 seq_printf(m, "C1DRB3 = 0x%04x\n",
2290 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002291 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002292 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2293 I915_READ(MAD_DIMM_C0));
2294 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2295 I915_READ(MAD_DIMM_C1));
2296 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2297 I915_READ(MAD_DIMM_C2));
2298 seq_printf(m, "TILECTL = 0x%08x\n",
2299 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002300 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002301 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2302 I915_READ(GAMTARBMODE));
2303 else
2304 seq_printf(m, "ARB_MODE = 0x%08x\n",
2305 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002306 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2307 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002308 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002309
2310 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2311 seq_puts(m, "L-shaped memory detected\n");
2312
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002313 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002314 mutex_unlock(&dev->struct_mutex);
2315
2316 return 0;
2317}
2318
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002319static int per_file_ctx(int id, void *ptr, void *data)
2320{
Chris Wilsone2efd132016-05-24 14:53:34 +01002321 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002322 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002323 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2324
2325 if (!ppgtt) {
2326 seq_printf(m, " no ppgtt for context %d\n",
2327 ctx->user_handle);
2328 return 0;
2329 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002330
Oscar Mateof83d6512014-05-22 14:13:38 +01002331 if (i915_gem_context_is_default(ctx))
2332 seq_puts(m, " default context:\n");
2333 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002334 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002335 ppgtt->debug_dump(ppgtt, m);
2336
2337 return 0;
2338}
2339
Ben Widawsky77df6772013-11-02 21:07:30 -07002340static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002341{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002342 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002343 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002344 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002345 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002346
Ben Widawsky77df6772013-11-02 21:07:30 -07002347 if (!ppgtt)
2348 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002349
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002350 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002351 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002352 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002353 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002354 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002355 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002356 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002357 }
2358 }
2359}
2360
2361static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2362{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002363 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002364 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002365
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002366 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002367 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2368
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002369 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002370 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002371 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002372 seq_printf(m, "GFX_MODE: 0x%08x\n",
2373 I915_READ(RING_MODE_GEN7(engine)));
2374 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2375 I915_READ(RING_PP_DIR_BASE(engine)));
2376 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2377 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2378 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2379 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002380 }
2381 if (dev_priv->mm.aliasing_ppgtt) {
2382 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2383
Damien Lespiau267f0c92013-06-24 22:59:48 +01002384 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002385 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002386
Ben Widawsky87d60b62013-12-06 14:11:29 -08002387 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002388 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002389
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002390 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002391}
2392
2393static int i915_ppgtt_info(struct seq_file *m, void *data)
2394{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002395 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002396 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002397 struct drm_i915_private *dev_priv = to_i915(dev);
Michel Thierryea91e402015-07-29 17:23:57 +01002398 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002399
2400 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2401 if (ret)
2402 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002403 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002404
2405 if (INTEL_INFO(dev)->gen >= 8)
2406 gen8_ppgtt_info(m, dev);
2407 else if (INTEL_INFO(dev)->gen >= 6)
2408 gen6_ppgtt_info(m, dev);
2409
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002410 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002411 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2412 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002413 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002414
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002415 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002416 if (!task) {
2417 ret = -ESRCH;
Wei Yongjunb0212482016-06-13 23:42:00 +00002418 goto out_unlock;
Dan Carpenter06812762015-10-02 18:14:22 +03002419 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002420 seq_printf(m, "\nproc: %s\n", task->comm);
2421 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002422 idr_for_each(&file_priv->context_idr, per_file_ctx,
2423 (void *)(unsigned long)m);
2424 }
Wei Yongjunb0212482016-06-13 23:42:00 +00002425out_unlock:
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002426 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002427
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002428 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002429 mutex_unlock(&dev->struct_mutex);
2430
Dan Carpenter06812762015-10-02 18:14:22 +03002431 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002432}
2433
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002434static int count_irq_waiters(struct drm_i915_private *i915)
2435{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002436 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002437 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002438
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002439 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002440 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002441
2442 return count;
2443}
2444
Chris Wilson1854d5c2015-04-07 16:20:32 +01002445static int i915_rps_boost_info(struct seq_file *m, void *data)
2446{
2447 struct drm_info_node *node = m->private;
2448 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002449 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002450 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002451
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002452 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002453 seq_printf(m, "GPU busy? %s [%x]\n",
2454 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002455 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2456 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2457 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2458 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2459 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2460 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2461 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002462
2463 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002464 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002465 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2466 struct drm_i915_file_private *file_priv = file->driver_priv;
2467 struct task_struct *task;
2468
2469 rcu_read_lock();
2470 task = pid_task(file->pid, PIDTYPE_PID);
2471 seq_printf(m, "%s [%d]: %d boosts%s\n",
2472 task ? task->comm : "<unknown>",
2473 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002474 file_priv->rps.boosts,
2475 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002476 rcu_read_unlock();
2477 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002478 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002479 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002480 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002481
Chris Wilson8d3afd72015-05-21 21:01:47 +01002482 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002483}
2484
Ben Widawsky63573eb2013-07-04 11:02:07 -07002485static int i915_llc(struct seq_file *m, void *data)
2486{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002487 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002488 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002489 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002490 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002491
Ben Widawsky63573eb2013-07-04 11:02:07 -07002492 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002493 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2494 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002495
2496 return 0;
2497}
2498
Alex Daifdf5d352015-08-12 15:43:37 +01002499static int i915_guc_load_status_info(struct seq_file *m, void *data)
2500{
2501 struct drm_info_node *node = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002502 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
Alex Daifdf5d352015-08-12 15:43:37 +01002503 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2504 u32 tmp, i;
2505
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002506 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002507 return 0;
2508
2509 seq_printf(m, "GuC firmware status:\n");
2510 seq_printf(m, "\tpath: %s\n",
2511 guc_fw->guc_fw_path);
2512 seq_printf(m, "\tfetch: %s\n",
2513 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2514 seq_printf(m, "\tload: %s\n",
2515 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2516 seq_printf(m, "\tversion wanted: %d.%d\n",
2517 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2518 seq_printf(m, "\tversion found: %d.%d\n",
2519 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002520 seq_printf(m, "\theader: offset is %d; size = %d\n",
2521 guc_fw->header_offset, guc_fw->header_size);
2522 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2523 guc_fw->ucode_offset, guc_fw->ucode_size);
2524 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2525 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002526
2527 tmp = I915_READ(GUC_STATUS);
2528
2529 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2530 seq_printf(m, "\tBootrom status = 0x%x\n",
2531 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2532 seq_printf(m, "\tuKernel status = 0x%x\n",
2533 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2534 seq_printf(m, "\tMIA Core status = 0x%x\n",
2535 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2536 seq_puts(m, "\nScratch registers:\n");
2537 for (i = 0; i < 16; i++)
2538 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2539
2540 return 0;
2541}
2542
Dave Gordon8b417c22015-08-12 15:43:44 +01002543static void i915_guc_client_info(struct seq_file *m,
2544 struct drm_i915_private *dev_priv,
2545 struct i915_guc_client *client)
2546{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002547 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002548 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002549
2550 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2551 client->priority, client->ctx_index, client->proc_desc_offset);
2552 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2553 client->doorbell_id, client->doorbell_offset, client->cookie);
2554 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2555 client->wq_size, client->wq_offset, client->wq_tail);
2556
Dave Gordon551aaec2016-05-13 15:36:33 +01002557 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002558 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2559 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2560 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2561
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002562 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002563 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordon0b63bb12016-06-20 15:18:07 +01002564 client->submissions[engine->id],
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002565 engine->name);
Dave Gordon0b63bb12016-06-20 15:18:07 +01002566 tot += client->submissions[engine->id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002567 }
2568 seq_printf(m, "\tTotal: %llu\n", tot);
2569}
2570
2571static int i915_guc_info(struct seq_file *m, void *data)
2572{
2573 struct drm_info_node *node = m->private;
2574 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002575 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Gordon8b417c22015-08-12 15:43:44 +01002576 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002577 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002578 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002579 u64 total = 0;
2580
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002581 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002582 return 0;
2583
Alex Dai5a843302015-12-02 16:56:29 -08002584 if (mutex_lock_interruptible(&dev->struct_mutex))
2585 return 0;
2586
Dave Gordon8b417c22015-08-12 15:43:44 +01002587 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002588 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002589 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002590 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002591
2592 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002593
Dave Gordon9636f6d2016-06-13 17:57:28 +01002594 seq_printf(m, "Doorbell map:\n");
2595 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2596 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2597
Dave Gordon8b417c22015-08-12 15:43:44 +01002598 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2599 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2600 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2601 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2602 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2603
2604 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002605 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002606 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordon0b63bb12016-06-20 15:18:07 +01002607 engine->name, guc.submissions[engine->id],
2608 guc.last_seqno[engine->id]);
2609 total += guc.submissions[engine->id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002610 }
2611 seq_printf(m, "\t%s: %llu\n", "Total", total);
2612
2613 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2614 i915_guc_client_info(m, dev_priv, &client);
2615
2616 /* Add more as required ... */
2617
2618 return 0;
2619}
2620
Alex Dai4c7e77f2015-08-12 15:43:40 +01002621static int i915_guc_log_dump(struct seq_file *m, void *data)
2622{
2623 struct drm_info_node *node = m->private;
2624 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002625 struct drm_i915_private *dev_priv = to_i915(dev);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002626 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2627 u32 *log;
2628 int i = 0, pg;
2629
2630 if (!log_obj)
2631 return 0;
2632
2633 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2634 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2635
2636 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2637 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2638 *(log + i), *(log + i + 1),
2639 *(log + i + 2), *(log + i + 3));
2640
2641 kunmap_atomic(log);
2642 }
2643
2644 seq_putc(m, '\n');
2645
2646 return 0;
2647}
2648
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002649static int i915_edp_psr_status(struct seq_file *m, void *data)
2650{
2651 struct drm_info_node *node = m->private;
2652 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002653 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002654 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002655 u32 stat[3];
2656 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002657 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002658
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002659 if (!HAS_PSR(dev)) {
2660 seq_puts(m, "PSR not supported\n");
2661 return 0;
2662 }
2663
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002664 intel_runtime_pm_get(dev_priv);
2665
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002666 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002667 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2668 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002669 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002670 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002671 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2672 dev_priv->psr.busy_frontbuffer_bits);
2673 seq_printf(m, "Re-enable work scheduled: %s\n",
2674 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002675
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002676 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002677 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002678 else {
2679 for_each_pipe(dev_priv, pipe) {
2680 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2681 VLV_EDP_PSR_CURR_STATE_MASK;
2682 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2683 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2684 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002685 }
2686 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002687
2688 seq_printf(m, "Main link in standby mode: %s\n",
2689 yesno(dev_priv->psr.link_standby));
2690
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002691 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002692
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002693 if (!HAS_DDI(dev))
2694 for_each_pipe(dev_priv, pipe) {
2695 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2696 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2697 seq_printf(m, " pipe %c", pipe_name(pipe));
2698 }
2699 seq_puts(m, "\n");
2700
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002701 /*
2702 * VLV/CHV PSR has no kind of performance counter
2703 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2704 */
2705 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002706 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002707 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002708
2709 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2710 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002711 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002712
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002713 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002714 return 0;
2715}
2716
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002717static int i915_sink_crc(struct seq_file *m, void *data)
2718{
2719 struct drm_info_node *node = m->private;
2720 struct drm_device *dev = node->minor->dev;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002721 struct intel_connector *connector;
2722 struct intel_dp *intel_dp = NULL;
2723 int ret;
2724 u8 crc[6];
2725
2726 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002727 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002728 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002729
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002730 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002731 continue;
2732
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002733 crtc = connector->base.state->crtc;
2734 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002735 continue;
2736
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002737 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002738 continue;
2739
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002740 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002741
2742 ret = intel_dp_sink_crc(intel_dp, crc);
2743 if (ret)
2744 goto out;
2745
2746 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2747 crc[0], crc[1], crc[2],
2748 crc[3], crc[4], crc[5]);
2749 goto out;
2750 }
2751 ret = -ENODEV;
2752out:
2753 drm_modeset_unlock_all(dev);
2754 return ret;
2755}
2756
Jesse Barnesec013e72013-08-20 10:29:23 +01002757static int i915_energy_uJ(struct seq_file *m, void *data)
2758{
2759 struct drm_info_node *node = m->private;
2760 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002761 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesec013e72013-08-20 10:29:23 +01002762 u64 power;
2763 u32 units;
2764
2765 if (INTEL_INFO(dev)->gen < 6)
2766 return -ENODEV;
2767
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002768 intel_runtime_pm_get(dev_priv);
2769
Jesse Barnesec013e72013-08-20 10:29:23 +01002770 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2771 power = (power & 0x1f00) >> 8;
2772 units = 1000000 / (1 << power); /* convert to uJ */
2773 power = I915_READ(MCH_SECP_NRG_STTS);
2774 power *= units;
2775
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002776 intel_runtime_pm_put(dev_priv);
2777
Jesse Barnesec013e72013-08-20 10:29:23 +01002778 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002779
2780 return 0;
2781}
2782
Damien Lespiau6455c872015-06-04 18:23:57 +01002783static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002784{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002785 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002786 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002787 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni371db662013-08-19 13:18:10 -03002788
Chris Wilsona156e642016-04-03 14:14:21 +01002789 if (!HAS_RUNTIME_PM(dev_priv))
2790 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002791
Chris Wilson67d97da2016-07-04 08:08:31 +01002792 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002793 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002794 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002795#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002796 seq_printf(m, "Usage count: %d\n",
2797 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002798#else
2799 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2800#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002801 seq_printf(m, "PCI device power state: %s [%d]\n",
Chris Wilson91c8a322016-07-05 10:40:23 +01002802 pci_power_name(dev_priv->drm.pdev->current_state),
2803 dev_priv->drm.pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002804
Jesse Barnesec013e72013-08-20 10:29:23 +01002805 return 0;
2806}
2807
Imre Deak1da51582013-11-25 17:15:35 +02002808static int i915_power_domain_info(struct seq_file *m, void *unused)
2809{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002810 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002811 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002812 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1da51582013-11-25 17:15:35 +02002813 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2814 int i;
2815
2816 mutex_lock(&power_domains->lock);
2817
2818 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2819 for (i = 0; i < power_domains->power_well_count; i++) {
2820 struct i915_power_well *power_well;
2821 enum intel_display_power_domain power_domain;
2822
2823 power_well = &power_domains->power_wells[i];
2824 seq_printf(m, "%-25s %d\n", power_well->name,
2825 power_well->count);
2826
2827 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2828 power_domain++) {
2829 if (!(BIT(power_domain) & power_well->domains))
2830 continue;
2831
2832 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002833 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002834 power_domains->domain_use_count[power_domain]);
2835 }
2836 }
2837
2838 mutex_unlock(&power_domains->lock);
2839
2840 return 0;
2841}
2842
Damien Lespiaub7cec662015-10-27 14:47:01 +02002843static int i915_dmc_info(struct seq_file *m, void *unused)
2844{
2845 struct drm_info_node *node = m->private;
2846 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002847 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002848 struct intel_csr *csr;
2849
2850 if (!HAS_CSR(dev)) {
2851 seq_puts(m, "not supported\n");
2852 return 0;
2853 }
2854
2855 csr = &dev_priv->csr;
2856
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002857 intel_runtime_pm_get(dev_priv);
2858
Damien Lespiaub7cec662015-10-27 14:47:01 +02002859 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2860 seq_printf(m, "path: %s\n", csr->fw_path);
2861
2862 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002863 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002864
2865 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2866 CSR_VERSION_MINOR(csr->version));
2867
Damien Lespiau83372062015-10-30 17:53:32 +02002868 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2869 seq_printf(m, "DC3 -> DC5 count: %d\n",
2870 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2871 seq_printf(m, "DC5 -> DC6 count: %d\n",
2872 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002873 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2874 seq_printf(m, "DC3 -> DC5 count: %d\n",
2875 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002876 }
2877
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002878out:
2879 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2880 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2881 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2882
Damien Lespiau83372062015-10-30 17:53:32 +02002883 intel_runtime_pm_put(dev_priv);
2884
Damien Lespiaub7cec662015-10-27 14:47:01 +02002885 return 0;
2886}
2887
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002888static void intel_seq_print_mode(struct seq_file *m, int tabs,
2889 struct drm_display_mode *mode)
2890{
2891 int i;
2892
2893 for (i = 0; i < tabs; i++)
2894 seq_putc(m, '\t');
2895
2896 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",
2897 mode->base.id, mode->name,
2898 mode->vrefresh, mode->clock,
2899 mode->hdisplay, mode->hsync_start,
2900 mode->hsync_end, mode->htotal,
2901 mode->vdisplay, mode->vsync_start,
2902 mode->vsync_end, mode->vtotal,
2903 mode->type, mode->flags);
2904}
2905
2906static void intel_encoder_info(struct seq_file *m,
2907 struct intel_crtc *intel_crtc,
2908 struct intel_encoder *intel_encoder)
2909{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002910 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002911 struct drm_device *dev = node->minor->dev;
2912 struct drm_crtc *crtc = &intel_crtc->base;
2913 struct intel_connector *intel_connector;
2914 struct drm_encoder *encoder;
2915
2916 encoder = &intel_encoder->base;
2917 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002918 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002919 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2920 struct drm_connector *connector = &intel_connector->base;
2921 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2922 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002923 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002924 drm_get_connector_status_name(connector->status));
2925 if (connector->status == connector_status_connected) {
2926 struct drm_display_mode *mode = &crtc->mode;
2927 seq_printf(m, ", mode:\n");
2928 intel_seq_print_mode(m, 2, mode);
2929 } else {
2930 seq_putc(m, '\n');
2931 }
2932 }
2933}
2934
2935static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2936{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002937 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002938 struct drm_device *dev = node->minor->dev;
2939 struct drm_crtc *crtc = &intel_crtc->base;
2940 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002941 struct drm_plane_state *plane_state = crtc->primary->state;
2942 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002943
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002944 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002945 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002946 fb->base.id, plane_state->src_x >> 16,
2947 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002948 else
2949 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002950 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2951 intel_encoder_info(m, intel_crtc, intel_encoder);
2952}
2953
2954static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2955{
2956 struct drm_display_mode *mode = panel->fixed_mode;
2957
2958 seq_printf(m, "\tfixed mode:\n");
2959 intel_seq_print_mode(m, 2, mode);
2960}
2961
2962static void intel_dp_info(struct seq_file *m,
2963 struct intel_connector *intel_connector)
2964{
2965 struct intel_encoder *intel_encoder = intel_connector->encoder;
2966 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2967
2968 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002969 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002970 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002971 intel_panel_info(m, &intel_connector->panel);
2972}
2973
2974static void intel_hdmi_info(struct seq_file *m,
2975 struct intel_connector *intel_connector)
2976{
2977 struct intel_encoder *intel_encoder = intel_connector->encoder;
2978 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2979
Jani Nikula742f4912015-09-03 11:16:09 +03002980 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002981}
2982
2983static void intel_lvds_info(struct seq_file *m,
2984 struct intel_connector *intel_connector)
2985{
2986 intel_panel_info(m, &intel_connector->panel);
2987}
2988
2989static void intel_connector_info(struct seq_file *m,
2990 struct drm_connector *connector)
2991{
2992 struct intel_connector *intel_connector = to_intel_connector(connector);
2993 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002994 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002995
2996 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002997 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002998 drm_get_connector_status_name(connector->status));
2999 if (connector->status == connector_status_connected) {
3000 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3001 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3002 connector->display_info.width_mm,
3003 connector->display_info.height_mm);
3004 seq_printf(m, "\tsubpixel order: %s\n",
3005 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3006 seq_printf(m, "\tCEA rev: %d\n",
3007 connector->display_info.cea_rev);
3008 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003009
3010 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3011 return;
3012
3013 switch (connector->connector_type) {
3014 case DRM_MODE_CONNECTOR_DisplayPort:
3015 case DRM_MODE_CONNECTOR_eDP:
3016 intel_dp_info(m, intel_connector);
3017 break;
3018 case DRM_MODE_CONNECTOR_LVDS:
3019 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003020 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003021 break;
3022 case DRM_MODE_CONNECTOR_HDMIA:
3023 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3024 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3025 intel_hdmi_info(m, intel_connector);
3026 break;
3027 default:
3028 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003029 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003030
Jesse Barnesf103fc72014-02-20 12:39:57 -08003031 seq_printf(m, "\tmodes:\n");
3032 list_for_each_entry(mode, &connector->modes, head)
3033 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003034}
3035
Chris Wilson065f2ec2014-03-12 09:13:13 +00003036static bool cursor_active(struct drm_device *dev, int pipe)
3037{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003038 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003039 u32 state;
3040
3041 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003042 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003043 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003044 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003045
3046 return state;
3047}
3048
3049static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
3050{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003051 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003052 u32 pos;
3053
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003054 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003055
3056 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3057 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3058 *x = -*x;
3059
3060 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3061 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3062 *y = -*y;
3063
3064 return cursor_active(dev, pipe);
3065}
3066
Robert Fekete3abc4e02015-10-27 16:58:32 +01003067static const char *plane_type(enum drm_plane_type type)
3068{
3069 switch (type) {
3070 case DRM_PLANE_TYPE_OVERLAY:
3071 return "OVL";
3072 case DRM_PLANE_TYPE_PRIMARY:
3073 return "PRI";
3074 case DRM_PLANE_TYPE_CURSOR:
3075 return "CUR";
3076 /*
3077 * Deliberately omitting default: to generate compiler warnings
3078 * when a new drm_plane_type gets added.
3079 */
3080 }
3081
3082 return "unknown";
3083}
3084
3085static const char *plane_rotation(unsigned int rotation)
3086{
3087 static char buf[48];
3088 /*
3089 * According to doc only one DRM_ROTATE_ is allowed but this
3090 * will print them all to visualize if the values are misused
3091 */
3092 snprintf(buf, sizeof(buf),
3093 "%s%s%s%s%s%s(0x%08x)",
3094 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3095 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3096 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3097 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3098 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3099 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3100 rotation);
3101
3102 return buf;
3103}
3104
3105static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3106{
3107 struct drm_info_node *node = m->private;
3108 struct drm_device *dev = node->minor->dev;
3109 struct intel_plane *intel_plane;
3110
3111 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3112 struct drm_plane_state *state;
3113 struct drm_plane *plane = &intel_plane->base;
3114
3115 if (!plane->state) {
3116 seq_puts(m, "plane->state is NULL!\n");
3117 continue;
3118 }
3119
3120 state = plane->state;
3121
3122 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",
3123 plane->base.id,
3124 plane_type(intel_plane->base.type),
3125 state->crtc_x, state->crtc_y,
3126 state->crtc_w, state->crtc_h,
3127 (state->src_x >> 16),
3128 ((state->src_x & 0xffff) * 15625) >> 10,
3129 (state->src_y >> 16),
3130 ((state->src_y & 0xffff) * 15625) >> 10,
3131 (state->src_w >> 16),
3132 ((state->src_w & 0xffff) * 15625) >> 10,
3133 (state->src_h >> 16),
3134 ((state->src_h & 0xffff) * 15625) >> 10,
3135 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3136 plane_rotation(state->rotation));
3137 }
3138}
3139
3140static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3141{
3142 struct intel_crtc_state *pipe_config;
3143 int num_scalers = intel_crtc->num_scalers;
3144 int i;
3145
3146 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3147
3148 /* Not all platformas have a scaler */
3149 if (num_scalers) {
3150 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3151 num_scalers,
3152 pipe_config->scaler_state.scaler_users,
3153 pipe_config->scaler_state.scaler_id);
3154
3155 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3156 struct intel_scaler *sc =
3157 &pipe_config->scaler_state.scalers[i];
3158
3159 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3160 i, yesno(sc->in_use), sc->mode);
3161 }
3162 seq_puts(m, "\n");
3163 } else {
3164 seq_puts(m, "\tNo scalers available on this platform\n");
3165 }
3166}
3167
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003168static int i915_display_info(struct seq_file *m, void *unused)
3169{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003170 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003171 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003172 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003173 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003174 struct drm_connector *connector;
3175
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003176 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003177 drm_modeset_lock_all(dev);
3178 seq_printf(m, "CRTC info\n");
3179 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003180 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003181 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003182 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003183 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003184
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003185 pipe_config = to_intel_crtc_state(crtc->base.state);
3186
Robert Fekete3abc4e02015-10-27 16:58:32 +01003187 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003188 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003189 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003190 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3191 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3192
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003193 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003194 intel_crtc_info(m, crtc);
3195
Paulo Zanonia23dc652014-04-01 14:55:11 -03003196 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003197 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 +03003198 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003199 x, y, crtc->base.cursor->state->crtc_w,
3200 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003201 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003202 intel_scaler_info(m, crtc);
3203 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003204 }
Daniel Vettercace8412014-05-22 17:56:31 +02003205
3206 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3207 yesno(!crtc->cpu_fifo_underrun_disabled),
3208 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003209 }
3210
3211 seq_printf(m, "\n");
3212 seq_printf(m, "Connector info\n");
3213 seq_printf(m, "--------------\n");
3214 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3215 intel_connector_info(m, connector);
3216 }
3217 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003218 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003219
3220 return 0;
3221}
3222
Ben Widawskye04934c2014-06-30 09:53:42 -07003223static int i915_semaphore_status(struct seq_file *m, void *unused)
3224{
3225 struct drm_info_node *node = (struct drm_info_node *) m->private;
3226 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003227 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003228 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003229 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003230 enum intel_engine_id id;
3231 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003232
Chris Wilson39df9192016-07-20 13:31:57 +01003233 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003234 seq_puts(m, "Semaphores are disabled\n");
3235 return 0;
3236 }
3237
3238 ret = mutex_lock_interruptible(&dev->struct_mutex);
3239 if (ret)
3240 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003241 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003242
3243 if (IS_BROADWELL(dev)) {
3244 struct page *page;
3245 uint64_t *seqno;
3246
3247 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3248
3249 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003250 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003251 uint64_t offset;
3252
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003253 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003254
3255 seq_puts(m, " Last signal:");
3256 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003257 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003258 seq_printf(m, "0x%08llx (0x%02llx) ",
3259 seqno[offset], offset * 8);
3260 }
3261 seq_putc(m, '\n');
3262
3263 seq_puts(m, " Last wait: ");
3264 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003265 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003266 seq_printf(m, "0x%08llx (0x%02llx) ",
3267 seqno[offset], offset * 8);
3268 }
3269 seq_putc(m, '\n');
3270
3271 }
3272 kunmap_atomic(seqno);
3273 } else {
3274 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003275 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003276 for (j = 0; j < num_rings; j++)
3277 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003278 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003279 seq_putc(m, '\n');
3280 }
3281
3282 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003283 for_each_engine(engine, dev_priv) {
3284 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003285 seq_printf(m, " 0x%08x ",
3286 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003287 seq_putc(m, '\n');
3288 }
3289 seq_putc(m, '\n');
3290
Paulo Zanoni03872062014-07-09 14:31:57 -03003291 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003292 mutex_unlock(&dev->struct_mutex);
3293 return 0;
3294}
3295
Daniel Vetter728e29d2014-06-25 22:01:53 +03003296static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3297{
3298 struct drm_info_node *node = (struct drm_info_node *) m->private;
3299 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003300 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003301 int i;
3302
3303 drm_modeset_lock_all(dev);
3304 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3305 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3306
3307 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003308 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3309 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003310 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003311 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3312 seq_printf(m, " dpll_md: 0x%08x\n",
3313 pll->config.hw_state.dpll_md);
3314 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3315 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3316 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003317 }
3318 drm_modeset_unlock_all(dev);
3319
3320 return 0;
3321}
3322
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003323static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003324{
3325 int i;
3326 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003327 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003328 struct drm_info_node *node = (struct drm_info_node *) m->private;
3329 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003330 struct drm_i915_private *dev_priv = to_i915(dev);
Arun Siluvery33136b02016-01-21 21:43:47 +00003331 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003332 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003333
Arun Siluvery888b5992014-08-26 14:44:51 +01003334 ret = mutex_lock_interruptible(&dev->struct_mutex);
3335 if (ret)
3336 return ret;
3337
3338 intel_runtime_pm_get(dev_priv);
3339
Arun Siluvery33136b02016-01-21 21:43:47 +00003340 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003341 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003342 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003343 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003344 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003345 i915_reg_t addr;
3346 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003347 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003348
Arun Siluvery33136b02016-01-21 21:43:47 +00003349 addr = workarounds->reg[i].addr;
3350 mask = workarounds->reg[i].mask;
3351 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003352 read = I915_READ(addr);
3353 ok = (value & mask) == (read & mask);
3354 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 +02003355 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003356 }
3357
3358 intel_runtime_pm_put(dev_priv);
3359 mutex_unlock(&dev->struct_mutex);
3360
3361 return 0;
3362}
3363
Damien Lespiauc5511e42014-11-04 17:06:51 +00003364static int i915_ddb_info(struct seq_file *m, void *unused)
3365{
3366 struct drm_info_node *node = m->private;
3367 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003368 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiauc5511e42014-11-04 17:06:51 +00003369 struct skl_ddb_allocation *ddb;
3370 struct skl_ddb_entry *entry;
3371 enum pipe pipe;
3372 int plane;
3373
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003374 if (INTEL_INFO(dev)->gen < 9)
3375 return 0;
3376
Damien Lespiauc5511e42014-11-04 17:06:51 +00003377 drm_modeset_lock_all(dev);
3378
3379 ddb = &dev_priv->wm.skl_hw.ddb;
3380
3381 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3382
3383 for_each_pipe(dev_priv, pipe) {
3384 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3385
Damien Lespiaudd740782015-02-28 14:54:08 +00003386 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003387 entry = &ddb->plane[pipe][plane];
3388 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3389 entry->start, entry->end,
3390 skl_ddb_entry_size(entry));
3391 }
3392
Matt Roper4969d332015-09-24 15:53:10 -07003393 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003394 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3395 entry->end, skl_ddb_entry_size(entry));
3396 }
3397
3398 drm_modeset_unlock_all(dev);
3399
3400 return 0;
3401}
3402
Vandana Kannana54746e2015-03-03 20:53:10 +05303403static void drrs_status_per_crtc(struct seq_file *m,
3404 struct drm_device *dev, struct intel_crtc *intel_crtc)
3405{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003406 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303407 struct i915_drrs *drrs = &dev_priv->drrs;
3408 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003409 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303410
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003411 drm_for_each_connector(connector, dev) {
3412 if (connector->state->crtc != &intel_crtc->base)
3413 continue;
3414
3415 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303416 }
3417
3418 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3419 seq_puts(m, "\tVBT: DRRS_type: Static");
3420 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3421 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3422 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3423 seq_puts(m, "\tVBT: DRRS_type: None");
3424 else
3425 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3426
3427 seq_puts(m, "\n\n");
3428
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003429 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303430 struct intel_panel *panel;
3431
3432 mutex_lock(&drrs->mutex);
3433 /* DRRS Supported */
3434 seq_puts(m, "\tDRRS Supported: Yes\n");
3435
3436 /* disable_drrs() will make drrs->dp NULL */
3437 if (!drrs->dp) {
3438 seq_puts(m, "Idleness DRRS: Disabled");
3439 mutex_unlock(&drrs->mutex);
3440 return;
3441 }
3442
3443 panel = &drrs->dp->attached_connector->panel;
3444 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3445 drrs->busy_frontbuffer_bits);
3446
3447 seq_puts(m, "\n\t\t");
3448 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3449 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3450 vrefresh = panel->fixed_mode->vrefresh;
3451 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3452 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3453 vrefresh = panel->downclock_mode->vrefresh;
3454 } else {
3455 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3456 drrs->refresh_rate_type);
3457 mutex_unlock(&drrs->mutex);
3458 return;
3459 }
3460 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3461
3462 seq_puts(m, "\n\t\t");
3463 mutex_unlock(&drrs->mutex);
3464 } else {
3465 /* DRRS not supported. Print the VBT parameter*/
3466 seq_puts(m, "\tDRRS Supported : No");
3467 }
3468 seq_puts(m, "\n");
3469}
3470
3471static int i915_drrs_status(struct seq_file *m, void *unused)
3472{
3473 struct drm_info_node *node = m->private;
3474 struct drm_device *dev = node->minor->dev;
3475 struct intel_crtc *intel_crtc;
3476 int active_crtc_cnt = 0;
3477
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003478 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303479 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003480 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303481 active_crtc_cnt++;
3482 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3483
3484 drrs_status_per_crtc(m, dev, intel_crtc);
3485 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303486 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003487 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303488
3489 if (!active_crtc_cnt)
3490 seq_puts(m, "No active crtc found\n");
3491
3492 return 0;
3493}
3494
Damien Lespiau07144422013-10-15 18:55:40 +01003495struct pipe_crc_info {
3496 const char *name;
3497 struct drm_device *dev;
3498 enum pipe pipe;
3499};
3500
Dave Airlie11bed952014-05-12 15:22:27 +10003501static int i915_dp_mst_info(struct seq_file *m, void *unused)
3502{
3503 struct drm_info_node *node = (struct drm_info_node *) m->private;
3504 struct drm_device *dev = node->minor->dev;
Dave Airlie11bed952014-05-12 15:22:27 +10003505 struct intel_encoder *intel_encoder;
3506 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003507 struct drm_connector *connector;
3508
Dave Airlie11bed952014-05-12 15:22:27 +10003509 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003510 drm_for_each_connector(connector, dev) {
3511 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003512 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003513
3514 intel_encoder = intel_attached_encoder(connector);
3515 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3516 continue;
3517
3518 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003519 if (!intel_dig_port->dp.can_mst)
3520 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003521
Jim Bride40ae80c2016-04-14 10:18:37 -07003522 seq_printf(m, "MST Source Port %c\n",
3523 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003524 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3525 }
3526 drm_modeset_unlock_all(dev);
3527 return 0;
3528}
3529
Damien Lespiau07144422013-10-15 18:55:40 +01003530static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003531{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003532 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003533 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003534 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3535
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003536 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3537 return -ENODEV;
3538
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003539 spin_lock_irq(&pipe_crc->lock);
3540
3541 if (pipe_crc->opened) {
3542 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003543 return -EBUSY; /* already open */
3544 }
3545
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003546 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003547 filep->private_data = inode->i_private;
3548
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003549 spin_unlock_irq(&pipe_crc->lock);
3550
Damien Lespiau07144422013-10-15 18:55:40 +01003551 return 0;
3552}
3553
3554static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3555{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003556 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003557 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003558 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3559
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003560 spin_lock_irq(&pipe_crc->lock);
3561 pipe_crc->opened = false;
3562 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003563
Damien Lespiau07144422013-10-15 18:55:40 +01003564 return 0;
3565}
3566
3567/* (6 fields, 8 chars each, space separated (5) + '\n') */
3568#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3569/* account for \'0' */
3570#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3571
3572static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3573{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003574 assert_spin_locked(&pipe_crc->lock);
3575 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3576 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003577}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003578
Damien Lespiau07144422013-10-15 18:55:40 +01003579static ssize_t
3580i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3581 loff_t *pos)
3582{
3583 struct pipe_crc_info *info = filep->private_data;
3584 struct drm_device *dev = info->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003585 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003586 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3587 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003588 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003589 ssize_t bytes_read;
3590
3591 /*
3592 * Don't allow user space to provide buffers not big enough to hold
3593 * a line of data.
3594 */
3595 if (count < PIPE_CRC_LINE_LEN)
3596 return -EINVAL;
3597
3598 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3599 return 0;
3600
3601 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003602 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003603 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003604 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003605
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003606 if (filep->f_flags & O_NONBLOCK) {
3607 spin_unlock_irq(&pipe_crc->lock);
3608 return -EAGAIN;
3609 }
3610
3611 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3612 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3613 if (ret) {
3614 spin_unlock_irq(&pipe_crc->lock);
3615 return ret;
3616 }
Damien Lespiau07144422013-10-15 18:55:40 +01003617 }
3618
3619 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003620 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003621
Damien Lespiau07144422013-10-15 18:55:40 +01003622 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003623 while (n_entries > 0) {
3624 struct intel_pipe_crc_entry *entry =
3625 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003626 int ret;
3627
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003628 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3629 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3630 break;
3631
3632 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3633 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3634
Damien Lespiau07144422013-10-15 18:55:40 +01003635 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3636 "%8u %8x %8x %8x %8x %8x\n",
3637 entry->frame, entry->crc[0],
3638 entry->crc[1], entry->crc[2],
3639 entry->crc[3], entry->crc[4]);
3640
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003641 spin_unlock_irq(&pipe_crc->lock);
3642
3643 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003644 if (ret == PIPE_CRC_LINE_LEN)
3645 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003646
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003647 user_buf += PIPE_CRC_LINE_LEN;
3648 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003649
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003650 spin_lock_irq(&pipe_crc->lock);
3651 }
3652
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003653 spin_unlock_irq(&pipe_crc->lock);
3654
Damien Lespiau07144422013-10-15 18:55:40 +01003655 return bytes_read;
3656}
3657
3658static const struct file_operations i915_pipe_crc_fops = {
3659 .owner = THIS_MODULE,
3660 .open = i915_pipe_crc_open,
3661 .read = i915_pipe_crc_read,
3662 .release = i915_pipe_crc_release,
3663};
3664
3665static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3666 {
3667 .name = "i915_pipe_A_crc",
3668 .pipe = PIPE_A,
3669 },
3670 {
3671 .name = "i915_pipe_B_crc",
3672 .pipe = PIPE_B,
3673 },
3674 {
3675 .name = "i915_pipe_C_crc",
3676 .pipe = PIPE_C,
3677 },
3678};
3679
3680static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3681 enum pipe pipe)
3682{
3683 struct drm_device *dev = minor->dev;
3684 struct dentry *ent;
3685 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3686
3687 info->dev = dev;
3688 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3689 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003690 if (!ent)
3691 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003692
3693 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003694}
3695
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003696static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003697 "none",
3698 "plane1",
3699 "plane2",
3700 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003701 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003702 "TV",
3703 "DP-B",
3704 "DP-C",
3705 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003706 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003707};
3708
3709static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3710{
3711 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3712 return pipe_crc_sources[source];
3713}
3714
Damien Lespiaubd9db022013-10-15 18:55:36 +01003715static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003716{
3717 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003718 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003719 int i;
3720
3721 for (i = 0; i < I915_MAX_PIPES; i++)
3722 seq_printf(m, "%c %s\n", pipe_name(i),
3723 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3724
3725 return 0;
3726}
3727
Damien Lespiaubd9db022013-10-15 18:55:36 +01003728static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003729{
3730 struct drm_device *dev = inode->i_private;
3731
Damien Lespiaubd9db022013-10-15 18:55:36 +01003732 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003733}
3734
Daniel Vetter46a19182013-11-01 10:50:20 +01003735static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003736 uint32_t *val)
3737{
Daniel Vetter46a19182013-11-01 10:50:20 +01003738 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3739 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3740
3741 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003742 case INTEL_PIPE_CRC_SOURCE_PIPE:
3743 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3744 break;
3745 case INTEL_PIPE_CRC_SOURCE_NONE:
3746 *val = 0;
3747 break;
3748 default:
3749 return -EINVAL;
3750 }
3751
3752 return 0;
3753}
3754
Daniel Vetter46a19182013-11-01 10:50:20 +01003755static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3756 enum intel_pipe_crc_source *source)
3757{
3758 struct intel_encoder *encoder;
3759 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003760 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003761 int ret = 0;
3762
3763 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3764
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003765 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003766 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003767 if (!encoder->base.crtc)
3768 continue;
3769
3770 crtc = to_intel_crtc(encoder->base.crtc);
3771
3772 if (crtc->pipe != pipe)
3773 continue;
3774
3775 switch (encoder->type) {
3776 case INTEL_OUTPUT_TVOUT:
3777 *source = INTEL_PIPE_CRC_SOURCE_TV;
3778 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003779 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003780 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003781 dig_port = enc_to_dig_port(&encoder->base);
3782 switch (dig_port->port) {
3783 case PORT_B:
3784 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3785 break;
3786 case PORT_C:
3787 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3788 break;
3789 case PORT_D:
3790 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3791 break;
3792 default:
3793 WARN(1, "nonexisting DP port %c\n",
3794 port_name(dig_port->port));
3795 break;
3796 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003797 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003798 default:
3799 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003800 }
3801 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003802 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003803
3804 return ret;
3805}
3806
3807static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3808 enum pipe pipe,
3809 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003810 uint32_t *val)
3811{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003812 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003813 bool need_stable_symbols = false;
3814
Daniel Vetter46a19182013-11-01 10:50:20 +01003815 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3816 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3817 if (ret)
3818 return ret;
3819 }
3820
3821 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003822 case INTEL_PIPE_CRC_SOURCE_PIPE:
3823 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3824 break;
3825 case INTEL_PIPE_CRC_SOURCE_DP_B:
3826 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003827 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003828 break;
3829 case INTEL_PIPE_CRC_SOURCE_DP_C:
3830 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003831 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003832 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003833 case INTEL_PIPE_CRC_SOURCE_DP_D:
3834 if (!IS_CHERRYVIEW(dev))
3835 return -EINVAL;
3836 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3837 need_stable_symbols = true;
3838 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003839 case INTEL_PIPE_CRC_SOURCE_NONE:
3840 *val = 0;
3841 break;
3842 default:
3843 return -EINVAL;
3844 }
3845
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003846 /*
3847 * When the pipe CRC tap point is after the transcoders we need
3848 * to tweak symbol-level features to produce a deterministic series of
3849 * symbols for a given frame. We need to reset those features only once
3850 * a frame (instead of every nth symbol):
3851 * - DC-balance: used to ensure a better clock recovery from the data
3852 * link (SDVO)
3853 * - DisplayPort scrambling: used for EMI reduction
3854 */
3855 if (need_stable_symbols) {
3856 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3857
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003858 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003859 switch (pipe) {
3860 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003861 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003862 break;
3863 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003864 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003865 break;
3866 case PIPE_C:
3867 tmp |= PIPE_C_SCRAMBLE_RESET;
3868 break;
3869 default:
3870 return -EINVAL;
3871 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003872 I915_WRITE(PORT_DFT2_G4X, tmp);
3873 }
3874
Daniel Vetter7ac01292013-10-18 16:37:06 +02003875 return 0;
3876}
3877
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003878static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003879 enum pipe pipe,
3880 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003881 uint32_t *val)
3882{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003883 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003884 bool need_stable_symbols = false;
3885
Daniel Vetter46a19182013-11-01 10:50:20 +01003886 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3887 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3888 if (ret)
3889 return ret;
3890 }
3891
3892 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003893 case INTEL_PIPE_CRC_SOURCE_PIPE:
3894 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3895 break;
3896 case INTEL_PIPE_CRC_SOURCE_TV:
3897 if (!SUPPORTS_TV(dev))
3898 return -EINVAL;
3899 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3900 break;
3901 case INTEL_PIPE_CRC_SOURCE_DP_B:
3902 if (!IS_G4X(dev))
3903 return -EINVAL;
3904 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003905 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003906 break;
3907 case INTEL_PIPE_CRC_SOURCE_DP_C:
3908 if (!IS_G4X(dev))
3909 return -EINVAL;
3910 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003911 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003912 break;
3913 case INTEL_PIPE_CRC_SOURCE_DP_D:
3914 if (!IS_G4X(dev))
3915 return -EINVAL;
3916 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003917 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003918 break;
3919 case INTEL_PIPE_CRC_SOURCE_NONE:
3920 *val = 0;
3921 break;
3922 default:
3923 return -EINVAL;
3924 }
3925
Daniel Vetter84093602013-11-01 10:50:21 +01003926 /*
3927 * When the pipe CRC tap point is after the transcoders we need
3928 * to tweak symbol-level features to produce a deterministic series of
3929 * symbols for a given frame. We need to reset those features only once
3930 * a frame (instead of every nth symbol):
3931 * - DC-balance: used to ensure a better clock recovery from the data
3932 * link (SDVO)
3933 * - DisplayPort scrambling: used for EMI reduction
3934 */
3935 if (need_stable_symbols) {
3936 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3937
3938 WARN_ON(!IS_G4X(dev));
3939
3940 I915_WRITE(PORT_DFT_I9XX,
3941 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3942
3943 if (pipe == PIPE_A)
3944 tmp |= PIPE_A_SCRAMBLE_RESET;
3945 else
3946 tmp |= PIPE_B_SCRAMBLE_RESET;
3947
3948 I915_WRITE(PORT_DFT2_G4X, tmp);
3949 }
3950
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003951 return 0;
3952}
3953
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003954static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3955 enum pipe pipe)
3956{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003957 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003958 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3959
Ville Syrjäläeb736672014-12-09 21:28:28 +02003960 switch (pipe) {
3961 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003962 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003963 break;
3964 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003965 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003966 break;
3967 case PIPE_C:
3968 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3969 break;
3970 default:
3971 return;
3972 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003973 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3974 tmp &= ~DC_BALANCE_RESET_VLV;
3975 I915_WRITE(PORT_DFT2_G4X, tmp);
3976
3977}
3978
Daniel Vetter84093602013-11-01 10:50:21 +01003979static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3980 enum pipe pipe)
3981{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003982 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003983 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3984
3985 if (pipe == PIPE_A)
3986 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3987 else
3988 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3989 I915_WRITE(PORT_DFT2_G4X, tmp);
3990
3991 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3992 I915_WRITE(PORT_DFT_I9XX,
3993 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3994 }
3995}
3996
Daniel Vetter46a19182013-11-01 10:50:20 +01003997static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003998 uint32_t *val)
3999{
Daniel Vetter46a19182013-11-01 10:50:20 +01004000 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4001 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4002
4003 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004004 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4005 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4006 break;
4007 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4008 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4009 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004010 case INTEL_PIPE_CRC_SOURCE_PIPE:
4011 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4012 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004013 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004014 *val = 0;
4015 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004016 default:
4017 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004018 }
4019
4020 return 0;
4021}
4022
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004023static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004024{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004025 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004026 struct intel_crtc *crtc =
4027 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004028 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004029 struct drm_atomic_state *state;
4030 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004031
4032 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004033 state = drm_atomic_state_alloc(dev);
4034 if (!state) {
4035 ret = -ENOMEM;
4036 goto out;
4037 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004038
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004039 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4040 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4041 if (IS_ERR(pipe_config)) {
4042 ret = PTR_ERR(pipe_config);
4043 goto out;
4044 }
4045
4046 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004047 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004048 pipe_config->pch_pfit.enabled != enable)
4049 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004050
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004051 ret = drm_atomic_commit(state);
4052out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004053 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004054 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4055 if (ret)
4056 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004057}
4058
4059static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4060 enum pipe pipe,
4061 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004062 uint32_t *val)
4063{
Daniel Vetter46a19182013-11-01 10:50:20 +01004064 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4065 *source = INTEL_PIPE_CRC_SOURCE_PF;
4066
4067 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004068 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4069 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4070 break;
4071 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4072 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4073 break;
4074 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004075 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004076 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004077
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004078 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4079 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004080 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004081 *val = 0;
4082 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004083 default:
4084 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004085 }
4086
4087 return 0;
4088}
4089
Daniel Vetter926321d2013-10-16 13:30:34 +02004090static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4091 enum intel_pipe_crc_source source)
4092{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004093 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaucc3da172013-10-15 18:55:31 +01004094 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004095 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4096 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004097 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004098 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004099 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004100
Damien Lespiaucc3da172013-10-15 18:55:31 +01004101 if (pipe_crc->source == source)
4102 return 0;
4103
Damien Lespiauae676fc2013-10-15 18:55:32 +01004104 /* forbid changing the source without going back to 'none' */
4105 if (pipe_crc->source && source)
4106 return -EINVAL;
4107
Imre Deake1296492016-02-12 18:55:17 +02004108 power_domain = POWER_DOMAIN_PIPE(pipe);
4109 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004110 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4111 return -EIO;
4112 }
4113
Daniel Vetter52f843f2013-10-21 17:26:38 +02004114 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004115 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004116 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004117 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004118 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004119 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004120 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004121 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004122 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004123 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004124
4125 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004126 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004127
Damien Lespiau4b584362013-10-15 18:55:33 +01004128 /* none -> real source transition */
4129 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004130 struct intel_pipe_crc_entry *entries;
4131
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004132 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4133 pipe_name(pipe), pipe_crc_source_name(source));
4134
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004135 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4136 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004137 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004138 if (!entries) {
4139 ret = -ENOMEM;
4140 goto out;
4141 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004142
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004143 /*
4144 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4145 * enabled and disabled dynamically based on package C states,
4146 * user space can't make reliable use of the CRCs, so let's just
4147 * completely disable it.
4148 */
4149 hsw_disable_ips(crtc);
4150
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004151 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004152 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004153 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004154 pipe_crc->head = 0;
4155 pipe_crc->tail = 0;
4156 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004157 }
4158
Damien Lespiaucc3da172013-10-15 18:55:31 +01004159 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004160
Daniel Vetter926321d2013-10-16 13:30:34 +02004161 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4162 POSTING_READ(PIPE_CRC_CTL(pipe));
4163
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004164 /* real source -> none transition */
4165 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004166 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004167 struct intel_crtc *crtc =
4168 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004169
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004170 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4171 pipe_name(pipe));
4172
Daniel Vettera33d7102014-06-06 08:22:08 +02004173 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004174 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004175 intel_wait_for_vblank(dev, pipe);
4176 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004177
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004178 spin_lock_irq(&pipe_crc->lock);
4179 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004180 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004181 pipe_crc->head = 0;
4182 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004183 spin_unlock_irq(&pipe_crc->lock);
4184
4185 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004186
4187 if (IS_G4X(dev))
4188 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004189 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004190 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004191 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004192 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004193
4194 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004195 }
4196
Imre Deake1296492016-02-12 18:55:17 +02004197 ret = 0;
4198
4199out:
4200 intel_display_power_put(dev_priv, power_domain);
4201
4202 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004203}
4204
4205/*
4206 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004207 * command: wsp* object wsp+ name wsp+ source wsp*
4208 * object: 'pipe'
4209 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004210 * source: (none | plane1 | plane2 | pf)
4211 * wsp: (#0x20 | #0x9 | #0xA)+
4212 *
4213 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004214 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4215 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004216 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004217static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004218{
4219 int n_words = 0;
4220
4221 while (*buf) {
4222 char *end;
4223
4224 /* skip leading white space */
4225 buf = skip_spaces(buf);
4226 if (!*buf)
4227 break; /* end of buffer */
4228
4229 /* find end of word */
4230 for (end = buf; *end && !isspace(*end); end++)
4231 ;
4232
4233 if (n_words == max_words) {
4234 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4235 max_words);
4236 return -EINVAL; /* ran out of words[] before bytes */
4237 }
4238
4239 if (*end)
4240 *end++ = '\0';
4241 words[n_words++] = buf;
4242 buf = end;
4243 }
4244
4245 return n_words;
4246}
4247
Damien Lespiaub94dec82013-10-15 18:55:35 +01004248enum intel_pipe_crc_object {
4249 PIPE_CRC_OBJECT_PIPE,
4250};
4251
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004252static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004253 "pipe",
4254};
4255
4256static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004257display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004258{
4259 int i;
4260
4261 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4262 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004263 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004264 return 0;
4265 }
4266
4267 return -EINVAL;
4268}
4269
Damien Lespiaubd9db022013-10-15 18:55:36 +01004270static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004271{
4272 const char name = buf[0];
4273
4274 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4275 return -EINVAL;
4276
4277 *pipe = name - 'A';
4278
4279 return 0;
4280}
4281
4282static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004283display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004284{
4285 int i;
4286
4287 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4288 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004289 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004290 return 0;
4291 }
4292
4293 return -EINVAL;
4294}
4295
Damien Lespiaubd9db022013-10-15 18:55:36 +01004296static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004297{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004298#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004299 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004300 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004301 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004302 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004303 enum intel_pipe_crc_source source;
4304
Damien Lespiaubd9db022013-10-15 18:55:36 +01004305 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004306 if (n_words != N_WORDS) {
4307 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4308 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004309 return -EINVAL;
4310 }
4311
Damien Lespiaubd9db022013-10-15 18:55:36 +01004312 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004313 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004314 return -EINVAL;
4315 }
4316
Damien Lespiaubd9db022013-10-15 18:55:36 +01004317 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004318 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4319 return -EINVAL;
4320 }
4321
Damien Lespiaubd9db022013-10-15 18:55:36 +01004322 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004323 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004324 return -EINVAL;
4325 }
4326
4327 return pipe_crc_set_source(dev, pipe, source);
4328}
4329
Damien Lespiaubd9db022013-10-15 18:55:36 +01004330static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4331 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004332{
4333 struct seq_file *m = file->private_data;
4334 struct drm_device *dev = m->private;
4335 char *tmpbuf;
4336 int ret;
4337
4338 if (len == 0)
4339 return 0;
4340
4341 if (len > PAGE_SIZE - 1) {
4342 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4343 PAGE_SIZE);
4344 return -E2BIG;
4345 }
4346
4347 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4348 if (!tmpbuf)
4349 return -ENOMEM;
4350
4351 if (copy_from_user(tmpbuf, ubuf, len)) {
4352 ret = -EFAULT;
4353 goto out;
4354 }
4355 tmpbuf[len] = '\0';
4356
Damien Lespiaubd9db022013-10-15 18:55:36 +01004357 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004358
4359out:
4360 kfree(tmpbuf);
4361 if (ret < 0)
4362 return ret;
4363
4364 *offp += len;
4365 return len;
4366}
4367
Damien Lespiaubd9db022013-10-15 18:55:36 +01004368static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004369 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004370 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004371 .read = seq_read,
4372 .llseek = seq_lseek,
4373 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004374 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004375};
4376
Todd Previteeb3394fa2015-04-18 00:04:19 -07004377static ssize_t i915_displayport_test_active_write(struct file *file,
4378 const char __user *ubuf,
4379 size_t len, loff_t *offp)
4380{
4381 char *input_buffer;
4382 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004383 struct drm_device *dev;
4384 struct drm_connector *connector;
4385 struct list_head *connector_list;
4386 struct intel_dp *intel_dp;
4387 int val = 0;
4388
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304389 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004390
Todd Previteeb3394fa2015-04-18 00:04:19 -07004391 connector_list = &dev->mode_config.connector_list;
4392
4393 if (len == 0)
4394 return 0;
4395
4396 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4397 if (!input_buffer)
4398 return -ENOMEM;
4399
4400 if (copy_from_user(input_buffer, ubuf, len)) {
4401 status = -EFAULT;
4402 goto out;
4403 }
4404
4405 input_buffer[len] = '\0';
4406 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4407
4408 list_for_each_entry(connector, connector_list, head) {
4409
4410 if (connector->connector_type !=
4411 DRM_MODE_CONNECTOR_DisplayPort)
4412 continue;
4413
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304414 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004415 connector->encoder != NULL) {
4416 intel_dp = enc_to_intel_dp(connector->encoder);
4417 status = kstrtoint(input_buffer, 10, &val);
4418 if (status < 0)
4419 goto out;
4420 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4421 /* To prevent erroneous activation of the compliance
4422 * testing code, only accept an actual value of 1 here
4423 */
4424 if (val == 1)
4425 intel_dp->compliance_test_active = 1;
4426 else
4427 intel_dp->compliance_test_active = 0;
4428 }
4429 }
4430out:
4431 kfree(input_buffer);
4432 if (status < 0)
4433 return status;
4434
4435 *offp += len;
4436 return len;
4437}
4438
4439static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4440{
4441 struct drm_device *dev = m->private;
4442 struct drm_connector *connector;
4443 struct list_head *connector_list = &dev->mode_config.connector_list;
4444 struct intel_dp *intel_dp;
4445
Todd Previteeb3394fa2015-04-18 00:04:19 -07004446 list_for_each_entry(connector, connector_list, head) {
4447
4448 if (connector->connector_type !=
4449 DRM_MODE_CONNECTOR_DisplayPort)
4450 continue;
4451
4452 if (connector->status == connector_status_connected &&
4453 connector->encoder != NULL) {
4454 intel_dp = enc_to_intel_dp(connector->encoder);
4455 if (intel_dp->compliance_test_active)
4456 seq_puts(m, "1");
4457 else
4458 seq_puts(m, "0");
4459 } else
4460 seq_puts(m, "0");
4461 }
4462
4463 return 0;
4464}
4465
4466static int i915_displayport_test_active_open(struct inode *inode,
4467 struct file *file)
4468{
4469 struct drm_device *dev = inode->i_private;
4470
4471 return single_open(file, i915_displayport_test_active_show, dev);
4472}
4473
4474static const struct file_operations i915_displayport_test_active_fops = {
4475 .owner = THIS_MODULE,
4476 .open = i915_displayport_test_active_open,
4477 .read = seq_read,
4478 .llseek = seq_lseek,
4479 .release = single_release,
4480 .write = i915_displayport_test_active_write
4481};
4482
4483static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4484{
4485 struct drm_device *dev = m->private;
4486 struct drm_connector *connector;
4487 struct list_head *connector_list = &dev->mode_config.connector_list;
4488 struct intel_dp *intel_dp;
4489
Todd Previteeb3394fa2015-04-18 00:04:19 -07004490 list_for_each_entry(connector, connector_list, head) {
4491
4492 if (connector->connector_type !=
4493 DRM_MODE_CONNECTOR_DisplayPort)
4494 continue;
4495
4496 if (connector->status == connector_status_connected &&
4497 connector->encoder != NULL) {
4498 intel_dp = enc_to_intel_dp(connector->encoder);
4499 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4500 } else
4501 seq_puts(m, "0");
4502 }
4503
4504 return 0;
4505}
4506static int i915_displayport_test_data_open(struct inode *inode,
4507 struct file *file)
4508{
4509 struct drm_device *dev = inode->i_private;
4510
4511 return single_open(file, i915_displayport_test_data_show, dev);
4512}
4513
4514static const struct file_operations i915_displayport_test_data_fops = {
4515 .owner = THIS_MODULE,
4516 .open = i915_displayport_test_data_open,
4517 .read = seq_read,
4518 .llseek = seq_lseek,
4519 .release = single_release
4520};
4521
4522static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4523{
4524 struct drm_device *dev = m->private;
4525 struct drm_connector *connector;
4526 struct list_head *connector_list = &dev->mode_config.connector_list;
4527 struct intel_dp *intel_dp;
4528
Todd Previteeb3394fa2015-04-18 00:04:19 -07004529 list_for_each_entry(connector, connector_list, head) {
4530
4531 if (connector->connector_type !=
4532 DRM_MODE_CONNECTOR_DisplayPort)
4533 continue;
4534
4535 if (connector->status == connector_status_connected &&
4536 connector->encoder != NULL) {
4537 intel_dp = enc_to_intel_dp(connector->encoder);
4538 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4539 } else
4540 seq_puts(m, "0");
4541 }
4542
4543 return 0;
4544}
4545
4546static int i915_displayport_test_type_open(struct inode *inode,
4547 struct file *file)
4548{
4549 struct drm_device *dev = inode->i_private;
4550
4551 return single_open(file, i915_displayport_test_type_show, dev);
4552}
4553
4554static const struct file_operations i915_displayport_test_type_fops = {
4555 .owner = THIS_MODULE,
4556 .open = i915_displayport_test_type_open,
4557 .read = seq_read,
4558 .llseek = seq_lseek,
4559 .release = single_release
4560};
4561
Damien Lespiau97e94b22014-11-04 17:06:50 +00004562static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004563{
4564 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004565 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004566 int num_levels;
4567
4568 if (IS_CHERRYVIEW(dev))
4569 num_levels = 3;
4570 else if (IS_VALLEYVIEW(dev))
4571 num_levels = 1;
4572 else
4573 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004574
4575 drm_modeset_lock_all(dev);
4576
4577 for (level = 0; level < num_levels; level++) {
4578 unsigned int latency = wm[level];
4579
Damien Lespiau97e94b22014-11-04 17:06:50 +00004580 /*
4581 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004582 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004583 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004584 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4585 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004586 latency *= 10;
4587 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004588 latency *= 5;
4589
4590 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004591 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004592 }
4593
4594 drm_modeset_unlock_all(dev);
4595}
4596
4597static int pri_wm_latency_show(struct seq_file *m, void *data)
4598{
4599 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004600 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004601 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004602
Damien Lespiau97e94b22014-11-04 17:06:50 +00004603 if (INTEL_INFO(dev)->gen >= 9)
4604 latencies = dev_priv->wm.skl_latency;
4605 else
4606 latencies = to_i915(dev)->wm.pri_latency;
4607
4608 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004609
4610 return 0;
4611}
4612
4613static int spr_wm_latency_show(struct seq_file *m, void *data)
4614{
4615 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004616 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004617 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004618
Damien Lespiau97e94b22014-11-04 17:06:50 +00004619 if (INTEL_INFO(dev)->gen >= 9)
4620 latencies = dev_priv->wm.skl_latency;
4621 else
4622 latencies = to_i915(dev)->wm.spr_latency;
4623
4624 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004625
4626 return 0;
4627}
4628
4629static int cur_wm_latency_show(struct seq_file *m, void *data)
4630{
4631 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004632 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004633 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004634
Damien Lespiau97e94b22014-11-04 17:06:50 +00004635 if (INTEL_INFO(dev)->gen >= 9)
4636 latencies = dev_priv->wm.skl_latency;
4637 else
4638 latencies = to_i915(dev)->wm.cur_latency;
4639
4640 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004641
4642 return 0;
4643}
4644
4645static int pri_wm_latency_open(struct inode *inode, struct file *file)
4646{
4647 struct drm_device *dev = inode->i_private;
4648
Ville Syrjäläde38b952015-06-24 22:00:09 +03004649 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004650 return -ENODEV;
4651
4652 return single_open(file, pri_wm_latency_show, dev);
4653}
4654
4655static int spr_wm_latency_open(struct inode *inode, struct file *file)
4656{
4657 struct drm_device *dev = inode->i_private;
4658
Sonika Jindal9ad02572014-07-21 15:23:39 +05304659 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004660 return -ENODEV;
4661
4662 return single_open(file, spr_wm_latency_show, dev);
4663}
4664
4665static int cur_wm_latency_open(struct inode *inode, struct file *file)
4666{
4667 struct drm_device *dev = inode->i_private;
4668
Sonika Jindal9ad02572014-07-21 15:23:39 +05304669 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004670 return -ENODEV;
4671
4672 return single_open(file, cur_wm_latency_show, dev);
4673}
4674
4675static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004676 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004677{
4678 struct seq_file *m = file->private_data;
4679 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004680 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004681 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004682 int level;
4683 int ret;
4684 char tmp[32];
4685
Ville Syrjäläde38b952015-06-24 22:00:09 +03004686 if (IS_CHERRYVIEW(dev))
4687 num_levels = 3;
4688 else if (IS_VALLEYVIEW(dev))
4689 num_levels = 1;
4690 else
4691 num_levels = ilk_wm_max_level(dev) + 1;
4692
Ville Syrjälä369a1342014-01-22 14:36:08 +02004693 if (len >= sizeof(tmp))
4694 return -EINVAL;
4695
4696 if (copy_from_user(tmp, ubuf, len))
4697 return -EFAULT;
4698
4699 tmp[len] = '\0';
4700
Damien Lespiau97e94b22014-11-04 17:06:50 +00004701 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4702 &new[0], &new[1], &new[2], &new[3],
4703 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004704 if (ret != num_levels)
4705 return -EINVAL;
4706
4707 drm_modeset_lock_all(dev);
4708
4709 for (level = 0; level < num_levels; level++)
4710 wm[level] = new[level];
4711
4712 drm_modeset_unlock_all(dev);
4713
4714 return len;
4715}
4716
4717
4718static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4719 size_t len, loff_t *offp)
4720{
4721 struct seq_file *m = file->private_data;
4722 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004723 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004724 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004725
Damien Lespiau97e94b22014-11-04 17:06:50 +00004726 if (INTEL_INFO(dev)->gen >= 9)
4727 latencies = dev_priv->wm.skl_latency;
4728 else
4729 latencies = to_i915(dev)->wm.pri_latency;
4730
4731 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004732}
4733
4734static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4735 size_t len, loff_t *offp)
4736{
4737 struct seq_file *m = file->private_data;
4738 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004739 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004740 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004741
Damien Lespiau97e94b22014-11-04 17:06:50 +00004742 if (INTEL_INFO(dev)->gen >= 9)
4743 latencies = dev_priv->wm.skl_latency;
4744 else
4745 latencies = to_i915(dev)->wm.spr_latency;
4746
4747 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004748}
4749
4750static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4751 size_t len, loff_t *offp)
4752{
4753 struct seq_file *m = file->private_data;
4754 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004755 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004756 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004757
Damien Lespiau97e94b22014-11-04 17:06:50 +00004758 if (INTEL_INFO(dev)->gen >= 9)
4759 latencies = dev_priv->wm.skl_latency;
4760 else
4761 latencies = to_i915(dev)->wm.cur_latency;
4762
4763 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004764}
4765
4766static const struct file_operations i915_pri_wm_latency_fops = {
4767 .owner = THIS_MODULE,
4768 .open = pri_wm_latency_open,
4769 .read = seq_read,
4770 .llseek = seq_lseek,
4771 .release = single_release,
4772 .write = pri_wm_latency_write
4773};
4774
4775static const struct file_operations i915_spr_wm_latency_fops = {
4776 .owner = THIS_MODULE,
4777 .open = spr_wm_latency_open,
4778 .read = seq_read,
4779 .llseek = seq_lseek,
4780 .release = single_release,
4781 .write = spr_wm_latency_write
4782};
4783
4784static const struct file_operations i915_cur_wm_latency_fops = {
4785 .owner = THIS_MODULE,
4786 .open = cur_wm_latency_open,
4787 .read = seq_read,
4788 .llseek = seq_lseek,
4789 .release = single_release,
4790 .write = cur_wm_latency_write
4791};
4792
Kees Cook647416f2013-03-10 14:10:06 -07004793static int
4794i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004795{
Kees Cook647416f2013-03-10 14:10:06 -07004796 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004797 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004798
Chris Wilsond98c52c2016-04-13 17:35:05 +01004799 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004800
Kees Cook647416f2013-03-10 14:10:06 -07004801 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004802}
4803
Kees Cook647416f2013-03-10 14:10:06 -07004804static int
4805i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004806{
Kees Cook647416f2013-03-10 14:10:06 -07004807 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004808 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakd46c0512014-04-14 20:24:27 +03004809
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004810 /*
4811 * There is no safeguard against this debugfs entry colliding
4812 * with the hangcheck calling same i915_handle_error() in
4813 * parallel, causing an explosion. For now we assume that the
4814 * test harness is responsible enough not to inject gpu hangs
4815 * while it is writing to 'i915_wedged'
4816 */
4817
Chris Wilsond98c52c2016-04-13 17:35:05 +01004818 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004819 return -EAGAIN;
4820
Imre Deakd46c0512014-04-14 20:24:27 +03004821 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004822
Chris Wilsonc0336662016-05-06 15:40:21 +01004823 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004824 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004825
4826 intel_runtime_pm_put(dev_priv);
4827
Kees Cook647416f2013-03-10 14:10:06 -07004828 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004829}
4830
Kees Cook647416f2013-03-10 14:10:06 -07004831DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4832 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004833 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004834
Kees Cook647416f2013-03-10 14:10:06 -07004835static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004836i915_ring_missed_irq_get(void *data, u64 *val)
4837{
4838 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004839 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004840
4841 *val = dev_priv->gpu_error.missed_irq_rings;
4842 return 0;
4843}
4844
4845static int
4846i915_ring_missed_irq_set(void *data, u64 val)
4847{
4848 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004849 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004850 int ret;
4851
4852 /* Lock against concurrent debugfs callers */
4853 ret = mutex_lock_interruptible(&dev->struct_mutex);
4854 if (ret)
4855 return ret;
4856 dev_priv->gpu_error.missed_irq_rings = val;
4857 mutex_unlock(&dev->struct_mutex);
4858
4859 return 0;
4860}
4861
4862DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4863 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4864 "0x%08llx\n");
4865
4866static int
4867i915_ring_test_irq_get(void *data, u64 *val)
4868{
4869 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004870 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004871
4872 *val = dev_priv->gpu_error.test_irq_rings;
4873
4874 return 0;
4875}
4876
4877static int
4878i915_ring_test_irq_set(void *data, u64 val)
4879{
4880 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004881 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004882
Chris Wilson3a122c22016-06-17 14:35:05 +01004883 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004884 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004885 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004886
4887 return 0;
4888}
4889
4890DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4891 i915_ring_test_irq_get, i915_ring_test_irq_set,
4892 "0x%08llx\n");
4893
Chris Wilsondd624af2013-01-15 12:39:35 +00004894#define DROP_UNBOUND 0x1
4895#define DROP_BOUND 0x2
4896#define DROP_RETIRE 0x4
4897#define DROP_ACTIVE 0x8
4898#define DROP_ALL (DROP_UNBOUND | \
4899 DROP_BOUND | \
4900 DROP_RETIRE | \
4901 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004902static int
4903i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004904{
Kees Cook647416f2013-03-10 14:10:06 -07004905 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004906
Kees Cook647416f2013-03-10 14:10:06 -07004907 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004908}
4909
Kees Cook647416f2013-03-10 14:10:06 -07004910static int
4911i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004912{
Kees Cook647416f2013-03-10 14:10:06 -07004913 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004914 struct drm_i915_private *dev_priv = to_i915(dev);
Kees Cook647416f2013-03-10 14:10:06 -07004915 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004916
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004917 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004918
4919 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4920 * on ioctls on -EAGAIN. */
4921 ret = mutex_lock_interruptible(&dev->struct_mutex);
4922 if (ret)
4923 return ret;
4924
4925 if (val & DROP_ACTIVE) {
Chris Wilson6e5a5be2016-06-24 14:55:57 +01004926 ret = i915_gem_wait_for_idle(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004927 if (ret)
4928 goto unlock;
4929 }
4930
4931 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004932 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004933
Chris Wilson21ab4e72014-09-09 11:16:08 +01004934 if (val & DROP_BOUND)
4935 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004936
Chris Wilson21ab4e72014-09-09 11:16:08 +01004937 if (val & DROP_UNBOUND)
4938 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004939
4940unlock:
4941 mutex_unlock(&dev->struct_mutex);
4942
Kees Cook647416f2013-03-10 14:10:06 -07004943 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004944}
4945
Kees Cook647416f2013-03-10 14:10:06 -07004946DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4947 i915_drop_caches_get, i915_drop_caches_set,
4948 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004949
Kees Cook647416f2013-03-10 14:10:06 -07004950static int
4951i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004952{
Kees Cook647416f2013-03-10 14:10:06 -07004953 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004954 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02004955
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004956 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004957 return -ENODEV;
4958
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004959 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004960 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004961}
4962
Kees Cook647416f2013-03-10 14:10:06 -07004963static int
4964i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004965{
Kees Cook647416f2013-03-10 14:10:06 -07004966 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004967 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05304968 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004969 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004970
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004971 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004972 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004973
Kees Cook647416f2013-03-10 14:10:06 -07004974 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004975
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004976 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004977 if (ret)
4978 return ret;
4979
Jesse Barnes358733e2011-07-27 11:53:01 -07004980 /*
4981 * Turbo will still be enabled, but won't go above the set value.
4982 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304983 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004984
Akash Goelbc4d91f2015-02-26 16:09:47 +05304985 hw_max = dev_priv->rps.max_freq;
4986 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004987
Ben Widawskyb39fb292014-03-19 18:31:11 -07004988 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004989 mutex_unlock(&dev_priv->rps.hw_lock);
4990 return -EINVAL;
4991 }
4992
Ben Widawskyb39fb292014-03-19 18:31:11 -07004993 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004994
Chris Wilsondc979972016-05-10 14:10:04 +01004995 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004996
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004997 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004998
Kees Cook647416f2013-03-10 14:10:06 -07004999 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005000}
5001
Kees Cook647416f2013-03-10 14:10:06 -07005002DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5003 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005004 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005005
Kees Cook647416f2013-03-10 14:10:06 -07005006static int
5007i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005008{
Kees Cook647416f2013-03-10 14:10:06 -07005009 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005010 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02005011
Chris Wilson62e1baa2016-07-13 09:10:36 +01005012 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005013 return -ENODEV;
5014
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005015 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005016 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005017}
5018
Kees Cook647416f2013-03-10 14:10:06 -07005019static int
5020i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005021{
Kees Cook647416f2013-03-10 14:10:06 -07005022 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005023 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05305024 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005025 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005026
Chris Wilson62e1baa2016-07-13 09:10:36 +01005027 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005028 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005029
Kees Cook647416f2013-03-10 14:10:06 -07005030 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005031
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005032 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005033 if (ret)
5034 return ret;
5035
Jesse Barnes1523c312012-05-25 12:34:54 -07005036 /*
5037 * Turbo will still be enabled, but won't go below the set value.
5038 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305039 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005040
Akash Goelbc4d91f2015-02-26 16:09:47 +05305041 hw_max = dev_priv->rps.max_freq;
5042 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005043
Ben Widawskyb39fb292014-03-19 18:31:11 -07005044 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005045 mutex_unlock(&dev_priv->rps.hw_lock);
5046 return -EINVAL;
5047 }
5048
Ben Widawskyb39fb292014-03-19 18:31:11 -07005049 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005050
Chris Wilsondc979972016-05-10 14:10:04 +01005051 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005052
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005053 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005054
Kees Cook647416f2013-03-10 14:10:06 -07005055 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005056}
5057
Kees Cook647416f2013-03-10 14:10:06 -07005058DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5059 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005060 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005061
Kees Cook647416f2013-03-10 14:10:06 -07005062static int
5063i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005064{
Kees Cook647416f2013-03-10 14:10:06 -07005065 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005066 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005067 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005068 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005069
Daniel Vetter004777c2012-08-09 15:07:01 +02005070 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5071 return -ENODEV;
5072
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005073 ret = mutex_lock_interruptible(&dev->struct_mutex);
5074 if (ret)
5075 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005076 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005077
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005078 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005079
5080 intel_runtime_pm_put(dev_priv);
Chris Wilson91c8a322016-07-05 10:40:23 +01005081 mutex_unlock(&dev_priv->drm.struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005082
Kees Cook647416f2013-03-10 14:10:06 -07005083 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005084
Kees Cook647416f2013-03-10 14:10:06 -07005085 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005086}
5087
Kees Cook647416f2013-03-10 14:10:06 -07005088static int
5089i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005090{
Kees Cook647416f2013-03-10 14:10:06 -07005091 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005092 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005093 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005094
Daniel Vetter004777c2012-08-09 15:07:01 +02005095 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5096 return -ENODEV;
5097
Kees Cook647416f2013-03-10 14:10:06 -07005098 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005099 return -EINVAL;
5100
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005101 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005102 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005103
5104 /* Update the cache sharing policy here as well */
5105 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5106 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5107 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5108 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5109
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005110 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005111 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005112}
5113
Kees Cook647416f2013-03-10 14:10:06 -07005114DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5115 i915_cache_sharing_get, i915_cache_sharing_set,
5116 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005117
Jeff McGee5d395252015-04-03 18:13:17 -07005118struct sseu_dev_status {
5119 unsigned int slice_total;
5120 unsigned int subslice_total;
5121 unsigned int subslice_per_slice;
5122 unsigned int eu_total;
5123 unsigned int eu_per_subslice;
5124};
5125
5126static void cherryview_sseu_device_status(struct drm_device *dev,
5127 struct sseu_dev_status *stat)
5128{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005129 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005130 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005131 int ss;
5132 u32 sig1[ss_max], sig2[ss_max];
5133
5134 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5135 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5136 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5137 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5138
5139 for (ss = 0; ss < ss_max; ss++) {
5140 unsigned int eu_cnt;
5141
5142 if (sig1[ss] & CHV_SS_PG_ENABLE)
5143 /* skip disabled subslice */
5144 continue;
5145
5146 stat->slice_total = 1;
5147 stat->subslice_per_slice++;
5148 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5149 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5150 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5151 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5152 stat->eu_total += eu_cnt;
5153 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5154 }
5155 stat->subslice_total = stat->subslice_per_slice;
5156}
5157
5158static void gen9_sseu_device_status(struct drm_device *dev,
5159 struct sseu_dev_status *stat)
5160{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005161 struct drm_i915_private *dev_priv = to_i915(dev);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005162 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005163 int s, ss;
5164 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5165
Jeff McGee1c046bc2015-04-03 18:13:18 -07005166 /* BXT has a single slice and at most 3 subslices. */
5167 if (IS_BROXTON(dev)) {
5168 s_max = 1;
5169 ss_max = 3;
5170 }
5171
5172 for (s = 0; s < s_max; s++) {
5173 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5174 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5175 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5176 }
5177
Jeff McGee5d395252015-04-03 18:13:17 -07005178 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5179 GEN9_PGCTL_SSA_EU19_ACK |
5180 GEN9_PGCTL_SSA_EU210_ACK |
5181 GEN9_PGCTL_SSA_EU311_ACK;
5182 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5183 GEN9_PGCTL_SSB_EU19_ACK |
5184 GEN9_PGCTL_SSB_EU210_ACK |
5185 GEN9_PGCTL_SSB_EU311_ACK;
5186
5187 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005188 unsigned int ss_cnt = 0;
5189
Jeff McGee5d395252015-04-03 18:13:17 -07005190 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5191 /* skip disabled slice */
5192 continue;
5193
5194 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005195
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005196 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005197 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5198
Jeff McGee5d395252015-04-03 18:13:17 -07005199 for (ss = 0; ss < ss_max; ss++) {
5200 unsigned int eu_cnt;
5201
Jeff McGee1c046bc2015-04-03 18:13:18 -07005202 if (IS_BROXTON(dev) &&
5203 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5204 /* skip disabled subslice */
5205 continue;
5206
5207 if (IS_BROXTON(dev))
5208 ss_cnt++;
5209
Jeff McGee5d395252015-04-03 18:13:17 -07005210 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5211 eu_mask[ss%2]);
5212 stat->eu_total += eu_cnt;
5213 stat->eu_per_subslice = max(stat->eu_per_subslice,
5214 eu_cnt);
5215 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005216
5217 stat->subslice_total += ss_cnt;
5218 stat->subslice_per_slice = max(stat->subslice_per_slice,
5219 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005220 }
5221}
5222
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005223static void broadwell_sseu_device_status(struct drm_device *dev,
5224 struct sseu_dev_status *stat)
5225{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005226 struct drm_i915_private *dev_priv = to_i915(dev);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005227 int s;
5228 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5229
5230 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5231
5232 if (stat->slice_total) {
5233 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5234 stat->subslice_total = stat->slice_total *
5235 stat->subslice_per_slice;
5236 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5237 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5238
5239 /* subtract fused off EU(s) from enabled slice(s) */
5240 for (s = 0; s < stat->slice_total; s++) {
5241 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5242
5243 stat->eu_total -= hweight8(subslice_7eu);
5244 }
5245 }
5246}
5247
Jeff McGee38732182015-02-13 10:27:54 -06005248static int i915_sseu_status(struct seq_file *m, void *unused)
5249{
5250 struct drm_info_node *node = (struct drm_info_node *) m->private;
David Weinehall238010e2016-08-01 17:33:27 +03005251 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
5252 struct drm_device *dev = &dev_priv->drm;
Jeff McGee5d395252015-04-03 18:13:17 -07005253 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005254
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005255 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005256 return -ENODEV;
5257
5258 seq_puts(m, "SSEU Device Info\n");
5259 seq_printf(m, " Available Slice Total: %u\n",
5260 INTEL_INFO(dev)->slice_total);
5261 seq_printf(m, " Available Subslice Total: %u\n",
5262 INTEL_INFO(dev)->subslice_total);
5263 seq_printf(m, " Available Subslice Per Slice: %u\n",
5264 INTEL_INFO(dev)->subslice_per_slice);
5265 seq_printf(m, " Available EU Total: %u\n",
5266 INTEL_INFO(dev)->eu_total);
5267 seq_printf(m, " Available EU Per Subslice: %u\n",
5268 INTEL_INFO(dev)->eu_per_subslice);
arun.siluvery@linux.intel.com33e141e2016-06-03 06:34:33 +01005269 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev)));
5270 if (HAS_POOLED_EU(dev))
5271 seq_printf(m, " Min EU in pool: %u\n",
5272 INTEL_INFO(dev)->min_eu_in_pool);
Jeff McGee38732182015-02-13 10:27:54 -06005273 seq_printf(m, " Has Slice Power Gating: %s\n",
5274 yesno(INTEL_INFO(dev)->has_slice_pg));
5275 seq_printf(m, " Has Subslice Power Gating: %s\n",
5276 yesno(INTEL_INFO(dev)->has_subslice_pg));
5277 seq_printf(m, " Has EU Power Gating: %s\n",
5278 yesno(INTEL_INFO(dev)->has_eu_pg));
5279
Jeff McGee7f992ab2015-02-13 10:27:55 -06005280 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005281 memset(&stat, 0, sizeof(stat));
David Weinehall238010e2016-08-01 17:33:27 +03005282
5283 intel_runtime_pm_get(dev_priv);
5284
Jeff McGee5575f032015-02-27 10:22:32 -08005285 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005286 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005287 } else if (IS_BROADWELL(dev)) {
5288 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005289 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005290 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005291 }
David Weinehall238010e2016-08-01 17:33:27 +03005292
5293 intel_runtime_pm_put(dev_priv);
5294
Jeff McGee5d395252015-04-03 18:13:17 -07005295 seq_printf(m, " Enabled Slice Total: %u\n",
5296 stat.slice_total);
5297 seq_printf(m, " Enabled Subslice Total: %u\n",
5298 stat.subslice_total);
5299 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5300 stat.subslice_per_slice);
5301 seq_printf(m, " Enabled EU Total: %u\n",
5302 stat.eu_total);
5303 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5304 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005305
Jeff McGee38732182015-02-13 10:27:54 -06005306 return 0;
5307}
5308
Ben Widawsky6d794d42011-04-25 11:25:56 -07005309static int i915_forcewake_open(struct inode *inode, struct file *file)
5310{
5311 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005312 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005313
Daniel Vetter075edca2012-01-24 09:44:28 +01005314 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005315 return 0;
5316
Chris Wilson6daccb02015-01-16 11:34:35 +02005317 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005318 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005319
5320 return 0;
5321}
5322
Ben Widawskyc43b5632012-04-16 14:07:40 -07005323static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005324{
5325 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005326 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005327
Daniel Vetter075edca2012-01-24 09:44:28 +01005328 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005329 return 0;
5330
Mika Kuoppala59bad942015-01-16 11:34:40 +02005331 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005332 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005333
5334 return 0;
5335}
5336
5337static const struct file_operations i915_forcewake_fops = {
5338 .owner = THIS_MODULE,
5339 .open = i915_forcewake_open,
5340 .release = i915_forcewake_release,
5341};
5342
5343static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5344{
5345 struct drm_device *dev = minor->dev;
5346 struct dentry *ent;
5347
5348 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005349 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005350 root, dev,
5351 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005352 if (!ent)
5353 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005354
Ben Widawsky8eb57292011-05-11 15:10:58 -07005355 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005356}
5357
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005358static int i915_debugfs_create(struct dentry *root,
5359 struct drm_minor *minor,
5360 const char *name,
5361 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005362{
5363 struct drm_device *dev = minor->dev;
5364 struct dentry *ent;
5365
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005366 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005367 S_IRUGO | S_IWUSR,
5368 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005369 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005370 if (!ent)
5371 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005372
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005373 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005374}
5375
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005376static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005377 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005378 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005379 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005380 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005381 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005382 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005383 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005384 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005385 {"i915_gem_request", i915_gem_request_info, 0},
5386 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005387 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005388 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005389 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5390 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5391 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005392 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005393 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005394 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005395 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005396 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305397 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005398 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005399 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005400 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005401 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005402 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005403 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005404 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005405 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005406 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005407 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005408 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005409 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005410 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005411 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005412 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005413 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005414 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005415 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005416 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005417 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005418 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005419 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005420 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005421 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005422 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005423 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005424 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005425 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005426 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005427 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005428 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305429 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005430 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005431};
Ben Gamari27c202a2009-07-01 22:26:52 -04005432#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005433
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005434static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005435 const char *name;
5436 const struct file_operations *fops;
5437} i915_debugfs_files[] = {
5438 {"i915_wedged", &i915_wedged_fops},
5439 {"i915_max_freq", &i915_max_freq_fops},
5440 {"i915_min_freq", &i915_min_freq_fops},
5441 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005442 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5443 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005444 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5445 {"i915_error_state", &i915_error_state_fops},
5446 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005447 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005448 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5449 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5450 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005451 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005452 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5453 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5454 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005455};
5456
Damien Lespiau07144422013-10-15 18:55:40 +01005457void intel_display_crc_init(struct drm_device *dev)
5458{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005459 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb3783602013-11-14 11:30:42 +01005460 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005461
Damien Lespiau055e3932014-08-18 13:49:10 +01005462 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005463 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005464
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005465 pipe_crc->opened = false;
5466 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005467 init_waitqueue_head(&pipe_crc->wq);
5468 }
5469}
5470
Chris Wilson1dac8912016-06-24 14:00:17 +01005471int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005472{
Chris Wilson91c8a322016-07-05 10:40:23 +01005473 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005474 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005475
Ben Widawsky6d794d42011-04-25 11:25:56 -07005476 ret = i915_forcewake_create(minor->debugfs_root, minor);
5477 if (ret)
5478 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005479
Damien Lespiau07144422013-10-15 18:55:40 +01005480 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5481 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5482 if (ret)
5483 return ret;
5484 }
5485
Daniel Vetter34b96742013-07-04 20:49:44 +02005486 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5487 ret = i915_debugfs_create(minor->debugfs_root, minor,
5488 i915_debugfs_files[i].name,
5489 i915_debugfs_files[i].fops);
5490 if (ret)
5491 return ret;
5492 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005493
Ben Gamari27c202a2009-07-01 22:26:52 -04005494 return drm_debugfs_create_files(i915_debugfs_list,
5495 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005496 minor->debugfs_root, minor);
5497}
5498
Chris Wilson1dac8912016-06-24 14:00:17 +01005499void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005500{
Chris Wilson91c8a322016-07-05 10:40:23 +01005501 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005502 int i;
5503
Ben Gamari27c202a2009-07-01 22:26:52 -04005504 drm_debugfs_remove_files(i915_debugfs_list,
5505 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005506
Ben Widawsky6d794d42011-04-25 11:25:56 -07005507 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5508 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005509
Daniel Vettere309a992013-10-16 22:55:51 +02005510 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005511 struct drm_info_list *info_list =
5512 (struct drm_info_list *)&i915_pipe_crc_data[i];
5513
5514 drm_debugfs_remove_files(info_list, 1, minor);
5515 }
5516
Daniel Vetter34b96742013-07-04 20:49:44 +02005517 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5518 struct drm_info_list *info_list =
5519 (struct drm_info_list *) i915_debugfs_files[i].fops;
5520
5521 drm_debugfs_remove_files(info_list, 1, minor);
5522 }
Ben Gamari20172632009-02-17 20:08:50 -05005523}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005524
5525struct dpcd_block {
5526 /* DPCD dump start address. */
5527 unsigned int offset;
5528 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5529 unsigned int end;
5530 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5531 size_t size;
5532 /* Only valid for eDP. */
5533 bool edp;
5534};
5535
5536static const struct dpcd_block i915_dpcd_debug[] = {
5537 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5538 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5539 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5540 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5541 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5542 { .offset = DP_SET_POWER },
5543 { .offset = DP_EDP_DPCD_REV },
5544 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5545 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5546 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5547};
5548
5549static int i915_dpcd_show(struct seq_file *m, void *data)
5550{
5551 struct drm_connector *connector = m->private;
5552 struct intel_dp *intel_dp =
5553 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5554 uint8_t buf[16];
5555 ssize_t err;
5556 int i;
5557
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005558 if (connector->status != connector_status_connected)
5559 return -ENODEV;
5560
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005561 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5562 const struct dpcd_block *b = &i915_dpcd_debug[i];
5563 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5564
5565 if (b->edp &&
5566 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5567 continue;
5568
5569 /* low tech for now */
5570 if (WARN_ON(size > sizeof(buf)))
5571 continue;
5572
5573 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5574 if (err <= 0) {
5575 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5576 size, b->offset, err);
5577 continue;
5578 }
5579
5580 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005581 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005582
5583 return 0;
5584}
5585
5586static int i915_dpcd_open(struct inode *inode, struct file *file)
5587{
5588 return single_open(file, i915_dpcd_show, inode->i_private);
5589}
5590
5591static const struct file_operations i915_dpcd_fops = {
5592 .owner = THIS_MODULE,
5593 .open = i915_dpcd_open,
5594 .read = seq_read,
5595 .llseek = seq_lseek,
5596 .release = single_release,
5597};
5598
5599/**
5600 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5601 * @connector: pointer to a registered drm_connector
5602 *
5603 * Cleanup will be done by drm_connector_unregister() through a call to
5604 * drm_debugfs_connector_remove().
5605 *
5606 * Returns 0 on success, negative error codes on error.
5607 */
5608int i915_debugfs_connector_add(struct drm_connector *connector)
5609{
5610 struct dentry *root = connector->debugfs_entry;
5611
5612 /* The connector must have been registered beforehands. */
5613 if (!root)
5614 return -ENODEV;
5615
5616 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5617 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5618 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5619 &i915_dpcd_fops);
5620
5621 return 0;
5622}