blob: 9796b07bdb0d341434bdf1bce9b4dc468ad16f81 [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;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100141 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800142 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000143 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800144
Chris Wilson188c1ab2016-04-03 14:14:20 +0100145 lockdep_assert_held(&obj->base.dev->struct_mutex);
146
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100147 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100148 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100149 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 get_pin_flag(obj),
151 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700152 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100153 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800154 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100155 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100156 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000157 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100158 seq_printf(m, "%x ",
Chris Wilsond72d9082016-08-04 07:52:31 +0100159 i915_gem_active_get_seqno(&obj->last_read[id],
160 &obj->base.dev->struct_mutex));
Chris Wilsonb4716182015-04-27 13:41:17 +0100161 seq_printf(m, "] %x %x%s%s%s",
Chris Wilsond72d9082016-08-04 07:52:31 +0100162 i915_gem_active_get_seqno(&obj->last_write,
163 &obj->base.dev->struct_mutex),
164 i915_gem_active_get_seqno(&obj->last_fence,
165 &obj->base.dev->struct_mutex),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100166 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100167 obj->dirty ? " dirty" : "",
168 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
169 if (obj->base.name)
170 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000171 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100172 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800173 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300174 }
175 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100176 if (obj->pin_display)
177 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100178 if (obj->fence_reg != I915_FENCE_REG_NONE)
179 seq_printf(m, " (fence: %d)", obj->fence_reg);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000180 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100181 if (!drm_mm_node_allocated(&vma->node))
182 continue;
183
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100184 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson3272db52016-08-04 16:32:32 +0100185 i915_vma_is_ggtt(vma) ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100186 vma->node.start, vma->node.size);
Chris Wilson3272db52016-08-04 16:32:32 +0100187 if (i915_vma_is_ggtt(vma))
Chris Wilson596c5922016-02-26 11:03:20 +0000188 seq_printf(m, ", type: %u", vma->ggtt_view.type);
189 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700190 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000191 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100192 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100193 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000194 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100195 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000196 *t++ = 'p';
197 if (obj->fault_mappable)
198 *t++ = 'f';
199 *t = '\0';
200 seq_printf(m, " (%s mappable)", s);
201 }
Chris Wilson27c01aa2016-08-04 07:52:30 +0100202
Chris Wilsond72d9082016-08-04 07:52:31 +0100203 engine = i915_gem_active_get_engine(&obj->last_write,
204 &obj->base.dev->struct_mutex);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100205 if (engine)
206 seq_printf(m, " (%s)", engine->name);
207
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100208 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
209 if (frontbuffer_bits)
210 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100211}
212
Ben Gamari433e12f2009-02-17 20:08:51 -0500213static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500214{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100215 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500216 uintptr_t list = (uintptr_t) node->info_ent->data;
217 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500218 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300219 struct drm_i915_private *dev_priv = to_i915(dev);
220 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Ben Widawskyca191b12013-07-31 17:00:14 -0700221 struct i915_vma *vma;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300222 u64 total_obj_size, total_gtt_size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100223 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100224
225 ret = mutex_lock_interruptible(&dev->struct_mutex);
226 if (ret)
227 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500228
Ben Widawskyca191b12013-07-31 17:00:14 -0700229 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500230 switch (list) {
231 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100232 seq_puts(m, "Active:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300233 head = &ggtt->base.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500234 break;
235 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100236 seq_puts(m, "Inactive:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300237 head = &ggtt->base.inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500238 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500239 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100240 mutex_unlock(&dev->struct_mutex);
241 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500242 }
243
Chris Wilson8f2480f2010-09-26 11:44:19 +0100244 total_obj_size = total_gtt_size = count = 0;
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000245 list_for_each_entry(vma, head, vm_link) {
Ben Widawskyca191b12013-07-31 17:00:14 -0700246 seq_printf(m, " ");
247 describe_obj(m, vma->obj);
248 seq_printf(m, "\n");
249 total_obj_size += vma->obj->base.size;
250 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100251 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500252 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100253 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700254
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300255 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson8f2480f2010-09-26 11:44:19 +0100256 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500257 return 0;
258}
259
Chris Wilson6d2b88852013-08-07 18:30:54 +0100260static int obj_rank_by_stolen(void *priv,
261 struct list_head *A, struct list_head *B)
262{
263 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200264 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100265 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200266 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100267
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200268 if (a->stolen->start < b->stolen->start)
269 return -1;
270 if (a->stolen->start > b->stolen->start)
271 return 1;
272 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100273}
274
275static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
276{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100277 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100278 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100279 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300281 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100282 LIST_HEAD(stolen);
283 int count, ret;
284
285 ret = mutex_lock_interruptible(&dev->struct_mutex);
286 if (ret)
287 return ret;
288
289 total_obj_size = total_gtt_size = count = 0;
290 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
291 if (obj->stolen == NULL)
292 continue;
293
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200294 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100295
296 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100297 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100298 count++;
299 }
300 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
301 if (obj->stolen == NULL)
302 continue;
303
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200304 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100305
306 total_obj_size += obj->base.size;
307 count++;
308 }
309 list_sort(NULL, &stolen, obj_rank_by_stolen);
310 seq_puts(m, "Stolen:\n");
311 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200312 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100313 seq_puts(m, " ");
314 describe_obj(m, obj);
315 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200316 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100317 }
318 mutex_unlock(&dev->struct_mutex);
319
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300320 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100321 count, total_obj_size, total_gtt_size);
322 return 0;
323}
324
Chris Wilson6299f992010-11-24 12:23:44 +0000325#define count_objects(list, member) do { \
326 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100327 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000328 ++count; \
329 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700330 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000331 ++mappable_count; \
332 } \
333 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400334} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000335
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100336struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000337 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300338 unsigned long count;
339 u64 total, unbound;
340 u64 global, shared;
341 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100342};
343
344static int per_file_stats(int id, void *ptr, void *data)
345{
346 struct drm_i915_gem_object *obj = ptr;
347 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000348 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100349
350 stats->count++;
351 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100352 if (!obj->bind_count)
353 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000354 if (obj->base.name || obj->base.dma_buf)
355 stats->shared += obj->base.size;
356
Chris Wilson894eeec2016-08-04 07:52:20 +0100357 list_for_each_entry(vma, &obj->vma_list, obj_link) {
358 if (!drm_mm_node_allocated(&vma->node))
359 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000360
Chris Wilson3272db52016-08-04 16:32:32 +0100361 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100362 stats->global += vma->node.size;
363 } else {
364 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000365
Chris Wilson2bfa9962016-08-04 07:52:25 +0100366 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000367 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000368 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100369
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100370 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100371 stats->active += vma->node.size;
372 else
373 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100374 }
375
376 return 0;
377}
378
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100379#define print_file_stats(m, name, stats) do { \
380 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300381 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 +0100382 name, \
383 stats.count, \
384 stats.total, \
385 stats.active, \
386 stats.inactive, \
387 stats.global, \
388 stats.shared, \
389 stats.unbound); \
390} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800391
392static void print_batch_pool_stats(struct seq_file *m,
393 struct drm_i915_private *dev_priv)
394{
395 struct drm_i915_gem_object *obj;
396 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000397 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000398 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800399
400 memset(&stats, 0, sizeof(stats));
401
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000402 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000403 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100404 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000405 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100406 batch_pool_link)
407 per_file_stats(0, obj, &stats);
408 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100409 }
Brad Volkin493018d2014-12-11 12:13:08 -0800410
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100411 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800412}
413
Chris Wilson15da9562016-05-24 14:53:43 +0100414static int per_file_ctx_stats(int id, void *ptr, void *data)
415{
416 struct i915_gem_context *ctx = ptr;
417 int n;
418
419 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
420 if (ctx->engine[n].state)
421 per_file_stats(0, ctx->engine[n].state, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100422 if (ctx->engine[n].ring)
423 per_file_stats(0, ctx->engine[n].ring->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100424 }
425
426 return 0;
427}
428
429static void print_context_stats(struct seq_file *m,
430 struct drm_i915_private *dev_priv)
431{
432 struct file_stats stats;
433 struct drm_file *file;
434
435 memset(&stats, 0, sizeof(stats));
436
Chris Wilson91c8a322016-07-05 10:40:23 +0100437 mutex_lock(&dev_priv->drm.struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100438 if (dev_priv->kernel_context)
439 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
440
Chris Wilson91c8a322016-07-05 10:40:23 +0100441 list_for_each_entry(file, &dev_priv->drm.filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100442 struct drm_i915_file_private *fpriv = file->driver_priv;
443 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
444 }
Chris Wilson91c8a322016-07-05 10:40:23 +0100445 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100446
447 print_file_stats(m, "[k]contexts", stats);
448}
449
Ben Widawskyca191b12013-07-31 17:00:14 -0700450#define count_vmas(list, member) do { \
451 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100452 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700453 ++count; \
454 if (vma->obj->map_and_fenceable) { \
455 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
456 ++mappable_count; \
457 } \
458 } \
459} while (0)
460
461static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100462{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100463 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100464 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300465 struct drm_i915_private *dev_priv = to_i915(dev);
466 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200467 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300468 u64 size, mappable_size, purgeable_size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100469 unsigned long pin_mapped_count = 0, pin_mapped_purgeable_count = 0;
470 u64 pin_mapped_size = 0, pin_mapped_purgeable_size = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000471 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100472 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700473 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100474 int ret;
475
476 ret = mutex_lock_interruptible(&dev->struct_mutex);
477 if (ret)
478 return ret;
479
Chris Wilson6299f992010-11-24 12:23:44 +0000480 seq_printf(m, "%u objects, %zu bytes\n",
481 dev_priv->mm.object_count,
482 dev_priv->mm.object_memory);
483
484 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700485 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300486 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000487 count, mappable_count, size, mappable_size);
488
489 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300490 count_vmas(&ggtt->base.active_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300491 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000492 count, mappable_count, size, mappable_size);
493
494 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300495 count_vmas(&ggtt->base.inactive_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300496 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000497 count, mappable_count, size, mappable_size);
498
Chris Wilsonb7abb712012-08-20 11:33:30 +0200499 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700500 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200501 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200502 if (obj->madv == I915_MADV_DONTNEED)
503 purgeable_size += obj->base.size, ++purgeable_count;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100504 if (obj->mapping) {
505 pin_mapped_count++;
506 pin_mapped_size += obj->base.size;
507 if (obj->pages_pin_count == 0) {
508 pin_mapped_purgeable_count++;
509 pin_mapped_purgeable_size += obj->base.size;
510 }
511 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200512 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300513 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200514
Chris Wilson6299f992010-11-24 12:23:44 +0000515 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700516 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000517 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700518 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000519 ++count;
520 }
Chris Wilson30154652015-04-07 17:28:24 +0100521 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700522 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000523 ++mappable_count;
524 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200525 if (obj->madv == I915_MADV_DONTNEED) {
526 purgeable_size += obj->base.size;
527 ++purgeable_count;
528 }
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100529 if (obj->mapping) {
530 pin_mapped_count++;
531 pin_mapped_size += obj->base.size;
532 if (obj->pages_pin_count == 0) {
533 pin_mapped_purgeable_count++;
534 pin_mapped_purgeable_size += obj->base.size;
535 }
536 }
Chris Wilson6299f992010-11-24 12:23:44 +0000537 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300538 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200539 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300540 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000541 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300542 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000543 count, size);
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100544 seq_printf(m,
545 "%lu [%lu] pin mapped objects, %llu [%llu] bytes [purgeable]\n",
546 pin_mapped_count, pin_mapped_purgeable_count,
547 pin_mapped_size, pin_mapped_purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000548
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300549 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300550 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100551
Damien Lespiau267f0c92013-06-24 22:59:48 +0100552 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800553 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200554 mutex_unlock(&dev->struct_mutex);
555
556 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100557 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100558 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
559 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900560 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100561
562 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000563 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100564 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100565 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100566 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900567 /*
568 * Although we have a valid reference on file->pid, that does
569 * not guarantee that the task_struct who called get_pid() is
570 * still alive (e.g. get_pid(current) => fork() => exit()).
571 * Therefore, we need to protect this ->comm access using RCU.
572 */
573 rcu_read_lock();
574 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800575 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900576 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100577 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200578 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100579
580 return 0;
581}
582
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100583static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000584{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100585 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000586 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100587 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100588 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson08c18322011-01-10 00:00:24 +0000589 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300590 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000591 int count, ret;
592
593 ret = mutex_lock_interruptible(&dev->struct_mutex);
594 if (ret)
595 return ret;
596
597 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700598 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800599 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100600 continue;
601
Damien Lespiau267f0c92013-06-24 22:59:48 +0100602 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000603 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100604 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000605 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100606 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000607 count++;
608 }
609
610 mutex_unlock(&dev->struct_mutex);
611
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300612 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000613 count, total_obj_size, total_gtt_size);
614
615 return 0;
616}
617
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100618static int i915_gem_pageflip_info(struct seq_file *m, void *data)
619{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100620 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100621 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100622 struct drm_i915_private *dev_priv = to_i915(dev);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100623 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200624 int ret;
625
626 ret = mutex_lock_interruptible(&dev->struct_mutex);
627 if (ret)
628 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100629
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100630 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800631 const char pipe = pipe_name(crtc->pipe);
632 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200633 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100634
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200635 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200636 work = crtc->flip_work;
637 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800638 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100639 pipe, plane);
640 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200641 u32 pending;
642 u32 addr;
643
644 pending = atomic_read(&work->pending);
645 if (pending) {
646 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
647 pipe, plane);
648 } else {
649 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
650 pipe, plane);
651 }
652 if (work->flip_queued_req) {
653 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
654
655 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
656 engine->name,
657 i915_gem_request_get_seqno(work->flip_queued_req),
658 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100659 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100660 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200661 } else
662 seq_printf(m, "Flip not associated with any ring\n");
663 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
664 work->flip_queued_vblank,
665 work->flip_ready_vblank,
666 intel_crtc_get_vblank_counter(crtc));
667 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
668
669 if (INTEL_INFO(dev)->gen >= 4)
670 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
671 else
672 addr = I915_READ(DSPADDR(crtc->plane));
673 seq_printf(m, "Current scanout address 0x%08x\n", addr);
674
675 if (work->pending_flip_obj) {
676 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
677 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100678 }
679 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200680 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100681 }
682
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200683 mutex_unlock(&dev->struct_mutex);
684
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100685 return 0;
686}
687
Brad Volkin493018d2014-12-11 12:13:08 -0800688static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
689{
690 struct drm_info_node *node = m->private;
691 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100692 struct drm_i915_private *dev_priv = to_i915(dev);
Brad Volkin493018d2014-12-11 12:13:08 -0800693 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000694 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100695 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000696 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800697
698 ret = mutex_lock_interruptible(&dev->struct_mutex);
699 if (ret)
700 return ret;
701
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000702 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000703 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100704 int count;
705
706 count = 0;
707 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000708 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100709 batch_pool_link)
710 count++;
711 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000712 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100713
714 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000715 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100716 batch_pool_link) {
717 seq_puts(m, " ");
718 describe_obj(m, obj);
719 seq_putc(m, '\n');
720 }
721
722 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100723 }
Brad Volkin493018d2014-12-11 12:13:08 -0800724 }
725
Chris Wilson8d9d5742015-04-07 16:20:38 +0100726 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800727
728 mutex_unlock(&dev->struct_mutex);
729
730 return 0;
731}
732
Ben Gamari20172632009-02-17 20:08:50 -0500733static int i915_gem_request_info(struct seq_file *m, void *data)
734{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100735 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500736 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100737 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000738 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200739 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000740 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100741
742 ret = mutex_lock_interruptible(&dev->struct_mutex);
743 if (ret)
744 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500745
Chris Wilson2d1070b2015-04-01 10:36:56 +0100746 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000747 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100748 int count;
749
750 count = 0;
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100751 list_for_each_entry(req, &engine->request_list, link)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100752 count++;
753 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100754 continue;
755
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000756 seq_printf(m, "%s requests: %d\n", engine->name, count);
Chris Wilsonefdf7c02016-08-04 07:52:33 +0100757 list_for_each_entry(req, &engine->request_list, link) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100758 struct task_struct *task;
759
760 rcu_read_lock();
761 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200762 if (req->pid)
763 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100764 seq_printf(m, " %x @ %d: %s [%d]\n",
Chris Wilson04769652016-07-20 09:21:11 +0100765 req->fence.seqno,
Daniel Vettereed29a52015-05-21 14:21:25 +0200766 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100767 task ? task->comm : "<unknown>",
768 task ? task->pid : -1);
769 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100770 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100771
772 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500773 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100774 mutex_unlock(&dev->struct_mutex);
775
Chris Wilson2d1070b2015-04-01 10:36:56 +0100776 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100777 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100778
Ben Gamari20172632009-02-17 20:08:50 -0500779 return 0;
780}
781
Chris Wilsonb2223492010-10-27 15:27:33 +0100782static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000783 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100784{
Chris Wilson688e6c72016-07-01 17:23:15 +0100785 struct intel_breadcrumbs *b = &engine->breadcrumbs;
786 struct rb_node *rb;
787
Chris Wilson12471ba2016-04-09 10:57:55 +0100788 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100789 engine->name, intel_engine_get_seqno(engine));
Chris Wilsonaca34b62016-07-06 12:39:02 +0100790 seq_printf(m, "Current user interrupts (%s): %lx\n",
791 engine->name, READ_ONCE(engine->breadcrumbs.irq_wakeups));
Chris Wilson688e6c72016-07-01 17:23:15 +0100792
793 spin_lock(&b->lock);
794 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
795 struct intel_wait *w = container_of(rb, typeof(*w), node);
796
797 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
798 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
799 }
800 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100801}
802
Ben Gamari20172632009-02-17 20:08:50 -0500803static int i915_gem_seqno_info(struct seq_file *m, void *data)
804{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100805 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500806 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100807 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000808 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000809 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100810
811 ret = mutex_lock_interruptible(&dev->struct_mutex);
812 if (ret)
813 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200814 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500815
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000816 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000817 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100818
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200819 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100820 mutex_unlock(&dev->struct_mutex);
821
Ben Gamari20172632009-02-17 20:08:50 -0500822 return 0;
823}
824
825
826static int i915_interrupt_info(struct seq_file *m, void *data)
827{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100828 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500829 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100830 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000831 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800832 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100833
834 ret = mutex_lock_interruptible(&dev->struct_mutex);
835 if (ret)
836 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200837 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500838
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300839 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300840 seq_printf(m, "Master Interrupt Control:\t%08x\n",
841 I915_READ(GEN8_MASTER_IRQ));
842
843 seq_printf(m, "Display IER:\t%08x\n",
844 I915_READ(VLV_IER));
845 seq_printf(m, "Display IIR:\t%08x\n",
846 I915_READ(VLV_IIR));
847 seq_printf(m, "Display IIR_RW:\t%08x\n",
848 I915_READ(VLV_IIR_RW));
849 seq_printf(m, "Display IMR:\t%08x\n",
850 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100851 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300852 seq_printf(m, "Pipe %c stat:\t%08x\n",
853 pipe_name(pipe),
854 I915_READ(PIPESTAT(pipe)));
855
856 seq_printf(m, "Port hotplug:\t%08x\n",
857 I915_READ(PORT_HOTPLUG_EN));
858 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
859 I915_READ(VLV_DPFLIPSTAT));
860 seq_printf(m, "DPINVGTT:\t%08x\n",
861 I915_READ(DPINVGTT));
862
863 for (i = 0; i < 4; i++) {
864 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
865 i, I915_READ(GEN8_GT_IMR(i)));
866 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
867 i, I915_READ(GEN8_GT_IIR(i)));
868 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
869 i, I915_READ(GEN8_GT_IER(i)));
870 }
871
872 seq_printf(m, "PCU interrupt mask:\t%08x\n",
873 I915_READ(GEN8_PCU_IMR));
874 seq_printf(m, "PCU interrupt identity:\t%08x\n",
875 I915_READ(GEN8_PCU_IIR));
876 seq_printf(m, "PCU interrupt enable:\t%08x\n",
877 I915_READ(GEN8_PCU_IER));
878 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700879 seq_printf(m, "Master Interrupt Control:\t%08x\n",
880 I915_READ(GEN8_MASTER_IRQ));
881
882 for (i = 0; i < 4; i++) {
883 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
884 i, I915_READ(GEN8_GT_IMR(i)));
885 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
886 i, I915_READ(GEN8_GT_IIR(i)));
887 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
888 i, I915_READ(GEN8_GT_IER(i)));
889 }
890
Damien Lespiau055e3932014-08-18 13:49:10 +0100891 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200892 enum intel_display_power_domain power_domain;
893
894 power_domain = POWER_DOMAIN_PIPE(pipe);
895 if (!intel_display_power_get_if_enabled(dev_priv,
896 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300897 seq_printf(m, "Pipe %c power disabled\n",
898 pipe_name(pipe));
899 continue;
900 }
Ben Widawskya123f152013-11-02 21:07:10 -0700901 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000902 pipe_name(pipe),
903 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700904 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000905 pipe_name(pipe),
906 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700907 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000908 pipe_name(pipe),
909 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200910
911 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700912 }
913
914 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
915 I915_READ(GEN8_DE_PORT_IMR));
916 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
917 I915_READ(GEN8_DE_PORT_IIR));
918 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
919 I915_READ(GEN8_DE_PORT_IER));
920
921 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
922 I915_READ(GEN8_DE_MISC_IMR));
923 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
924 I915_READ(GEN8_DE_MISC_IIR));
925 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
926 I915_READ(GEN8_DE_MISC_IER));
927
928 seq_printf(m, "PCU interrupt mask:\t%08x\n",
929 I915_READ(GEN8_PCU_IMR));
930 seq_printf(m, "PCU interrupt identity:\t%08x\n",
931 I915_READ(GEN8_PCU_IIR));
932 seq_printf(m, "PCU interrupt enable:\t%08x\n",
933 I915_READ(GEN8_PCU_IER));
934 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700935 seq_printf(m, "Display IER:\t%08x\n",
936 I915_READ(VLV_IER));
937 seq_printf(m, "Display IIR:\t%08x\n",
938 I915_READ(VLV_IIR));
939 seq_printf(m, "Display IIR_RW:\t%08x\n",
940 I915_READ(VLV_IIR_RW));
941 seq_printf(m, "Display IMR:\t%08x\n",
942 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100943 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700944 seq_printf(m, "Pipe %c stat:\t%08x\n",
945 pipe_name(pipe),
946 I915_READ(PIPESTAT(pipe)));
947
948 seq_printf(m, "Master IER:\t%08x\n",
949 I915_READ(VLV_MASTER_IER));
950
951 seq_printf(m, "Render IER:\t%08x\n",
952 I915_READ(GTIER));
953 seq_printf(m, "Render IIR:\t%08x\n",
954 I915_READ(GTIIR));
955 seq_printf(m, "Render IMR:\t%08x\n",
956 I915_READ(GTIMR));
957
958 seq_printf(m, "PM IER:\t\t%08x\n",
959 I915_READ(GEN6_PMIER));
960 seq_printf(m, "PM IIR:\t\t%08x\n",
961 I915_READ(GEN6_PMIIR));
962 seq_printf(m, "PM IMR:\t\t%08x\n",
963 I915_READ(GEN6_PMIMR));
964
965 seq_printf(m, "Port hotplug:\t%08x\n",
966 I915_READ(PORT_HOTPLUG_EN));
967 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
968 I915_READ(VLV_DPFLIPSTAT));
969 seq_printf(m, "DPINVGTT:\t%08x\n",
970 I915_READ(DPINVGTT));
971
972 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800973 seq_printf(m, "Interrupt enable: %08x\n",
974 I915_READ(IER));
975 seq_printf(m, "Interrupt identity: %08x\n",
976 I915_READ(IIR));
977 seq_printf(m, "Interrupt mask: %08x\n",
978 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100979 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800980 seq_printf(m, "Pipe %c stat: %08x\n",
981 pipe_name(pipe),
982 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800983 } else {
984 seq_printf(m, "North Display Interrupt enable: %08x\n",
985 I915_READ(DEIER));
986 seq_printf(m, "North Display Interrupt identity: %08x\n",
987 I915_READ(DEIIR));
988 seq_printf(m, "North Display Interrupt mask: %08x\n",
989 I915_READ(DEIMR));
990 seq_printf(m, "South Display Interrupt enable: %08x\n",
991 I915_READ(SDEIER));
992 seq_printf(m, "South Display Interrupt identity: %08x\n",
993 I915_READ(SDEIIR));
994 seq_printf(m, "South Display Interrupt mask: %08x\n",
995 I915_READ(SDEIMR));
996 seq_printf(m, "Graphics Interrupt enable: %08x\n",
997 I915_READ(GTIER));
998 seq_printf(m, "Graphics Interrupt identity: %08x\n",
999 I915_READ(GTIIR));
1000 seq_printf(m, "Graphics Interrupt mask: %08x\n",
1001 I915_READ(GTIMR));
1002 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001003 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -07001004 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001005 seq_printf(m,
1006 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001007 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +00001008 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001009 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +00001010 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001011 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001012 mutex_unlock(&dev->struct_mutex);
1013
Ben Gamari20172632009-02-17 20:08:50 -05001014 return 0;
1015}
1016
Chris Wilsona6172a82009-02-11 14:26:38 +00001017static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
1018{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001019 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +00001020 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001021 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001022 int i, ret;
1023
1024 ret = mutex_lock_interruptible(&dev->struct_mutex);
1025 if (ret)
1026 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +00001027
Chris Wilsona6172a82009-02-11 14:26:38 +00001028 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
1029 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +00001030 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +00001031
Chris Wilson6c085a72012-08-20 11:40:46 +02001032 seq_printf(m, "Fence %d, pin count = %d, object = ",
1033 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001034 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001035 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001036 else
Chris Wilson05394f32010-11-08 19:18:58 +00001037 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001038 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001039 }
1040
Chris Wilson05394f32010-11-08 19:18:58 +00001041 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001042 return 0;
1043}
1044
Ben Gamari20172632009-02-17 20:08:50 -05001045static int i915_hws_info(struct seq_file *m, void *data)
1046{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001047 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001048 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001049 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001050 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001051 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001052 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001053
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001054 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001055 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001056 if (hws == NULL)
1057 return 0;
1058
1059 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1060 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1061 i * 4,
1062 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1063 }
1064 return 0;
1065}
1066
Daniel Vetterd5442302012-04-27 15:17:40 +02001067static ssize_t
1068i915_error_state_write(struct file *filp,
1069 const char __user *ubuf,
1070 size_t cnt,
1071 loff_t *ppos)
1072{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001073 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001074 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001075 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001076
1077 DRM_DEBUG_DRIVER("Resetting error state\n");
1078
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001079 ret = mutex_lock_interruptible(&dev->struct_mutex);
1080 if (ret)
1081 return ret;
1082
Daniel Vetterd5442302012-04-27 15:17:40 +02001083 i915_destroy_error_state(dev);
1084 mutex_unlock(&dev->struct_mutex);
1085
1086 return cnt;
1087}
1088
1089static int i915_error_state_open(struct inode *inode, struct file *file)
1090{
1091 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001092 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001093
1094 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1095 if (!error_priv)
1096 return -ENOMEM;
1097
1098 error_priv->dev = dev;
1099
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001100 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001101
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001102 file->private_data = error_priv;
1103
1104 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001105}
1106
1107static int i915_error_state_release(struct inode *inode, struct file *file)
1108{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001109 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001110
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001111 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001112 kfree(error_priv);
1113
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001114 return 0;
1115}
1116
1117static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1118 size_t count, loff_t *pos)
1119{
1120 struct i915_error_state_file_priv *error_priv = file->private_data;
1121 struct drm_i915_error_state_buf error_str;
1122 loff_t tmp_pos = 0;
1123 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001124 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001125
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001126 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001127 if (ret)
1128 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001129
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001130 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001131 if (ret)
1132 goto out;
1133
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001134 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1135 error_str.buf,
1136 error_str.bytes);
1137
1138 if (ret_count < 0)
1139 ret = ret_count;
1140 else
1141 *pos = error_str.start + ret_count;
1142out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001143 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001144 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001145}
1146
1147static const struct file_operations i915_error_state_fops = {
1148 .owner = THIS_MODULE,
1149 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001150 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001151 .write = i915_error_state_write,
1152 .llseek = default_llseek,
1153 .release = i915_error_state_release,
1154};
1155
Kees Cook647416f2013-03-10 14:10:06 -07001156static int
1157i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001158{
Kees Cook647416f2013-03-10 14:10:06 -07001159 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001160 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala40633212012-12-04 15:12:00 +02001161 int ret;
1162
1163 ret = mutex_lock_interruptible(&dev->struct_mutex);
1164 if (ret)
1165 return ret;
1166
Kees Cook647416f2013-03-10 14:10:06 -07001167 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001168 mutex_unlock(&dev->struct_mutex);
1169
Kees Cook647416f2013-03-10 14:10:06 -07001170 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001171}
1172
Kees Cook647416f2013-03-10 14:10:06 -07001173static int
1174i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001175{
Kees Cook647416f2013-03-10 14:10:06 -07001176 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001177 int ret;
1178
Mika Kuoppala40633212012-12-04 15:12:00 +02001179 ret = mutex_lock_interruptible(&dev->struct_mutex);
1180 if (ret)
1181 return ret;
1182
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001183 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001184 mutex_unlock(&dev->struct_mutex);
1185
Kees Cook647416f2013-03-10 14:10:06 -07001186 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001187}
1188
Kees Cook647416f2013-03-10 14:10:06 -07001189DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1190 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001191 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001192
Deepak Sadb4bd12014-03-31 11:30:02 +05301193static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001194{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001195 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001196 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001197 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001198 int ret = 0;
1199
1200 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001201
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001202 if (IS_GEN5(dev)) {
1203 u16 rgvswctl = I915_READ16(MEMSWCTL);
1204 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1205
1206 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1207 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1208 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1209 MEMSTAT_VID_SHIFT);
1210 seq_printf(m, "Current P-state: %d\n",
1211 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001212 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1213 u32 freq_sts;
1214
1215 mutex_lock(&dev_priv->rps.hw_lock);
1216 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1217 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1218 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1219
1220 seq_printf(m, "actual GPU freq: %d MHz\n",
1221 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1222
1223 seq_printf(m, "current GPU freq: %d MHz\n",
1224 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1225
1226 seq_printf(m, "max GPU freq: %d MHz\n",
1227 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1228
1229 seq_printf(m, "min GPU freq: %d MHz\n",
1230 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1231
1232 seq_printf(m, "idle GPU freq: %d MHz\n",
1233 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1234
1235 seq_printf(m,
1236 "efficient (RPe) frequency: %d MHz\n",
1237 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1238 mutex_unlock(&dev_priv->rps.hw_lock);
1239 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001240 u32 rp_state_limits;
1241 u32 gt_perf_status;
1242 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001243 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001244 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001245 u32 rpupei, rpcurup, rpprevup;
1246 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001247 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001248 int max_freq;
1249
Bob Paauwe35040562015-06-25 14:54:07 -07001250 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1251 if (IS_BROXTON(dev)) {
1252 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1253 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1254 } else {
1255 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1256 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1257 }
1258
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001259 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001260 ret = mutex_lock_interruptible(&dev->struct_mutex);
1261 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001262 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001263
Mika Kuoppala59bad942015-01-16 11:34:40 +02001264 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001265
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001266 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301267 if (IS_GEN9(dev))
1268 reqf >>= 23;
1269 else {
1270 reqf &= ~GEN6_TURBO_DISABLE;
1271 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1272 reqf >>= 24;
1273 else
1274 reqf >>= 25;
1275 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001276 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001277
Chris Wilson0d8f9492014-03-27 09:06:14 +00001278 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1279 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1280 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1281
Jesse Barnesccab5c82011-01-18 15:49:25 -08001282 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301283 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1284 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1285 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1286 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1287 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1288 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301289 if (IS_GEN9(dev))
1290 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1291 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001292 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1293 else
1294 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001295 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001296
Mika Kuoppala59bad942015-01-16 11:34:40 +02001297 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001298 mutex_unlock(&dev->struct_mutex);
1299
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001300 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1301 pm_ier = I915_READ(GEN6_PMIER);
1302 pm_imr = I915_READ(GEN6_PMIMR);
1303 pm_isr = I915_READ(GEN6_PMISR);
1304 pm_iir = I915_READ(GEN6_PMIIR);
1305 pm_mask = I915_READ(GEN6_PMINTRMSK);
1306 } else {
1307 pm_ier = I915_READ(GEN8_GT_IER(2));
1308 pm_imr = I915_READ(GEN8_GT_IMR(2));
1309 pm_isr = I915_READ(GEN8_GT_ISR(2));
1310 pm_iir = I915_READ(GEN8_GT_IIR(2));
1311 pm_mask = I915_READ(GEN6_PMINTRMSK);
1312 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001313 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 -03001314 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301315 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001316 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001317 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301318 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001319 seq_printf(m, "Render p-state VID: %d\n",
1320 gt_perf_status & 0xff);
1321 seq_printf(m, "Render p-state limit: %d\n",
1322 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001323 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1324 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1325 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1326 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001327 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001328 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301329 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1330 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1331 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1332 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1333 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1334 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001335 seq_printf(m, "Up threshold: %d%%\n",
1336 dev_priv->rps.up_threshold);
1337
Akash Goeld6cda9c2016-04-23 00:05:46 +05301338 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1339 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1340 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1341 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1342 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1343 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001344 seq_printf(m, "Down threshold: %d%%\n",
1345 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001346
Bob Paauwe35040562015-06-25 14:54:07 -07001347 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1348 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001349 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1350 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001351 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001352 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001353
1354 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001355 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1356 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001357 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001358 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001359
Bob Paauwe35040562015-06-25 14:54:07 -07001360 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1361 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001362 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1363 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001364 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001365 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001366 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001367 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001368
Chris Wilsond86ed342015-04-27 13:41:19 +01001369 seq_printf(m, "Current freq: %d MHz\n",
1370 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1371 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001372 seq_printf(m, "Idle freq: %d MHz\n",
1373 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001374 seq_printf(m, "Min freq: %d MHz\n",
1375 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001376 seq_printf(m, "Boost freq: %d MHz\n",
1377 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001378 seq_printf(m, "Max freq: %d MHz\n",
1379 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1380 seq_printf(m,
1381 "efficient (RPe) frequency: %d MHz\n",
1382 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001383 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001384 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001385 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001386
Mika Kahola1170f282015-09-25 14:00:32 +03001387 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1388 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1389 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1390
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001391out:
1392 intel_runtime_pm_put(dev_priv);
1393 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001394}
1395
Chris Wilsonf6544492015-01-26 18:03:04 +02001396static int i915_hangcheck_info(struct seq_file *m, void *unused)
1397{
1398 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001399 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001400 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001401 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001402 u64 acthd[I915_NUM_ENGINES];
1403 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001404 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001405 enum intel_engine_id id;
1406 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001407
1408 if (!i915.enable_hangcheck) {
1409 seq_printf(m, "Hangcheck disabled\n");
1410 return 0;
1411 }
1412
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001413 intel_runtime_pm_get(dev_priv);
1414
Dave Gordonc3232b12016-03-23 18:19:53 +00001415 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001416 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001417 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001418 }
1419
Chris Wilsonc0336662016-05-06 15:40:21 +01001420 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001421
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001422 intel_runtime_pm_put(dev_priv);
1423
Chris Wilsonf6544492015-01-26 18:03:04 +02001424 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1425 seq_printf(m, "Hangcheck active, fires in %dms\n",
1426 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1427 jiffies));
1428 } else
1429 seq_printf(m, "Hangcheck inactive\n");
1430
Dave Gordonc3232b12016-03-23 18:19:53 +00001431 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001432 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001433 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1434 engine->hangcheck.seqno,
1435 seqno[id],
1436 engine->last_submitted_seqno);
Chris Wilson688e6c72016-07-01 17:23:15 +01001437 seq_printf(m, "\twaiters? %d\n",
1438 intel_engine_has_waiter(engine));
Chris Wilsonaca34b62016-07-06 12:39:02 +01001439 seq_printf(m, "\tuser interrupts = %lx [current %lx]\n",
Chris Wilson12471ba2016-04-09 10:57:55 +01001440 engine->hangcheck.user_interrupts,
Chris Wilsonaca34b62016-07-06 12:39:02 +01001441 READ_ONCE(engine->breadcrumbs.irq_wakeups));
Chris Wilsonf6544492015-01-26 18:03:04 +02001442 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001443 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001444 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001445 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1446 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001447
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001448 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001449 seq_puts(m, "\tinstdone read =");
1450
1451 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1452 seq_printf(m, " 0x%08x", instdone[j]);
1453
1454 seq_puts(m, "\n\tinstdone accu =");
1455
1456 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1457 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001458 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001459
1460 seq_puts(m, "\n");
1461 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001462 }
1463
1464 return 0;
1465}
1466
Ben Widawsky4d855292011-12-12 19:34:16 -08001467static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001468{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001469 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001470 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001471 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001472 u32 rgvmodectl, rstdbyctl;
1473 u16 crstandvid;
1474 int ret;
1475
1476 ret = mutex_lock_interruptible(&dev->struct_mutex);
1477 if (ret)
1478 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001479 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001480
1481 rgvmodectl = I915_READ(MEMMODECTL);
1482 rstdbyctl = I915_READ(RSTDBYCTL);
1483 crstandvid = I915_READ16(CRSTANDVID);
1484
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001485 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001486 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001487
Jani Nikula742f4912015-09-03 11:16:09 +03001488 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001489 seq_printf(m, "Boost freq: %d\n",
1490 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1491 MEMMODE_BOOST_FREQ_SHIFT);
1492 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001493 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001494 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001495 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001496 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001497 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001498 seq_printf(m, "Starting frequency: P%d\n",
1499 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001500 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001501 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001502 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1503 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1504 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1505 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001506 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001507 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001508 switch (rstdbyctl & RSX_STATUS_MASK) {
1509 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001510 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001511 break;
1512 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001513 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001514 break;
1515 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001516 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001517 break;
1518 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001519 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001520 break;
1521 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001522 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001523 break;
1524 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001525 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001526 break;
1527 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001528 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001529 break;
1530 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001531
1532 return 0;
1533}
1534
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001535static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001536{
1537 struct drm_info_node *node = m->private;
1538 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001539 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001540 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001541
1542 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001543 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001544 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001545 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001546 fw_domain->wake_count);
1547 }
1548 spin_unlock_irq(&dev_priv->uncore.lock);
1549
1550 return 0;
1551}
1552
Deepak S669ab5a2014-01-10 15:18:26 +05301553static int vlv_drpc_info(struct seq_file *m)
1554{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001555 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301556 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001557 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001558 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301559
Imre Deakd46c0512014-04-14 20:24:27 +03001560 intel_runtime_pm_get(dev_priv);
1561
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001562 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301563 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1564 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1565
Imre Deakd46c0512014-04-14 20:24:27 +03001566 intel_runtime_pm_put(dev_priv);
1567
Deepak S669ab5a2014-01-10 15:18:26 +05301568 seq_printf(m, "Video Turbo Mode: %s\n",
1569 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1570 seq_printf(m, "Turbo enabled: %s\n",
1571 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1572 seq_printf(m, "HW control enabled: %s\n",
1573 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1574 seq_printf(m, "SW control enabled: %s\n",
1575 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1576 GEN6_RP_MEDIA_SW_MODE));
1577 seq_printf(m, "RC6 Enabled: %s\n",
1578 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1579 GEN6_RC_CTL_EI_MODE(1))));
1580 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001581 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301582 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001583 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301584
Imre Deak9cc19be2014-04-14 20:24:24 +03001585 seq_printf(m, "Render RC6 residency since boot: %u\n",
1586 I915_READ(VLV_GT_RENDER_RC6));
1587 seq_printf(m, "Media RC6 residency since boot: %u\n",
1588 I915_READ(VLV_GT_MEDIA_RC6));
1589
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001590 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301591}
1592
Ben Widawsky4d855292011-12-12 19:34:16 -08001593static int gen6_drpc_info(struct seq_file *m)
1594{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001595 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001596 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001597 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001598 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301599 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001600 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001601 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001602
1603 ret = mutex_lock_interruptible(&dev->struct_mutex);
1604 if (ret)
1605 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001606 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001607
Chris Wilson907b28c2013-07-19 20:36:52 +01001608 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001609 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001610 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001611
1612 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001613 seq_puts(m, "RC information inaccurate because somebody "
1614 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001615 } else {
1616 /* NB: we cannot use forcewake, else we read the wrong values */
1617 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1618 udelay(10);
1619 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1620 }
1621
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001622 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001623 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001624
1625 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1626 rcctl1 = I915_READ(GEN6_RC_CONTROL);
Akash Goelf2dd7572016-06-27 20:10:01 +05301627 if (INTEL_INFO(dev)->gen >= 9) {
1628 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1629 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1630 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001631 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001632 mutex_lock(&dev_priv->rps.hw_lock);
1633 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1634 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001635
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001636 intel_runtime_pm_put(dev_priv);
1637
Ben Widawsky4d855292011-12-12 19:34:16 -08001638 seq_printf(m, "Video Turbo Mode: %s\n",
1639 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1640 seq_printf(m, "HW control enabled: %s\n",
1641 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1642 seq_printf(m, "SW control enabled: %s\n",
1643 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1644 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001645 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001646 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1647 seq_printf(m, "RC6 Enabled: %s\n",
1648 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
Akash Goelf2dd7572016-06-27 20:10:01 +05301649 if (INTEL_INFO(dev)->gen >= 9) {
1650 seq_printf(m, "Render Well Gating Enabled: %s\n",
1651 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1652 seq_printf(m, "Media Well Gating Enabled: %s\n",
1653 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1654 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001655 seq_printf(m, "Deep RC6 Enabled: %s\n",
1656 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1657 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1658 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001659 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001660 switch (gt_core_status & GEN6_RCn_MASK) {
1661 case GEN6_RC0:
1662 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001663 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001664 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001665 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001666 break;
1667 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001668 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001669 break;
1670 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001671 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001672 break;
1673 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001674 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001675 break;
1676 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001677 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001678 break;
1679 }
1680
1681 seq_printf(m, "Core Power Down: %s\n",
1682 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Akash Goelf2dd7572016-06-27 20:10:01 +05301683 if (INTEL_INFO(dev)->gen >= 9) {
1684 seq_printf(m, "Render Power Well: %s\n",
1685 (gen9_powergate_status &
1686 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1687 seq_printf(m, "Media Power Well: %s\n",
1688 (gen9_powergate_status &
1689 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1690 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001691
1692 /* Not exactly sure what this is */
1693 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1694 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1695 seq_printf(m, "RC6 residency since boot: %u\n",
1696 I915_READ(GEN6_GT_GFX_RC6));
1697 seq_printf(m, "RC6+ residency since boot: %u\n",
1698 I915_READ(GEN6_GT_GFX_RC6p));
1699 seq_printf(m, "RC6++ residency since boot: %u\n",
1700 I915_READ(GEN6_GT_GFX_RC6pp));
1701
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001702 seq_printf(m, "RC6 voltage: %dmV\n",
1703 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1704 seq_printf(m, "RC6+ voltage: %dmV\n",
1705 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1706 seq_printf(m, "RC6++ voltage: %dmV\n",
1707 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301708 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001709}
1710
1711static int i915_drpc_info(struct seq_file *m, void *unused)
1712{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001713 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001714 struct drm_device *dev = node->minor->dev;
1715
Wayne Boyer666a4532015-12-09 12:29:35 -08001716 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301717 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001718 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001719 return gen6_drpc_info(m);
1720 else
1721 return ironlake_drpc_info(m);
1722}
1723
Daniel Vetter9a851782015-06-18 10:30:22 +02001724static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1725{
1726 struct drm_info_node *node = m->private;
1727 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001728 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter9a851782015-06-18 10:30:22 +02001729
1730 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1731 dev_priv->fb_tracking.busy_bits);
1732
1733 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1734 dev_priv->fb_tracking.flip_bits);
1735
1736 return 0;
1737}
1738
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001739static int i915_fbc_status(struct seq_file *m, void *unused)
1740{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001741 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001742 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001743 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001744
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001745 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001746 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001747 return 0;
1748 }
1749
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001750 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001751 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001752
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001753 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001754 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001755 else
1756 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001757 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001758
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001759 if (INTEL_INFO(dev_priv)->gen >= 7)
1760 seq_printf(m, "Compressing: %s\n",
1761 yesno(I915_READ(FBC_STATUS2) &
1762 FBC_COMPRESSION_MASK));
1763
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001764 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001765 intel_runtime_pm_put(dev_priv);
1766
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001767 return 0;
1768}
1769
Rodrigo Vivida46f932014-08-01 02:04:45 -07001770static int i915_fbc_fc_get(void *data, u64 *val)
1771{
1772 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001773 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001774
1775 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1776 return -ENODEV;
1777
Rodrigo Vivida46f932014-08-01 02:04:45 -07001778 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001779
1780 return 0;
1781}
1782
1783static int i915_fbc_fc_set(void *data, u64 val)
1784{
1785 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001786 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001787 u32 reg;
1788
1789 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1790 return -ENODEV;
1791
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001792 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001793
1794 reg = I915_READ(ILK_DPFC_CONTROL);
1795 dev_priv->fbc.false_color = val;
1796
1797 I915_WRITE(ILK_DPFC_CONTROL, val ?
1798 (reg | FBC_CTL_FALSE_COLOR) :
1799 (reg & ~FBC_CTL_FALSE_COLOR));
1800
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001801 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001802 return 0;
1803}
1804
1805DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1806 i915_fbc_fc_get, i915_fbc_fc_set,
1807 "%llu\n");
1808
Paulo Zanoni92d44622013-05-31 16:33:24 -03001809static int i915_ips_status(struct seq_file *m, void *unused)
1810{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001811 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001812 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001813 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001814
Damien Lespiauf5adf942013-06-24 18:29:34 +01001815 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001816 seq_puts(m, "not supported\n");
1817 return 0;
1818 }
1819
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001820 intel_runtime_pm_get(dev_priv);
1821
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001822 seq_printf(m, "Enabled by kernel parameter: %s\n",
1823 yesno(i915.enable_ips));
1824
1825 if (INTEL_INFO(dev)->gen >= 8) {
1826 seq_puts(m, "Currently: unknown\n");
1827 } else {
1828 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1829 seq_puts(m, "Currently: enabled\n");
1830 else
1831 seq_puts(m, "Currently: disabled\n");
1832 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001833
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001834 intel_runtime_pm_put(dev_priv);
1835
Paulo Zanoni92d44622013-05-31 16:33:24 -03001836 return 0;
1837}
1838
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001839static int i915_sr_status(struct seq_file *m, void *unused)
1840{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001841 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001842 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001843 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001844 bool sr_enabled = false;
1845
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001846 intel_runtime_pm_get(dev_priv);
1847
Yuanhan Liu13982612010-12-15 15:42:31 +08001848 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001849 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001850 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1851 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001852 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1853 else if (IS_I915GM(dev))
1854 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1855 else if (IS_PINEVIEW(dev))
1856 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001857 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001858 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001859
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001860 intel_runtime_pm_put(dev_priv);
1861
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001862 seq_printf(m, "self-refresh: %s\n",
1863 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001864
1865 return 0;
1866}
1867
Jesse Barnes7648fa92010-05-20 14:28:11 -07001868static int i915_emon_status(struct seq_file *m, void *unused)
1869{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001870 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001871 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001872 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001873 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001874 int ret;
1875
Chris Wilson582be6b2012-04-30 19:35:02 +01001876 if (!IS_GEN5(dev))
1877 return -ENODEV;
1878
Chris Wilsonde227ef2010-07-03 07:58:38 +01001879 ret = mutex_lock_interruptible(&dev->struct_mutex);
1880 if (ret)
1881 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001882
1883 temp = i915_mch_val(dev_priv);
1884 chipset = i915_chipset_val(dev_priv);
1885 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001886 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001887
1888 seq_printf(m, "GMCH temp: %ld\n", temp);
1889 seq_printf(m, "Chipset power: %ld\n", chipset);
1890 seq_printf(m, "GFX power: %ld\n", gfx);
1891 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1892
1893 return 0;
1894}
1895
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001896static int i915_ring_freq_table(struct seq_file *m, void *unused)
1897{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001898 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001899 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001900 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001901 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001902 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301903 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001904
Akash Goel97d33082015-06-29 14:50:23 +05301905 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001906 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001907 return 0;
1908 }
1909
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001910 intel_runtime_pm_get(dev_priv);
1911
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001912 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001913 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001914 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001915
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001916 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301917 /* Convert GT frequency to 50 HZ units */
1918 min_gpu_freq =
1919 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1920 max_gpu_freq =
1921 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1922 } else {
1923 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1924 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1925 }
1926
Damien Lespiau267f0c92013-06-24 22:59:48 +01001927 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001928
Akash Goelf936ec32015-06-29 14:50:22 +05301929 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001930 ia_freq = gpu_freq;
1931 sandybridge_pcode_read(dev_priv,
1932 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1933 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001934 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301935 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001936 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1937 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001938 ((ia_freq >> 0) & 0xff) * 100,
1939 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001940 }
1941
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001942 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001943
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001944out:
1945 intel_runtime_pm_put(dev_priv);
1946 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001947}
1948
Chris Wilson44834a62010-08-19 16:09:23 +01001949static int i915_opregion(struct seq_file *m, void *unused)
1950{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001951 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001952 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001953 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson44834a62010-08-19 16:09:23 +01001954 struct intel_opregion *opregion = &dev_priv->opregion;
1955 int ret;
1956
1957 ret = mutex_lock_interruptible(&dev->struct_mutex);
1958 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001959 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001960
Jani Nikula2455a8e2015-12-14 12:50:53 +02001961 if (opregion->header)
1962 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001963
1964 mutex_unlock(&dev->struct_mutex);
1965
Daniel Vetter0d38f002012-04-21 22:49:10 +02001966out:
Chris Wilson44834a62010-08-19 16:09:23 +01001967 return 0;
1968}
1969
Jani Nikulaada8f952015-12-15 13:17:12 +02001970static int i915_vbt(struct seq_file *m, void *unused)
1971{
1972 struct drm_info_node *node = m->private;
1973 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001974 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulaada8f952015-12-15 13:17:12 +02001975 struct intel_opregion *opregion = &dev_priv->opregion;
1976
1977 if (opregion->vbt)
1978 seq_write(m, opregion->vbt, opregion->vbt_size);
1979
1980 return 0;
1981}
1982
Chris Wilson37811fc2010-08-25 22:45:57 +01001983static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1984{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001985 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001986 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301987 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001988 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001989 int ret;
1990
1991 ret = mutex_lock_interruptible(&dev->struct_mutex);
1992 if (ret)
1993 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001994
Daniel Vetter06957262015-08-10 13:34:08 +02001995#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson25bcce92016-07-02 15:36:00 +01001996 if (to_i915(dev)->fbdev) {
1997 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001998
Chris Wilson25bcce92016-07-02 15:36:00 +01001999 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
2000 fbdev_fb->base.width,
2001 fbdev_fb->base.height,
2002 fbdev_fb->base.depth,
2003 fbdev_fb->base.bits_per_pixel,
2004 fbdev_fb->base.modifier[0],
2005 drm_framebuffer_read_refcount(&fbdev_fb->base));
2006 describe_obj(m, fbdev_fb->obj);
2007 seq_putc(m, '\n');
2008 }
Daniel Vetter4520f532013-10-09 09:18:51 +02002009#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01002010
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002011 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02002012 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05302013 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
2014 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01002015 continue;
2016
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002017 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 +01002018 fb->base.width,
2019 fb->base.height,
2020 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01002021 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002022 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10002023 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00002024 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01002025 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01002026 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002027 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01002028 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01002029
2030 return 0;
2031}
2032
Chris Wilson7e37f882016-08-02 22:50:21 +01002033static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002034{
2035 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01002036 ring->space, ring->head, ring->tail,
2037 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002038}
2039
Ben Widawskye76d3632011-03-19 18:14:29 -07002040static int i915_context_status(struct seq_file *m, void *unused)
2041{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002042 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07002043 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002044 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002045 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002046 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00002047 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07002048
Daniel Vetterf3d28872014-05-29 23:23:08 +02002049 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002050 if (ret)
2051 return ret;
2052
Ben Widawskya33afea2013-09-17 21:12:45 -07002053 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01002054 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsond28b99a2016-05-24 14:53:39 +01002055 if (IS_ERR(ctx->file_priv)) {
2056 seq_puts(m, "(deleted) ");
2057 } else if (ctx->file_priv) {
2058 struct pid *pid = ctx->file_priv->file->pid;
2059 struct task_struct *task;
2060
2061 task = get_pid_task(pid, PIDTYPE_PID);
2062 if (task) {
2063 seq_printf(m, "(%s [%d]) ",
2064 task->comm, task->pid);
2065 put_task_struct(task);
2066 }
2067 } else {
2068 seq_puts(m, "(kernel) ");
2069 }
2070
Chris Wilsonbca44d82016-05-24 14:53:41 +01002071 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
2072 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07002073
Chris Wilsonbca44d82016-05-24 14:53:41 +01002074 for_each_engine(engine, dev_priv) {
2075 struct intel_context *ce = &ctx->engine[engine->id];
2076
2077 seq_printf(m, "%s: ", engine->name);
2078 seq_putc(m, ce->initialised ? 'I' : 'i');
2079 if (ce->state)
2080 describe_obj(m, ce->state);
Chris Wilsondca33ec2016-08-02 22:50:20 +01002081 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01002082 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002083 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002084 }
2085
Ben Widawskya33afea2013-09-17 21:12:45 -07002086 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002087 }
2088
Daniel Vetterf3d28872014-05-29 23:23:08 +02002089 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002090
2091 return 0;
2092}
2093
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002094static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002095 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002096 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002097{
Chris Wilsonbca44d82016-05-24 14:53:41 +01002098 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002099 struct page *page;
2100 uint32_t *reg_state;
2101 int j;
2102 unsigned long ggtt_offset = 0;
2103
Chris Wilson7069b142016-04-28 09:56:52 +01002104 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2105
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002106 if (ctx_obj == NULL) {
Chris Wilson7069b142016-04-28 09:56:52 +01002107 seq_puts(m, "\tNot allocated\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002108 return;
2109 }
2110
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002111 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2112 seq_puts(m, "\tNot bound in GGTT\n");
2113 else
2114 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2115
2116 if (i915_gem_object_get_pages(ctx_obj)) {
2117 seq_puts(m, "\tFailed to get pages for context object\n");
2118 return;
2119 }
2120
Alex Daid1675192015-08-12 15:43:43 +01002121 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002122 if (!WARN_ON(page == NULL)) {
2123 reg_state = kmap_atomic(page);
2124
2125 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2126 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2127 ggtt_offset + 4096 + (j * 4),
2128 reg_state[j], reg_state[j + 1],
2129 reg_state[j + 2], reg_state[j + 3]);
2130 }
2131 kunmap_atomic(reg_state);
2132 }
2133
2134 seq_putc(m, '\n');
2135}
2136
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002137static int i915_dump_lrc(struct seq_file *m, void *unused)
2138{
2139 struct drm_info_node *node = (struct drm_info_node *) m->private;
2140 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002141 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002142 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002143 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002144 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002145
2146 if (!i915.enable_execlists) {
2147 seq_printf(m, "Logical Ring Contexts are disabled\n");
2148 return 0;
2149 }
2150
2151 ret = mutex_lock_interruptible(&dev->struct_mutex);
2152 if (ret)
2153 return ret;
2154
Dave Gordone28e4042016-01-19 19:02:55 +00002155 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002156 for_each_engine(engine, dev_priv)
2157 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002158
2159 mutex_unlock(&dev->struct_mutex);
2160
2161 return 0;
2162}
2163
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002164static int i915_execlists(struct seq_file *m, void *data)
2165{
2166 struct drm_info_node *node = (struct drm_info_node *)m->private;
2167 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002168 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002169 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002170 u32 status_pointer;
2171 u8 read_pointer;
2172 u8 write_pointer;
2173 u32 status;
2174 u32 ctx_id;
2175 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002176 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002177
2178 if (!i915.enable_execlists) {
2179 seq_puts(m, "Logical Ring Contexts are disabled\n");
2180 return 0;
2181 }
2182
2183 ret = mutex_lock_interruptible(&dev->struct_mutex);
2184 if (ret)
2185 return ret;
2186
Michel Thierryfc0412e2014-10-16 16:13:38 +01002187 intel_runtime_pm_get(dev_priv);
2188
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002189 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002190 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002191 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002192
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002193 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002194
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002195 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2196 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002197 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2198 status, ctx_id);
2199
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002200 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002201 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2202
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002203 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002204 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002205 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002206 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002207 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2208 read_pointer, write_pointer);
2209
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002210 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002211 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2212 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002213
2214 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2215 i, status, ctx_id);
2216 }
2217
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002218 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002219 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002220 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002221 head_req = list_first_entry_or_null(&engine->execlist_queue,
2222 struct drm_i915_gem_request,
2223 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002224 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002225
2226 seq_printf(m, "\t%d requests in queue\n", count);
2227 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002228 seq_printf(m, "\tHead request context: %u\n",
2229 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002230 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002231 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002232 }
2233
2234 seq_putc(m, '\n');
2235 }
2236
Michel Thierryfc0412e2014-10-16 16:13:38 +01002237 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002238 mutex_unlock(&dev->struct_mutex);
2239
2240 return 0;
2241}
2242
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002243static const char *swizzle_string(unsigned swizzle)
2244{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002245 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002246 case I915_BIT_6_SWIZZLE_NONE:
2247 return "none";
2248 case I915_BIT_6_SWIZZLE_9:
2249 return "bit9";
2250 case I915_BIT_6_SWIZZLE_9_10:
2251 return "bit9/bit10";
2252 case I915_BIT_6_SWIZZLE_9_11:
2253 return "bit9/bit11";
2254 case I915_BIT_6_SWIZZLE_9_10_11:
2255 return "bit9/bit10/bit11";
2256 case I915_BIT_6_SWIZZLE_9_17:
2257 return "bit9/bit17";
2258 case I915_BIT_6_SWIZZLE_9_10_17:
2259 return "bit9/bit10/bit17";
2260 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002261 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002262 }
2263
2264 return "bug";
2265}
2266
2267static int i915_swizzle_info(struct seq_file *m, void *data)
2268{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002269 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002270 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002271 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002272 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002273
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002274 ret = mutex_lock_interruptible(&dev->struct_mutex);
2275 if (ret)
2276 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002277 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002278
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002279 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2280 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2281 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2282 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2283
2284 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2285 seq_printf(m, "DDC = 0x%08x\n",
2286 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002287 seq_printf(m, "DDC2 = 0x%08x\n",
2288 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002289 seq_printf(m, "C0DRB3 = 0x%04x\n",
2290 I915_READ16(C0DRB3));
2291 seq_printf(m, "C1DRB3 = 0x%04x\n",
2292 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002293 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002294 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2295 I915_READ(MAD_DIMM_C0));
2296 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2297 I915_READ(MAD_DIMM_C1));
2298 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2299 I915_READ(MAD_DIMM_C2));
2300 seq_printf(m, "TILECTL = 0x%08x\n",
2301 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002302 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002303 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2304 I915_READ(GAMTARBMODE));
2305 else
2306 seq_printf(m, "ARB_MODE = 0x%08x\n",
2307 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002308 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2309 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002310 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002311
2312 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2313 seq_puts(m, "L-shaped memory detected\n");
2314
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002315 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002316 mutex_unlock(&dev->struct_mutex);
2317
2318 return 0;
2319}
2320
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002321static int per_file_ctx(int id, void *ptr, void *data)
2322{
Chris Wilsone2efd132016-05-24 14:53:34 +01002323 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002324 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002325 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2326
2327 if (!ppgtt) {
2328 seq_printf(m, " no ppgtt for context %d\n",
2329 ctx->user_handle);
2330 return 0;
2331 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002332
Oscar Mateof83d6512014-05-22 14:13:38 +01002333 if (i915_gem_context_is_default(ctx))
2334 seq_puts(m, " default context:\n");
2335 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002336 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002337 ppgtt->debug_dump(ppgtt, m);
2338
2339 return 0;
2340}
2341
Ben Widawsky77df6772013-11-02 21:07:30 -07002342static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002343{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002344 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002345 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002346 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002347 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002348
Ben Widawsky77df6772013-11-02 21:07:30 -07002349 if (!ppgtt)
2350 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002351
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002352 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002353 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002354 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002355 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002356 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002357 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002358 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002359 }
2360 }
2361}
2362
2363static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2364{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002365 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002366 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002367
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002368 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002369 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2370
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002371 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002372 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002373 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002374 seq_printf(m, "GFX_MODE: 0x%08x\n",
2375 I915_READ(RING_MODE_GEN7(engine)));
2376 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2377 I915_READ(RING_PP_DIR_BASE(engine)));
2378 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2379 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2380 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2381 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002382 }
2383 if (dev_priv->mm.aliasing_ppgtt) {
2384 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2385
Damien Lespiau267f0c92013-06-24 22:59:48 +01002386 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002387 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002388
Ben Widawsky87d60b62013-12-06 14:11:29 -08002389 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002390 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002391
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002392 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002393}
2394
2395static int i915_ppgtt_info(struct seq_file *m, void *data)
2396{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002397 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002398 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002399 struct drm_i915_private *dev_priv = to_i915(dev);
Michel Thierryea91e402015-07-29 17:23:57 +01002400 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002401
2402 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2403 if (ret)
2404 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002405 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002406
2407 if (INTEL_INFO(dev)->gen >= 8)
2408 gen8_ppgtt_info(m, dev);
2409 else if (INTEL_INFO(dev)->gen >= 6)
2410 gen6_ppgtt_info(m, dev);
2411
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002412 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002413 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2414 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002415 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002416
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002417 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002418 if (!task) {
2419 ret = -ESRCH;
Wei Yongjunb0212482016-06-13 23:42:00 +00002420 goto out_unlock;
Dan Carpenter06812762015-10-02 18:14:22 +03002421 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002422 seq_printf(m, "\nproc: %s\n", task->comm);
2423 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002424 idr_for_each(&file_priv->context_idr, per_file_ctx,
2425 (void *)(unsigned long)m);
2426 }
Wei Yongjunb0212482016-06-13 23:42:00 +00002427out_unlock:
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002428 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002429
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002430 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002431 mutex_unlock(&dev->struct_mutex);
2432
Dan Carpenter06812762015-10-02 18:14:22 +03002433 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002434}
2435
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002436static int count_irq_waiters(struct drm_i915_private *i915)
2437{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002438 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002439 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002440
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002441 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002442 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002443
2444 return count;
2445}
2446
Chris Wilson1854d5c2015-04-07 16:20:32 +01002447static int i915_rps_boost_info(struct seq_file *m, void *data)
2448{
2449 struct drm_info_node *node = m->private;
2450 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002451 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002452 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002453
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002454 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002455 seq_printf(m, "GPU busy? %s [%x]\n",
2456 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002457 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2458 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2459 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2460 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2461 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2462 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2463 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002464
2465 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002466 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002467 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2468 struct drm_i915_file_private *file_priv = file->driver_priv;
2469 struct task_struct *task;
2470
2471 rcu_read_lock();
2472 task = pid_task(file->pid, PIDTYPE_PID);
2473 seq_printf(m, "%s [%d]: %d boosts%s\n",
2474 task ? task->comm : "<unknown>",
2475 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002476 file_priv->rps.boosts,
2477 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002478 rcu_read_unlock();
2479 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002480 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002481 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002482 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002483
Chris Wilson8d3afd72015-05-21 21:01:47 +01002484 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002485}
2486
Ben Widawsky63573eb2013-07-04 11:02:07 -07002487static int i915_llc(struct seq_file *m, void *data)
2488{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002489 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002490 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002491 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002492 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002493
Ben Widawsky63573eb2013-07-04 11:02:07 -07002494 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002495 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2496 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002497
2498 return 0;
2499}
2500
Alex Daifdf5d352015-08-12 15:43:37 +01002501static int i915_guc_load_status_info(struct seq_file *m, void *data)
2502{
2503 struct drm_info_node *node = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002504 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
Alex Daifdf5d352015-08-12 15:43:37 +01002505 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2506 u32 tmp, i;
2507
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002508 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002509 return 0;
2510
2511 seq_printf(m, "GuC firmware status:\n");
2512 seq_printf(m, "\tpath: %s\n",
2513 guc_fw->guc_fw_path);
2514 seq_printf(m, "\tfetch: %s\n",
2515 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2516 seq_printf(m, "\tload: %s\n",
2517 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2518 seq_printf(m, "\tversion wanted: %d.%d\n",
2519 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2520 seq_printf(m, "\tversion found: %d.%d\n",
2521 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002522 seq_printf(m, "\theader: offset is %d; size = %d\n",
2523 guc_fw->header_offset, guc_fw->header_size);
2524 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2525 guc_fw->ucode_offset, guc_fw->ucode_size);
2526 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2527 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002528
2529 tmp = I915_READ(GUC_STATUS);
2530
2531 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2532 seq_printf(m, "\tBootrom status = 0x%x\n",
2533 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2534 seq_printf(m, "\tuKernel status = 0x%x\n",
2535 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2536 seq_printf(m, "\tMIA Core status = 0x%x\n",
2537 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2538 seq_puts(m, "\nScratch registers:\n");
2539 for (i = 0; i < 16; i++)
2540 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2541
2542 return 0;
2543}
2544
Dave Gordon8b417c22015-08-12 15:43:44 +01002545static void i915_guc_client_info(struct seq_file *m,
2546 struct drm_i915_private *dev_priv,
2547 struct i915_guc_client *client)
2548{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002549 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002550 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002551
2552 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2553 client->priority, client->ctx_index, client->proc_desc_offset);
2554 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2555 client->doorbell_id, client->doorbell_offset, client->cookie);
2556 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2557 client->wq_size, client->wq_offset, client->wq_tail);
2558
Dave Gordon551aaec2016-05-13 15:36:33 +01002559 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002560 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2561 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2562 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2563
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002564 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002565 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordon0b63bb12016-06-20 15:18:07 +01002566 client->submissions[engine->id],
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002567 engine->name);
Dave Gordon0b63bb12016-06-20 15:18:07 +01002568 tot += client->submissions[engine->id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002569 }
2570 seq_printf(m, "\tTotal: %llu\n", tot);
2571}
2572
2573static int i915_guc_info(struct seq_file *m, void *data)
2574{
2575 struct drm_info_node *node = m->private;
2576 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002577 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Gordon8b417c22015-08-12 15:43:44 +01002578 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002579 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002580 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002581 u64 total = 0;
2582
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002583 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002584 return 0;
2585
Alex Dai5a843302015-12-02 16:56:29 -08002586 if (mutex_lock_interruptible(&dev->struct_mutex))
2587 return 0;
2588
Dave Gordon8b417c22015-08-12 15:43:44 +01002589 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002590 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002591 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002592 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002593
2594 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002595
Dave Gordon9636f6d2016-06-13 17:57:28 +01002596 seq_printf(m, "Doorbell map:\n");
2597 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2598 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2599
Dave Gordon8b417c22015-08-12 15:43:44 +01002600 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2601 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2602 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2603 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2604 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2605
2606 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002607 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002608 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordon0b63bb12016-06-20 15:18:07 +01002609 engine->name, guc.submissions[engine->id],
2610 guc.last_seqno[engine->id]);
2611 total += guc.submissions[engine->id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002612 }
2613 seq_printf(m, "\t%s: %llu\n", "Total", total);
2614
2615 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2616 i915_guc_client_info(m, dev_priv, &client);
2617
2618 /* Add more as required ... */
2619
2620 return 0;
2621}
2622
Alex Dai4c7e77f2015-08-12 15:43:40 +01002623static int i915_guc_log_dump(struct seq_file *m, void *data)
2624{
2625 struct drm_info_node *node = m->private;
2626 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002627 struct drm_i915_private *dev_priv = to_i915(dev);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002628 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2629 u32 *log;
2630 int i = 0, pg;
2631
2632 if (!log_obj)
2633 return 0;
2634
2635 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2636 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2637
2638 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2639 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2640 *(log + i), *(log + i + 1),
2641 *(log + i + 2), *(log + i + 3));
2642
2643 kunmap_atomic(log);
2644 }
2645
2646 seq_putc(m, '\n');
2647
2648 return 0;
2649}
2650
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002651static int i915_edp_psr_status(struct seq_file *m, void *data)
2652{
2653 struct drm_info_node *node = m->private;
2654 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002655 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002656 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002657 u32 stat[3];
2658 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002659 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002660
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002661 if (!HAS_PSR(dev)) {
2662 seq_puts(m, "PSR not supported\n");
2663 return 0;
2664 }
2665
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002666 intel_runtime_pm_get(dev_priv);
2667
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002668 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002669 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2670 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002671 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002672 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002673 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2674 dev_priv->psr.busy_frontbuffer_bits);
2675 seq_printf(m, "Re-enable work scheduled: %s\n",
2676 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002677
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002678 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002679 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002680 else {
2681 for_each_pipe(dev_priv, pipe) {
2682 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2683 VLV_EDP_PSR_CURR_STATE_MASK;
2684 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2685 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2686 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002687 }
2688 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002689
2690 seq_printf(m, "Main link in standby mode: %s\n",
2691 yesno(dev_priv->psr.link_standby));
2692
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002693 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002694
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002695 if (!HAS_DDI(dev))
2696 for_each_pipe(dev_priv, pipe) {
2697 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2698 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2699 seq_printf(m, " pipe %c", pipe_name(pipe));
2700 }
2701 seq_puts(m, "\n");
2702
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002703 /*
2704 * VLV/CHV PSR has no kind of performance counter
2705 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2706 */
2707 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002708 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002709 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002710
2711 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2712 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002713 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002714
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002715 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002716 return 0;
2717}
2718
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002719static int i915_sink_crc(struct seq_file *m, void *data)
2720{
2721 struct drm_info_node *node = m->private;
2722 struct drm_device *dev = node->minor->dev;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002723 struct intel_connector *connector;
2724 struct intel_dp *intel_dp = NULL;
2725 int ret;
2726 u8 crc[6];
2727
2728 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002729 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002730 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002731
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002732 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002733 continue;
2734
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002735 crtc = connector->base.state->crtc;
2736 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002737 continue;
2738
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002739 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002740 continue;
2741
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002742 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002743
2744 ret = intel_dp_sink_crc(intel_dp, crc);
2745 if (ret)
2746 goto out;
2747
2748 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2749 crc[0], crc[1], crc[2],
2750 crc[3], crc[4], crc[5]);
2751 goto out;
2752 }
2753 ret = -ENODEV;
2754out:
2755 drm_modeset_unlock_all(dev);
2756 return ret;
2757}
2758
Jesse Barnesec013e72013-08-20 10:29:23 +01002759static int i915_energy_uJ(struct seq_file *m, void *data)
2760{
2761 struct drm_info_node *node = m->private;
2762 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002763 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesec013e72013-08-20 10:29:23 +01002764 u64 power;
2765 u32 units;
2766
2767 if (INTEL_INFO(dev)->gen < 6)
2768 return -ENODEV;
2769
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002770 intel_runtime_pm_get(dev_priv);
2771
Jesse Barnesec013e72013-08-20 10:29:23 +01002772 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2773 power = (power & 0x1f00) >> 8;
2774 units = 1000000 / (1 << power); /* convert to uJ */
2775 power = I915_READ(MCH_SECP_NRG_STTS);
2776 power *= units;
2777
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002778 intel_runtime_pm_put(dev_priv);
2779
Jesse Barnesec013e72013-08-20 10:29:23 +01002780 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002781
2782 return 0;
2783}
2784
Damien Lespiau6455c872015-06-04 18:23:57 +01002785static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002786{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002787 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002788 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002789 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni371db662013-08-19 13:18:10 -03002790
Chris Wilsona156e642016-04-03 14:14:21 +01002791 if (!HAS_RUNTIME_PM(dev_priv))
2792 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002793
Chris Wilson67d97da2016-07-04 08:08:31 +01002794 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002795 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002796 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002797#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002798 seq_printf(m, "Usage count: %d\n",
2799 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002800#else
2801 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2802#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002803 seq_printf(m, "PCI device power state: %s [%d]\n",
Chris Wilson91c8a322016-07-05 10:40:23 +01002804 pci_power_name(dev_priv->drm.pdev->current_state),
2805 dev_priv->drm.pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002806
Jesse Barnesec013e72013-08-20 10:29:23 +01002807 return 0;
2808}
2809
Imre Deak1da51582013-11-25 17:15:35 +02002810static int i915_power_domain_info(struct seq_file *m, void *unused)
2811{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002812 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002813 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002814 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1da51582013-11-25 17:15:35 +02002815 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2816 int i;
2817
2818 mutex_lock(&power_domains->lock);
2819
2820 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2821 for (i = 0; i < power_domains->power_well_count; i++) {
2822 struct i915_power_well *power_well;
2823 enum intel_display_power_domain power_domain;
2824
2825 power_well = &power_domains->power_wells[i];
2826 seq_printf(m, "%-25s %d\n", power_well->name,
2827 power_well->count);
2828
2829 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2830 power_domain++) {
2831 if (!(BIT(power_domain) & power_well->domains))
2832 continue;
2833
2834 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002835 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002836 power_domains->domain_use_count[power_domain]);
2837 }
2838 }
2839
2840 mutex_unlock(&power_domains->lock);
2841
2842 return 0;
2843}
2844
Damien Lespiaub7cec662015-10-27 14:47:01 +02002845static int i915_dmc_info(struct seq_file *m, void *unused)
2846{
2847 struct drm_info_node *node = m->private;
2848 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002849 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002850 struct intel_csr *csr;
2851
2852 if (!HAS_CSR(dev)) {
2853 seq_puts(m, "not supported\n");
2854 return 0;
2855 }
2856
2857 csr = &dev_priv->csr;
2858
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002859 intel_runtime_pm_get(dev_priv);
2860
Damien Lespiaub7cec662015-10-27 14:47:01 +02002861 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2862 seq_printf(m, "path: %s\n", csr->fw_path);
2863
2864 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002865 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002866
2867 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2868 CSR_VERSION_MINOR(csr->version));
2869
Damien Lespiau83372062015-10-30 17:53:32 +02002870 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2871 seq_printf(m, "DC3 -> DC5 count: %d\n",
2872 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2873 seq_printf(m, "DC5 -> DC6 count: %d\n",
2874 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002875 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2876 seq_printf(m, "DC3 -> DC5 count: %d\n",
2877 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002878 }
2879
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002880out:
2881 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2882 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2883 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2884
Damien Lespiau83372062015-10-30 17:53:32 +02002885 intel_runtime_pm_put(dev_priv);
2886
Damien Lespiaub7cec662015-10-27 14:47:01 +02002887 return 0;
2888}
2889
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002890static void intel_seq_print_mode(struct seq_file *m, int tabs,
2891 struct drm_display_mode *mode)
2892{
2893 int i;
2894
2895 for (i = 0; i < tabs; i++)
2896 seq_putc(m, '\t');
2897
2898 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",
2899 mode->base.id, mode->name,
2900 mode->vrefresh, mode->clock,
2901 mode->hdisplay, mode->hsync_start,
2902 mode->hsync_end, mode->htotal,
2903 mode->vdisplay, mode->vsync_start,
2904 mode->vsync_end, mode->vtotal,
2905 mode->type, mode->flags);
2906}
2907
2908static void intel_encoder_info(struct seq_file *m,
2909 struct intel_crtc *intel_crtc,
2910 struct intel_encoder *intel_encoder)
2911{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002912 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002913 struct drm_device *dev = node->minor->dev;
2914 struct drm_crtc *crtc = &intel_crtc->base;
2915 struct intel_connector *intel_connector;
2916 struct drm_encoder *encoder;
2917
2918 encoder = &intel_encoder->base;
2919 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002920 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002921 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2922 struct drm_connector *connector = &intel_connector->base;
2923 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2924 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002925 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002926 drm_get_connector_status_name(connector->status));
2927 if (connector->status == connector_status_connected) {
2928 struct drm_display_mode *mode = &crtc->mode;
2929 seq_printf(m, ", mode:\n");
2930 intel_seq_print_mode(m, 2, mode);
2931 } else {
2932 seq_putc(m, '\n');
2933 }
2934 }
2935}
2936
2937static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2938{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002939 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002940 struct drm_device *dev = node->minor->dev;
2941 struct drm_crtc *crtc = &intel_crtc->base;
2942 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002943 struct drm_plane_state *plane_state = crtc->primary->state;
2944 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002945
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002946 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002947 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002948 fb->base.id, plane_state->src_x >> 16,
2949 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002950 else
2951 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002952 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2953 intel_encoder_info(m, intel_crtc, intel_encoder);
2954}
2955
2956static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2957{
2958 struct drm_display_mode *mode = panel->fixed_mode;
2959
2960 seq_printf(m, "\tfixed mode:\n");
2961 intel_seq_print_mode(m, 2, mode);
2962}
2963
2964static void intel_dp_info(struct seq_file *m,
2965 struct intel_connector *intel_connector)
2966{
2967 struct intel_encoder *intel_encoder = intel_connector->encoder;
2968 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2969
2970 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002971 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002972 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002973 intel_panel_info(m, &intel_connector->panel);
2974}
2975
2976static void intel_hdmi_info(struct seq_file *m,
2977 struct intel_connector *intel_connector)
2978{
2979 struct intel_encoder *intel_encoder = intel_connector->encoder;
2980 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2981
Jani Nikula742f4912015-09-03 11:16:09 +03002982 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002983}
2984
2985static void intel_lvds_info(struct seq_file *m,
2986 struct intel_connector *intel_connector)
2987{
2988 intel_panel_info(m, &intel_connector->panel);
2989}
2990
2991static void intel_connector_info(struct seq_file *m,
2992 struct drm_connector *connector)
2993{
2994 struct intel_connector *intel_connector = to_intel_connector(connector);
2995 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002996 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002997
2998 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002999 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003000 drm_get_connector_status_name(connector->status));
3001 if (connector->status == connector_status_connected) {
3002 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3003 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3004 connector->display_info.width_mm,
3005 connector->display_info.height_mm);
3006 seq_printf(m, "\tsubpixel order: %s\n",
3007 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3008 seq_printf(m, "\tCEA rev: %d\n",
3009 connector->display_info.cea_rev);
3010 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003011
3012 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3013 return;
3014
3015 switch (connector->connector_type) {
3016 case DRM_MODE_CONNECTOR_DisplayPort:
3017 case DRM_MODE_CONNECTOR_eDP:
3018 intel_dp_info(m, intel_connector);
3019 break;
3020 case DRM_MODE_CONNECTOR_LVDS:
3021 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003022 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003023 break;
3024 case DRM_MODE_CONNECTOR_HDMIA:
3025 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3026 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3027 intel_hdmi_info(m, intel_connector);
3028 break;
3029 default:
3030 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003031 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003032
Jesse Barnesf103fc72014-02-20 12:39:57 -08003033 seq_printf(m, "\tmodes:\n");
3034 list_for_each_entry(mode, &connector->modes, head)
3035 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003036}
3037
Chris Wilson065f2ec2014-03-12 09:13:13 +00003038static bool cursor_active(struct drm_device *dev, int pipe)
3039{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003040 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003041 u32 state;
3042
3043 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003044 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003045 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003046 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003047
3048 return state;
3049}
3050
3051static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
3052{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003053 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003054 u32 pos;
3055
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003056 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003057
3058 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3059 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3060 *x = -*x;
3061
3062 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3063 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3064 *y = -*y;
3065
3066 return cursor_active(dev, pipe);
3067}
3068
Robert Fekete3abc4e02015-10-27 16:58:32 +01003069static const char *plane_type(enum drm_plane_type type)
3070{
3071 switch (type) {
3072 case DRM_PLANE_TYPE_OVERLAY:
3073 return "OVL";
3074 case DRM_PLANE_TYPE_PRIMARY:
3075 return "PRI";
3076 case DRM_PLANE_TYPE_CURSOR:
3077 return "CUR";
3078 /*
3079 * Deliberately omitting default: to generate compiler warnings
3080 * when a new drm_plane_type gets added.
3081 */
3082 }
3083
3084 return "unknown";
3085}
3086
3087static const char *plane_rotation(unsigned int rotation)
3088{
3089 static char buf[48];
3090 /*
3091 * According to doc only one DRM_ROTATE_ is allowed but this
3092 * will print them all to visualize if the values are misused
3093 */
3094 snprintf(buf, sizeof(buf),
3095 "%s%s%s%s%s%s(0x%08x)",
3096 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3097 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3098 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3099 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3100 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3101 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3102 rotation);
3103
3104 return buf;
3105}
3106
3107static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3108{
3109 struct drm_info_node *node = m->private;
3110 struct drm_device *dev = node->minor->dev;
3111 struct intel_plane *intel_plane;
3112
3113 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3114 struct drm_plane_state *state;
3115 struct drm_plane *plane = &intel_plane->base;
3116
3117 if (!plane->state) {
3118 seq_puts(m, "plane->state is NULL!\n");
3119 continue;
3120 }
3121
3122 state = plane->state;
3123
3124 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",
3125 plane->base.id,
3126 plane_type(intel_plane->base.type),
3127 state->crtc_x, state->crtc_y,
3128 state->crtc_w, state->crtc_h,
3129 (state->src_x >> 16),
3130 ((state->src_x & 0xffff) * 15625) >> 10,
3131 (state->src_y >> 16),
3132 ((state->src_y & 0xffff) * 15625) >> 10,
3133 (state->src_w >> 16),
3134 ((state->src_w & 0xffff) * 15625) >> 10,
3135 (state->src_h >> 16),
3136 ((state->src_h & 0xffff) * 15625) >> 10,
3137 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3138 plane_rotation(state->rotation));
3139 }
3140}
3141
3142static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3143{
3144 struct intel_crtc_state *pipe_config;
3145 int num_scalers = intel_crtc->num_scalers;
3146 int i;
3147
3148 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3149
3150 /* Not all platformas have a scaler */
3151 if (num_scalers) {
3152 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3153 num_scalers,
3154 pipe_config->scaler_state.scaler_users,
3155 pipe_config->scaler_state.scaler_id);
3156
3157 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3158 struct intel_scaler *sc =
3159 &pipe_config->scaler_state.scalers[i];
3160
3161 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3162 i, yesno(sc->in_use), sc->mode);
3163 }
3164 seq_puts(m, "\n");
3165 } else {
3166 seq_puts(m, "\tNo scalers available on this platform\n");
3167 }
3168}
3169
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003170static int i915_display_info(struct seq_file *m, void *unused)
3171{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003172 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003173 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003174 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003175 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003176 struct drm_connector *connector;
3177
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003178 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003179 drm_modeset_lock_all(dev);
3180 seq_printf(m, "CRTC info\n");
3181 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003182 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003183 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003184 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003185 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003186
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003187 pipe_config = to_intel_crtc_state(crtc->base.state);
3188
Robert Fekete3abc4e02015-10-27 16:58:32 +01003189 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003190 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003191 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003192 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3193 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3194
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003195 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003196 intel_crtc_info(m, crtc);
3197
Paulo Zanonia23dc652014-04-01 14:55:11 -03003198 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003199 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 +03003200 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003201 x, y, crtc->base.cursor->state->crtc_w,
3202 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003203 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003204 intel_scaler_info(m, crtc);
3205 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003206 }
Daniel Vettercace8412014-05-22 17:56:31 +02003207
3208 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3209 yesno(!crtc->cpu_fifo_underrun_disabled),
3210 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003211 }
3212
3213 seq_printf(m, "\n");
3214 seq_printf(m, "Connector info\n");
3215 seq_printf(m, "--------------\n");
3216 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3217 intel_connector_info(m, connector);
3218 }
3219 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003220 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003221
3222 return 0;
3223}
3224
Ben Widawskye04934c2014-06-30 09:53:42 -07003225static int i915_semaphore_status(struct seq_file *m, void *unused)
3226{
3227 struct drm_info_node *node = (struct drm_info_node *) m->private;
3228 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003229 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003230 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003231 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003232 enum intel_engine_id id;
3233 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003234
Chris Wilson39df9192016-07-20 13:31:57 +01003235 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003236 seq_puts(m, "Semaphores are disabled\n");
3237 return 0;
3238 }
3239
3240 ret = mutex_lock_interruptible(&dev->struct_mutex);
3241 if (ret)
3242 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003243 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003244
3245 if (IS_BROADWELL(dev)) {
3246 struct page *page;
3247 uint64_t *seqno;
3248
3249 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3250
3251 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003252 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003253 uint64_t offset;
3254
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003255 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003256
3257 seq_puts(m, " Last signal:");
3258 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003259 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003260 seq_printf(m, "0x%08llx (0x%02llx) ",
3261 seqno[offset], offset * 8);
3262 }
3263 seq_putc(m, '\n');
3264
3265 seq_puts(m, " Last wait: ");
3266 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003267 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003268 seq_printf(m, "0x%08llx (0x%02llx) ",
3269 seqno[offset], offset * 8);
3270 }
3271 seq_putc(m, '\n');
3272
3273 }
3274 kunmap_atomic(seqno);
3275 } else {
3276 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003277 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003278 for (j = 0; j < num_rings; j++)
3279 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003280 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003281 seq_putc(m, '\n');
3282 }
3283
3284 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003285 for_each_engine(engine, dev_priv) {
3286 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003287 seq_printf(m, " 0x%08x ",
3288 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003289 seq_putc(m, '\n');
3290 }
3291 seq_putc(m, '\n');
3292
Paulo Zanoni03872062014-07-09 14:31:57 -03003293 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003294 mutex_unlock(&dev->struct_mutex);
3295 return 0;
3296}
3297
Daniel Vetter728e29d2014-06-25 22:01:53 +03003298static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3299{
3300 struct drm_info_node *node = (struct drm_info_node *) m->private;
3301 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003302 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003303 int i;
3304
3305 drm_modeset_lock_all(dev);
3306 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3307 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3308
3309 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003310 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3311 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003312 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003313 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3314 seq_printf(m, " dpll_md: 0x%08x\n",
3315 pll->config.hw_state.dpll_md);
3316 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3317 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3318 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003319 }
3320 drm_modeset_unlock_all(dev);
3321
3322 return 0;
3323}
3324
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003325static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003326{
3327 int i;
3328 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003329 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003330 struct drm_info_node *node = (struct drm_info_node *) m->private;
3331 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003332 struct drm_i915_private *dev_priv = to_i915(dev);
Arun Siluvery33136b02016-01-21 21:43:47 +00003333 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003334 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003335
Arun Siluvery888b5992014-08-26 14:44:51 +01003336 ret = mutex_lock_interruptible(&dev->struct_mutex);
3337 if (ret)
3338 return ret;
3339
3340 intel_runtime_pm_get(dev_priv);
3341
Arun Siluvery33136b02016-01-21 21:43:47 +00003342 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003343 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003344 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003345 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003346 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003347 i915_reg_t addr;
3348 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003349 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003350
Arun Siluvery33136b02016-01-21 21:43:47 +00003351 addr = workarounds->reg[i].addr;
3352 mask = workarounds->reg[i].mask;
3353 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003354 read = I915_READ(addr);
3355 ok = (value & mask) == (read & mask);
3356 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 +02003357 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003358 }
3359
3360 intel_runtime_pm_put(dev_priv);
3361 mutex_unlock(&dev->struct_mutex);
3362
3363 return 0;
3364}
3365
Damien Lespiauc5511e42014-11-04 17:06:51 +00003366static int i915_ddb_info(struct seq_file *m, void *unused)
3367{
3368 struct drm_info_node *node = m->private;
3369 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003370 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiauc5511e42014-11-04 17:06:51 +00003371 struct skl_ddb_allocation *ddb;
3372 struct skl_ddb_entry *entry;
3373 enum pipe pipe;
3374 int plane;
3375
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003376 if (INTEL_INFO(dev)->gen < 9)
3377 return 0;
3378
Damien Lespiauc5511e42014-11-04 17:06:51 +00003379 drm_modeset_lock_all(dev);
3380
3381 ddb = &dev_priv->wm.skl_hw.ddb;
3382
3383 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3384
3385 for_each_pipe(dev_priv, pipe) {
3386 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3387
Damien Lespiaudd740782015-02-28 14:54:08 +00003388 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003389 entry = &ddb->plane[pipe][plane];
3390 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3391 entry->start, entry->end,
3392 skl_ddb_entry_size(entry));
3393 }
3394
Matt Roper4969d332015-09-24 15:53:10 -07003395 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003396 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3397 entry->end, skl_ddb_entry_size(entry));
3398 }
3399
3400 drm_modeset_unlock_all(dev);
3401
3402 return 0;
3403}
3404
Vandana Kannana54746e2015-03-03 20:53:10 +05303405static void drrs_status_per_crtc(struct seq_file *m,
3406 struct drm_device *dev, struct intel_crtc *intel_crtc)
3407{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003408 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303409 struct i915_drrs *drrs = &dev_priv->drrs;
3410 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003411 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303412
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003413 drm_for_each_connector(connector, dev) {
3414 if (connector->state->crtc != &intel_crtc->base)
3415 continue;
3416
3417 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303418 }
3419
3420 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3421 seq_puts(m, "\tVBT: DRRS_type: Static");
3422 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3423 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3424 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3425 seq_puts(m, "\tVBT: DRRS_type: None");
3426 else
3427 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3428
3429 seq_puts(m, "\n\n");
3430
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003431 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303432 struct intel_panel *panel;
3433
3434 mutex_lock(&drrs->mutex);
3435 /* DRRS Supported */
3436 seq_puts(m, "\tDRRS Supported: Yes\n");
3437
3438 /* disable_drrs() will make drrs->dp NULL */
3439 if (!drrs->dp) {
3440 seq_puts(m, "Idleness DRRS: Disabled");
3441 mutex_unlock(&drrs->mutex);
3442 return;
3443 }
3444
3445 panel = &drrs->dp->attached_connector->panel;
3446 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3447 drrs->busy_frontbuffer_bits);
3448
3449 seq_puts(m, "\n\t\t");
3450 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3451 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3452 vrefresh = panel->fixed_mode->vrefresh;
3453 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3454 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3455 vrefresh = panel->downclock_mode->vrefresh;
3456 } else {
3457 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3458 drrs->refresh_rate_type);
3459 mutex_unlock(&drrs->mutex);
3460 return;
3461 }
3462 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3463
3464 seq_puts(m, "\n\t\t");
3465 mutex_unlock(&drrs->mutex);
3466 } else {
3467 /* DRRS not supported. Print the VBT parameter*/
3468 seq_puts(m, "\tDRRS Supported : No");
3469 }
3470 seq_puts(m, "\n");
3471}
3472
3473static int i915_drrs_status(struct seq_file *m, void *unused)
3474{
3475 struct drm_info_node *node = m->private;
3476 struct drm_device *dev = node->minor->dev;
3477 struct intel_crtc *intel_crtc;
3478 int active_crtc_cnt = 0;
3479
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003480 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303481 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003482 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303483 active_crtc_cnt++;
3484 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3485
3486 drrs_status_per_crtc(m, dev, intel_crtc);
3487 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303488 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003489 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303490
3491 if (!active_crtc_cnt)
3492 seq_puts(m, "No active crtc found\n");
3493
3494 return 0;
3495}
3496
Damien Lespiau07144422013-10-15 18:55:40 +01003497struct pipe_crc_info {
3498 const char *name;
3499 struct drm_device *dev;
3500 enum pipe pipe;
3501};
3502
Dave Airlie11bed952014-05-12 15:22:27 +10003503static int i915_dp_mst_info(struct seq_file *m, void *unused)
3504{
3505 struct drm_info_node *node = (struct drm_info_node *) m->private;
3506 struct drm_device *dev = node->minor->dev;
Dave Airlie11bed952014-05-12 15:22:27 +10003507 struct intel_encoder *intel_encoder;
3508 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003509 struct drm_connector *connector;
3510
Dave Airlie11bed952014-05-12 15:22:27 +10003511 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003512 drm_for_each_connector(connector, dev) {
3513 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003514 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003515
3516 intel_encoder = intel_attached_encoder(connector);
3517 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3518 continue;
3519
3520 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003521 if (!intel_dig_port->dp.can_mst)
3522 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003523
Jim Bride40ae80c2016-04-14 10:18:37 -07003524 seq_printf(m, "MST Source Port %c\n",
3525 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003526 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3527 }
3528 drm_modeset_unlock_all(dev);
3529 return 0;
3530}
3531
Damien Lespiau07144422013-10-15 18:55:40 +01003532static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003533{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003534 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003535 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003536 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3537
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003538 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3539 return -ENODEV;
3540
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003541 spin_lock_irq(&pipe_crc->lock);
3542
3543 if (pipe_crc->opened) {
3544 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003545 return -EBUSY; /* already open */
3546 }
3547
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003548 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003549 filep->private_data = inode->i_private;
3550
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003551 spin_unlock_irq(&pipe_crc->lock);
3552
Damien Lespiau07144422013-10-15 18:55:40 +01003553 return 0;
3554}
3555
3556static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3557{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003558 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003559 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003560 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3561
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003562 spin_lock_irq(&pipe_crc->lock);
3563 pipe_crc->opened = false;
3564 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003565
Damien Lespiau07144422013-10-15 18:55:40 +01003566 return 0;
3567}
3568
3569/* (6 fields, 8 chars each, space separated (5) + '\n') */
3570#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3571/* account for \'0' */
3572#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3573
3574static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3575{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003576 assert_spin_locked(&pipe_crc->lock);
3577 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3578 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003579}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003580
Damien Lespiau07144422013-10-15 18:55:40 +01003581static ssize_t
3582i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3583 loff_t *pos)
3584{
3585 struct pipe_crc_info *info = filep->private_data;
3586 struct drm_device *dev = info->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003587 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003588 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3589 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003590 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003591 ssize_t bytes_read;
3592
3593 /*
3594 * Don't allow user space to provide buffers not big enough to hold
3595 * a line of data.
3596 */
3597 if (count < PIPE_CRC_LINE_LEN)
3598 return -EINVAL;
3599
3600 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3601 return 0;
3602
3603 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003604 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003605 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003606 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003607
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003608 if (filep->f_flags & O_NONBLOCK) {
3609 spin_unlock_irq(&pipe_crc->lock);
3610 return -EAGAIN;
3611 }
3612
3613 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3614 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3615 if (ret) {
3616 spin_unlock_irq(&pipe_crc->lock);
3617 return ret;
3618 }
Damien Lespiau07144422013-10-15 18:55:40 +01003619 }
3620
3621 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003622 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003623
Damien Lespiau07144422013-10-15 18:55:40 +01003624 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003625 while (n_entries > 0) {
3626 struct intel_pipe_crc_entry *entry =
3627 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003628 int ret;
3629
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003630 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3631 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3632 break;
3633
3634 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3635 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3636
Damien Lespiau07144422013-10-15 18:55:40 +01003637 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3638 "%8u %8x %8x %8x %8x %8x\n",
3639 entry->frame, entry->crc[0],
3640 entry->crc[1], entry->crc[2],
3641 entry->crc[3], entry->crc[4]);
3642
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003643 spin_unlock_irq(&pipe_crc->lock);
3644
3645 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003646 if (ret == PIPE_CRC_LINE_LEN)
3647 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003648
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003649 user_buf += PIPE_CRC_LINE_LEN;
3650 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003651
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003652 spin_lock_irq(&pipe_crc->lock);
3653 }
3654
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003655 spin_unlock_irq(&pipe_crc->lock);
3656
Damien Lespiau07144422013-10-15 18:55:40 +01003657 return bytes_read;
3658}
3659
3660static const struct file_operations i915_pipe_crc_fops = {
3661 .owner = THIS_MODULE,
3662 .open = i915_pipe_crc_open,
3663 .read = i915_pipe_crc_read,
3664 .release = i915_pipe_crc_release,
3665};
3666
3667static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3668 {
3669 .name = "i915_pipe_A_crc",
3670 .pipe = PIPE_A,
3671 },
3672 {
3673 .name = "i915_pipe_B_crc",
3674 .pipe = PIPE_B,
3675 },
3676 {
3677 .name = "i915_pipe_C_crc",
3678 .pipe = PIPE_C,
3679 },
3680};
3681
3682static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3683 enum pipe pipe)
3684{
3685 struct drm_device *dev = minor->dev;
3686 struct dentry *ent;
3687 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3688
3689 info->dev = dev;
3690 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3691 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003692 if (!ent)
3693 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003694
3695 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003696}
3697
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003698static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003699 "none",
3700 "plane1",
3701 "plane2",
3702 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003703 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003704 "TV",
3705 "DP-B",
3706 "DP-C",
3707 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003708 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003709};
3710
3711static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3712{
3713 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3714 return pipe_crc_sources[source];
3715}
3716
Damien Lespiaubd9db022013-10-15 18:55:36 +01003717static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003718{
3719 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003720 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003721 int i;
3722
3723 for (i = 0; i < I915_MAX_PIPES; i++)
3724 seq_printf(m, "%c %s\n", pipe_name(i),
3725 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3726
3727 return 0;
3728}
3729
Damien Lespiaubd9db022013-10-15 18:55:36 +01003730static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003731{
3732 struct drm_device *dev = inode->i_private;
3733
Damien Lespiaubd9db022013-10-15 18:55:36 +01003734 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003735}
3736
Daniel Vetter46a19182013-11-01 10:50:20 +01003737static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003738 uint32_t *val)
3739{
Daniel Vetter46a19182013-11-01 10:50:20 +01003740 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3741 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3742
3743 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003744 case INTEL_PIPE_CRC_SOURCE_PIPE:
3745 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3746 break;
3747 case INTEL_PIPE_CRC_SOURCE_NONE:
3748 *val = 0;
3749 break;
3750 default:
3751 return -EINVAL;
3752 }
3753
3754 return 0;
3755}
3756
Daniel Vetter46a19182013-11-01 10:50:20 +01003757static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3758 enum intel_pipe_crc_source *source)
3759{
3760 struct intel_encoder *encoder;
3761 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003762 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003763 int ret = 0;
3764
3765 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3766
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003767 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003768 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003769 if (!encoder->base.crtc)
3770 continue;
3771
3772 crtc = to_intel_crtc(encoder->base.crtc);
3773
3774 if (crtc->pipe != pipe)
3775 continue;
3776
3777 switch (encoder->type) {
3778 case INTEL_OUTPUT_TVOUT:
3779 *source = INTEL_PIPE_CRC_SOURCE_TV;
3780 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003781 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003782 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003783 dig_port = enc_to_dig_port(&encoder->base);
3784 switch (dig_port->port) {
3785 case PORT_B:
3786 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3787 break;
3788 case PORT_C:
3789 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3790 break;
3791 case PORT_D:
3792 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3793 break;
3794 default:
3795 WARN(1, "nonexisting DP port %c\n",
3796 port_name(dig_port->port));
3797 break;
3798 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003799 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003800 default:
3801 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003802 }
3803 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003804 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003805
3806 return ret;
3807}
3808
3809static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3810 enum pipe pipe,
3811 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003812 uint32_t *val)
3813{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003814 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003815 bool need_stable_symbols = false;
3816
Daniel Vetter46a19182013-11-01 10:50:20 +01003817 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3818 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3819 if (ret)
3820 return ret;
3821 }
3822
3823 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003824 case INTEL_PIPE_CRC_SOURCE_PIPE:
3825 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3826 break;
3827 case INTEL_PIPE_CRC_SOURCE_DP_B:
3828 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003829 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003830 break;
3831 case INTEL_PIPE_CRC_SOURCE_DP_C:
3832 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003833 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003834 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003835 case INTEL_PIPE_CRC_SOURCE_DP_D:
3836 if (!IS_CHERRYVIEW(dev))
3837 return -EINVAL;
3838 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3839 need_stable_symbols = true;
3840 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003841 case INTEL_PIPE_CRC_SOURCE_NONE:
3842 *val = 0;
3843 break;
3844 default:
3845 return -EINVAL;
3846 }
3847
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003848 /*
3849 * When the pipe CRC tap point is after the transcoders we need
3850 * to tweak symbol-level features to produce a deterministic series of
3851 * symbols for a given frame. We need to reset those features only once
3852 * a frame (instead of every nth symbol):
3853 * - DC-balance: used to ensure a better clock recovery from the data
3854 * link (SDVO)
3855 * - DisplayPort scrambling: used for EMI reduction
3856 */
3857 if (need_stable_symbols) {
3858 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3859
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003860 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003861 switch (pipe) {
3862 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003863 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003864 break;
3865 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003866 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003867 break;
3868 case PIPE_C:
3869 tmp |= PIPE_C_SCRAMBLE_RESET;
3870 break;
3871 default:
3872 return -EINVAL;
3873 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003874 I915_WRITE(PORT_DFT2_G4X, tmp);
3875 }
3876
Daniel Vetter7ac01292013-10-18 16:37:06 +02003877 return 0;
3878}
3879
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003880static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003881 enum pipe pipe,
3882 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003883 uint32_t *val)
3884{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003885 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003886 bool need_stable_symbols = false;
3887
Daniel Vetter46a19182013-11-01 10:50:20 +01003888 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3889 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3890 if (ret)
3891 return ret;
3892 }
3893
3894 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003895 case INTEL_PIPE_CRC_SOURCE_PIPE:
3896 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3897 break;
3898 case INTEL_PIPE_CRC_SOURCE_TV:
3899 if (!SUPPORTS_TV(dev))
3900 return -EINVAL;
3901 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3902 break;
3903 case INTEL_PIPE_CRC_SOURCE_DP_B:
3904 if (!IS_G4X(dev))
3905 return -EINVAL;
3906 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003907 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003908 break;
3909 case INTEL_PIPE_CRC_SOURCE_DP_C:
3910 if (!IS_G4X(dev))
3911 return -EINVAL;
3912 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003913 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003914 break;
3915 case INTEL_PIPE_CRC_SOURCE_DP_D:
3916 if (!IS_G4X(dev))
3917 return -EINVAL;
3918 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003919 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003920 break;
3921 case INTEL_PIPE_CRC_SOURCE_NONE:
3922 *val = 0;
3923 break;
3924 default:
3925 return -EINVAL;
3926 }
3927
Daniel Vetter84093602013-11-01 10:50:21 +01003928 /*
3929 * When the pipe CRC tap point is after the transcoders we need
3930 * to tweak symbol-level features to produce a deterministic series of
3931 * symbols for a given frame. We need to reset those features only once
3932 * a frame (instead of every nth symbol):
3933 * - DC-balance: used to ensure a better clock recovery from the data
3934 * link (SDVO)
3935 * - DisplayPort scrambling: used for EMI reduction
3936 */
3937 if (need_stable_symbols) {
3938 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3939
3940 WARN_ON(!IS_G4X(dev));
3941
3942 I915_WRITE(PORT_DFT_I9XX,
3943 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3944
3945 if (pipe == PIPE_A)
3946 tmp |= PIPE_A_SCRAMBLE_RESET;
3947 else
3948 tmp |= PIPE_B_SCRAMBLE_RESET;
3949
3950 I915_WRITE(PORT_DFT2_G4X, tmp);
3951 }
3952
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003953 return 0;
3954}
3955
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003956static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3957 enum pipe pipe)
3958{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003959 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003960 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3961
Ville Syrjäläeb736672014-12-09 21:28:28 +02003962 switch (pipe) {
3963 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003964 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003965 break;
3966 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003967 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003968 break;
3969 case PIPE_C:
3970 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3971 break;
3972 default:
3973 return;
3974 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003975 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3976 tmp &= ~DC_BALANCE_RESET_VLV;
3977 I915_WRITE(PORT_DFT2_G4X, tmp);
3978
3979}
3980
Daniel Vetter84093602013-11-01 10:50:21 +01003981static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3982 enum pipe pipe)
3983{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003984 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003985 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3986
3987 if (pipe == PIPE_A)
3988 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3989 else
3990 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3991 I915_WRITE(PORT_DFT2_G4X, tmp);
3992
3993 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3994 I915_WRITE(PORT_DFT_I9XX,
3995 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3996 }
3997}
3998
Daniel Vetter46a19182013-11-01 10:50:20 +01003999static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004000 uint32_t *val)
4001{
Daniel Vetter46a19182013-11-01 10:50:20 +01004002 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4003 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4004
4005 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004006 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4007 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4008 break;
4009 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4010 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4011 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004012 case INTEL_PIPE_CRC_SOURCE_PIPE:
4013 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4014 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004015 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004016 *val = 0;
4017 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004018 default:
4019 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004020 }
4021
4022 return 0;
4023}
4024
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004025static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004026{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004027 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004028 struct intel_crtc *crtc =
4029 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004030 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004031 struct drm_atomic_state *state;
4032 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004033
4034 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004035 state = drm_atomic_state_alloc(dev);
4036 if (!state) {
4037 ret = -ENOMEM;
4038 goto out;
4039 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004040
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004041 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4042 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4043 if (IS_ERR(pipe_config)) {
4044 ret = PTR_ERR(pipe_config);
4045 goto out;
4046 }
4047
4048 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004049 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004050 pipe_config->pch_pfit.enabled != enable)
4051 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004052
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004053 ret = drm_atomic_commit(state);
4054out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004055 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004056 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4057 if (ret)
4058 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004059}
4060
4061static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4062 enum pipe pipe,
4063 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004064 uint32_t *val)
4065{
Daniel Vetter46a19182013-11-01 10:50:20 +01004066 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4067 *source = INTEL_PIPE_CRC_SOURCE_PF;
4068
4069 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004070 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4071 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4072 break;
4073 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4074 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4075 break;
4076 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004077 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004078 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004079
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004080 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4081 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004082 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004083 *val = 0;
4084 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004085 default:
4086 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004087 }
4088
4089 return 0;
4090}
4091
Daniel Vetter926321d2013-10-16 13:30:34 +02004092static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4093 enum intel_pipe_crc_source source)
4094{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004095 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaucc3da172013-10-15 18:55:31 +01004096 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004097 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4098 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004099 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004100 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004101 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004102
Damien Lespiaucc3da172013-10-15 18:55:31 +01004103 if (pipe_crc->source == source)
4104 return 0;
4105
Damien Lespiauae676fc2013-10-15 18:55:32 +01004106 /* forbid changing the source without going back to 'none' */
4107 if (pipe_crc->source && source)
4108 return -EINVAL;
4109
Imre Deake1296492016-02-12 18:55:17 +02004110 power_domain = POWER_DOMAIN_PIPE(pipe);
4111 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004112 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4113 return -EIO;
4114 }
4115
Daniel Vetter52f843f2013-10-21 17:26:38 +02004116 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004117 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004118 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004119 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004120 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004121 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004122 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004123 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004124 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004125 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004126
4127 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004128 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004129
Damien Lespiau4b584362013-10-15 18:55:33 +01004130 /* none -> real source transition */
4131 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004132 struct intel_pipe_crc_entry *entries;
4133
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004134 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4135 pipe_name(pipe), pipe_crc_source_name(source));
4136
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004137 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4138 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004139 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004140 if (!entries) {
4141 ret = -ENOMEM;
4142 goto out;
4143 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004144
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004145 /*
4146 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4147 * enabled and disabled dynamically based on package C states,
4148 * user space can't make reliable use of the CRCs, so let's just
4149 * completely disable it.
4150 */
4151 hsw_disable_ips(crtc);
4152
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004153 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004154 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004155 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004156 pipe_crc->head = 0;
4157 pipe_crc->tail = 0;
4158 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004159 }
4160
Damien Lespiaucc3da172013-10-15 18:55:31 +01004161 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004162
Daniel Vetter926321d2013-10-16 13:30:34 +02004163 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4164 POSTING_READ(PIPE_CRC_CTL(pipe));
4165
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004166 /* real source -> none transition */
4167 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004168 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004169 struct intel_crtc *crtc =
4170 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004171
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004172 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4173 pipe_name(pipe));
4174
Daniel Vettera33d7102014-06-06 08:22:08 +02004175 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004176 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004177 intel_wait_for_vblank(dev, pipe);
4178 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004179
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004180 spin_lock_irq(&pipe_crc->lock);
4181 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004182 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004183 pipe_crc->head = 0;
4184 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004185 spin_unlock_irq(&pipe_crc->lock);
4186
4187 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004188
4189 if (IS_G4X(dev))
4190 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004191 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004192 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004193 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004194 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004195
4196 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004197 }
4198
Imre Deake1296492016-02-12 18:55:17 +02004199 ret = 0;
4200
4201out:
4202 intel_display_power_put(dev_priv, power_domain);
4203
4204 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004205}
4206
4207/*
4208 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004209 * command: wsp* object wsp+ name wsp+ source wsp*
4210 * object: 'pipe'
4211 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004212 * source: (none | plane1 | plane2 | pf)
4213 * wsp: (#0x20 | #0x9 | #0xA)+
4214 *
4215 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004216 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4217 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004218 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004219static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004220{
4221 int n_words = 0;
4222
4223 while (*buf) {
4224 char *end;
4225
4226 /* skip leading white space */
4227 buf = skip_spaces(buf);
4228 if (!*buf)
4229 break; /* end of buffer */
4230
4231 /* find end of word */
4232 for (end = buf; *end && !isspace(*end); end++)
4233 ;
4234
4235 if (n_words == max_words) {
4236 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4237 max_words);
4238 return -EINVAL; /* ran out of words[] before bytes */
4239 }
4240
4241 if (*end)
4242 *end++ = '\0';
4243 words[n_words++] = buf;
4244 buf = end;
4245 }
4246
4247 return n_words;
4248}
4249
Damien Lespiaub94dec82013-10-15 18:55:35 +01004250enum intel_pipe_crc_object {
4251 PIPE_CRC_OBJECT_PIPE,
4252};
4253
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004254static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004255 "pipe",
4256};
4257
4258static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004259display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004260{
4261 int i;
4262
4263 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4264 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004265 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004266 return 0;
4267 }
4268
4269 return -EINVAL;
4270}
4271
Damien Lespiaubd9db022013-10-15 18:55:36 +01004272static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004273{
4274 const char name = buf[0];
4275
4276 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4277 return -EINVAL;
4278
4279 *pipe = name - 'A';
4280
4281 return 0;
4282}
4283
4284static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004285display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004286{
4287 int i;
4288
4289 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4290 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004291 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004292 return 0;
4293 }
4294
4295 return -EINVAL;
4296}
4297
Damien Lespiaubd9db022013-10-15 18:55:36 +01004298static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004299{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004300#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004301 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004302 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004303 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004304 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004305 enum intel_pipe_crc_source source;
4306
Damien Lespiaubd9db022013-10-15 18:55:36 +01004307 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004308 if (n_words != N_WORDS) {
4309 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4310 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004311 return -EINVAL;
4312 }
4313
Damien Lespiaubd9db022013-10-15 18:55:36 +01004314 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004315 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004316 return -EINVAL;
4317 }
4318
Damien Lespiaubd9db022013-10-15 18:55:36 +01004319 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004320 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4321 return -EINVAL;
4322 }
4323
Damien Lespiaubd9db022013-10-15 18:55:36 +01004324 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004325 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004326 return -EINVAL;
4327 }
4328
4329 return pipe_crc_set_source(dev, pipe, source);
4330}
4331
Damien Lespiaubd9db022013-10-15 18:55:36 +01004332static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4333 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004334{
4335 struct seq_file *m = file->private_data;
4336 struct drm_device *dev = m->private;
4337 char *tmpbuf;
4338 int ret;
4339
4340 if (len == 0)
4341 return 0;
4342
4343 if (len > PAGE_SIZE - 1) {
4344 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4345 PAGE_SIZE);
4346 return -E2BIG;
4347 }
4348
4349 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4350 if (!tmpbuf)
4351 return -ENOMEM;
4352
4353 if (copy_from_user(tmpbuf, ubuf, len)) {
4354 ret = -EFAULT;
4355 goto out;
4356 }
4357 tmpbuf[len] = '\0';
4358
Damien Lespiaubd9db022013-10-15 18:55:36 +01004359 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004360
4361out:
4362 kfree(tmpbuf);
4363 if (ret < 0)
4364 return ret;
4365
4366 *offp += len;
4367 return len;
4368}
4369
Damien Lespiaubd9db022013-10-15 18:55:36 +01004370static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004371 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004372 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004373 .read = seq_read,
4374 .llseek = seq_lseek,
4375 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004376 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004377};
4378
Todd Previteeb3394fa2015-04-18 00:04:19 -07004379static ssize_t i915_displayport_test_active_write(struct file *file,
4380 const char __user *ubuf,
4381 size_t len, loff_t *offp)
4382{
4383 char *input_buffer;
4384 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004385 struct drm_device *dev;
4386 struct drm_connector *connector;
4387 struct list_head *connector_list;
4388 struct intel_dp *intel_dp;
4389 int val = 0;
4390
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304391 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004392
Todd Previteeb3394fa2015-04-18 00:04:19 -07004393 connector_list = &dev->mode_config.connector_list;
4394
4395 if (len == 0)
4396 return 0;
4397
4398 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4399 if (!input_buffer)
4400 return -ENOMEM;
4401
4402 if (copy_from_user(input_buffer, ubuf, len)) {
4403 status = -EFAULT;
4404 goto out;
4405 }
4406
4407 input_buffer[len] = '\0';
4408 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4409
4410 list_for_each_entry(connector, connector_list, head) {
4411
4412 if (connector->connector_type !=
4413 DRM_MODE_CONNECTOR_DisplayPort)
4414 continue;
4415
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304416 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004417 connector->encoder != NULL) {
4418 intel_dp = enc_to_intel_dp(connector->encoder);
4419 status = kstrtoint(input_buffer, 10, &val);
4420 if (status < 0)
4421 goto out;
4422 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4423 /* To prevent erroneous activation of the compliance
4424 * testing code, only accept an actual value of 1 here
4425 */
4426 if (val == 1)
4427 intel_dp->compliance_test_active = 1;
4428 else
4429 intel_dp->compliance_test_active = 0;
4430 }
4431 }
4432out:
4433 kfree(input_buffer);
4434 if (status < 0)
4435 return status;
4436
4437 *offp += len;
4438 return len;
4439}
4440
4441static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4442{
4443 struct drm_device *dev = m->private;
4444 struct drm_connector *connector;
4445 struct list_head *connector_list = &dev->mode_config.connector_list;
4446 struct intel_dp *intel_dp;
4447
Todd Previteeb3394fa2015-04-18 00:04:19 -07004448 list_for_each_entry(connector, connector_list, head) {
4449
4450 if (connector->connector_type !=
4451 DRM_MODE_CONNECTOR_DisplayPort)
4452 continue;
4453
4454 if (connector->status == connector_status_connected &&
4455 connector->encoder != NULL) {
4456 intel_dp = enc_to_intel_dp(connector->encoder);
4457 if (intel_dp->compliance_test_active)
4458 seq_puts(m, "1");
4459 else
4460 seq_puts(m, "0");
4461 } else
4462 seq_puts(m, "0");
4463 }
4464
4465 return 0;
4466}
4467
4468static int i915_displayport_test_active_open(struct inode *inode,
4469 struct file *file)
4470{
4471 struct drm_device *dev = inode->i_private;
4472
4473 return single_open(file, i915_displayport_test_active_show, dev);
4474}
4475
4476static const struct file_operations i915_displayport_test_active_fops = {
4477 .owner = THIS_MODULE,
4478 .open = i915_displayport_test_active_open,
4479 .read = seq_read,
4480 .llseek = seq_lseek,
4481 .release = single_release,
4482 .write = i915_displayport_test_active_write
4483};
4484
4485static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4486{
4487 struct drm_device *dev = m->private;
4488 struct drm_connector *connector;
4489 struct list_head *connector_list = &dev->mode_config.connector_list;
4490 struct intel_dp *intel_dp;
4491
Todd Previteeb3394fa2015-04-18 00:04:19 -07004492 list_for_each_entry(connector, connector_list, head) {
4493
4494 if (connector->connector_type !=
4495 DRM_MODE_CONNECTOR_DisplayPort)
4496 continue;
4497
4498 if (connector->status == connector_status_connected &&
4499 connector->encoder != NULL) {
4500 intel_dp = enc_to_intel_dp(connector->encoder);
4501 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4502 } else
4503 seq_puts(m, "0");
4504 }
4505
4506 return 0;
4507}
4508static int i915_displayport_test_data_open(struct inode *inode,
4509 struct file *file)
4510{
4511 struct drm_device *dev = inode->i_private;
4512
4513 return single_open(file, i915_displayport_test_data_show, dev);
4514}
4515
4516static const struct file_operations i915_displayport_test_data_fops = {
4517 .owner = THIS_MODULE,
4518 .open = i915_displayport_test_data_open,
4519 .read = seq_read,
4520 .llseek = seq_lseek,
4521 .release = single_release
4522};
4523
4524static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4525{
4526 struct drm_device *dev = m->private;
4527 struct drm_connector *connector;
4528 struct list_head *connector_list = &dev->mode_config.connector_list;
4529 struct intel_dp *intel_dp;
4530
Todd Previteeb3394fa2015-04-18 00:04:19 -07004531 list_for_each_entry(connector, connector_list, head) {
4532
4533 if (connector->connector_type !=
4534 DRM_MODE_CONNECTOR_DisplayPort)
4535 continue;
4536
4537 if (connector->status == connector_status_connected &&
4538 connector->encoder != NULL) {
4539 intel_dp = enc_to_intel_dp(connector->encoder);
4540 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4541 } else
4542 seq_puts(m, "0");
4543 }
4544
4545 return 0;
4546}
4547
4548static int i915_displayport_test_type_open(struct inode *inode,
4549 struct file *file)
4550{
4551 struct drm_device *dev = inode->i_private;
4552
4553 return single_open(file, i915_displayport_test_type_show, dev);
4554}
4555
4556static const struct file_operations i915_displayport_test_type_fops = {
4557 .owner = THIS_MODULE,
4558 .open = i915_displayport_test_type_open,
4559 .read = seq_read,
4560 .llseek = seq_lseek,
4561 .release = single_release
4562};
4563
Damien Lespiau97e94b22014-11-04 17:06:50 +00004564static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004565{
4566 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004567 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004568 int num_levels;
4569
4570 if (IS_CHERRYVIEW(dev))
4571 num_levels = 3;
4572 else if (IS_VALLEYVIEW(dev))
4573 num_levels = 1;
4574 else
4575 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004576
4577 drm_modeset_lock_all(dev);
4578
4579 for (level = 0; level < num_levels; level++) {
4580 unsigned int latency = wm[level];
4581
Damien Lespiau97e94b22014-11-04 17:06:50 +00004582 /*
4583 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004584 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004585 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004586 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4587 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004588 latency *= 10;
4589 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004590 latency *= 5;
4591
4592 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004593 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004594 }
4595
4596 drm_modeset_unlock_all(dev);
4597}
4598
4599static int pri_wm_latency_show(struct seq_file *m, void *data)
4600{
4601 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004602 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004603 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004604
Damien Lespiau97e94b22014-11-04 17:06:50 +00004605 if (INTEL_INFO(dev)->gen >= 9)
4606 latencies = dev_priv->wm.skl_latency;
4607 else
4608 latencies = to_i915(dev)->wm.pri_latency;
4609
4610 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004611
4612 return 0;
4613}
4614
4615static int spr_wm_latency_show(struct seq_file *m, void *data)
4616{
4617 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004618 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004619 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004620
Damien Lespiau97e94b22014-11-04 17:06:50 +00004621 if (INTEL_INFO(dev)->gen >= 9)
4622 latencies = dev_priv->wm.skl_latency;
4623 else
4624 latencies = to_i915(dev)->wm.spr_latency;
4625
4626 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004627
4628 return 0;
4629}
4630
4631static int cur_wm_latency_show(struct seq_file *m, void *data)
4632{
4633 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004634 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004635 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004636
Damien Lespiau97e94b22014-11-04 17:06:50 +00004637 if (INTEL_INFO(dev)->gen >= 9)
4638 latencies = dev_priv->wm.skl_latency;
4639 else
4640 latencies = to_i915(dev)->wm.cur_latency;
4641
4642 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004643
4644 return 0;
4645}
4646
4647static int pri_wm_latency_open(struct inode *inode, struct file *file)
4648{
4649 struct drm_device *dev = inode->i_private;
4650
Ville Syrjäläde38b952015-06-24 22:00:09 +03004651 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004652 return -ENODEV;
4653
4654 return single_open(file, pri_wm_latency_show, dev);
4655}
4656
4657static int spr_wm_latency_open(struct inode *inode, struct file *file)
4658{
4659 struct drm_device *dev = inode->i_private;
4660
Sonika Jindal9ad02572014-07-21 15:23:39 +05304661 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004662 return -ENODEV;
4663
4664 return single_open(file, spr_wm_latency_show, dev);
4665}
4666
4667static int cur_wm_latency_open(struct inode *inode, struct file *file)
4668{
4669 struct drm_device *dev = inode->i_private;
4670
Sonika Jindal9ad02572014-07-21 15:23:39 +05304671 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004672 return -ENODEV;
4673
4674 return single_open(file, cur_wm_latency_show, dev);
4675}
4676
4677static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004678 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004679{
4680 struct seq_file *m = file->private_data;
4681 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004682 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004683 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004684 int level;
4685 int ret;
4686 char tmp[32];
4687
Ville Syrjäläde38b952015-06-24 22:00:09 +03004688 if (IS_CHERRYVIEW(dev))
4689 num_levels = 3;
4690 else if (IS_VALLEYVIEW(dev))
4691 num_levels = 1;
4692 else
4693 num_levels = ilk_wm_max_level(dev) + 1;
4694
Ville Syrjälä369a1342014-01-22 14:36:08 +02004695 if (len >= sizeof(tmp))
4696 return -EINVAL;
4697
4698 if (copy_from_user(tmp, ubuf, len))
4699 return -EFAULT;
4700
4701 tmp[len] = '\0';
4702
Damien Lespiau97e94b22014-11-04 17:06:50 +00004703 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4704 &new[0], &new[1], &new[2], &new[3],
4705 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004706 if (ret != num_levels)
4707 return -EINVAL;
4708
4709 drm_modeset_lock_all(dev);
4710
4711 for (level = 0; level < num_levels; level++)
4712 wm[level] = new[level];
4713
4714 drm_modeset_unlock_all(dev);
4715
4716 return len;
4717}
4718
4719
4720static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4721 size_t len, loff_t *offp)
4722{
4723 struct seq_file *m = file->private_data;
4724 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004725 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004726 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004727
Damien Lespiau97e94b22014-11-04 17:06:50 +00004728 if (INTEL_INFO(dev)->gen >= 9)
4729 latencies = dev_priv->wm.skl_latency;
4730 else
4731 latencies = to_i915(dev)->wm.pri_latency;
4732
4733 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004734}
4735
4736static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4737 size_t len, loff_t *offp)
4738{
4739 struct seq_file *m = file->private_data;
4740 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004741 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004742 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004743
Damien Lespiau97e94b22014-11-04 17:06:50 +00004744 if (INTEL_INFO(dev)->gen >= 9)
4745 latencies = dev_priv->wm.skl_latency;
4746 else
4747 latencies = to_i915(dev)->wm.spr_latency;
4748
4749 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004750}
4751
4752static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4753 size_t len, loff_t *offp)
4754{
4755 struct seq_file *m = file->private_data;
4756 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004757 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004758 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004759
Damien Lespiau97e94b22014-11-04 17:06:50 +00004760 if (INTEL_INFO(dev)->gen >= 9)
4761 latencies = dev_priv->wm.skl_latency;
4762 else
4763 latencies = to_i915(dev)->wm.cur_latency;
4764
4765 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004766}
4767
4768static const struct file_operations i915_pri_wm_latency_fops = {
4769 .owner = THIS_MODULE,
4770 .open = pri_wm_latency_open,
4771 .read = seq_read,
4772 .llseek = seq_lseek,
4773 .release = single_release,
4774 .write = pri_wm_latency_write
4775};
4776
4777static const struct file_operations i915_spr_wm_latency_fops = {
4778 .owner = THIS_MODULE,
4779 .open = spr_wm_latency_open,
4780 .read = seq_read,
4781 .llseek = seq_lseek,
4782 .release = single_release,
4783 .write = spr_wm_latency_write
4784};
4785
4786static const struct file_operations i915_cur_wm_latency_fops = {
4787 .owner = THIS_MODULE,
4788 .open = cur_wm_latency_open,
4789 .read = seq_read,
4790 .llseek = seq_lseek,
4791 .release = single_release,
4792 .write = cur_wm_latency_write
4793};
4794
Kees Cook647416f2013-03-10 14:10:06 -07004795static int
4796i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004797{
Kees Cook647416f2013-03-10 14:10:06 -07004798 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004799 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004800
Chris Wilsond98c52c2016-04-13 17:35:05 +01004801 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004802
Kees Cook647416f2013-03-10 14:10:06 -07004803 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004804}
4805
Kees Cook647416f2013-03-10 14:10:06 -07004806static int
4807i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004808{
Kees Cook647416f2013-03-10 14:10:06 -07004809 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004810 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakd46c0512014-04-14 20:24:27 +03004811
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004812 /*
4813 * There is no safeguard against this debugfs entry colliding
4814 * with the hangcheck calling same i915_handle_error() in
4815 * parallel, causing an explosion. For now we assume that the
4816 * test harness is responsible enough not to inject gpu hangs
4817 * while it is writing to 'i915_wedged'
4818 */
4819
Chris Wilsond98c52c2016-04-13 17:35:05 +01004820 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004821 return -EAGAIN;
4822
Imre Deakd46c0512014-04-14 20:24:27 +03004823 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004824
Chris Wilsonc0336662016-05-06 15:40:21 +01004825 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004826 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004827
4828 intel_runtime_pm_put(dev_priv);
4829
Kees Cook647416f2013-03-10 14:10:06 -07004830 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004831}
4832
Kees Cook647416f2013-03-10 14:10:06 -07004833DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4834 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004835 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004836
Kees Cook647416f2013-03-10 14:10:06 -07004837static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004838i915_ring_missed_irq_get(void *data, u64 *val)
4839{
4840 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004841 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004842
4843 *val = dev_priv->gpu_error.missed_irq_rings;
4844 return 0;
4845}
4846
4847static int
4848i915_ring_missed_irq_set(void *data, u64 val)
4849{
4850 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004851 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004852 int ret;
4853
4854 /* Lock against concurrent debugfs callers */
4855 ret = mutex_lock_interruptible(&dev->struct_mutex);
4856 if (ret)
4857 return ret;
4858 dev_priv->gpu_error.missed_irq_rings = val;
4859 mutex_unlock(&dev->struct_mutex);
4860
4861 return 0;
4862}
4863
4864DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4865 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4866 "0x%08llx\n");
4867
4868static int
4869i915_ring_test_irq_get(void *data, u64 *val)
4870{
4871 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004872 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004873
4874 *val = dev_priv->gpu_error.test_irq_rings;
4875
4876 return 0;
4877}
4878
4879static int
4880i915_ring_test_irq_set(void *data, u64 val)
4881{
4882 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004883 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004884
Chris Wilson3a122c22016-06-17 14:35:05 +01004885 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004886 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004887 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004888
4889 return 0;
4890}
4891
4892DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4893 i915_ring_test_irq_get, i915_ring_test_irq_set,
4894 "0x%08llx\n");
4895
Chris Wilsondd624af2013-01-15 12:39:35 +00004896#define DROP_UNBOUND 0x1
4897#define DROP_BOUND 0x2
4898#define DROP_RETIRE 0x4
4899#define DROP_ACTIVE 0x8
4900#define DROP_ALL (DROP_UNBOUND | \
4901 DROP_BOUND | \
4902 DROP_RETIRE | \
4903 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004904static int
4905i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004906{
Kees Cook647416f2013-03-10 14:10:06 -07004907 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004908
Kees Cook647416f2013-03-10 14:10:06 -07004909 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004910}
4911
Kees Cook647416f2013-03-10 14:10:06 -07004912static int
4913i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004914{
Kees Cook647416f2013-03-10 14:10:06 -07004915 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004916 struct drm_i915_private *dev_priv = to_i915(dev);
Kees Cook647416f2013-03-10 14:10:06 -07004917 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004918
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004919 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004920
4921 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4922 * on ioctls on -EAGAIN. */
4923 ret = mutex_lock_interruptible(&dev->struct_mutex);
4924 if (ret)
4925 return ret;
4926
4927 if (val & DROP_ACTIVE) {
Chris Wilson6e5a5be2016-06-24 14:55:57 +01004928 ret = i915_gem_wait_for_idle(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004929 if (ret)
4930 goto unlock;
4931 }
4932
4933 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004934 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004935
Chris Wilson21ab4e72014-09-09 11:16:08 +01004936 if (val & DROP_BOUND)
4937 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004938
Chris Wilson21ab4e72014-09-09 11:16:08 +01004939 if (val & DROP_UNBOUND)
4940 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004941
4942unlock:
4943 mutex_unlock(&dev->struct_mutex);
4944
Kees Cook647416f2013-03-10 14:10:06 -07004945 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004946}
4947
Kees Cook647416f2013-03-10 14:10:06 -07004948DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4949 i915_drop_caches_get, i915_drop_caches_set,
4950 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004951
Kees Cook647416f2013-03-10 14:10:06 -07004952static int
4953i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004954{
Kees Cook647416f2013-03-10 14:10:06 -07004955 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004956 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02004957
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004958 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004959 return -ENODEV;
4960
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004961 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004962 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004963}
4964
Kees Cook647416f2013-03-10 14:10:06 -07004965static int
4966i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004967{
Kees Cook647416f2013-03-10 14:10:06 -07004968 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004969 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05304970 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004971 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004972
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004973 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004974 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004975
Kees Cook647416f2013-03-10 14:10:06 -07004976 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004977
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004978 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004979 if (ret)
4980 return ret;
4981
Jesse Barnes358733e2011-07-27 11:53:01 -07004982 /*
4983 * Turbo will still be enabled, but won't go above the set value.
4984 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304985 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004986
Akash Goelbc4d91f2015-02-26 16:09:47 +05304987 hw_max = dev_priv->rps.max_freq;
4988 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004989
Ben Widawskyb39fb292014-03-19 18:31:11 -07004990 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004991 mutex_unlock(&dev_priv->rps.hw_lock);
4992 return -EINVAL;
4993 }
4994
Ben Widawskyb39fb292014-03-19 18:31:11 -07004995 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004996
Chris Wilsondc979972016-05-10 14:10:04 +01004997 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004998
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004999 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005000
Kees Cook647416f2013-03-10 14:10:06 -07005001 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005002}
5003
Kees Cook647416f2013-03-10 14:10:06 -07005004DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5005 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005006 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005007
Kees Cook647416f2013-03-10 14:10:06 -07005008static int
5009i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005010{
Kees Cook647416f2013-03-10 14:10:06 -07005011 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005012 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02005013
Chris Wilson62e1baa2016-07-13 09:10:36 +01005014 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005015 return -ENODEV;
5016
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005017 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005018 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005019}
5020
Kees Cook647416f2013-03-10 14:10:06 -07005021static int
5022i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005023{
Kees Cook647416f2013-03-10 14:10:06 -07005024 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005025 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05305026 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005027 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005028
Chris Wilson62e1baa2016-07-13 09:10:36 +01005029 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005030 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005031
Kees Cook647416f2013-03-10 14:10:06 -07005032 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005033
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005034 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005035 if (ret)
5036 return ret;
5037
Jesse Barnes1523c312012-05-25 12:34:54 -07005038 /*
5039 * Turbo will still be enabled, but won't go below the set value.
5040 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305041 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005042
Akash Goelbc4d91f2015-02-26 16:09:47 +05305043 hw_max = dev_priv->rps.max_freq;
5044 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005045
Ben Widawskyb39fb292014-03-19 18:31:11 -07005046 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005047 mutex_unlock(&dev_priv->rps.hw_lock);
5048 return -EINVAL;
5049 }
5050
Ben Widawskyb39fb292014-03-19 18:31:11 -07005051 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005052
Chris Wilsondc979972016-05-10 14:10:04 +01005053 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005054
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005055 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005056
Kees Cook647416f2013-03-10 14:10:06 -07005057 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005058}
5059
Kees Cook647416f2013-03-10 14:10:06 -07005060DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5061 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005062 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005063
Kees Cook647416f2013-03-10 14:10:06 -07005064static int
5065i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005066{
Kees Cook647416f2013-03-10 14:10:06 -07005067 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005068 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005069 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005070 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005071
Daniel Vetter004777c2012-08-09 15:07:01 +02005072 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5073 return -ENODEV;
5074
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005075 ret = mutex_lock_interruptible(&dev->struct_mutex);
5076 if (ret)
5077 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005078 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005079
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005080 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005081
5082 intel_runtime_pm_put(dev_priv);
Chris Wilson91c8a322016-07-05 10:40:23 +01005083 mutex_unlock(&dev_priv->drm.struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005084
Kees Cook647416f2013-03-10 14:10:06 -07005085 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005086
Kees Cook647416f2013-03-10 14:10:06 -07005087 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005088}
5089
Kees Cook647416f2013-03-10 14:10:06 -07005090static int
5091i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005092{
Kees Cook647416f2013-03-10 14:10:06 -07005093 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005094 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005095 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005096
Daniel Vetter004777c2012-08-09 15:07:01 +02005097 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5098 return -ENODEV;
5099
Kees Cook647416f2013-03-10 14:10:06 -07005100 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005101 return -EINVAL;
5102
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005103 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005104 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005105
5106 /* Update the cache sharing policy here as well */
5107 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5108 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5109 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5110 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5111
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005112 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005113 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005114}
5115
Kees Cook647416f2013-03-10 14:10:06 -07005116DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5117 i915_cache_sharing_get, i915_cache_sharing_set,
5118 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005119
Jeff McGee5d395252015-04-03 18:13:17 -07005120struct sseu_dev_status {
5121 unsigned int slice_total;
5122 unsigned int subslice_total;
5123 unsigned int subslice_per_slice;
5124 unsigned int eu_total;
5125 unsigned int eu_per_subslice;
5126};
5127
5128static void cherryview_sseu_device_status(struct drm_device *dev,
5129 struct sseu_dev_status *stat)
5130{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005131 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005132 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005133 int ss;
5134 u32 sig1[ss_max], sig2[ss_max];
5135
5136 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5137 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5138 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5139 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5140
5141 for (ss = 0; ss < ss_max; ss++) {
5142 unsigned int eu_cnt;
5143
5144 if (sig1[ss] & CHV_SS_PG_ENABLE)
5145 /* skip disabled subslice */
5146 continue;
5147
5148 stat->slice_total = 1;
5149 stat->subslice_per_slice++;
5150 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5151 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5152 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5153 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5154 stat->eu_total += eu_cnt;
5155 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5156 }
5157 stat->subslice_total = stat->subslice_per_slice;
5158}
5159
5160static void gen9_sseu_device_status(struct drm_device *dev,
5161 struct sseu_dev_status *stat)
5162{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005163 struct drm_i915_private *dev_priv = to_i915(dev);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005164 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005165 int s, ss;
5166 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5167
Jeff McGee1c046bc2015-04-03 18:13:18 -07005168 /* BXT has a single slice and at most 3 subslices. */
5169 if (IS_BROXTON(dev)) {
5170 s_max = 1;
5171 ss_max = 3;
5172 }
5173
5174 for (s = 0; s < s_max; s++) {
5175 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5176 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5177 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5178 }
5179
Jeff McGee5d395252015-04-03 18:13:17 -07005180 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5181 GEN9_PGCTL_SSA_EU19_ACK |
5182 GEN9_PGCTL_SSA_EU210_ACK |
5183 GEN9_PGCTL_SSA_EU311_ACK;
5184 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5185 GEN9_PGCTL_SSB_EU19_ACK |
5186 GEN9_PGCTL_SSB_EU210_ACK |
5187 GEN9_PGCTL_SSB_EU311_ACK;
5188
5189 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005190 unsigned int ss_cnt = 0;
5191
Jeff McGee5d395252015-04-03 18:13:17 -07005192 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5193 /* skip disabled slice */
5194 continue;
5195
5196 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005197
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005198 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005199 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5200
Jeff McGee5d395252015-04-03 18:13:17 -07005201 for (ss = 0; ss < ss_max; ss++) {
5202 unsigned int eu_cnt;
5203
Jeff McGee1c046bc2015-04-03 18:13:18 -07005204 if (IS_BROXTON(dev) &&
5205 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5206 /* skip disabled subslice */
5207 continue;
5208
5209 if (IS_BROXTON(dev))
5210 ss_cnt++;
5211
Jeff McGee5d395252015-04-03 18:13:17 -07005212 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5213 eu_mask[ss%2]);
5214 stat->eu_total += eu_cnt;
5215 stat->eu_per_subslice = max(stat->eu_per_subslice,
5216 eu_cnt);
5217 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005218
5219 stat->subslice_total += ss_cnt;
5220 stat->subslice_per_slice = max(stat->subslice_per_slice,
5221 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005222 }
5223}
5224
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005225static void broadwell_sseu_device_status(struct drm_device *dev,
5226 struct sseu_dev_status *stat)
5227{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005228 struct drm_i915_private *dev_priv = to_i915(dev);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005229 int s;
5230 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5231
5232 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5233
5234 if (stat->slice_total) {
5235 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5236 stat->subslice_total = stat->slice_total *
5237 stat->subslice_per_slice;
5238 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5239 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5240
5241 /* subtract fused off EU(s) from enabled slice(s) */
5242 for (s = 0; s < stat->slice_total; s++) {
5243 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5244
5245 stat->eu_total -= hweight8(subslice_7eu);
5246 }
5247 }
5248}
5249
Jeff McGee38732182015-02-13 10:27:54 -06005250static int i915_sseu_status(struct seq_file *m, void *unused)
5251{
5252 struct drm_info_node *node = (struct drm_info_node *) m->private;
David Weinehall238010e2016-08-01 17:33:27 +03005253 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
5254 struct drm_device *dev = &dev_priv->drm;
Jeff McGee5d395252015-04-03 18:13:17 -07005255 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005256
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005257 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005258 return -ENODEV;
5259
5260 seq_puts(m, "SSEU Device Info\n");
5261 seq_printf(m, " Available Slice Total: %u\n",
5262 INTEL_INFO(dev)->slice_total);
5263 seq_printf(m, " Available Subslice Total: %u\n",
5264 INTEL_INFO(dev)->subslice_total);
5265 seq_printf(m, " Available Subslice Per Slice: %u\n",
5266 INTEL_INFO(dev)->subslice_per_slice);
5267 seq_printf(m, " Available EU Total: %u\n",
5268 INTEL_INFO(dev)->eu_total);
5269 seq_printf(m, " Available EU Per Subslice: %u\n",
5270 INTEL_INFO(dev)->eu_per_subslice);
arun.siluvery@linux.intel.com33e141e2016-06-03 06:34:33 +01005271 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev)));
5272 if (HAS_POOLED_EU(dev))
5273 seq_printf(m, " Min EU in pool: %u\n",
5274 INTEL_INFO(dev)->min_eu_in_pool);
Jeff McGee38732182015-02-13 10:27:54 -06005275 seq_printf(m, " Has Slice Power Gating: %s\n",
5276 yesno(INTEL_INFO(dev)->has_slice_pg));
5277 seq_printf(m, " Has Subslice Power Gating: %s\n",
5278 yesno(INTEL_INFO(dev)->has_subslice_pg));
5279 seq_printf(m, " Has EU Power Gating: %s\n",
5280 yesno(INTEL_INFO(dev)->has_eu_pg));
5281
Jeff McGee7f992ab2015-02-13 10:27:55 -06005282 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005283 memset(&stat, 0, sizeof(stat));
David Weinehall238010e2016-08-01 17:33:27 +03005284
5285 intel_runtime_pm_get(dev_priv);
5286
Jeff McGee5575f032015-02-27 10:22:32 -08005287 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005288 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005289 } else if (IS_BROADWELL(dev)) {
5290 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005291 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005292 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005293 }
David Weinehall238010e2016-08-01 17:33:27 +03005294
5295 intel_runtime_pm_put(dev_priv);
5296
Jeff McGee5d395252015-04-03 18:13:17 -07005297 seq_printf(m, " Enabled Slice Total: %u\n",
5298 stat.slice_total);
5299 seq_printf(m, " Enabled Subslice Total: %u\n",
5300 stat.subslice_total);
5301 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5302 stat.subslice_per_slice);
5303 seq_printf(m, " Enabled EU Total: %u\n",
5304 stat.eu_total);
5305 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5306 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005307
Jeff McGee38732182015-02-13 10:27:54 -06005308 return 0;
5309}
5310
Ben Widawsky6d794d42011-04-25 11:25:56 -07005311static int i915_forcewake_open(struct inode *inode, struct file *file)
5312{
5313 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005314 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005315
Daniel Vetter075edca2012-01-24 09:44:28 +01005316 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005317 return 0;
5318
Chris Wilson6daccb02015-01-16 11:34:35 +02005319 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005320 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005321
5322 return 0;
5323}
5324
Ben Widawskyc43b5632012-04-16 14:07:40 -07005325static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005326{
5327 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005328 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005329
Daniel Vetter075edca2012-01-24 09:44:28 +01005330 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005331 return 0;
5332
Mika Kuoppala59bad942015-01-16 11:34:40 +02005333 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005334 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005335
5336 return 0;
5337}
5338
5339static const struct file_operations i915_forcewake_fops = {
5340 .owner = THIS_MODULE,
5341 .open = i915_forcewake_open,
5342 .release = i915_forcewake_release,
5343};
5344
5345static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5346{
5347 struct drm_device *dev = minor->dev;
5348 struct dentry *ent;
5349
5350 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005351 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005352 root, dev,
5353 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005354 if (!ent)
5355 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005356
Ben Widawsky8eb57292011-05-11 15:10:58 -07005357 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005358}
5359
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005360static int i915_debugfs_create(struct dentry *root,
5361 struct drm_minor *minor,
5362 const char *name,
5363 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005364{
5365 struct drm_device *dev = minor->dev;
5366 struct dentry *ent;
5367
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005368 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005369 S_IRUGO | S_IWUSR,
5370 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005371 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005372 if (!ent)
5373 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005374
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005375 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005376}
5377
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005378static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005379 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005380 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005381 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005382 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005383 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005384 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005385 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005386 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005387 {"i915_gem_request", i915_gem_request_info, 0},
5388 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005389 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005390 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005391 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5392 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5393 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005394 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005395 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005396 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005397 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005398 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305399 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005400 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005401 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005402 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005403 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005404 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005405 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005406 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005407 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005408 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005409 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005410 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005411 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005412 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005413 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005414 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005415 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005416 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005417 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005418 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005419 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005420 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005421 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005422 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005423 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005424 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005425 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005426 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005427 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005428 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005429 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005430 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305431 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005432 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005433};
Ben Gamari27c202a2009-07-01 22:26:52 -04005434#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005435
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005436static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005437 const char *name;
5438 const struct file_operations *fops;
5439} i915_debugfs_files[] = {
5440 {"i915_wedged", &i915_wedged_fops},
5441 {"i915_max_freq", &i915_max_freq_fops},
5442 {"i915_min_freq", &i915_min_freq_fops},
5443 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005444 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5445 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005446 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5447 {"i915_error_state", &i915_error_state_fops},
5448 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005449 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005450 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5451 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5452 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005453 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005454 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5455 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5456 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005457};
5458
Damien Lespiau07144422013-10-15 18:55:40 +01005459void intel_display_crc_init(struct drm_device *dev)
5460{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005461 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb3783602013-11-14 11:30:42 +01005462 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005463
Damien Lespiau055e3932014-08-18 13:49:10 +01005464 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005465 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005466
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005467 pipe_crc->opened = false;
5468 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005469 init_waitqueue_head(&pipe_crc->wq);
5470 }
5471}
5472
Chris Wilson1dac8912016-06-24 14:00:17 +01005473int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005474{
Chris Wilson91c8a322016-07-05 10:40:23 +01005475 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005476 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005477
Ben Widawsky6d794d42011-04-25 11:25:56 -07005478 ret = i915_forcewake_create(minor->debugfs_root, minor);
5479 if (ret)
5480 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005481
Damien Lespiau07144422013-10-15 18:55:40 +01005482 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5483 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5484 if (ret)
5485 return ret;
5486 }
5487
Daniel Vetter34b96742013-07-04 20:49:44 +02005488 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5489 ret = i915_debugfs_create(minor->debugfs_root, minor,
5490 i915_debugfs_files[i].name,
5491 i915_debugfs_files[i].fops);
5492 if (ret)
5493 return ret;
5494 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005495
Ben Gamari27c202a2009-07-01 22:26:52 -04005496 return drm_debugfs_create_files(i915_debugfs_list,
5497 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005498 minor->debugfs_root, minor);
5499}
5500
Chris Wilson1dac8912016-06-24 14:00:17 +01005501void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005502{
Chris Wilson91c8a322016-07-05 10:40:23 +01005503 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005504 int i;
5505
Ben Gamari27c202a2009-07-01 22:26:52 -04005506 drm_debugfs_remove_files(i915_debugfs_list,
5507 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005508
Ben Widawsky6d794d42011-04-25 11:25:56 -07005509 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5510 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005511
Daniel Vettere309a992013-10-16 22:55:51 +02005512 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005513 struct drm_info_list *info_list =
5514 (struct drm_info_list *)&i915_pipe_crc_data[i];
5515
5516 drm_debugfs_remove_files(info_list, 1, minor);
5517 }
5518
Daniel Vetter34b96742013-07-04 20:49:44 +02005519 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5520 struct drm_info_list *info_list =
5521 (struct drm_info_list *) i915_debugfs_files[i].fops;
5522
5523 drm_debugfs_remove_files(info_list, 1, minor);
5524 }
Ben Gamari20172632009-02-17 20:08:50 -05005525}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005526
5527struct dpcd_block {
5528 /* DPCD dump start address. */
5529 unsigned int offset;
5530 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5531 unsigned int end;
5532 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5533 size_t size;
5534 /* Only valid for eDP. */
5535 bool edp;
5536};
5537
5538static const struct dpcd_block i915_dpcd_debug[] = {
5539 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5540 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5541 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5542 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5543 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5544 { .offset = DP_SET_POWER },
5545 { .offset = DP_EDP_DPCD_REV },
5546 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5547 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5548 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5549};
5550
5551static int i915_dpcd_show(struct seq_file *m, void *data)
5552{
5553 struct drm_connector *connector = m->private;
5554 struct intel_dp *intel_dp =
5555 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5556 uint8_t buf[16];
5557 ssize_t err;
5558 int i;
5559
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005560 if (connector->status != connector_status_connected)
5561 return -ENODEV;
5562
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005563 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5564 const struct dpcd_block *b = &i915_dpcd_debug[i];
5565 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5566
5567 if (b->edp &&
5568 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5569 continue;
5570
5571 /* low tech for now */
5572 if (WARN_ON(size > sizeof(buf)))
5573 continue;
5574
5575 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5576 if (err <= 0) {
5577 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5578 size, b->offset, err);
5579 continue;
5580 }
5581
5582 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005583 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005584
5585 return 0;
5586}
5587
5588static int i915_dpcd_open(struct inode *inode, struct file *file)
5589{
5590 return single_open(file, i915_dpcd_show, inode->i_private);
5591}
5592
5593static const struct file_operations i915_dpcd_fops = {
5594 .owner = THIS_MODULE,
5595 .open = i915_dpcd_open,
5596 .read = seq_read,
5597 .llseek = seq_lseek,
5598 .release = single_release,
5599};
5600
5601/**
5602 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5603 * @connector: pointer to a registered drm_connector
5604 *
5605 * Cleanup will be done by drm_connector_unregister() through a call to
5606 * drm_debugfs_connector_remove().
5607 *
5608 * Returns 0 on success, negative error codes on error.
5609 */
5610int i915_debugfs_connector_add(struct drm_connector *connector)
5611{
5612 struct dentry *root = connector->debugfs_entry;
5613
5614 /* The connector must have been registered beforehands. */
5615 if (!root)
5616 return -ENODEV;
5617
5618 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5619 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5620 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5621 &i915_dpcd_fops);
5622
5623 return 0;
5624}