blob: c461072da142f896be267868a3c8c460177133bb [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{
Chris Wilson573adb32016-08-04 16:32:39 +010094 return i915_gem_object_is_active(obj) ? '*' : ' ';
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{
Chris Wilson3e510a82016-08-05 10:14:23 +0100104 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -0400105 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 Wilson688e6c72016-07-01 17:23:15 +0100790
791 spin_lock(&b->lock);
792 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
793 struct intel_wait *w = container_of(rb, typeof(*w), node);
794
795 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
796 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
797 }
798 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100799}
800
Ben Gamari20172632009-02-17 20:08:50 -0500801static int i915_gem_seqno_info(struct seq_file *m, void *data)
802{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100803 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500804 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100805 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000806 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000807 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100808
809 ret = mutex_lock_interruptible(&dev->struct_mutex);
810 if (ret)
811 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200812 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500813
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000814 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000815 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100816
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200817 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100818 mutex_unlock(&dev->struct_mutex);
819
Ben Gamari20172632009-02-17 20:08:50 -0500820 return 0;
821}
822
823
824static int i915_interrupt_info(struct seq_file *m, void *data)
825{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100826 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500827 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100828 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000829 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800830 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100831
832 ret = mutex_lock_interruptible(&dev->struct_mutex);
833 if (ret)
834 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200835 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500836
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300837 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300838 seq_printf(m, "Master Interrupt Control:\t%08x\n",
839 I915_READ(GEN8_MASTER_IRQ));
840
841 seq_printf(m, "Display IER:\t%08x\n",
842 I915_READ(VLV_IER));
843 seq_printf(m, "Display IIR:\t%08x\n",
844 I915_READ(VLV_IIR));
845 seq_printf(m, "Display IIR_RW:\t%08x\n",
846 I915_READ(VLV_IIR_RW));
847 seq_printf(m, "Display IMR:\t%08x\n",
848 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100849 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300850 seq_printf(m, "Pipe %c stat:\t%08x\n",
851 pipe_name(pipe),
852 I915_READ(PIPESTAT(pipe)));
853
854 seq_printf(m, "Port hotplug:\t%08x\n",
855 I915_READ(PORT_HOTPLUG_EN));
856 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
857 I915_READ(VLV_DPFLIPSTAT));
858 seq_printf(m, "DPINVGTT:\t%08x\n",
859 I915_READ(DPINVGTT));
860
861 for (i = 0; i < 4; i++) {
862 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
863 i, I915_READ(GEN8_GT_IMR(i)));
864 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
865 i, I915_READ(GEN8_GT_IIR(i)));
866 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
867 i, I915_READ(GEN8_GT_IER(i)));
868 }
869
870 seq_printf(m, "PCU interrupt mask:\t%08x\n",
871 I915_READ(GEN8_PCU_IMR));
872 seq_printf(m, "PCU interrupt identity:\t%08x\n",
873 I915_READ(GEN8_PCU_IIR));
874 seq_printf(m, "PCU interrupt enable:\t%08x\n",
875 I915_READ(GEN8_PCU_IER));
876 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700877 seq_printf(m, "Master Interrupt Control:\t%08x\n",
878 I915_READ(GEN8_MASTER_IRQ));
879
880 for (i = 0; i < 4; i++) {
881 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
882 i, I915_READ(GEN8_GT_IMR(i)));
883 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
884 i, I915_READ(GEN8_GT_IIR(i)));
885 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
886 i, I915_READ(GEN8_GT_IER(i)));
887 }
888
Damien Lespiau055e3932014-08-18 13:49:10 +0100889 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200890 enum intel_display_power_domain power_domain;
891
892 power_domain = POWER_DOMAIN_PIPE(pipe);
893 if (!intel_display_power_get_if_enabled(dev_priv,
894 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300895 seq_printf(m, "Pipe %c power disabled\n",
896 pipe_name(pipe));
897 continue;
898 }
Ben Widawskya123f152013-11-02 21:07:10 -0700899 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000900 pipe_name(pipe),
901 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700902 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000903 pipe_name(pipe),
904 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700905 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000906 pipe_name(pipe),
907 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200908
909 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700910 }
911
912 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
913 I915_READ(GEN8_DE_PORT_IMR));
914 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
915 I915_READ(GEN8_DE_PORT_IIR));
916 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
917 I915_READ(GEN8_DE_PORT_IER));
918
919 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
920 I915_READ(GEN8_DE_MISC_IMR));
921 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
922 I915_READ(GEN8_DE_MISC_IIR));
923 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
924 I915_READ(GEN8_DE_MISC_IER));
925
926 seq_printf(m, "PCU interrupt mask:\t%08x\n",
927 I915_READ(GEN8_PCU_IMR));
928 seq_printf(m, "PCU interrupt identity:\t%08x\n",
929 I915_READ(GEN8_PCU_IIR));
930 seq_printf(m, "PCU interrupt enable:\t%08x\n",
931 I915_READ(GEN8_PCU_IER));
932 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700933 seq_printf(m, "Display IER:\t%08x\n",
934 I915_READ(VLV_IER));
935 seq_printf(m, "Display IIR:\t%08x\n",
936 I915_READ(VLV_IIR));
937 seq_printf(m, "Display IIR_RW:\t%08x\n",
938 I915_READ(VLV_IIR_RW));
939 seq_printf(m, "Display IMR:\t%08x\n",
940 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100941 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700942 seq_printf(m, "Pipe %c stat:\t%08x\n",
943 pipe_name(pipe),
944 I915_READ(PIPESTAT(pipe)));
945
946 seq_printf(m, "Master IER:\t%08x\n",
947 I915_READ(VLV_MASTER_IER));
948
949 seq_printf(m, "Render IER:\t%08x\n",
950 I915_READ(GTIER));
951 seq_printf(m, "Render IIR:\t%08x\n",
952 I915_READ(GTIIR));
953 seq_printf(m, "Render IMR:\t%08x\n",
954 I915_READ(GTIMR));
955
956 seq_printf(m, "PM IER:\t\t%08x\n",
957 I915_READ(GEN6_PMIER));
958 seq_printf(m, "PM IIR:\t\t%08x\n",
959 I915_READ(GEN6_PMIIR));
960 seq_printf(m, "PM IMR:\t\t%08x\n",
961 I915_READ(GEN6_PMIMR));
962
963 seq_printf(m, "Port hotplug:\t%08x\n",
964 I915_READ(PORT_HOTPLUG_EN));
965 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
966 I915_READ(VLV_DPFLIPSTAT));
967 seq_printf(m, "DPINVGTT:\t%08x\n",
968 I915_READ(DPINVGTT));
969
970 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800971 seq_printf(m, "Interrupt enable: %08x\n",
972 I915_READ(IER));
973 seq_printf(m, "Interrupt identity: %08x\n",
974 I915_READ(IIR));
975 seq_printf(m, "Interrupt mask: %08x\n",
976 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100977 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800978 seq_printf(m, "Pipe %c stat: %08x\n",
979 pipe_name(pipe),
980 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800981 } else {
982 seq_printf(m, "North Display Interrupt enable: %08x\n",
983 I915_READ(DEIER));
984 seq_printf(m, "North Display Interrupt identity: %08x\n",
985 I915_READ(DEIIR));
986 seq_printf(m, "North Display Interrupt mask: %08x\n",
987 I915_READ(DEIMR));
988 seq_printf(m, "South Display Interrupt enable: %08x\n",
989 I915_READ(SDEIER));
990 seq_printf(m, "South Display Interrupt identity: %08x\n",
991 I915_READ(SDEIIR));
992 seq_printf(m, "South Display Interrupt mask: %08x\n",
993 I915_READ(SDEIMR));
994 seq_printf(m, "Graphics Interrupt enable: %08x\n",
995 I915_READ(GTIER));
996 seq_printf(m, "Graphics Interrupt identity: %08x\n",
997 I915_READ(GTIIR));
998 seq_printf(m, "Graphics Interrupt mask: %08x\n",
999 I915_READ(GTIMR));
1000 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001001 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -07001002 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001003 seq_printf(m,
1004 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001005 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +00001006 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001007 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +00001008 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001009 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001010 mutex_unlock(&dev->struct_mutex);
1011
Ben Gamari20172632009-02-17 20:08:50 -05001012 return 0;
1013}
1014
Chris Wilsona6172a82009-02-11 14:26:38 +00001015static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
1016{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001017 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +00001018 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001019 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001020 int i, ret;
1021
1022 ret = mutex_lock_interruptible(&dev->struct_mutex);
1023 if (ret)
1024 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +00001025
Chris Wilsona6172a82009-02-11 14:26:38 +00001026 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
1027 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +00001028 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +00001029
Chris Wilson6c085a72012-08-20 11:40:46 +02001030 seq_printf(m, "Fence %d, pin count = %d, object = ",
1031 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001032 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001033 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001034 else
Chris Wilson05394f32010-11-08 19:18:58 +00001035 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001036 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001037 }
1038
Chris Wilson05394f32010-11-08 19:18:58 +00001039 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001040 return 0;
1041}
1042
Ben Gamari20172632009-02-17 20:08:50 -05001043static int i915_hws_info(struct seq_file *m, void *data)
1044{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001045 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001046 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001047 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001048 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001049 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001050 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001051
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001052 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001053 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001054 if (hws == NULL)
1055 return 0;
1056
1057 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1058 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1059 i * 4,
1060 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1061 }
1062 return 0;
1063}
1064
Daniel Vetterd5442302012-04-27 15:17:40 +02001065static ssize_t
1066i915_error_state_write(struct file *filp,
1067 const char __user *ubuf,
1068 size_t cnt,
1069 loff_t *ppos)
1070{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001071 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001072 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001073 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001074
1075 DRM_DEBUG_DRIVER("Resetting error state\n");
1076
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001077 ret = mutex_lock_interruptible(&dev->struct_mutex);
1078 if (ret)
1079 return ret;
1080
Daniel Vetterd5442302012-04-27 15:17:40 +02001081 i915_destroy_error_state(dev);
1082 mutex_unlock(&dev->struct_mutex);
1083
1084 return cnt;
1085}
1086
1087static int i915_error_state_open(struct inode *inode, struct file *file)
1088{
1089 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001090 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001091
1092 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1093 if (!error_priv)
1094 return -ENOMEM;
1095
1096 error_priv->dev = dev;
1097
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001098 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001099
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001100 file->private_data = error_priv;
1101
1102 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001103}
1104
1105static int i915_error_state_release(struct inode *inode, struct file *file)
1106{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001107 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001108
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001109 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001110 kfree(error_priv);
1111
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001112 return 0;
1113}
1114
1115static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1116 size_t count, loff_t *pos)
1117{
1118 struct i915_error_state_file_priv *error_priv = file->private_data;
1119 struct drm_i915_error_state_buf error_str;
1120 loff_t tmp_pos = 0;
1121 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001122 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001123
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001124 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001125 if (ret)
1126 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001127
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001128 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001129 if (ret)
1130 goto out;
1131
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001132 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1133 error_str.buf,
1134 error_str.bytes);
1135
1136 if (ret_count < 0)
1137 ret = ret_count;
1138 else
1139 *pos = error_str.start + ret_count;
1140out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001141 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001142 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001143}
1144
1145static const struct file_operations i915_error_state_fops = {
1146 .owner = THIS_MODULE,
1147 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001148 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001149 .write = i915_error_state_write,
1150 .llseek = default_llseek,
1151 .release = i915_error_state_release,
1152};
1153
Kees Cook647416f2013-03-10 14:10:06 -07001154static int
1155i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001156{
Kees Cook647416f2013-03-10 14:10:06 -07001157 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001158 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala40633212012-12-04 15:12:00 +02001159 int ret;
1160
1161 ret = mutex_lock_interruptible(&dev->struct_mutex);
1162 if (ret)
1163 return ret;
1164
Kees Cook647416f2013-03-10 14:10:06 -07001165 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001166 mutex_unlock(&dev->struct_mutex);
1167
Kees Cook647416f2013-03-10 14:10:06 -07001168 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001169}
1170
Kees Cook647416f2013-03-10 14:10:06 -07001171static int
1172i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001173{
Kees Cook647416f2013-03-10 14:10:06 -07001174 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001175 int ret;
1176
Mika Kuoppala40633212012-12-04 15:12:00 +02001177 ret = mutex_lock_interruptible(&dev->struct_mutex);
1178 if (ret)
1179 return ret;
1180
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001181 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001182 mutex_unlock(&dev->struct_mutex);
1183
Kees Cook647416f2013-03-10 14:10:06 -07001184 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001185}
1186
Kees Cook647416f2013-03-10 14:10:06 -07001187DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1188 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001189 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001190
Deepak Sadb4bd12014-03-31 11:30:02 +05301191static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001192{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001193 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001194 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001195 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001196 int ret = 0;
1197
1198 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001199
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001200 if (IS_GEN5(dev)) {
1201 u16 rgvswctl = I915_READ16(MEMSWCTL);
1202 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1203
1204 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1205 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1206 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1207 MEMSTAT_VID_SHIFT);
1208 seq_printf(m, "Current P-state: %d\n",
1209 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001210 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1211 u32 freq_sts;
1212
1213 mutex_lock(&dev_priv->rps.hw_lock);
1214 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1215 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1216 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1217
1218 seq_printf(m, "actual GPU freq: %d MHz\n",
1219 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1220
1221 seq_printf(m, "current GPU freq: %d MHz\n",
1222 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1223
1224 seq_printf(m, "max GPU freq: %d MHz\n",
1225 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1226
1227 seq_printf(m, "min GPU freq: %d MHz\n",
1228 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1229
1230 seq_printf(m, "idle GPU freq: %d MHz\n",
1231 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1232
1233 seq_printf(m,
1234 "efficient (RPe) frequency: %d MHz\n",
1235 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1236 mutex_unlock(&dev_priv->rps.hw_lock);
1237 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001238 u32 rp_state_limits;
1239 u32 gt_perf_status;
1240 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001241 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001242 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001243 u32 rpupei, rpcurup, rpprevup;
1244 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001245 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001246 int max_freq;
1247
Bob Paauwe35040562015-06-25 14:54:07 -07001248 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1249 if (IS_BROXTON(dev)) {
1250 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1251 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1252 } else {
1253 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1254 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1255 }
1256
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001257 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001258 ret = mutex_lock_interruptible(&dev->struct_mutex);
1259 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001260 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001261
Mika Kuoppala59bad942015-01-16 11:34:40 +02001262 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001264 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301265 if (IS_GEN9(dev))
1266 reqf >>= 23;
1267 else {
1268 reqf &= ~GEN6_TURBO_DISABLE;
1269 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1270 reqf >>= 24;
1271 else
1272 reqf >>= 25;
1273 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001274 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001275
Chris Wilson0d8f9492014-03-27 09:06:14 +00001276 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1277 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1278 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1279
Jesse Barnesccab5c82011-01-18 15:49:25 -08001280 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301281 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1282 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1283 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1284 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1285 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1286 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301287 if (IS_GEN9(dev))
1288 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1289 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001290 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1291 else
1292 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001293 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001294
Mika Kuoppala59bad942015-01-16 11:34:40 +02001295 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001296 mutex_unlock(&dev->struct_mutex);
1297
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001298 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1299 pm_ier = I915_READ(GEN6_PMIER);
1300 pm_imr = I915_READ(GEN6_PMIMR);
1301 pm_isr = I915_READ(GEN6_PMISR);
1302 pm_iir = I915_READ(GEN6_PMIIR);
1303 pm_mask = I915_READ(GEN6_PMINTRMSK);
1304 } else {
1305 pm_ier = I915_READ(GEN8_GT_IER(2));
1306 pm_imr = I915_READ(GEN8_GT_IMR(2));
1307 pm_isr = I915_READ(GEN8_GT_ISR(2));
1308 pm_iir = I915_READ(GEN8_GT_IIR(2));
1309 pm_mask = I915_READ(GEN6_PMINTRMSK);
1310 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001311 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001312 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301313 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001314 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001315 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301316 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001317 seq_printf(m, "Render p-state VID: %d\n",
1318 gt_perf_status & 0xff);
1319 seq_printf(m, "Render p-state limit: %d\n",
1320 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001321 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1322 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1323 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1324 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001325 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001326 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301327 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1328 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1329 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1330 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1331 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1332 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001333 seq_printf(m, "Up threshold: %d%%\n",
1334 dev_priv->rps.up_threshold);
1335
Akash Goeld6cda9c2016-04-23 00:05:46 +05301336 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1337 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1338 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1339 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1340 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1341 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001342 seq_printf(m, "Down threshold: %d%%\n",
1343 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001344
Bob Paauwe35040562015-06-25 14:54:07 -07001345 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1346 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001347 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1348 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001349 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001350 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001351
1352 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001353 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1354 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001355 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001356 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001357
Bob Paauwe35040562015-06-25 14:54:07 -07001358 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1359 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001360 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1361 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001362 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001363 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001364 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001365 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001366
Chris Wilsond86ed342015-04-27 13:41:19 +01001367 seq_printf(m, "Current freq: %d MHz\n",
1368 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1369 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001370 seq_printf(m, "Idle freq: %d MHz\n",
1371 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001372 seq_printf(m, "Min freq: %d MHz\n",
1373 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001374 seq_printf(m, "Boost freq: %d MHz\n",
1375 intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001376 seq_printf(m, "Max freq: %d MHz\n",
1377 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1378 seq_printf(m,
1379 "efficient (RPe) frequency: %d MHz\n",
1380 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001381 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001382 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001383 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001384
Mika Kahola1170f282015-09-25 14:00:32 +03001385 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1386 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1387 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1388
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001389out:
1390 intel_runtime_pm_put(dev_priv);
1391 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001392}
1393
Chris Wilsonf6544492015-01-26 18:03:04 +02001394static int i915_hangcheck_info(struct seq_file *m, void *unused)
1395{
1396 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001397 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001398 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001399 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001400 u64 acthd[I915_NUM_ENGINES];
1401 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001402 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001403 enum intel_engine_id id;
1404 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001405
1406 if (!i915.enable_hangcheck) {
1407 seq_printf(m, "Hangcheck disabled\n");
1408 return 0;
1409 }
1410
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001411 intel_runtime_pm_get(dev_priv);
1412
Dave Gordonc3232b12016-03-23 18:19:53 +00001413 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001414 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001415 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001416 }
1417
Chris Wilsonc0336662016-05-06 15:40:21 +01001418 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001419
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001420 intel_runtime_pm_put(dev_priv);
1421
Chris Wilsonf6544492015-01-26 18:03:04 +02001422 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1423 seq_printf(m, "Hangcheck active, fires in %dms\n",
1424 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1425 jiffies));
1426 } else
1427 seq_printf(m, "Hangcheck inactive\n");
1428
Dave Gordonc3232b12016-03-23 18:19:53 +00001429 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001430 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001431 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1432 engine->hangcheck.seqno,
1433 seqno[id],
1434 engine->last_submitted_seqno);
Chris Wilson83348ba2016-08-09 17:47:51 +01001435 seq_printf(m, "\twaiters? %s, fake irq active? %s\n",
1436 yesno(intel_engine_has_waiter(engine)),
1437 yesno(test_bit(engine->id,
1438 &dev_priv->gpu_error.missed_irq_rings)));
Chris Wilsonf6544492015-01-26 18:03:04 +02001439 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001440 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001441 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001442 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1443 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001444
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001445 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001446 seq_puts(m, "\tinstdone read =");
1447
1448 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1449 seq_printf(m, " 0x%08x", instdone[j]);
1450
1451 seq_puts(m, "\n\tinstdone accu =");
1452
1453 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1454 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001455 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001456
1457 seq_puts(m, "\n");
1458 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001459 }
1460
1461 return 0;
1462}
1463
Ben Widawsky4d855292011-12-12 19:34:16 -08001464static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001465{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001466 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001467 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001468 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001469 u32 rgvmodectl, rstdbyctl;
1470 u16 crstandvid;
1471 int ret;
1472
1473 ret = mutex_lock_interruptible(&dev->struct_mutex);
1474 if (ret)
1475 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001476 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001477
1478 rgvmodectl = I915_READ(MEMMODECTL);
1479 rstdbyctl = I915_READ(RSTDBYCTL);
1480 crstandvid = I915_READ16(CRSTANDVID);
1481
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001482 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001483 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001484
Jani Nikula742f4912015-09-03 11:16:09 +03001485 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001486 seq_printf(m, "Boost freq: %d\n",
1487 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1488 MEMMODE_BOOST_FREQ_SHIFT);
1489 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001490 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001491 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001492 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001493 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001494 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001495 seq_printf(m, "Starting frequency: P%d\n",
1496 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001497 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001498 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001499 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1500 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1501 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1502 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001503 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001504 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001505 switch (rstdbyctl & RSX_STATUS_MASK) {
1506 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001507 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001508 break;
1509 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001510 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001511 break;
1512 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001513 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001514 break;
1515 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001516 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001517 break;
1518 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001519 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001520 break;
1521 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001522 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001523 break;
1524 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001525 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001526 break;
1527 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001528
1529 return 0;
1530}
1531
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001532static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001533{
1534 struct drm_info_node *node = m->private;
1535 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001536 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001537 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001538
1539 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001540 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001541 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001542 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001543 fw_domain->wake_count);
1544 }
1545 spin_unlock_irq(&dev_priv->uncore.lock);
1546
1547 return 0;
1548}
1549
Deepak S669ab5a2014-01-10 15:18:26 +05301550static int vlv_drpc_info(struct seq_file *m)
1551{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001552 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301553 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001554 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001555 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301556
Imre Deakd46c0512014-04-14 20:24:27 +03001557 intel_runtime_pm_get(dev_priv);
1558
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001559 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301560 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1561 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1562
Imre Deakd46c0512014-04-14 20:24:27 +03001563 intel_runtime_pm_put(dev_priv);
1564
Deepak S669ab5a2014-01-10 15:18:26 +05301565 seq_printf(m, "Video Turbo Mode: %s\n",
1566 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1567 seq_printf(m, "Turbo enabled: %s\n",
1568 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1569 seq_printf(m, "HW control enabled: %s\n",
1570 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1571 seq_printf(m, "SW control enabled: %s\n",
1572 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1573 GEN6_RP_MEDIA_SW_MODE));
1574 seq_printf(m, "RC6 Enabled: %s\n",
1575 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1576 GEN6_RC_CTL_EI_MODE(1))));
1577 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001578 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301579 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001580 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301581
Imre Deak9cc19be2014-04-14 20:24:24 +03001582 seq_printf(m, "Render RC6 residency since boot: %u\n",
1583 I915_READ(VLV_GT_RENDER_RC6));
1584 seq_printf(m, "Media RC6 residency since boot: %u\n",
1585 I915_READ(VLV_GT_MEDIA_RC6));
1586
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001587 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301588}
1589
Ben Widawsky4d855292011-12-12 19:34:16 -08001590static int gen6_drpc_info(struct seq_file *m)
1591{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001592 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001594 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001595 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301596 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001597 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001598 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001599
1600 ret = mutex_lock_interruptible(&dev->struct_mutex);
1601 if (ret)
1602 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001603 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001604
Chris Wilson907b28c2013-07-19 20:36:52 +01001605 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001606 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001607 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001608
1609 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001610 seq_puts(m, "RC information inaccurate because somebody "
1611 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001612 } else {
1613 /* NB: we cannot use forcewake, else we read the wrong values */
1614 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1615 udelay(10);
1616 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1617 }
1618
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001619 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001620 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001621
1622 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1623 rcctl1 = I915_READ(GEN6_RC_CONTROL);
Akash Goelf2dd7572016-06-27 20:10:01 +05301624 if (INTEL_INFO(dev)->gen >= 9) {
1625 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1626 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1627 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001628 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001629 mutex_lock(&dev_priv->rps.hw_lock);
1630 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1631 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001632
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001633 intel_runtime_pm_put(dev_priv);
1634
Ben Widawsky4d855292011-12-12 19:34:16 -08001635 seq_printf(m, "Video Turbo Mode: %s\n",
1636 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1637 seq_printf(m, "HW control enabled: %s\n",
1638 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1639 seq_printf(m, "SW control enabled: %s\n",
1640 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1641 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001642 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001643 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1644 seq_printf(m, "RC6 Enabled: %s\n",
1645 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
Akash Goelf2dd7572016-06-27 20:10:01 +05301646 if (INTEL_INFO(dev)->gen >= 9) {
1647 seq_printf(m, "Render Well Gating Enabled: %s\n",
1648 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1649 seq_printf(m, "Media Well Gating Enabled: %s\n",
1650 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1651 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001652 seq_printf(m, "Deep RC6 Enabled: %s\n",
1653 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1654 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1655 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001656 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001657 switch (gt_core_status & GEN6_RCn_MASK) {
1658 case GEN6_RC0:
1659 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001660 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001661 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001662 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001663 break;
1664 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001665 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001666 break;
1667 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001668 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001669 break;
1670 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001671 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001672 break;
1673 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001674 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001675 break;
1676 }
1677
1678 seq_printf(m, "Core Power Down: %s\n",
1679 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Akash Goelf2dd7572016-06-27 20:10:01 +05301680 if (INTEL_INFO(dev)->gen >= 9) {
1681 seq_printf(m, "Render Power Well: %s\n",
1682 (gen9_powergate_status &
1683 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1684 seq_printf(m, "Media Power Well: %s\n",
1685 (gen9_powergate_status &
1686 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1687 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001688
1689 /* Not exactly sure what this is */
1690 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1691 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1692 seq_printf(m, "RC6 residency since boot: %u\n",
1693 I915_READ(GEN6_GT_GFX_RC6));
1694 seq_printf(m, "RC6+ residency since boot: %u\n",
1695 I915_READ(GEN6_GT_GFX_RC6p));
1696 seq_printf(m, "RC6++ residency since boot: %u\n",
1697 I915_READ(GEN6_GT_GFX_RC6pp));
1698
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001699 seq_printf(m, "RC6 voltage: %dmV\n",
1700 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1701 seq_printf(m, "RC6+ voltage: %dmV\n",
1702 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1703 seq_printf(m, "RC6++ voltage: %dmV\n",
1704 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301705 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001706}
1707
1708static int i915_drpc_info(struct seq_file *m, void *unused)
1709{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001710 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001711 struct drm_device *dev = node->minor->dev;
1712
Wayne Boyer666a4532015-12-09 12:29:35 -08001713 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301714 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001715 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001716 return gen6_drpc_info(m);
1717 else
1718 return ironlake_drpc_info(m);
1719}
1720
Daniel Vetter9a851782015-06-18 10:30:22 +02001721static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1722{
1723 struct drm_info_node *node = m->private;
1724 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001725 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter9a851782015-06-18 10:30:22 +02001726
1727 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1728 dev_priv->fb_tracking.busy_bits);
1729
1730 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1731 dev_priv->fb_tracking.flip_bits);
1732
1733 return 0;
1734}
1735
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001736static int i915_fbc_status(struct seq_file *m, void *unused)
1737{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001738 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001739 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001740 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001741
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001742 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001743 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001744 return 0;
1745 }
1746
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001747 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001748 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001749
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001750 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001751 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001752 else
1753 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001754 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001755
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001756 if (INTEL_INFO(dev_priv)->gen >= 7)
1757 seq_printf(m, "Compressing: %s\n",
1758 yesno(I915_READ(FBC_STATUS2) &
1759 FBC_COMPRESSION_MASK));
1760
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001761 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001762 intel_runtime_pm_put(dev_priv);
1763
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001764 return 0;
1765}
1766
Rodrigo Vivida46f932014-08-01 02:04:45 -07001767static int i915_fbc_fc_get(void *data, u64 *val)
1768{
1769 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001770 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001771
1772 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1773 return -ENODEV;
1774
Rodrigo Vivida46f932014-08-01 02:04:45 -07001775 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001776
1777 return 0;
1778}
1779
1780static int i915_fbc_fc_set(void *data, u64 val)
1781{
1782 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001783 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001784 u32 reg;
1785
1786 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1787 return -ENODEV;
1788
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001789 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001790
1791 reg = I915_READ(ILK_DPFC_CONTROL);
1792 dev_priv->fbc.false_color = val;
1793
1794 I915_WRITE(ILK_DPFC_CONTROL, val ?
1795 (reg | FBC_CTL_FALSE_COLOR) :
1796 (reg & ~FBC_CTL_FALSE_COLOR));
1797
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001798 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001799 return 0;
1800}
1801
1802DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1803 i915_fbc_fc_get, i915_fbc_fc_set,
1804 "%llu\n");
1805
Paulo Zanoni92d44622013-05-31 16:33:24 -03001806static int i915_ips_status(struct seq_file *m, void *unused)
1807{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001808 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001809 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001810 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001811
Damien Lespiauf5adf942013-06-24 18:29:34 +01001812 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001813 seq_puts(m, "not supported\n");
1814 return 0;
1815 }
1816
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001817 intel_runtime_pm_get(dev_priv);
1818
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001819 seq_printf(m, "Enabled by kernel parameter: %s\n",
1820 yesno(i915.enable_ips));
1821
1822 if (INTEL_INFO(dev)->gen >= 8) {
1823 seq_puts(m, "Currently: unknown\n");
1824 } else {
1825 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1826 seq_puts(m, "Currently: enabled\n");
1827 else
1828 seq_puts(m, "Currently: disabled\n");
1829 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001830
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001831 intel_runtime_pm_put(dev_priv);
1832
Paulo Zanoni92d44622013-05-31 16:33:24 -03001833 return 0;
1834}
1835
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001836static int i915_sr_status(struct seq_file *m, void *unused)
1837{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001838 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001839 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001840 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001841 bool sr_enabled = false;
1842
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001843 intel_runtime_pm_get(dev_priv);
1844
Yuanhan Liu13982612010-12-15 15:42:31 +08001845 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001846 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001847 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1848 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001849 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1850 else if (IS_I915GM(dev))
1851 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1852 else if (IS_PINEVIEW(dev))
1853 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001854 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001855 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001856
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001857 intel_runtime_pm_put(dev_priv);
1858
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001859 seq_printf(m, "self-refresh: %s\n",
1860 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001861
1862 return 0;
1863}
1864
Jesse Barnes7648fa92010-05-20 14:28:11 -07001865static int i915_emon_status(struct seq_file *m, void *unused)
1866{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001867 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001868 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001869 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001870 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001871 int ret;
1872
Chris Wilson582be6b2012-04-30 19:35:02 +01001873 if (!IS_GEN5(dev))
1874 return -ENODEV;
1875
Chris Wilsonde227ef2010-07-03 07:58:38 +01001876 ret = mutex_lock_interruptible(&dev->struct_mutex);
1877 if (ret)
1878 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001879
1880 temp = i915_mch_val(dev_priv);
1881 chipset = i915_chipset_val(dev_priv);
1882 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001883 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001884
1885 seq_printf(m, "GMCH temp: %ld\n", temp);
1886 seq_printf(m, "Chipset power: %ld\n", chipset);
1887 seq_printf(m, "GFX power: %ld\n", gfx);
1888 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1889
1890 return 0;
1891}
1892
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001893static int i915_ring_freq_table(struct seq_file *m, void *unused)
1894{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001895 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001896 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001897 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001898 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001899 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301900 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001901
Akash Goel97d33082015-06-29 14:50:23 +05301902 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001903 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001904 return 0;
1905 }
1906
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001907 intel_runtime_pm_get(dev_priv);
1908
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001909 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001910 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001911 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001912
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001913 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301914 /* Convert GT frequency to 50 HZ units */
1915 min_gpu_freq =
1916 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1917 max_gpu_freq =
1918 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1919 } else {
1920 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1921 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1922 }
1923
Damien Lespiau267f0c92013-06-24 22:59:48 +01001924 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001925
Akash Goelf936ec32015-06-29 14:50:22 +05301926 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001927 ia_freq = gpu_freq;
1928 sandybridge_pcode_read(dev_priv,
1929 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1930 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001931 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301932 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001933 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1934 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001935 ((ia_freq >> 0) & 0xff) * 100,
1936 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001937 }
1938
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001939 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001940
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001941out:
1942 intel_runtime_pm_put(dev_priv);
1943 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001944}
1945
Chris Wilson44834a62010-08-19 16:09:23 +01001946static int i915_opregion(struct seq_file *m, void *unused)
1947{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001948 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001949 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001950 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson44834a62010-08-19 16:09:23 +01001951 struct intel_opregion *opregion = &dev_priv->opregion;
1952 int ret;
1953
1954 ret = mutex_lock_interruptible(&dev->struct_mutex);
1955 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001956 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001957
Jani Nikula2455a8e2015-12-14 12:50:53 +02001958 if (opregion->header)
1959 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001960
1961 mutex_unlock(&dev->struct_mutex);
1962
Daniel Vetter0d38f002012-04-21 22:49:10 +02001963out:
Chris Wilson44834a62010-08-19 16:09:23 +01001964 return 0;
1965}
1966
Jani Nikulaada8f952015-12-15 13:17:12 +02001967static int i915_vbt(struct seq_file *m, void *unused)
1968{
1969 struct drm_info_node *node = m->private;
1970 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001971 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulaada8f952015-12-15 13:17:12 +02001972 struct intel_opregion *opregion = &dev_priv->opregion;
1973
1974 if (opregion->vbt)
1975 seq_write(m, opregion->vbt, opregion->vbt_size);
1976
1977 return 0;
1978}
1979
Chris Wilson37811fc2010-08-25 22:45:57 +01001980static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1981{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001982 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001983 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301984 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001985 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001986 int ret;
1987
1988 ret = mutex_lock_interruptible(&dev->struct_mutex);
1989 if (ret)
1990 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001991
Daniel Vetter06957262015-08-10 13:34:08 +02001992#ifdef CONFIG_DRM_FBDEV_EMULATION
Chris Wilson25bcce92016-07-02 15:36:00 +01001993 if (to_i915(dev)->fbdev) {
1994 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001995
Chris Wilson25bcce92016-07-02 15:36:00 +01001996 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1997 fbdev_fb->base.width,
1998 fbdev_fb->base.height,
1999 fbdev_fb->base.depth,
2000 fbdev_fb->base.bits_per_pixel,
2001 fbdev_fb->base.modifier[0],
2002 drm_framebuffer_read_refcount(&fbdev_fb->base));
2003 describe_obj(m, fbdev_fb->obj);
2004 seq_putc(m, '\n');
2005 }
Daniel Vetter4520f532013-10-09 09:18:51 +02002006#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01002007
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002008 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02002009 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05302010 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
2011 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01002012 continue;
2013
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002014 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 +01002015 fb->base.width,
2016 fb->base.height,
2017 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01002018 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002019 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10002020 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00002021 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01002022 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01002023 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002024 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01002025 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01002026
2027 return 0;
2028}
2029
Chris Wilson7e37f882016-08-02 22:50:21 +01002030static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002031{
2032 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
Chris Wilson7e37f882016-08-02 22:50:21 +01002033 ring->space, ring->head, ring->tail,
2034 ring->last_retired_head);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002035}
2036
Ben Widawskye76d3632011-03-19 18:14:29 -07002037static int i915_context_status(struct seq_file *m, void *unused)
2038{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002039 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07002040 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002041 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002042 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002043 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00002044 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07002045
Daniel Vetterf3d28872014-05-29 23:23:08 +02002046 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002047 if (ret)
2048 return ret;
2049
Ben Widawskya33afea2013-09-17 21:12:45 -07002050 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01002051 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsond28b99a2016-05-24 14:53:39 +01002052 if (IS_ERR(ctx->file_priv)) {
2053 seq_puts(m, "(deleted) ");
2054 } else if (ctx->file_priv) {
2055 struct pid *pid = ctx->file_priv->file->pid;
2056 struct task_struct *task;
2057
2058 task = get_pid_task(pid, PIDTYPE_PID);
2059 if (task) {
2060 seq_printf(m, "(%s [%d]) ",
2061 task->comm, task->pid);
2062 put_task_struct(task);
2063 }
2064 } else {
2065 seq_puts(m, "(kernel) ");
2066 }
2067
Chris Wilsonbca44d82016-05-24 14:53:41 +01002068 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
2069 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07002070
Chris Wilsonbca44d82016-05-24 14:53:41 +01002071 for_each_engine(engine, dev_priv) {
2072 struct intel_context *ce = &ctx->engine[engine->id];
2073
2074 seq_printf(m, "%s: ", engine->name);
2075 seq_putc(m, ce->initialised ? 'I' : 'i');
2076 if (ce->state)
2077 describe_obj(m, ce->state);
Chris Wilsondca33ec2016-08-02 22:50:20 +01002078 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01002079 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002080 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002081 }
2082
Ben Widawskya33afea2013-09-17 21:12:45 -07002083 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002084 }
2085
Daniel Vetterf3d28872014-05-29 23:23:08 +02002086 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002087
2088 return 0;
2089}
2090
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002091static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002092 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002093 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002094{
Chris Wilsonbca44d82016-05-24 14:53:41 +01002095 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002096 struct page *page;
2097 uint32_t *reg_state;
2098 int j;
2099 unsigned long ggtt_offset = 0;
2100
Chris Wilson7069b142016-04-28 09:56:52 +01002101 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2102
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002103 if (ctx_obj == NULL) {
Chris Wilson7069b142016-04-28 09:56:52 +01002104 seq_puts(m, "\tNot allocated\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002105 return;
2106 }
2107
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002108 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2109 seq_puts(m, "\tNot bound in GGTT\n");
2110 else
2111 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2112
2113 if (i915_gem_object_get_pages(ctx_obj)) {
2114 seq_puts(m, "\tFailed to get pages for context object\n");
2115 return;
2116 }
2117
Alex Daid1675192015-08-12 15:43:43 +01002118 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002119 if (!WARN_ON(page == NULL)) {
2120 reg_state = kmap_atomic(page);
2121
2122 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2123 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2124 ggtt_offset + 4096 + (j * 4),
2125 reg_state[j], reg_state[j + 1],
2126 reg_state[j + 2], reg_state[j + 3]);
2127 }
2128 kunmap_atomic(reg_state);
2129 }
2130
2131 seq_putc(m, '\n');
2132}
2133
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002134static int i915_dump_lrc(struct seq_file *m, void *unused)
2135{
2136 struct drm_info_node *node = (struct drm_info_node *) m->private;
2137 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002138 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002139 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002140 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002141 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002142
2143 if (!i915.enable_execlists) {
2144 seq_printf(m, "Logical Ring Contexts are disabled\n");
2145 return 0;
2146 }
2147
2148 ret = mutex_lock_interruptible(&dev->struct_mutex);
2149 if (ret)
2150 return ret;
2151
Dave Gordone28e4042016-01-19 19:02:55 +00002152 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002153 for_each_engine(engine, dev_priv)
2154 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002155
2156 mutex_unlock(&dev->struct_mutex);
2157
2158 return 0;
2159}
2160
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002161static int i915_execlists(struct seq_file *m, void *data)
2162{
2163 struct drm_info_node *node = (struct drm_info_node *)m->private;
2164 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002165 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002166 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002167 u32 status_pointer;
2168 u8 read_pointer;
2169 u8 write_pointer;
2170 u32 status;
2171 u32 ctx_id;
2172 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002173 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002174
2175 if (!i915.enable_execlists) {
2176 seq_puts(m, "Logical Ring Contexts are disabled\n");
2177 return 0;
2178 }
2179
2180 ret = mutex_lock_interruptible(&dev->struct_mutex);
2181 if (ret)
2182 return ret;
2183
Michel Thierryfc0412e2014-10-16 16:13:38 +01002184 intel_runtime_pm_get(dev_priv);
2185
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002186 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002187 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002188 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002189
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002190 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002191
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002192 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2193 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002194 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2195 status, ctx_id);
2196
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002197 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002198 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2199
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002200 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002201 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002202 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002203 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002204 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2205 read_pointer, write_pointer);
2206
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002207 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002208 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2209 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002210
2211 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2212 i, status, ctx_id);
2213 }
2214
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002215 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002216 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002217 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002218 head_req = list_first_entry_or_null(&engine->execlist_queue,
2219 struct drm_i915_gem_request,
2220 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002221 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002222
2223 seq_printf(m, "\t%d requests in queue\n", count);
2224 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002225 seq_printf(m, "\tHead request context: %u\n",
2226 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002227 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002228 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002229 }
2230
2231 seq_putc(m, '\n');
2232 }
2233
Michel Thierryfc0412e2014-10-16 16:13:38 +01002234 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002235 mutex_unlock(&dev->struct_mutex);
2236
2237 return 0;
2238}
2239
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002240static const char *swizzle_string(unsigned swizzle)
2241{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002242 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002243 case I915_BIT_6_SWIZZLE_NONE:
2244 return "none";
2245 case I915_BIT_6_SWIZZLE_9:
2246 return "bit9";
2247 case I915_BIT_6_SWIZZLE_9_10:
2248 return "bit9/bit10";
2249 case I915_BIT_6_SWIZZLE_9_11:
2250 return "bit9/bit11";
2251 case I915_BIT_6_SWIZZLE_9_10_11:
2252 return "bit9/bit10/bit11";
2253 case I915_BIT_6_SWIZZLE_9_17:
2254 return "bit9/bit17";
2255 case I915_BIT_6_SWIZZLE_9_10_17:
2256 return "bit9/bit10/bit17";
2257 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002258 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002259 }
2260
2261 return "bug";
2262}
2263
2264static int i915_swizzle_info(struct seq_file *m, void *data)
2265{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002266 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002267 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002268 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002269 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002270
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002271 ret = mutex_lock_interruptible(&dev->struct_mutex);
2272 if (ret)
2273 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002274 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002275
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002276 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2277 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2278 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2279 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2280
2281 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2282 seq_printf(m, "DDC = 0x%08x\n",
2283 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002284 seq_printf(m, "DDC2 = 0x%08x\n",
2285 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002286 seq_printf(m, "C0DRB3 = 0x%04x\n",
2287 I915_READ16(C0DRB3));
2288 seq_printf(m, "C1DRB3 = 0x%04x\n",
2289 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002290 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002291 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2292 I915_READ(MAD_DIMM_C0));
2293 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2294 I915_READ(MAD_DIMM_C1));
2295 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2296 I915_READ(MAD_DIMM_C2));
2297 seq_printf(m, "TILECTL = 0x%08x\n",
2298 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002299 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002300 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2301 I915_READ(GAMTARBMODE));
2302 else
2303 seq_printf(m, "ARB_MODE = 0x%08x\n",
2304 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002305 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2306 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002307 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002308
2309 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2310 seq_puts(m, "L-shaped memory detected\n");
2311
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002312 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002313 mutex_unlock(&dev->struct_mutex);
2314
2315 return 0;
2316}
2317
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002318static int per_file_ctx(int id, void *ptr, void *data)
2319{
Chris Wilsone2efd132016-05-24 14:53:34 +01002320 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002321 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002322 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2323
2324 if (!ppgtt) {
2325 seq_printf(m, " no ppgtt for context %d\n",
2326 ctx->user_handle);
2327 return 0;
2328 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002329
Oscar Mateof83d6512014-05-22 14:13:38 +01002330 if (i915_gem_context_is_default(ctx))
2331 seq_puts(m, " default context:\n");
2332 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002333 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002334 ppgtt->debug_dump(ppgtt, m);
2335
2336 return 0;
2337}
2338
Ben Widawsky77df6772013-11-02 21:07:30 -07002339static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002340{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002341 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002342 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002343 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002344 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002345
Ben Widawsky77df6772013-11-02 21:07:30 -07002346 if (!ppgtt)
2347 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002348
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002349 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002350 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002351 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002352 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002353 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002354 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002355 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002356 }
2357 }
2358}
2359
2360static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2361{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002362 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002363 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002364
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002365 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002366 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2367
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002368 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002369 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002370 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002371 seq_printf(m, "GFX_MODE: 0x%08x\n",
2372 I915_READ(RING_MODE_GEN7(engine)));
2373 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2374 I915_READ(RING_PP_DIR_BASE(engine)));
2375 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2376 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2377 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2378 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002379 }
2380 if (dev_priv->mm.aliasing_ppgtt) {
2381 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2382
Damien Lespiau267f0c92013-06-24 22:59:48 +01002383 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002384 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002385
Ben Widawsky87d60b62013-12-06 14:11:29 -08002386 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002387 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002388
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002389 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002390}
2391
2392static int i915_ppgtt_info(struct seq_file *m, void *data)
2393{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002394 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002395 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002396 struct drm_i915_private *dev_priv = to_i915(dev);
Michel Thierryea91e402015-07-29 17:23:57 +01002397 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002398
2399 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2400 if (ret)
2401 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002402 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002403
2404 if (INTEL_INFO(dev)->gen >= 8)
2405 gen8_ppgtt_info(m, dev);
2406 else if (INTEL_INFO(dev)->gen >= 6)
2407 gen6_ppgtt_info(m, dev);
2408
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002409 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002410 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2411 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002412 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002413
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002414 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002415 if (!task) {
2416 ret = -ESRCH;
Wei Yongjunb0212482016-06-13 23:42:00 +00002417 goto out_unlock;
Dan Carpenter06812762015-10-02 18:14:22 +03002418 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002419 seq_printf(m, "\nproc: %s\n", task->comm);
2420 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002421 idr_for_each(&file_priv->context_idr, per_file_ctx,
2422 (void *)(unsigned long)m);
2423 }
Wei Yongjunb0212482016-06-13 23:42:00 +00002424out_unlock:
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002425 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002426
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002427 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002428 mutex_unlock(&dev->struct_mutex);
2429
Dan Carpenter06812762015-10-02 18:14:22 +03002430 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002431}
2432
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002433static int count_irq_waiters(struct drm_i915_private *i915)
2434{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002435 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002436 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002437
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002438 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002439 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002440
2441 return count;
2442}
2443
Chris Wilson1854d5c2015-04-07 16:20:32 +01002444static int i915_rps_boost_info(struct seq_file *m, void *data)
2445{
2446 struct drm_info_node *node = m->private;
2447 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002448 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002449 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002450
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002451 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
Chris Wilson67d97da2016-07-04 08:08:31 +01002452 seq_printf(m, "GPU busy? %s [%x]\n",
2453 yesno(dev_priv->gt.awake), dev_priv->gt.active_engines);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002454 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2455 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2456 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2457 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2458 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2459 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2460 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002461
2462 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002463 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002464 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2465 struct drm_i915_file_private *file_priv = file->driver_priv;
2466 struct task_struct *task;
2467
2468 rcu_read_lock();
2469 task = pid_task(file->pid, PIDTYPE_PID);
2470 seq_printf(m, "%s [%d]: %d boosts%s\n",
2471 task ? task->comm : "<unknown>",
2472 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002473 file_priv->rps.boosts,
2474 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002475 rcu_read_unlock();
2476 }
Chris Wilson197be2a2016-07-20 09:21:13 +01002477 seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002478 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002479 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002480
Chris Wilson8d3afd72015-05-21 21:01:47 +01002481 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002482}
2483
Ben Widawsky63573eb2013-07-04 11:02:07 -07002484static int i915_llc(struct seq_file *m, void *data)
2485{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002486 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002487 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002488 struct drm_i915_private *dev_priv = to_i915(dev);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002489 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002490
Ben Widawsky63573eb2013-07-04 11:02:07 -07002491 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002492 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2493 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002494
2495 return 0;
2496}
2497
Alex Daifdf5d352015-08-12 15:43:37 +01002498static int i915_guc_load_status_info(struct seq_file *m, void *data)
2499{
2500 struct drm_info_node *node = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002501 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
Alex Daifdf5d352015-08-12 15:43:37 +01002502 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2503 u32 tmp, i;
2504
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002505 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002506 return 0;
2507
2508 seq_printf(m, "GuC firmware status:\n");
2509 seq_printf(m, "\tpath: %s\n",
2510 guc_fw->guc_fw_path);
2511 seq_printf(m, "\tfetch: %s\n",
2512 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2513 seq_printf(m, "\tload: %s\n",
2514 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2515 seq_printf(m, "\tversion wanted: %d.%d\n",
2516 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2517 seq_printf(m, "\tversion found: %d.%d\n",
2518 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002519 seq_printf(m, "\theader: offset is %d; size = %d\n",
2520 guc_fw->header_offset, guc_fw->header_size);
2521 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2522 guc_fw->ucode_offset, guc_fw->ucode_size);
2523 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2524 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002525
2526 tmp = I915_READ(GUC_STATUS);
2527
2528 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2529 seq_printf(m, "\tBootrom status = 0x%x\n",
2530 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2531 seq_printf(m, "\tuKernel status = 0x%x\n",
2532 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2533 seq_printf(m, "\tMIA Core status = 0x%x\n",
2534 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2535 seq_puts(m, "\nScratch registers:\n");
2536 for (i = 0; i < 16; i++)
2537 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2538
2539 return 0;
2540}
2541
Dave Gordon8b417c22015-08-12 15:43:44 +01002542static void i915_guc_client_info(struct seq_file *m,
2543 struct drm_i915_private *dev_priv,
2544 struct i915_guc_client *client)
2545{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002546 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002547 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002548 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002549
2550 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2551 client->priority, client->ctx_index, client->proc_desc_offset);
2552 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2553 client->doorbell_id, client->doorbell_offset, client->cookie);
2554 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2555 client->wq_size, client->wq_offset, client->wq_tail);
2556
Dave Gordon551aaec2016-05-13 15:36:33 +01002557 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002558 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2559 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2560
Dave Gordonc18468c2016-08-09 15:19:22 +01002561 for_each_engine_id(engine, dev_priv, id) {
2562 u64 submissions = client->submissions[id];
2563 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002564 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002565 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002566 }
2567 seq_printf(m, "\tTotal: %llu\n", tot);
2568}
2569
2570static int i915_guc_info(struct seq_file *m, void *data)
2571{
2572 struct drm_info_node *node = m->private;
2573 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002574 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Gordon8b417c22015-08-12 15:43:44 +01002575 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002576 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002577 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002578 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002579 u64 total = 0;
2580
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002581 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002582 return 0;
2583
Alex Dai5a843302015-12-02 16:56:29 -08002584 if (mutex_lock_interruptible(&dev->struct_mutex))
2585 return 0;
2586
Dave Gordon8b417c22015-08-12 15:43:44 +01002587 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002588 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002589 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002590 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002591
2592 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002593
Dave Gordon9636f6d2016-06-13 17:57:28 +01002594 seq_printf(m, "Doorbell map:\n");
2595 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2596 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2597
Dave Gordon8b417c22015-08-12 15:43:44 +01002598 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2599 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2600 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2601 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2602 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2603
2604 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonc18468c2016-08-09 15:19:22 +01002605 for_each_engine_id(engine, dev_priv, id) {
2606 u64 submissions = guc.submissions[id];
2607 total += submissions;
Alex Dai397097b2016-01-23 11:58:14 -08002608 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002609 engine->name, submissions, guc.last_seqno[id]);
Dave Gordon8b417c22015-08-12 15:43:44 +01002610 }
2611 seq_printf(m, "\t%s: %llu\n", "Total", total);
2612
2613 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2614 i915_guc_client_info(m, dev_priv, &client);
2615
2616 /* Add more as required ... */
2617
2618 return 0;
2619}
2620
Alex Dai4c7e77f2015-08-12 15:43:40 +01002621static int i915_guc_log_dump(struct seq_file *m, void *data)
2622{
2623 struct drm_info_node *node = m->private;
2624 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002625 struct drm_i915_private *dev_priv = to_i915(dev);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002626 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2627 u32 *log;
2628 int i = 0, pg;
2629
2630 if (!log_obj)
2631 return 0;
2632
2633 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2634 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2635
2636 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2637 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2638 *(log + i), *(log + i + 1),
2639 *(log + i + 2), *(log + i + 3));
2640
2641 kunmap_atomic(log);
2642 }
2643
2644 seq_putc(m, '\n');
2645
2646 return 0;
2647}
2648
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002649static int i915_edp_psr_status(struct seq_file *m, void *data)
2650{
2651 struct drm_info_node *node = m->private;
2652 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002653 struct drm_i915_private *dev_priv = to_i915(dev);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002654 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002655 u32 stat[3];
2656 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002657 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002658
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002659 if (!HAS_PSR(dev)) {
2660 seq_puts(m, "PSR not supported\n");
2661 return 0;
2662 }
2663
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002664 intel_runtime_pm_get(dev_priv);
2665
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002666 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002667 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2668 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002669 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002670 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002671 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2672 dev_priv->psr.busy_frontbuffer_bits);
2673 seq_printf(m, "Re-enable work scheduled: %s\n",
2674 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002675
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002676 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002677 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002678 else {
2679 for_each_pipe(dev_priv, pipe) {
2680 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2681 VLV_EDP_PSR_CURR_STATE_MASK;
2682 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2683 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2684 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002685 }
2686 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002687
2688 seq_printf(m, "Main link in standby mode: %s\n",
2689 yesno(dev_priv->psr.link_standby));
2690
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002691 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002692
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002693 if (!HAS_DDI(dev))
2694 for_each_pipe(dev_priv, pipe) {
2695 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2696 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2697 seq_printf(m, " pipe %c", pipe_name(pipe));
2698 }
2699 seq_puts(m, "\n");
2700
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002701 /*
2702 * VLV/CHV PSR has no kind of performance counter
2703 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2704 */
2705 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002706 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002707 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002708
2709 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2710 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002711 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002712
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002713 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002714 return 0;
2715}
2716
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002717static int i915_sink_crc(struct seq_file *m, void *data)
2718{
2719 struct drm_info_node *node = m->private;
2720 struct drm_device *dev = node->minor->dev;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002721 struct intel_connector *connector;
2722 struct intel_dp *intel_dp = NULL;
2723 int ret;
2724 u8 crc[6];
2725
2726 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002727 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002728 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002729
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002730 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002731 continue;
2732
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002733 crtc = connector->base.state->crtc;
2734 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002735 continue;
2736
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002737 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002738 continue;
2739
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002740 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002741
2742 ret = intel_dp_sink_crc(intel_dp, crc);
2743 if (ret)
2744 goto out;
2745
2746 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2747 crc[0], crc[1], crc[2],
2748 crc[3], crc[4], crc[5]);
2749 goto out;
2750 }
2751 ret = -ENODEV;
2752out:
2753 drm_modeset_unlock_all(dev);
2754 return ret;
2755}
2756
Jesse Barnesec013e72013-08-20 10:29:23 +01002757static int i915_energy_uJ(struct seq_file *m, void *data)
2758{
2759 struct drm_info_node *node = m->private;
2760 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002761 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesec013e72013-08-20 10:29:23 +01002762 u64 power;
2763 u32 units;
2764
2765 if (INTEL_INFO(dev)->gen < 6)
2766 return -ENODEV;
2767
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002768 intel_runtime_pm_get(dev_priv);
2769
Jesse Barnesec013e72013-08-20 10:29:23 +01002770 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2771 power = (power & 0x1f00) >> 8;
2772 units = 1000000 / (1 << power); /* convert to uJ */
2773 power = I915_READ(MCH_SECP_NRG_STTS);
2774 power *= units;
2775
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002776 intel_runtime_pm_put(dev_priv);
2777
Jesse Barnesec013e72013-08-20 10:29:23 +01002778 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002779
2780 return 0;
2781}
2782
Damien Lespiau6455c872015-06-04 18:23:57 +01002783static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002784{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002785 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002786 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002787 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni371db662013-08-19 13:18:10 -03002788
Chris Wilsona156e642016-04-03 14:14:21 +01002789 if (!HAS_RUNTIME_PM(dev_priv))
2790 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002791
Chris Wilson67d97da2016-07-04 08:08:31 +01002792 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002793 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002794 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002795#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002796 seq_printf(m, "Usage count: %d\n",
2797 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002798#else
2799 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2800#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002801 seq_printf(m, "PCI device power state: %s [%d]\n",
Chris Wilson91c8a322016-07-05 10:40:23 +01002802 pci_power_name(dev_priv->drm.pdev->current_state),
2803 dev_priv->drm.pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002804
Jesse Barnesec013e72013-08-20 10:29:23 +01002805 return 0;
2806}
2807
Imre Deak1da51582013-11-25 17:15:35 +02002808static int i915_power_domain_info(struct seq_file *m, void *unused)
2809{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002810 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002811 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002812 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1da51582013-11-25 17:15:35 +02002813 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2814 int i;
2815
2816 mutex_lock(&power_domains->lock);
2817
2818 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2819 for (i = 0; i < power_domains->power_well_count; i++) {
2820 struct i915_power_well *power_well;
2821 enum intel_display_power_domain power_domain;
2822
2823 power_well = &power_domains->power_wells[i];
2824 seq_printf(m, "%-25s %d\n", power_well->name,
2825 power_well->count);
2826
2827 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2828 power_domain++) {
2829 if (!(BIT(power_domain) & power_well->domains))
2830 continue;
2831
2832 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002833 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002834 power_domains->domain_use_count[power_domain]);
2835 }
2836 }
2837
2838 mutex_unlock(&power_domains->lock);
2839
2840 return 0;
2841}
2842
Damien Lespiaub7cec662015-10-27 14:47:01 +02002843static int i915_dmc_info(struct seq_file *m, void *unused)
2844{
2845 struct drm_info_node *node = m->private;
2846 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002847 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002848 struct intel_csr *csr;
2849
2850 if (!HAS_CSR(dev)) {
2851 seq_puts(m, "not supported\n");
2852 return 0;
2853 }
2854
2855 csr = &dev_priv->csr;
2856
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002857 intel_runtime_pm_get(dev_priv);
2858
Damien Lespiaub7cec662015-10-27 14:47:01 +02002859 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2860 seq_printf(m, "path: %s\n", csr->fw_path);
2861
2862 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002863 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002864
2865 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2866 CSR_VERSION_MINOR(csr->version));
2867
Damien Lespiau83372062015-10-30 17:53:32 +02002868 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2869 seq_printf(m, "DC3 -> DC5 count: %d\n",
2870 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2871 seq_printf(m, "DC5 -> DC6 count: %d\n",
2872 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002873 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2874 seq_printf(m, "DC3 -> DC5 count: %d\n",
2875 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002876 }
2877
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002878out:
2879 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2880 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2881 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2882
Damien Lespiau83372062015-10-30 17:53:32 +02002883 intel_runtime_pm_put(dev_priv);
2884
Damien Lespiaub7cec662015-10-27 14:47:01 +02002885 return 0;
2886}
2887
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002888static void intel_seq_print_mode(struct seq_file *m, int tabs,
2889 struct drm_display_mode *mode)
2890{
2891 int i;
2892
2893 for (i = 0; i < tabs; i++)
2894 seq_putc(m, '\t');
2895
2896 seq_printf(m, "id %d:\"%s\" freq %d clock %d hdisp %d hss %d hse %d htot %d vdisp %d vss %d vse %d vtot %d type 0x%x flags 0x%x\n",
2897 mode->base.id, mode->name,
2898 mode->vrefresh, mode->clock,
2899 mode->hdisplay, mode->hsync_start,
2900 mode->hsync_end, mode->htotal,
2901 mode->vdisplay, mode->vsync_start,
2902 mode->vsync_end, mode->vtotal,
2903 mode->type, mode->flags);
2904}
2905
2906static void intel_encoder_info(struct seq_file *m,
2907 struct intel_crtc *intel_crtc,
2908 struct intel_encoder *intel_encoder)
2909{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002910 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002911 struct drm_device *dev = node->minor->dev;
2912 struct drm_crtc *crtc = &intel_crtc->base;
2913 struct intel_connector *intel_connector;
2914 struct drm_encoder *encoder;
2915
2916 encoder = &intel_encoder->base;
2917 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002918 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002919 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2920 struct drm_connector *connector = &intel_connector->base;
2921 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2922 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002923 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002924 drm_get_connector_status_name(connector->status));
2925 if (connector->status == connector_status_connected) {
2926 struct drm_display_mode *mode = &crtc->mode;
2927 seq_printf(m, ", mode:\n");
2928 intel_seq_print_mode(m, 2, mode);
2929 } else {
2930 seq_putc(m, '\n');
2931 }
2932 }
2933}
2934
2935static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2936{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002937 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002938 struct drm_device *dev = node->minor->dev;
2939 struct drm_crtc *crtc = &intel_crtc->base;
2940 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002941 struct drm_plane_state *plane_state = crtc->primary->state;
2942 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002943
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002944 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002945 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002946 fb->base.id, plane_state->src_x >> 16,
2947 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002948 else
2949 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002950 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2951 intel_encoder_info(m, intel_crtc, intel_encoder);
2952}
2953
2954static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2955{
2956 struct drm_display_mode *mode = panel->fixed_mode;
2957
2958 seq_printf(m, "\tfixed mode:\n");
2959 intel_seq_print_mode(m, 2, mode);
2960}
2961
2962static void intel_dp_info(struct seq_file *m,
2963 struct intel_connector *intel_connector)
2964{
2965 struct intel_encoder *intel_encoder = intel_connector->encoder;
2966 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2967
2968 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002969 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002970 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002971 intel_panel_info(m, &intel_connector->panel);
2972}
2973
2974static void intel_hdmi_info(struct seq_file *m,
2975 struct intel_connector *intel_connector)
2976{
2977 struct intel_encoder *intel_encoder = intel_connector->encoder;
2978 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2979
Jani Nikula742f4912015-09-03 11:16:09 +03002980 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002981}
2982
2983static void intel_lvds_info(struct seq_file *m,
2984 struct intel_connector *intel_connector)
2985{
2986 intel_panel_info(m, &intel_connector->panel);
2987}
2988
2989static void intel_connector_info(struct seq_file *m,
2990 struct drm_connector *connector)
2991{
2992 struct intel_connector *intel_connector = to_intel_connector(connector);
2993 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002994 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002995
2996 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002997 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002998 drm_get_connector_status_name(connector->status));
2999 if (connector->status == connector_status_connected) {
3000 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3001 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3002 connector->display_info.width_mm,
3003 connector->display_info.height_mm);
3004 seq_printf(m, "\tsubpixel order: %s\n",
3005 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3006 seq_printf(m, "\tCEA rev: %d\n",
3007 connector->display_info.cea_rev);
3008 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003009
3010 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3011 return;
3012
3013 switch (connector->connector_type) {
3014 case DRM_MODE_CONNECTOR_DisplayPort:
3015 case DRM_MODE_CONNECTOR_eDP:
3016 intel_dp_info(m, intel_connector);
3017 break;
3018 case DRM_MODE_CONNECTOR_LVDS:
3019 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003020 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003021 break;
3022 case DRM_MODE_CONNECTOR_HDMIA:
3023 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3024 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3025 intel_hdmi_info(m, intel_connector);
3026 break;
3027 default:
3028 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003029 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003030
Jesse Barnesf103fc72014-02-20 12:39:57 -08003031 seq_printf(m, "\tmodes:\n");
3032 list_for_each_entry(mode, &connector->modes, head)
3033 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003034}
3035
Chris Wilson065f2ec2014-03-12 09:13:13 +00003036static bool cursor_active(struct drm_device *dev, int pipe)
3037{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003038 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003039 u32 state;
3040
3041 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003042 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003043 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003044 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003045
3046 return state;
3047}
3048
3049static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
3050{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003051 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003052 u32 pos;
3053
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003054 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003055
3056 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3057 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3058 *x = -*x;
3059
3060 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3061 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3062 *y = -*y;
3063
3064 return cursor_active(dev, pipe);
3065}
3066
Robert Fekete3abc4e02015-10-27 16:58:32 +01003067static const char *plane_type(enum drm_plane_type type)
3068{
3069 switch (type) {
3070 case DRM_PLANE_TYPE_OVERLAY:
3071 return "OVL";
3072 case DRM_PLANE_TYPE_PRIMARY:
3073 return "PRI";
3074 case DRM_PLANE_TYPE_CURSOR:
3075 return "CUR";
3076 /*
3077 * Deliberately omitting default: to generate compiler warnings
3078 * when a new drm_plane_type gets added.
3079 */
3080 }
3081
3082 return "unknown";
3083}
3084
3085static const char *plane_rotation(unsigned int rotation)
3086{
3087 static char buf[48];
3088 /*
3089 * According to doc only one DRM_ROTATE_ is allowed but this
3090 * will print them all to visualize if the values are misused
3091 */
3092 snprintf(buf, sizeof(buf),
3093 "%s%s%s%s%s%s(0x%08x)",
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +03003094 (rotation & DRM_ROTATE_0) ? "0 " : "",
3095 (rotation & DRM_ROTATE_90) ? "90 " : "",
3096 (rotation & DRM_ROTATE_180) ? "180 " : "",
3097 (rotation & DRM_ROTATE_270) ? "270 " : "",
3098 (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
3099 (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003100 rotation);
3101
3102 return buf;
3103}
3104
3105static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3106{
3107 struct drm_info_node *node = m->private;
3108 struct drm_device *dev = node->minor->dev;
3109 struct intel_plane *intel_plane;
3110
3111 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3112 struct drm_plane_state *state;
3113 struct drm_plane *plane = &intel_plane->base;
3114
3115 if (!plane->state) {
3116 seq_puts(m, "plane->state is NULL!\n");
3117 continue;
3118 }
3119
3120 state = plane->state;
3121
3122 seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
3123 plane->base.id,
3124 plane_type(intel_plane->base.type),
3125 state->crtc_x, state->crtc_y,
3126 state->crtc_w, state->crtc_h,
3127 (state->src_x >> 16),
3128 ((state->src_x & 0xffff) * 15625) >> 10,
3129 (state->src_y >> 16),
3130 ((state->src_y & 0xffff) * 15625) >> 10,
3131 (state->src_w >> 16),
3132 ((state->src_w & 0xffff) * 15625) >> 10,
3133 (state->src_h >> 16),
3134 ((state->src_h & 0xffff) * 15625) >> 10,
3135 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3136 plane_rotation(state->rotation));
3137 }
3138}
3139
3140static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3141{
3142 struct intel_crtc_state *pipe_config;
3143 int num_scalers = intel_crtc->num_scalers;
3144 int i;
3145
3146 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3147
3148 /* Not all platformas have a scaler */
3149 if (num_scalers) {
3150 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3151 num_scalers,
3152 pipe_config->scaler_state.scaler_users,
3153 pipe_config->scaler_state.scaler_id);
3154
3155 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3156 struct intel_scaler *sc =
3157 &pipe_config->scaler_state.scalers[i];
3158
3159 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3160 i, yesno(sc->in_use), sc->mode);
3161 }
3162 seq_puts(m, "\n");
3163 } else {
3164 seq_puts(m, "\tNo scalers available on this platform\n");
3165 }
3166}
3167
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003168static int i915_display_info(struct seq_file *m, void *unused)
3169{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003170 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003171 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003172 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson065f2ec2014-03-12 09:13:13 +00003173 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003174 struct drm_connector *connector;
3175
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003176 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003177 drm_modeset_lock_all(dev);
3178 seq_printf(m, "CRTC info\n");
3179 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003180 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003181 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003182 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003183 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003184
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003185 pipe_config = to_intel_crtc_state(crtc->base.state);
3186
Robert Fekete3abc4e02015-10-27 16:58:32 +01003187 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003188 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003189 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003190 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3191 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3192
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003193 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003194 intel_crtc_info(m, crtc);
3195
Paulo Zanonia23dc652014-04-01 14:55:11 -03003196 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003197 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x, active? %s\n",
Chris Wilson4b0e3332014-05-30 16:35:26 +03003198 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003199 x, y, crtc->base.cursor->state->crtc_w,
3200 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003201 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003202 intel_scaler_info(m, crtc);
3203 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003204 }
Daniel Vettercace8412014-05-22 17:56:31 +02003205
3206 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3207 yesno(!crtc->cpu_fifo_underrun_disabled),
3208 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003209 }
3210
3211 seq_printf(m, "\n");
3212 seq_printf(m, "Connector info\n");
3213 seq_printf(m, "--------------\n");
3214 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3215 intel_connector_info(m, connector);
3216 }
3217 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003218 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003219
3220 return 0;
3221}
3222
Ben Widawskye04934c2014-06-30 09:53:42 -07003223static int i915_semaphore_status(struct seq_file *m, void *unused)
3224{
3225 struct drm_info_node *node = (struct drm_info_node *) m->private;
3226 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003227 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003228 struct intel_engine_cs *engine;
Tvrtko Ursulinc1bb1142016-08-10 16:22:10 +01003229 int num_rings = INTEL_INFO(dev)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003230 enum intel_engine_id id;
3231 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003232
Chris Wilson39df9192016-07-20 13:31:57 +01003233 if (!i915.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003234 seq_puts(m, "Semaphores are disabled\n");
3235 return 0;
3236 }
3237
3238 ret = mutex_lock_interruptible(&dev->struct_mutex);
3239 if (ret)
3240 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003241 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003242
3243 if (IS_BROADWELL(dev)) {
3244 struct page *page;
3245 uint64_t *seqno;
3246
3247 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3248
3249 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003250 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003251 uint64_t offset;
3252
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003253 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003254
3255 seq_puts(m, " Last signal:");
3256 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003257 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003258 seq_printf(m, "0x%08llx (0x%02llx) ",
3259 seqno[offset], offset * 8);
3260 }
3261 seq_putc(m, '\n');
3262
3263 seq_puts(m, " Last wait: ");
3264 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003265 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003266 seq_printf(m, "0x%08llx (0x%02llx) ",
3267 seqno[offset], offset * 8);
3268 }
3269 seq_putc(m, '\n');
3270
3271 }
3272 kunmap_atomic(seqno);
3273 } else {
3274 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003275 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003276 for (j = 0; j < num_rings; j++)
3277 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003278 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003279 seq_putc(m, '\n');
3280 }
3281
3282 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003283 for_each_engine(engine, dev_priv) {
3284 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003285 seq_printf(m, " 0x%08x ",
3286 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003287 seq_putc(m, '\n');
3288 }
3289 seq_putc(m, '\n');
3290
Paulo Zanoni03872062014-07-09 14:31:57 -03003291 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003292 mutex_unlock(&dev->struct_mutex);
3293 return 0;
3294}
3295
Daniel Vetter728e29d2014-06-25 22:01:53 +03003296static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3297{
3298 struct drm_info_node *node = (struct drm_info_node *) m->private;
3299 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003300 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003301 int i;
3302
3303 drm_modeset_lock_all(dev);
3304 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3305 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3306
3307 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003308 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3309 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003310 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003311 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3312 seq_printf(m, " dpll_md: 0x%08x\n",
3313 pll->config.hw_state.dpll_md);
3314 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3315 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3316 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003317 }
3318 drm_modeset_unlock_all(dev);
3319
3320 return 0;
3321}
3322
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003323static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003324{
3325 int i;
3326 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003327 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003328 struct drm_info_node *node = (struct drm_info_node *) m->private;
3329 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003330 struct drm_i915_private *dev_priv = to_i915(dev);
Arun Siluvery33136b02016-01-21 21:43:47 +00003331 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003332 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003333
Arun Siluvery888b5992014-08-26 14:44:51 +01003334 ret = mutex_lock_interruptible(&dev->struct_mutex);
3335 if (ret)
3336 return ret;
3337
3338 intel_runtime_pm_get(dev_priv);
3339
Arun Siluvery33136b02016-01-21 21:43:47 +00003340 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003341 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003342 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003343 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003344 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003345 i915_reg_t addr;
3346 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003347 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003348
Arun Siluvery33136b02016-01-21 21:43:47 +00003349 addr = workarounds->reg[i].addr;
3350 mask = workarounds->reg[i].mask;
3351 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003352 read = I915_READ(addr);
3353 ok = (value & mask) == (read & mask);
3354 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003355 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003356 }
3357
3358 intel_runtime_pm_put(dev_priv);
3359 mutex_unlock(&dev->struct_mutex);
3360
3361 return 0;
3362}
3363
Damien Lespiauc5511e42014-11-04 17:06:51 +00003364static int i915_ddb_info(struct seq_file *m, void *unused)
3365{
3366 struct drm_info_node *node = m->private;
3367 struct drm_device *dev = node->minor->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003368 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiauc5511e42014-11-04 17:06:51 +00003369 struct skl_ddb_allocation *ddb;
3370 struct skl_ddb_entry *entry;
3371 enum pipe pipe;
3372 int plane;
3373
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003374 if (INTEL_INFO(dev)->gen < 9)
3375 return 0;
3376
Damien Lespiauc5511e42014-11-04 17:06:51 +00003377 drm_modeset_lock_all(dev);
3378
3379 ddb = &dev_priv->wm.skl_hw.ddb;
3380
3381 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3382
3383 for_each_pipe(dev_priv, pipe) {
3384 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3385
Damien Lespiaudd740782015-02-28 14:54:08 +00003386 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003387 entry = &ddb->plane[pipe][plane];
3388 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3389 entry->start, entry->end,
3390 skl_ddb_entry_size(entry));
3391 }
3392
Matt Roper4969d332015-09-24 15:53:10 -07003393 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003394 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3395 entry->end, skl_ddb_entry_size(entry));
3396 }
3397
3398 drm_modeset_unlock_all(dev);
3399
3400 return 0;
3401}
3402
Vandana Kannana54746e2015-03-03 20:53:10 +05303403static void drrs_status_per_crtc(struct seq_file *m,
3404 struct drm_device *dev, struct intel_crtc *intel_crtc)
3405{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003406 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303407 struct i915_drrs *drrs = &dev_priv->drrs;
3408 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003409 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303410
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003411 drm_for_each_connector(connector, dev) {
3412 if (connector->state->crtc != &intel_crtc->base)
3413 continue;
3414
3415 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303416 }
3417
3418 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3419 seq_puts(m, "\tVBT: DRRS_type: Static");
3420 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3421 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3422 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3423 seq_puts(m, "\tVBT: DRRS_type: None");
3424 else
3425 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3426
3427 seq_puts(m, "\n\n");
3428
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003429 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303430 struct intel_panel *panel;
3431
3432 mutex_lock(&drrs->mutex);
3433 /* DRRS Supported */
3434 seq_puts(m, "\tDRRS Supported: Yes\n");
3435
3436 /* disable_drrs() will make drrs->dp NULL */
3437 if (!drrs->dp) {
3438 seq_puts(m, "Idleness DRRS: Disabled");
3439 mutex_unlock(&drrs->mutex);
3440 return;
3441 }
3442
3443 panel = &drrs->dp->attached_connector->panel;
3444 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3445 drrs->busy_frontbuffer_bits);
3446
3447 seq_puts(m, "\n\t\t");
3448 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3449 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3450 vrefresh = panel->fixed_mode->vrefresh;
3451 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3452 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3453 vrefresh = panel->downclock_mode->vrefresh;
3454 } else {
3455 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3456 drrs->refresh_rate_type);
3457 mutex_unlock(&drrs->mutex);
3458 return;
3459 }
3460 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3461
3462 seq_puts(m, "\n\t\t");
3463 mutex_unlock(&drrs->mutex);
3464 } else {
3465 /* DRRS not supported. Print the VBT parameter*/
3466 seq_puts(m, "\tDRRS Supported : No");
3467 }
3468 seq_puts(m, "\n");
3469}
3470
3471static int i915_drrs_status(struct seq_file *m, void *unused)
3472{
3473 struct drm_info_node *node = m->private;
3474 struct drm_device *dev = node->minor->dev;
3475 struct intel_crtc *intel_crtc;
3476 int active_crtc_cnt = 0;
3477
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003478 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303479 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003480 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303481 active_crtc_cnt++;
3482 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3483
3484 drrs_status_per_crtc(m, dev, intel_crtc);
3485 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303486 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003487 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303488
3489 if (!active_crtc_cnt)
3490 seq_puts(m, "No active crtc found\n");
3491
3492 return 0;
3493}
3494
Damien Lespiau07144422013-10-15 18:55:40 +01003495struct pipe_crc_info {
3496 const char *name;
3497 struct drm_device *dev;
3498 enum pipe pipe;
3499};
3500
Dave Airlie11bed952014-05-12 15:22:27 +10003501static int i915_dp_mst_info(struct seq_file *m, void *unused)
3502{
3503 struct drm_info_node *node = (struct drm_info_node *) m->private;
3504 struct drm_device *dev = node->minor->dev;
Dave Airlie11bed952014-05-12 15:22:27 +10003505 struct intel_encoder *intel_encoder;
3506 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003507 struct drm_connector *connector;
3508
Dave Airlie11bed952014-05-12 15:22:27 +10003509 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003510 drm_for_each_connector(connector, dev) {
3511 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003512 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003513
3514 intel_encoder = intel_attached_encoder(connector);
3515 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3516 continue;
3517
3518 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003519 if (!intel_dig_port->dp.can_mst)
3520 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003521
Jim Bride40ae80c2016-04-14 10:18:37 -07003522 seq_printf(m, "MST Source Port %c\n",
3523 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003524 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3525 }
3526 drm_modeset_unlock_all(dev);
3527 return 0;
3528}
3529
Damien Lespiau07144422013-10-15 18:55:40 +01003530static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003531{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003532 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003533 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003534 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3535
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003536 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3537 return -ENODEV;
3538
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003539 spin_lock_irq(&pipe_crc->lock);
3540
3541 if (pipe_crc->opened) {
3542 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003543 return -EBUSY; /* already open */
3544 }
3545
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003546 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003547 filep->private_data = inode->i_private;
3548
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003549 spin_unlock_irq(&pipe_crc->lock);
3550
Damien Lespiau07144422013-10-15 18:55:40 +01003551 return 0;
3552}
3553
3554static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3555{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003556 struct pipe_crc_info *info = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003557 struct drm_i915_private *dev_priv = to_i915(info->dev);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003558 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3559
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003560 spin_lock_irq(&pipe_crc->lock);
3561 pipe_crc->opened = false;
3562 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003563
Damien Lespiau07144422013-10-15 18:55:40 +01003564 return 0;
3565}
3566
3567/* (6 fields, 8 chars each, space separated (5) + '\n') */
3568#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3569/* account for \'0' */
3570#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3571
3572static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3573{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003574 assert_spin_locked(&pipe_crc->lock);
3575 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3576 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003577}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003578
Damien Lespiau07144422013-10-15 18:55:40 +01003579static ssize_t
3580i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3581 loff_t *pos)
3582{
3583 struct pipe_crc_info *info = filep->private_data;
3584 struct drm_device *dev = info->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003585 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau07144422013-10-15 18:55:40 +01003586 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3587 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003588 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003589 ssize_t bytes_read;
3590
3591 /*
3592 * Don't allow user space to provide buffers not big enough to hold
3593 * a line of data.
3594 */
3595 if (count < PIPE_CRC_LINE_LEN)
3596 return -EINVAL;
3597
3598 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3599 return 0;
3600
3601 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003602 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003603 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003604 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003605
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003606 if (filep->f_flags & O_NONBLOCK) {
3607 spin_unlock_irq(&pipe_crc->lock);
3608 return -EAGAIN;
3609 }
3610
3611 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3612 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3613 if (ret) {
3614 spin_unlock_irq(&pipe_crc->lock);
3615 return ret;
3616 }
Damien Lespiau07144422013-10-15 18:55:40 +01003617 }
3618
3619 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003620 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003621
Damien Lespiau07144422013-10-15 18:55:40 +01003622 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003623 while (n_entries > 0) {
3624 struct intel_pipe_crc_entry *entry =
3625 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003626
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003627 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3628 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3629 break;
3630
3631 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3632 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3633
Damien Lespiau07144422013-10-15 18:55:40 +01003634 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3635 "%8u %8x %8x %8x %8x %8x\n",
3636 entry->frame, entry->crc[0],
3637 entry->crc[1], entry->crc[2],
3638 entry->crc[3], entry->crc[4]);
3639
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003640 spin_unlock_irq(&pipe_crc->lock);
3641
Rodrigo Vivi4e9121e2016-08-03 08:22:57 -07003642 if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
Damien Lespiau07144422013-10-15 18:55:40 +01003643 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003644
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003645 user_buf += PIPE_CRC_LINE_LEN;
3646 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003647
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003648 spin_lock_irq(&pipe_crc->lock);
3649 }
3650
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003651 spin_unlock_irq(&pipe_crc->lock);
3652
Damien Lespiau07144422013-10-15 18:55:40 +01003653 return bytes_read;
3654}
3655
3656static const struct file_operations i915_pipe_crc_fops = {
3657 .owner = THIS_MODULE,
3658 .open = i915_pipe_crc_open,
3659 .read = i915_pipe_crc_read,
3660 .release = i915_pipe_crc_release,
3661};
3662
3663static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3664 {
3665 .name = "i915_pipe_A_crc",
3666 .pipe = PIPE_A,
3667 },
3668 {
3669 .name = "i915_pipe_B_crc",
3670 .pipe = PIPE_B,
3671 },
3672 {
3673 .name = "i915_pipe_C_crc",
3674 .pipe = PIPE_C,
3675 },
3676};
3677
3678static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3679 enum pipe pipe)
3680{
3681 struct drm_device *dev = minor->dev;
3682 struct dentry *ent;
3683 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3684
3685 info->dev = dev;
3686 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3687 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003688 if (!ent)
3689 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003690
3691 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003692}
3693
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003694static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003695 "none",
3696 "plane1",
3697 "plane2",
3698 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003699 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003700 "TV",
3701 "DP-B",
3702 "DP-C",
3703 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003704 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003705};
3706
3707static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3708{
3709 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3710 return pipe_crc_sources[source];
3711}
3712
Damien Lespiaubd9db022013-10-15 18:55:36 +01003713static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003714{
3715 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003716 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003717 int i;
3718
3719 for (i = 0; i < I915_MAX_PIPES; i++)
3720 seq_printf(m, "%c %s\n", pipe_name(i),
3721 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3722
3723 return 0;
3724}
3725
Damien Lespiaubd9db022013-10-15 18:55:36 +01003726static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003727{
3728 struct drm_device *dev = inode->i_private;
3729
Damien Lespiaubd9db022013-10-15 18:55:36 +01003730 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003731}
3732
Daniel Vetter46a19182013-11-01 10:50:20 +01003733static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003734 uint32_t *val)
3735{
Daniel Vetter46a19182013-11-01 10:50:20 +01003736 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3737 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3738
3739 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003740 case INTEL_PIPE_CRC_SOURCE_PIPE:
3741 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3742 break;
3743 case INTEL_PIPE_CRC_SOURCE_NONE:
3744 *val = 0;
3745 break;
3746 default:
3747 return -EINVAL;
3748 }
3749
3750 return 0;
3751}
3752
Daniel Vetter46a19182013-11-01 10:50:20 +01003753static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3754 enum intel_pipe_crc_source *source)
3755{
3756 struct intel_encoder *encoder;
3757 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003758 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003759 int ret = 0;
3760
3761 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3762
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003763 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003764 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003765 if (!encoder->base.crtc)
3766 continue;
3767
3768 crtc = to_intel_crtc(encoder->base.crtc);
3769
3770 if (crtc->pipe != pipe)
3771 continue;
3772
3773 switch (encoder->type) {
3774 case INTEL_OUTPUT_TVOUT:
3775 *source = INTEL_PIPE_CRC_SOURCE_TV;
3776 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +03003777 case INTEL_OUTPUT_DP:
Daniel Vetter46a19182013-11-01 10:50:20 +01003778 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003779 dig_port = enc_to_dig_port(&encoder->base);
3780 switch (dig_port->port) {
3781 case PORT_B:
3782 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3783 break;
3784 case PORT_C:
3785 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3786 break;
3787 case PORT_D:
3788 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3789 break;
3790 default:
3791 WARN(1, "nonexisting DP port %c\n",
3792 port_name(dig_port->port));
3793 break;
3794 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003795 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003796 default:
3797 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003798 }
3799 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003800 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003801
3802 return ret;
3803}
3804
3805static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3806 enum pipe pipe,
3807 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003808 uint32_t *val)
3809{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003810 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003811 bool need_stable_symbols = false;
3812
Daniel Vetter46a19182013-11-01 10:50:20 +01003813 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3814 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3815 if (ret)
3816 return ret;
3817 }
3818
3819 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003820 case INTEL_PIPE_CRC_SOURCE_PIPE:
3821 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3822 break;
3823 case INTEL_PIPE_CRC_SOURCE_DP_B:
3824 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003825 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003826 break;
3827 case INTEL_PIPE_CRC_SOURCE_DP_C:
3828 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003829 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003830 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003831 case INTEL_PIPE_CRC_SOURCE_DP_D:
3832 if (!IS_CHERRYVIEW(dev))
3833 return -EINVAL;
3834 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3835 need_stable_symbols = true;
3836 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003837 case INTEL_PIPE_CRC_SOURCE_NONE:
3838 *val = 0;
3839 break;
3840 default:
3841 return -EINVAL;
3842 }
3843
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003844 /*
3845 * When the pipe CRC tap point is after the transcoders we need
3846 * to tweak symbol-level features to produce a deterministic series of
3847 * symbols for a given frame. We need to reset those features only once
3848 * a frame (instead of every nth symbol):
3849 * - DC-balance: used to ensure a better clock recovery from the data
3850 * link (SDVO)
3851 * - DisplayPort scrambling: used for EMI reduction
3852 */
3853 if (need_stable_symbols) {
3854 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3855
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003856 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003857 switch (pipe) {
3858 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003859 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003860 break;
3861 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003862 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003863 break;
3864 case PIPE_C:
3865 tmp |= PIPE_C_SCRAMBLE_RESET;
3866 break;
3867 default:
3868 return -EINVAL;
3869 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003870 I915_WRITE(PORT_DFT2_G4X, tmp);
3871 }
3872
Daniel Vetter7ac01292013-10-18 16:37:06 +02003873 return 0;
3874}
3875
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003876static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003877 enum pipe pipe,
3878 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003879 uint32_t *val)
3880{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003881 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003882 bool need_stable_symbols = false;
3883
Daniel Vetter46a19182013-11-01 10:50:20 +01003884 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3885 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3886 if (ret)
3887 return ret;
3888 }
3889
3890 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003891 case INTEL_PIPE_CRC_SOURCE_PIPE:
3892 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3893 break;
3894 case INTEL_PIPE_CRC_SOURCE_TV:
3895 if (!SUPPORTS_TV(dev))
3896 return -EINVAL;
3897 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3898 break;
3899 case INTEL_PIPE_CRC_SOURCE_DP_B:
3900 if (!IS_G4X(dev))
3901 return -EINVAL;
3902 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003903 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003904 break;
3905 case INTEL_PIPE_CRC_SOURCE_DP_C:
3906 if (!IS_G4X(dev))
3907 return -EINVAL;
3908 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003909 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003910 break;
3911 case INTEL_PIPE_CRC_SOURCE_DP_D:
3912 if (!IS_G4X(dev))
3913 return -EINVAL;
3914 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003915 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003916 break;
3917 case INTEL_PIPE_CRC_SOURCE_NONE:
3918 *val = 0;
3919 break;
3920 default:
3921 return -EINVAL;
3922 }
3923
Daniel Vetter84093602013-11-01 10:50:21 +01003924 /*
3925 * When the pipe CRC tap point is after the transcoders we need
3926 * to tweak symbol-level features to produce a deterministic series of
3927 * symbols for a given frame. We need to reset those features only once
3928 * a frame (instead of every nth symbol):
3929 * - DC-balance: used to ensure a better clock recovery from the data
3930 * link (SDVO)
3931 * - DisplayPort scrambling: used for EMI reduction
3932 */
3933 if (need_stable_symbols) {
3934 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3935
3936 WARN_ON(!IS_G4X(dev));
3937
3938 I915_WRITE(PORT_DFT_I9XX,
3939 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3940
3941 if (pipe == PIPE_A)
3942 tmp |= PIPE_A_SCRAMBLE_RESET;
3943 else
3944 tmp |= PIPE_B_SCRAMBLE_RESET;
3945
3946 I915_WRITE(PORT_DFT2_G4X, tmp);
3947 }
3948
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003949 return 0;
3950}
3951
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003952static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3953 enum pipe pipe)
3954{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003955 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003956 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3957
Ville Syrjäläeb736672014-12-09 21:28:28 +02003958 switch (pipe) {
3959 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003960 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003961 break;
3962 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003963 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003964 break;
3965 case PIPE_C:
3966 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3967 break;
3968 default:
3969 return;
3970 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003971 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3972 tmp &= ~DC_BALANCE_RESET_VLV;
3973 I915_WRITE(PORT_DFT2_G4X, tmp);
3974
3975}
3976
Daniel Vetter84093602013-11-01 10:50:21 +01003977static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3978 enum pipe pipe)
3979{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003980 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter84093602013-11-01 10:50:21 +01003981 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3982
3983 if (pipe == PIPE_A)
3984 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3985 else
3986 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3987 I915_WRITE(PORT_DFT2_G4X, tmp);
3988
3989 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3990 I915_WRITE(PORT_DFT_I9XX,
3991 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3992 }
3993}
3994
Daniel Vetter46a19182013-11-01 10:50:20 +01003995static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003996 uint32_t *val)
3997{
Daniel Vetter46a19182013-11-01 10:50:20 +01003998 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3999 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
4000
4001 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004002 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4003 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4004 break;
4005 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4006 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4007 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004008 case INTEL_PIPE_CRC_SOURCE_PIPE:
4009 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4010 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004011 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004012 *val = 0;
4013 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004014 default:
4015 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004016 }
4017
4018 return 0;
4019}
4020
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004021static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004022{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004023 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004024 struct intel_crtc *crtc =
4025 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004026 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004027 struct drm_atomic_state *state;
4028 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004029
4030 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004031 state = drm_atomic_state_alloc(dev);
4032 if (!state) {
4033 ret = -ENOMEM;
4034 goto out;
4035 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004036
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004037 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4038 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4039 if (IS_ERR(pipe_config)) {
4040 ret = PTR_ERR(pipe_config);
4041 goto out;
4042 }
4043
4044 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004045 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004046 pipe_config->pch_pfit.enabled != enable)
4047 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004048
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004049 ret = drm_atomic_commit(state);
4050out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004051 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004052 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4053 if (ret)
4054 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004055}
4056
4057static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4058 enum pipe pipe,
4059 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004060 uint32_t *val)
4061{
Daniel Vetter46a19182013-11-01 10:50:20 +01004062 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4063 *source = INTEL_PIPE_CRC_SOURCE_PF;
4064
4065 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004066 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4067 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4068 break;
4069 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4070 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4071 break;
4072 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004073 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004074 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004075
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004076 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4077 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004078 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004079 *val = 0;
4080 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004081 default:
4082 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004083 }
4084
4085 return 0;
4086}
4087
Daniel Vetter926321d2013-10-16 13:30:34 +02004088static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4089 enum intel_pipe_crc_source source)
4090{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004091 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaucc3da172013-10-15 18:55:31 +01004092 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004093 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4094 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004095 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004096 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004097 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004098
Damien Lespiaucc3da172013-10-15 18:55:31 +01004099 if (pipe_crc->source == source)
4100 return 0;
4101
Damien Lespiauae676fc2013-10-15 18:55:32 +01004102 /* forbid changing the source without going back to 'none' */
4103 if (pipe_crc->source && source)
4104 return -EINVAL;
4105
Imre Deake1296492016-02-12 18:55:17 +02004106 power_domain = POWER_DOMAIN_PIPE(pipe);
4107 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004108 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4109 return -EIO;
4110 }
4111
Daniel Vetter52f843f2013-10-21 17:26:38 +02004112 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004113 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004114 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004115 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004116 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004117 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004118 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004119 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004120 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004121 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004122
4123 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004124 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004125
Damien Lespiau4b584362013-10-15 18:55:33 +01004126 /* none -> real source transition */
4127 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004128 struct intel_pipe_crc_entry *entries;
4129
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004130 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4131 pipe_name(pipe), pipe_crc_source_name(source));
4132
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004133 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4134 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004135 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004136 if (!entries) {
4137 ret = -ENOMEM;
4138 goto out;
4139 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004140
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004141 /*
4142 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4143 * enabled and disabled dynamically based on package C states,
4144 * user space can't make reliable use of the CRCs, so let's just
4145 * completely disable it.
4146 */
4147 hsw_disable_ips(crtc);
4148
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004149 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004150 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004151 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004152 pipe_crc->head = 0;
4153 pipe_crc->tail = 0;
4154 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004155 }
4156
Damien Lespiaucc3da172013-10-15 18:55:31 +01004157 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004158
Daniel Vetter926321d2013-10-16 13:30:34 +02004159 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4160 POSTING_READ(PIPE_CRC_CTL(pipe));
4161
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004162 /* real source -> none transition */
4163 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004164 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004165 struct intel_crtc *crtc =
4166 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004167
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004168 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4169 pipe_name(pipe));
4170
Daniel Vettera33d7102014-06-06 08:22:08 +02004171 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004172 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004173 intel_wait_for_vblank(dev, pipe);
4174 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004175
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004176 spin_lock_irq(&pipe_crc->lock);
4177 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004178 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004179 pipe_crc->head = 0;
4180 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004181 spin_unlock_irq(&pipe_crc->lock);
4182
4183 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004184
4185 if (IS_G4X(dev))
4186 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004187 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004188 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004189 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004190 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004191
4192 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004193 }
4194
Imre Deake1296492016-02-12 18:55:17 +02004195 ret = 0;
4196
4197out:
4198 intel_display_power_put(dev_priv, power_domain);
4199
4200 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004201}
4202
4203/*
4204 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004205 * command: wsp* object wsp+ name wsp+ source wsp*
4206 * object: 'pipe'
4207 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004208 * source: (none | plane1 | plane2 | pf)
4209 * wsp: (#0x20 | #0x9 | #0xA)+
4210 *
4211 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004212 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4213 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004214 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004215static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004216{
4217 int n_words = 0;
4218
4219 while (*buf) {
4220 char *end;
4221
4222 /* skip leading white space */
4223 buf = skip_spaces(buf);
4224 if (!*buf)
4225 break; /* end of buffer */
4226
4227 /* find end of word */
4228 for (end = buf; *end && !isspace(*end); end++)
4229 ;
4230
4231 if (n_words == max_words) {
4232 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4233 max_words);
4234 return -EINVAL; /* ran out of words[] before bytes */
4235 }
4236
4237 if (*end)
4238 *end++ = '\0';
4239 words[n_words++] = buf;
4240 buf = end;
4241 }
4242
4243 return n_words;
4244}
4245
Damien Lespiaub94dec82013-10-15 18:55:35 +01004246enum intel_pipe_crc_object {
4247 PIPE_CRC_OBJECT_PIPE,
4248};
4249
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004250static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004251 "pipe",
4252};
4253
4254static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004255display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004256{
4257 int i;
4258
4259 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4260 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004261 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004262 return 0;
4263 }
4264
4265 return -EINVAL;
4266}
4267
Damien Lespiaubd9db022013-10-15 18:55:36 +01004268static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004269{
4270 const char name = buf[0];
4271
4272 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4273 return -EINVAL;
4274
4275 *pipe = name - 'A';
4276
4277 return 0;
4278}
4279
4280static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004281display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004282{
4283 int i;
4284
4285 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4286 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004287 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004288 return 0;
4289 }
4290
4291 return -EINVAL;
4292}
4293
Damien Lespiaubd9db022013-10-15 18:55:36 +01004294static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004295{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004296#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004297 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004298 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004299 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004300 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004301 enum intel_pipe_crc_source source;
4302
Damien Lespiaubd9db022013-10-15 18:55:36 +01004303 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004304 if (n_words != N_WORDS) {
4305 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4306 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004307 return -EINVAL;
4308 }
4309
Damien Lespiaubd9db022013-10-15 18:55:36 +01004310 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004311 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004312 return -EINVAL;
4313 }
4314
Damien Lespiaubd9db022013-10-15 18:55:36 +01004315 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004316 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4317 return -EINVAL;
4318 }
4319
Damien Lespiaubd9db022013-10-15 18:55:36 +01004320 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004321 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004322 return -EINVAL;
4323 }
4324
4325 return pipe_crc_set_source(dev, pipe, source);
4326}
4327
Damien Lespiaubd9db022013-10-15 18:55:36 +01004328static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4329 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004330{
4331 struct seq_file *m = file->private_data;
4332 struct drm_device *dev = m->private;
4333 char *tmpbuf;
4334 int ret;
4335
4336 if (len == 0)
4337 return 0;
4338
4339 if (len > PAGE_SIZE - 1) {
4340 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4341 PAGE_SIZE);
4342 return -E2BIG;
4343 }
4344
4345 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4346 if (!tmpbuf)
4347 return -ENOMEM;
4348
4349 if (copy_from_user(tmpbuf, ubuf, len)) {
4350 ret = -EFAULT;
4351 goto out;
4352 }
4353 tmpbuf[len] = '\0';
4354
Damien Lespiaubd9db022013-10-15 18:55:36 +01004355 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004356
4357out:
4358 kfree(tmpbuf);
4359 if (ret < 0)
4360 return ret;
4361
4362 *offp += len;
4363 return len;
4364}
4365
Damien Lespiaubd9db022013-10-15 18:55:36 +01004366static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004367 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004368 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004369 .read = seq_read,
4370 .llseek = seq_lseek,
4371 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004372 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004373};
4374
Todd Previteeb3394fa2015-04-18 00:04:19 -07004375static ssize_t i915_displayport_test_active_write(struct file *file,
4376 const char __user *ubuf,
4377 size_t len, loff_t *offp)
4378{
4379 char *input_buffer;
4380 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004381 struct drm_device *dev;
4382 struct drm_connector *connector;
4383 struct list_head *connector_list;
4384 struct intel_dp *intel_dp;
4385 int val = 0;
4386
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304387 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004388
Todd Previteeb3394fa2015-04-18 00:04:19 -07004389 connector_list = &dev->mode_config.connector_list;
4390
4391 if (len == 0)
4392 return 0;
4393
4394 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4395 if (!input_buffer)
4396 return -ENOMEM;
4397
4398 if (copy_from_user(input_buffer, ubuf, len)) {
4399 status = -EFAULT;
4400 goto out;
4401 }
4402
4403 input_buffer[len] = '\0';
4404 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4405
4406 list_for_each_entry(connector, connector_list, head) {
4407
4408 if (connector->connector_type !=
4409 DRM_MODE_CONNECTOR_DisplayPort)
4410 continue;
4411
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304412 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004413 connector->encoder != NULL) {
4414 intel_dp = enc_to_intel_dp(connector->encoder);
4415 status = kstrtoint(input_buffer, 10, &val);
4416 if (status < 0)
4417 goto out;
4418 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4419 /* To prevent erroneous activation of the compliance
4420 * testing code, only accept an actual value of 1 here
4421 */
4422 if (val == 1)
4423 intel_dp->compliance_test_active = 1;
4424 else
4425 intel_dp->compliance_test_active = 0;
4426 }
4427 }
4428out:
4429 kfree(input_buffer);
4430 if (status < 0)
4431 return status;
4432
4433 *offp += len;
4434 return len;
4435}
4436
4437static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4438{
4439 struct drm_device *dev = m->private;
4440 struct drm_connector *connector;
4441 struct list_head *connector_list = &dev->mode_config.connector_list;
4442 struct intel_dp *intel_dp;
4443
Todd Previteeb3394fa2015-04-18 00:04:19 -07004444 list_for_each_entry(connector, connector_list, head) {
4445
4446 if (connector->connector_type !=
4447 DRM_MODE_CONNECTOR_DisplayPort)
4448 continue;
4449
4450 if (connector->status == connector_status_connected &&
4451 connector->encoder != NULL) {
4452 intel_dp = enc_to_intel_dp(connector->encoder);
4453 if (intel_dp->compliance_test_active)
4454 seq_puts(m, "1");
4455 else
4456 seq_puts(m, "0");
4457 } else
4458 seq_puts(m, "0");
4459 }
4460
4461 return 0;
4462}
4463
4464static int i915_displayport_test_active_open(struct inode *inode,
4465 struct file *file)
4466{
4467 struct drm_device *dev = inode->i_private;
4468
4469 return single_open(file, i915_displayport_test_active_show, dev);
4470}
4471
4472static const struct file_operations i915_displayport_test_active_fops = {
4473 .owner = THIS_MODULE,
4474 .open = i915_displayport_test_active_open,
4475 .read = seq_read,
4476 .llseek = seq_lseek,
4477 .release = single_release,
4478 .write = i915_displayport_test_active_write
4479};
4480
4481static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4482{
4483 struct drm_device *dev = m->private;
4484 struct drm_connector *connector;
4485 struct list_head *connector_list = &dev->mode_config.connector_list;
4486 struct intel_dp *intel_dp;
4487
Todd Previteeb3394fa2015-04-18 00:04:19 -07004488 list_for_each_entry(connector, connector_list, head) {
4489
4490 if (connector->connector_type !=
4491 DRM_MODE_CONNECTOR_DisplayPort)
4492 continue;
4493
4494 if (connector->status == connector_status_connected &&
4495 connector->encoder != NULL) {
4496 intel_dp = enc_to_intel_dp(connector->encoder);
4497 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4498 } else
4499 seq_puts(m, "0");
4500 }
4501
4502 return 0;
4503}
4504static int i915_displayport_test_data_open(struct inode *inode,
4505 struct file *file)
4506{
4507 struct drm_device *dev = inode->i_private;
4508
4509 return single_open(file, i915_displayport_test_data_show, dev);
4510}
4511
4512static const struct file_operations i915_displayport_test_data_fops = {
4513 .owner = THIS_MODULE,
4514 .open = i915_displayport_test_data_open,
4515 .read = seq_read,
4516 .llseek = seq_lseek,
4517 .release = single_release
4518};
4519
4520static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4521{
4522 struct drm_device *dev = m->private;
4523 struct drm_connector *connector;
4524 struct list_head *connector_list = &dev->mode_config.connector_list;
4525 struct intel_dp *intel_dp;
4526
Todd Previteeb3394fa2015-04-18 00:04:19 -07004527 list_for_each_entry(connector, connector_list, head) {
4528
4529 if (connector->connector_type !=
4530 DRM_MODE_CONNECTOR_DisplayPort)
4531 continue;
4532
4533 if (connector->status == connector_status_connected &&
4534 connector->encoder != NULL) {
4535 intel_dp = enc_to_intel_dp(connector->encoder);
4536 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4537 } else
4538 seq_puts(m, "0");
4539 }
4540
4541 return 0;
4542}
4543
4544static int i915_displayport_test_type_open(struct inode *inode,
4545 struct file *file)
4546{
4547 struct drm_device *dev = inode->i_private;
4548
4549 return single_open(file, i915_displayport_test_type_show, dev);
4550}
4551
4552static const struct file_operations i915_displayport_test_type_fops = {
4553 .owner = THIS_MODULE,
4554 .open = i915_displayport_test_type_open,
4555 .read = seq_read,
4556 .llseek = seq_lseek,
4557 .release = single_release
4558};
4559
Damien Lespiau97e94b22014-11-04 17:06:50 +00004560static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004561{
4562 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004563 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004564 int num_levels;
4565
4566 if (IS_CHERRYVIEW(dev))
4567 num_levels = 3;
4568 else if (IS_VALLEYVIEW(dev))
4569 num_levels = 1;
4570 else
4571 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004572
4573 drm_modeset_lock_all(dev);
4574
4575 for (level = 0; level < num_levels; level++) {
4576 unsigned int latency = wm[level];
4577
Damien Lespiau97e94b22014-11-04 17:06:50 +00004578 /*
4579 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004580 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004581 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004582 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4583 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004584 latency *= 10;
4585 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004586 latency *= 5;
4587
4588 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004589 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004590 }
4591
4592 drm_modeset_unlock_all(dev);
4593}
4594
4595static int pri_wm_latency_show(struct seq_file *m, void *data)
4596{
4597 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004598 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004599 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004600
Damien Lespiau97e94b22014-11-04 17:06:50 +00004601 if (INTEL_INFO(dev)->gen >= 9)
4602 latencies = dev_priv->wm.skl_latency;
4603 else
4604 latencies = to_i915(dev)->wm.pri_latency;
4605
4606 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004607
4608 return 0;
4609}
4610
4611static int spr_wm_latency_show(struct seq_file *m, void *data)
4612{
4613 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004614 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004615 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004616
Damien Lespiau97e94b22014-11-04 17:06:50 +00004617 if (INTEL_INFO(dev)->gen >= 9)
4618 latencies = dev_priv->wm.skl_latency;
4619 else
4620 latencies = to_i915(dev)->wm.spr_latency;
4621
4622 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004623
4624 return 0;
4625}
4626
4627static int cur_wm_latency_show(struct seq_file *m, void *data)
4628{
4629 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004630 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004631 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004632
Damien Lespiau97e94b22014-11-04 17:06:50 +00004633 if (INTEL_INFO(dev)->gen >= 9)
4634 latencies = dev_priv->wm.skl_latency;
4635 else
4636 latencies = to_i915(dev)->wm.cur_latency;
4637
4638 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004639
4640 return 0;
4641}
4642
4643static int pri_wm_latency_open(struct inode *inode, struct file *file)
4644{
4645 struct drm_device *dev = inode->i_private;
4646
Ville Syrjäläde38b952015-06-24 22:00:09 +03004647 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004648 return -ENODEV;
4649
4650 return single_open(file, pri_wm_latency_show, dev);
4651}
4652
4653static int spr_wm_latency_open(struct inode *inode, struct file *file)
4654{
4655 struct drm_device *dev = inode->i_private;
4656
Sonika Jindal9ad02572014-07-21 15:23:39 +05304657 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004658 return -ENODEV;
4659
4660 return single_open(file, spr_wm_latency_show, dev);
4661}
4662
4663static int cur_wm_latency_open(struct inode *inode, struct file *file)
4664{
4665 struct drm_device *dev = inode->i_private;
4666
Sonika Jindal9ad02572014-07-21 15:23:39 +05304667 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004668 return -ENODEV;
4669
4670 return single_open(file, cur_wm_latency_show, dev);
4671}
4672
4673static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004674 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004675{
4676 struct seq_file *m = file->private_data;
4677 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004678 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004679 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004680 int level;
4681 int ret;
4682 char tmp[32];
4683
Ville Syrjäläde38b952015-06-24 22:00:09 +03004684 if (IS_CHERRYVIEW(dev))
4685 num_levels = 3;
4686 else if (IS_VALLEYVIEW(dev))
4687 num_levels = 1;
4688 else
4689 num_levels = ilk_wm_max_level(dev) + 1;
4690
Ville Syrjälä369a1342014-01-22 14:36:08 +02004691 if (len >= sizeof(tmp))
4692 return -EINVAL;
4693
4694 if (copy_from_user(tmp, ubuf, len))
4695 return -EFAULT;
4696
4697 tmp[len] = '\0';
4698
Damien Lespiau97e94b22014-11-04 17:06:50 +00004699 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4700 &new[0], &new[1], &new[2], &new[3],
4701 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004702 if (ret != num_levels)
4703 return -EINVAL;
4704
4705 drm_modeset_lock_all(dev);
4706
4707 for (level = 0; level < num_levels; level++)
4708 wm[level] = new[level];
4709
4710 drm_modeset_unlock_all(dev);
4711
4712 return len;
4713}
4714
4715
4716static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4717 size_t len, loff_t *offp)
4718{
4719 struct seq_file *m = file->private_data;
4720 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004721 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004722 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004723
Damien Lespiau97e94b22014-11-04 17:06:50 +00004724 if (INTEL_INFO(dev)->gen >= 9)
4725 latencies = dev_priv->wm.skl_latency;
4726 else
4727 latencies = to_i915(dev)->wm.pri_latency;
4728
4729 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004730}
4731
4732static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4733 size_t len, loff_t *offp)
4734{
4735 struct seq_file *m = file->private_data;
4736 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004737 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004738 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004739
Damien Lespiau97e94b22014-11-04 17:06:50 +00004740 if (INTEL_INFO(dev)->gen >= 9)
4741 latencies = dev_priv->wm.skl_latency;
4742 else
4743 latencies = to_i915(dev)->wm.spr_latency;
4744
4745 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004746}
4747
4748static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4749 size_t len, loff_t *offp)
4750{
4751 struct seq_file *m = file->private_data;
4752 struct drm_device *dev = m->private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004753 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiau97e94b22014-11-04 17:06:50 +00004754 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004755
Damien Lespiau97e94b22014-11-04 17:06:50 +00004756 if (INTEL_INFO(dev)->gen >= 9)
4757 latencies = dev_priv->wm.skl_latency;
4758 else
4759 latencies = to_i915(dev)->wm.cur_latency;
4760
4761 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004762}
4763
4764static const struct file_operations i915_pri_wm_latency_fops = {
4765 .owner = THIS_MODULE,
4766 .open = pri_wm_latency_open,
4767 .read = seq_read,
4768 .llseek = seq_lseek,
4769 .release = single_release,
4770 .write = pri_wm_latency_write
4771};
4772
4773static const struct file_operations i915_spr_wm_latency_fops = {
4774 .owner = THIS_MODULE,
4775 .open = spr_wm_latency_open,
4776 .read = seq_read,
4777 .llseek = seq_lseek,
4778 .release = single_release,
4779 .write = spr_wm_latency_write
4780};
4781
4782static const struct file_operations i915_cur_wm_latency_fops = {
4783 .owner = THIS_MODULE,
4784 .open = cur_wm_latency_open,
4785 .read = seq_read,
4786 .llseek = seq_lseek,
4787 .release = single_release,
4788 .write = cur_wm_latency_write
4789};
4790
Kees Cook647416f2013-03-10 14:10:06 -07004791static int
4792i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004793{
Kees Cook647416f2013-03-10 14:10:06 -07004794 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004795 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004796
Chris Wilsond98c52c2016-04-13 17:35:05 +01004797 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004798
Kees Cook647416f2013-03-10 14:10:06 -07004799 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004800}
4801
Kees Cook647416f2013-03-10 14:10:06 -07004802static int
4803i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004804{
Kees Cook647416f2013-03-10 14:10:06 -07004805 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004806 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakd46c0512014-04-14 20:24:27 +03004807
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004808 /*
4809 * There is no safeguard against this debugfs entry colliding
4810 * with the hangcheck calling same i915_handle_error() in
4811 * parallel, causing an explosion. For now we assume that the
4812 * test harness is responsible enough not to inject gpu hangs
4813 * while it is writing to 'i915_wedged'
4814 */
4815
Chris Wilsond98c52c2016-04-13 17:35:05 +01004816 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004817 return -EAGAIN;
4818
Imre Deakd46c0512014-04-14 20:24:27 +03004819 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004820
Chris Wilsonc0336662016-05-06 15:40:21 +01004821 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004822 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004823
4824 intel_runtime_pm_put(dev_priv);
4825
Kees Cook647416f2013-03-10 14:10:06 -07004826 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004827}
4828
Kees Cook647416f2013-03-10 14:10:06 -07004829DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4830 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004831 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004832
Kees Cook647416f2013-03-10 14:10:06 -07004833static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004834i915_ring_missed_irq_get(void *data, u64 *val)
4835{
4836 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004837 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004838
4839 *val = dev_priv->gpu_error.missed_irq_rings;
4840 return 0;
4841}
4842
4843static int
4844i915_ring_missed_irq_set(void *data, u64 val)
4845{
4846 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004847 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004848 int ret;
4849
4850 /* Lock against concurrent debugfs callers */
4851 ret = mutex_lock_interruptible(&dev->struct_mutex);
4852 if (ret)
4853 return ret;
4854 dev_priv->gpu_error.missed_irq_rings = val;
4855 mutex_unlock(&dev->struct_mutex);
4856
4857 return 0;
4858}
4859
4860DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4861 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4862 "0x%08llx\n");
4863
4864static int
4865i915_ring_test_irq_get(void *data, u64 *val)
4866{
4867 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004868 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004869
4870 *val = dev_priv->gpu_error.test_irq_rings;
4871
4872 return 0;
4873}
4874
4875static int
4876i915_ring_test_irq_set(void *data, u64 val)
4877{
4878 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004879 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson094f9a52013-09-25 17:34:55 +01004880
Chris Wilson3a122c22016-06-17 14:35:05 +01004881 val &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004882 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004883 dev_priv->gpu_error.test_irq_rings = val;
Chris Wilson094f9a52013-09-25 17:34:55 +01004884
4885 return 0;
4886}
4887
4888DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4889 i915_ring_test_irq_get, i915_ring_test_irq_set,
4890 "0x%08llx\n");
4891
Chris Wilsondd624af2013-01-15 12:39:35 +00004892#define DROP_UNBOUND 0x1
4893#define DROP_BOUND 0x2
4894#define DROP_RETIRE 0x4
4895#define DROP_ACTIVE 0x8
4896#define DROP_ALL (DROP_UNBOUND | \
4897 DROP_BOUND | \
4898 DROP_RETIRE | \
4899 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004900static int
4901i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004902{
Kees Cook647416f2013-03-10 14:10:06 -07004903 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004904
Kees Cook647416f2013-03-10 14:10:06 -07004905 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004906}
4907
Kees Cook647416f2013-03-10 14:10:06 -07004908static int
4909i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004910{
Kees Cook647416f2013-03-10 14:10:06 -07004911 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004912 struct drm_i915_private *dev_priv = to_i915(dev);
Kees Cook647416f2013-03-10 14:10:06 -07004913 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004914
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004915 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004916
4917 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4918 * on ioctls on -EAGAIN. */
4919 ret = mutex_lock_interruptible(&dev->struct_mutex);
4920 if (ret)
4921 return ret;
4922
4923 if (val & DROP_ACTIVE) {
Chris Wilsondcff85c2016-08-05 10:14:11 +01004924 ret = i915_gem_wait_for_idle(dev_priv, true);
Chris Wilsondd624af2013-01-15 12:39:35 +00004925 if (ret)
4926 goto unlock;
4927 }
4928
4929 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004930 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004931
Chris Wilson21ab4e72014-09-09 11:16:08 +01004932 if (val & DROP_BOUND)
4933 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004934
Chris Wilson21ab4e72014-09-09 11:16:08 +01004935 if (val & DROP_UNBOUND)
4936 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004937
4938unlock:
4939 mutex_unlock(&dev->struct_mutex);
4940
Kees Cook647416f2013-03-10 14:10:06 -07004941 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004942}
4943
Kees Cook647416f2013-03-10 14:10:06 -07004944DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4945 i915_drop_caches_get, i915_drop_caches_set,
4946 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004947
Kees Cook647416f2013-03-10 14:10:06 -07004948static int
4949i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004950{
Kees Cook647416f2013-03-10 14:10:06 -07004951 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004952 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02004953
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004954 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004955 return -ENODEV;
4956
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004957 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004958 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004959}
4960
Kees Cook647416f2013-03-10 14:10:06 -07004961static int
4962i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004963{
Kees Cook647416f2013-03-10 14:10:06 -07004964 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004965 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05304966 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004967 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004968
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004969 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004970 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004971
Kees Cook647416f2013-03-10 14:10:06 -07004972 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004973
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004974 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004975 if (ret)
4976 return ret;
4977
Jesse Barnes358733e2011-07-27 11:53:01 -07004978 /*
4979 * Turbo will still be enabled, but won't go above the set value.
4980 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304981 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004982
Akash Goelbc4d91f2015-02-26 16:09:47 +05304983 hw_max = dev_priv->rps.max_freq;
4984 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004985
Ben Widawskyb39fb292014-03-19 18:31:11 -07004986 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004987 mutex_unlock(&dev_priv->rps.hw_lock);
4988 return -EINVAL;
4989 }
4990
Ben Widawskyb39fb292014-03-19 18:31:11 -07004991 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004992
Chris Wilsondc979972016-05-10 14:10:04 +01004993 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004994
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004995 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004996
Kees Cook647416f2013-03-10 14:10:06 -07004997 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004998}
4999
Kees Cook647416f2013-03-10 14:10:06 -07005000DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5001 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005002 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005003
Kees Cook647416f2013-03-10 14:10:06 -07005004static int
5005i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005006{
Kees Cook647416f2013-03-10 14:10:06 -07005007 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005008 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter004777c2012-08-09 15:07:01 +02005009
Chris Wilson62e1baa2016-07-13 09:10:36 +01005010 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005011 return -ENODEV;
5012
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005013 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07005014 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005015}
5016
Kees Cook647416f2013-03-10 14:10:06 -07005017static int
5018i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005019{
Kees Cook647416f2013-03-10 14:10:06 -07005020 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005021 struct drm_i915_private *dev_priv = to_i915(dev);
Akash Goelbc4d91f2015-02-26 16:09:47 +05305022 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005023 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005024
Chris Wilson62e1baa2016-07-13 09:10:36 +01005025 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005026 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005027
Kees Cook647416f2013-03-10 14:10:06 -07005028 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005029
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005030 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005031 if (ret)
5032 return ret;
5033
Jesse Barnes1523c312012-05-25 12:34:54 -07005034 /*
5035 * Turbo will still be enabled, but won't go below the set value.
5036 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305037 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005038
Akash Goelbc4d91f2015-02-26 16:09:47 +05305039 hw_max = dev_priv->rps.max_freq;
5040 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005041
Ben Widawskyb39fb292014-03-19 18:31:11 -07005042 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005043 mutex_unlock(&dev_priv->rps.hw_lock);
5044 return -EINVAL;
5045 }
5046
Ben Widawskyb39fb292014-03-19 18:31:11 -07005047 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005048
Chris Wilsondc979972016-05-10 14:10:04 +01005049 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005050
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005051 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005052
Kees Cook647416f2013-03-10 14:10:06 -07005053 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005054}
5055
Kees Cook647416f2013-03-10 14:10:06 -07005056DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5057 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005058 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005059
Kees Cook647416f2013-03-10 14:10:06 -07005060static int
5061i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005062{
Kees Cook647416f2013-03-10 14:10:06 -07005063 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005064 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005065 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005066 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005067
Daniel Vetter004777c2012-08-09 15:07:01 +02005068 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5069 return -ENODEV;
5070
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005071 ret = mutex_lock_interruptible(&dev->struct_mutex);
5072 if (ret)
5073 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005074 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005075
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005076 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005077
5078 intel_runtime_pm_put(dev_priv);
Chris Wilson91c8a322016-07-05 10:40:23 +01005079 mutex_unlock(&dev_priv->drm.struct_mutex);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005080
Kees Cook647416f2013-03-10 14:10:06 -07005081 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005082
Kees Cook647416f2013-03-10 14:10:06 -07005083 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005084}
5085
Kees Cook647416f2013-03-10 14:10:06 -07005086static int
5087i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005088{
Kees Cook647416f2013-03-10 14:10:06 -07005089 struct drm_device *dev = data;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005090 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005091 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005092
Daniel Vetter004777c2012-08-09 15:07:01 +02005093 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5094 return -ENODEV;
5095
Kees Cook647416f2013-03-10 14:10:06 -07005096 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005097 return -EINVAL;
5098
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005099 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005100 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005101
5102 /* Update the cache sharing policy here as well */
5103 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5104 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5105 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5106 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5107
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005108 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005109 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005110}
5111
Kees Cook647416f2013-03-10 14:10:06 -07005112DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5113 i915_cache_sharing_get, i915_cache_sharing_set,
5114 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005115
Jeff McGee5d395252015-04-03 18:13:17 -07005116struct sseu_dev_status {
5117 unsigned int slice_total;
5118 unsigned int subslice_total;
5119 unsigned int subslice_per_slice;
5120 unsigned int eu_total;
5121 unsigned int eu_per_subslice;
5122};
5123
5124static void cherryview_sseu_device_status(struct drm_device *dev,
5125 struct sseu_dev_status *stat)
5126{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005127 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005128 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005129 int ss;
5130 u32 sig1[ss_max], sig2[ss_max];
5131
5132 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5133 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5134 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5135 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5136
5137 for (ss = 0; ss < ss_max; ss++) {
5138 unsigned int eu_cnt;
5139
5140 if (sig1[ss] & CHV_SS_PG_ENABLE)
5141 /* skip disabled subslice */
5142 continue;
5143
5144 stat->slice_total = 1;
5145 stat->subslice_per_slice++;
5146 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5147 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5148 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5149 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5150 stat->eu_total += eu_cnt;
5151 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5152 }
5153 stat->subslice_total = stat->subslice_per_slice;
5154}
5155
5156static void gen9_sseu_device_status(struct drm_device *dev,
5157 struct sseu_dev_status *stat)
5158{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005159 struct drm_i915_private *dev_priv = to_i915(dev);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005160 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005161 int s, ss;
5162 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5163
Jeff McGee1c046bc2015-04-03 18:13:18 -07005164 /* BXT has a single slice and at most 3 subslices. */
5165 if (IS_BROXTON(dev)) {
5166 s_max = 1;
5167 ss_max = 3;
5168 }
5169
5170 for (s = 0; s < s_max; s++) {
5171 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5172 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5173 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5174 }
5175
Jeff McGee5d395252015-04-03 18:13:17 -07005176 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5177 GEN9_PGCTL_SSA_EU19_ACK |
5178 GEN9_PGCTL_SSA_EU210_ACK |
5179 GEN9_PGCTL_SSA_EU311_ACK;
5180 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5181 GEN9_PGCTL_SSB_EU19_ACK |
5182 GEN9_PGCTL_SSB_EU210_ACK |
5183 GEN9_PGCTL_SSB_EU311_ACK;
5184
5185 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005186 unsigned int ss_cnt = 0;
5187
Jeff McGee5d395252015-04-03 18:13:17 -07005188 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5189 /* skip disabled slice */
5190 continue;
5191
5192 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005193
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005194 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005195 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5196
Jeff McGee5d395252015-04-03 18:13:17 -07005197 for (ss = 0; ss < ss_max; ss++) {
5198 unsigned int eu_cnt;
5199
Jeff McGee1c046bc2015-04-03 18:13:18 -07005200 if (IS_BROXTON(dev) &&
5201 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5202 /* skip disabled subslice */
5203 continue;
5204
5205 if (IS_BROXTON(dev))
5206 ss_cnt++;
5207
Jeff McGee5d395252015-04-03 18:13:17 -07005208 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5209 eu_mask[ss%2]);
5210 stat->eu_total += eu_cnt;
5211 stat->eu_per_subslice = max(stat->eu_per_subslice,
5212 eu_cnt);
5213 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005214
5215 stat->subslice_total += ss_cnt;
5216 stat->subslice_per_slice = max(stat->subslice_per_slice,
5217 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005218 }
5219}
5220
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005221static void broadwell_sseu_device_status(struct drm_device *dev,
5222 struct sseu_dev_status *stat)
5223{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005224 struct drm_i915_private *dev_priv = to_i915(dev);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005225 int s;
5226 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5227
5228 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5229
5230 if (stat->slice_total) {
5231 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5232 stat->subslice_total = stat->slice_total *
5233 stat->subslice_per_slice;
5234 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5235 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5236
5237 /* subtract fused off EU(s) from enabled slice(s) */
5238 for (s = 0; s < stat->slice_total; s++) {
5239 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5240
5241 stat->eu_total -= hweight8(subslice_7eu);
5242 }
5243 }
5244}
5245
Jeff McGee38732182015-02-13 10:27:54 -06005246static int i915_sseu_status(struct seq_file *m, void *unused)
5247{
5248 struct drm_info_node *node = (struct drm_info_node *) m->private;
David Weinehall238010e2016-08-01 17:33:27 +03005249 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
5250 struct drm_device *dev = &dev_priv->drm;
Jeff McGee5d395252015-04-03 18:13:17 -07005251 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005252
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005253 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005254 return -ENODEV;
5255
5256 seq_puts(m, "SSEU Device Info\n");
5257 seq_printf(m, " Available Slice Total: %u\n",
5258 INTEL_INFO(dev)->slice_total);
5259 seq_printf(m, " Available Subslice Total: %u\n",
5260 INTEL_INFO(dev)->subslice_total);
5261 seq_printf(m, " Available Subslice Per Slice: %u\n",
5262 INTEL_INFO(dev)->subslice_per_slice);
5263 seq_printf(m, " Available EU Total: %u\n",
5264 INTEL_INFO(dev)->eu_total);
5265 seq_printf(m, " Available EU Per Subslice: %u\n",
5266 INTEL_INFO(dev)->eu_per_subslice);
arun.siluvery@linux.intel.com33e141e2016-06-03 06:34:33 +01005267 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev)));
5268 if (HAS_POOLED_EU(dev))
5269 seq_printf(m, " Min EU in pool: %u\n",
5270 INTEL_INFO(dev)->min_eu_in_pool);
Jeff McGee38732182015-02-13 10:27:54 -06005271 seq_printf(m, " Has Slice Power Gating: %s\n",
5272 yesno(INTEL_INFO(dev)->has_slice_pg));
5273 seq_printf(m, " Has Subslice Power Gating: %s\n",
5274 yesno(INTEL_INFO(dev)->has_subslice_pg));
5275 seq_printf(m, " Has EU Power Gating: %s\n",
5276 yesno(INTEL_INFO(dev)->has_eu_pg));
5277
Jeff McGee7f992ab2015-02-13 10:27:55 -06005278 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005279 memset(&stat, 0, sizeof(stat));
David Weinehall238010e2016-08-01 17:33:27 +03005280
5281 intel_runtime_pm_get(dev_priv);
5282
Jeff McGee5575f032015-02-27 10:22:32 -08005283 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005284 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005285 } else if (IS_BROADWELL(dev)) {
5286 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005287 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005288 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005289 }
David Weinehall238010e2016-08-01 17:33:27 +03005290
5291 intel_runtime_pm_put(dev_priv);
5292
Jeff McGee5d395252015-04-03 18:13:17 -07005293 seq_printf(m, " Enabled Slice Total: %u\n",
5294 stat.slice_total);
5295 seq_printf(m, " Enabled Subslice Total: %u\n",
5296 stat.subslice_total);
5297 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5298 stat.subslice_per_slice);
5299 seq_printf(m, " Enabled EU Total: %u\n",
5300 stat.eu_total);
5301 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5302 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005303
Jeff McGee38732182015-02-13 10:27:54 -06005304 return 0;
5305}
5306
Ben Widawsky6d794d42011-04-25 11:25:56 -07005307static int i915_forcewake_open(struct inode *inode, struct file *file)
5308{
5309 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005310 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005311
Daniel Vetter075edca2012-01-24 09:44:28 +01005312 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005313 return 0;
5314
Chris Wilson6daccb02015-01-16 11:34:35 +02005315 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005316 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005317
5318 return 0;
5319}
5320
Ben Widawskyc43b5632012-04-16 14:07:40 -07005321static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005322{
5323 struct drm_device *dev = inode->i_private;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005324 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005325
Daniel Vetter075edca2012-01-24 09:44:28 +01005326 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005327 return 0;
5328
Mika Kuoppala59bad942015-01-16 11:34:40 +02005329 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005330 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005331
5332 return 0;
5333}
5334
5335static const struct file_operations i915_forcewake_fops = {
5336 .owner = THIS_MODULE,
5337 .open = i915_forcewake_open,
5338 .release = i915_forcewake_release,
5339};
5340
5341static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5342{
5343 struct drm_device *dev = minor->dev;
5344 struct dentry *ent;
5345
5346 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005347 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005348 root, dev,
5349 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005350 if (!ent)
5351 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005352
Ben Widawsky8eb57292011-05-11 15:10:58 -07005353 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005354}
5355
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005356static int i915_debugfs_create(struct dentry *root,
5357 struct drm_minor *minor,
5358 const char *name,
5359 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005360{
5361 struct drm_device *dev = minor->dev;
5362 struct dentry *ent;
5363
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005364 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005365 S_IRUGO | S_IWUSR,
5366 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005367 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005368 if (!ent)
5369 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005370
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005371 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005372}
5373
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005374static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005375 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005376 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005377 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005378 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005379 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005380 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005381 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005382 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005383 {"i915_gem_request", i915_gem_request_info, 0},
5384 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005385 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005386 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005387 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5388 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5389 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005390 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005391 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005392 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005393 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005394 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305395 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005396 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005397 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005398 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005399 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005400 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005401 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005402 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005403 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005404 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005405 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005406 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005407 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005408 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005409 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005410 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005411 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005412 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005413 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005414 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005415 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005416 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005417 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005418 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005419 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005420 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005421 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005422 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005423 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005424 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005425 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005426 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305427 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005428 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005429};
Ben Gamari27c202a2009-07-01 22:26:52 -04005430#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005431
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005432static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005433 const char *name;
5434 const struct file_operations *fops;
5435} i915_debugfs_files[] = {
5436 {"i915_wedged", &i915_wedged_fops},
5437 {"i915_max_freq", &i915_max_freq_fops},
5438 {"i915_min_freq", &i915_min_freq_fops},
5439 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005440 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5441 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005442 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5443 {"i915_error_state", &i915_error_state_fops},
5444 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005445 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005446 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5447 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5448 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005449 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005450 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5451 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5452 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005453};
5454
Damien Lespiau07144422013-10-15 18:55:40 +01005455void intel_display_crc_init(struct drm_device *dev)
5456{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005457 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb3783602013-11-14 11:30:42 +01005458 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005459
Damien Lespiau055e3932014-08-18 13:49:10 +01005460 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005461 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005462
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005463 pipe_crc->opened = false;
5464 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005465 init_waitqueue_head(&pipe_crc->wq);
5466 }
5467}
5468
Chris Wilson1dac8912016-06-24 14:00:17 +01005469int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005470{
Chris Wilson91c8a322016-07-05 10:40:23 +01005471 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005472 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005473
Ben Widawsky6d794d42011-04-25 11:25:56 -07005474 ret = i915_forcewake_create(minor->debugfs_root, minor);
5475 if (ret)
5476 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005477
Damien Lespiau07144422013-10-15 18:55:40 +01005478 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5479 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5480 if (ret)
5481 return ret;
5482 }
5483
Daniel Vetter34b96742013-07-04 20:49:44 +02005484 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5485 ret = i915_debugfs_create(minor->debugfs_root, minor,
5486 i915_debugfs_files[i].name,
5487 i915_debugfs_files[i].fops);
5488 if (ret)
5489 return ret;
5490 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005491
Ben Gamari27c202a2009-07-01 22:26:52 -04005492 return drm_debugfs_create_files(i915_debugfs_list,
5493 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005494 minor->debugfs_root, minor);
5495}
5496
Chris Wilson1dac8912016-06-24 14:00:17 +01005497void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005498{
Chris Wilson91c8a322016-07-05 10:40:23 +01005499 struct drm_minor *minor = dev_priv->drm.primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005500 int i;
5501
Ben Gamari27c202a2009-07-01 22:26:52 -04005502 drm_debugfs_remove_files(i915_debugfs_list,
5503 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005504
Ben Widawsky6d794d42011-04-25 11:25:56 -07005505 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5506 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005507
Daniel Vettere309a992013-10-16 22:55:51 +02005508 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005509 struct drm_info_list *info_list =
5510 (struct drm_info_list *)&i915_pipe_crc_data[i];
5511
5512 drm_debugfs_remove_files(info_list, 1, minor);
5513 }
5514
Daniel Vetter34b96742013-07-04 20:49:44 +02005515 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5516 struct drm_info_list *info_list =
5517 (struct drm_info_list *) i915_debugfs_files[i].fops;
5518
5519 drm_debugfs_remove_files(info_list, 1, minor);
5520 }
Ben Gamari20172632009-02-17 20:08:50 -05005521}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005522
5523struct dpcd_block {
5524 /* DPCD dump start address. */
5525 unsigned int offset;
5526 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5527 unsigned int end;
5528 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5529 size_t size;
5530 /* Only valid for eDP. */
5531 bool edp;
5532};
5533
5534static const struct dpcd_block i915_dpcd_debug[] = {
5535 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5536 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5537 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5538 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5539 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5540 { .offset = DP_SET_POWER },
5541 { .offset = DP_EDP_DPCD_REV },
5542 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5543 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5544 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5545};
5546
5547static int i915_dpcd_show(struct seq_file *m, void *data)
5548{
5549 struct drm_connector *connector = m->private;
5550 struct intel_dp *intel_dp =
5551 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5552 uint8_t buf[16];
5553 ssize_t err;
5554 int i;
5555
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005556 if (connector->status != connector_status_connected)
5557 return -ENODEV;
5558
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005559 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5560 const struct dpcd_block *b = &i915_dpcd_debug[i];
5561 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5562
5563 if (b->edp &&
5564 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5565 continue;
5566
5567 /* low tech for now */
5568 if (WARN_ON(size > sizeof(buf)))
5569 continue;
5570
5571 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5572 if (err <= 0) {
5573 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5574 size, b->offset, err);
5575 continue;
5576 }
5577
5578 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005579 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005580
5581 return 0;
5582}
5583
5584static int i915_dpcd_open(struct inode *inode, struct file *file)
5585{
5586 return single_open(file, i915_dpcd_show, inode->i_private);
5587}
5588
5589static const struct file_operations i915_dpcd_fops = {
5590 .owner = THIS_MODULE,
5591 .open = i915_dpcd_open,
5592 .read = seq_read,
5593 .llseek = seq_lseek,
5594 .release = single_release,
5595};
5596
5597/**
5598 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5599 * @connector: pointer to a registered drm_connector
5600 *
5601 * Cleanup will be done by drm_connector_unregister() through a call to
5602 * drm_debugfs_connector_remove().
5603 *
5604 * Returns 0 on success, negative error codes on error.
5605 */
5606int i915_debugfs_connector_add(struct drm_connector *connector)
5607{
5608 struct dentry *root = connector->debugfs_entry;
5609
5610 /* The connector must have been registered beforehands. */
5611 if (!root)
5612 return -ENODEV;
5613
5614 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5615 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5616 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5617 &i915_dpcd_fops);
5618
5619 return 0;
5620}